Skip to content

Commit f5786b1

Browse files
committed
Added oneof clause to all Debug* and Library* responses
1 parent 366f240 commit f5786b1

10 files changed

+1542
-593
lines changed

commands/service_debug.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func (s *arduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer)
4242
// Launch debug recipe attaching stdin and out to grpc streaming
4343
signalChan := make(chan os.Signal)
4444
defer close(signalChan)
45-
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.DebugResponse{Data: data}) })
45+
outStream := feedStreamTo(func(data []byte) {
46+
stream.Send(&rpc.DebugResponse{Message: &rpc.DebugResponse_Data{
47+
Data: data,
48+
}})
49+
})
4650
resp, debugErr := Debug(stream.Context(), req,
4751
consumeStreamFrom(func() ([]byte, error) {
4852
command, err := stream.Recv()

commands/service_debug_run.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Read
7171
// Get stdIn pipe from tool
7272
in, err := cmd.StdinPipe()
7373
if err != nil {
74-
return &rpc.DebugResponse{Error: err.Error()}, nil
74+
return &rpc.DebugResponse{Message: &rpc.DebugResponse_Result_{
75+
Result: &rpc.DebugResponse_Result{Error: err.Error()},
76+
}}, nil
7577
}
7678
defer in.Close()
7779

@@ -81,7 +83,9 @@ func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Read
8183

8284
// Start the debug command
8385
if err := cmd.Start(); err != nil {
84-
return &rpc.DebugResponse{Error: err.Error()}, nil
86+
return &rpc.DebugResponse{Message: &rpc.DebugResponse_Result_{
87+
Result: &rpc.DebugResponse_Result{Error: err.Error()},
88+
}}, nil
8589
}
8690

8791
if interrupt != nil {
@@ -107,9 +111,13 @@ func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Read
107111

108112
// Wait for process to finish
109113
if err := cmd.Wait(); err != nil {
110-
return &rpc.DebugResponse{Error: err.Error()}, nil
114+
return &rpc.DebugResponse{Message: &rpc.DebugResponse_Result_{
115+
Result: &rpc.DebugResponse_Result{Error: err.Error()},
116+
}}, nil
111117
}
112-
return &rpc.DebugResponse{}, nil
118+
return &rpc.DebugResponse{Message: &rpc.DebugResponse_Result_{
119+
Result: &rpc.DebugResponse_Result{},
120+
}}, nil
113121
}
114122

115123
// getCommandLine compose a debug command represented by a core recipe

commands/service_library_download.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ func LibraryDownloadStreamResponseToCallbackFunction(ctx context.Context, downlo
4141
func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest, stream rpc.ArduinoCoreService_LibraryDownloadServer) error {
4242
syncSend := NewSynchronizedSend(stream.Send)
4343
ctx := stream.Context()
44-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryDownloadResponse{Progress: p}) }
44+
downloadCB := func(p *rpc.DownloadProgress) {
45+
syncSend.Send(&rpc.LibraryDownloadResponse{
46+
Message: &rpc.LibraryDownloadResponse_Progress{Progress: p},
47+
})
48+
}
4549

4650
var downloadsDir *paths.Path
4751
if pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance()); err != nil {
@@ -70,7 +74,11 @@ func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
7074
return err
7175
}
7276

73-
return syncSend.Send(&rpc.LibraryDownloadResponse{})
77+
return syncSend.Send(&rpc.LibraryDownloadResponse{
78+
Message: &rpc.LibraryDownloadResponse_Result_{
79+
Result: &rpc.LibraryDownloadResponse_Result{},
80+
},
81+
})
7482
}
7583

7684
func downloadLibrary(_ context.Context, downloadsDir *paths.Path, libRelease *librariesindex.Release,

commands/service_library_install.go

+35-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,16 @@ func LibraryInstallStreamResponseToCallbackFunction(ctx context.Context, downloa
4848
func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, stream rpc.ArduinoCoreService_LibraryInstallServer) error {
4949
ctx := stream.Context()
5050
syncSend := NewSynchronizedSend(stream.Send)
51-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryInstallResponse{Progress: p}) }
52-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryInstallResponse{TaskProgress: p}) }
51+
downloadCB := func(p *rpc.DownloadProgress) {
52+
syncSend.Send(&rpc.LibraryInstallResponse{
53+
Message: &rpc.LibraryInstallResponse_Progress{Progress: p},
54+
})
55+
}
56+
taskCB := func(p *rpc.TaskProgress) {
57+
syncSend.Send(&rpc.LibraryInstallResponse{
58+
Message: &rpc.LibraryInstallResponse_TaskProgress{TaskProgress: p},
59+
})
60+
}
5361

