19 #ifndef INCLUDE_RCF_RCFSESSION_HPP
20 #define INCLUDE_RCF_RCFSESSION_HPP
24 #include <boost/any.hpp>
25 #include <boost/enable_shared_from_this.hpp>
26 #include <boost/function.hpp>
27 #include <boost/shared_ptr.hpp>
29 #include <RCF/Filter.hpp>
30 #include <RCF/Export.hpp>
31 #include <RCF/MethodInvocation.hpp>
32 #include <RCF/SerializationProtocol.hpp>
33 #include <RCF/ServerTransport.hpp>
34 #include <RCF/StubEntry.hpp>
36 #if RCF_FEATURE_FILETRANSFER==1
37 #include <RCF/FileDownload.hpp>
38 #include <RCF/FileUpload.hpp>
47 typedef boost::shared_ptr<Filter> FilterPtr;
51 typedef boost::shared_ptr<RcfSession> RcfSessionPtr;
52 typedef boost::weak_ptr<RcfSession> RcfSessionWeakPtr;
58 class UdpServerTransport;
59 class UdpSessionState;
61 class FileTransferService;
63 class FileDownloadInfo;
67 typedef boost::shared_ptr<FileUploadInfo> FileUploadInfoPtr;
68 typedef boost::shared_ptr<FileDownloadInfo> FileDownloadInfoPtr;
70 typedef std::pair<boost::uint32_t, RcfSessionWeakPtr> PingBackTimerEntry;
72 class AsioSessionState;
91 class AllocateServerParameters;
110 class ServerParameters;
112 class PingBackService;
114 struct TypeInfoCompare
117 const std::type_info* lhs,
118 const std::type_info* rhs)
const
120 if (lhs->before(*rhs))
128 class RCF_EXPORT RcfSession :
129 public boost::enable_shared_from_this<RcfSession>
132 RcfSession(RcfServer &server);
135 typedef boost::function1<void, RcfSession&> OnWriteCompletedCallback;
136 typedef boost::function1<void, RcfSession&> OnWriteInitiatedCallback;
137 typedef boost::function1<void, RcfSession&> OnDestroyCallback;
139 typedef std::map<const std::type_info *, boost::any, TypeInfoCompare> SessionObjectMap;
140 SessionObjectMap mSessionObjects;
145 T * getSessionObjectImpl(
bool createIfDoesntExist)
147 typedef boost::shared_ptr<T> TPtr;
149 const std::type_info & whichType =
typeid(T);
150 const std::type_info * pWhichType = &whichType;
152 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
153 if (iter != mSessionObjects.end())
155 boost::any & a = iter->second;
156 TPtr * ptPtr = boost::any_cast<TPtr>(&a);
157 RCF_ASSERT(ptPtr && *ptPtr);
160 else if (createIfDoesntExist)
162 TPtr tPtr(
new T() );
163 mSessionObjects[pWhichType] = tPtr;
175 void deleteSessionObject()
177 typedef boost::shared_ptr<T> TPtr;
179 const std::type_info & whichType =
typeid(T);
180 const std::type_info * pWhichType = &whichType;
182 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
183 if (iter != mSessionObjects.end())
185 mSessionObjects.erase(iter);
190 T & createSessionObject()
192 deleteSessionObject<T>();
193 T * pt = getSessionObjectImpl<T>(
true);
199 T & getSessionObject(
bool createIfDoesntExist =
false)
201 T * pt = getSessionObjectImpl<T>(createIfDoesntExist);
204 RCF_THROW( Exception(_RcfError_SessionObjectDoesNotExist(
typeid(T).name())));
210 T * querySessionObject()
212 T * pt = getSessionObjectImpl<T>(
false);
222 void addOnWriteCompletedCallback(
223 const OnWriteCompletedCallback & onWriteCompletedCallback);
225 void extractOnWriteCompletedCallbacks(
226 std::vector<OnWriteCompletedCallback> & onWriteCompletedCallbacks);
228 void setOnDestroyCallback(
229 OnDestroyCallback onDestroyCallback);
233 const RemoteAddress &
236 RcfServer & getRcfServer();
240 bool hasDefaultServerStub();
241 StubEntryPtr getDefaultStubEntryPtr();
242 void setDefaultStubEntryPtr(StubEntryPtr stubEntryPtr);
243 void setCachedStubEntryPtr(StubEntryPtr stubEntryPtr);
245 void setEnableSfPointerTracking(
bool enable);
246 bool getEnableSfPointerTracking()
const;
248 boost::uint32_t getRuntimeVersion();
249 void setRuntimeVersion(boost::uint32_t version);
251 boost::uint32_t getArchiveVersion();
252 void setArchiveVersion(boost::uint32_t version);
254 bool getNativeWstringSerialization();
255 void setNativeWstringSerialization(
bool enable);
257 void setUserData(
const boost::any & userData);
258 boost::any & getUserData();
260 void getMessageFilters(std::vector<FilterPtr> &filters);
261 void getTransportFilters(std::vector<FilterPtr> &filters);
263 void lockTransportFilters();
264 void unlockTransportFilters();
265 bool transportFiltersLocked();
267 SerializationProtocolIn & getSpIn();
268 SerializationProtocolOut & getSpOut();
271 void setFiltered(
bool filtered);
273 std::vector<FilterPtr> & getFilters();
275 void setCloseSessionAfterWrite(
bool close);
277 boost::uint32_t getPingBackIntervalMs();
279 boost::uint32_t getPingTimestamp();
280 void setPingTimestamp();
282 boost::uint32_t getPingIntervalMs();
283 void setPingIntervalMs(boost::uint32_t pingIntervalMs);
285 boost::uint32_t getTouchTimestamp();
292 void setWeakThisPtr();
294 void setRequestUserData(
const std::string & userData);
295 std::string getRequestUserData();
297 void setResponseUserData(
const std::string & userData);
298 std::string getResponseUserData();
303 void setInProcess(
bool inProcess);
306 I_Parameters * getInProcessParameters();
308 void cancelDownload();
310 #if RCF_FEATURE_FILETRANSFER==1
312 void addDownloadStream(
313 boost::uint32_t sessionLocalId,
314 FileStream fileStream);
318 Mutex mStopCallInProgressMutex;
319 bool mStopCallInProgress;
340 friend class AllocateServerParameters;
359 friend class ServerParameters;
361 friend class PingBackService;
362 friend class FilterService;
364 friend class StubAccess;
366 friend class InProcessTransport;
368 RcfServer & mRcfServer;
371 std::vector<OnWriteCompletedCallback> mOnWriteCompletedCallbacks;
372 std::vector<OnWriteInitiatedCallback> mOnWriteInitiatedCallbacks;
373 OnDestroyCallback mOnDestroyCallback;
375 boost::uint32_t mRuntimeVersion;
376 boost::uint32_t mArchiveVersion;
378 bool mUseNativeWstringSerialization;
379 bool mEnableSfPointerTracking;
381 bool mTransportFiltersLocked;
383 SerializationProtocolIn mIn;
384 SerializationProtocolOut mOut;
387 std::vector<FilterPtr> mFilters;
390 MethodInvocationRequest mRequest;
393 I_Parameters * mpInProcessParameters;
395 bool mCloseSessionAfterWrite;
396 boost::uint32_t mPingTimestamp;
397 boost::uint32_t mPingIntervalMs;
398 boost::uint32_t mTouchTimestamp;
399 ByteBuffer mPingBackByteBuffer;
400 PingBackTimerEntry mPingBackTimerEntry;
403 bool mWritingPingBack;
404 std::vector<ByteBuffer> mQueuedSendBuffers;
406 void clearParameters();
408 void onReadCompleted();
409 void onWriteCompleted();
411 void processJsonRpcRequest();
413 void processRequest();
414 void invokeServant();
417 void sendResponseException(
const std::exception &e);
418 void sendResponseUncaughtException();
420 void encodeRemoteException(
421 SerializationProtocolOut & out,
422 const RemoteException & e);
424 void sendSessionResponse();
426 void registerForPingBacks();
427 void unregisterForPingBacks();
429 void verifyTransportProtocol(RCF::TransportProtocol protocol);
431 friend class RcfServer;
432 friend class RemoteCallContextImpl;
434 I_Parameters * mpParameters;
435 std::vector<char> mParametersVec;
438 std::vector< std::vector<char> > mParmsVec;
442 RcfSessionWeakPtr mWeakThisPtr;
448 friend class UdpServerTransport;
449 friend class UdpSessionState;
450 friend class FileStreamImpl;
452 #if RCF_FEATURE_FILETRANSFER==1
456 friend class FileTransferService;
458 FileDownloadInfoPtr mDownloadInfoPtr;
459 FileUploadInfoPtr mUploadInfoPtr;
461 typedef std::map<boost::uint32_t, FileUploadInfoPtr> SessionUploads;
462 typedef std::map<boost::uint32_t, FileDownload> SessionDownloads;
464 SessionUploads mSessionUploads;
465 SessionDownloads mSessionDownloads;
471 boost::any mUserData;
472 StubEntryPtr mDefaultStubEntryPtr;
473 StubEntryPtr mCachedStubEntryPtr;
476 SessionState & getSessionState()
const;
477 void setSessionState(SessionState & sessionState);
480 SessionState * mpSessionState;
483 std::string mCurrentCallDesc;
486 Mutex mDisableIoMutex;
489 friend class AsioSessionState;
496 tstring getClientUsername();
497 TransportProtocol getTransportProtocol();
498 TransportType getTransportType();
500 bool getEnableCompression();
502 CertificatePtr getClientCertificatePtr();
504 bool getIsCallbackSession()
const;
505 void setIsCallbackSession(
bool isCallbackSession);
507 RemoteCallRequest getRemoteCallRequest()
const;
509 time_t getConnectedAtTime()
const;
511 std::size_t getConnectionDuration()
const;
513 std::size_t getRemoteCallCount()
const;
514 boost::uint64_t getTotalBytesReceived()
const;
515 boost::uint64_t getTotalBytesSent()
const;
517 bool isConnected()
const;
521 void setConnectedAtTime(time_t connectedAtTime);
523 friend class SspiServerFilter;
524 friend class Win32NamedPipeSessionState;
526 tstring mClientUsername;
527 TransportProtocol mTransportProtocol;
528 bool mEnableCompression;
530 bool mTransportProtocolVerified;
531 bool mIsCallbackSession;
533 time_t mConnectedAtTime;
535 std::size_t mRemoteCallCount;
540 #endif // ! INCLUDE_RCF_RCFSESSION_HPP