-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
238 refactor dronecore server #295
Changes from all commits
dcccd07
8f7b9ec
6e5b783
8139246
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <gmock/gmock.h> | ||
|
||
#include "connection_result.h" | ||
|
||
namespace dronecore { | ||
namespace testing { | ||
|
||
typedef std::function<void(uint64_t uuid)> event_callback_t; | ||
|
||
class MockDroneCore | ||
{ | ||
public: | ||
MOCK_CONST_METHOD1(add_udp_connection, ConnectionResult(int local_port_number)); | ||
MOCK_CONST_METHOD1(register_on_discover, void(event_callback_t)); | ||
MOCK_CONST_METHOD1(register_on_timeout, void(event_callback_t)); | ||
}; | ||
|
||
} // testing | ||
} // dronecore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "backend.h" | ||
|
||
#include <grpc/grpc.h> | ||
#include <grpc++/server.h> | ||
#include <grpc++/server_builder.h> | ||
#include <grpc++/server_context.h> | ||
#include <grpc++/security/server_credentials.h> | ||
|
||
#include "action/actionrpc_impl.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So ideally, backend shall include all plugin header files as it doesn't know what a user wants. Is that right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, plugins are somehow loaded dynamically. But the first version is hard-coded because it is faster to do xD. |
||
#include "core/corerpc_impl.h" | ||
#include "log.h" | ||
#include "mission/missionrpc_impl.h" | ||
#include "telemetry/telemetryrpc_impl.h" | ||
|
||
namespace dronecore { | ||
namespace backend { | ||
|
||
bool DroneCoreBackend::run(const int mavlink_listen_port) | ||
{ | ||
_connection_initiator.start(_dc, 14540); | ||
_connection_initiator.wait(); | ||
|
||
grpc::ServerBuilder builder; | ||
setup_port(builder); | ||
|
||
CoreServiceImpl core(_dc); | ||
builder.RegisterService(&core); | ||
|
||
Action action(&_dc.device()); | ||
ActionServiceImpl actionService(action); | ||
builder.RegisterService(&actionService); | ||
|
||
Mission mission(&_dc.device()); | ||
MissionServiceImpl missionService(mission); | ||
builder.RegisterService(&missionService); | ||
|
||
Telemetry telemetry(&_dc.device()); | ||
TelemetryServiceImpl telemetryService(telemetry); | ||
builder.RegisterService(&telemetryService); | ||
|
||
_server = builder.BuildAndStart(); | ||
LogInfo() << "Server started"; | ||
_server->Wait(); | ||
|
||
return true; | ||
} | ||
|
||
void DroneCoreBackend::setup_port(grpc::ServerBuilder &builder) | ||
{ | ||
std::string server_address("0.0.0.0:50051"); | ||
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); | ||
LogInfo() << "Server set to listen on " << server_address; | ||
} | ||
|
||
} // namespace backend | ||
} //namespace dronecore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <grpc++/server.h> | ||
#include <memory> | ||
#include <mutex> | ||
|
||
#include "connection_initiator.h" | ||
#include "dronecore.h" | ||
|
||
namespace dronecore { | ||
namespace backend { | ||
|
||
class DroneCoreBackend | ||
{ | ||
public: | ||
DroneCoreBackend() {} | ||
~DroneCoreBackend() {} | ||
|
||
bool run(const int mavlink_listen_port = 14540); | ||
|
||
private: | ||
bool run_server(); | ||
void setup_port(grpc::ServerBuilder &builder); | ||
|
||
dronecore::DroneCore _dc; | ||
dronecore::backend::ConnectionInitiator<dronecore::DroneCore> _connection_initiator; | ||
std::unique_ptr<grpc::Server> _server; | ||
}; | ||
|
||
} // namespace backend | ||
} // namespace dronecore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
set(PROTOC_BINARY ${CMAKE_BINARY_DIR}/../default/third_party/protobuf/bin/protoc) | ||
set(GRPC_CPP_PLUGIN_BINARY ${CMAKE_BINARY_DIR}/../default/third_party/grpc/bin/grpc_cpp_plugin) | ||
|
||
if(NOT EXISTS ${PROTOC_BINARY} OR NOT EXISTS ${GRPC_CPP_PLUGIN_BINARY}) | ||
message(FATAL_ERROR "Could not find 'protoc' or 'grpc_cpp_plugin' in the 'default' build folder. Please build for your host first (`make BUILD_DRONECORESERVER=YES default`).") | ||
endif() | ||
|
||
function(compile_proto_pb COMPONENT_NAME PB_COMPILED_SOURCE) | ||
add_custom_command(OUTPUT ${COMPONENT_NAME}/${COMPONENT_NAME}.pb.cc | ||
COMMAND ${PROTOC_BINARY} | ||
-I ${PROTO_DIR} | ||
--cpp_out=. | ||
${PROTO_DIR}/${COMPONENT_NAME}/${COMPONENT_NAME}.proto | ||
) | ||
|
||
set(PB_COMPILED_SOURCE ${COMPONENT_NAME}/${COMPONENT_NAME}.pb.cc PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(compile_proto_grpc COMPONENT_NAME GRPC_COMPILED_SOURCES) | ||
add_custom_command(OUTPUT ${COMPONENT_NAME}/${COMPONENT_NAME}.grpc.pb.cc | ||
COMMAND ${PROTOC_BINARY} | ||
-I ${PROTO_DIR} | ||
--grpc_out=. | ||
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN_BINARY} | ||
--cpp_out=. | ||
${PROTO_DIR}/${COMPONENT_NAME}/${COMPONENT_NAME}.proto | ||
) | ||
|
||
set(GRPC_COMPILED_SOURCE ${COMPONENT_NAME}/${COMPONENT_NAME}.grpc.pb.cc PARENT_SCOPE) | ||
endfunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! No plugin list ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, it is hard-coded. We need to deliver a first version soon. So our first version will not really support plugins (i.e. the backend has all our plugins). Later, we'll upgrade for a more dynamic architecture.
Still, the frontend now should look like the plugins are loaded dynamically, so that it is transparent to the user when we update the backend :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK :-)