// $Revision: 1.4 $ // Copyright (C) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_DISPATCHERON #define TaligentSamples_DISPATCHERON #ifndef TaligentSamples_PROTOCOLON #include "ProtocolOn.h" #endif #ifndef Taligent_REMOTEDISPATCHER #include // Included for MRemoteDispatcher. #endif #ifndef TaligentSamples_IMPLEMENTATIONON #include "ImplementationOn.h" #endif #ifndef TaligentSamples_STANDARDFUNCTORON #include "StandardFunctorOn.h" #endif #ifndef IOSTREAMH #include // Included for cout #endif //---- TDispatcherOn ----------------------------------------------------------- template class TDispatcherOn : public MRemoteDispatcher { public: TaligentTypeExtensionTemplateDeclarationsMacro(TDispatcherOn,AType) public: TDispatcherOn(TImplementationOn* adoptedImplementation); virtual ~TDispatcherOn(); enum EAdditionRequest { kDo, kLastRequest = kDo }; protected: TDispatcherOn(); void DoStub(TStream& argStream, TStream& resultStream); private: // The following member functions are privatized because MRemoteDispatcher requires that // they won't be called. TDispatcherOn(const TDispatcherOn& source) {} TDispatcherOn& operator=(const TDispatcherOn& source) {return *this;} virtual TStream& operator>>=(TStream& toStream) const {return toStream;} virtual TStream& operator<<=(TStream& fromStream) {return fromStream;} enum {kOriginalVersion}; TImplementationOn* fImplementation; }; //---- TDispatcherOn --------------------------------------------------------- TaligentTypeExtensionTemplateMacro(TDispatcherOn,AType) template TDispatcherOn::TDispatcherOn() : MRemoteDispatcher(), fImplementation(NIL) { } template TDispatcherOn::TDispatcherOn(TImplementationOn* adoptedImplementation) : MRemoteDispatcher(), fImplementation(adoptedImplementation) { static RequestEntry requests[] = { {kDo, (RemoteFnPtr)&TDispatcherOn::DoStub}, // The following constant is very important to include in the request entry. {MRemoteCaller::kUnknownRequest} }; RegisterRequests(TStandardText(typeid(*this).name()), kLastRequest, requests); } template TDispatcherOn::~TDispatcherOn() { delete fImplementation; } template void TDispatcherOn::DoStub(TStream& argStream, TStream& resultStream) { ::Assertion(fImplementation != NIL, "\nCannot have a NIL implementation!\n"); TStandardFunctorOn* functor; ::Resurrect(functor, argStream); fImplementation->Do(*functor); ReturnSuccess(resultStream); *functor >>= resultStream; } #endif