|
| 1 | +// Copyright 2021 Open Source Robotics Foundation, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef RCLCPP__EXECUTORS__EVENTS_EXECUTOR_EVENT_TYPES_HPP_ |
| 16 | +#define RCLCPP__EXECUTORS__EVENTS_EXECUTOR_EVENT_TYPES_HPP_ |
| 17 | + |
| 18 | +namespace rclcpp |
| 19 | +{ |
| 20 | +namespace executors |
| 21 | +{ |
| 22 | + |
| 23 | +// forward declaration of EventsExecutor to avoid circular dependency |
| 24 | +class EventsExecutor; |
| 25 | + |
| 26 | +enum ExecutorEventType |
| 27 | +{ |
| 28 | + SUBSCRIPTION_EVENT, |
| 29 | + SERVICE_EVENT, |
| 30 | + CLIENT_EVENT, |
| 31 | + WAITABLE_EVENT |
| 32 | +}; |
| 33 | + |
| 34 | +struct ExecutorEvent |
| 35 | +{ |
| 36 | + const void * entity_id; |
| 37 | + ExecutorEventType type; |
| 38 | +}; |
| 39 | + |
| 40 | +// The EventsExecutorCallbackData struct is what the listeners |
| 41 | +// will use as argument when calling their callbacks from the |
| 42 | +// RMW implementation. The listeners get a (void *) of this struct, |
| 43 | +// and the executor is in charge to cast it back and use the data. |
| 44 | +struct EventsExecutorCallbackData |
| 45 | +{ |
| 46 | + EventsExecutorCallbackData( |
| 47 | + EventsExecutor * _executor, |
| 48 | + ExecutorEvent _event) |
| 49 | + { |
| 50 | + executor = _executor; |
| 51 | + event = _event; |
| 52 | + } |
| 53 | + |
| 54 | + // Equal operator |
| 55 | + bool operator==(const EventsExecutorCallbackData & other) const |
| 56 | + { |
| 57 | + return (event.entity_id == other.event.entity_id); |
| 58 | + } |
| 59 | + |
| 60 | + // Struct members |
| 61 | + EventsExecutor * executor; |
| 62 | + ExecutorEvent event; |
| 63 | +}; |
| 64 | + |
| 65 | +// To be able to use std::unordered_map with an EventsExecutorCallbackData |
| 66 | +// as key, we need a hasher. We use the entity ID as hash, since it is |
| 67 | +// unique for each EventsExecutorCallbackData object. |
| 68 | +struct KeyHasher |
| 69 | +{ |
| 70 | + size_t operator()(const EventsExecutorCallbackData & key) const |
| 71 | + { |
| 72 | + return std::hash<const void *>()(key.event.entity_id); |
| 73 | + } |
| 74 | +}; |
| 75 | + |
| 76 | +} // namespace executors |
| 77 | +} // namespace rclcpp |
| 78 | + |
| 79 | +#endif // RCLCPP__EXECUTORS__EVENTS_EXECUTOR_EVENT_TYPES_HPP_ |
0 commit comments