Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Examples

GetAsync.cpp

This is an example of how to use the asynchronous get call. The program reads and prints a value of the device property specified by the command line arguments (device name, property name, cycle selector).
See also:
Example.h
#include "Example.h"

//
// A simple reply handler which prints the call result (a value or an 
// error) on stdout and terminates the application.
//
class AsyncReplyHandler : public rdaReplyHandler
{
   public:

      virtual void handleReply(const rdaRequest&, const rdaData& value)
      {
         cout << value;
         exit(0);
      }

      virtual void handleError(const rdaRequest&, const rdaException& ex)
      {
         cout << ex << endl;
         exit(0);
      }
};

int main(int argc, char** argv)
{
   //
   // Set device call parameters (deviceName, property, cycle) from
   // the command line arguments (see Example.h).
   //
   setParameters(argc, argv);

   try
   {
      //
      // Initialize RDA and obtain the device handle
      //
      rdaRDAService* rda = rdaRDAService::init();
      rdaDeviceHandle* device = rda->getDeviceHandle(deviceName);
      //
      // Create a callback object that will receive results of the call
      //
      AsyncReplyHandler rh;
      //
      // Send to the device a request to read the property value
      //
      if (cycle == 0) device->get(property, &rh);
      else device->get(property, cycle, &rh);
      //
      // Wait for results
      //
      sleepForever(); // see Example.h
   }
   catch(const rdaException& ex)
   {
      cout << ex << endl;
   }
   catch(const rdaInternalError& ex)
   {
      cout << ex << endl;
   }
   return 0;
}

RDA-2.3 documentation - 27 Jun 2007 - N.Trofimov