5462
// Obtain the library index from the manager
5563
li, err := instances.GetLibrariesIndex(req.GetInstance())
@@ -162,6 +170,11 @@ func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
162170
return err
163171
}
164172

173+
syncSend.Send(&rpc.LibraryInstallResponse{
174+
Message: &rpc.LibraryInstallResponse_Result_{
175+
Result: &rpc.LibraryInstallResponse_Result{},
176+
},
177+
})
165178
return nil
166179
}
167180

@@ -202,7 +215,11 @@ func ZipLibraryInstallStreamResponseToCallbackFunction(ctx context.Context, task
202215
func (s *arduinoCoreServerImpl) ZipLibraryInstall(req *rpc.ZipLibraryInstallRequest, stream rpc.ArduinoCoreService_ZipLibraryInstallServer) error {
203216
ctx := stream.Context()
204217
syncSend := NewSynchronizedSend(stream.Send)
205-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.ZipLibraryInstallResponse{TaskProgress: p}) }
218+
taskCB := func(p *rpc.TaskProgress) {
219+
syncSend.Send(&rpc.ZipLibraryInstallResponse{
220+
Message: &rpc.ZipLibraryInstallResponse_TaskProgress{TaskProgress: p},
221+
})
222+
}
206223

207224
lm, err := instances.GetLibraryManager(req.GetInstance())
208225
if err != nil {
@@ -214,6 +231,11 @@ func (s *arduinoCoreServerImpl) ZipLibraryInstall(req *rpc.ZipLibraryInstallRequ
214231
return &cmderrors.FailedLibraryInstallError{Cause: err}
215232
}
216233
taskCB(&rpc.TaskProgress{Message: tr("Library installed"), Completed: true})
234+
syncSend.Send(&rpc.ZipLibraryInstallResponse{
235+
Message: &rpc.ZipLibraryInstallResponse_Result_{
236+
Result: &rpc.ZipLibraryInstallResponse_Result{},
237+
},
238+
})
217239
return nil
218240
}
219241

@@ -231,7 +253,11 @@ func GitLibraryInstallStreamResponseToCallbackFunction(ctx context.Context, task
231253
// GitLibraryInstall FIXMEDOC
232254
func (s *arduinoCoreServerImpl) GitLibraryInstall(req *rpc.GitLibraryInstallRequest, stream rpc.ArduinoCoreService_GitLibraryInstallServer) error {
233255
syncSend := NewSynchronizedSend(stream.Send)
234-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.GitLibraryInstallResponse{TaskProgress: p}) }
256+
taskCB := func(p *rpc.TaskProgress) {
257+
syncSend.Send(&rpc.GitLibraryInstallResponse{
258+
Message: &rpc.GitLibraryInstallResponse_TaskProgress{TaskProgress: p},
259+
})
260+
}
235261
lm, err := instances.GetLibraryManager(req.GetInstance())
236262
if err != nil {
237263
return err
@@ -245,5 +271,10 @@ func (s *arduinoCoreServerImpl) GitLibraryInstall(req *rpc.GitLibraryInstallRequ
245271
return &cmderrors.FailedLibraryInstallError{Cause: err}
246272
}
247273
taskCB(&rpc.TaskProgress{Message: tr("Library installed"), Completed: true})
274+
syncSend.Send(&rpc.GitLibraryInstallResponse{
275+
Message: &rpc.GitLibraryInstallResponse_Result_{
276+
Result: &rpc.GitLibraryInstallResponse_Result{},
277+
},
278+
})
248279
return nil
249280
}

commands/service_library_uninstall.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ func LibraryUninstallStreamResponseToCallbackFunction(ctx context.Context, taskC
3838

3939
// LibraryUninstall uninstalls a library
4040
func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallRequest, stream rpc.ArduinoCoreService_LibraryUninstallServer) error {
41-
// ctx := stream.Context()
4241
syncSend := NewSynchronizedSend(stream.Send)
43-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryUninstallResponse{TaskProgress: p}) }
42+
taskCB := func(p *rpc.TaskProgress) {
43+
syncSend.Send(&rpc.LibraryUninstallResponse{
44+
Message: &rpc.LibraryUninstallResponse_TaskProgress{TaskProgress: p},
45+
})
46+
}
4447

4548
lm, err := instances.GetLibraryManager(req.GetInstance())
4649
if err != nil {
@@ -57,14 +60,19 @@ func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReques
5760
libs := lmi.FindByReference(req.GetName(), version, libraries.User)
5861
if len(libs) == 0 {
5962
taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.GetName()), Completed: true})
63+
syncSend.Send(&rpc.LibraryUninstallResponse{
64+
Message: &rpc.LibraryUninstallResponse_Result_{Result: &rpc.LibraryUninstallResponse_Result{}},
65+
})
6066
return nil
6167
}
6268

