Changeset 774


Ignore:
Timestamp:
12/20/2010 08:45:58 AM (10 years ago)
Author:
lmalek
Message:

Tiny Samgar module code cleaning

Location:
libs/SAMGAR V2/GUI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libs/SAMGAR V2/GUI/samheader.h

    r550 r774  
    1010 
    1111#include "server3Gui.h" 
    12  
    13 //#define maxmodules 50 
    14 //#define maxconns   100 
    15 //#define maxports   10 
    1612 
    1713MyConnectionView *myconnwindow; 
  • libs/SAMGAR V2/GUI/server3Gui.cpp

    r582 r774  
    1010double Xshift=0; 
    1111 
    12 SamConnection SamCons[100]; 
     12SamConnection SamCons[maxconns]; 
    1313SamConnection TempConnect; 
    1414 
  • libs/SAMGAR V2/GUI/server3Gui.h

    r582 r774  
    6565using namespace yarp::name; 
    6666using namespace std; 
    67 //#include <QtGui> 
    6867 
    6968// not using proper lists, only arrays so we can easily preallocated memory 
  • libs/SAMGAR V2/GUI/yarpserver3.cpp

    r547 r774  
    2020{ 
    2121 
    22  QApplication app(argc, argv); 
    23  myconnwindow = new MyConnectionView(); 
     22   QApplication app(argc, argv); 
     23   myconnwindow = new MyConnectionView(); 
    2424 
    25  myconnwindow->mylogwindow->WriteToLog("Samgar V3 Started",true); 
     25   myconnwindow->mylogwindow->WriteToLog("Samgar V3 Started",true); 
    2626 
    27  //string namey = "hello"; 
    28  //string portnamesy[10]; 
    29  //portnamesy[0]="hey"; 
    30  //myconnwindow->AddAlterModule(SAMdef::add_module,namey,portnamesy,0,0,true); 
     27   // check if YARP version is sufficiently up to date - there was 
     28   // an important bug fix 
     29   Bottle b("ip 10.0.0.10"); 
     30   if (b.get(1).asString()!="10.0.0.10") { 
     31      fprintf(stderr, "Sorry, please update YARP version"); 
     32      exit(1); 
     33   } 
    3134 
    32  
    33          
    34  
    35     // check if YARP version is sufficiently up to date - there was 
    36     // an important bug fix 
    37     Bottle b("ip 10.0.0.10"); 
    38     if (b.get(1).asString()!="10.0.0.10") { 
    39         fprintf(stderr, "Sorry, please update YARP version"); 
    40         exit(1); 
    41     } 
    42  
    43     printf("__   __ _    ____  ____  \n\ 
     35   printf("__   __ _    ____  ____  \n\ 
    4436\\ \\ / // \\  |  _ \\|  _ \\ \n\ 
    4537 \\ V // _ \\ | |_) | |_) |\n\ 
     
    4739  |_/_/   \\_\\_| \\_\\_|    \n\n"); 
    4840 
    49     Property options; 
    50     options.fromCommand(argc,argv); 
    51     ConstString dbFilename = options.check("portdb", 
    52                                            Value("ports.db")).asString(); 
    53     ConstString subdbFilename = options.check("subdb", 
    54                                               Value("subs.db")).asString(); 
    55     ConstString ip = options.check("ip",Value("...")).asString(); 
    56     int sock = options.check("socket",Value(10000)).asInt(); 
    57     bool cautious = options.check("cautious"); 
     41   Property options; 
     42   options.fromCommand(argc,argv); 
     43   ConstString dbFilename = options.check("portdb", 
     44                                          Value("ports.db")).asString(); 
     45   ConstString subdbFilename = options.check("subdb", 
     46                                             Value("subs.db")).asString(); 
     47   ConstString ip = options.check("ip",Value("...")).asString(); 
     48   int sock = options.check("socket",Value(10000)).asInt(); 
     49   bool cautious = options.check("cautious"); 
    5850 
    59     printf("Port database: %s (change with \"--portdb newports.db\")\n",  
    60            dbFilename.c_str()); 
    61     printf("Subscription database: %s (change with \"--subdb newsubs.db\")\n",  
    62            subdbFilename.c_str()); 
    63     printf("*** Make sure these database files are not on a shared file system ***\n"); 
    64     printf("To clear the name server state, simply stop it, delete these files, and restart.\n"); 
    65     printf("IP address: %s (change with \"--ip N.N.N.N\")\n",  
    66            (ip=="...")?"default":ip.c_str()); 
    67     printf("Port number: %d (change with \"--socket NNNNN\")\n", sock); 
     51   printf("Port database: %s (change with \"--portdb newports.db\")\n",  
     52          dbFilename.c_str()); 
     53   printf("Subscription database: %s (change with \"--subdb newsubs.db\")\n",  
     54          subdbFilename.c_str()); 
     55   printf("*** Make sure these database files are not on a shared file system ***\n"); 
     56   printf("To clear the name server state, simply stop it, delete these files, and restart.\n"); 
     57   printf("IP address: %s (change with \"--ip N.N.N.N\")\n",  
     58          (ip=="...")?"default":ip.c_str()); 
     59   printf("Port number: %d (change with \"--socket NNNNN\")\n", sock); 
    6860     
    69     Network yarp; 
     61   Network yarp; 
    7062 
    71     bool reset = false; 
    72     if (options.check("ip")||options.check("socket")) { 
    73         fprintf(stderr,"Database needs to be reset, IP or port number set.\n"); 
    74         reset = true; 
    75     } 
     63   bool reset = false; 
     64   if (options.check("ip")||options.check("socket")) { 
     65      fprintf(stderr,"Database needs to be reset, IP or port number set.\n"); 
     66      reset = true; 
     67   } 
    7668 
    77     TripleSourceCreator db; 
    78     TripleSource *pmem = db.open(dbFilename.c_str(),cautious,reset); 
    79     if (pmem == NULL) { 
    80         fprintf(stderr,"Aborting, ports database failed to open.\n"); 
    81         return 1; 
    82     } 
     69   TripleSourceCreator db; 
     70   TripleSource *pmem = db.open(dbFilename.c_str(),cautious,reset); 
     71   if (pmem == NULL) { 
     72      fprintf(stderr,"Aborting, ports database failed to open.\n"); 
     73      return 1; 
     74   } 
    8375 
    84     SubscriberOnSql subscriber; 
    85     if (!subscriber.open(subdbFilename.c_str())) { 
    86         fprintf(stderr,"Aborting, subscription database failed to open.\n"); 
    87         return 1; 
    88     } 
     76   SubscriberOnSql subscriber; 
     77   if (!subscriber.open(subdbFilename.c_str())) { 
     78      fprintf(stderr,"Aborting, subscription database failed to open.\n"); 
     79      return 1; 
     80   } 
    8981 
    90     Contact contact =  
    91         Contact::byName("...").addSocket("tcp",ip.c_str(),sock); 
     82   Contact contact =  
     83      Contact::byName("...").addSocket("tcp",ip.c_str(),sock); 
    9284     
    93     BootstrapServer::configFileBootstrap(contact); 
     85   BootstrapServer::configFileBootstrap(contact); 
    9486 
    95     AllocatorConfig config; 
    96     config.minPortNumber = contact.getPort()+2; 
    97     config.maxPortNumber = contact.getPort()+9999; 
    98     AllocatorOnTriples alloc(pmem,config); 
    99     NameServiceOnTriples ns(pmem,&alloc,contact); 
    100     yarp.queryBypass(&ns); 
    101     subscriber.setStore(ns); 
    102     ns.setSubscriber(&subscriber); 
    103     ComposedNameService combo(subscriber,ns); 
    104     NameServerManager name(combo); 
    105     BootstrapServer fallback(name); 
     87   AllocatorConfig config; 
     88   config.minPortNumber = contact.getPort()+2; 
     89   config.maxPortNumber = contact.getPort()+9999; 
     90   AllocatorOnTriples alloc(pmem,config); 
     91   NameServiceOnTriples ns(pmem,&alloc,contact); 
     92   yarp.queryBypass(&ns); 
     93   subscriber.setStore(ns); 
     94   ns.setSubscriber(&subscriber); 
     95   ComposedNameService combo(subscriber,ns); 
     96   NameServerManager name(combo); 
     97   BootstrapServer fallback(name); 
    10698 
    107     Port server; 
    108     name.setPort(server); 
    109     server.setReaderCreator(name); 
    110     bool ok = server.open(contact,false); 
    111     if (!ok) { 
    112         fprintf(stderr, "Name server failed to open\n"); 
    113         return 1; 
    114     } 
    115     printf("\n"); 
     99   Port server; 
     100   name.setPort(server); 
     101   server.setReaderCreator(name); 
     102   bool ok = server.open(contact,false); 
     103   if (!ok) { 
     104      fprintf(stderr, "Name server failed to open\n"); 
     105      return 1; 
     106   } 
     107   printf("\n"); 
    116108 
    117     fallback.start(); 
     109   fallback.start(); 
    118110 
    119         DataPort ControlPort; 
    120         myPortReport myPortStatus; 
    121         ControlPort.setReporter(myPortStatus); 
    122         ControlPort.useCallback(); 
    123         ControlPort.open("/CONTROL"); 
     111   DataPort ControlPort; 
     112   myPortReport myPortStatus; 
     113   ControlPort.setReporter(myPortStatus); 
     114   ControlPort.useCallback(); 
     115   ControlPort.open("/CONTROL"); 
    124116 
    125117 
    126     // Repeat registrations for the server and fallback server - 
    127     // these registrations are more complete. 
    128     Network::registerContact(contact); 
    129     subscriber.welcome(contact.getName().c_str(),1); 
    130     Network::registerContact(fallback.where()); 
    131     subscriber.welcome(fallback.where().getName().c_str(),1); 
    132     ns.goPublic(); 
     118   // Repeat registrations for the server and fallback server - 
     119   // these registrations are more complete. 
     120   Network::registerContact(contact); 
     121   subscriber.welcome(contact.getName().c_str(),1); 
     122   Network::registerContact(fallback.where()); 
     123   subscriber.welcome(fallback.where().getName().c_str(),1); 
     124   ns.goPublic(); 
    133125 
    134     app.exec(); 
     126   app.exec(); 
    135127 
    136     while (true) { 
    137         Time::delay(600); 
    138         printf("Name server running happily\n"); 
    139     } 
    140     server.close(); 
     128   while (true) { 
     129      Time::delay(600); 
     130      printf("Name server running happily\n"); 
     131   } 
     132   server.close(); 
    141133 
    142     db.close(); 
     134   db.close(); 
    143135 
    144     return 0; 
     136   return 0; 
    145137} 
Note: See TracChangeset for help on using the changeset viewer.