20 #ifndef INCLUDE_RCF_RCFSESSION_HPP 21 #define INCLUDE_RCF_RCFSESSION_HPP 28 #include <RCF/Any.hpp> 29 #include <RCF/Export.hpp> 30 #include <RCF/MethodInvocation.hpp> 32 #include <RCF/SerializationProtocol.hpp> 35 #if RCF_FEATURE_FILETRANSFER==1 39 #if RCF_FEATURE_SSPI==1 46 struct TypeInfoCompare
49 const std::type_info* lhs,
50 const std::type_info* rhs)
const 52 if (lhs->before(*rhs))
65 public std::enable_shared_from_this<RcfSession>
72 typedef std::function<void(RcfSession&)> OnWriteCompletedCallback;
73 typedef std::function<void(RcfSession&)> OnWriteInitiatedCallback;
74 typedef std::function<void(RcfSession&)> OnDestroyCallback;
76 typedef std::map<const std::type_info *, Any, TypeInfoCompare> SessionObjectMap;
77 SessionObjectMap mSessionObjects;
82 T * getSessionObjectImpl(
bool createIfDoesntExist)
84 typedef std::shared_ptr<T> TPtr;
86 const std::type_info & whichType =
typeid(T);
87 const std::type_info * pWhichType = &whichType;
89 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
90 if (iter != mSessionObjects.end())
92 Any & a = iter->second;
93 TPtr & tPtr = a.
get<TPtr>();
94 RCF_ASSERT(tPtr.get());
97 else if (createIfDoesntExist)
100 mSessionObjects[pWhichType] = tPtr;
124 typedef std::shared_ptr<T> TPtr;
126 const std::type_info & whichType =
typeid(T);
127 const std::type_info * pWhichType = &whichType;
129 SessionObjectMap::iterator iter = mSessionObjects.find(pWhichType);
130 if (iter != mSessionObjects.end())
132 mSessionObjects.erase(iter);
140 deleteSessionObject<T>();
141 T * pt = getSessionObjectImpl<T>(
true);
145 RCF_THROW(
Exception(RcfError_SessionObjectNotCreated,
typeid(T).name()));
154 T * pt = getSessionObjectImpl<T>(createIfDoesntExist);
157 RCF_THROW(
Exception(RcfError_SessionObjectDoesNotExist,
typeid(T).name()));
166 T * pt = getSessionObjectImpl<T>(
false);
178 RcfClientPtr getDefaultStubEntryPtr();
179 void setDefaultStubEntryPtr(RcfClientPtr stubEntryPtr);
180 void setCachedStubEntryPtr(RcfClientPtr stubEntryPtr);
188 void setRequestUserData(
const std::string & userData);
191 std::string getRequestUserData();
194 void setResponseUserData(
const std::string & userData);
197 std::string getResponseUserData();
225 std::uint32_t getPingBackIntervalMs();
228 tstring getClientUserName();
232 getTransportProtocol();
237 #if RCF_FEATURE_SSPI==1 241 PCtxtHandle getTransportSecurityContext()
const;
245 PCtxtHandle getTransportProtocolSecurityContext()
const;
250 bool getEnableCompression();
259 time_t getConnectedAtTime()
const;
262 std::size_t getConnectionDuration()
const;
265 std::size_t getRemoteCallCount()
const;
268 std::uint64_t getTotalBytesReceived()
const;
271 std::uint64_t getTotalBytesSent()
const;
274 void setEnableSfPointerTracking(
bool enable);
277 bool getEnableSfPointerTracking()
const;
282 #if RCF_FEATURE_FILETRANSFER==1 294 void setAllowUploads(
bool allowUploads);
297 bool getAllowUploads()
const;
306 Path getUploadPath(
const std::string& uploadId);
316 void addOnWriteCompletedCallback(
317 const OnWriteCompletedCallback & onWriteCompletedCallback);
319 void extractOnWriteCompletedCallbacks(
320 std::vector<OnWriteCompletedCallback> & onWriteCompletedCallbacks);
322 void setOnDestroyCallback(
323 OnDestroyCallback onDestroyCallback);
327 void setEnableNativeWstringSerialization(
bool enable);
328 bool getEnableNativeWstringSerialization()
const;
330 void getMessageFilters(std::vector<FilterPtr> &filters)
const;
331 void getTransportFilters(std::vector<FilterPtr> &filters)
const;
333 void lockTransportFilters();
334 void unlockTransportFilters();
335 bool transportFiltersLocked();
337 SerializationProtocolIn & getSpIn();
338 SerializationProtocolOut & getSpOut();
341 void setFiltered(
bool filtered);
343 std::vector<FilterPtr> & getFilters();
345 void setCloseSessionAfterWrite(
bool close);
349 std::uint32_t getPingTimestamp();
350 void setPingTimestamp();
352 std::uint32_t getPingIntervalMs();
353 void setPingIntervalMs(std::uint32_t pingIntervalMs);
355 std::uint32_t getTouchTimestamp();
356 bool getCallInProgress();
359 void setCallInProgress(
bool callInProgress);
364 void setWeakThisPtr();
366 void cancelDownload();
368 #if RCF_FEATURE_FILETRANSFER==1 370 void addDownloadStream(
371 std::uint32_t sessionLocalId,
372 FileStream fileStream);
376 Mutex mStopCallInProgressMutex;
377 bool mStopCallInProgress;
398 friend class AllocateServerParameters;
417 friend class ServerParameters;
419 friend class PingBackService;
420 friend class FilterService;
422 friend class StubAccess;
427 std::vector<OnWriteCompletedCallback> mOnWriteCompletedCallbacks;
428 std::vector<OnWriteInitiatedCallback> mOnWriteInitiatedCallbacks;
429 OnDestroyCallback mOnDestroyCallback;
431 std::uint32_t mRuntimeVersion;
432 std::uint32_t mArchiveVersion;
434 bool mEnableSfPointerTracking;
436 bool mTransportFiltersLocked;
438 bool mEnableNativeWstringSerialization =
false;
440 SerializationProtocolIn mIn;
441 SerializationProtocolOut mOut;
444 std::vector<FilterPtr> mFilters;
447 MethodInvocationRequest mRequest;
449 bool mCallInProgress =
false;
450 bool mCloseSessionAfterWrite;
451 std::uint32_t mPingTimestamp;
452 std::uint32_t mPingIntervalMs;
453 std::uint32_t mTouchTimestamp;
455 PingBackTimerEntry mPingBackTimerEntry;
458 bool mWritingPingBack;
459 std::vector<ByteBuffer> mQueuedSendBuffers;
461 void clearParameters();
463 void onReadCompleted();
464 void onWriteCompleted();
466 void processRequest();
468 void processOob_RequestTransportFilters(OobMessage& msg);
469 void processOob_CreateCallbackConnection(OobMessage& msg);
470 void processOob_RequestSubscription(OobMessage& msg);
471 void processOob_RequestProxyConnection(OobMessage& msg);
472 void processOobMessages();
477 void sendResponseException(
const std::exception &e);
478 void sendResponseUncaughtException();
480 void encodeRemoteException(
481 SerializationProtocolOut & out,
484 void sendSessionResponse();
486 void registerForPingBacks();
487 void unregisterForPingBacks();
494 I_Parameters * mpParameters;
495 std::vector<char> mParametersVec;
498 std::vector< std::vector<char> > mParmsVec;
502 RcfSessionWeakPtr mWeakThisPtr;
508 friend class UdpServerTransport;
509 friend class UdpNetworkSession;
510 friend class FileStreamImpl;
512 friend class AsioNetworkSession;
513 void runOnDestroyCallbacks();
515 #if RCF_FEATURE_FILETRANSFER==1 519 friend class FileTransferService;
521 FileDownloadInfoPtr mDownloadInfoPtr;
522 FileUploadInfoPtr mUploadInfoPtr;
524 typedef std::map<std::uint32_t, FileUploadInfoPtr> SessionUploads;
525 typedef std::map<std::uint32_t, FileDownload> SessionDownloads;
527 SessionUploads mSessionUploads;
528 SessionDownloads mSessionDownloads;
534 RcfClientPtr mDefaultStubEntryPtr;
535 RcfClientPtr mCachedStubEntryPtr;
538 NetworkSession & getNetworkSession()
const;
539 void setNetworkSession(NetworkSession & networkSession);
541 #if RCF_FEATURE_HTTP==1 543 void getHttpFrameInfo(
544 std::string& requestLine,
545 std::vector< std::pair<std::string, std::string> >& headers);
550 friend class HttpSessionFilter;
551 NetworkSession * mpNetworkSession;
554 std::string mCurrentCallDesc;
558 bool getIsCallbackSession()
const;
559 void setIsCallbackSession(
bool isCallbackSession);
561 bool isConnected()
const;
565 void setConnectedAtTime(time_t connectedAtTime);
567 friend class SspiServerFilter;
568 friend class Win32NamedPipeNetworkSession;
570 tstring mClientUsername;
572 bool mEnableCompression;
574 bool mTransportProtocolVerified;
575 bool mIsCallbackSession;
577 time_t mConnectedAtTime;
579 std::size_t mRemoteCallCount;
584 #endif // ! INCLUDE_RCF_RCFSESSION_HPP Describes the network address of a remote peer.
Definition: ServerTransport.hpp:36
Generic container type used to hold arbitrary objects.
Definition: RCF/Any.hpp:63
RCF_FILESYSTEM_NS::path Path
Typedef for standard C++ path type.
Definition: FileSystem.hpp:31
RCF_EXPORT std::uint32_t getArchiveVersion()
Gets the RCF archive version number.
Contains details about the currently executing remote call.
Definition: MethodInvocation.hpp:62
Represents a server side session, associated with a client connection.
Definition: RcfSession.hpp:64
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:103
std::shared_ptr< BandwidthQuota > BandwidthQuotaPtr
Reference counted wrapper for RCF::BandwidthQuota.
Definition: RcfFwd.hpp:127
Base class of RemoteCallContext.
Definition: RemoteCallContext.hpp:38
std::shared_ptr< Certificate > CertificatePtr
Reference counted wrapper for RCF::Certificate.
Definition: RcfFwd.hpp:108
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:67
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:138
void deleteSessionObject()
Deletes a session object.
Definition: RcfSession.hpp:122
Provides RCF server-side functionality.
Definition: RcfServer.hpp:53
Represents an error that occurs on a RCF server and is transmitted back to the client.
Definition: Exception.hpp:168
Definition: ByteBuffer.hpp:39
TransportProtocol
Describes the transport protocols used by a RCF connection. Transport protocols are layered on top of...
Definition: Enums.hpp:62
Definition: AmiIoHandler.hpp:23
TransportType
Describes the transport types used by a RCF connection.
Definition: Enums.hpp:33
T * querySessionObject()
Queries for the existence of a session object.
Definition: RcfSession.hpp:164
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:152