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/ClientProgress.hpp>
32 #include <RCF/Filter.hpp>
33 #include <RCF/ClientTransport.hpp>
34 #include <RCF/Endpoint.hpp>
35 #include <RCF/Enums.hpp>
36 #include <RCF/Export.hpp>
37 #include <RCF/GetInterfaceName.hpp>
38 #include <RCF/MethodInvocation.hpp>
39 #include <RCF/OverlappedAmi.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 InProcessTransport;
151 class RCF_EXPORT CurrentClientStubSentry
154 CurrentClientStubSentry(ClientStub & clientStub);
155 ~CurrentClientStubSentry();
158 class RCF_EXPORT ClientStub :
159 public ClientTransportCallback,
160 public boost::enable_shared_from_this<ClientStub>
163 ClientStub(
const std::string &interfaceName);
164 ClientStub(
const std::string &interfaceName,
const std::string &objectName);
165 ClientStub(
const ClientStub &rhs);
168 ClientStub &operator=(
const ClientStub &rhs);
170 void setEndpoint(
const Endpoint &endpoint);
171 void setEndpoint(EndpointPtr endpointPtr);
172 EndpointPtr getEndpoint()
const;
173 Token getTargetToken()
const;
174 void setTargetToken(Token token);
175 const std::string & getTargetName()
const;
176 void setTargetName(
const std::string &targetName);
177 void setInterfaceName(
const std::string & interfaceName);
178 const std::string & getInterfaceName();
179 RemoteCallSemantics getRemoteCallSemantics()
const;
180 void setRemoteCallSemantics(RemoteCallSemantics defaultCallingSemantics);
183 RemoteCallSemantics getDefaultCallingSemantics()
const;
184 void setDefaultCallingSemantics(RemoteCallSemantics defaultCallingSemantics);
186 void setSerializationProtocol(SerializationProtocol protocol);
187 SerializationProtocol getSerializationProtocol()
const;
189 void setMarshalingProtocol(MarshalingProtocol protocol);
190 MarshalingProtocol getMarshalingProtocol()
const;
192 bool getNativeWstringSerialization();
193 void setNativeWstringSerialization(
bool enable);
195 void setEnableSfPointerTracking(
bool enable);
196 bool getEnableSfPointerTracking()
const;
198 void setTransport(ClientTransportAutoPtr transport);
200 ClientTransport& getTransport();
201 IpClientTransport & getIpTransport();
203 ClientTransportAutoPtr releaseTransport();
205 void instantiateTransport();
207 void connectAsync(boost::function0<void> onCompletion);
208 void wait(boost::function0<void> onCompletion, boost::uint32_t timeoutMs);
211 void setConnected(
bool connected);
213 void setMessageFilters(
const std::vector<FilterPtr> &filters);
214 void setMessageFilters();
215 void setMessageFilters(FilterPtr filterPtr);
217 const std::vector<FilterPtr> &
222 void requestTransportFilters(
const std::vector<FilterPtr> &filters);
223 void requestTransportFilters(FilterPtr filterPtr);
224 void requestTransportFilters();
226 void clearTransportFilters();
229 void requestTransportFiltersAsync(
230 const std::vector<FilterPtr> &filters,
231 boost::function0<void> onCompletion);
233 void requestTransportFiltersAsync(
235 boost::function0<void> onCompletion);
237 void setRemoteCallTimeoutMs(
unsigned int remoteCallTimeoutMs);
238 unsigned int getRemoteCallTimeoutMs()
const;
240 void setConnectTimeoutMs(
unsigned int connectTimeoutMs);
241 unsigned int getConnectTimeoutMs()
const;
243 void setAutoReconnect(
bool autoReconnect);
244 bool getAutoReconnect()
const;
246 void setAutoVersioning(
bool autoVersioning);
247 bool getAutoVersioning()
const;
249 void setRuntimeVersion(boost::uint32_t version);
250 boost::uint32_t getRuntimeVersion()
const;
252 void setArchiveVersion(boost::uint32_t version);
253 boost::uint32_t getArchiveVersion()
const;
255 void setClientProgressPtr(ClientProgressPtr clientProgressPtr);
258 getClientProgressPtr()
const;
260 typedef ClientProgress::ProgressCallback RemoteCallProgressCallback;
262 void setRemoteCallProgressCallback(
263 RemoteCallProgressCallback cb,
264 boost::uint32_t callbackIntervalMs);
266 void setTries(std::size_t tries);
267 std::size_t getTries()
const;
269 void setUserData(boost::any userData);
270 boost::any getUserData();
277 void createRemoteObject(
const std::string &objectName =
"");
278 void deleteRemoteObject();
280 void createRemoteSessionObject(
const std::string &objectName =
"");
281 void deleteRemoteSessionObject();
283 #if RCF_FEATURE_FILETRANSFER==1
284 void setFileProgressCallback(FileProgressCb fileProgressCb);
285 void setFileProgressCallback() { setFileProgressCallback( FileProgressCb() ); }
288 const std::string & whichFile,
289 std::string & uploadId,
290 boost::uint32_t chunkSize,
291 boost::uint32_t transferRateBps,
292 boost::uint32_t sessionLocalId);
295 const FileManifest & whichFile,
296 std::string & uploadId,
297 boost::uint32_t chunkSize,
298 boost::uint32_t transferRateBps,
299 boost::uint32_t sessionLocalId);
302 const std::string & downloadLocation,
303 FileManifest & manifest,
304 boost::uint32_t chunkSize,
305 boost::uint32_t transferRateBps,
306 boost::uint32_t sessionLocalId);
308 boost::uint32_t addUploadStream(FileUpload fileStream);
309 void processUploadStreams();
311 boost::uint32_t addDownloadStream(FileDownload fileStream);
314 void setTransferWindowS(boost::uint32_t transferWindowS);
315 boost::uint32_t getTransferWindowS();
318 FutureImpl<Void> ping();
319 FutureImpl<Void> ping(
const CallOptions & callOptions);
323 void setPingBackIntervalMs(
int pingBackIntervalMs);
324 int getPingBackIntervalMs();
326 std::size_t getPingBackCount();
327 boost::uint32_t getPingBackTimeStamp();
329 void clearParameters();
331 SerializationProtocolIn & getSpIn();
332 SerializationProtocolOut & getSpOut();
334 std::auto_ptr<Exception> getAsyncException();
335 void setAsyncException(std::auto_ptr<Exception>);
336 bool hasAsyncException();
338 boost::uint32_t generatePollingTimeout(boost::uint32_t timeoutMs);
339 void onPollingTimeout();
342 friend class CallOptions;
347 friend class FutureImpl;
366 friend class AllocateClientParameters;
385 friend class ClientParameters;
387 friend class InProcessTransport;
390 RemoteCallSemantics mDefaultCallingSemantics;
391 SerializationProtocol mProtocol;
392 MarshalingProtocol mMarshalingProtocol;
393 std::string mEndpointName;
394 std::string mObjectName;
395 std::string mInterfaceName;
397 unsigned int mRemoteCallTimeoutMs;
398 unsigned int mConnectTimeoutMs;
403 EndpointPtr mEndpoint;
404 ClientTransportAutoPtr mTransport;
406 VectorFilter mMessageFilters;
408 ClientProgressPtr mClientProgressPtr;
410 bool mAutoVersioning;
411 boost::uint32_t mRuntimeVersion;
412 boost::uint32_t mArchiveVersion;
414 bool mUseNativeWstringSerialization;
415 bool mEnableSfPointerTracking;
417 std::vector<I_Future *> mFutures;
418 boost::any mUserData;
420 MethodInvocationRequest mRequest;
421 SerializationProtocolIn mIn;
422 SerializationProtocolOut mOut;
425 OverlappedAmi::AsyncOpType mAsyncOpType;
426 boost::function0<void> mAsyncCallback;
427 std::auto_ptr<Exception> mAsyncException;
428 unsigned int mEndTimeMs;
430 RemoteCallSemantics mRcs;
431 ByteBuffer mEncodedByteBuffer;
432 std::vector<ByteBuffer> mEncodedByteBuffers;
434 std::vector<char> mRetValVec;
435 std::vector<char> mParametersVec;
436 I_Parameters * mpParameters;
438 boost::uint32_t mPingBackIntervalMs;
439 boost::uint32_t mPingBackTimeStamp;
440 std::size_t mPingBackCount;
442 boost::uint32_t mNextTimerCallbackMs;
443 boost::uint32_t mNextPingBackCheckMs;
444 boost::uint32_t mPingBackCheckIntervalMs;
445 boost::uint32_t mTimerIntervalMs;
447 MutexPtr mSignalledMutexPtr;
448 ConditionPtr mSignalledConditionPtr;
449 LockPtr mSignalledLockPtr;
453 Mutex mSubRcfClientMutex;
454 RcfClientPtr mSubRcfClientPtr;
457 ReallocBufferPtr mBatchBufferPtr;
458 ReallocBuffer mBatchBufferTemp;
459 boost::uint32_t mBatchMaxMessageLength;
460 boost::uint32_t mBatchCount;
461 boost::uint32_t mBatchMessageCount;
464 bool mSetTransportProtocol;
470 const std::string & interfaceName,
472 RCF::RemoteCallSemantics rcs);
481 RCF::RemoteCallSemantics rcs);
483 void onConnectCompleted(
484 bool alreadyConnected =
false);
486 void onRequestTransportFiltersCompleted();
490 void onSendCompleted();
492 void onReceiveCompleted();
494 void onTimerExpired();
497 const std::exception &e);
499 void setAsyncCallback(
500 boost::function0<void> callback);
503 const Exception & e);
505 void scheduleAmiNotification();
507 void createFilterSequence(std::vector<FilterPtr> & filters);
512 std::vector<char> & getRetValVec() {
return mRetValVec; }
516 void enableBatching();
517 void disableBatching(
bool flush =
true);
518 void flushBatch(
unsigned int timeoutMs = 0);
520 void setMaxBatchMessageLength(boost::uint32_t maxBatchMessageLength);
521 boost::uint32_t getMaxBatchMessageLength();
523 boost::uint32_t getBatchesSent();
524 boost::uint32_t getMessagesInCurrentBatch();
528 void setAsync(
bool async);
532 void waitForReady(boost::uint32_t timeoutMs = 0);
535 void setSubRcfClientPtr(RcfClientPtr clientStubPtr);
536 RcfClientPtr getSubRcfClientPtr();
540 void setRequestUserData(
const std::string & userData);
541 std::string getRequestUserData();
543 void setResponseUserData(
const std::string & userData);
544 std::string getResponseUserData();
546 #if RCF_FEATURE_FILETRANSFER==1
547 FileProgressCb mFileProgressCb;
549 std::vector<FileUpload> mUploadStreams;
550 std::vector<FileDownload> mDownloadStreams;
553 boost::uint32_t mTransferWindowS;
555 RecursionState<int, int> mRecursionState;
557 std::string mCurrentCallDesc;
558 bool mCallInProgress;
562 void setHttpProxy(
const std::string & httpProxy);
563 std::string getHttpProxy();
565 void setHttpProxyPort(
int httpProxyPort);
566 int getHttpProxyPort();
568 void setTransportProtocol(TransportProtocol protocol);
569 TransportProtocol getTransportProtocol();
571 TransportType getTransportType();
573 void setUsername(
const tstring & username);
574 tstring getUsername();
576 void setPassword(
const tstring & password);
577 tstring getPassword();
579 void setKerberosSpn(
const tstring & kerberosSpn);
580 tstring getKerberosSpn();
582 void setEnableCompression(
bool enableCompression);
583 bool getEnableCompression();
585 void setCertificate(CertificatePtr certificatePtr);
586 CertificatePtr getCertificate();
588 void setCaCertificate(CertificatePtr certificatePtr);
589 CertificatePtr getCaCertificate();
591 void setOpenSslCipherSuite(
const std::string & cipherSuite);
592 std::string getOpenSslCipherSuite()
const;
594 void setEnableSchannelCertificateValidation(
const tstring & peerName);
595 tstring getEnableSchannelCertificateValidation()
const;
597 typedef boost::function<bool(Certificate *)> CertificateValidationCb;
598 void setCertificateValidationCallback(CertificateValidationCb certificateValidationCb);
599 const CertificateValidationCb & getCertificateValidationCallback()
const;
601 void setSslImplementation(SslImplementation sslImplementation);
602 SslImplementation getSslImplementation()
const;
605 void setWindowsImpersonationToken(HANDLE hToken);
606 HANDLE getWindowsImpersonationToken()
const;
608 std::auto_ptr<HANDLE> mWindowsImpersonationToken;
612 std::string mHttpProxy;
614 TransportProtocol mTransportProtocol;
617 tstring mKerberosSpn;
618 bool mEnableCompression;
620 CertificatePtr mCertificatePtr;
621 CertificatePtr mCaCertificatePtr;
622 CertificateValidationCb mCertificateValidationCb;
623 tstring mSchannelCertificateValidation;
625 std::string mOpenSslCipherSuite;
627 SslImplementation mSslImplementation;
635 mRcsSpecified(false),
640 CallOptions(RemoteCallSemantics rcs) :
647 CallOptions(RemoteCallSemantics rcs,
const boost::function0<void> & callback) :
654 CallOptions(boost::function0<void> callback) :
656 mRcsSpecified(false),
661 RemoteCallSemantics apply(ClientStub &clientStub)
const
663 clientStub.setAsync(mAsync);
664 clientStub.setAsyncCallback(mCallback);
665 return mRcsSpecified ? mRcs : clientStub.getRemoteCallSemantics();
671 RemoteCallSemantics mRcs;
672 boost::function0<void> mCallback;
675 class RCF_EXPORT AsyncTwoway :
public CallOptions
678 AsyncTwoway(
const boost::function0<void> & callback) :
679 CallOptions(RCF::Twoway, callback)
683 class RCF_EXPORT AsyncOneway :
public CallOptions
686 AsyncOneway(
const boost::function0<void> & callback) :
687 CallOptions(RCF::Oneway, callback)
691 class RestoreClientTransportGuard
695 RestoreClientTransportGuard(ClientStub &client, ClientStub &clientTemp) :
697 mClientTemp(clientTemp)
700 ~RestoreClientTransportGuard()
703 mClient.setTransport(mClientTemp.releaseTransport());
709 ClientStub &mClientTemp;
715 #endif // ! INCLUDE_RCF_CLIENTSTUB_HPP