File: configClientToServer.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 (82 lines) | stat: -rw-r--r-- 1,911 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
#include "Aria.h"
#include "ArNetworking.h"

/*
  Pass this a file to send to the server (should be made by configClient then modified).

  Takes a file to send, and can take the host to send to too

 */

ArClientBase *client;
ArClientHandlerConfig *configHandler;

char *file;

void saveConfigSucceeded(void)
{
  printf("HERE: Save config succeeded\n");
}

void saveConfigFailed(const char *str)
{
  printf("HERE: Save config failed: %s\n", str);
}

void gotConfig(void)
{
  char errorBuffer[1024];
  ArConfig *newConfig;
  if (!configHandler->getConfig()->parseFile(file, false, false, errorBuffer,
					     sizeof(errorBuffer)))
    printf("Error loading file: %s\n", errorBuffer);
  
  configHandler->saveConfigToServer();
  client->loopOnce();
  ArUtil::sleep(1000);
  client->loopOnce();
  ArUtil::sleep(1000);
  client->disconnect();
  Aria::shutdown();
  exit(0);
}

int main(int argc, char **argv)
{
  Aria::init();
  //ArLog::init(ArLog::StdOut, ArLog::Verbose);
  ArGlobalFunctor gotConfigCB(&gotConfig);
  ArGlobalFunctor saveConfigSucceededCB(&saveConfigSucceeded);
  ArGlobalFunctor1<const char *> saveConfigFailedCB(&saveConfigFailed);
  std::string hostname;

  client = new ArClientBase;
  configHandler = new ArClientHandlerConfig(client, true);

  configHandler->addGotConfigCB(&gotConfigCB);
  configHandler->addSaveConfigSucceededCB(&saveConfigSucceededCB);
  configHandler->addSaveConfigFailedCB(&saveConfigFailedCB);
	
  if (argc == 1)
  {
    printf("Usage: %s <file> <host>\n", argv[0]);
    exit(1);
  }
  file = argv[1];
  if (argc == 2)
    hostname = "localhost";
  else
    hostname = argv[2];

  
  if (!client->blockingConnect(hostname.c_str(), 7272))
  {
    printf("Could not connect to server, exiting\n");
    exit(1);
  }
  //client->requestOnce("setConfig");
  configHandler->requestConfigFromServer();
  //client->requestOnce("setConfig");
  client->run();
  return 0;
}