-
-
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
Conversation
MockDroneCore dc; | ||
event_callback_t discover_callback; | ||
EXPECT_CALL(dc, register_on_discover(_)) | ||
.WillOnce(SaveCallback(&discover_callback)); |
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.
This should be indented, but I can't seem to find how to do this with astyle -_-.
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.
Yer that's weird about astyle. I guess at some point we should try to out the clang tooling to enforce style.
d693b1d
to
24ac4a2
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.
Looks clean!
grpc/server/src/backend.h
Outdated
|
||
dronecore::DroneCore _dc; | ||
dronecore::backend::ConnectionInitiator<dronecore::DroneCore> _connection_initiator; | ||
std::unique_ptr<grpc::Server> 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.
Should it be _server
?
grpc/server/src/backend.h
Outdated
std::unique_ptr<grpc::Server> server; | ||
}; | ||
|
||
} // namespace 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.
I like the namespacing.
MockDroneCore dc; | ||
event_callback_t discover_callback; | ||
EXPECT_CALL(dc, register_on_discover(_)) | ||
.WillOnce(SaveCallback(&discover_callback)); |
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.
Yer that's weird about astyle. I guess at some point we should try to out the clang tooling to enforce style.
initiator.wait(); | ||
}); | ||
|
||
EXPECT_TRUE(async_future.wait_for(std::chrono::milliseconds(100)) == std::future_status::timeout) << |
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 usually use fake time for unit tests. Have you seen that?
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, I've seen a FAKE_TIME
, but immediately forgot about it. I'll have a look!
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 am not sure how I should use it here, actually. In call_every_handler_test.cpp
, I see the benefit of the fake time because the object under test is using the fake time as well. But here, I don't know how I can make my initiator.wait()
use the fake time?
I am a bit confused, maybe that's because I am not used to FakeTime
^^. How would you do it?
LogInfo() << "Waiting to discover device..."; | ||
|
||
dc.register_on_discover([this](uint64_t uuid) { | ||
std::call_once(_discovery_flag, [this, uuid]() { |
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.
Does this mean that it is only called once? So it is not called anymore after a timeout and then 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.
I think it doesn't matter here, as I only want to initiate the connection? And the dronecore
plugin (or telemetry? I don't remember) is the one sending the state to the client.
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.
And actually as soon as the first connection is established, the dronecore
plugin will probably overwrite the register_on_discover
callback since, for now, there is only one callback saved at a time.
24ac4a2
to
2ac2e5c
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.
I added few minor questions.
|
||
file(STRINGS ${PLUGINS_DIR}/plugins.conf PLUGINS_LIST) | ||
set(COMPONENTS_LIST core action mission telemetry) |
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 :-)
#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 comment
The 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 comment
The 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.
ConnectionInitiator() {} | ||
~ConnectionInitiator() {} | ||
|
||
bool start(DroneCore &dc, 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.
What about connection URL ?
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.
Some further enhancement as well :-). Shouldn't be difficult to add, but not part of the "minimum viable product".
EXPECT_CALL(dc, register_on_discover(_)) | ||
.Times(1); | ||
|
||
initiator.start(dc, ARBITRARY_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.
Can we also add one that initiates via connection URL ?
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.
Its good that you switched to references. :)
* Required for some platforms (e.g. iOS) * Rename dronecore_server into libdronecore_backend and backend_bin * Use smart pointers and references instead of pointers
2ac2e5c
to
8139246
Compare
Refactor dronecore_server in order to have it build as a library (for iOS) and to have the connection unit tested (saved me from a few bugs like having the discover callback called multiple times or me calling
register_on_discover
multiple times.Connects to #238.