19 #ifndef INCLUDE_RCF_RCFPROTO_HPP
20 #define INCLUDE_RCF_RCFPROTO_HPP
22 #include <RCF/GoogleProtobufs.hpp>
24 #include <RCF/RCF.hpp>
25 #include <RCF/ClientStub.hpp>
26 #include <RCF/Exception.hpp>
27 #include <RCF/Export.hpp>
28 #include <RCF/RemoteCallContext.hpp>
31 #include <RCF/Win32Certificate.hpp>
34 #if RCF_FEATURE_OPENSSL==1
36 #include <RCF/OpenSslEncryptionFilter.hpp>
44 PemCertificate(
const std::string & pathToCert,
const std::string & password =
"")
46 RCF_THROW(Exception(_RcfError_NotSupportedInThisBuild(
"PemCertificate")));
55 RCF_THROW(Exception(_RcfError_NotSupportedInThisBuild(
"X509Certificate")));
57 std::string getCertificateName() {
return "";}
58 std::string getIssuerName() {
return ""; }
65 #if RCF_FEATURE_SSPI==1
66 #include <RCF/Schannel.hpp>
69 #if RCF_FEATURE_NAMEDPIPE==1
70 #include <RCF/Win32NamedPipeEndpoint.hpp>
73 #if RCF_FEATURE_LOCALSOCKET==1
74 #include <RCF/UnixLocalEndpoint.hpp>
77 #if RCF_FEATURE_LOCALSOCKET==0
84 UnixLocalEndpoint(
const std::string & socketName) { RCF_THROW(Exception(_RcfError_NotSupportedInThisBuild(
"UnixLocalEndpoint"))); }
86 virtual std::auto_ptr<ServerTransport> createServerTransport()
const {
return std::auto_ptr<ServerTransport>(); }
87 virtual std::auto_ptr<ClientTransport> createClientTransport()
const {
return std::auto_ptr<ClientTransport>(); }
88 virtual EndpointPtr clone()
const {
return EndpointPtr(); }
89 virtual std::string asString()
const {
return std::string(); }
94 #endif // RCF_FEATURE_LOCALSOCKET==0
100 class RCF_EXPORT LogToDebugWindow :
public LogTarget
105 Exception e(_RcfError_SupportedOnWindowsOnly(
"LogToDebugWindow"));
108 virtual LogTarget * clone()
const {
return NULL; }
109 virtual void write(
const RCF::ByteBuffer & output) {}
112 class RCF_EXPORT LogToEventLog :
public LogTarget
115 LogToEventLog(
const std::string & appName,
int eventLogLevel)
117 Exception e(_RcfError_SupportedOnWindowsOnly(
"LogToEventLog"));
120 virtual LogTarget * clone()
const {
return NULL; }
121 virtual void write(
const RCF::ByteBuffer & output) {}
129 Exception e(_RcfError_SupportedOnWindowsOnly(
"Win32Certificate"));
133 virtual CertificateImplementationType _getType()
138 tstring getCertificateName() {
return tstring(); }
139 tstring getIssuerName() {
return tstring(); }
140 void exportToPfx(
const std::string & pfxFilePath) {}
142 Win32CertificatePtr findRootCertificate(
143 Win32CertificateLocation certStoreLocation,
144 Win32CertificateStore certStore) {
return Win32CertificatePtr(); }
153 const std::string & pathToCert,
154 const tstring & password,
155 const tstring & certName)
157 Exception e(_RcfError_SupportedOnWindowsOnly(
"PfxCertificate"));
162 Win32CertificateLocation certStoreLocation,
163 Win32CertificateStore certStore) {}
171 Win32CertificateLocation certStoreLocation,
172 Win32CertificateStore certStore,
173 const tstring & certName)
175 Exception e(_RcfError_SupportedOnWindowsOnly(
"StoreCertificate"));
179 void removeFromStore() {}
188 Win32CertificateLocation certStoreLocation,
189 Win32CertificateStore certStore)
191 Exception e(_RcfError_SupportedOnWindowsOnly(
"StoreCertificateIterator"));
195 bool moveNext() {
return false; }
197 Win32CertificatePtr current() {
return Win32CertificatePtr(); }
204 #if RCF_FEATURE_NAMEDPIPE==0
211 Win32NamedPipeEndpoint(
const tstring & pipeName) { RCF_THROW(Exception(_RcfError_SupportedOnWindowsOnly(
"Win32NamedPipeEndpoint"))); }
213 virtual std::auto_ptr<ServerTransport> createServerTransport()
const {
return std::auto_ptr<ServerTransport>(); }
214 virtual std::auto_ptr<ClientTransport> createClientTransport()
const {
return std::auto_ptr<ClientTransport>(); }
215 virtual EndpointPtr clone()
const {
return EndpointPtr(); }
216 virtual std::string asString()
const {
return std::string(); }
221 #endif // RCF_FEATURE_NAMEDPIPE==0
223 #if RCF_FEATURE_SSPI==0
229 #endif // RCF_FEATURE_SSPI==0
233 RCF_EXPORT
bool isProBuild();
235 class RcfProtoChannel;
236 class RcfProtoSession;
237 class RcfProtoController;
239 typedef boost::shared_ptr<RcfProtoController> RcfProtoControllerPtr;
248 virtual void Reset();
253 virtual bool Failed()
const;
256 virtual std::string ErrorText()
const;
261 virtual void StartCancel();
266 virtual bool Completed()
const;
278 virtual void SetFailed(
const std::string& reason);
283 virtual bool IsCanceled()
const;
292 virtual void NotifyOnCancel(google::protobuf::Closure* callback);
314 template<
typename T>
class RcfClient;
319 class RCF_EXPORT _SwigCallbackArgs
325 std::string mErrorString;
327 CertificatePtr mCertificatePtr;
333 class RCF_EXPORT _SwigCallback
340 virtual ~_SwigCallback();
346 virtual void ProtoRpcBegin(
347 _SwigCallbackArgs * args,
348 RcfProtoServer * server,
349 RcfProtoSession * session,
350 const std::string & serviceName,
354 virtual bool ValidateCertificate(
355 _SwigCallbackArgs * args);
361 class _SwigCallbackCpp :
public _SwigCallback
364 _SwigCallbackCpp(RcfProtoChannel & channel);
368 RcfProtoChannel & mChannel;
377 void _CallMethodSwig(
378 const std::string& serviceName,
380 unsigned char * szBuffer,
382 _SwigCallback * closure);
384 int _GetResponseBufferLength()
const;
385 void _GetResponseBuffer(
unsigned char * szBuffer,
int bufferLen)
const;
388 void _CallMethodSwig(
389 const std::string& serviceName,
393 _SwigCallback * closure);
395 void _GetResponseBuffer(
char * szBuffer,
size_t bufferLen)
const;
403 void _CallMethodSwig_WithCopy(
404 const std::string& serviceName,
406 const std::string& strBuffer,
407 _SwigCallback * closure);
409 std::string _GetResponseBuffer_WithCopy()
const;
420 std::string ErrorText();
440 void setMaxMessageLength(std::size_t maxMessageSize);
443 std::size_t getMaxMessageLength()
const;
446 void setRemoteCallTimeoutMs(
unsigned int remoteCallTimeoutMs);
449 unsigned int getRemoteCallTimeoutMs()
const;
452 void setConnectTimeoutMs(
unsigned int connectTimeoutMs);
455 unsigned int getConnectTimeoutMs()
const;
458 void setTransportProtocol(RCF::TransportProtocol protocol);
461 RCF::TransportProtocol getTransportProtocol();
464 void setAsynchronousRpcMode(
bool enable);
467 bool getAsynchronousRpcMode();
472 void setPingBackIntervalMs(
int pingBackIntervalMs);
475 int getPingBackIntervalMs();
478 void setHttpProxy(
const std::string & httpProxy);
481 std::string getHttpProxy();
484 void setHttpProxyPort(
int httpProxyPort);
487 int getHttpProxyPort();
490 TransportType getTransportType();
493 void setUsername(
const tstring & username);
496 tstring getUsername();
499 void setPassword(
const tstring & password);
502 tstring getPassword();
505 void setKerberosSpn(
const tstring & kerberosSpn);
508 tstring getKerberosSpn();
511 void setEnableCompression(
bool enableCompression);
514 bool getEnableCompression();
517 void setCertificate(CertificatePtr certificatePtr);
520 CertificatePtr getCertificate();
523 void setCaCertificate(CertificatePtr certificatePtr);
526 CertificatePtr getCaCertificate();
529 void setOpenSslCipherSuite(
const std::string & cipherSuite);
532 std::string getOpenSslCipherSuite()
const;
536 void setEnableSchannelCertificateValidation(
const tstring & peerName);
539 tstring getEnableSchannelCertificateValidation()
const;
541 void _setCertificateValidationCallback(_SwigCallback * pcb);
544 void setSslImplementation(SslImplementation sslImplementation);
547 SslImplementation getSslImplementation()
const;
561 virtual void CallMethod(
562 const google::protobuf::MethodDescriptor * method,
563 google::protobuf::RpcController * controller,
564 const google::protobuf::Message * request,
565 google::protobuf::Message * response,
566 google::protobuf::Closure * done);
569 void CallMethodInternal(
570 const std::string & serviceName,
572 RCF::ByteBuffer requestBuffer,
573 _SwigCallback * closure);
577 friend class _SwigCallbackCpp;
578 _SwigCallbackCpp mSwigCallbackCpp;
580 void onCompletionCpp();
583 boost::shared_ptr< RcfClient<I_Pb> > mRcfClientPtr;
585 const google::protobuf::Message * mpRequest;
586 google::protobuf::Message * mpResponse;
587 google::protobuf::Closure * mpClosure;
589 _SwigCallback * mpSwigCallback;
591 boost::function<void()> mCompletionHandlerSwig;
593 RCF::Future<RCF::ByteBuffer> mFuture;
594 RCF::Exception mError;
595 RCF::ByteBuffer mResponseBuffer;
597 std::string mRequestCopy;
605 typedef RCF::RemoteCallContext<
609 RCF::ByteBuffer> RcfProtoContext;
612 typedef boost::shared_ptr<RcfProtoSession> RcfProtoSessionPtr;
622 int _GetRequestBufferLength();
625 void _GetRequestBuffer(
unsigned char * szBuffer,
int szBufferLen);
626 void _SetResponseBuffer(
unsigned char * szBuffer,
int szBufferLen);
629 void _GetRequestBuffer(
char * szBuffer,
size_t szBufferLen);
630 void _SetResponseBuffer(
char * szBuffer,
size_t szBufferLen);
639 void SetFailed(
const std::string& reason);
644 bool IsCanceled()
const;
646 void _Commit(
const std::string& errorMsg);
649 std::string _GetRequestBuffer_WithCopy();
651 void _SetResponseBuffer_WithCopy(
const std::string& buffer);
654 tstring getClientUsername();
657 TransportProtocol getTransportProtocol();
660 TransportType getTransportType();
663 bool getEnableCompression();
666 std::size_t getConnectionDuration()
const;
669 std::size_t getRemoteCallCount()
const;
672 boost::uint64_t getTotalBytesReceived()
const;
675 boost::uint64_t getTotalBytesSent()
const;
691 void NotifyOnCancel(google::protobuf::Closure * callback);
693 RcfSession& getRcfSession();
699 RcfSession & mRcfSession;
701 RcfProtoContext mServerContext;
703 RCF::ByteBuffer mRequestBuffer;
704 RCF::ByteBuffer mResponseBuffer;
707 typedef boost::shared_ptr<google::protobuf::Message> MessagePtr;
727 void _setCallbackTable(_SwigCallback * pCallback);
730 void setThreadPool(ThreadPoolPtr threadPoolPtr) { RcfServer::setThreadPool(threadPoolPtr); }
745 void setSupportedTransportProtocols(
746 const std::vector<TransportProtocol> & protocols) { RcfServer::setSupportedTransportProtocols(protocols); }
749 const std::vector<TransportProtocol> &
754 void setSessionTimeoutMs(boost::uint32_t sessionTimeoutMs) {
return RcfServer::setSessionTimeoutMs(sessionTimeoutMs); }
767 void setCertificate(CertificatePtr certificatePtr) { RcfServer::setCertificate(certificatePtr); }
779 void setCaCertificate(CertificatePtr certificatePtr) { RcfServer::setCaCertificate(certificatePtr); }
792 void setSslImplementation(SslImplementation sslImplementation) { RcfServer::setSslImplementation(sslImplementation); }
806 void bindService(google::protobuf::Service & service);
808 RCF::ByteBuffer DoProtoRpc(
809 const std::string & serviceName,
811 RCF::ByteBuffer requestBuffer);
815 void ProtoRpcBeginCpp(
817 const std::string & serviceName,
821 std::pair<MessagePtr, MessagePtr> requestResponsePair,
822 RcfProtoControllerPtr controllerPtr);
824 typedef std::map<std::string, google::protobuf::Service *> ProtobufServices;
826 ProtobufServices mProtobufServices;
828 _SwigCallback * mpSwigCallback;
831 class BoostBindClosure :
public google::protobuf::Closure
840 BoostBindClosure(
const boost::function<
void()> & func,
bool permanent =
false) :
842 mPermanent(permanent)
846 void assign(
const boost::function<
void()> & func,
bool permanent =
true)
849 mPermanent = permanent;
861 boost::function<void()> mFunc;
867 #endif // ! INCLUDE_RCF_RCFPROTO_HPP