@@ -24,8 +24,34 @@ import (
24
24
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
25
25
)
26
26
27
- // PlatformUpgrade FIXMEDOC
28
- func PlatformUpgrade (ctx context.Context , srv rpc.ArduinoCoreServiceServer , req * rpc.PlatformUpgradeRequest , downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) (* rpc.PlatformUpgradeResponse , error ) {
27
+ // PlatformUpgradeStreamResponseToCallbackFunction returns a gRPC stream to be used in PlatformUpgrade that sends
28
+ // 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
31
+ return streamResponseToCallback (ctx , func (r * rpc.PlatformUpgradeResponse ) error {
32
+ // TODO: use oneof in protoc files?
33
+ if r .GetProgress () != nil {
34
+ downloadCB (r .GetProgress ())
35
+ }
36
+ if r .GetTaskProgress () != nil {
37
+ taskCB (r .GetTaskProgress ())
38
+ }
39
+ if r .GetPlatform () != nil {
40
+ resp = r .GetPlatform ()
41
+ }
42
+ return nil
43
+ }), func () * rpc.Platform {
44
+ return resp
45
+ }
46
+ }
47
+
48
+ // PlatformUpgrade upgrades a platform package
49
+ func (s * arduinoCoreServerImpl ) PlatformUpgrade (req * rpc.PlatformUpgradeRequest , stream rpc.ArduinoCoreService_PlatformUpgradeServer ) error {
50
+ syncSend := NewSynchronizedSend (stream .Send )
51
+ 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 }) }
54
+
29
55
upgrade := func () (* cores.PlatformRelease , error ) {
30
56
pme , release , err := instances .GetPackageManagerExplorer (req .GetInstance ())
31
57
if err != nil {
@@ -46,20 +72,22 @@ func PlatformUpgrade(ctx context.Context, srv rpc.ArduinoCoreServiceServer, req
46
72
return platform , nil
47
73
}
48
74
49
- var rpcPlatform * rpc.Platform
50
75
platformRelease , err := upgrade ()
51
76
if platformRelease != nil {
52
- rpcPlatform = & rpc.Platform {
53
- Metadata : PlatformToRPCPlatformMetadata (platformRelease .Platform ),
54
- Release : PlatformReleaseToRPC (platformRelease ),
55
- }
77
+ syncSend .Send (& rpc.PlatformUpgradeResponse {
78
+ Platform : & rpc.Platform {
79
+ Metadata : PlatformToRPCPlatformMetadata (platformRelease .Platform ),
80
+ Release : PlatformReleaseToRPC (platformRelease ),
81
+ },
82
+ })
56
83
}
57
84
if err != nil {
58
- return & rpc. PlatformUpgradeResponse { Platform : rpcPlatform }, err
85
+ return err
59
86
}
60
- if err := srv .Init (& rpc.InitRequest {Instance : req .GetInstance ()}, InitStreamResponseToCallbackFunction (ctx , nil )); err != nil {
61
- return nil , err
87
+
88
+ if err := s .Init (& rpc.InitRequest {Instance : req .GetInstance ()}, InitStreamResponseToCallbackFunction (ctx , nil )); err != nil {
89
+ return err
62
90
}
63
91
64
- return & rpc. PlatformUpgradeResponse { Platform : rpcPlatform }, nil
92
+ return nil
65
93
}
0 commit comments