18 #ifndef __IGN_TRANSPORT_HANDLERSTORAGE_HH_INCLUDED__ 19 #define __IGN_TRANSPORT_HANDLERSTORAGE_HH_INCLUDED__ 39 using UUIDHandler_M = std::map<std::string, std::shared_ptr<T>>;
40 using UUIDHandler_Collection_M = std::map<std::string, UUIDHandler_M>;
43 using TopicServiceCalls_M =
44 std::map<std::string, UUIDHandler_Collection_M>;
60 public:
bool Handlers(
const std::string &_topic,
62 std::map<std::string, std::shared_ptr<T> >> &_handlers)
const 64 if (this->data.find(_topic) == this->data.end())
67 _handlers = this->data.at(_topic);
79 const std::string &_reqTypeName,
80 const std::string &_repTypeName,
81 std::shared_ptr<T> &_handler)
const 83 if (this->data.find(_topic) == this->data.end())
86 const auto &m = this->data.at(_topic);
87 for (
const auto &node : m)
89 for (
const auto &handler : node.second)
91 if (_reqTypeName == handler.second->ReqTypeName() &&
92 _repTypeName == handler.second->RepTypeName())
94 _handler = handler.second;
109 const std::string &_msgTypeName,
110 std::shared_ptr<T> &_handler)
const 112 if (this->data.find(_topic) == this->data.end())
115 const auto &m = this->data.at(_topic);
116 for (
const auto &node : m)
118 for (
const auto &handler : node.second)
120 if (_msgTypeName == handler.second->TypeName())
122 _handler = handler.second;
136 public:
bool Handler(
const std::string &_topic,
137 const std::string &_nUuid,
138 const std::string &_hUuid,
139 std::shared_ptr<T> &_handler)
const 141 if (this->data.find(_topic) == this->data.end())
144 auto const &m = this->data.at(_topic);
145 if (m.find(_nUuid) == m.end())
148 if (m.at(_nUuid).find(_hUuid) == m.at(_nUuid).end())
151 _handler = m.at(_nUuid).at(_hUuid);
161 const std::string &_nUuid,
162 const std::shared_ptr<T> &_handler)
165 if (this->data.find(_topic) == this->data.end())
166 this->data[_topic] = UUIDHandler_Collection_M();
169 if (this->data[_topic].find(_nUuid) == this->data[_topic].end())
170 this->data[_topic][_nUuid] = UUIDHandler_M();
173 this->data[_topic][_nUuid].insert(
174 std::make_pair(_handler->HandlerUuid(), _handler));
183 if (this->data.find(_topic) == this->data.end())
186 return !this->data.at(_topic).empty();
194 const std::string &_nUuid)
const 196 if (this->data.find(_topic) == this->data.end())
199 return this->data.at(_topic).find(_nUuid) !=
200 this->data.at(_topic).end();
210 const std::string &_nUuid,
211 const std::string &_reqUuid)
214 if (this->data.find(_topic) != this->data.end())
216 if (this->data[_topic].find(_nUuid) != this->data[_topic].end())
218 counter = this->data[_topic][_nUuid].erase(_reqUuid);
219 if (this->data[_topic][_nUuid].empty())
220 this->data[_topic].erase(_nUuid);
221 if (this->data[_topic].empty())
222 this->data.erase(_topic);
234 const std::string &_nUuid)
237 if (this->data.find(_topic) != this->data.end())
239 counter = this->data[_topic].erase(_nUuid);
240 if (this->data[_topic].empty())
241 this->data.erase(_topic);
250 private: TopicServiceCalls_M data;
bool RemoveHandlersForNode(const std::string &_topic, const std::string &_nUuid)
Remove all the handlers from a given node.
Definition: HandlerStorage.hh:233
bool HasHandlersForTopic(const std::string &_topic) const
Return true if we have stored at least one request for the topic.
Definition: HandlerStorage.hh:181
bool FirstHandler(const std::string &_topic, const std::string &_reqTypeName, const std::string &_repTypeName, std::shared_ptr< T > &_handler) const
Get the first handler for a topic that matches a specific pair of request/response types...
Definition: HandlerStorage.hh:78
ignition/transport/HandlerStorage.hh
Definition: HandlerStorage.hh:33
bool HasHandlersForNode(const std::string &_topic, const std::string &_nUuid) const
Check if a node has at least one handler.
Definition: HandlerStorage.hh:193
bool Handlers(const std::string &_topic, std::map< std::string, std::map< std::string, std::shared_ptr< T > >> &_handlers) const
Get the data handlers for a topic.
Definition: HandlerStorage.hh:60
bool FirstHandler(const std::string &_topic, const std::string &_msgTypeName, std::shared_ptr< T > &_handler) const
Get the first handler for a topic that matches a specific message type.
Definition: HandlerStorage.hh:108
virtual ~HandlerStorage()=default
Destructor.
HandlerStorage()=default
Constructor.
bool RemoveHandler(const std::string &_topic, const std::string &_nUuid, const std::string &_reqUuid)
Remove a request handler.
Definition: HandlerStorage.hh:209
bool Handler(const std::string &_topic, const std::string &_nUuid, const std::string &_hUuid, std::shared_ptr< T > &_handler) const
Get a specific handler.
Definition: HandlerStorage.hh:136
Definition: AdvertiseOptions.hh:25
void AddHandler(const std::string &_topic, const std::string &_nUuid, const std::shared_ptr< T > &_handler)
Add a request handler to a topic.
Definition: HandlerStorage.hh:160