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

Revision 514, 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
37    // check if YARP version is sufficiently up to date - there was
38    // an important bug fix
39    Bottle b("ip 10.0.0.10");
40    if (b.get(1).asString()!="10.0.0.10") {
41        fprintf(stderr, "Sorry, please update YARP version");
42        exit(1);
43    }
44
45    printf("__   __ _    ____  ____  \n\
46\\ \\ / // \\  |  _ \\|  _ \\ \n\
47 \\ V // _ \\ | |_) | |_) |\n\
48  | |/ ___ \\|  _ <|  __/ \n\
49  |_/_/   \\_\\_| \\_\\_|    \n\n");
50
51    Property options;
52    options.fromCommand(argc,argv);
53    ConstString dbFilename = options.check("portdb",
54                                           Value("ports.db")).asString();
55    ConstString subdbFilename = options.check("subdb",
56                                              Value("subs.db")).asString();
57    ConstString ip = options.check("ip",Value("...")).asString();
58    int sock = options.check("socket",Value(10000)).asInt();
59    bool cautious = options.check("cautious");
60
61    printf("Port database: %s (change with \"--portdb newports.db\")\n",
62           dbFilename.c_str());
63    printf("Subscription database: %s (change with \"--subdb newsubs.db\")\n",
64           subdbFilename.c_str());
65    printf("*** Make sure these database files are not on a shared file system ***\n");
66    printf("To clear the name server state, simply stop it, delete these files, and restart.\n");
67    printf("IP address: %s (change with \"--ip N.N.N.N\")\n",
68           (ip=="...")?"default":ip.c_str());
69    printf("Port number: %d (change with \"--socket NNNNN\")\n", sock);
70   
71    Network yarp;
72
73    bool reset = false;
74    if (options.check("ip")||options.check("socket")) {
75        fprintf(stderr,"Database needs to be reset, IP or port number set.\n");
76        reset = true;
77    }
78
79    TripleSourceCreator db;
80    TripleSource *pmem = db.open(dbFilename.c_str(),cautious,reset);
81    if (pmem == NULL) {
82        fprintf(stderr,"Aborting, ports database failed to open.\n");
83        return 1;
84    }
85
86    SubscriberOnSql subscriber;
87    if (!subscriber.open(subdbFilename.c_str())) {
88        fprintf(stderr,"Aborting, subscription database failed to open.\n");
89        return 1;
90    }
91
92    Contact contact =
93        Contact::byName("...").addSocket("tcp",ip.c_str(),sock);
94   
95    BootstrapServer::configFileBootstrap(contact);
96
97    AllocatorConfig config;
98    config.minPortNumber = contact.getPort()+2;
99    config.maxPortNumber = contact.getPort()+9999;
100    AllocatorOnTriples alloc(pmem,config);
101    NameServiceOnTriples ns(pmem,&alloc,contact);
102    yarp.queryBypass(&ns);
103    subscriber.setStore(ns);
104    ns.setSubscriber(&subscriber);
105    ComposedNameService combo(subscriber,ns);
106    NameServerManager name(combo);
107    BootstrapServer fallback(name);
108
109    Port server;
110    name.setPort(server);
111    server.setReaderCreator(name);
112    bool ok = server.open(contact,false);
113    if (!ok) {
114        fprintf(stderr, "Name server failed to open\n");
115        return 1;
116    }
117    printf("\n");
118
119    fallback.start();
120
121        DataPort ControlPort;
122        myPortReport myPortStatus;
123        ControlPort.setReporter(myPortStatus);
124        ControlPort.useCallback();
125        ControlPort.open("/CONTROL");
126
127
128    // Repeat registrations for the server and fallback server -
129    // these registrations are more complete.
130    Network::registerContact(contact);
131    subscriber.welcome(contact.getName().c_str(),1);
132    Network::registerContact(fallback.where());
133    subscriber.welcome(fallback.where().getName().c_str(),1);
134    ns.goPublic();
135
136
137
138
139
140
141
142
143
144
145
146
147    app.exec();
148
149    while (true) {
150        Time::delay(600);
151        printf("Name server running happily\n");
152    }
153    server.close();
154
155    db.close();
156
157    return 0;
158}
Note: See TracBrowser for help on using the repository browser.