Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend: improve backend api and initialization
- Loading branch information
1 parent
ca6d09a
commit 5f00f15
Showing
9 changed files
with
132 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
#include <future> | ||
|
||
#include "connection_result.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
#include "backend.h" | ||
#include "backend_api.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
dronecore::backend::DroneCoreBackend backend; | ||
|
||
if (!backend.run()) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
runBackend(14540, nullptr, nullptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "grpc_server.h" | ||
|
||
#include <grpc++/server_builder.h> | ||
#include <grpc++/security/server_credentials.h> | ||
|
||
#include "log.h" | ||
|
||
namespace dronecore { | ||
namespace backend { | ||
|
||
void GRPCServer::run() | ||
{ | ||
grpc::ServerBuilder builder; | ||
setup_port(builder); | ||
|
||
builder.RegisterService(&_core); | ||
builder.RegisterService(&_action_service); | ||
builder.RegisterService(&_mission_service); | ||
builder.RegisterService(&_telemetry_service); | ||
|
||
_server = builder.BuildAndStart(); | ||
LogInfo() << "Server started"; | ||
} | ||
|
||
void GRPCServer::wait() | ||
{ | ||
if (_server != nullptr) { | ||
_server->Wait(); | ||
} else { | ||
LogWarn() << "Calling 'wait()' on a non-existing server. Did you call 'run()' before?"; | ||
} | ||
} | ||
|
||
void GRPCServer::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <grpc++/server.h> | ||
#include <memory> | ||
|
||
#include "action/action.h" | ||
#include "action/action_service_impl.h" | ||
#include "core/core_service_impl.h" | ||
#include "dronecore.h" | ||
#include "mission/mission.h" | ||
#include "mission/mission_service_impl.h" | ||
#include "telemetry/telemetry_service_impl.h" | ||
|
||
namespace dronecore { | ||
namespace backend { | ||
|
||
class GRPCServer | ||
{ | ||
public: | ||
GRPCServer(DroneCore &dc) | ||
: _dc(dc), | ||
_core(_dc), | ||
_action(_dc.system()), | ||
_action_service(_action), | ||
_mission(_dc.system()), | ||
_mission_service(_mission), | ||
_telemetry(_dc.system()), | ||
_telemetry_service(_telemetry) | ||
{ | ||
assert(_dc.system_uuids().size() >= 1); | ||
} | ||
|
||
void run(); | ||
void wait(); | ||
|
||
private: | ||
void setup_port(grpc::ServerBuilder &builder); | ||
|
||
DroneCore &_dc; | ||
|
||
CoreServiceImpl<> _core; | ||
Action _action; | ||
ActionServiceImpl<> _action_service; | ||
Mission _mission; | ||
MissionServiceImpl<> _mission_service; | ||
Telemetry _telemetry; | ||
TelemetryServiceImpl<> _telemetry_service; | ||
|
||
std::unique_ptr<grpc::Server> _server; | ||
}; | ||
|
||
} // namespace backend | ||
} // namespace dronecore |