Skip to content

Commit

Permalink
Automate generation of dronecore_server executable
Browse files Browse the repository at this point in the history
Create a list of generated source files for all the plugins
  • Loading branch information
Rjasuja committed Nov 8, 2017
1 parent 8b20aa7 commit 110df51
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 53 deletions.
18 changes: 7 additions & 11 deletions grpc/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ foreach(plugin ${plugins_list})
)
endforeach()

add_executable(dronecore_server
dronecore_server.cpp
dronecore.pb.cc # generated
dronecore.grpc.pb.cc # generated
action.pb.cc # generated
action.grpc.pb.cc # generated
mission.pb.cc # generated
mission.grpc.pb.cc # generated
telemetry.pb.cc # generated
telemetry.grpc.pb.cc # generated
)
set(plugins_src dronecore_server.cpp dronecore.pb.cc dronecore.grpc.pb.cc)
foreach(plugin ${plugins_list})
list(APPEND plugins_src ${plugin}.pb.cc)
list(APPEND plugins_src ${plugin}.grpc.pb.cc)
endforeach(plugin)

add_executable(dronecore_server ${plugins_src})

target_link_libraries(dronecore_server
dronecore
Expand Down
5 changes: 2 additions & 3 deletions grpc/server/dronecore_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ using grpc::ServerContext;
using grpc::ServerReader;
using grpc::ServerReaderWriter;
using grpc::Status;
using dronecorerpc::Empty;
using dronecorerpc::DroneCoreRPC;

using namespace dronecore;
using namespace std::placeholders;

static DroneCore dc;

template<typename T> ::grpc::Service *createInstances(DroneCore* dc_obj) {return new T(dc_obj);}
template<typename T> ::grpc::Service *createInstances(DroneCore *dc_obj) {return new T(dc_obj);}

typedef std::map<std::string, ::grpc::Service*(*)(DroneCore* dc_obj)> map_type;
typedef std::map<std::string, ::grpc::Service*(*)(DroneCore *dc_obj)> map_type;

class DroneCoreRPCImpl final : public DroneCoreRPC::Service
{
Expand Down
11 changes: 5 additions & 6 deletions grpc/server/plugins/action/action.proto
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

package dronecorerpc;

service ActionRPC {
rpc Arm(ActionEmpty) returns(ActionResult) {}
rpc TakeOff(ActionEmpty) returns(ActionResult) {}
rpc Land(ActionEmpty) returns(ActionResult) {}
rpc Arm(google.protobuf.Empty) returns(ActionResult) {}
rpc TakeOff(google.protobuf.Empty) returns(ActionResult) {}
rpc Land(google.protobuf.Empty) returns(ActionResult) {}
}

// FIXME these different Empty types are ugly
message ActionEmpty {}

message ActionResult {

enum Result {
Expand Down
21 changes: 11 additions & 10 deletions grpc/server/plugins/action/actionrpc_impl.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include "action.h"
#include "action.grpc.pb.h"
#include <google/protobuf/empty.pb.h>

using grpc::Status;
using grpc::ServerContext;
using dronecorerpc::ActionRPC;
using dronecorerpc::ActionEmpty;
using dronecorerpc::Empty;

using namespace dronecore;

class ActionRPCImpl final : public ActionRPC::Service
{
public:
ActionRPCImpl(DroneCore* dc_obj)
{
dc = dc_obj;
}
Status Arm(ServerContext *context, const ActionEmpty *request,
ActionRPCImpl(DroneCore *dc_obj)
{
dc = dc_obj;
}

Status Arm(ServerContext *context, const ::google::protobuf::Empty *request,
dronecorerpc::ActionResult *response) override
{
const Action::Result action_result = dc->device().action().arm();
Expand All @@ -25,7 +26,7 @@ class ActionRPCImpl final : public ActionRPC::Service
return Status::OK;
}

Status TakeOff(ServerContext *context, const ActionEmpty *request,
Status TakeOff(ServerContext *context, const ::google::protobuf::Empty *request,
dronecorerpc::ActionResult *response) override
{
const Action::Result action_result = dc->device().action().takeoff();
Expand All @@ -34,7 +35,7 @@ class ActionRPCImpl final : public ActionRPC::Service
return Status::OK;
}

Status Land(ServerContext *context, const ActionEmpty *request,
Status Land(ServerContext *context, const ::google::protobuf::Empty *request,
dronecorerpc::ActionResult *response) override
{
const Action::Result action_result = dc->device().action().land();
Expand All @@ -44,5 +45,5 @@ class ActionRPCImpl final : public ActionRPC::Service
}

private:
DroneCore* dc;
DroneCore *dc;
};
6 changes: 3 additions & 3 deletions grpc/server/plugins/mission/mission.proto
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

package dronecorerpc;

service MissionRPC {
rpc SendMission(Mission) returns(MissionResult) {}
rpc StartMission(MissionEmpty) returns(MissionResult) {}
rpc StartMission(google.protobuf.Empty) returns(MissionResult) {}
}

message MissionEmpty {}

message MissionResult {

enum Result {
Expand Down
18 changes: 9 additions & 9 deletions grpc/server/plugins/mission/missionrpc_impl.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include "mission.h"
#include "mission.grpc.pb.h"
#include <google/protobuf/empty.pb.h>

using grpc::Status;
using grpc::ServerContext;
using dronecorerpc::MissionEmpty;
using dronecorerpc::MissionRPC;

using namespace dronecore;

class MissionRPCImpl final : public MissionRPC::Service
{
public:
MissionRPCImpl(DroneCore* dc_obj)
{
dc = dc_obj;
}
MissionRPCImpl(DroneCore *dc_obj)
{
dc = dc_obj;
}

Status SendMission(ServerContext *context, const dronecorerpc::Mission *mission,
dronecorerpc::MissionResult *response) override
{
Expand Down Expand Up @@ -50,9 +50,9 @@ class MissionRPCImpl final : public MissionRPC::Service
return Status::OK;
}

Status StartMission(ServerContext *context, const MissionEmpty *request,
Status StartMission(ServerContext *context, const ::google::protobuf::Empty *request,
dronecorerpc::MissionResult *response) override
{
{
// TODO: there has to be a beter way than using std::future.
auto prom = std::make_shared<std::promise<void>>();
auto future_result = prom->get_future();
Expand All @@ -71,5 +71,5 @@ class MissionRPCImpl final : public MissionRPC::Service
}

private:
DroneCore* dc;
DroneCore *dc;
};
6 changes: 3 additions & 3 deletions grpc/server/plugins/telemetry/telemetry.proto
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
syntax = "proto3";

import "google/protobuf/empty.proto";

package dronecorerpc;

service TelemetryRPC {
rpc TelemetryPositionSubscription(TelemetryEmpty) returns(stream TelemetryPosition) {}
rpc TelemetryPositionSubscription(google.protobuf.Empty) returns(stream TelemetryPosition) {}
}

message TelemetryEmpty {}

message TelemetryPosition {
double latitude_deg = 1;
double longitude_deg = 2;
Expand Down
16 changes: 8 additions & 8 deletions grpc/server/plugins/telemetry/telemetryrpc_impl.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "telemetry.h"
#include "telemetry.grpc.pb.h"
#include <google/protobuf/empty.pb.h>

using grpc::Status;
using grpc::ServerContext;
using dronecorerpc::TelemetryEmpty;
using dronecorerpc::TelemetryRPC;
using grpc::ServerWriter;

Expand All @@ -12,12 +12,12 @@ using namespace dronecore;
class TelemetryRPCImpl final : public TelemetryRPC::Service
{
public:
TelemetryRPCImpl(DroneCore* dc_obj)
{
dc = dc_obj;
}
TelemetryRPCImpl(DroneCore *dc_obj)
{
dc = dc_obj;
}

Status TelemetryPositionSubscription(ServerContext *context, const TelemetryEmpty *request,
Status TelemetryPositionSubscription(ServerContext *context, const ::google::protobuf::Empty *request,
ServerWriter<dronecorerpc::TelemetryPosition> *writer) override
{
dc->device().telemetry().position_async([&writer](Telemetry::Position position) {
Expand All @@ -35,6 +35,6 @@ class TelemetryRPCImpl final : public TelemetryRPC::Service
return Status::OK;
}

private:
DroneCore* dc;
private:
DroneCore *dc;
};

0 comments on commit 110df51

Please sign in to comment.