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

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

Reformatting

File size: 2.6 KB
RevLine 
[14]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
[16]18// we use namespace std, to avoid writing for examlpe std::string
[14]19using namespace std;
[16]20// idem for TCLAP
[14]21using namespace TCLAP;
[16]22// idem for flair
[14]23using namespace flair::core;
24
[16]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
[14]31
[16]32void parseOptions(int argc, char **argv);
[14]33
[16]34int main(int argc, char *argv[]) {
35 // get command line arguments (name,port,xml_file,log_path)
36 parseOptions(argc, argv);
[14]37
[16]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);
[14]44
[16]45 // creation of the
46 Loop *example = new Loop(manager, "Loop");
[14]47
[16]48 // start loop
49 example->Start();
[14]50
[16]51 // wait for loop ends (with kill button)
52 example->Join();
[14]53
[16]54 delete manager;
[14]55}
56
[16]57void parseOptions(int argc, char **argv) {
58 try {
59 CmdLine cmd("Command description message", ' ', "0.1");
[14]60
[16]61 // name of the FrameworkManager, Sinus by default
62 ValueArg<string> nameArg("n", "name", "program name", false, "Sinus",
63 "string");
64 cmd.add(nameArg);
[14]65
[16]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);
[14]70
[16]71 // log path, ./ by defaults
72 ValueArg<string> logArg("l", "log", "log path", false, "/tmp", "string");
73 cmd.add(logArg);
[14]74
[16]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);
[14]80
[16]81 // port for FlairGCS, 9000 by default
82 ValueArg<int> portArg("p", "port", "port for FlairGCS", false, 9000, "int");
83 cmd.add(portArg);
[14]84
[16]85 cmd.parse(argc, argv);
[14]86
[16]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();
[14]93
[16]94 } catch (ArgException &e) { // catch any exceptions
95 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
96 }
[14]97}
Note: See TracBrowser for help on using the repository browser.