Exemplo n.º 1
0
int TestQueueArray() {

  std::string testString = "<VRDataQueue num=\"2\"><VRDataQueueItem timeStamp=\"1454671331220377\"><atestarray type=\"intarray\" separator=\"@\">0@1@2@3@4@5@6@7@8@9@10@11@12@13@14@15@16@17@18@19@20@21@22@23@24@25@26@27@28@29@30@31@32@33@34@35@36@37@38@39@40@41@42@43@44@45@46@47@48@49@50@51@52@53@54@55@56@57@58@59@60@61@62@63@64@65@66@67@68@69@70@71@72@73@74@75@76@77@78@79@80@81@82@83@84@85@86@87@88@89@90@91@92@93@94@95@96@97@98@99</atestarray></VRDataQueueItem><VRDataQueueItem timeStamp=\"1454671331220395\"><d0 type=\"doublearray\">1.200000,2.300000,3.400000,4.500000,5.600000</d0></VRDataQueueItem></VRDataQueue>";

  testString = removeTimeStamps(testString);
  
  VRDataIndex *n = setupQIndex();
  VRDataQueue *q = new VRDataQueue;
  
  std::vector<int>e;

  for (int i = 0; i < 100; i++) {
    e.push_back(i);
  }

  n->addData("/george/atestarray", e);
  n->getDatum("/george/atestarray")->setAttributeValue("separator", "@");
  
  q->push(n->serialize("atestarray", "/george/"));
  q->push(n->serialize("/donna/d0"));
  
  std::string output = removeTimeStamps(q->serialize());
  
  //std::cout << "test:" << testString << std::endl;
  //std::cout << "outp:" << output << std::endl;
  
  // Test that the new queue is the same as the test string.
  int out = output.compare(testString);
  delete n;
  delete q;
  
  return out;
}
Exemplo n.º 2
0
VRDataQueue VRNetClient::syncEventDataAcrossAllNodes(VRDataQueue eventQueue) {

  // 1. send inputEvents to server
  sendEventData(_socketFD, eventQueue.serialize());

  // 2. receive all events from the server
  VRDataQueue::serialData allEventData = waitForAndReceiveEventData(_socketFD);

  return VRDataQueue(allEventData);
}
Exemplo n.º 3
0
int TestQueueUnpack() {

  std::string testString;

  // Create an index and a queue.
  VRDataIndex *n = setupQIndex();
  VRDataQueue *q = new VRDataQueue;
  
  std::vector<int>e;

  for (int i = 0; i < 100; i++) {
    e.push_back(i);
  }

  // Add an array to the index.
  n->addData("/george/atestarray", e);

  // Get the serialized version of an index object.
  testString = n->serialize("/george");

  // Put that object into the queue.
  q->push(n->serialize("/george"));
  
  VRDataIndex* index = new VRDataIndex;

  // Unpack the serialized object.
  index->addSerializedValue( q->getSerializedObject(), "/" );

  // Unpack it into a different index.
  std::string output = index->serialize("/george");

  // Does it match?
  int out = testString.compare(output);

  delete n;
  delete q;
  delete index;

  return out;
}
Exemplo n.º 4
0
int main() {
  VRDataIndex *index = new VRDataIndex;

  // Create a container object called cora, with two member objects.
  index->addData("/cora/nora", 4);
  index->addData("/cora/flora", "gosh and golly");

  // Create another container called homer, with two members.
  index->addData("/homer/bart", 3.4);
  index->addData("/homer/lisa", 5.2);

  // Show the index structure.
  std::cout << "Index Structure" << std::endl;
  std::cout << index->printStructure();

  VRDataQueue *queue = new VRDataQueue;

  // Push cora onto the queue.
  queue->push(index->serialize("cora", "/"));

  // Change the values of cora's members.
  index->addData("/cora/nora", 7);
  index->addData("/cora/flora", "are you sure?");

  VRIntArray ia;
  ia.push_back(1);
  ia.push_back(2);
  ia.push_back(3);
  index->addData("/cora/ia", ia);

  VRDoubleArray da;
  da.push_back(1.2);
  da.push_back(3.4);
  da.push_back(5.6);
  index->addData("/cora/da", da);

  VRStringArray sa;
  sa.push_back("hello");
  sa.push_back("good-bye");
  index->addData("/cora/sa", sa);
  
  std::cout << "Index Structure after changing /cora" << std::endl;
  std::cout << index->printStructure();

  // Push the new cora onto the queue.
  queue->push(index->serialize("cora", "/"));

  // Push homer onto the queue.
  queue->push(index->serialize("homer", "/"));

  // Show the queue.
  std::cout << "Queue" << std::endl;
  std::cout << queue->printQueue();

  std::cout << std::endl;
  std::cout << "serialized queue: " << queue->serialize() << std::endl;
  std::string queueData = queue->serialize();
  
  // Pretend we are in a remote program, having received event data
  // over the net.  It comes in as some kind of string data called
  // queueData.
  VRDataQueue *newQueue = new VRDataQueue(queueData);

  // Here's the index we'll populate with the new data.
  VRDataIndex *remoteIndex = new VRDataIndex;
  
  // While there is something in the queue, unpack it into the index,
  // and examine it.
  while (newQueue->notEmpty()) {

    // Unpack the items from the queue.
    std::string p =
      remoteIndex->addSerializedValue( newQueue->getSerializedObject() );

    std::cout << std::endl << "examining the data..." << std::endl;
    std::cout << "The object named " << p << " is a " <<
      remoteIndex->getTypeString(p) << "." << std::endl;
    if (remoteIndex->getType(p) == VRCORETYPE_CONTAINER) {
      VRContainer lp = remoteIndex->getValue(p);

      std::cout << "... it contains these" << std::endl;

      for (VRContainer::iterator it = lp.begin(); it != lp.end(); it++) {
        std::cout << "  " << *it << " (" << remoteIndex->getTypeString(*it) << ")" << std::endl;
      }
    }
    
    // Print out the entire index.
    std::cout << "Remote Index Structure" << std::endl;
    std::cout << remoteIndex->printStructure();

    // Perform arithmetic with some data from the index.
    int r = remoteIndex->getValue("/cora/nora");
    std::cout << " ... sum of /cora/nora and seven = " << 7 + r << std::endl;

    // Get the next item from the queue.
    newQueue->pop();

  }
}