18 #ifndef IGN_TRANSPORT_HANDLERSTORAGE_HH_
19 #define IGN_TRANSPORT_HANDLERSTORAGE_HH_
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() ||
123 _handler = handler.second;
137 public:
bool Handler(
const std::string &_topic,
138 const std::string &_nUuid,
139 const std::string &_hUuid,
140 std::shared_ptr<T> &_handler)
const
142 if (this->data.find(_topic) == this->data.end())
145 auto const &m = this->data.at(_topic);
146 if (m.find(_nUuid) == m.end())
149 if (m.at(_nUuid).find(_hUuid) == m.at(_nUuid).end())
152 _handler = m.at(_nUuid).at(_hUuid);
162 const std::string &_nUuid,
163 const std::shared_ptr<T> &_handler)
166 if (this->data.find(_topic) == this->data.end())
167 this->data[_topic] = UUIDHandler_Collection_M();
170 if (this->data[_topic].find(_nUuid) == this->data[_topic].end())
171 this->data[_topic][_nUuid] = UUIDHandler_M();
174 this->data[_topic][_nUuid].insert(
175 std::make_pair(_handler->HandlerUuid(), _handler));
184 if (this->data.find(_topic) == this->data.end())
187 return !this->data.at(_topic).empty();
195 const std::string &_nUuid)
const
197 if (this->data.find(_topic) == this->data.end())
200 return this->data.at(_topic).find(_nUuid) !=
201 this->data.at(_topic).end();
211 const std::string &_nUuid,
212 const std::string &_reqUuid)
215 if (this->data.find(_topic) != this->data.end())
217 if (this->data[_topic].find(_nUuid) != this->data[_topic].end())
219 counter = this->data[_topic][_nUuid].erase(_reqUuid);
220 if (this->data[_topic][_nUuid].empty())
221 this->data[_topic].erase(_nUuid);
222 if (this->data[_topic].empty())
223 this->data.erase(_topic);
235 const std::string &_nUuid)
238 if (this->data.find(_topic) != this->data.end())
240 counter = this->data[_topic].erase(_nUuid);
241 if (this->data[_topic].empty())
242 this->data.erase(_topic);
251 private: TopicServiceCalls_M data;
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
bool RemoveHandlersForNode(const std::string &_topic, const std::string &_nUuid)
Remove all the handlers from a given node.
Definition: HandlerStorage.hh:234
ignition/transport/HandlerStorage.hh
Definition: HandlerStorage.hh:33
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
bool HasHandlersForTopic(const std::string &_topic) const
Return true if we have stored at least one request for the topic.
Definition: HandlerStorage.hh:182
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
virtual ~HandlerStorage()=default
Destructor.
bool HasHandlersForNode(const std::string &_topic, const std::string &_nUuid) const
Check if a node has at least one handler.
Definition: HandlerStorage.hh:194
HandlerStorage()=default
Constructor.
bool RemoveHandler(const std::string &_topic, const std::string &_nUuid, const std::string &_reqUuid)
Remove a request handler.
Definition: HandlerStorage.hh:210
const std::string kGenericMessageType
The string type used for generic messages.
Definition: TransportTypes.hh:132
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:137
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:161