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

Subscription.cpp

This is an example of how to use rdaSubscription objects. This program:
See also:
Example.h
#include "Example.h"
#include <rda/Subscription.h>

//
// This class provides a simple implementation of the callback methods
// defined in the rdaSubscription class.
//
class SimpleSubscription : public rdaSubscription
{
   int counter;

   public:
   
      SimpleSubscription(const char* device, 
                         const char* prop, 
                         const char* cycle)
      : rdaSubscription(device, prop, cycle, 0, false), counter(10) {}

      virtual ~SimpleSubscription() {}
      
   protected:

      virtual void rejected(const rdaException& why)
      {
         cout << "REJECTED (" << why << ")\n";
         delete this;
         exit(1);
      }

      virtual void handleValue(const rdaData& value)
      {
         cout << value << "*****\n";
         if (--counter == 0)
         {
            delete this;
            exit(0);
         }
      }

      virtual void handleError(const rdaIOError& err)
      {
         cout << err << "\n*****\n";
      }

      virtual void disconnected()
      {
         cout << "DISCONNECTED FROM DATA SOURCE\n";
      }

      virtual void reconnected() 
      {         
         cout << "RECONNECTED TO DATA SOURCE\n";
      }
};

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
   {
      //
      // Create a subscription and wait for results
      //
      new SimpleSubscription(deviceName, property, cycle);
      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