File: infoDrawingClient.cpp

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (133 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "Aria.h"
#include "ArNetworking.h"

ArClientBase client;

// suppress the output of drawings until we get the whole list in and then for a few seconds beyond that
bool getDrawingListDone = true;
ArTime getDrawingListDoneTime;

void drawingData(ArNetPacket *packet)
{
  if (getDrawingListDone && getDrawingListDoneTime.secSince() < 5)
    return;

  int x, y;
  int numReadings;
  int i;

  numReadings = packet->bufToByte4();

  if (numReadings == 0)
  {
    printf("No readings for sensor %s\n\n", client.getName(packet));
    return;
  }

  printf("Readings (%d) for %s:", numReadings, client.getName(packet));
  for (i = 0; i < numReadings; i++)
  {
    x = packet->bufToByte4();
    y = packet->bufToByte4();
    printf(" (%d %d)", x, y);
  }
  printf("\n\n");
}

ArGlobalFunctor1<ArNetPacket *> drawingDataCB(&drawingData);

void getDrawingList(ArNetPacket *packet)
{
  int numDrawings;
  int i;
  char name[512];
  char shape[512];
  char visibility[512];
  long primary, size, layer, secondary;
  unsigned long refresh;

  if (packet->getDataReadLength() == packet->getDataLength())
  {
    ArLog::log(ArLog::Normal, "");
    ArLog::log(ArLog::Normal, "Done with getDrawingList, will begin logging drawing data in 5 seconds");
    getDrawingListDone = true;
    getDrawingListDoneTime.setToNow();
    return;
  }

  packet->bufToStr(name, sizeof(name));
  packet->bufToStr(shape, sizeof(shape));
  primary = packet->bufToByte4();
  size = packet->bufToByte4();
  layer = packet->bufToByte4();
  refresh = packet->bufToByte4();
  secondary = packet->bufToByte4();
  packet->bufToStr(visibility, sizeof(visibility));  

  ArLog::log(ArLog::Normal, "name %-40s shape %20s", name, shape);
  ArLog::log(ArLog::Normal, 
	     "\tprimary %08x size %2d layer %2d refresh %4u secondary %08x",
	     primary, size, layer, refresh, secondary);

  if (strcasecmp(visibility, "On") == 0 || 
      strcasecmp(visibility, "DefaultOn") == 0)
  {
    client.addHandler(name, &drawingDataCB);
    client.request(name, refresh);
    ArLog::log(ArLog::Normal, "\tRequesting %s since visibilty %s", name, visibility);
  }
  else
  {
    ArLog::log(ArLog::Normal, "\tNot requesting %s since visibilty %s", name, visibility);
  }
  
}

int main(int argc, char **argv)
{

  std::string hostname;
  ArGlobalFunctor1<ArNetPacket *> getDrawingListCB(&getDrawingList);
  Aria::init();
  //ArLog::init(ArLog::StdOut, ArLog::Verbose);



  ArArgumentParser parser(&argc, argv);

  ArClientSimpleConnector clientConnector(&parser);
  
  parser.loadDefaultArguments();

  /* Check for -help, and unhandled arguments: */
  if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
  {
    Aria::logOptions();
    exit(0);
  }

  /* Connect our client object to the remote server: */
  if (!clientConnector.connectClient(&client))
  {
    if (client.wasRejected())
      printf("Server '%s' rejected connection, exiting\n", client.getHost());
    else
      printf("Could not connect to server '%s', exiting\n", client.getHost());
    exit(1);
  } 

  printf("Connected to server.\n");

  client.addHandler("getDrawingList", &getDrawingListCB);
  client.requestOnce("getDrawingList");
  
  client.runAsync();
  while (client.getRunningWithLock())
  {
    ArUtil::sleep(1);
    //printf("%d ms since last data\n", client.getLastPacketReceived().mSecSince());
  }
  Aria::shutdown();
  return 0;

}