Skip to content
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

269 update core proto #346

Merged
merged 4 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backend/proto
Submodule proto updated from 0dd841 to 57ecd0
18 changes: 8 additions & 10 deletions backend/src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "action/action.h"
#include "action/action_service_impl.h"
#include "connection_initiator.h"
#include "core/corerpc_impl.h"
#include "core/core_service_impl.h"
#include "dronecore.h"
#include "log.h"
#include "mission/mission.h"
Expand All @@ -35,22 +35,20 @@ class DroneCoreBackend::Impl
grpc::ServerBuilder builder;
setup_port(builder);

CoreServiceImpl core(_dc);
CoreServiceImpl<> core(_dc);
builder.RegisterService(&core);

Action action(_dc.system());
ActionServiceImpl<dronecore::Action> actionService(action);
builder.RegisterService(&actionService);
ActionServiceImpl<> action_service(action);
builder.RegisterService(&action_service);

Mission mission(_dc.system());
MissionServiceImpl<dronecore::Mission> missionService(mission);

builder.RegisterService(&missionService);
MissionServiceImpl<> mission_service(mission);
builder.RegisterService(&mission_service);

Telemetry telemetry(_dc.system());
TelemetryServiceImpl<> telemetryService(telemetry);

builder.RegisterService(&telemetryService);
TelemetryServiceImpl<> telemetry_service(telemetry);
builder.RegisterService(&telemetry_service);

_server = builder.BuildAndStart();
LogInfo() << "Server started";
Expand Down
75 changes: 75 additions & 0 deletions backend/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <future>
#include <string>

#include "core/core.grpc.pb.h"
#include "dronecore.h"

namespace dronecore {
namespace backend {

template <typename DroneCore = DroneCore>
class CoreServiceImpl final: public dronecore::rpc::core::CoreService::Service
{
public:
CoreServiceImpl(DroneCore &dc)
: _dc(dc),
_stop_promise(std::promise<void>()),
_stop_future(_stop_promise.get_future()) {}

grpc::Status SubscribeDiscover(grpc::ServerContext * /* context */,
const rpc::core::SubscribeDiscoverRequest * /* request */,
grpc::ServerWriter<rpc::core::DiscoverResponse> *writer) override
{
_dc.register_on_discover([&writer](const uint64_t uuid) {
dronecore::rpc::core::DiscoverResponse rpc_discover_response;
rpc_discover_response.set_uuid(uuid);
writer->Write(rpc_discover_response);
});

_stop_future.wait();
return grpc::Status::OK;
}

grpc::Status SubscribeTimeout(grpc::ServerContext * /* context */,
const rpc::core::SubscribeTimeoutRequest * /* request */,
grpc::ServerWriter<rpc::core::TimeoutResponse> *writer) override
{
_dc.register_on_timeout([&writer](const uint64_t /* uuid */) {
dronecore::rpc::core::TimeoutResponse rpc_timeout_response;
writer->Write(rpc_timeout_response);
});

_stop_future.wait();
return grpc::Status::OK;
}

// For now, the running plugins are hardcoded and we assume they are always started by the backend.
grpc::Status ListRunningPlugins(grpc::ServerContext * /* context */,
const rpc::core::ListRunningPluginsRequest * /* request */,
dronecore::rpc::core::ListRunningPluginsResponse *response) override
{
std::string plugin_names[3] = { "action", "mission", "telemetry" };

for (const auto plugin_name : plugin_names) {
auto plugin_info = response->add_plugin_info();
plugin_info->set_name(plugin_name);
plugin_info->set_address("localhost");
plugin_info->set_port(50051);
}

return grpc::Status::OK;
}

void stop()
{
_stop_promise.set_value();
}

private:
DroneCore &_dc;
std::promise<void> _stop_promise;
std::future<void> _stop_future;
};

} // namespace backend
} // namespace dronecore
37 changes: 0 additions & 37 deletions backend/src/core/corerpc_impl.h

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/plugins/action/action_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace dronecore {
namespace backend {

template <typename Action>
template <typename Action = Action>
class ActionServiceImpl final : public dronecore::rpc::action::ActionService::Service
{
public:
Expand Down
3 changes: 2 additions & 1 deletion backend/src/plugins/mission/mission_service_impl.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <future>

#include "mission/mission.h"
#include "mission/mission.grpc.pb.h"

namespace dronecore {
namespace backend {

template <typename Mission>
template <typename Mission = Mission>
class MissionServiceImpl final : public dronecore::rpc::mission::MissionService::Service
{
public:
Expand Down
2 changes: 2 additions & 0 deletions backend/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.1)
add_executable(unit_tests_backend
action_service_impl_test.cpp
connection_initiator_test.cpp
core_service_impl_test.cpp
mission_service_impl_test.cpp
telemetry_service_impl_test.cpp
)
Expand All @@ -15,6 +16,7 @@ target_include_directories(unit_tests_backend
${CMAKE_CURRENT_SOURCE_DIR}/../src/plugins
${CMAKE_SOURCE_DIR}/plugins
${CMAKE_BINARY_DIR}/backend/src
${CMAKE_SOURCE_DIR}
)

target_link_libraries(unit_tests_backend
Expand Down
Loading