// 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 license@arduino.cc.

syntax = "proto3";

package cc.arduino.cli.monitor;

option go_package = "github.com/arduino/arduino-cli/rpc/monitor";

import "google/protobuf/struct.proto";

// Service that abstract a Monitor usage
service Monitor {
  // Open a bidirectional monitor stream. This can be used to implement
  // something similar to the Arduino IDE's Serial Monitor.
  rpc StreamingOpen(stream StreamingOpenReq)
      returns (stream StreamingOpenResp) {}
}

// The top-level message sent by the client for the `StreamingOpen` method.
// Multiple `StreamingOpenReq` messages can be sent but the first message
// must contain a `monitor_config` message to initialize the monitor target.
// All subsequent messages must contain bytes to be sent to the target
// and must not contain a `monitor_config` message.
message StreamingOpenReq {
  // Content must be either a monitor config or data to be sent.
  oneof content {
    // Provides information to the monitor that specifies which is the target.
    // The first `StreamingOpenReq` message must contain a `monitor_config`
    // message.
    MonitorConfig monitorConfig = 1;

    // The data to be sent to the target being monitored.
    bytes data = 2;
  }
}

// Tells the monitor which target to open and provides additional parameters
// that might be needed to configure the target or the monitor itself.
message MonitorConfig {
  enum TargetType { SERIAL = 0; }

  // The target name.
  string target = 1;
  TargetType type = 2;
  // Additional parameters that might be needed to configure the target or the
  // monitor itself.
  google.protobuf.Struct additionalConfig = 3;
}

//
message StreamingOpenResp {
    // The data received from the target.
    bytes data = 1;
}