Skip to content

Commit

Permalink
Docking command returns bool to determine whether it has been recognized
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Nov 16, 2021
1 parent 3c31a01 commit e58cc91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
10 changes: 7 additions & 3 deletions free_fleet/include/free_fleet/client/CommandHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ class CommandHandle
/// Have the robot resume following its command before it was stopped.
virtual void resume(RequestCompleted resumed_callback) = 0;

/// Have the robot begin a pre-defined docking procedure. Implement this
/// function as a no-op if your robots do not perform docking procedures.
/// Have the robot begin a pre-defined docking procedure. If the robot has no
/// docking capabilities, implement this by simply triggering
/// docking_finished_callback immediately.
///
/// \param[in] dock_name
/// The predefined name of the docking procedure to use.
///
/// \param[in] docking_finished_callback
/// Trigger this callback when the docking is finished.
virtual void dock(
///
/// \return True if the docking command and dock_name is recognized, false
/// otherwise.
virtual bool dock(
const std::string& dock_name,
RequestCompleted docking_finished_callback) = 0;

Expand Down
18 changes: 12 additions & 6 deletions free_fleet/src/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ void Client::Implementation::DataHandle::handle_dock_request(
{
if (!is_valid_request(request))
return;

if (!command_handle->dock(
request.dock_name(),
[d = shared_from_this()]()
{
d->complete_command();
}))
{
fferr << "Dock request unrecognized by client.\n";
return;
}

command_id = request.command_id();
command_ids.insert(command_id.value());
command_handle->dock(
request.dock_name(),
[d = shared_from_this()]()
{
d->complete_command();
});
}

//==============================================================================
Expand Down
6 changes: 4 additions & 2 deletions free_fleet/test/unit/mock_CommandHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class MockCommandHandle : public client::CommandHandle
void resume(RequestCompleted) final
{}

void dock(
bool dock(
const std::string&,
RequestCompleted) final
{}
{
return true;
}

};

Expand Down

0 comments on commit e58cc91

Please sign in to comment.