38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
54 namespace pexExceptions =lsst::pex::exceptions;
62 EventSystem::EventSystem() {
66 EventSystem::~EventSystem() {
76 list<boost::shared_ptr<EventTransmitter> >EventSystem::_transmitters;
77 list<boost::shared_ptr<EventReceiver> >EventSystem::_receivers;
79 void EventSystem::createTransmitter(std::string
const& hostName, std::string
const& topicName,
int hostPort) {
80 boost::shared_ptr<EventTransmitter> transmitter;
81 if ((transmitter = getTransmitter(topicName)) == 0) {
82 boost::shared_ptr<EventTransmitter> transmitter(
new EventTransmitter(hostName, topicName, hostPort));
83 _transmitters.push_back(transmitter);
86 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is already registered with EventSystem");
89 void EventSystem::createReceiver(std::string
const& hostName, std::string
const& topicName,
int hostPort) {
90 boost::shared_ptr<EventReceiver> receiver;
91 if ((receiver = getReceiver(topicName)) == 0) {
92 boost::shared_ptr<EventReceiver> receiver(
new EventReceiver(hostName, topicName, hostPort));
93 _receivers.push_back(receiver);
96 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is already registered with EventSystem");
99 void EventSystem::createReceiver(std::string
const& hostName, std::string
const& topicName, std::string
const& selector,
int hostPort) {
100 boost::shared_ptr<EventReceiver> receiver(
new EventReceiver(hostName, topicName, selector, hostPort));
101 _receivers.push_back(receiver);
105 void EventSystem::publishEvent(std::string
const& topicName,
Event& event) {
106 boost::shared_ptr<EventTransmitter> transmitter;
107 if ((transmitter = getTransmitter(topicName)) == 0) {
108 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"topic "+ topicName +
" is not registered with EventSystem");
110 transmitter->publishEvent(event);
115 boost::shared_ptr<EventTransmitter> EventSystem::getTransmitter(std::string
const&
name) {
116 list<boost::shared_ptr<EventTransmitter> >::iterator i;
117 for (i = _transmitters.begin(); i != _transmitters.end(); i++) {
118 if ((*i)->getTopicName() ==
name) {
122 return boost::shared_ptr<EventTransmitter>();
126 Event* EventSystem::receiveEvent(std::string
const& topicName) {
127 return receiveEvent(topicName, EventReceiver::infiniteTimeout);
130 Event* EventSystem::receiveEvent(std::string
const& topicName,
const long timeout) {
131 boost::shared_ptr<EventReceiver> receiver;
132 if ((receiver = getReceiver(topicName)) == 0) {
133 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"Topic "+ topicName +
" is not registered with EventSystem");
136 return receiver->receiveEvent(timeout);
145 boost::shared_ptr<EventReceiver> EventSystem::getReceiver(std::string
const&
name) {
146 list<boost::shared_ptr<EventReceiver> >::iterator i;
147 for (i = _receivers.begin(); i != _receivers.end(); i++) {
148 if ((*i)->getTopicName() ==
name)
151 return boost::shared_ptr<EventReceiver>();
Singleton use to make sure the events library is initialized.
Receive events from the event bus.
table::Key< std::string > name
defines the LocationId class
boost::shared_ptr< LocationId > Ptr
Representation of an LSST Event.
Representation of an LSST CommandEvent.
defines the EventLibrary class
Transmit events to the event bus.
defines the CommandEvent class
#define LSST_EXCEPT(type,...)
Representation of an LSST Event.
Represent process that created an event.
defines the StatusEvent class
static void initializeLibrary()
initialize the ActiveMQ library, but only do it once.
Interface for PropertySet class.
This object allows creation of the system's event transmitters and receivers, which can be specified ...
defines the EventSystem class
Include files required for standard LSST Exception handling.