Skip to content

Commit 366f240

Browse files
committed
Added oneof clause to all Platform* responses
1 parent 8b78c05 commit 366f240

File tree

8 files changed

+675
-192
lines changed

8 files changed

+675
-192
lines changed

commands/service_platform_download.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques
6363
return &cmderrors.PlatformNotFoundError{Platform: ref.String(), Cause: err}
6464
}
6565

66-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.PlatformDownloadResponse{Progress: p}) }
66+
downloadCB := func(p *rpc.DownloadProgress) {
67+
syncSend.Send(&rpc.PlatformDownloadResponse{
68+
Message: &rpc.PlatformDownloadResponse_Progress{
69+
Progress: p,
70+
},
71+
})
72+
}
6773

6874
// TODO: pass context
6975
// ctx := stream.Context()
@@ -78,5 +84,7 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques
7884
}
7985
}
8086

81-
return syncSend.Send(&rpc.PlatformDownloadResponse{})
87+
return syncSend.Send(&rpc.PlatformDownloadResponse{Message: &rpc.PlatformDownloadResponse_Result_{
88+
Result: &rpc.PlatformDownloadResponse_Result{},
89+
}})
8290
}

commands/service_platform_install.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,20 @@ func PlatformInstallStreamResponseToCallbackFunction(ctx context.Context, downlo
4343
func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest, stream rpc.ArduinoCoreService_PlatformInstallServer) error {
4444
ctx := stream.Context()
4545
syncSend := NewSynchronizedSend(stream.Send)
46-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformInstallResponse{TaskProgress: p}) }
47-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.PlatformInstallResponse{Progress: p}) }
46+
taskCB := func(p *rpc.TaskProgress) {
47+
syncSend.Send(&rpc.PlatformInstallResponse{
48+
Message: &rpc.PlatformInstallResponse_TaskProgress{
49+
TaskProgress: p,
50+
},
51+
})
52+
}
53+
downloadCB := func(p *rpc.DownloadProgress) {
54+
syncSend.Send(&rpc.PlatformInstallResponse{
55+
Message: &rpc.PlatformInstallResponse_Progress{
56+
Progress: p,
57+
},
58+
})
59+
}
4860

4961
install := func() error {
5062
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
@@ -102,5 +114,9 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest,
102114
return err
103115
}
104116

105-
return syncSend.Send(&rpc.PlatformInstallResponse{})
117+
return syncSend.Send(&rpc.PlatformInstallResponse{
118+
Message: &rpc.PlatformInstallResponse_Result_{
119+
Result: &rpc.PlatformInstallResponse_Result{},
120+
},
121+
})
106122
}

commands/service_platform_uninstall.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,24 @@ func PlatformUninstallStreamResponseToCallbackFunction(ctx context.Context, task
3939
func (s *arduinoCoreServerImpl) PlatformUninstall(req *rpc.PlatformUninstallRequest, stream rpc.ArduinoCoreService_PlatformUninstallServer) error {
4040
syncSend := NewSynchronizedSend(stream.Send)
4141
ctx := stream.Context()
42-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformUninstallResponse{TaskProgress: p}) }
42+
taskCB := func(p *rpc.TaskProgress) {
43+
syncSend.Send(&rpc.PlatformUninstallResponse{
44+
Message: &rpc.PlatformUninstallResponse_TaskProgress{
45+
TaskProgress: p,
46+
},
47+
})
48+
}
4349
if err := platformUninstall(ctx, req, taskCB); err != nil {
4450
return err
4551
}
4652
if err := s.Init(&rpc.InitRequest{Instance: req.GetInstance()}, InitStreamResponseToCallbackFunction(ctx, nil)); err != nil {
4753
return err
4854
}
49-
return syncSend.Send(&rpc.PlatformUninstallResponse{})
55+
return syncSend.Send(&rpc.PlatformUninstallResponse{
56+
Message: &rpc.PlatformUninstallResponse_Result_{
57+
Result: &rpc.PlatformUninstallResponse_Result{},
58+
},
59+
})
5060
}
5161

5262
// platformUninstall is the implementation of platform unistaller

commands/service_platform_upgrade.go

