Esempio n. 1
0
int main(int argc, char** argv) {
    //yarp::os::Thread::setDefaultStackSize(3145728);
    yarp::os::Network yarp;
    if (!yarp.checkNetwork())
    {
        fprintf (stderr, "Error: could not initialize YARP network (is the nameserver running?)\n");
        return 1;
    }
    
    YARP_REGISTER_DEVICES(icubmod)
    yarp::os::Property options;
    options.fromCommand(argc,argv);

    // the "bundle" controls the implementation used for the simulation
    // (as opposed to the simulation interface).  The default is the
    // standard ODE/SDL implementation.  There is a "fake" do-nothing
    // simulation for test purposes that does nothing other than create
    // the standard ports (pass --fake to start this simulation).
    SimulationBundle *bundle = NULL;

    if (options.check("fake")) {
#ifdef ICUB_SIM_ENABLE_FAKE
        bundle = new FakeSimulationBundle;
#endif
    } else {
#ifdef ICUB_SIM_ENABLE_ODESDL
        bundle = new OdeSdlSimulationBundle;
#endif
    }
    if (options.check("verbose"))
    {
        bundle->verbose = true;
        fprintf(stdout, "Starting the simulator with verbose flag on\n");
    }
    if (bundle==NULL) {
        fprintf(stderr,"Failed to allocate simulator\n");
        return 1;
    }

    //SimulationRun main;
    //if (!main.run(bundle,argc,argv)) return 1;
    MainThread thread;
   thread.bundle = bundle;
   thread.argc = argc;
   thread.argv = argv;
#ifdef _WIN32
   //thread.setOptions(3145728);
#endif
   thread.start();
   thread.join();
   return thread.result?0:1;
    return 0;
}
 /**
  * Common kernel method which will be stated by target kernel.
  * 
  * @return error code or zero.
  */   
 int32 Main::main()  
 {
   int32 stage = 0;
   int32 error = -1;
   do{
     // Stage 1 
     stage++;
     if( not Interrupt::init() ) break;
     // Stage 2
     stage++;
     if( not Thread::init() ) break;      
     // Stage 3
     stage++;
     if( not Synchronizer::init() ) break;      
     // Stage 4
     stage++;
     if( not Core::init() ) break;      
     // Stage complete
     stage = -1;
     {
       MainThread main;
       if(main.isConstructed())
       {
         main.start();
         Thread::execute();
         error = main.error();
       }
     }
   }while(false);
   switch(stage)
   {
     default:
     case  4: Core::deinit();
     case  3: Synchronizer::deinit();      
     case  2: Thread::deinit();
     case  1: Interrupt::deinit();      
     case  0: break;
   }
   return error;
 }