Commit 2c1b10d8 authored by Cristian Maglie's avatar Cristian Maglie

Added status streaming to Init grpc call

This will be useful in the next commits
parent 02a8800f
...@@ -86,7 +86,7 @@ func packageManagerInitReq() *rpc.InitReq { ...@@ -86,7 +86,7 @@ func packageManagerInitReq() *rpc.InitReq {
func InitInstance() *rpc.InitResp { func InitInstance() *rpc.InitResp {
logrus.Info("Initializing package manager") logrus.Info("Initializing package manager")
req := packageManagerInitReq() req := packageManagerInitReq()
resp, err := commands.Init(context.Background(), req) resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress())
if err != nil { if err != nil {
formatter.PrintError(err, "Error initializing package manager") formatter.PrintError(err, "Error initializing package manager")
os.Exit(ErrGeneric) os.Exit(ErrGeneric)
......
...@@ -72,7 +72,7 @@ func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager ...@@ -72,7 +72,7 @@ func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager
return i.lm return i.lm
} }
func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) { func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, taskCB TaskProgressCB) (*rpc.InitResp, error) {
inConfig := req.GetConfiguration() inConfig := req.GetConfiguration()
if inConfig == nil { if inConfig == nil {
return nil, fmt.Errorf("invalid request") return nil, fmt.Errorf("invalid request")
......
...@@ -46,7 +46,7 @@ func main() { ...@@ -46,7 +46,7 @@ func main() {
// INIT // INIT
fmt.Println("=== calling Init") fmt.Println("=== calling Init")
initResp, err := client.Init(context.Background(), &rpc.InitReq{ initRespStream, err := client.Init(context.Background(), &rpc.InitReq{
Configuration: &rpc.Configuration{ Configuration: &rpc.Configuration{
DataDir: datadir, DataDir: datadir,
}, },
...@@ -55,9 +55,28 @@ func main() { ...@@ -55,9 +55,28 @@ func main() {
fmt.Printf("Error creating server instance: %s\n", err) fmt.Printf("Error creating server instance: %s\n", err)
os.Exit(1) os.Exit(1)
} }
instance := initResp.GetInstance() var instance *rpc.Instance
fmt.Printf("---> %+v\n", initResp) for {
fmt.Println() initResp, err := initRespStream.Recv()
if err == io.EOF {
fmt.Println()
break
}
if err != nil {
fmt.Printf("Init error: %s\n", err)
os.Exit(1)
}
if initResp.GetInstance() != nil {
instance = initResp.GetInstance()
fmt.Printf("---> %+v\n", initResp)
}
if initResp.GetDownloadProgress() != nil {
fmt.Printf(">> DOWNLOAD: %s\n", initResp.GetDownloadProgress())
}
if initResp.GetTaskProgress() != nil {
fmt.Printf(">> TASK: %s\n", initResp.GetTaskProgress())
}
}
// UPDATE-INDEX // UPDATE-INDEX
fmt.Println("=== calling UpdateIndex") fmt.Println("=== calling UpdateIndex")
......
...@@ -103,8 +103,16 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd ...@@ -103,8 +103,16 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
return stream.Send(&rpc.UpdateLibrariesIndexResp{}) return stream.Send(&rpc.UpdateLibrariesIndexResp{})
} }
func (s *ArduinoCoreServerImpl) Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) { func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_InitServer) error {
return commands.Init(ctx, req) resp, err := commands.Init(stream.Context(), req,
func(p *rpc.DownloadProgress) { stream.Send(&rpc.InitResp{DownloadProgress: p}) },
func(p *rpc.TaskProgress) { stream.Send(&rpc.InitResp{TaskProgress: p}) },
)
if err != nil {
return err
}
fmt.Println(resp)
return stream.Send(resp)
} }
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error { func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
......
This diff is collapsed.
...@@ -34,7 +34,7 @@ service ArduinoCore { ...@@ -34,7 +34,7 @@ service ArduinoCore {
//------------------- //-------------------
// Start a new instance of the Arduino Core Service // Start a new instance of the Arduino Core Service
rpc Init(InitReq) returns (InitResp) {} rpc Init(InitReq) returns (stream InitResp) {}
// Destroy an instance of the Arduino Core Service // Destroy an instance of the Arduino Core Service
rpc Destroy(DestroyReq) returns (DestroyResp) {} rpc Destroy(DestroyReq) returns (DestroyResp) {}
...@@ -115,6 +115,8 @@ message InitResp { ...@@ -115,6 +115,8 @@ message InitResp {
Instance instance = 1; Instance instance = 1;
repeated string platforms_index_errors = 2; repeated string platforms_index_errors = 2;
string libraries_index_error = 3; string libraries_index_error = 3;
DownloadProgress download_progress = 4;
TaskProgress task_progress = 5;
} }
message DestroyReq { Instance instance = 1; } message DestroyReq { Instance instance = 1; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment