TemplateRPC

Template RPC is an alternate way of approaching RPC, using templates. It is a small layer above RPC, to be used as-is, that allows you to do networking without having to write caller and dispatcher classes. This functionality is achieved by using a template caller, a template dispatcher, and by writing functors that act on the remote data.

Files and classes

TemplateDispatcherApp.C

TemplateDispatcherMain.C is linked into a library because it's not safe to have code that uses template classes that have not been defined in a library. It is best to assume that template classes should never be used in a binary. TemplateDispatcherApp.C which is linked into a binary, calls DispatcherMain() from TemplateDispatcherMain.C to avoid the problem.

TemplateRPCApp.C

TemplateCallerMain.C is linked into a library because it's not safe to have code that uses template classes that have not been defined in a library. It is best to assume that template classes should never be used in a binary. TemplateRPCApp.C which is linked into a binary, calls CallerMain() from TemplateCallerMain.C to avoid the problem.

TemplateDispatcherMain.C

The TQualityOfService object that is passed into the constructor of the TStandardServiceDefinition object determines whether the service is accessible to programs on remote machines or not. This example only allows for local access, not remote.

Users of TServiceDefinition must take care to properly increment the reference count after creating it. TServiceDefinition will delete itself when the reference count goes to zero, so you do not delete TServiceDefinition yourself.

TDispatcherThread::Dispatch() is a static member function that uses this thread to do the dispatching.

TemplateCallerMain.C

The call caller.ExitDispatcher() tells the dispatcher to shut down.

TemplateCallerMacros.h

This file contains versions of the MRemoteCaller macros that can handle having template classes passed into them. There are different macros for each permutation of having template or non-template callers, and template or non-template dispatchers.

StandardFunctorOn.h

TStandardFunctorOn is an abstract class that defines protocol for interacting with the object that's in a TDispatcherOn object. Derived classes have to override the function-call operator. The function-call operator will be handed an object of the type specified by the template parameter.

CalcFunctors.h

Defines two derived classes of TStandardFunctorOn. Both of these derived classes act on TRPNCalc objects.

CalcFunctors.C

Both classes override the function call operator and manipulate the TRPNCalc object that is handed to them. They both hold a result so that when they are streamed back to the caller (from the dispatcher) the caller can get the result.

RPNCalc.h

Defines an extremely simple RPN calculator. It only handles setting registers and getting values from the registers.

RPNCalc.C

Implements an x register and a y register.

ProtocolOn.h

Defines an abstract class that defines a protocol for accepting TStandardFunctorOn objects. Derived classes can decide what to do with the functor. TCallerOn sends the functor off to a dispatcher that uses the functor on its internal state. TImplementationOn takes the functor and directly applies it to its internal state.

ImplementationOn.h

A concrete derived class of MProtocolOn. It overrides MProtocolOn::Do() to take the functor that is passed-in as a parameter and applies it directly to its internal state object.

DispatcherOn.h

Defines a template dispatcher class. It takes care of receiving functors from TCallerOn objects and giving them to its internal implementation object. After its internal implementation object has used the functor, the TDispatcherOn object sends the functor back to the TCallerOn object.

CallerOn.h

A concrete derived class of MProtocolOn. It overrides MProtocolOn::Do() to take the functor that is passed-in as a parameter and sends it to a TDispatcherOn object. After the TDispatcherOn object has applied the functor to its internal state, it sends back the functor in case the functor is holding any information regarding its dealings with the state in the server.


Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.