21 #ifndef INCLUDE_RCF_RCFSESSION_HPP 22 #define INCLUDE_RCF_RCFSESSION_HPP 29 #include <RCF/Any.hpp> 30 #include <RCF/Export.hpp> 31 #include <RCF/MethodInvocation.hpp> 33 #include <RCF/SerializationProtocol.hpp> 36 #if RCF_FEATURE_FILETRANSFER==1 40 #if RCF_FEATURE_SSPI==1 47 struct TypeInfoCompare
50 const std::type_info* lhs,
51 const std::type_info* rhs)
const 53 if (lhs->before(*rhs))
66 public std::enable_shared_from_this<RcfSession>
73 typedef std::function<void(RcfSession&)> OnWriteCompletedCallback;
74 typedef std::function<void(RcfSession&)> OnWriteInitiatedCallback;
75 typedef std::function<void(RcfSession&)> OnDestroyCallback;
77 typedef std::map<const std::type_info *, Any, TypeInfoCompare> SessionObjectMap;
78 SessionObjectMap mSessionObjects;
83 T * getSessionObjectImpl(
bool createIfDoesntExist)
85 typedef std::shared_ptr<T> TPtr;
87 const std::type_info & whichType =
typeid(T);
88 const std::type_info * pWhichType = &whichType;
90 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
91 if (iter != mSessionObjects.end())
93 Any & a = iter->second;
94 TPtr & tPtr = a.
get<TPtr>();
95 RCF_ASSERT(tPtr.get());
98 else if (createIfDoesntExist)
100 TPtr tPtr(
new T() );
101 mSessionObjects[pWhichType] = tPtr;
125 typedef std::shared_ptr<T> TPtr;
127 const std::type_info & whichType =
typeid(T);
128 const std::type_info * pWhichType = &whichType;
130 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
131 if (iter != mSessionObjects.end())
133 mSessionObjects.erase(iter);
141 deleteSessionObject<T>();
142 T * pt = getSessionObjectImpl<T>(
true);
146 RCF_THROW(
Exception(RcfError_SessionObjectNotCreated,
typeid(T).name()));
155 T * pt = getSessionObjectImpl<T>(createIfDoesntExist);
158 RCF_THROW(
Exception(RcfError_SessionObjectDoesNotExist,
typeid(T).name()));
167 T * pt = getSessionObjectImpl<T>(
false);
179 RcfClientPtr getDefaultStubEntryPtr();
180 void setDefaultStubEntryPtr(RcfClientPtr stubEntryPtr);
181 void setCachedStubEntryPtr(RcfClientPtr stubEntryPtr);
189 void setRequestUserData(
const std::string & userData);
192 std::string getRequestUserData();
195 void setResponseUserData(
const std::string & userData);
198 std::string getResponseUserData();
226 std::uint32_t getPingBackIntervalMs();
229 tstring getClientUserName();
233 getTransportProtocol();
238 #if RCF_FEATURE_SSPI==1 242 PCtxtHandle getTransportSecurityContext()
const;
246 PCtxtHandle getTransportProtocolSecurityContext()
const;
251 bool getEnableCompression();
260 time_t getConnectedAtTime()
const;
263 std::size_t getConnectionDuration()
const;
266 std::size_t getRemoteCallCount()
const;
269 std::uint64_t getTotalBytesReceived()
const;
272 std::uint64_t getTotalBytesSent()
const;
275 void setEnableSfPointerTracking(
bool enable);
278 bool getEnableSfPointerTracking()
const;
283 #if RCF_FEATURE_FILETRANSFER==1 295 void setAllowUploads(
bool allowUploads);
298 bool getAllowUploads()
const;
307 Path getUploadPath(
const std::string& uploadId);
317 void addOnWriteCompletedCallback(
318 const OnWriteCompletedCallback & onWriteCompletedCallback);
320 void extractOnWriteCompletedCallbacks(
321 std::vector<OnWriteCompletedCallback> & onWriteCompletedCallbacks);
323 void setOnDestroyCallback(
324 OnDestroyCallback onDestroyCallback);
328 void setEnableNativeWstringSerialization(
bool enable);
329 bool getEnableNativeWstringSerialization()
const;
331 void getMessageFilters(std::vector<FilterPtr> &filters)
const;
332 void getTransportFilters(std::vector<FilterPtr> &filters)
const;
334 void lockTransportFilters();
335 void unlockTransportFilters();
336 bool transportFiltersLocked();
338 SerializationProtocolIn & getSpIn();
339 SerializationProtocolOut & getSpOut();
342 void setFiltered(
bool filtered);
344 std::vector<FilterPtr> & getFilters();
346 void setCloseSessionAfterWrite(
bool close);
350 std::uint32_t getPingTimestamp();
351 void setPingTimestamp();
353 std::uint32_t getPingIntervalMs();
354 void setPingIntervalMs(std::uint32_t pingIntervalMs);
356 std::uint32_t getTouchTimestamp();
357 bool getCallInProgress();
360 void setCallInProgress(
bool callInProgress);
365 void setWeakThisPtr();
367 void cancelDownload();
369 #if RCF_FEATURE_FILETRANSFER==1 371 void addDownloadStream(
372 std::uint32_t sessionLocalId,
373 FileStream fileStream);
377 Mutex mStopCallInProgressMutex;
378 bool mStopCallInProgress;
399 friend class AllocateServerParameters;
418 friend class ServerParameters;
420 friend class PingBackService;
421 friend class FilterService;
423 friend class StubAccess;
428 std::vector<OnWriteCompletedCallback> mOnWriteCompletedCallbacks;
429 std::vector<OnWriteInitiatedCallback> mOnWriteInitiatedCallbacks;
430 OnDestroyCallback mOnDestroyCallback;
432 std::uint32_t mRuntimeVersion;
433 std::uint32_t mArchiveVersion;
435 bool mEnableSfPointerTracking;
437 bool mTransportFiltersLocked;
439 bool mEnableNativeWstringSerialization =
false;
441 SerializationProtocolIn mIn;
442 SerializationProtocolOut mOut;
445 std::vector<FilterPtr> mFilters;
448 MethodInvocationRequest mRequest;
450 bool mCallInProgress =
false;
451 bool mCloseSessionAfterWrite;
452 std::uint32_t mPingTimestamp;
453 std::uint32_t mPingIntervalMs;
454 std::uint32_t mTouchTimestamp;
456 PingBackTimerEntry mPingBackTimerEntry;
459 bool mWritingPingBack;
460 std::vector<ByteBuffer> mQueuedSendBuffers;
462 void clearParameters();
464 void onReadCompleted();
465 void onWriteCompleted();
467 void processRequest();
469 void processOob_RequestTransportFilters(OobMessage& msg);
470 void processOob_CreateCallbackConnection(OobMessage& msg);
471 void processOob_RequestSubscription(OobMessage& msg);
472 void processOob_RequestProxyConnection(OobMessage& msg);
473 void processOobMessages();
478 void sendResponseException(
const std::exception &e);
479 void sendResponseUncaughtException();
481 void encodeRemoteException(
482 SerializationProtocolOut & out,
485 void sendSessionResponse();
487 void registerForPingBacks();
488 void unregisterForPingBacks();
495 I_Parameters * mpParameters;
496 std::vector<char> mParametersVec;
499 std::vector< std::vector<char> > mParmsVec;
503 RcfSessionWeakPtr mWeakThisPtr;
509 friend class UdpServerTransport;
510 friend class UdpNetworkSession;
511 friend class FileStreamImpl;
513 friend class AsioNetworkSession;
514 void runOnDestroyCallbacks();
516 #if RCF_FEATURE_FILETRANSFER==1 520 friend class FileTransferService;
522 FileDownloadInfoPtr mDownloadInfoPtr;
523 FileUploadInfoPtr mUploadInfoPtr;
525 typedef std::map<std::uint32_t, FileUploadInfoPtr> SessionUploads;
526 typedef std::map<std::uint32_t, FileDownload> SessionDownloads;
528 SessionUploads mSessionUploads;
529 SessionDownloads mSessionDownloads;
535 RcfClientPtr mDefaultStubEntryPtr;
536 RcfClientPtr mCachedStubEntryPtr;
539 NetworkSession & getNetworkSession()
const;
540 void setNetworkSession(NetworkSession & networkSession);
542 #if RCF_FEATURE_HTTP==1 544 void getHttpFrameInfo(
545 std::string& requestLine,
546 std::vector< std::pair<std::string, std::string> >& headers);
551 friend class HttpSessionFilter;
552 NetworkSession * mpNetworkSession;
555 std::string mCurrentCallDesc;
559 bool getIsCallbackSession()
const;
560 void setIsCallbackSession(
bool isCallbackSession);
562 bool isConnected()
const;
566 void setConnectedAtTime(time_t connectedAtTime);
568 friend class SspiServerFilter;
569 friend class Win32NamedPipeNetworkSession;
571 tstring mClientUsername;
573 bool mEnableCompression;
575 bool mTransportProtocolVerified;
576 bool mIsCallbackSession;
578 time_t mConnectedAtTime;
580 std::size_t mRemoteCallCount;
585 #endif // ! INCLUDE_RCF_RCFSESSION_HPP Describes the network address of a remote peer.
Definition: ServerTransport.hpp:37
Generic container type used to hold arbitrary objects.
Definition: RCF/Any.hpp:64
RCF_FILESYSTEM_NS::path Path
Typedef for standard C++ path type.
Definition: FileSystem.hpp:32
RCF_EXPORT std::uint32_t getArchiveVersion()
Gets the RCF archive version number.
Contains details about the currently executing remote call.
Definition: MethodInvocation.hpp:63
Represents a server side session, associated with a client connection.
Definition: RcfSession.hpp:65
T & get()
Type-safe retrieval of the contained value. Throws an exception if T does not match the type of the c...
Definition: RCF/Any.hpp:104
std::shared_ptr< BandwidthQuota > BandwidthQuotaPtr
Reference counted wrapper for RCF::BandwidthQuota.
Definition: RcfFwd.hpp:128
Base class of RemoteCallContext.
Definition: RemoteCallContext.hpp:39
std::shared_ptr< Certificate > CertificatePtr
Reference counted wrapper for RCF::Certificate.
Definition: RcfFwd.hpp:109
RCF_EXPORT RcfSession & getCurrentRcfSession()
Can only be called from within the server-side implementation of a remote call. Returns a reference t...
Base class for all RCF exceptions.
Definition: Exception.hpp:64
RCF_EXPORT void setArchiveVersion(std::uint32_t version)
Sets the RCF archive version number. Applies to all RCF clients and servers within the current proces...
RCF_EXPORT std::uint32_t getRuntimeVersion()
Gets the RCF runtime version number.
T & createSessionObject()
Creates a session object.
Definition: RcfSession.hpp:139
void deleteSessionObject()
Deletes a session object.
Definition: RcfSession.hpp:123
Provides RCF server-side functionality.
Definition: RcfServer.hpp:54
Represents an error that occurs on a RCF server and is transmitted back to the client.
Definition: Exception.hpp:153
Definition: ByteBuffer.hpp:40
TransportProtocol
Describes the transport protocols used by a RCF connection. Transport protocols are layered on top of...
Definition: Enums.hpp:63
Definition: AmiIoHandler.hpp:24
TransportType
Describes the transport types used by a RCF connection.
Definition: Enums.hpp:34
T * querySessionObject()
Queries for the existence of a session object.
Definition: RcfSession.hpp:165
RCF_EXPORT void setRuntimeVersion(std::uint32_t version)
Sets the RCF runtime version number. Applies to all RCF clients and servers within the current proces...
T & getSessionObject(bool createIfDoesntExist=false)
Retrieves a session object, and optionally creates it.
Definition: RcfSession.hpp:153