Skip to content

Commit

Permalink
arduino#1447 - back-end usage scenario
Browse files Browse the repository at this point in the history
Add `FilesService` impl.
  • Loading branch information
4ntoine committed Nov 4, 2021
1 parent b9bebad commit 9f90e2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
srv_debug "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
srv_monitor "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/monitor/v1"
srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
srv_files "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1"
"github.com/segmentio/stats/v4"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -98,6 +99,9 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
// Register the debug session service
srv_debug.RegisterDebugServiceServer(s, &daemon.DebugService{})

// Register the files service
srv_files.RegisterFilesServiceServer(s, &daemon.FilesService{})

if !daemonize {
// When parent process ends terminate also the daemon
go func() {
Expand Down
41 changes: 41 additions & 0 deletions commands/daemon/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package daemon

import (
"context"
"os"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1"
)

// FilesService implements the `Files` service
type FilesService struct {
rpc.UnimplementedFilesServiceServer
}

// LoadFile returns a requested file content or an error.
func (s *FilesService) LoadFile(ctx context.Context, req *rpc.LoadFileRequest) (*rpc.LoadFileResponse, error) {
content, err := os.ReadFile(req.Path)
if err == nil {
return &rpc.LoadFileResponse{
Content: content,
Type: rpc.ContentType_CONTENT_TYPE_RAW_UNSPECIFIED,
}, nil
}

return nil, err
}

0 comments on commit 9f90e2e

Please sign in to comment.