18 #ifndef INCLUDE_RCF_PUBLISHINGSERVICE_HPP 19 #define INCLUDE_RCF_PUBLISHINGSERVICE_HPP 26 #include <RCF/Export.hpp> 27 #include <RCF/PeriodicTimer.hpp> 30 #include <RCF/Service.hpp> 31 #include <RCF/ThreadLibrary.hpp> 32 #include <RCF/Timer.hpp> 33 #include <RCF/Tools.hpp> 43 void setTopicName(
const std::string & topicName);
46 std::string getTopicName()
const;
56 friend class PublishingService;
58 std::string mTopicName;
71 std::string getTopicName();
74 std::size_t getSubscriberCount();
80 void dropSubscriber(RcfSessionWeakPtr sessionWeakPtr);
84 friend class PublishingService;
88 PublishingService & mPublishingService;
91 std::string mTopicName;
92 RcfClientPtr mRcfClientPtr;
96 template<
typename Interface>
101 typedef typename Interface::RcfClientT RcfClientT;
107 if (mTopicName.empty())
109 mTopicName = getInterfaceName<Interface>();
112 mRcfClientPtr.reset(
new RcfClientT(
ClientStub(mTopicName) ) );
113 mpClient =
dynamic_cast<RcfClientT *
>(mRcfClientPtr.get());
121 RCF_ASSERT(!mClosed);
127 RcfClientT * mpClient;
130 class I_RequestSubscription;
131 template<
typename T>
class RcfClient;
133 class RCF_EXPORT PublishingService :
140 ~PublishingService();
142 template<
typename Interface>
143 std::shared_ptr< Publisher<Interface> > createPublisher(
146 std::shared_ptr< Publisher<Interface> > publisherPtr(
149 std::string topicName = publisherPtr->getTopicName();
151 RCF_ASSERT(topicName.size() > 0);
152 Lock lock(mPublishersMutex);
153 mPublishers[topicName] = publisherPtr;
157 void setPingIntervalMs(std::uint32_t pingIntervalMs);
158 std::uint32_t getPingIntervalMs()
const;
160 void closeSubscription(
const std::string connectionGuid);
165 friend class RcfClient<I_RequestSubscription>;
167 friend class PublishingServicePb;
170 std::int32_t RequestSubscription(
171 const std::string &subscriptionName);
173 std::int32_t RequestSubscription(
174 const std::string &subscriptionName,
175 std::uint32_t subToPubPingIntervalMs,
176 std::uint32_t & pubToSubPingIntervalMs);
181 void onServiceRemoved(
RcfServer &server);
185 void addSubscriberTransport(
187 const std::string &publisherName,
188 ClientTransportUniquePtrPtr clientTransportUniquePtrPtr,
189 const std::string & connectionGuid);
191 void closePublisher(
const std::string & name);
195 typedef std::map<std::string, PublisherWeakPtr> Publishers;
197 Mutex mPublishersMutex;
198 Publishers mPublishers;
200 std::uint32_t mPingIntervalMs;
201 PeriodicTimer mPeriodicTimer;
204 std::map<std::string, std::weak_ptr<ClientTransportUniquePtr>> mSubscriberConnections;
206 virtual void onTimer();
207 void pingAllSubscriptions();
208 void harvestExpiredSubscriptions();
212 typedef std::shared_ptr<PublishingService> PublishingServicePtr;
216 #endif // ! INCLUDE_RCF_PUBLISHINGSERVICE_HPP RcfClientT & publish()
Returns a reference to the RcfClient<> instance to use when publishing messages.
Definition: PublishingService.hpp:119
Represents a server side session, associated with a client connection.
Definition: RcfSession.hpp:64
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:82
std::function< void(RcfSession &, const std::string &)> OnSubscriberDisconnect
Describes a user-provided callback function to be called on the publisher side, whenever a subscriber...
Definition: RcfFwd.hpp:74
Provides RCF server-side functionality.
Definition: RcfServer.hpp:53
Represents a single publisher within a RcfServer. To create a publisher, use RcfServer::createPublish...
Definition: PublishingService.hpp:97
Definition: AmiIoHandler.hpp:23
General configuration of a publisher.
Definition: PublishingService.hpp:38
std::function< bool(RcfSession &, const std::string &)> OnSubscriberConnect
Describes a user-provided callback function to be called on the publisher side, whenever a subscriber...
Definition: RcfFwd.hpp:71
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...
Base class of all publishers.
Definition: PublishingService.hpp:64