Skip to content

Commit

Permalink
protogetter: refactor all direct proto access with getter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Nov 10, 2023
1 parent 8fa2062 commit bd0eb8c
Show file tree
Hide file tree
Showing 52 changed files with 282 additions and 282 deletions.
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/install_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (pme *Explorer) IsToolRequired(toolRelease *cores.ToolRelease) bool {

func skipEmptyMessageTaskProgressCB(taskCB rpc.TaskProgressCB) rpc.TaskProgressCB {
return func(msg *rpc.TaskProgress) {
if msg != nil && len(msg.Message) == 0 {
if msg != nil && len(msg.GetMessage()) == 0 {
return
}
taskCB(msg)
Expand Down
16 changes: 8 additions & 8 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ func PortFromRPCPort(o *rpc.Port) (p *Port) {
return nil
}
res := &Port{
Address: o.Address,
AddressLabel: o.Label,
Protocol: o.Protocol,
ProtocolLabel: o.ProtocolLabel,
HardwareID: o.HardwareId,
}
if o.Properties != nil {
res.Properties = properties.NewFromHashmap(o.Properties)
Address: o.GetAddress(),
AddressLabel: o.GetLabel(),
Protocol: o.GetProtocol(),
ProtocolLabel: o.GetProtocolLabel(),
HardwareID: o.GetHardwareId(),
}
if o.GetProperties() != nil {
res.Properties = properties.NewFromHashmap(o.GetProperties())
}
return res
}
Expand Down
8 changes: 4 additions & 4 deletions arduino/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ type NoBoardsDetectedError struct {
func (e *NoBoardsDetectedError) Error() string {
return tr(
"Please specify an FQBN. The board on port %[1]s with protocol %[2]s can't be identified",
e.Port.Address,
e.Port.Protocol,
e.Port.GetAddress(),
e.Port.GetProtocol(),
)
}

Expand All @@ -154,8 +154,8 @@ type MultipleBoardsDetectedError struct {
func (e *MultipleBoardsDetectedError) Error() string {
return tr(
"Please specify an FQBN. Multiple possible boards detected on port %[1]s with protocol %[2]s",
e.Port.Address,
e.Port.Protocol,
e.Port.GetAddress(),
e.Port.GetProtocol(),
)
}

Expand Down
20 changes: 10 additions & 10 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func createInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance {
if err != nil {
log.Fatalf("Error creating server instance: %s", err)
}
return res.Instance
return res.GetInstance()
}

func initInstance(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
Expand Down Expand Up @@ -521,8 +521,8 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance
log.Fatalf("Error getting board data: %s\n", err)
}

for _, board := range res.Boards {
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Metadata.Id)
for _, board := range res.GetBoards() {
log.Printf("Board Name: %s, Board Platform: %s\n", board.GetName(), board.GetPlatform().GetMetadata().GetId())
}
}

Expand Down Expand Up @@ -650,16 +650,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
} else if err != nil {
log.Fatalf("Board list watch error: %s\n", err)
}
if res.EventType == "error" {
log.Printf("res: %s\n", res.Error)
if res.GetEventType() == "error" {
log.Printf("res: %s\n", res.GetError())
continue
}

log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Port.Address)
if res.EventType == "add" {
log.Printf("protocol: %s, ", res.Port.Port.Protocol)
log.Printf("protocolLabel: %s, ", res.Port.Port.ProtocolLabel)
log.Printf("boards: %s\n\n", res.Port.MatchingBoards)
log.Printf("event: %s, address: %s\n", res.GetEventType(), res.GetPort().GetPort().GetAddress())
if res.GetEventType() == "add" {
log.Printf("protocol: %s, ", res.GetPort().GetPort().GetProtocol())
log.Printf("protocolLabel: %s, ", res.GetPort().GetPort().GetProtocolLabel())
log.Printf("boards: %s\n\n", res.GetPort().GetMatchingBoards())
}
}
}()
Expand Down
14 changes: 7 additions & 7 deletions commands/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
details.Version = board.PlatformRelease.Version.String()
details.IdentificationProperties = []*rpc.BoardIdentificationProperties{}
for _, p := range board.GetIdentificationProperties() {
details.IdentificationProperties = append(details.IdentificationProperties, &rpc.BoardIdentificationProperties{
details.IdentificationProperties = append(details.GetIdentificationProperties(), &rpc.BoardIdentificationProperties{
Properties: p.AsMap(),
})
}
for _, k := range boardProperties.Keys() {
v := boardProperties.Get(k)
details.BuildProperties = append(details.BuildProperties, k+"="+v)
details.BuildProperties = append(details.GetBuildProperties(), k+"="+v)
}
if !req.GetDoNotExpandBuildProperties() {
details.BuildProperties, _ = utils.ExpandBuildProperties(details.BuildProperties)
details.BuildProperties, _ = utils.ExpandBuildProperties(details.GetBuildProperties())
}

details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
Expand Down Expand Up @@ -111,10 +111,10 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
}
configValue.Value = value
configValue.ValueLabel = values.Get(value)
configOption.Values = append(configOption.Values, configValue)
configOption.Values = append(configOption.GetValues(), configValue)
}

details.ConfigOptions = append(details.ConfigOptions, configOption)
details.ConfigOptions = append(details.GetConfigOptions(), configOption)
}

details.ToolsDependencies = []*rpc.ToolsDependencies{}
Expand All @@ -132,7 +132,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
})
}
}
details.ToolsDependencies = append(details.ToolsDependencies, &rpc.ToolsDependencies{
details.ToolsDependencies = append(details.GetToolsDependencies(), &rpc.ToolsDependencies{
Name: tool.ToolName,
Packager: tool.ToolPackager,
Version: tool.ToolVersion.String(),
Expand All @@ -142,7 +142,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai

details.Programmers = []*rpc.Programmer{}
for id, p := range boardPlatformRelease.Programmers {
details.Programmers = append(details.Programmers, &rpc.Programmer{
details.Programmers = append(details.GetProgrammers(), &rpc.Programmer{
Platform: boardPlatformRelease.Name,
Id: id,
Name: p.Name,
Expand Down
8 changes: 4 additions & 4 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL

// Sort by FQBN alphabetically
sort.Slice(boards, func(i, j int) bool {
return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn)
return strings.ToLower(boards[i].GetFqbn()) < strings.ToLower(boards[j].GetFqbn())
})

// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination
sort.SliceStable(boards, func(i, j int) bool {
if boards[i].Platform.Metadata.Maintainer == "Arduino" && boards[j].Platform.Metadata.Maintainer != "Arduino" {
if boards[i].GetPlatform().GetMetadata().GetMaintainer() == "Arduino" && boards[j].GetPlatform().GetMetadata().GetMaintainer() != "Arduino" {
return true
}
return false
Expand Down Expand Up @@ -246,8 +246,8 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
}

func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool {
for _, detectedBoard := range b.MatchingBoards {
detectedFqbn, err := cores.ParseFQBN(detectedBoard.Fqbn)
for _, detectedBoard := range b.GetMatchingBoards() {
detectedFqbn, err := cores.ParseFQBN(detectedBoard.GetFqbn())
if err != nil {
continue
}
Expand Down
12 changes: 6 additions & 6 deletions commands/board/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestGetByVidPid(t *testing.T) {
res, err := apiByVidPid("0xf420", "0XF069")
require.Nil(t, err)
require.Len(t, res, 1)
require.Equal(t, "Arduino/Genuino MKR1000", res[0].Name)
require.Equal(t, "arduino:samd:mkr1000", res[0].Fqbn)
require.Equal(t, "Arduino/Genuino MKR1000", res[0].GetName())
require.Equal(t, "arduino:samd:mkr1000", res[0].GetFqbn())

// wrong vid (too long), wrong pid (not an hex value)
_, err = apiByVidPid("0xfffff", "0xDEFG")
Expand Down Expand Up @@ -156,8 +156,8 @@ func TestBoardIdentifySorting(t *testing.T) {
require.Len(t, res, 4)

// Verify expected sorting
require.Equal(t, res[0].Fqbn, "arduino:avr:assurdo")
require.Equal(t, res[1].Fqbn, "arduino:avr:nessuno")
require.Equal(t, res[2].Fqbn, "packager:platform:boardA")
require.Equal(t, res[3].Fqbn, "packager:platform:boardB")
require.Equal(t, res[0].GetFqbn(), "arduino:avr:assurdo")
require.Equal(t, res[1].GetFqbn(), "arduino:avr:nessuno")
require.Equal(t, res[2].GetFqbn(), "packager:platform:boardA")
require.Equal(t, res[3].GetFqbn(), "packager:platform:boardB")
}
2 changes: 1 addition & 1 deletion commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
continue
}

list.Boards = append(list.Boards, &rpc.BoardListItem{
list.Boards = append(list.GetBoards(), &rpc.BoardListItem{
Name: board.Name(),
Fqbn: board.FQBN(),
IsHidden: board.IsHidden(),
Expand Down
6 changes: 3 additions & 3 deletions commands/board/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
}

sort.Slice(foundBoards, func(i, j int) bool {
if foundBoards[i].Name != foundBoards[j].Name {
return foundBoards[i].Name < foundBoards[j].Name
if foundBoards[i].GetName() != foundBoards[j].GetName() {
return foundBoards[i].GetName() < foundBoards[j].GetName()
}
return foundBoards[i].Platform.Metadata.Id < foundBoards[j].Platform.Metadata.Id
return foundBoards[i].GetPlatform().GetMetadata().GetId() < foundBoards[j].GetPlatform().GetMetadata().GetId()
})

return &rpc.BoardSearchResponse{Boards: foundBoards}, nil
Expand Down
14 changes: 7 additions & 7 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
// the optionality of this property, otherwise we would have no way of knowing if the property
// was set in the request or it's just the default boolean value.
if reqExportBinaries := req.GetExportBinaries(); reqExportBinaries != nil {
exportBinaries = reqExportBinaries.Value
exportBinaries = reqExportBinaries.GetValue()
}

pme, release := instances.GetPackageManagerExplorer(req.GetInstance())
Expand Down Expand Up @@ -110,13 +110,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()

// Setup sign keys if requested
if req.KeysKeychain != "" {
if req.GetKeysKeychain() != "" {
boardBuildProperties.Set("build.keys.keychain", req.GetKeysKeychain())
}
if req.SignKey != "" {
if req.GetSignKey() != "" {
boardBuildProperties.Set("build.keys.sign_key", req.GetSignKey())
}
if req.EncryptKey != "" {
if req.GetEncryptKey() != "" {
boardBuildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey())
}
// At the current time we do not have a way of knowing if a board supports the secure boot or not,
Expand Down Expand Up @@ -197,7 +197,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
targetPlatform, actualPlatform,
req.GetSkipLibrariesDiscovery(),
libsManager,
paths.NewPathList(req.Library...),
paths.NewPathList(req.GetLibrary()...),
outStream, errStream, req.GetVerbose(), req.GetWarnings(),
progressCB,
)
Expand Down Expand Up @@ -231,10 +231,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
keys := buildProperties.Keys()
sort.Strings(keys)
for _, key := range keys {
r.BuildProperties = append(r.BuildProperties, key+"="+buildProperties.Get(key))
r.BuildProperties = append(r.GetBuildProperties(), key+"="+buildProperties.Get(key))
}
if !req.GetDoNotExpandBuildProperties() {
r.BuildProperties, _ = utils.ExpandBuildProperties(r.BuildProperties)
r.BuildProperties, _ = utils.ExpandBuildProperties(r.GetBuildProperties())
}
}()

Expand Down
4 changes: 2 additions & 2 deletions commands/core/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow
}

ref := &packagemanager.PlatformReference{
Package: req.PlatformPackage,
PlatformArchitecture: req.Architecture,
Package: req.GetPlatformPackage(),
PlatformArchitecture: req.GetArchitecture(),
PlatformVersion: version,
}
platform, tools, err := pme.FindPlatformReleaseDependencies(ref)
Expand Down
6 changes: 3 additions & 3 deletions commands/core/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
}

ref := &packagemanager.PlatformReference{
Package: req.PlatformPackage,
PlatformArchitecture: req.Architecture,
Package: req.GetPlatformPackage(),
PlatformArchitecture: req.GetArchitecture(),
PlatformVersion: version,
}
platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref)
Expand Down Expand Up @@ -74,7 +74,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl
if err := install(); err != nil {
return nil, err
}
if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil {
if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil {
return nil, err
}
return &rpc.PlatformInstallResponse{}, nil
Expand Down
12 changes: 6 additions & 6 deletions commands/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
defer release()

res := []*cores.Platform{}
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb {
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.GetSearchArgs()); isUsb {
vid, pid := req.GetSearchArgs()[:4], req.GetSearchArgs()[5:]
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
} else {
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
searchArgs := utils.SearchTermsFromQueryString(req.GetSearchArgs())
for _, targetPackage := range pme.GetPackages() {
for _, platform := range targetPackage.Platforms {
if platform == nil {
continue
}
// Users can install platforms manually in the Sketchbook hardware folder,
// if not explictily requested we skip them.
if !req.ManuallyInstalled && platform.ManuallyInstalled {
if !req.GetManuallyInstalled() && platform.ManuallyInstalled {
continue
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
}
for _, platformRelease := range platform.GetAllReleases() {
rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease)
rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease
rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease
}
out = append(out, rpcPlatformSummary)
}
Expand All @@ -104,7 +104,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
return strings.ToLower(out[i].GetMetadata().GetId()) < strings.ToLower(out[j].GetMetadata().GetId())
})
sort.SliceStable(out, func(i, j int) bool {
return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated
return !out[i].GetMetadata().GetDeprecated() && out[j].GetMetadata().GetDeprecated()
})
return &rpc.PlatformSearchResponse{SearchOutput: out}, nil
}
Loading

0 comments on commit bd0eb8c

Please sign in to comment.