source: libs/SAMGAR V2/GUI/yarpserver3.cpp @ 483

Revision 483, 4.3 KB checked in by KDucasse, 9 years ago (diff)
Line 
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3/*
4 * Copyright (C) 2009 Paul Fitzpatrick
5 * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
6 *
7 */
8
9
10#include "samheader.h"
11
12//#include "My_moc.cpp"
13
14
15
16
17
18//Network yarphelp;
19
20int main(int argc, char *argv[])
21{
22
23
24 QApplication app(argc, argv);
25 myconnwindow = new MyConnectionView();
26
27 myconnwindow->mylogwindow->WriteToLog("Samgar V3 Started",true);
28
29 //string namey = "hello";
30 //string portnamesy[10];
31 //portnamesy[0]="hey";
32 //myconnwindow->AddAlterModule(SAMdef::add_module,namey,portnamesy,0,0,true);
33
34
35
36    // check if YARP version is sufficiently up to date - there was
37    // an important bug fix
38    Bottle b("ip 10.0.0.10");
39    if (b.get(1).asString()!="10.0.0.10") {
40        fprintf(stderr, "Sorry, please update YARP version");
41        exit(1);
42    }
43
44    printf("__   __ _    ____  ____  \n\
45\\ \\ / // \\  |  _ \\|  _ \\ \n\
46 \\ V // _ \\ | |_) | |_) |\n\
47  | |/ ___ \\|  _ <|  __/ \n\
48  |_/_/   \\_\\_| \\_\\_|    \n\n");
49
50    Property options;
51    options.fromCommand(argc,argv);
52    ConstString dbFilename = options.check("portdb",
53                                           Value("ports.db")).asString();
54    ConstString subdbFilename = options.check("subdb",
55                                              Value("subs.db")).asString();
56    ConstString ip = options.check("ip",Value("...")).asString();
57    int sock = options.check("socket",Value(10000)).asInt();
58    bool cautious = options.check("cautious");
59
60    printf("Port database: %s (change with \"--portdb newports.db\")\n",
61           dbFilename.c_str());
62    printf("Subscription database: %s (change with \"--subdb newsubs.db\")\n",
63           subdbFilename.c_str());
64    printf("*** Make sure these database files are not on a shared file system ***\n");
65    printf("To clear the name server state, simply stop it, delete these files, and restart.\n");
66    printf("IP address: %s (change with \"--ip N.N.N.N\")\n",
67           (ip=="...")?"default":ip.c_str());
68    printf("Port number: %d (change with \"--socket NNNNN\")\n", sock);
69   
70    Network yarp;
71
72    bool reset = false;
73    if (options.check("ip")||options.check("socket")) {
74        fprintf(stderr,"Database needs to be reset, IP or port number set.\n");
75        reset = true;
76    }
77
78    TripleSourceCreator db;
79    TripleSource *pmem = db.open(dbFilename.c_str(),cautious,reset);
80    if (pmem == NULL) {
81        fprintf(stderr,"Aborting, ports database failed to open.\n");
82        return 1;
83    }
84
85    SubscriberOnSql subscriber;
86    if (!subscriber.open(subdbFilename.c_str())) {
87        fprintf(stderr,"Aborting, subscription database failed to open.\n");
88        return 1;
89    }
90
91    Contact contact =
92        Contact::byName("...").addSocket("tcp",ip.c_str(),sock);
93   
94    BootstrapServer::configFileBootstrap(contact);
95
96    AllocatorConfig config;
97    config.minPortNumber = contact.getPort()+2;
98    config.maxPortNumber = contact.getPort()+9999;
99    AllocatorOnTriples alloc(pmem,config);
100    NameServiceOnTriples ns(pmem,&alloc,contact);
101    yarp.queryBypass(&ns);
102    subscriber.setStore(ns);
103    ns.setSubscriber(&subscriber);
104    ComposedNameService combo(subscriber,ns);
105    NameServerManager name(combo);
106    BootstrapServer fallback(name);
107
108    Port server;
109    name.setPort(server);
110    server.setReaderCreator(name);
111    bool ok = server.open(contact,false);
112    if (!ok) {
113        fprintf(stderr, "Name server failed to open\n");
114        return 1;
115    }
116    printf("\n");
117
118    fallback.start();
119
120    // Repeat registrations for the server and fallback server -
121    // these registrations are more complete.
122    Network::registerContact(contact);
123    subscriber.welcome(contact.getName().c_str(),1);
124    Network::registerContact(fallback.where());
125    subscriber.welcome(fallback.where().getName().c_str(),1);
126    ns.goPublic();
127
128
129
130
131
132
133        DataPort ControlPort;
134        myPortReport myPortStatus;
135        ControlPort.setReporter(myPortStatus);
136        ControlPort.useCallback();
137        ControlPort.open("/CONTROL");
138       
139
140
141
142
143
144    app.exec();
145
146    while (true) {
147        Time::delay(600);
148        printf("Name server running happily\n");
149    }
150    server.close();
151
152    db.close();
153
154    return 0;
155}
Note: See TracBrowser for help on using the repository browser.