Skip to content

[breaking] Refactor initialization steps #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 16, 2021
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5ad5bdb
[breaking] Split rpc Init and remove Rescan function
silvanocerza May 7, 2021
dbad881
[breaking] Refactored commands package to reflect gRPC changes
silvanocerza Jun 7, 2021
1e8764f
[breaking] Refactored cli package to reflect commands changes
silvanocerza Apr 23, 2021
93655a4
Fix instance creation for CLI commands that update indexes
silvanocerza Apr 23, 2021
9adeb3f
Fix unit tests
silvanocerza Apr 23, 2021
2079c0c
Change update indexes commands to not reload instance after
silvanocerza Jun 7, 2021
ced6b48
Fix installation of builtin tools
silvanocerza Apr 23, 2021
a9141cf
Fix integration tests
silvanocerza Apr 23, 2021
58821fd
Fix code for linting
silvanocerza Apr 23, 2021
61b40d2
Update i18n files
silvanocerza Apr 26, 2021
e0b20df
Update UPGRADING.md with breaking changes
silvanocerza Jun 7, 2021
29aacd4
Update comment with correct information
silvanocerza Apr 27, 2021
f4391fd
Using callback instead of channel+goroutine for Init
cmaglie Apr 27, 2021
0c0f8a5
Enhance platform loading step
silvanocerza Apr 27, 2021
410ecd7
Update client_example to reflect new gRPC changes
silvanocerza Apr 27, 2021
2e44c3b
Enhance Init docstring
silvanocerza Apr 29, 2021
1193930
Enhance builtin tools installation during Init
silvanocerza Apr 29, 2021
68871fc
Fix unit test
silvanocerza May 11, 2021
7b035d1
Fix integration tests
silvanocerza May 11, 2021
30280c2
[skip changelog] Fix after botched rebase
silvanocerza Jun 7, 2021
d6ed084
Fix issue when using Init to rescan installed core on already initial…
silvanocerza Jun 15, 2021
bee0970
Update generated file from .proto
silvanocerza Jun 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update client_example to reflect new gRPC changes
  • Loading branch information
silvanocerza committed Jun 16, 2021
commit 410ecd70ded2db59b31d2cfddcad73f974797df1
60 changes: 36 additions & 24 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ func main() {
// Before we can do anything with the CLI, an "instance" must be created.
// We keep a reference to the created instance because we will need it to
// run subsequent commands.
log.Println("calling Create")
instance := createInstance(client)

log.Println("calling Init")
instance := initInstance(client)
initInstance(client, instance)

// We set up the proxy and then run the update to verify that the proxy settings are currently used
log.Println("calling setProxy")
Expand All @@ -129,6 +132,11 @@ func main() {
log.Println("calling UpdateIndex")
callUpdateIndex(client, instance)

// Indexes are not implicitly detected after an update
// so we must initialize again explicitly
log.Println("calling Init")
initInstance(client, instance)

// Let's search for a platform (also known as 'core') called 'samd'.
log.Println("calling PlatformSearch(samd)")
callPlatformSearch(client, instance)
Expand Down Expand Up @@ -198,6 +206,11 @@ func main() {
log.Println("calling UpdateLibrariesIndex()")
callUpdateLibraryIndex(client, instance)

// Indexes are not implicitly detected after an update
// so we must initialize again explicitly
log.Println("calling Init")
initInstance(client, instance)

// Download a library
log.Println("calling LibraryDownload([email protected])")
callLibDownload(client, instance)
Expand Down Expand Up @@ -326,47 +339,46 @@ func callWrite(client settings.SettingsServiceClient) {
}
}

func initInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance {
// The configuration for this example client only contains the path to
// the data folder.
initRespStream, err := client.Init(context.Background(), &rpc.InitRequest{})
func createInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance {
res, err := client.Create(context.Background(), &rpc.CreateRequest{})
if err != nil {
log.Fatalf("Error creating server instance: %s", err)
}
return res.Instance
}

func initInstance(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
stream, err := client.Init(context.Background(), &rpc.InitRequest{
Instance: instance,
})
if err != nil {
log.Fatalf("Error initializing server instance: %s", err)
}

var instance *rpc.Instance
// Loop and consume the server stream until all the setup procedures are done.
for {
initResp, err := initRespStream.Recv()
// The server is done.
res, err := stream.Recv()
// Server has finished sending
if err == io.EOF {
break
}

// There was an error.
if err != nil {
log.Fatalf("Init error: %s", err)
}

// The server sent us a valid instance, let's print its ID.
if initResp.GetInstance() != nil {
instance = initResp.GetInstance()
log.Printf("Got a new instance with ID: %v", instance.GetId())
}

// When a download is ongoing, log the progress
if initResp.GetDownloadProgress() != nil {
log.Printf("DOWNLOAD: %s", initResp.GetDownloadProgress())
if status := res.GetError(); status != nil {
log.Printf("Init error %s", status.String())
}

// When an overall task is ongoing, log the progress
if initResp.GetTaskProgress() != nil {
log.Printf("TASK: %s", initResp.GetTaskProgress())
if progress := res.GetInitProgress(); progress != nil {
if downloadProgress := progress.GetDownloadProgress(); downloadProgress != nil {
log.Printf("DOWNLOAD: %s", downloadProgress)
}
if taskProgress := progress.GetTaskProgress(); taskProgress != nil {
log.Printf("TASK: %s", taskProgress)
}
}
}

return instance
}

func callUpdateIndex(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
Expand Down