39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
55 namespace pexExceptions =lsst::pex::exceptions;
67 EventSystem::EventSystem() {
73 EventSystem::~EventSystem() {
81 if (defaultEventSystem == 0) {
89 unsigned char a,
b,c,
d;
91 gethostname(buf, 255) ;
92 ent = (
struct hostent *)gethostbyname(buf) ;
94 a = ent->h_addr_list[0][0] & 0xFF;
95 b = ent->h_addr_list[0][1] & 0xFF;
96 c = ent->h_addr_list[0][2] & 0xFF;
97 d = ent->h_addr_list[0][3] & 0xFF;
99 _IPId = (a << 24) | (b << 16) | (c << 8) | d;
104 return *defaultEventSystem;
109 int EventSystem::_IPId = 0;
110 short EventSystem::_localId = 0;
116 boost::shared_ptr<EventTransmitter> transmitter(
new EventTransmitter(policy));
117 boost::shared_ptr<EventTransmitter> transmitter2;
118 if ((transmitter2 = getTransmitter(transmitter->getTopicName())) == 0) {
119 _transmitters.push_back(transmitter);
122 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ transmitter->getTopicName() +
" is already registered with EventSystem");
130 void EventSystem::createTransmitter(
const std::string& hostName,
const std::string& topicName,
int hostPort) {
131 boost::shared_ptr<EventTransmitter> transmitter;
132 if ((transmitter = getTransmitter(topicName)) == 0) {
133 boost::shared_ptr<EventTransmitter> transmitter(
new EventTransmitter(hostName, topicName, hostPort));
134 _transmitters.push_back(transmitter);
137 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is already registered with EventSystem");
144 boost::shared_ptr<EventReceiver> receiver(
new EventReceiver(policy));
145 boost::shared_ptr<EventReceiver> receiver2;
146 if ((receiver2 = getReceiver(receiver->getTopicName())) == 0) {
147 _receivers.push_back(receiver);
150 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic " + receiver->getTopicName() +
" is already registered with EventSystem");
158 void EventSystem::createReceiver(
const std::string& hostName,
const std::string& topicName,
int hostPort) {
159 boost::shared_ptr<EventReceiver> receiver;
160 if ((receiver = getReceiver(topicName)) == 0) {
161 boost::shared_ptr<EventReceiver> receiver(
new EventReceiver(hostName, topicName, hostPort));
162 _receivers.push_back(receiver);
165 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is already registered with EventSystem");
174 void EventSystem::createReceiver(
const std::string& hostName,
const std::string& topicName,
const std::string& selector,
int hostPort) {
175 boost::shared_ptr<EventReceiver> receiver(
new EventReceiver(hostName, topicName, selector, hostPort));
176 _receivers.push_back(receiver);
186 void EventSystem::publishEvent(
const std::string& topicName,
Event& event) {
187 boost::shared_ptr<EventTransmitter> transmitter;
188 if ((transmitter = getTransmitter(topicName)) == 0) {
189 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is not registered with EventSystem");
191 transmitter->publishEvent(event);
196 boost::shared_ptr<EventTransmitter> EventSystem::getTransmitter(
const std::string& name) {
197 list<boost::shared_ptr<EventTransmitter> >::iterator i;
198 for (i = _transmitters.begin(); i != _transmitters.end(); i++) {
199 if ((*i)->getTopicName() == name)
202 return boost::shared_ptr<EventTransmitter>();
211 Event* EventSystem::receiveEvent(
const std::string& topicName) {
212 return receiveEvent(topicName, EventReceiver::infiniteTimeout);
223 Event* EventSystem::receiveEvent(
const std::string& topicName,
const long timeout) {
224 boost::shared_ptr<EventReceiver> receiver;
225 if ((receiver = getReceiver(topicName)) == 0) {
226 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"Topic "+ topicName +
" is not registered with EventSystem");
229 return receiver->receiveEvent(timeout);
235 boost::shared_ptr<EventReceiver> EventSystem::getReceiver(
const std::string& name) {
236 list<boost::shared_ptr<EventReceiver> >::iterator i;
237 for (i = _receivers.begin(); i != _receivers.end(); i++) {
238 if ((*i)->getTopicName() == name)
241 return boost::shared_ptr<EventReceiver>();
244 int64_t EventSystem::createOriginatorId() {
245 int64_t pid = getpid();
247 int64_t originatorId = _IPId & 0x0FFFFFFFF;
248 int64_t locid = _localId & 0x7FFF;
250 originatorId = (locid << 49) | (pid << 32) | originatorId;
261 int EventSystem::extractIPId(int64_t identificationId) {
262 return identificationId & 0xFFFFFFFF;
268 int EventSystem::extractProcessId(int64_t identificationId) {
269 return (identificationId & 0x1FFFF00000000LL) >> 32;
275 short EventSystem::extractLocalId(int64_t identificationId) {
276 return (identificationId & 0xFFFE000000000000LL) >> 49;
Singleton use to make sure the events library is initialized.
Receive events from the event bus.
defines the EventLog class
a container for holding hierarchical configuration data in memory.
Representation of an LSST Event.
Representation of an LSST Event.
Include files required for standard LSST Exception handling.
defines the EventLibrary class
Transmit events to the event bus.
defines the CommandEvent class
static void initializeLibrary()
initialize the ActiveMQ library, but only do it once.
#define LSST_EXCEPT(type,...)
Representation of an LSST Event.
afw::table::Key< double > b
Interface for PropertySet class.
Coordinate publishing and receiving events.
defines the EventSystem class