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

Refactor dronecore server #266

Closed
wants to merge 4 commits into from

Conversation

JonasVautherin
Copy link
Collaborator

  • some cleanup on the proto generation (build_system)
  • use references and smart pointers instead of old-style pointers
  • make a library out of dronecore_server (necessary for running from iOS)
  • rename dronecore_server into backend

A PR actually updating the proto files will come just after this one is merged.

Connects to #238.

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

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

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?

Copy link
Collaborator Author

@JonasVautherin JonasVautherin Feb 15, 2018

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

Copy link
Collaborator

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.

{
LogInfo() << "Waiting to discover device...";
auto discoveryFuture = wrapped_register_on_discover();
discoveryFuture.wait();
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@@ -70,12 +36,16 @@ target_include_directories(
${PLUGINS_DIR}
)

target_link_libraries(
dronecore_server
add_executable(backend_bin
Copy link
Contributor

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 ?

Copy link
Collaborator Author

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?

Copy link
Contributor

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.


namespace dronecore::backend {

int DroneCoreBackend::run(const int mavlink_listen_port)
Copy link
Contributor

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.

Copy link
Collaborator Author

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

}

log_uuid_on_timeout();
wait_for_discovery();
Copy link
Contributor

Choose a reason for hiding this comment

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

return value omitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch :-).

Copy link
Contributor

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.

return 0;
}

int DroneCoreBackend::connect_to_vehicle(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.

Why not boolean as return value ?

Copy link
Collaborator Author

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

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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,
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 name it as UploadMission() (or just Upload() as its mission upload indeed, because we call as mission.upload(...)) ? Makes sense ?

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 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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

* Required for some platforms (e.g. iOS)
* Rename dronecore_server into libdronecore_backend and backend_bin
* Use smart pointers and references instead of pointers
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.

Feel free to merge when that's done.

@JonasVautherin
Copy link
Collaborator Author

Yes sorry, I got stuck on the iOS build. I'm working on this right now.

@JonasVautherin
Copy link
Collaborator Author

Coming back with some unit tests soon.

@JonasVautherin JonasVautherin deleted the 238-refactor-dronecore-server branch February 27, 2018 11:14
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