@@ -32,16 +32,37 @@ namespace rclcpp
3232namespace executors
3333{
3434
35+ // / Structure to represent a single entity's entry in a collection
3536template <typename EntityValueType>
3637struct CollectionEntry
3738{
39+ // / Weak pointer to entity type
3840 using EntityWeakPtr = typename EntityValueType::WeakPtr;
41+ // / Shared pointer to entity type
3942 using EntitySharedPtr = typename EntityValueType::SharedPtr;
4043
44+ // / The entity
4145 EntityWeakPtr entity;
46+
47+ // / If relevant, the entity's corresponding callback_group
4248 rclcpp::CallbackGroup::WeakPtr callback_group;
4349};
4450
51+ // / Update a collection based on another collection
52+ /*
53+ * Iterates update_from and update_to to see which entities have been added/removed between
54+ * the two collections.
55+ *
56+ * For each new entry (in update_from, but not in update_to),
57+ * add the entity and fire the on_added callback
58+ * For each removed entry (in update_to, but not in update_from),
59+ * remove the entity and fire the on_removed callback.
60+ *
61+ * \param[in] update_from The collection representing the next iteration's state
62+ * \param[inout] update_to The collection representing the current iteration's state
63+ * \param[in] on_added Callback fired when a new entity is detected
64+ * \param[in] on_removed Callback fired when an entity is removed
65+ */
4566template <typename CollectionType>
4667void update_entities (
4768 const CollectionType & update_from,
@@ -71,15 +92,31 @@ void update_entities(
7192 }
7293 }
7394}
95+
96+ // / A collection of entities, indexed by their corresponding handles
7497template <typename EntityKeyType, typename EntityValueType>
7598class EntityCollection
7699 : public std::unordered_map<const EntityKeyType *, CollectionEntry<EntityValueType>>
77100{
78101public:
102+ // / Key type of the map
79103 using Key = const EntityKeyType *;
104+
105+ // / Weak pointer to entity type
80106 using EntityWeakPtr = typename EntityValueType::WeakPtr;
107+
108+ // / Shared pointer to entity type
81109 using EntitySharedPtr = typename EntityValueType::SharedPtr;
82110
111+ // / Update this collection based on the contents of another collection
112+ /* *
113+ * Update the internal state of this collection, firing callbacks when entities have been
114+ * added or removed.
115+ *
116+ * \param[in] other Collection to compare to
117+ * \param[in] on_added Callback for when entities have been added
118+ * \param[in] on_removed Callback for when entities have been removed
119+ */
83120 void update (
84121 const EntityCollection<EntityKeyType, EntityValueType> & other,
85122 std::function<void (EntitySharedPtr)> on_added,
@@ -96,40 +133,72 @@ class EntityCollection
96133 */
97134struct ExecutorEntitiesCollection
98135{
99- // / Entity entries for timers
136+ // / Collection type for timer entities
100137 using TimerCollection = EntityCollection<rcl_timer_t , rclcpp::TimerBase>;
101138
102- // / Entity entries for subscriptions
139+ // / Collection type for subscription entities
103140 using SubscriptionCollection = EntityCollection<rcl_subscription_t , rclcpp::SubscriptionBase>;
104141
105- // / Entity entries for clients
142+ // / Collection type for client entities
106143 using ClientCollection = EntityCollection<rcl_client_t , rclcpp::ClientBase>;
107144
108- // / Entity entries for services
145+ // / Collection type for service entities
109146 using ServiceCollection = EntityCollection<rcl_service_t , rclcpp::ServiceBase>;
110147
111- // / Entity entries for waitables
148+ // / Collection type for waitable entities
112149 using WaitableCollection = EntityCollection<rclcpp::Waitable, rclcpp::Waitable>;
113150
114- // / Entity entries for guard conditions
151+ // / Collection type for guard condition entities
115152 using GuardConditionCollection = EntityCollection<rcl_guard_condition_t , rclcpp::GuardCondition>;
116153
154+ // / Collection of timers currently in use by the executor.
117155 TimerCollection timers;
156+
157+ // / Collection of subscriptions currently in use by the executor.
118158 SubscriptionCollection subscriptions;
159+
160+ // / Collection of clients currently in use by the executor.
119161 ClientCollection clients;
162+
163+ // / Collection of services currently in use by the executor.
120164 ServiceCollection services;
165+
166+ // / Collection of guard conditions currently in use by the executor.
121167 GuardConditionCollection guard_conditions;
168+
169+ // / Collection of waitables currently in use by the executor.
122170 WaitableCollection waitables;
123171
172+ // / Check if the entities collection is empty
173+ /* *
174+ * \return true if all member collections are empty, false otherwise
175+ */
124176 bool empty () const ;
177+
178+ // / Clear the entities collection
125179 void clear ();
126180};
127181
182+ // / Build an entities collection from callback groups
183+ /* *
184+ * Iterates a list of callback groups and adds entities from each valid group
185+ *
186+ * \param[in] callback_groups List of callback groups to check for entities
187+ * \param[inout] colletion Entities collection to populate with found entities
188+ */
128189void
129190build_entities_collection (
130191 const std::vector<rclcpp::CallbackGroup::WeakPtr> & callback_groups,
131192 ExecutorEntitiesCollection & collection);
132193
194+ // / Build a queue of executables ready to be executed
195+ /* *
196+ * Iterates a list of entities and adds them to a queue if they are ready.
197+ *
198+ * \param[in] collection Collection of entities corresponding to the current wait set.
199+ * \param[in] wait_result Result of rclcpp::WaitSet::wait corresponding to the collection.
200+ * \return A queue of executables that have been marked ready by the waitset.
201+ */
133202std::deque<rclcpp::AnyExecutable>
134203ready_executables (
135204 const ExecutorEntitiesCollection & collection,
0 commit comments