-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Refactor dronecore server #266
Conversation
@@ -384,7 +384,7 @@ void Device::set_disconnected() | |||
_parent->notify_on_timeout(_target_uuid); | |||
|
|||
// Let's reset the flag hope again for the next time we see this target. | |||
_target_uuid_initialized = 0; | |||
_target_uuid_initialized = false; |
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.
Better.
LogInfo() << "Device discovered [UUID: " << discoveryFuture.get() << "]"; | ||
} | ||
|
||
std::future<uint64_t> DroneCoreBackend::wrapped_register_on_discover() |
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.
I think we should either go for snake_case
or camelCase
, or is the mix intentional?
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.
No it's not, sorry. Good catch. dronecore_server
was using camelCase, so I continued with that, but dronecore is using snake_case... so maybe it's the occasion to make it more consistent and go back to snake_case. I don't mind, as long as we are consistent (which I wasn't here :D).
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.
Same, I don't care either one as long as it's consistent. The rest of the API is snake_case
, so presumably continue with that.
grpc/server/src/backend.cpp
Outdated
{ | ||
LogInfo() << "Waiting to discover device..."; | ||
auto discoveryFuture = wrapped_register_on_discover(); | ||
discoveryFuture.wait(); |
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.
The problem here is that std::promise
in C++11 does not support triggering the callback multiple times. Therefore, this will crash when the vehicle is discovered a second time.
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.
That's one of those cases where I wish we had streams :D.
I thought it was not called the second time, as the device
stays the same. I'll see what I can do here. But it sounds like a mutex and it's more complicated than what I would like to have :).
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.
boost::fibers
would support something like that as well.
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.
But since we don't depend on boost yet, I'm happy to try to avoid it unless necessary :D. I'm not sure I want to build it for Android/iOS...
5e17e66
to
721a9a8
Compare
@@ -70,12 +36,16 @@ target_include_directories( | |||
${PLUGINS_DIR} | |||
) | |||
|
|||
target_link_libraries( | |||
dronecore_server | |||
add_executable(backend_bin |
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.
How about renaming it as backend_server
?
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.
But then should the library be called libdronecore_backend_server
? I assumed that "backend" was enough, as a "grpc backend" is necessarily a server somehow :D.
What do you think?
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.
If "backend" is the name used in practice, I am fine with it.
grpc/server/src/backend.cpp
Outdated
|
||
namespace dronecore::backend { | ||
|
||
int DroneCoreBackend::run(const int mavlink_listen_port) |
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.
const
doesn't serve purpose here, right ? Its call by value.
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.
Doesn't hurt either :-). It says that mavlink_listen_port
is not modified in run
. Not much, but it's also about the principle: I try to make const
everything I can :-).
grpc/server/src/backend.cpp
Outdated
} | ||
|
||
log_uuid_on_timeout(); | ||
wait_for_discovery(); |
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.
return value omitted.
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.
Good catch :-).
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! I said that you have omitted returning an int
value from this function.
grpc/server/src/backend.cpp
Outdated
return 0; | ||
} | ||
|
||
int DroneCoreBackend::connect_to_vehicle(const int port) |
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.
Why not boolean as return value ?
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.
Yeah, you're right.
response->set_result(static_cast<rpc::action::ActionResult::Result>(action_result)); | ||
response->set_result_str(Action::result_str(action_result)); | ||
return Status::OK; | ||
} | ||
|
||
private: | ||
DroneCore *dc; | ||
std::shared_ptr<Action> action; | ||
const Action &action; |
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.
If its const
, then how does action.arm()
can work ? IMO, const
is used when you do read-only. Operations that change the state (such as arm, takeoff, etc) can't be const
. Please correct me if I am wrong.
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.
The Action
object doesn't have state. It just passes the message further. By having it const
, it makes it clear. Mission
has some internal state and, therefore, isn't const.
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.
I see.
mission = std::make_shared<Mission>(&dc->device()); | ||
} | ||
MissionServiceImpl(Mission &mission) | ||
: mission(mission) {} | ||
|
||
Status SendMission(ServerContext *context, const rpc::mission::SendMissionRequest *request, |
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.
Can we name it as UploadMission()
(or just Upload()
as its mission upload indeed, because we call as mission.upload(...)
) ? Makes sense ?
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.
I don't have a strong opinion on it, but note that this implies changing the proto files, and very soon we won't be able to change the proto files anymore as it will break the API for all the modules.
This said, I had put SendMission
instead of UploadMission
because I remember having had weird discussion with users who were assuming that "upload" is over the internet, and hence you "upload the mission to some website" :D. But maybe that's not relevant here.
@julianoes do you have an opinion on the naming?
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.
Hm, when it is SendMission
what's the other direction? ReceiveMission
, RequestMission
?
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.
Actually, I am completely wrong. It is already UploadMission. It's just not in the scope of this PR :-). Sorry about that :-).
721a9a8
to
252f49e
Compare
* Required for some platforms (e.g. iOS) * Rename dronecore_server into libdronecore_backend and backend_bin * Use smart pointers and references instead of pointers
252f49e
to
bf048bb
Compare
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.
Feel free to merge when that's done.
Yes sorry, I got stuck on the iOS build. I'm working on this right now. |
Coming back with some unit tests soon. |
dronecore_server
(necessary for running from iOS)dronecore_server
intobackend
A PR actually updating the proto files will come just after this one is merged.
Connects to #238.