While a dispatcher is similar to a caller in that its member functions act as stubs to the remote dispatcher implementations, dispatcher classes do not inherit from the abstract base class that defines the interface of the remote calls. This is because the dispatcher stubs must accept specific arguments that do not match the arguments of the remote call interface.
To define a dispatcher you:
In the declaration for your dispatcher class:
class TAdditionDispatcher : public MRemoteDispatcher { public: TaligentTypeExtensionDeclarationsMacro(TAdditionDispatcher) public: TAdditionDispatcher(TAdditionImplementation* adoptedImplementation); virtual ~TAdditionDispatcher(); enumEAdditionRequest { kAdd, kAddOne, kLastRequest = kAddOne }; protected: TAdditionDispatcher(); void AddStub(TStream& argStream, TStream& resultStream); void AddOneStub(TStream& argStream, TStream& resultStream); private: TAdditionDispatcher(const TAdditionDispatcher& source) {} TAdditionDispatcher&operator=(const TAdditionDispatcher& source) {return *this;} virtual TStream& operator>>=(TStream& toStream) const {return toStream;} virtual TStream& operator<<=(TStream& fromStream) {return fromStream;} enum {kOriginalVersion}; TAdditionImplementation*fImplementation; };
In the dispatcher class constructor:
TAdditionDispatcher::TAdditionDispatcher(TAdditionImplementation* adoptedImplementation) : MRemoteDispatcher(), fImplementation(adoptedImplementation) { ::Assertion(adoptedImplementation != NIL, "\nCannot adopt a NIL implementation!\n"); static RequestEntry requests[] = { {kAdd, (RemoteFnPtr)&TAdditionDispatcher::AddStub}, {kAddOne, (RemoteFnPtr)&TAdditionDispatcher::AddOneStub}, {MRemoteCaller::kUnknownRequest} }; RegisterRequests(TStandardText("TAdditionDispatcher"), kLastRequest, requests); }
void TAdditionDispatcher::AddStub(TStream& argStream, TStream& resultStream) { ::Assertion(fImplementation != NIL, "\nNIL implementation!\n"); long num1; long num2; num1 <<= argStream; num2 <<= argStream; long result = fImplementation->Add(num1, num2); ReturnSuccess(resultStream); result >>= resultStream; }