// $Revision: 1.4 $ // Copyright (C) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_TCALLERON #define TaligentSamples_TCALLERON #ifndef Taligent_REMOTECALLER #include #endif #ifndef Taligent_SERVICEACCESS #include #endif #ifndef TaligentSamples_PROTOCOLON #include "ProtocolOn.h" #endif #ifndef TaligentSamples_STANDARDFUNCTORON #include "StandardFunctorOn.h" #endif #ifndef TaligentSamples_DISPATCHERON #include "DispatcherOn.h" #endif #ifndef Taligent_ASSERTIONS #include #endif #ifndef TaligentSamples_TEMPLATECALLERMACROS #include "TemplateCallerMacros.h" #endif class TMessageStreamsTransport; //---- TCallerOn ----------------------------------------------------------- template class TCallerOn : public MRemoteCaller, public MProtocolOn { public: TaligentTypeExtensionTemplateDeclarationsMacro(TCallerOn,AType) public: TCallerOn(); TCallerOn(const TServiceReference& serviceReference); TCallerOn(const TCallerOn& source); virtual ~TCallerOn(); virtual TStream& operator>>=(TStream& toStream) const; virtual TStream& operator<<=(TStream& fromStream); virtual void Do(TStandardFunctorOn& functor); MRemoteCallerTemplateDeclarationsMacro() private: TCallerOn& operator=(const TCallerOn& source); private: enum {kOriginalVersion}; TServiceReference* fServiceReference; TMessageStreamsTransport* fTransport; }; //---- TCallerOn --------------------------------------------------------- MRemoteCallerTemplateCallerAndTemplateDispatcherDefinitionsMacro(TCallerOn,TDispatcherOn,AType) TaligentTypeExtensionTemplateMacro(TCallerOn,AType) template TCallerOn::TCallerOn() : MRemoteCaller(), MProtocolOn(), fServiceReference(NIL), fTransport(NIL) { MRemoteCallerEnable(); } template TCallerOn::TCallerOn(const TServiceReference& serviceReference) : MRemoteCaller(), MProtocolOn(), fServiceReference(NIL), fTransport(NIL) { MRemoteCallerEnable(); fServiceReference = ::Copy(serviceReference); fTransport = new TMessageStreamsTransport(new TRequestSenderStream(*fServiceReference)); SetTransport(fTransport); } template TCallerOn::TCallerOn(const TCallerOn& source) : MRemoteCaller(), fServiceReference(NIL), fTransport(NIL) { fServiceReference = ::CopyPointer(source.fServiceReference); fTransport = new TMessageStreamsTransport(new TRequestSenderStream(*fServiceReference)); SetTransport(fTransport); } template TCallerOn::~TCallerOn() { delete fTransport; } template TCallerOn& TCallerOn::operator=(const TCallerOn& source) { // Can't be done because you can't change the transport you are using. // This member function has been privatized due to this. return *this; } template TStream& TCallerOn::operator>>=(TStream& toStream) const { ::WriteVersion(toStream, kOriginalVersion); ::Flatten(fServiceReference, toStream); return toStream; } template TStream& TCallerOn::operator<<=(TStream& fromStream) { ::ReadVersion(fromStream, kOriginalVersion, kOriginalVersion); delete fServiceReference; ::Resurrect(fServiceReference, fromStream); delete fTransport; fTransport = new TMessageStreamsTransport(new TRequestSenderStream(*fServiceReference)); SetTransport(fTransport); return fromStream; } template void TCallerOn::Do(TStandardFunctorOn& functor) { try { TStream& argumentStream = *BeginRequest(TDispatcherOn::kDo); ::Flatten(&functor, argumentStream); TStream& resultStream = *SendRequest(); functor <<= resultStream; EndRequest(); } catch (TRemoteCallException& exception) { cout << endl << "*** Remote call failed. ***" << endl; } catch (TStandardException& exception) { cout << endl << "*** Encountered an error while making remote call. ***" << endl; } catch (...) { cout << endl << "*** Encountered a completely unknown error while making remote call. ***" << endl; } } #endif