Skip to content

Commit

Permalink
Add identifier in RequestFactory
Browse files Browse the repository at this point in the history
Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
  • Loading branch information
xiyuoh committed Mar 12, 2024
1 parent a63096d commit 4ed0837
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/RequestFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class RequestFactory
/// request.
virtual ConstRequestPtr make_request(const State& state) const = 0;

/// Returns an identifier representing the request type.
virtual const std::string& request_type() const = 0;

virtual ~RequestFactory() = default;
};

Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/requests/ChargeBatteryFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class ChargeBatteryFactory : public RequestFactory
/// Documentation inherited
ConstRequestPtr make_request(const State& state) const final;

/// Documentation inherited
const std::string& request_type() const final;

class Implementation;

private:
Expand Down
3 changes: 3 additions & 0 deletions rmf_task/include/rmf_task/requests/ParkRobotFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class ParkRobotFactory : public RequestFactory
/// Documentation inherited
ConstRequestPtr make_request(const State& state) const final;

/// Documentation inherited
const std::string& request_type() const final;

class Implementation;

private:
Expand Down
9 changes: 8 additions & 1 deletion rmf_task/src/rmf_task/requests/ChargeBatteryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ChargeBatteryFactory::Implementation
std::optional<std::string> requester;
std::function<rmf_traffic::Time()> time_now_cb;
bool indefinite = false;
std::string request_type = "Charge";
};

//==============================================================================
Expand Down Expand Up @@ -85,7 +86,7 @@ bool ChargeBatteryFactory::indefinite() const
//==============================================================================
ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
{
const std::string id = "Charge" + generate_uuid();
const std::string id = _pimpl->request_type + generate_uuid();
Task::ConstBookingPtr booking;
if (_pimpl->requester.has_value() && _pimpl->time_now_cb)
{
Expand Down Expand Up @@ -114,5 +115,11 @@ ConstRequestPtr ChargeBatteryFactory::make_request(const State& state) const
return std::make_shared<Request>(std::move(booking), std::move(description));
}

//==============================================================================
const std::string& ChargeBatteryFactory::request_type() const
{
return _pimpl->request_type;
}

} // namespace requests
} // namespace rmf_task
9 changes: 8 additions & 1 deletion rmf_task/src/rmf_task/requests/ParkRobotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ParkRobotFactory::Implementation
std::optional<std::string> requester;
std::function<rmf_traffic::Time()> time_now_cb;
std::optional<std::size_t> parking_waypoint;
const std::string request_type = "ParkRobot";
};

//==============================================================================
Expand All @@ -76,7 +77,7 @@ ParkRobotFactory::ParkRobotFactory(
//==============================================================================
ConstRequestPtr ParkRobotFactory::make_request(const State& state) const
{
std::string id = "ParkRobot" + generate_uuid();
std::string id = _pimpl->request_type + generate_uuid();
const auto start_waypoint = state.waypoint().value();
const auto finish_waypoint = _pimpl->parking_waypoint.has_value() ?
_pimpl->parking_waypoint.value() :
Expand Down Expand Up @@ -105,5 +106,11 @@ ConstRequestPtr ParkRobotFactory::make_request(const State& state) const
true);
}

//==============================================================================
const std::string& ParkRobotFactory::request_type() const
{
return _pimpl->request_type;
}

} // namespace requests
} // namespace rmf_task

0 comments on commit 4ed0837

Please sign in to comment.