18 #ifndef INCLUDE_RCF_SUBSCRIPTIONSERVICE_HPP 19 #define INCLUDE_RCF_SUBSCRIPTIONSERVICE_HPP 29 #include <RCF/Export.hpp> 32 #include <RCF/PeriodicTimer.hpp> 33 #include <RCF/ServerStub.hpp> 34 #include <RCF/Service.hpp> 44 SubscriptionService & subscriptionService,
46 RcfSessionWeakPtr rcfSessionWeakPtr,
47 std::uint32_t incomingPingIntervalMs,
48 const std::string & publisherUrl,
49 const std::string & topic,
52 void setWeakThisPtr(SubscriptionWeakPtr thisWeakPtr);
54 void setPublisherConnectionGuid(
const std::string& connectionGuid);
60 unsigned int getPingTimestamp();
61 RcfSessionPtr getRcfSessionPtr();
69 std::string getPublisherConnectionGuid()
const;
72 friend class SubscriptionService;
74 static void onDisconnect(SubscriptionWeakPtr subPtr,
RcfSession & session);
76 SubscriptionService & mSubscriptionService;
77 SubscriptionWeakPtr mThisWeakPtr;
79 RecursiveMutex mMutex;
80 RcfSessionWeakPtr mRcfSessionWeakPtr;
82 RcfClientPtr mConnectionPtr;
84 std::uint32_t mPubToSubPingIntervalMs = 0;
85 bool mPublisherSupportsPubSubPings =
true;
86 std::string mPublisherUrl;
88 std::string mPublisherConnectionGuid;
101 void setTopicName(
const std::string & publisherName);
104 std::string getTopicName()
const;
107 void setPublisherEndpoint(
const Endpoint & publisherEp);
110 void setPublisherEndpoint(
I_RcfClient & rcfClient);
120 friend class SubscriptionService;
122 std::string mPublisherName;
128 class RCF_EXPORT SubscriptionService :
134 SubscriptionService(std::uint32_t pingIntervalMs = 0);
136 ~SubscriptionService();
138 template<
typename Interface,
typename T>
139 SubscriptionPtr createSubscription(
143 std::string defaultPublisherName = getInterfaceName((Interface *) NULL);
145 std::reference_wrapper<T> refWrapper(t);
147 RcfClientPtr rcfClientPtr(
148 createServerStub((Interface *) 0, (T *) 0, refWrapper));
150 return createSubscriptionImpl(rcfClientPtr, parms, defaultPublisherName);
153 template<
typename Interface,
typename T>
154 SubscriptionPtr createSubscription(
160 return createSubscription<Interface>(t, parms);
163 SubscriptionPtr createSubscriptionImpl(
164 RcfClientPtr rcfClientPtr,
166 const std::string & defaultPublisherName);
168 void createSubscriptionImplBegin(
169 RcfClientPtr rcfClientPtr,
171 const std::string & defaultPublisherName);
173 void createSubscriptionImplEnd(
175 ClientStubPtr clientStubPtr,
177 const std::string & publisherName,
178 RcfClientPtr rcfClientPtr,
181 std::uint32_t pubToSubPingIntervalMs,
184 void closeSubscription(SubscriptionWeakPtr subscriptionPtr);
186 void setPingIntervalMs(std::uint32_t pingIntervalMs);
187 std::uint32_t getPingIntervalMs()
const;
195 Mutex mSubscriptionsMutex;
197 typedef std::set<SubscriptionWeakPtr> Subscriptions;
198 Subscriptions mSubscriptions;
200 std::uint32_t mPingIntervalMs;
201 PeriodicTimer mPeriodicTimer;
203 virtual void onTimer();
204 void pingAllSubscriptions();
205 void harvestExpiredSubscriptions();
207 static void sOnPingCompleted(RecursiveLockPtr lockPtr);
211 SubscriptionPtr onRequestSubscriptionCompleted(
213 const std::string & publisherName,
215 RcfClientPtr rcfClientPtr,
217 std::uint32_t pubToSubPingIntervalMs,
222 std::int32_t doRequestSubscription(
224 const std::string & publisherName,
225 std::uint32_t subToPubPingIntervalMs,
226 std::uint32_t & pubToSubPingIntervalMs,
227 bool & pingsEnabled);
229 void doRequestSubscriptionAsync(
231 const std::string & publisherName,
232 RcfClientPtr rcfClientPtr,
235 void doRequestSubscriptionAsync_Complete(
237 RcfClientPtr requestClientPtr,
238 const std::string & publisherName,
239 RcfClientPtr rcfClientPtr,
245 std::int32_t doRequestSubscription_Legacy(
247 const std::string & publisherName,
248 std::uint32_t subToPubPingIntervalMs,
249 std::uint32_t & pubToSubPingIntervalMs,
250 bool & pingsEnabled);
252 void doRequestSubscriptionAsync_Legacy(
254 const std::string & publisherName,
255 RcfClientPtr rcfClientPtr,
258 void doRequestSubscriptionAsync_Legacy_Complete(
259 ClientStubPtr clientStubPtr,
261 const std::string & publisherName,
262 RcfClientPtr rcfClientPtr,
271 typedef std::shared_ptr<SubscriptionService> SubscriptionServicePtr;
275 #endif // ! INCLUDE_RCF_SUBSCRIPTIONSERVICE_HPP
Base class of all RcfClient<> templates.
Definition: RcfClient.hpp:44
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::unique_ptr< ClientTransport > ClientTransportUniquePtr
Unique pointer wrapper for RCF::ClientTransport.
Definition: RcfFwd.hpp:43
void setPublisherEndpoint(const Endpoint &publisherEp)
Sets the network endpoint of the publishing server.
Provides the ability for remote calls to be executed asynchronously.
Definition: Future.hpp:50
Provides RCF server-side functionality.
Definition: RcfServer.hpp:53
Base class for all network endpoint types.
Definition: Endpoint.hpp:40
std::function< void(RcfSession &)> OnSubscriptionDisconnect
Describes a user-provided callback function to be called on the subscriber side, whenever a subscribe...
Definition: RcfFwd.hpp:77
General configuration of a subscription.
Definition: SubscriptionService.hpp:95
Definition: AmiIoHandler.hpp:23
Represents a subscription to a RCF publisher. To create a subscription, use RcfServer::createSubscrip...
Definition: SubscriptionService.hpp:39
std::function< void(SubscriptionPtr, ExceptionPtr)> OnAsyncSubscribeCompleted
Describes a user-provided callback function to be called on the subscriber side, when an subscription...
Definition: RcfFwd.hpp:80