19 #ifndef INCLUDE_RCF_CLIENTSTUB_HPP
20 #define INCLUDE_RCF_CLIENTSTUB_HPP
26 #include <boost/scoped_ptr.hpp>
27 #include <boost/any.hpp>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/enable_shared_from_this.hpp>
31 #include <RCF/Certificate.hpp>
32 #include <RCF/ClientProgress.hpp>
33 #include <RCF/Filter.hpp>
34 #include <RCF/ClientTransport.hpp>
35 #include <RCF/Endpoint.hpp>
36 #include <RCF/Enums.hpp>
37 #include <RCF/Export.hpp>
38 #include <RCF/GetInterfaceName.hpp>
39 #include <RCF/MethodInvocation.hpp>
40 #include <RCF/SerializationProtocol_Base.hpp>
41 #include <RCF/RecursionLimiter.hpp>
42 #include <RCF/SerializationProtocol.hpp>
43 #include <RCF/Token.hpp>
45 #if RCF_FEATURE_FILETRANSFER==1
46 #include <RCF/FileStream.hpp>
47 #include <RCF/FileDownload.hpp>
48 #include <RCF/FileUpload.hpp>
60 class ConnectionResetGuard;
65 RCF_EXPORT
void setDefaultSslImplementation(SslImplementation sslImplementation);
68 RCF_EXPORT SslImplementation getDefaultSslImplementation();
70 RCF_EXPORT
void setDefaultConnectTimeoutMs(
unsigned int connectTimeoutMs);
71 RCF_EXPORT
unsigned int getDefaultConnectTimeoutMs();
73 RCF_EXPORT
void setDefaultRemoteCallTimeoutMs(
unsigned int remoteCallTimeoutMs);
74 RCF_EXPORT
unsigned int getDefaultRemoteCallTimeoutMs();
76 RCF_EXPORT
void setDefaultNativeWstringSerialization(
bool enable);
77 RCF_EXPORT
bool getDefaultNativeWstringSerialization();
81 typedef boost::shared_ptr<ClientStub> ClientStubPtr;
83 typedef Token FileTransferToken;
86 typedef boost::shared_ptr<ClientProgress> ClientProgressPtr;
88 class ClientTransport;
89 typedef std::auto_ptr<ClientTransport> ClientTransportAutoPtr;
92 typedef boost::shared_ptr<I_RcfClient> RcfClientPtr;
95 class IpClientTransport;
100 class FileTransferProgress;
102 class OpenSslEncryptionFilter;
106 typedef boost::function1<void, const FileTransferProgress &> FileProgressCb;
125 class AllocateClientParameters;
144 class ClientParameters;
147 typedef boost::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
149 class RCF_EXPORT CurrentClientStubSentry
152 CurrentClientStubSentry(ClientStub & clientStub);
153 CurrentClientStubSentry(ClientStub * pClientStub);
154 ~CurrentClientStubSentry();
160 class RCF_EXPORT ClientStub :
161 public ClientTransportCallback,
162 public boost::enable_shared_from_this<ClientStub>
165 ClientStub(
const std::string & interfaceName);
166 ClientStub(
const std::string & interfaceName,
const std::string &objectName);
167 ClientStub(
const ClientStub & rhs);
170 ClientStub &operator=(
const ClientStub & rhs);
173 void init(
const std::string & interfaceName,
const std::string & objectName);
174 void assign(
const ClientStub & rhs);
178 void setEndpoint(
const Endpoint &endpoint);
179 void setEndpoint(EndpointPtr endpointPtr);
180 EndpointPtr getEndpoint()
const;
181 Token getTargetToken()
const;
182 void setTargetToken(Token token);
183 const std::string & getTargetName()
const;
184 void setTargetName(
const std::string &targetName);
185 void setInterfaceName(
const std::string & interfaceName);
186 const std::string & getInterfaceName();
187 RemoteCallSemantics getRemoteCallSemantics()
const;
188 void setRemoteCallSemantics(RemoteCallSemantics defaultCallingSemantics);
191 RemoteCallSemantics getDefaultCallingSemantics()
const;
192 void setDefaultCallingSemantics(RemoteCallSemantics defaultCallingSemantics);
194 void setSerializationProtocol(SerializationProtocol protocol);
195 SerializationProtocol getSerializationProtocol()
const;
197 void setMarshalingProtocol(MarshalingProtocol protocol);
198 MarshalingProtocol getMarshalingProtocol()
const;
200 bool getNativeWstringSerialization();
201 void setNativeWstringSerialization(
bool enable);
203 void setEnableSfPointerTracking(
bool enable);
204 bool getEnableSfPointerTracking()
const;
206 void setTransport(ClientTransportAutoPtr transport);
208 ClientTransport& getTransport();
209 IpClientTransport & getIpTransport();
211 ClientTransportAutoPtr releaseTransport();
213 void instantiateTransport();
215 void connectAsync(boost::function0<void> onCompletion);
216 void wait(boost::function0<void> onCompletion, boost::uint32_t timeoutMs);
219 void setConnected(
bool connected);
221 void setMessageFilters(
const std::vector<FilterPtr> &filters);
222 void setMessageFilters();
223 void setMessageFilters(FilterPtr filterPtr);
225 const std::vector<FilterPtr> &
228 virtual bool isClientStub()
const;
232 void requestTransportFilters_Legacy(
const std::vector<FilterPtr> &filters);
233 void requestTransportFilters(
const std::vector<FilterPtr> &filters);
234 void requestTransportFilters(FilterPtr filterPtr);
235 void requestTransportFilters();
237 void clearTransportFilters();
240 void requestTransportFiltersAsync_Legacy(
241 const std::vector<FilterPtr> &filters,
242 boost::function0<void> onCompletion);
244 void requestTransportFiltersAsync(
245 const std::vector<FilterPtr> &filters,
246 boost::function0<void> onCompletion);
248 void requestTransportFiltersAsync(
250 boost::function0<void> onCompletion);
253 void setRemoteCallTimeoutMs(
unsigned int remoteCallTimeoutMs);
254 unsigned int getRemoteCallTimeoutMs()
const;
256 void setConnectTimeoutMs(
unsigned int connectTimeoutMs);
257 unsigned int getConnectTimeoutMs()
const;
259 void setAutoReconnect(
bool autoReconnect);
260 bool getAutoReconnect()
const;
262 void setAutoVersioning(
bool autoVersioning);
263 bool getAutoVersioning()
const;
265 void setRuntimeVersion(boost::uint32_t version);
266 boost::uint32_t getRuntimeVersion()
const;
268 void setArchiveVersion(boost::uint32_t version);
269 boost::uint32_t getArchiveVersion()
const;
271 void setClientProgressPtr(ClientProgressPtr clientProgressPtr);
273 ClientProgressPtr getClientProgressPtr()
const;
275 typedef ClientProgress::ProgressCallback RemoteCallProgressCallback;
277 void setRemoteCallProgressCallback(
278 RemoteCallProgressCallback cb,
279 boost::uint32_t callbackIntervalMs);
281 void setTries(std::size_t tries);
282 std::size_t getTries()
const;
284 void setUserData(boost::any userData);
285 boost::any getUserData();
292 #if RCF_FEATURE_LEGACY==1
294 void createRemoteObject(
const std::string &objectName =
"");
295 void deleteRemoteObject();
297 void createRemoteSessionObject(
const std::string &objectName =
"");
298 void deleteRemoteSessionObject();
302 #if RCF_FEATURE_FILETRANSFER==1
303 void setFileProgressCallback(FileProgressCb fileProgressCb);
304 void setFileProgressCallback() { setFileProgressCallback( FileProgressCb() ); }
307 const std::string & whichFile,
308 std::string & uploadId,
309 boost::uint32_t chunkSize,
310 boost::uint32_t transferRateBps,
311 boost::uint32_t sessionLocalId);
314 const FileManifest & whichFile,
315 std::string & uploadId,
316 boost::uint32_t chunkSize,
317 boost::uint32_t transferRateBps,
318 boost::uint32_t sessionLocalId);
321 const std::string & downloadLocation,
322 FileManifest & manifest,
323 boost::uint32_t chunkSize,
324 boost::uint32_t transferRateBps,
325 boost::uint32_t sessionLocalId);
327 boost::uint32_t addUploadStream(FileUpload fileStream);
328 void processUploadStreams();
330 boost::uint32_t addDownloadStream(FileDownload fileStream);
333 void setTransferWindowS(boost::uint32_t transferWindowS);
334 boost::uint32_t getTransferWindowS();
337 FutureImpl<Void> ping();
338 FutureImpl<Void> ping(
const CallOptions & callOptions);
340 ByteBuffer getOutOfBandRequest();
341 void setOutofBandRequest(ByteBuffer requestBuffer);
343 ByteBuffer getOutOfBandResponse();
344 void setOutofBandResponse(ByteBuffer responseBuffer);
346 FutureImpl<Void> doControlMessage(
347 const CallOptions & callOptions,
348 ByteBuffer controlRequest);
352 void setPingBackIntervalMs(
int pingBackIntervalMs);
353 int getPingBackIntervalMs();
355 std::size_t getPingBackCount();
356 boost::uint32_t getPingBackTimeStamp();
358 void clearParameters();
360 SerializationProtocolIn & getSpIn();
361 SerializationProtocolOut & getSpOut();
363 std::auto_ptr<Exception> getAsyncException();
364 void setAsyncException(std::auto_ptr<Exception>);
365 bool hasAsyncException();
367 boost::uint32_t generatePollingTimeout(boost::uint32_t timeoutMs);
368 void onPollingTimeout();
371 friend class CallOptions;
375 friend class FutureImplBase;
394 friend class AllocateClientParameters;
413 friend class ClientParameters;
416 RemoteCallSemantics mDefaultCallingSemantics;
417 SerializationProtocol mProtocol;
418 MarshalingProtocol mMarshalingProtocol;
419 std::string mEndpointName;
420 std::string mObjectName;
421 std::string mInterfaceName;
423 unsigned int mRemoteCallTimeoutMs;
424 unsigned int mConnectTimeoutMs;
429 EndpointPtr mEndpoint;
430 ClientTransportAutoPtr mTransport;
432 VectorFilter mMessageFilters;
434 ClientProgressPtr mClientProgressPtr;
436 bool mAutoVersioning;
437 boost::uint32_t mRuntimeVersion;
438 boost::uint32_t mArchiveVersion;
440 bool mUseNativeWstringSerialization;
441 bool mEnableSfPointerTracking;
443 std::vector<I_Future *> mFutures;
444 boost::any mUserData;
446 MethodInvocationRequest mRequest;
447 SerializationProtocolIn mIn;
448 SerializationProtocolOut mOut;
451 AsyncOpType mAsyncOpType;
452 boost::function0<void> mAsyncCallback;
453 std::auto_ptr<Exception> mAsyncException;
454 unsigned int mEndTimeMs;
456 RemoteCallSemantics mRcs;
457 ByteBuffer mEncodedByteBuffer;
458 std::vector<ByteBuffer> mEncodedByteBuffers;
460 std::vector<char> mRetValVec;
461 std::vector<char> mParametersVec;
462 I_Parameters * mpParameters;
464 boost::uint32_t mPingBackIntervalMs;
465 boost::uint32_t mPingBackTimeStamp;
466 std::size_t mPingBackCount;
468 boost::uint32_t mNextTimerCallbackMs;
469 boost::uint32_t mNextPingBackCheckMs;
470 boost::uint32_t mPingBackCheckIntervalMs;
471 boost::uint32_t mTimerIntervalMs;
473 MutexPtr mSignalledMutexPtr;
474 ConditionPtr mSignalledConditionPtr;
475 LockPtr mSignalledLockPtr;
479 Mutex mSubRcfClientMutex;
480 RcfClientPtr mSubRcfClientPtr;
483 ReallocBufferPtr mBatchBufferPtr;
484 ReallocBuffer mBatchBufferTemp;
485 boost::uint32_t mBatchMaxMessageLength;
486 boost::uint32_t mBatchCount;
487 boost::uint32_t mBatchMessageCount;
490 bool mSetTransportProtocol;
496 const std::string & interfaceName,
498 RCF::RemoteCallSemantics rcs);
507 RCF::RemoteCallSemantics rcs);
509 void onConnectCompleted(
510 bool alreadyConnected =
false);
512 void onRequestTransportFiltersCompleted();
516 void onSendCompleted();
518 void onReceiveCompleted();
520 void onTimerExpired();
523 const std::exception &e);
525 void setAsyncCallback(
526 boost::function0<void> callback);
529 const Exception & e);
531 void scheduleAmiNotification();
533 void createFilterSequence(std::vector<FilterPtr> & filters);
538 std::vector<char> & getRetValVec() {
return mRetValVec; }
542 void enableBatching();
543 void disableBatching(
bool flush =
true);
544 void flushBatch(
unsigned int timeoutMs = 0);
546 void setMaxBatchMessageLength(boost::uint32_t maxBatchMessageLength);
547 boost::uint32_t getMaxBatchMessageLength();
549 boost::uint32_t getBatchesSent();
550 boost::uint32_t getMessagesInCurrentBatch();
554 void setAsync(
bool async);
558 void waitForReady(boost::uint32_t timeoutMs = 0);
561 void setSubRcfClientPtr(RcfClientPtr clientStubPtr);
562 RcfClientPtr getSubRcfClientPtr();
566 void setRequestUserData(
const std::string & userData);
567 std::string getRequestUserData();
569 void setResponseUserData(
const std::string & userData);
570 std::string getResponseUserData();
572 #if RCF_FEATURE_FILETRANSFER==1
573 FileProgressCb mFileProgressCb;
575 std::vector<FileUpload> mUploadStreams;
576 std::vector<FileDownload> mDownloadStreams;
579 boost::uint32_t mTransferWindowS;
581 RecursionState<int, int> mRecursionState;
583 std::string mCurrentCallDesc;
584 bool mCallInProgress;
588 void setHttpProxy(
const std::string & httpProxy);
589 std::string getHttpProxy()
const;
591 void setHttpProxyPort(
int httpProxyPort);
592 int getHttpProxyPort()
const;
594 void setTransportProtocol(TransportProtocol protocol);
595 TransportProtocol getTransportProtocol()
const;
597 TransportType getTransportType();
599 void setUsername(
const tstring & username);
600 tstring getUsername()
const;
602 void setPassword(
const tstring & password);
603 tstring getPassword()
const;
605 void setHttpProxyUsername(
const tstring & proxyUsername);
606 tstring getHttpProxyUsername()
const;
608 void setHttpProxyPassword(
const tstring & proxyPassword);
609 tstring getHttpProxyPassword()
const;
611 void setHttpProxyRealm(
const tstring & proxyRealm);
612 tstring getHttpProxyRealm()
const;
614 void setKerberosSpn(
const tstring & kerberosSpn);
615 tstring getKerberosSpn()
const;
617 void setEnableCompression(
bool enableCompression);
618 bool getEnableCompression()
const;
620 void setCertificate(CertificatePtr certificatePtr);
621 CertificatePtr getCertificate()
const;
623 void setCaCertificate(CertificatePtr certificatePtr);
624 CertificatePtr getCaCertificate()
const;
626 void setOpenSslCipherSuite(
const std::string & cipherSuite);
627 std::string getOpenSslCipherSuite()
const;
629 void setEnableSchannelCertificateValidation(
const tstring & peerName);
630 tstring getEnableSchannelCertificateValidation()
const;
632 typedef boost::function<bool(Certificate *)> CertificateValidationCb;
633 void setCertificateValidationCallback(CertificateValidationCb certificateValidationCb);
634 const CertificateValidationCb & getCertificateValidationCallback()
const;
636 void setSslImplementation(SslImplementation sslImplementation);
637 SslImplementation getSslImplementation()
const;
640 void setWindowsImpersonationToken(HANDLE hToken);
641 HANDLE getWindowsImpersonationToken()
const;
644 std::auto_ptr<HANDLE> mWindowsImpersonationToken;
648 std::string mHttpProxy;
650 tstring mHttpProxyRealm;
651 TransportProtocol mTransportProtocol;
654 tstring mHttpProxyUsername;
655 tstring mHttpProxyPassword;
656 tstring mKerberosSpn;
657 bool mEnableCompression;
659 CertificatePtr mCertificatePtr;
660 CertificatePtr mCaCertificatePtr;
661 CertificateValidationCb mCertificateValidationCb;
662 tstring mSchannelCertificateValidation;
664 std::string mOpenSslCipherSuite;
666 SslImplementation mSslImplementation;
674 mRcsSpecified(false),
679 CallOptions(RemoteCallSemantics rcs) :
686 CallOptions(RemoteCallSemantics rcs,
const boost::function0<void> & callback) :
693 CallOptions(boost::function0<void> callback) :
695 mRcsSpecified(false),
700 RemoteCallSemantics apply(ClientStub &clientStub)
const
702 clientStub.setAsync(mAsync);
703 clientStub.setAsyncCallback(mCallback);
704 return mRcsSpecified ? mRcs : clientStub.getRemoteCallSemantics();
710 RemoteCallSemantics mRcs;
711 boost::function0<void> mCallback;
714 class RCF_EXPORT AsyncTwoway :
public CallOptions
717 AsyncTwoway(
const boost::function0<void> & callback) :
718 CallOptions(RCF::Twoway, callback)
722 class RCF_EXPORT AsyncOneway :
public CallOptions
725 AsyncOneway(
const boost::function0<void> & callback) :
726 CallOptions(RCF::Oneway, callback)
730 class RestoreClientTransportGuard
734 RestoreClientTransportGuard(ClientStub &client, ClientStub &clientTemp);
735 ~RestoreClientTransportGuard();
739 ClientStub &mClientTemp;
744 #endif // ! INCLUDE_RCF_CLIENTSTUB_HPP