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

238 refactor dronecore server #295

Merged
merged 4 commits into from
Mar 2, 2018
Merged

Conversation

JonasVautherin
Copy link
Collaborator

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.

MockDroneCore dc;
event_callback_t discover_callback;
EXPECT_CALL(dc, register_on_discover(_))
.WillOnce(SaveCallback(&discover_callback));
Copy link
Collaborator Author

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 -_-.

Copy link
Collaborator

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.

@JonasVautherin JonasVautherin force-pushed the 238-refactor-dronecore-server branch 2 times, most recently from d693b1d to 24ac4a2 Compare March 1, 2018 10:13
Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean!


dronecore::DroneCore _dc;
dronecore::backend::ConnectionInitiator<dronecore::DroneCore> _connection_initiator;
std::unique_ptr<grpc::Server> server;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be _server?

std::unique_ptr<grpc::Server> server;
};

} // namespace backend
Copy link
Collaborator

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));
Copy link
Collaborator

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) <<
Copy link
Collaborator

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?

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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]() {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@shakthi-prashanth-m shakthi-prashanth-m left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! No plugin list ?

Copy link
Collaborator Author

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 :-).

Copy link
Contributor

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"
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about connection URL ?

Copy link
Collaborator Author

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);
Copy link
Contributor

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;
Copy link
Contributor

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
@JonasVautherin JonasVautherin merged commit 12cedcc into develop Mar 2, 2018
@JonasVautherin JonasVautherin deleted the 238-refactor-dronecore-server branch March 2, 2018 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants