source: flair-src/trunk/demos/Sinus/src/main.cpp@ 228

Last change on this file since 228 was 16, checked in by Bayard Gildas, 9 years ago

Reformatting

File size: 2.6 KB
Line 
1// created: 2013/06/26
2// filename: main.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9//
10//
11/*********************************************************************/
12
13#include "Loop.h"
14#include <FrameworkManager.h>
15#include <tclap/CmdLine.h>
16#include <stdio.h>
17
18// we use namespace std, to avoid writing for examlpe std::string
19using namespace std;
20// idem for TCLAP
21using namespace TCLAP;
22// idem for flair
23using namespace flair::core;
24
25// global variables for the command line arguments
26string logPath; // path for logs
27string address; // address for FlairGCS
28int port; // port for FlairGCS
29string xmlFile; // setup xml file
30string name; // name
31
32void parseOptions(int argc, char **argv);
33
34int main(int argc, char *argv[]) {
35 // get command line arguments (name,port,xml_file,log_path)
36 parseOptions(argc, argv);
37
38 // creation of FrameworkManager
39 FrameworkManager *manager;
40 manager = new FrameworkManager(name);
41 manager->SetupConnection(address, port);
42 manager->SetupUserInterface(xmlFile);
43 manager->SetupLogger(logPath);
44
45 // creation of the
46 Loop *example = new Loop(manager, "Loop");
47
48 // start loop
49 example->Start();
50
51 // wait for loop ends (with kill button)
52 example->Join();
53
54 delete manager;
55}
56
57void parseOptions(int argc, char **argv) {
58 try {
59 CmdLine cmd("Command description message", ' ', "0.1");
60
61 // name of the FrameworkManager, Sinus by default
62 ValueArg<string> nameArg("n", "name", "program name", false, "Sinus",
63 "string");
64 cmd.add(nameArg);
65
66 // setup xml file, ./Sinus.xml by default
67 ValueArg<string> xmlArg("x", "xml", "xml file", false, "./Sinus.xml",
68 "string");
69 cmd.add(xmlArg);
70
71 // log path, ./ by defaults
72 ValueArg<string> logArg("l", "log", "log path", false, "/tmp", "string");
73 cmd.add(logArg);
74
75 // address for FlairGCS
76 ValueArg<string> addressArg("a", "address",
77 "address for FlairGCS station sol", false,
78 "127.0.0.1", "string");
79 cmd.add(addressArg);
80
81 // port for FlairGCS, 9000 by default
82 ValueArg<int> portArg("p", "port", "port for FlairGCS", false, 9000, "int");
83 cmd.add(portArg);
84
85 cmd.parse(argc, argv);
86
87 // Get the value parsed by each arg.
88 logPath = logArg.getValue();
89 port = portArg.getValue();
90 xmlFile = xmlArg.getValue();
91 name = nameArg.getValue();
92 address = addressArg.getValue();
93
94 } catch (ArgException &e) { // catch any exceptions
95 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
96 }
97}
Note: See TracBrowser for help on using the repository browser.