+26-11
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ import (
2626

2727
// PlatformUpgradeStreamResponseToCallbackFunction returns a gRPC stream to be used in PlatformUpgrade that sends
2828
// all responses to the callback function.
29-
func PlatformUpgradeStreamResponseToCallbackFunction(ctx context.Context, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (rpc.ArduinoCoreService_PlatformUpgradeServer, func() *rpc.Platform) {
30-
var resp *rpc.Platform
29+
func PlatformUpgradeStreamResponseToCallbackFunction(ctx context.Context, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (rpc.ArduinoCoreService_PlatformUpgradeServer, func() *rpc.PlatformUpgradeResponse_Result) {
30+
var resp *rpc.PlatformUpgradeResponse_Result
3131
return streamResponseToCallback(ctx, func(r *rpc.PlatformUpgradeResponse) error {
32-
// TODO: use oneof in protoc files?
3332
if r.GetProgress() != nil {
3433
downloadCB(r.GetProgress())
3534
}
3635
if r.GetTaskProgress() != nil {
3736
taskCB(r.GetTaskProgress())
3837
}
39-
if r.GetPlatform() != nil {
40-
resp = r.GetPlatform()
38+
if r.GetResult() != nil {
39+
resp = r.GetResult()
4140
}
4241
return nil
43-
}), func() *rpc.Platform {
42+
}), func() *rpc.PlatformUpgradeResponse_Result {
4443
return resp
4544
}
4645
}
@@ -49,8 +48,20 @@ func PlatformUpgradeStreamResponseToCallbackFunction(ctx context.Context, downlo
4948
func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest, stream rpc.ArduinoCoreService_PlatformUpgradeServer) error {
5049
syncSend := NewSynchronizedSend(stream.Send)
5150
ctx := stream.Context()
52-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.PlatformUpgradeResponse{Progress: p}) }
53-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.PlatformUpgradeResponse{TaskProgress: p}) }
51+
downloadCB := func(p *rpc.DownloadProgress) {
52+
syncSend.Send(&rpc.PlatformUpgradeResponse{
53+
Message: &rpc.PlatformUpgradeResponse_Progress{
54+
Progress: p,
55+
},
56+
})
57+
}
58+
taskCB := func(p *rpc.TaskProgress) {
59+
syncSend.Send(&rpc.PlatformUpgradeResponse{
60+
Message: &rpc.PlatformUpgradeResponse_TaskProgress{
61+
TaskProgress: p,
62+
},
63+
})
64+
}
5465

5566
upgrade := func() (*cores.PlatformRelease, error) {
5667
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
@@ -75,9 +86,13 @@ func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest,
7586
platformRelease, err := upgrade()
7687
if platformRelease != nil {
7788
syncSend.Send(&rpc.PlatformUpgradeResponse{
78-
Platform: &rpc.Platform{
79-
Metadata: platformToRPCPlatformMetadata(platformRelease.Platform),
80-
Release: platformReleaseToRPC(platformRelease),
89+
Message: &rpc.PlatformUpgradeResponse_Result_{
90+
Result: &rpc.PlatformUpgradeResponse_Result{
91+
Platform: &rpc.Platform{
92+
Metadata: platformToRPCPlatformMetadata(platformRelease.Platform),
93+
Release: platformReleaseToRPC(platformRelease),
94+
},
95+
},
8196
},
8297
})
8398
}

internal/cli/core/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func Upgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, inst *rpc.In
124124
}
125125
stream, respCB := commands.PlatformUpgradeStreamResponseToCallbackFunction(ctx, feedback.ProgressBar(), feedback.TaskProgress())
126126
err := srv.PlatformUpgrade(r, stream)
127-
warningMissingIndex(respCB())
127+
warningMissingIndex(respCB().GetPlatform())
128128
if err != nil {
129129
var alreadyAtLatestVersionErr *cmderrors.PlatformAlreadyAtTheLatestVersionError
130130
if errors.As(err, &alreadyAtLatestVersionErr) {

internal/integrationtest/daemon/daemon_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ func analyzePlatformUpgradeClient(cl commands.ArduinoCoreService_PlatformUpgrade
559559
if errors.Is(err, io.EOF) {
560560
break
561561
}
562-
if msg.GetPlatform() != nil {
563-
platform = msg.GetPlatform()
562+
if res := msg.GetResult(); res != nil {
563+
platform = res.GetPlatform()
564564
}
565565
if err != nil {
566566
upgradeError = err

0 commit comments

Comments
 (0)