Using TDispatcherThread

TDispatcherThread derives from TThread. You instantiate this class by passing it the incoming stream (from the caller) and the dispatcher that you want to run. The incoming stream must be an instance of TReceiverStream.

TDispatcherThread::Main processes requests by:

  1. Calling the Receive function of the receiver stream.
  2. Running the dispatcher's DispatchRequest function, passing the argument stream.
  3. Sending the result stream (the reply) back to the caller, via the Reply function of the stream.
One way to create a dispatcher and start it processing (using TDispatcherThread) is to:

  1. Create a service definition.
    The Service Access framework provides service definition classes for several types of services. Read Chapter 4, "Communications access," in OS Services.
  2. Create a pointer to the dispatcher implementation object.
  3. Instantiate a TRequestReceiverStream using the service definition object.
  4. Create a dispatcher object, passing in a dispatcher implementation object.
  5. Instantiate TDispatcherThread, passing the pointer to the receiver stream and a new dispatcher.
    The TDispatcherThread object adopts the receiver stream and the dispatcher.
  6. Call the Start function to start the thread.
  7. Call WaitForDeath.
This example shows the main() for the calculator dispatcher:

      void
      main()
      {
          
    TQualityOfService serviceQuality(TQualityOfService::kSameHost);
      
          TStandardServiceDefinition* serviceDefinition =
              new TStandardServiceDefinition( 
                  TLocalObjectName("RPCAdditionDispatcher"), serviceQuality);
          
          
    TAdditionImplementation* dispatcherImp = new TAdditionImplementation;
              
          TRequestReceiverStream* receiverStream 
              = new TRequestReceiverStream(serviceDefinition);
          
          
    TAdditionDispatcher* dispatcher = new TAdditionDispatcher(dispatcherImp);
          
          
    TDispatcherThread thread(receiverStream, dispatcher);
          thread.Start();
          thread.WaitForDeath();
      }

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

Generated with WebMaker