libbgp  0.6
A C++ BGP Library.
route-event-bus.cc
Go to the documentation of this file.
1 
11 #include "route-event-bus.h"
12 
13 namespace libbgp {
14 
15 RouteEventBus::RouteEventBus() {
16  subscription_id = 0;
17 }
18 
29  int n = 0;
30 
31  for (RouteEventReceiver* &subscriber : subscribers) {
32  if (recv == NULL || subscriber->subscription_id != recv->subscription_id) {
33  if (subscriber->handleRouteEvent(ev)) n++;
34  }
35  }
36 
37  return n;
38 }
39 
48  recv->subscription_id = ++subscription_id;
49  subscribers.push_back(recv);
50  return true;
51 }
52 
61  for (auto it = subscribers.begin(); it != subscribers.end(); it++) {
62  if ((*it)->subscription_id == recv->subscription_id) {
63  subscribers.erase(it);
64  return true;
65  }
66  }
67 
68  return false;
69 }
70 
71 }
int publish(RouteEventReceiver *recv, const RouteEvent &ev)
Publish a route event.
The route event bus.
bool subscribe(RouteEventReceiver *recv)
Subscribe from this event bus.
bool unsubscribe(RouteEventReceiver *recv)
Unsubscribe to this event bus.
Definition: bgp-afi.h:14
The RouteEventReceiver interface.
The RouteEvent base.
Definition: route-event.h:39