22 #ifndef __M2ETIS_PUBSUB_PUBSUBSYSTEM_H__
23 #define __M2ETIS_PUBSUB_PUBSUBSYSTEM_H__
35 #include "boost/function.hpp"
42 template<
class EventType>
class BasicDeliverCallbackInterface;
43 class PubSubSystemEnvironment;
62 PubSubSystem(
const std::string & listenIP,
const uint16_t listenPort,
const std::string & connectIP,
const uint16_t connectPort,
const std::vector<std::string> & rootList);
89 template<
class EventType>
const PubSubSystem & unsubscribe(
const ChannelName channel)
const;
119 template<
class EventType> std::string getSelf(
const ChannelName channel)
const;
126 void registerExceptionCallback(
exceptionEvents e, boost::function<
void(
const std::string &)> _ptr);
132 bool exceptionLoop();
141 std::vector<std::vector<boost::function<void(const std::string &)>>> _exceptionCallbacks;
143 uint64_t exceptionID_;
166 M2ETIS_THROW_API(
"PubSubSystem",
"Invalid call, initialize PubSubSystem first.");
168 if (channel >= channels_->
count) {
169 M2ETIS_THROW_API(
"PubSubSystem", std::string(
"Invalid channel, enum exceeds CHANNEL_COUNT: ") + std::to_string(channel));
171 BasicChannelInterface<EventType> *
const ret =
dynamic_cast<BasicChannelInterface<EventType> * const
>(channels_->
channels()[channel]);
173 M2ETIS_THROW_API(
"PubSubSystem",
"Invalid channel type cast. Check your channel configuration.");
179 const boost::shared_ptr<filter::FilterExp<EventType> > pred = boost::make_shared<filter::TruePredicate<EventType> >();
181 return subscribe(channel, callback, pred);
212 return getChannelHandle<EventType>(channel)->
createMessage(payload);
216 return createMessage<EventType>(channel, EventType());
virtual void subscribe(BasicDeliverCallbackInterface< EventType > &callback, boost::shared_ptr< filter::FilterExp< EventType > >)=0
subscribes to the channel
boost::shared_ptr< M2Message< EventType > > Ptr
virtual void unsubscribe()=0
const PubSubSystem & unsubscribe(const ChannelName channel) const
User unsubscribes to the requested channel.
BasicChannelInterface< EventType > & subscribe(const ChannelName channel, BasicDeliverCallbackInterface< EventType > &callback)
User subscribes to the requested channel.
const PubSubSystem & publish(const ChannelName channel, const typename message::M2Message< EventType >::Ptr publish_message) const
Publishes a message to a channel.
const std::vector< ChannelEventInterface * > & channels() const
PubSubSystemEnvironment * _pssi
std::string getSelf(const ChannelName channel) const
Returns a string representation of the requested channel.
bool isInitialized() const
sets callback for disconnect
message::M2Message< EventType >::Ptr createMessage(const ChannelName channel, const EventType &payload)
returns a M2Message for the given EventType and Payload
class for accessing the m2etis pub/sub system. It is the main entry point for the usage of the m2etis...
virtual void publish(const typename message::M2Message< EventType >::Ptr msg)=0
publishes a message on the channel
#define M2ETIS_THROW_API(module, message)
throws on wrong API usage