6369
if len(libs) == 1 {
6470
taskCB(&rpc.TaskProgress{Name: tr("Uninstalling %s", libs)})
65-
// TODO: pass context
6671
lmi.Uninstall(libs[0])
6772
taskCB(&rpc.TaskProgress{Completed: true})
73+
syncSend.Send(&rpc.LibraryUninstallResponse{
74+
Message: &rpc.LibraryUninstallResponse_Result_{Result: &rpc.LibraryUninstallResponse_Result{}},
75+
})
6876
return nil
6977
}
7078

commands/service_library_upgrade.go

+37-7
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ func LibraryUpgradeAllStreamResponseToCallbackFunction(ctx context.Context, down
4141
func (s *arduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, stream rpc.ArduinoCoreService_LibraryUpgradeAllServer) error {
4242
ctx := stream.Context()
4343
syncSend := NewSynchronizedSend(stream.Send)
44-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryUpgradeAllResponse{Progress: p}) }
45-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryUpgradeAllResponse{TaskProgress: p}) }
44+
downloadCB := func(p *rpc.DownloadProgress) {
45+
syncSend.Send(&rpc.LibraryUpgradeAllResponse{
46+
Message: &rpc.LibraryUpgradeAllResponse_Progress{Progress: p},
47+
})
48+
}
49+
taskCB := func(p *rpc.TaskProgress) {
50+
syncSend.Send(&rpc.LibraryUpgradeAllResponse{
51+
Message: &rpc.LibraryUpgradeAllResponse_TaskProgress{TaskProgress: p},
52+
})
53+
}
4654

4755
li, err := instances.GetLibrariesIndex(req.GetInstance())
4856
if err != nil {
@@ -67,6 +75,11 @@ func (s *arduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequ
6775
return err
6876
}
6977

78+
syncSend.Send(&rpc.LibraryUpgradeAllResponse{
79+
Message: &rpc.LibraryUpgradeAllResponse_Result_{
80+
Result: &rpc.LibraryUpgradeAllResponse_Result{},
81+
},
82+
})
7083
return nil
7184
}
7285

@@ -88,8 +101,16 @@ func LibraryUpgradeStreamResponseToCallbackFunction(ctx context.Context, downloa
88101
func (s *arduinoCoreServerImpl) LibraryUpgrade(req *rpc.LibraryUpgradeRequest, stream rpc.ArduinoCoreService_LibraryUpgradeServer) error {
89102
ctx := stream.Context()
90103
syncSend := NewSynchronizedSend(stream.Send)
91-
downloadCB := func(p *rpc.DownloadProgress) { syncSend.Send(&rpc.LibraryUpgradeResponse{Progress: p}) }
92-
taskCB := func(p *rpc.TaskProgress) { syncSend.Send(&rpc.LibraryUpgradeResponse{TaskProgress: p}) }
104+
downloadCB := func(p *rpc.DownloadProgress) {
105+
syncSend.Send(&rpc.LibraryUpgradeResponse{
106+
Message: &rpc.LibraryUpgradeResponse_Progress{Progress: p},
107+
})
108+
}
109+
taskCB := func(p *rpc.TaskProgress) {
110+
syncSend.Send(&rpc.LibraryUpgradeResponse{
111+
Message: &rpc.LibraryUpgradeResponse_TaskProgress{TaskProgress: p},
112+
})
113+
}
93114

94115
li, err := instances.GetLibrariesIndex(req.GetInstance())
95116
if err != nil {
@@ -111,12 +132,21 @@ func (s *arduinoCoreServerImpl) LibraryUpgrade(req *rpc.LibraryUpgradeRequest, s
111132
return &cmderrors.LibraryNotFoundError{Library: name}
112133
}
113134
if lib.Available == nil {
135+
// library already at the latest version
114136
taskCB(&rpc.TaskProgress{Message: tr("Library %s is already at the latest version", name), Completed: true})
115-
return nil
137+
} else {
138+
// Install update
139+
if err := s.libraryUpgrade(ctx, req.GetInstance(), []*installedLib{lib}, downloadCB, taskCB); err != nil {
140+
return err
141+
}
116142
}
117143

118-
// Install update
119-
return s.libraryUpgrade(ctx, req.GetInstance(), []*installedLib{lib}, downloadCB, taskCB)
144+
syncSend.Send(&rpc.LibraryUpgradeResponse{
145+
Message: &rpc.LibraryUpgradeResponse_Result_{
146+
Result: &rpc.LibraryUpgradeResponse_Result{},
147+
},
148+
})
149+
return nil
120150
}
121151

122152
func (s *arduinoCoreServerImpl) libraryUpgrade(ctx context.Context, instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {

0 commit comments

Comments
 (0)