Class Database¶
Defined in File Database.hpp
Inheritance Relationships¶
Base Types¶
public rmf_traffic::schedule::ItineraryViewer
(Class ItineraryViewer)public rmf_traffic::schedule::Writer
(Class Writer)public rmf_traffic::schedule::Snappable
(Class Snappable)
Class Documentation¶
-
class
rmf_traffic::schedule
::
Database
: public rmf_traffic::schedule::ItineraryViewer, public rmf_traffic::schedule::Writer, public rmf_traffic::schedule::Snappable¶ A class that maintains a database of scheduled Trajectories. This class is intended to be used only for the canonical RMF traffic schedule database.
The Viewer API can be queried to find Trajectories that match certain criteria.
You can also retrieve update patches from a database. To apply those patches to a downstream Viewer, it is strongly advised to use the rmf_traffic::schedule::Mirror class.
Public Functions
-
virtual void
set
(ParticipantId participant, PlanId plan, const Itinerary &itinerary, StorageId storage_base, ItineraryVersion version) final¶ Set a brand new itinerary for a participant. This will replace any itinerary that is already in the schedule for the participant.
- Parameters
[in] participant
: The ID of the participant whose itinerary is being updated.[in] plan
: The ID of the plan that this new itinerary belongs to.[in] itinerary
: The new itinerary of the participant.[in] storage_base
: The storage index offset that the database should use for this plan. This should generally be the integer number of total routes that the participant has ever given to the writer prior to setting this new itinerary. This value helps ensure consistent unique IDs for every route, even after a database has failed over or restarted.[in] version
: The version for this itinerary change.
-
virtual void
extend
(ParticipantId participant, const Itinerary &routes, ItineraryVersion version) final¶ Add a set of routes to the itinerary of this participant.
- Parameters
[in] participant
: The ID of the participant whose itinerary is being updated.[in] routes
: The set of routes that should be added to the itinerary.[in] version
: The version for this itinerary change
-
virtual void
delay
(ParticipantId participant, Duration delay, ItineraryVersion version) final¶ Add a delay to the itinerary from the specified Time.
Nothing about the routes in the itinerary will be changed except that waypoints will shifted through time.
- Parameters
[in] participant
: The ID of the participant whose itinerary is being delayed.[in] delay
: This is the duration of time to delay all qualifying Trajectory Waypoints.[in] version
: The version for this itinerary change
-
virtual void
reached
(ParticipantId participant, PlanId plan, const std::vector<CheckpointId> &reached_checkpoints, ProgressVersion version) final¶ Indicate that a participant has reached certain checkpoints.
- Parameters
[in] participant
: The ID of the participant whose progress is being set.[in] plan
: The ID of the plan which progress has been made for.[in] reached_checkpoints
: The set of checkpoints that have been reached. The indices in the vector must correspond to the RouteIds of the plan.[in] version
: The version number for this progress.
-
virtual void
clear
(ParticipantId participant, ItineraryVersion version) final¶ Erase an itinerary from this database.
- Parameters
[in] participant
: The ID of the participant whose itinerary is being erased.[in] version
: The version for this itinerary change
-
virtual Registration
register_participant
(ParticipantDescription participant_info) final¶ Register a new participant.
- Return
result of registering the new participant.
- Parameters
[in] participant_info
: Information about the new participant.[in] time
: The time at which the registration is being requested.
-
virtual void
update_description
(ParticipantId participant, ParticipantDescription desc) final¶ Updates a participants footprint
- Parameters
[in] participant
: The ID of the participant to update[in] desc
: The participant description
-
virtual void
unregister_participant
(ParticipantId participant) final¶ Before calling this function on a Database, you should set the current time for the database by calling set_current_time(). This will allow the database to cull this participant after a reasonable amount of time has passed.
-
virtual View
query
(const Query ¶meters) const final¶ Query this Viewer to get a View of the Trajectories inside of it that match the Query parameters.
-
virtual View
query
(const Query::Spacetime &spacetime, const Query::Participants &participants) const final¶ Alternative signature for query()
-
virtual const std::unordered_set<ParticipantId> &
participant_ids
() const final¶ Get the set of active participant IDs.
-
std::shared_ptr<const ParticipantDescription>
get_participant
(std::size_t participant_id) const final¶
-
std::optional<ItineraryView>
get_itinerary
(std::size_t participant_id) const final¶
-
virtual const std::vector<CheckpointId> *
get_current_progress
(ParticipantId participant_id) const final¶ Get the current progress of a specific participant. If a participant with the specified ID is not registered with the schedule or has never made progress, then this will return a nullptr.
-
virtual ProgressVersion
get_current_progress_version
(ParticipantId participant_id) const final¶ Get the current known progress of a specific participant along its current plan. If no progress has been made, this will have a value of 0.
-
virtual DependencySubscription
watch_dependency
(Dependency dependency, std::function<void()> on_reachedstd::function<void()> on_deprecated) const final¶ Watch a traffic dependency. When a relevant event happens for the dependency, the on_reached or on_deprecated will be triggered. If the event had already come to pass before this function is called, then the relevant callback will be triggered right away, within the scope of this function.
Only one of the callbacks will ever be triggered, and it will only be triggered at most once.
- Return
an object that maintains the dependency for the viewer.
- Parameters
[in] on_reached
: If the dependency is reached, this will be triggered. on_changed will never be triggered afterwards.[in] on_deprecated
: If the plan of the participant changed before it reached this dependency then the dependency is deprecated and this callback will be triggered. on_reached will never be triggered afterwards.
-
const Inconsistencies &
inconsistencies
() const¶ A description of all inconsistencies currently present in the database. Inconsistencies are isolated between Participants.
To fix the inconsistency, the Participant should resend every Itinerary change that was missing from every range, or else send a change that nullifies all previous changes, such as a set(~) or erase(ParticipantId).
-
Patch
changes
(const Query ¶meters, std::optional<Version> after) const¶ Get the changes in this Database that match the given Query parameters. If a version number is specified, then the returned Patch will reflect the changes that occurred from the specified version to the current version of the schedule.
To get a consistent reflection of the schedule when specifying a base version, it is important that the query parameters are not changed in between calls.
- Return
A Patch of schedule changes that are relevant to the specified query parameters.
- Parameters
[in] parameters
: The parameters describing what types of schedule entries the mirror cares about.[in] after
: Specify that only changes which come after this version number are desired. If you give a nullopt for this argument, then all changes will be provided.
-
View
query
(const Query ¶meters, Version after) const¶ View the routes that match the parameters and have changed (been added or delayed) since the specified version. This is useful for viewing incremental changes.
- Return
a view of the routes that are different since the specified version.
- Parameters
[in] parameters
: The parameters describing what types of schedule entries are relevant.[in] after
: Specify that only routes which changed after this version number are desired.
-
void
set_current_time
(Time time)¶ Set the current time on the database. This should be used immediately before calling unregister_participant() so that the database can cull the existence of the participant at an appropriate time. There’s no need to call this function for any other purpose.
-
ItineraryVersion
itinerary_version
(ParticipantId participant) const¶ Get the current itinerary version for the specified participant.
-
PlanId
latest_plan_id
(ParticipantId participant) const¶ Get the last Plan ID used by this participant.
This provides the same information as get_current_plan_id, except it throws an exception instead of returning an optional if the participant does not exist.
-
StorageId
next_storage_base
(ParticipantId participant) const¶ Get the last Storage ID used by this participant.
-
virtual void