49 class subscription_node
62 void set_next(subscription_node* sub)
68 subscription_node* get_next()
const
76 set_next(ETL_NULLPTR);
80 void append(subscription_node* sub)
82 if (sub != ETL_NULLPTR)
84 sub->set_next(get_next());
89 subscription_node* p_next;
97 class subscription :
public subscription_node
101 friend class message_broker;
112 virtual message_id_span_t message_id_list()
const = 0;
121 subscription* next_subscription()
const
123 return static_cast<subscription*
>(get_next());
129 using etl::imessage_router::receive;
135 : imessage_router(
etl::imessage_router::MESSAGE_BROKER)
144 : imessage_router(
etl::imessage_router::MESSAGE_BROKER, successor_)
153 : imessage_router(id_)
156 ETL_ASSERT((id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER) || (id_ == etl::imessage_router::MESSAGE_BROKER),
164 : imessage_router(id_, successor_)
167 ETL_ASSERT((id_ <= etl::imessage_router::MAX_MESSAGE_ROUTER) || (id_ == etl::imessage_router::MESSAGE_BROKER),
176 initialise_insertion_point(new_sub.get_router(), &new_sub);
182 initialise_insertion_point(&router, ETL_NULLPTR);
188 receive(etl::imessage_router::ALL_MESSAGE_ROUTERS, msg);
191 virtual void receive(etl::shared_message shared_msg) ETL_OVERRIDE
193 receive(etl::imessage_router::ALL_MESSAGE_ROUTERS, shared_msg);
197 virtual void receive(etl::message_router_id_t destination_router_id,
const etl::imessage& msg) ETL_OVERRIDE
206 while (sub != ETL_NULLPTR)
208 message_id_span_t message_ids = sub->message_id_list();
210 message_id_span_t::iterator itr = etl::find(message_ids.begin(), message_ids.end(),
id);
212 if (itr != message_ids.end())
214 etl::imessage_router* router = sub->get_router();
216 if (destination_router_id == etl::imessage_router::ALL_MESSAGE_ROUTERS || destination_router_id == router->get_message_router_id())
218 router->receive(msg);
222 sub = sub->next_subscription();
234 virtual void receive(etl::message_router_id_t destination_router_id, etl::shared_message shared_msg) ETL_OVERRIDE
243 while (sub != ETL_NULLPTR)
245 message_id_span_t message_ids = sub->message_id_list();
247 message_id_span_t::iterator itr = etl::find(message_ids.begin(), message_ids.end(),
id);
249 if (itr != message_ids.end())
251 etl::imessage_router* router = sub->get_router();
253 if (destination_router_id == etl::imessage_router::ALL_MESSAGE_ROUTERS || destination_router_id == router->get_message_router_id())
255 router->receive(shared_msg);
259 sub = sub->next_subscription();
270 using imessage_router::accepts;
283 while (sub != ETL_NULLPTR)
285 message_id_span_t message_ids = sub->message_id_list();
287 message_id_span_t::iterator itr = etl::find(message_ids.
begin(), message_ids.
end(),
id);
289 if (itr != message_ids.
end())
293 if (router->accepts(
id))
299 sub = sub->next_subscription();
325 virtual bool is_null_router() const ETL_OVERRIDE
331 virtual bool is_producer() const ETL_OVERRIDE
337 virtual bool is_consumer() const ETL_OVERRIDE
345 return head.get_next() == ETL_NULLPTR;
351 void initialise_insertion_point(
const etl::imessage_router* p_router, etl::message_broker::subscription* p_new_sub)
353 const etl::imessage_router* p_target_router = p_router;
355 subscription_node* p_sub = head.get_next();
356 subscription_node* p_sub_previous = &head;
358 while (p_sub != ETL_NULLPTR)
361 if (
static_cast<subscription*
>(p_sub)->get_router() == p_target_router)
364 p_sub_previous->set_next(p_sub->get_next());
372 p_sub = p_sub->get_next();
373 p_sub_previous = p_sub_previous->get_next();
376 if (p_new_sub != ETL_NULLPTR)
379 p_sub_previous->append(p_new_sub);
383 subscription_node head;