The Eclipse Test and Performance Tools Platform
by Andy Kaylor


Listing One

#include "tptp/client/INode.h"
#include "tptp/client/NodeFactory.h"
#include "tptp/client/Agent.h"
#include "tptp/client/Collector.h"
#include "tptp/client/IDataProcessor.h"

using namespace TPTP::Client;

class MyDataProcessor: public IDataProcessor
{
public:
   MyDataProcessor() {}
   ~MyDataProcessor() {}

   // Handle the data coming
   virtual void incomingData(char buffer[], int length, DIME_HEADER_PTR_T
dimeHeader)
   {
      // TODO: Do something with the data
   }

   virtual void invalidDataType(char data[], int length) {}
   virtual void waitingForData() {}
};

int main(int argc, char* argv[])
{
   // Create a Node that represents the Target Machine
   INode* SampleNode = NodeFactory::createNode("localhost");

   // Get the Agent Controller on the Node
   AgentController* agentCtrlr = SampleNode->connect(10002);

   // Request an instance of our agent
   Collector* myCollector = new Collector("com.ddj.tptp.sample.myCollector");
   agentCtrlr->getAgent(myCollector, TPTP_CONTROLLER_ACCESS);

   // Establish Data Path and Data Listener
   MyDataProcessor* dataProcessor = new MyDataProcessor();
   int dataConnectionID = myCollector->addDataListener(dataProcessor);

   // Starts the collector
   myCollector->run();
   Sleep( 5000 );

   // Stop the collector
   myCollector->stop();

   return 0;
}


Listing Two

#include "tptp/agents/BaseCollectorImpl.h"

class MyCollector : public BaseCollectorImpl
{
public:
   MyCollector() {}
   ~MyCollector() {}
virtual int run(CmdBlock* cmd)
   {
      char data[] = "<mySampleData>        \
                        <mood>happy</mood> \
                     </mySampleData>";

      // TODO: Do whatever it is that starts data collection

      // Send the replay command
      int destID = cmd->getDestID();
      int sourceID = cmd->getSourceID();
      int contextID = cmd->getContextID();

      char   commandFormat[] = "<Cmd src=\"%ld\" dest=\"%ld\ ""
        "" ctxt=\"%ld\"><agentRunning ""
        "" iid=\"org.eclipse.tptp.Collector\"></agentRunning></Cmd>";
      char   command[1024];
      sprintf( command, commandFormat, destID, sourceID, contextID );

      sendCommand( command );

      // Simulated activity for sample purposes only
      Sleep( 500 );

      sendData(sourceID, data, sizeof(data) );

      return 0;
   }

   virtual int stop(CmdBlock* cmd)
   {
      // TODO: Do whatever it is that starts data collection

      // Send the replay command
      int destID = cmd->getDestID();
      int sourceID = cmd->getSourceID();
      int contextID = cmd->getContextID();

      char   commandFormat[] = "<Cmd src=\"%ld\" dest=\"%ld\ ""
        "" ctxt=\"%ld\"><agentStopped ""
        "" iid=\"org.eclipse.tptp.Collector\"></agentStopped></Cmd>";
      char   command[1024];
      sprintf( command, commandFormat, destID, sourceID, contextID );

      sendCommand( command );

      return 0;
   }

   // This sample doesn't expect to receive data
   virtual int receiveData(int sourceID, char buffer[], int bytesRead,
       DIME_HEADER_PTR_T dimeHeader) { return 0; }
};

int main(int argc, char* argv[])
{
   MyCollector* collector = new MyCollector();
   collector->registerAgent("com.ddj.tptp.sample.myCollector", "MyCollector");
   collector->waitForTermination();
   return 0;
}




