File: commandTestClient.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 (94 lines) | stat: -rw-r--r-- 2,307 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
#include "Aria.h"
#include "ArNetworking.h"

ArClientBase client;

void commandList(ArNetPacket *packet)
{
  char name[512];
  char description[512];
  int numCommands;
  int i;

  numCommands = packet->bufToByte2();
  printf("%d commands\n", numCommands);
  for (i = 0; i < numCommands; i++)
  {
    packet->bufToStr(name, sizeof(name));
    packet->bufToStr(description, sizeof(description));
    printf("%-20s%s\n", name, description);
    client.requestOnce(name);
  }

}

void stringCommandList(ArNetPacket *packet)
{
  char name[512];
  char description[512];
  int numCommands;
  int i;
  char buf[512];

  numCommands = packet->bufToByte2();
  printf("%d string commands\n", numCommands);
  for (i = 0; i < numCommands; i++)
  {
    packet->bufToStr(name, sizeof(name));
    packet->bufToStr(description, sizeof(description));
    printf("%-20s%s\n", name, description);
    sprintf(buf, "%ld some random fun string %ld", ArMath::random(),
	    ArMath::random());
    client.requestOnceWithString(name, buf);
  }
  
}



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

  std::string hostname;
  Aria::init();
  //ArLog::init(ArLog::StdOut, ArLog::Verbose);

  if (argc == 1)
    hostname = "localhost";
  else
    hostname = argv[1];
  if (!client.blockingConnect(hostname.c_str(), 7272))
  {
    printf("Could not connect to server, exiting\n");
    exit(1);
  } 
  ArGlobalFunctor1<ArNetPacket *> commandCB(&commandList);
  ArGlobalFunctor1<ArNetPacket *> stringCommandCB(&stringCommandList);
  client.addHandler("listCommands", &commandCB);
  client.addHandler("listStringCommands", &stringCommandCB);
  client.requestOnce("listCommands");
  client.requestOnce("listStringCommands");
  /*
  client.requestOnce("Function1");
  client.requestOnce("Function2");
  client.requestOnce("Function3");
  client.requestOnce("Function1");
  client.requestOnceWithString("StringFunction4", "Some string!");
  client.requestOnceWithString("StringFunction5", "funfunfun");
  client.requestOnceWithString("StringFunction6", "six");
  client.requestOnceWithString("StringFunction4", "Some other string!");
  */
  client.runAsync();
  while (client.getRunningWithLock())
  {
    ArUtil::sleep(1);
    //printf("%d ms since last data\n", client.getLastPacketReceived().mSecSince());
  }
  Aria::shutdown();
  return 0;

}