示例#1
0
int main(int argc, char** argv) {

    using namespace Sirikata;

    DynamicLibrary::Initialize();

    InitOptions();
    Trace::Trace::InitOptions();
    SpaceTrace::InitOptions();
    InitSpaceOptions();
    ParseOptions(argc, argv, OPT_CONFIG_FILE, AllowUnregisteredOptions);

    PluginManager plugins;
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_EXTRA_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_SPACE_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_SPACE_EXTRA_PLUGINS) );

    // Fill defaults after plugin loading to ensure plugin-added
    // options get their defaults.
    FillMissingOptionDefaults();
    // Rerun original parse to make sure any newly added options are
    // properly parsed.
    ParseOptions(argc, argv, OPT_CONFIG_FILE);

    DaemonizeAndSetOutputs();
    ReportVersion(); // After options so log goes to the right place

    std::string time_server=GetOptionValue<String>("time-server");
    NTPTimeSync sync;
    if (time_server.size() > 0)
        sync.start(time_server);

    ServerID server_id = GetOptionValue<ServerID>("id");
    String trace_file = GetPerServerFile(STATS_TRACE_FILE, server_id);
    Sirikata::Trace::Trace* gTrace = new Trace::Trace(trace_file);

    // Compute the starting date/time
    String start_time_str = GetOptionValue<String>("wait-until");
    Time start_time = start_time_str.empty() ? Timer::now() : Timer::getSpecifiedDate( start_time_str );
    start_time += GetOptionValue<Duration>("wait-additional");

    Duration duration = GetOptionValue<Duration>("duration");

    Network::IOService* ios = new Network::IOService("Space");
    Network::IOStrand* mainStrand = ios->createStrand("Space Main");

    ODPSST::ConnectionManager* sstConnMgr = new ODPSST::ConnectionManager();
    OHDPSST::ConnectionManager* ohSstConnMgr = new OHDPSST::ConnectionManager();

    SpaceContext* space_context = new SpaceContext("space", server_id, sstConnMgr, ohSstConnMgr, ios, mainStrand, start_time, gTrace, duration);

    String servermap_type = GetOptionValue<String>("servermap");
    String servermap_options = GetOptionValue<String>("servermap-options");
    ServerIDMap * server_id_map =
        ServerIDMapFactory::getSingleton().getConstructor(servermap_type)(space_context, servermap_options);

    space_context->add(space_context);


    String timeseries_type = GetOptionValue<String>(OPT_TRACE_TIMESERIES);
    String timeseries_options = GetOptionValue<String>(OPT_TRACE_TIMESERIES_OPTIONS);
    Trace::TimeSeries* time_series = Trace::TimeSeriesFactory::getSingleton().getConstructor(timeseries_type)(space_context, timeseries_options);

    String commander_type = GetOptionValue<String>(OPT_COMMAND_COMMANDER);
    String commander_options = GetOptionValue<String>(OPT_COMMAND_COMMANDER_OPTIONS);
    Command::Commander* commander = NULL;
    if (!commander_type.empty())
        commander = Command::CommanderFactory::getSingleton().getConstructor(commander_type)(space_context, commander_options);

    Transfer::TransferMediator::getSingleton().registerContext(space_context);


    Sirikata::SpaceNetwork* gNetwork = NULL;
    String network_type = GetOptionValue<String>(NETWORK_TYPE);
    if (network_type == "tcp")
      gNetwork = new TCPSpaceNetwork(space_context);

    BoundingBox3f region = GetOptionValue<BoundingBox3f>("region");
    Vector3ui32 layout = GetOptionValue<Vector3ui32>("layout");

    srand( GetOptionValue<uint32>("rand-seed") );

    ObjectHostSessionManager* oh_sess_mgr = new ObjectHostSessionManager(space_context);
    ObjectSessionManager* obj_sess_mgr = new ObjectSessionManager(space_context);

    String auth_type = GetOptionValue<String>(SPACE_OPT_AUTH);
    String auth_opts = GetOptionValue<String>(SPACE_OPT_AUTH_OPTIONS);
    Authenticator* auth =
        AuthenticatorFactory::getSingleton().getConstructor(auth_type)(space_context, auth_opts);

    gNetwork->setServerIDMap(server_id_map);


    Forwarder* forwarder = new Forwarder(space_context);


    String cseg_type = GetOptionValue<String>(CSEG);
    CoordinateSegmentation* cseg = NULL;
    if (cseg_type == "uniform")
        cseg = new UniformCoordinateSegmentation(space_context, region, layout);
    else if (cseg_type == "client") {
      cseg = new CoordinateSegmentationClient(space_context, region, layout, server_id_map);
    }
    else {
        assert(false);
        exit(-1);
    }


    String loc_update_type = GetOptionValue<String>(LOC_UPDATE);
    String loc_update_opts = GetOptionValue<String>(LOC_UPDATE_OPTIONS);
    LocationUpdatePolicy* loc_update_policy =
        LocationUpdatePolicyFactory::getSingleton().getConstructor(loc_update_type)(space_context, loc_update_opts);

    String loc_service_type = GetOptionValue<String>(LOC);
    String loc_service_opts = GetOptionValue<String>(LOC_OPTIONS);
    LocationService* loc_service =
        LocationServiceFactory::getSingleton().getConstructor(loc_service_type)(space_context, loc_update_policy, loc_service_opts);

    ServerMessageQueue* sq = NULL;
    String server_queue_type = GetOptionValue<String>(SERVER_QUEUE);
    if (server_queue_type == "fair") {
        sq = new FairServerMessageQueue(
            space_context, gNetwork,
            (ServerMessageQueue::Sender*)forwarder);
    }
    else {
        assert(false);
        exit(-1);
    }

    ServerMessageReceiver* server_message_receiver = NULL;
    String server_receiver_type = GetOptionValue<String>(SERVER_RECEIVER);
    if (server_queue_type == "fair")
        server_message_receiver =
                new FairServerMessageReceiver(space_context, gNetwork, (ServerMessageReceiver::Listener*)forwarder);
    else {
        assert(false);
        exit(-1);
    }



    LoadMonitor* loadMonitor = new LoadMonitor(space_context, cseg);


    // OSeg Cache
    OSegCache* oseg_cache = NULL;
    std::string cacheSelector = GetOptionValue<String>(CACHE_SELECTOR);
    uint32 cacheSize = GetOptionValue<uint32>(OSEG_CACHE_SIZE);
    if (cacheSelector == CACHE_TYPE_COMMUNICATION) {
        double cacheCommScaling = GetOptionValue<double>(CACHE_COMM_SCALING);
        oseg_cache = new CommunicationCache(space_context, cacheCommScaling, cseg, cacheSize);
    }
    else if (cacheSelector == CACHE_TYPE_ORIGINAL_LRU) {
        uint32 cacheCleanGroupSize = GetOptionValue<uint32>(OSEG_CACHE_CLEAN_GROUP_SIZE);
        Duration entryLifetime = GetOptionValue<Duration>(OSEG_CACHE_ENTRY_LIFETIME);
        oseg_cache = new CacheLRUOriginal(space_context, cacheSize, cacheCleanGroupSize, entryLifetime);
    }
    else {
        std::cout<<"\n\nUNKNOWN CACHE TYPE SELECTED.  Please re-try.\n\n";
        std::cout.flush();
        assert(false);
    }

    //Create OSeg
    std::string oseg_type = GetOptionValue<String>(OSEG);
    std::string oseg_options = GetOptionValue<String>(OSEG_OPTIONS);
    Network::IOStrand* osegStrand = space_context->ioService->createStrand("OSeg");
    ObjectSegmentation* oseg =
        OSegFactory::getSingleton().getConstructor(oseg_type)(space_context, osegStrand, cseg, oseg_cache, oseg_options);
    //end create oseg


    // We have all the info to initialize the forwarder now
    forwarder->initialize(oseg, sq, server_message_receiver, loc_service);

    String aggmgr_hostname = GetOptionValue<String>(OPT_AGGMGR_HOSTNAME);
    String aggmgr_service = GetOptionValue<String>(OPT_AGGMGR_SERVICE);
    String aggmgr_consumer_key = GetOptionValue<String>(OPT_AGGMGR_CONSUMER_KEY);
    String aggmgr_consumer_secret = GetOptionValue<String>(OPT_AGGMGR_CONSUMER_SECRET);
    String aggmgr_access_key = GetOptionValue<String>(OPT_AGGMGR_ACCESS_KEY);
    String aggmgr_access_secret = GetOptionValue<String>(OPT_AGGMGR_ACCESS_SECRET);
    String aggmgr_username = GetOptionValue<String>(OPT_AGGMGR_USERNAME);
    Transfer::OAuthParamsPtr aggmgr_oauth;
    // Currently you need to explicitly override hostname to enable upload
    if (!aggmgr_hostname.empty()&&
        !aggmgr_consumer_key.empty() && !aggmgr_consumer_secret.empty() &&
        !aggmgr_access_key.empty() && !aggmgr_access_secret.empty()) {
        aggmgr_oauth = Transfer::OAuthParamsPtr(
            new Transfer::OAuthParams(
                aggmgr_hostname, aggmgr_service,
                aggmgr_consumer_key, aggmgr_consumer_secret,
                aggmgr_access_key, aggmgr_access_secret
            )
        );
    }
    std::string aggmgr_type = GetOptionValue<String>(OPT_AGGMGR);
    AggregateManager* aggmgr = AggregateManagerFactory::getSingleton().getConstructor(aggmgr_type)(loc_service, aggmgr_oauth, aggmgr_username);

    std::string prox_type = GetOptionValue<String>(OPT_PROX);
    std::string prox_options = GetOptionValue<String>(OPT_PROX_OPTIONS);
    Proximity* prox = ProximityFactory::getSingleton().getConstructor(prox_type)(space_context, loc_service, cseg, gNetwork, aggmgr, prox_options);

    // We need to do an async lookup, and to finish it the server needs to be
    // running. But we can't create the server until we have the address from
    // this lookup. We isolate as little as possible into this callback --
    // creating the server, finishing prox initialization, and getting them both
    // registered. We pass storage for the Server to the callback so we can
    // handle cleaning it up ourselves.
    using std::tr1::placeholders::_1;
    using std::tr1::placeholders::_2;
    Server* server = NULL;
    ModuleList modules;
    ServerData sd;
    sd.space_context = space_context;
    sd.auth = auth;
    sd.forwarder = forwarder;
    sd.loc_service = loc_service;
    sd.cseg = cseg;
    sd.prox = prox;
    sd.oseg = oseg;
    sd.oh_sess_mgr = oh_sess_mgr;
    sd.obj_sess_mgr = obj_sess_mgr;
    server_id_map->lookupExternal(
        space_context->id(),
        space_context->mainStrand->wrap(
            std::tr1::bind( &createServer, &server, &modules, sd, _1, _2)
        )
    );

    // If we're one of the initial nodes, we'll have to wait until we hit the start time
    {
        Time now_time = Timer::now();
        if (start_time > now_time) {
            Duration sleep_time = start_time - now_time;
            printf("Waiting %f seconds\n", sleep_time.toSeconds() ); fflush(stdout);
            Timer::sleep(sleep_time);
        }
    }

    ///////////Go go go!! start of simulation/////////////////////


    space_context->add(auth);
    space_context->add(gNetwork);
    space_context->add(cseg);
    space_context->add(loc_service);
    space_context->add(oseg);
    space_context->add(loadMonitor);
    space_context->add(sstConnMgr);
    space_context->add(ohSstConnMgr);
    space_context->add(prox);

    space_context->run(3);

    space_context->cleanup();

    if (GetOptionValue<bool>(PROFILE)) {
        space_context->profiler->report();
    }

    gTrace->prepareShutdown();
    Mesh::FilterFactory::destroy();
    ModelsSystemFactory::destroy();
    LocationServiceFactory::destroy();
    LocationUpdatePolicyFactory::destroy();

    for(ModuleList::iterator it = modules.begin(); it != modules.end(); it++)
        delete *it;
    modules.clear();

    delete server;
    delete sq;
    delete server_message_receiver;
    delete prox;
    delete aggmgr;
    delete server_id_map;

    delete loadMonitor;

    delete cseg;
    delete oseg;
    delete oseg_cache;
    delete loc_service;
    delete forwarder;

    delete obj_sess_mgr;
    delete oh_sess_mgr;

    delete gNetwork;
    gNetwork=NULL;

    gTrace->shutdown();
    delete gTrace;
    gTrace = NULL;


    delete commander;

    delete space_context;
    space_context = NULL;

    delete time_series;

    delete mainStrand;
    delete osegStrand;

    delete ios;

    delete sstConnMgr;
    delete ohSstConnMgr;

    Transfer::TransferMediator::destroy();

    sync.stop();

    plugins.gc();

    Sirikata::Logging::finishLog();

    DaemonCleanup();
    return 0;
}
示例#2
0
int main ( int argc,const char**argv ) {

    int myargc = argc+2;
    const char **myargv = new const char*[myargc];
    memcpy(myargv, argv, argc*sizeof(const char*));
    myargv[argc] = "--moduleloglevel";
    myargv[argc+1] = "transfer=fatal,ogre=fatal,task=fatal,resource=fatal";

    using namespace Sirikata;

    PluginManager plugins;
    const char* pluginNames[] = { "tcpsst", "monoscript", "sqlite", "ogregraphics", "bulletphysics", "colladamodels", NULL};
    for(const char** plugin_name = pluginNames; *plugin_name != NULL; plugin_name++)
        plugins.load( DynamicLibrary::filename(*plugin_name) );

    OptionSet::getOptions ( "" )->parse ( myargc,myargv );

#ifdef __GNUC__
#ifndef __APPLE__
    if (floatExcept->as<bool>()) {
        feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
    }
#endif
#endif

    OptionMapPtr transferOptions (new OptionMap);
    {
        std::string contents(cdnConfigFile->as<String>());
        std::string::size_type pos(0);
        parseConfig(contents, transferOptions, transferOptions, pos);
        std::cout << *transferOptions;
    }

    initializeProtocols();

    Network::IOService *ioServ = Network::IOServiceFactory::makeIOService();
    Task::WorkQueue *workQueue = new Task::LockFreeWorkQueue;
    Task::GenEventManager *eventManager = new Task::GenEventManager(workQueue);

    SpaceID mainSpace(UUID("12345678-1111-1111-1111-DEFA01759ACE",UUID::HumanReadable()));
    SpaceIDMap *spaceMap = new SpaceIDMap;
    spaceMap->insert(mainSpace, Network::Address(host->as<String>(),"5943"));
    String localDbFile=dbFile->as<String>();
    if (localDbFile.length()&&localDbFile[0]!='/'&&localDbFile[0]!='\\') {
        FILE * fp=fopen(localDbFile.c_str(),"rb");
        for (int i=0;i<4&&fp==NULL;++i) {
            localDbFile="../"+localDbFile;
            fp=fopen(localDbFile.c_str(),"rb");
        }
        if (fp) fclose(fp);
        else localDbFile=dbFile->as<String>();
    }
    Persistence::ReadWriteHandler *database=Persistence::ReadWriteHandlerFactory::getSingleton()
        .getConstructor("sqlite")(String("--databasefile ")+localDbFile);

    ObjectHost *oh = new ObjectHost(spaceMap, workQueue, ioServ);
    oh->registerService(Services::PERSISTENCE, database);

    {
        UUIDLister lister(oh, mainSpace);
        lister.goWait(ioServ, workQueue);
    }

    ProxyManager *provider = oh->getProxyManager(mainSpace);
    if (!provider) {
        SILOG(cppoh,error,String("Unable to load database in ") + String(dbFile->as<String>()));
        std::cout << "Press enter to continue" << std::endl;
        std::cerr << "Press enter to continue" << std::endl;
        fgetc(stdin);
        return 1;
    }

    TransferManager *tm;
    try {
        tm = initializeTransferManager((*transferOptions)["cdn"], eventManager);
    } catch (OptionDoesNotExist &err) {
        SILOG(input,fatal,"Fatal Error: Failed to load CDN config: " << err.what());
        std::cout << "Press enter to continue" << std::endl;
        std::cerr << "Press enter to continue" << std::endl;
        fgetc(stdin);
        return 1;
    }
    OptionSet::getOptions("")->parse(myargc,myargv);

    String graphicsCommandArguments;
    {
        std::ostringstream os;
        os << "--transfermanager=" << tm << " ";
        os << "--eventmanager=" << eventManager << " ";
        os << "--workqueue=" << workQueue << " ";
        graphicsCommandArguments = os.str();
    }
    if (!provider) {
        SILOG(cppoh,error,"Failed to get TopLevelSpaceConnection for main space "<<mainSpace);
    }

    bool continue_simulation = true;

    typedef std::vector<TimeSteppedSimulation*> SimList;
    SimList sims;

    struct SimulationRequest {
        const char* name;
        bool required;
    };
    const uint32 nSimRequests = 2;
    SimulationRequest simRequests[nSimRequests] = {
        {"ogregraphics", true},
        {"bulletphysics", false}
    };
    for(uint32 ir = 0; ir < nSimRequests && continue_simulation; ir++) {
        String simName = simRequests[ir].name;
        SILOG(cppoh,info,String("Initializing ") + simName);
        TimeSteppedSimulation *sim =
            SimulationFactory::getSingleton()
            .getConstructor ( simName ) ( provider,graphicsCommandArguments );
        if (!sim) {
            if (simRequests[ir].required) {
                SILOG(cppoh,error,String("Unable to load ") + simName + String(" plugin. The PATH environment variable is ignored, so make sure you have copied the DLLs from dependencies/ogre/bin/ into the current directory. Sorry about this!"));
                std::cout << "Press enter to continue" << std::endl;
                std::cerr << "Press enter to continue" << std::endl;
                fgetc(stdin);
                continue_simulation = false;
            }
            else {
                SILOG(cppoh,info,String("Couldn't load ") + simName + String(" plugin."));
            }
        }
        else {
            SILOG(cppoh,info,String("Successfully initialized ") + simName);
            sims.push_back(sim);
			sim->forwardMessagesTo(oh);
        }
    }
    while ( continue_simulation ) {
        for(SimList::iterator it = sims.begin(); it != sims.end(); it++) {
            continue_simulation = continue_simulation && (*it)->tick();
        }
        oh->tick();
        Network::IOServiceFactory::pollService(ioServ);
    }
	for(SimList::iterator it = sims.begin(); it != sims.end(); it++) {
		(*it)->endForwardingMessagesTo(oh);
	}
    delete oh;

    // delete after OH in case objects want to do last-minute state flushes
    delete database;

    destroyTransferManager(tm);
    delete eventManager;
    delete workQueue;

    for(SimList::reverse_iterator it = sims.rbegin(); it != sims.rend(); it++) {
        delete *it;
    }
    sims.clear();
    plugins.gc();
    SimulationFactory::destroy();

    Network::IOServiceFactory::destroyIOService(ioServ);
    delete spaceMap;

    delete []myargv;

    return 0;
}
示例#3
0
int main (int argc, char** argv) {
    using namespace Sirikata;

    DynamicLibrary::Initialize();

    InitOptions();
    Trace::Trace::InitOptions();
    OHTrace::InitOptions();
    InitCPPOHOptions();

    ParseOptions(argc, argv, OPT_CONFIG_FILE, AllowUnregisteredOptions);

    PluginManager plugins;
    String search_path=GetOptionValue<String>(OPT_OH_PLUGIN_SEARCH_PATHS);
    if (search_path.length()) {
        while (true) {
            String::size_type where=search_path.find(":");
            if (where==String::npos) {
                DynamicLibrary::AddLoadPath(search_path);
                break;
            }else {
                DynamicLibrary::AddLoadPath(search_path.substr(0,where));
                search_path=search_path.substr(where+1);
            }
        }
    }
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_EXTRA_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_OH_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_OH_EXTRA_PLUGINS) );

    // Fill defaults after plugin loading to ensure plugin-added
    // options get their defaults.
    FillMissingOptionDefaults();
    // Rerun original parse to make sure any newly added options are
    // properly parsed.
    ParseOptions(argc, argv, OPT_CONFIG_FILE);

    DaemonizeAndSetOutputs();
    ReportVersion(); // After options so log goes to the right place

    String time_server = GetOptionValue<String>("time-server");
    NTPTimeSync sync;
    if (time_server.size() > 0)
        sync.start(time_server);

#ifdef __GNUC__
#ifndef __APPLE__
    if (GetOptionValue<bool>(OPT_SIGFPE)) {
        feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
    }
#endif
#endif


    ObjectHostID oh_id = GetOptionValue<ObjectHostID>("ohid");
    String trace_file = GetPerServerFile(STATS_OH_TRACE_FILE, oh_id);
    Trace::Trace* trace = new Trace::Trace(trace_file);

    srand( GetOptionValue<uint32>("rand-seed") );

    Network::IOService* ios = new Network::IOService("Object Host");
    Network::IOStrand* mainStrand = ios->createStrand("Object Host Main");

    ODPSST::ConnectionManager* sstConnMgr = new ODPSST::ConnectionManager();
    OHDPSST::ConnectionManager* ohSstConnMgr = new OHDPSST::ConnectionManager();

    Time start_time = Timer::now(); // Just for stats in ObjectHostContext.
    Duration duration = Duration::zero(); // Indicates to run forever.
    ObjectHostContext* ctx = new ObjectHostContext("cppoh", oh_id, sstConnMgr, ohSstConnMgr, ios, mainStrand, trace, start_time, duration);

    String servermap_type = GetOptionValue<String>("servermap");
    String servermap_options = GetOptionValue<String>("servermap-options");
    ServerIDMap * server_id_map =
        ServerIDMapFactory::getSingleton().getConstructor(servermap_type)(ctx, servermap_options);

    String timeseries_type = GetOptionValue<String>(OPT_TRACE_TIMESERIES);
    String timeseries_options = GetOptionValue<String>(OPT_TRACE_TIMESERIES_OPTIONS);
    Trace::TimeSeries* time_series = Trace::TimeSeriesFactory::getSingleton().getConstructor(timeseries_type)(ctx, timeseries_options);

    String commander_type = GetOptionValue<String>(OPT_COMMAND_COMMANDER);
    String commander_options = GetOptionValue<String>(OPT_COMMAND_COMMANDER_OPTIONS);
    Command::Commander* commander = NULL;
    if (!commander_type.empty())
        commander = Command::CommanderFactory::getSingleton().getConstructor(commander_type)(ctx, commander_options);

    Transfer::TransferMediator::getSingleton().registerContext(ctx);


    SpaceID mainSpace(GetOptionValue<UUID>(OPT_MAIN_SPACE));

    String oh_options = GetOptionValue<String>(OPT_OH_OPTIONS);
    ObjectHost *oh = new CppohObjectHost(ctx, ios, oh_options);

    // Add all the spaces to the ObjectHost.  We used to have SpaceIDMap and
    // fill in the same ServerIDMap for all these. Now we just add the
    // ServerIDMap for the main space. We need a better way of handling multiple
    // spaces.
    oh->addServerIDMap(mainSpace, server_id_map);

    String objstorage_type = GetOptionValue<String>(OPT_OBJECT_STORAGE);
    String objstorage_options = GetOptionValue<String>(OPT_OBJECT_STORAGE_OPTS);
    OH::Storage* obj_storage =
        OH::StorageFactory::getSingleton().getConstructor(objstorage_type)(ctx, objstorage_options);
    oh->setStorage(obj_storage);

    String objpersistentset_type = GetOptionValue<String>(OPT_OH_PERSISTENT_SET);
    String objpersistentset_options = GetOptionValue<String>(OPT_OH_PERSISTENT_SET_OPTS);
    OH::PersistedObjectSet* obj_persistent_set =
        OH::PersistedObjectSetFactory::getSingleton().getConstructor(objpersistentset_type)(ctx, objpersistentset_options);
        oh->setPersistentSet(obj_persistent_set);

    String objfactory_type = GetOptionValue<String>(OPT_OBJECT_FACTORY);
    String objfactory_options = GetOptionValue<String>(OPT_OBJECT_FACTORY_OPTS);
    ObjectFactory* obj_factory = NULL;

    String obj_query_type = GetOptionValue<String>(OPT_OBJECT_QUERY_PROCESSOR);
    String obj_query_options = GetOptionValue<String>(OPT_OBJECT_QUERY_PROCESSOR_OPTS);
    OH::ObjectQueryProcessor* obj_query_processor =
        OH::ObjectQueryProcessorFactory::getSingleton().getConstructor(obj_query_type)(ctx, obj_query_options);
    oh->setQueryProcessor(obj_query_processor);

    String query_data_type = GetOptionValue<String>(OPT_OBJECT_QUERY_DATA);
    String query_data_type_opts = GetOptionValue<String>(OPT_OBJECT_QUERY_DATA_OPTS);
    if (query_data_type != "") {
        assert(QueryDataLookupFactory::getSingleton().hasConstructor(query_data_type));
        oh->setQueryDataLookupConstructor(QueryDataLookupFactory::getSingleton().getConstructor(query_data_type), query_data_type_opts);
    }

    ///////////Go go go!! start of simulation/////////////////////
    ctx->add(ctx);
    ctx->add(obj_storage);
    ctx->add(obj_persistent_set);
    ctx->add(obj_query_processor);

    ctx->add(oh);
    ctx->add(sstConnMgr);
    ctx->add(ohSstConnMgr);

    if (!objfactory_type.empty())
    {
        obj_factory = ObjectFactoryFactory::getSingleton().getConstructor(objfactory_type)(ctx, oh, mainSpace, objfactory_options);
        obj_factory->generate();
    }


    ctx->run(1);

    ctx->cleanup();

    if (GetOptionValue<bool>(PROFILE)) {
        ctx->profiler->report();
    }

    trace->prepareShutdown();
    Mesh::FilterFactory::destroy();
    ModelsSystemFactory::destroy();
    ObjectScriptManagerFactory::destroy();
    delete oh;


    delete obj_storage;
    delete obj_persistent_set;


    SimulationFactory::destroy();



    delete commander;
    delete ctx;
    delete time_series;

    trace->shutdown();
    delete trace;
    trace = NULL;

    delete mainStrand;
    delete ios;

    delete sstConnMgr;
    delete ohSstConnMgr;

    Transfer::TransferMediator::destroy();

    plugins.gc();
    sync.stop();

    Sirikata::Logging::finishLog();

    DaemonCleanup();
    return 0;
}
示例#4
0
文件: main.cpp 项目: SinSiXX/sirikata
int main(int argc, char** argv) {
    using namespace Sirikata;

    DynamicLibrary::Initialize();

    InitOptions();
    Trace::Trace::InitOptions();
    InitCSegOptions();
    ParseOptions(argc, argv);

    PluginManager plugins;
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS));
    plugins.loadList( GetOptionValue<String>(OPT_EXTRA_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_CSEG_PLUGINS));

    // Fill defaults after plugin loading to ensure plugin-added
    // options get their defaults.
    FillMissingOptionDefaults();
    // Rerun original parse to make sure any newly added options are
    // properly parsed.
    ParseOptions(argc, argv);

    ReportVersion(); // After options so log goes to the right place

    ServerID server_id = GetOptionValue<ServerID>("cseg-id");
    String trace_file = GetPerServerFile(STATS_TRACE_FILE, server_id);
    Trace::Trace* trace = new Trace::Trace(trace_file);

    // Compute the starting date/time
    String start_time_str = GetOptionValue<String>("wait-until");
    Time start_time = start_time_str.empty() ? Timer::now() : Timer::getSpecifiedDate( start_time_str );

    Duration duration = GetOptionValue<Duration>("duration")
                        + GetOptionValue<Duration>("additional-cseg-duration")
                        + GetOptionValue<Duration>("wait-additional");

    Network::IOService* ios = new Network::IOService("CSeg");
    Network::IOStrand* mainStrand = ios->createStrand("CSeg Main");


    CSegContext* cseg_context = new CSegContext(server_id, ios, mainStrand, trace, start_time, duration);

    String timeseries_type = GetOptionValue<String>(OPT_TRACE_TIMESERIES);
    String timeseries_options = GetOptionValue<String>(OPT_TRACE_TIMESERIES_OPTIONS);
    Trace::TimeSeries* time_series = Trace::TimeSeriesFactory::getSingleton().getConstructor(timeseries_type)(cseg_context, timeseries_options);

    BoundingBox3f region = GetOptionValue<BoundingBox3f>("region");
    Vector3ui32 layout = GetOptionValue<Vector3ui32>("layout");

    uint32 max_space_servers = GetOptionValue<uint32>("max-servers");
    if (max_space_servers == 0)
      max_space_servers = layout.x * layout.y * layout.z;

    srand( GetOptionValue<uint32>("rand-seed") );

    String servermap_type = GetOptionValue<String>("servermap");
    String servermap_options = GetOptionValue<String>("cseg-servermap-options");
    ServerIDMap * server_id_map =
        ServerIDMapFactory::getSingleton().getConstructor(servermap_type)(cseg_context, servermap_options);

    DistributedCoordinateSegmentation* cseg = new DistributedCoordinateSegmentation(cseg_context, region, layout, max_space_servers, server_id_map);

    ///////////Go go go!! start of simulation/////////////////////

    srand(time(NULL));

    cseg_context->add(cseg_context);
    cseg_context->add(cseg);

    cseg_context->run(2);

    std::cout << "CSEG cleaning up\n";
    fflush(stdout);

    cseg_context->cleanup();

    if (GetOptionValue<bool>(PROFILE)) {
        cseg_context->profiler->report();
    }

    trace->prepareShutdown();

    delete cseg;

    trace->shutdown();
    delete trace;
    trace = NULL;

    delete cseg_context;
    cseg_context = NULL;

    delete time_series;

    delete mainStrand;
    delete ios;

    plugins.gc();

    Sirikata::Logging::finishLog();

    return 0;
}
示例#5
0
int main (int argc, char** argv) {
    using namespace Sirikata;

    DynamicLibrary::Initialize();

    InitOptions();
    Trace::Trace::InitOptions();
    OHTrace::InitOptions();
    InitCPPOHOptions();

    ParseOptions(argc, argv, OPT_CONFIG_FILE);

    PluginManager plugins;
    String search_path=GetOptionValue<String>(OPT_OH_PLUGIN_SEARCH_PATHS);
    if (search_path.length()) {
        while (true) {
            String::size_type where=search_path.find(":");
            if (where==String::npos) {
                DynamicLibrary::AddLoadPath(search_path);
                break;
            }else {
                DynamicLibrary::AddLoadPath(search_path.substr(0,where));
                search_path=search_path.substr(where+1);
            }
        }
    }
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_OH_PLUGINS) );


    String time_server = GetOptionValue<String>("time-server");
    NTPTimeSync sync;
    if (time_server.size() > 0)
        sync.start(time_server);

#ifdef __GNUC__
#ifndef __APPLE__
    if (GetOptionValue<bool>(OPT_SIGFPE)) {
        feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
    }
#endif
#endif


    ObjectHostID oh_id = GetOptionValue<ObjectHostID>("ohid");
    String trace_file = GetPerServerFile(STATS_OH_TRACE_FILE, oh_id);
    Trace::Trace* trace = new Trace::Trace(trace_file);

    String servermap_type = GetOptionValue<String>("servermap");
    String servermap_options = GetOptionValue<String>("servermap-options");
    ServerIDMap * server_id_map =
        ServerIDMapFactory::getSingleton().getConstructor(servermap_type)(servermap_options);

    srand( GetOptionValue<uint32>("rand-seed") );

    Network::IOService* ios = Network::IOServiceFactory::makeIOService();
    Network::IOStrand* mainStrand = ios->createStrand();

    Time start_time = Timer::now(); // Just for stats in ObjectHostContext.
    Duration duration = Duration::zero(); // Indicates to run forever.
    ObjectHostContext* ctx = new ObjectHostContext(oh_id, ios, mainStrand, trace, start_time, duration);
    Context::mainContextPtr = ctx;

    String timeseries_type = GetOptionValue<String>(OPT_TRACE_TIMESERIES);
    String timeseries_options = GetOptionValue<String>(OPT_TRACE_TIMESERIES_OPTIONS);
    Trace::TimeSeries* time_series = Trace::TimeSeriesFactory::getSingleton().getConstructor(timeseries_type)(ctx, timeseries_options);


    SSTConnectionManager* sstConnMgr = new SSTConnectionManager();

    SpaceID mainSpace(GetOptionValue<UUID>(OPT_MAIN_SPACE));

    String oh_options = GetOptionValue<String>(OPT_OH_OPTIONS);
    ObjectHost *oh = new CppohObjectHost(ctx, ios, oh_options);

    // Add all the spaces to the ObjectHost.  We used to have SpaceIDMap and
    // fill in the same ServerIDMap for all these. Now we just add the
    // ServerIDMap for the main space. We need a better way of handling multiple
    // spaces.
    oh->addServerIDMap(mainSpace, server_id_map);

    String objstorage_type = GetOptionValue<String>(OPT_OBJECT_STORAGE);
    String objstorage_options = GetOptionValue<String>(OPT_OBJECT_STORAGE_OPTS);
    OH::Storage* obj_storage =
        OH::StorageFactory::getSingleton().getConstructor(objstorage_type)(ctx, objstorage_options);
    oh->setStorage(obj_storage);

    String objpersistentset_type = GetOptionValue<String>(OPT_OH_PERSISTENT_SET);
    String objpersistentset_options = GetOptionValue<String>(OPT_OH_PERSISTENT_SET_OPTS);
    OH::PersistedObjectSet* obj_persistent_set =
        OH::PersistedObjectSetFactory::getSingleton().getConstructor(objpersistentset_type)(ctx, objpersistentset_options);
    oh->setPersistentSet(obj_persistent_set);

    String objfactory_type = GetOptionValue<String>(OPT_OBJECT_FACTORY);
    String objfactory_options = GetOptionValue<String>(OPT_OBJECT_FACTORY_OPTS);
    ObjectFactory* obj_factory = NULL;


    ///////////Go go go!! start of simulation/////////////////////
    ctx->add(ctx);
    ctx->add(obj_storage);
    ctx->add(obj_persistent_set);
    ctx->add(oh);
    ctx->add(sstConnMgr);

    if (!objfactory_type.empty())
    {
        obj_factory = ObjectFactoryFactory::getSingleton().getConstructor(objfactory_type)(ctx, oh, mainSpace, objfactory_options);
        obj_factory->generate();
    }

    
    ctx->run(1);

    ctx->cleanup();
    trace->prepareShutdown();


    delete oh;
    //delete pd;

    delete obj_storage;
    delete obj_persistent_set;

    SimulationFactory::destroy();

    delete sstConnMgr;

    delete ctx;
    delete time_series;

    trace->shutdown();
    delete trace;
    trace = NULL;

    delete mainStrand;
    Network::IOServiceFactory::destroyIOService(ios);

    plugins.gc();
    sync.stop();

    return 0;
}
示例#6
0
int main(int argc, char** argv) {
    InitOptions();

    InitializeClassOptions::module(SIRIKATA_OPTIONS_MODULE)
        .addOption(new OptionValue("mesh","",Sirikata::OptionValueType<String>(),"Mesh to load and display."))
        .addOption(new OptionValue("screenshot","",Sirikata::OptionValueType<String>(),"If non-empty, trigger a screenshot to the given filename and exit."))
        ;

    ParseOptions(argc, argv, AllowUnregisteredOptions);

    PluginManager plugins;
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS) );
    plugins.loadList( GetOptionValue<String>(OPT_EXTRA_PLUGINS) );
    // FIXME this should be an option
    plugins.loadList( "colladamodels,mesh-billboard,mesh-ply,common-filters,nvtt" );

    // Fill defaults after plugin loading to ensure plugin-added
    // options get their defaults.
    FillMissingOptionDefaults();
    // Rerun original parse to make sure any newly added options are
    // properly parsed.
    ParseOptions(argc, argv);

    DaemonizeAndSetOutputs();
    ReportVersion(); // After options so log goes to the right place

    Network::IOService* ios = new Network::IOService("MeshView");
    Network::IOStrand* iostrand = ios->createStrand("MeshView Main");

    Trace::Trace* trace = new Trace::Trace("meshview.log");
    Time epoch = Timer::now();

    Context* ctx = new Context("MeshView", ios, iostrand, trace, epoch);

    OgreRenderer* renderer = new OgreRenderer(ctx,Network::IOStrandPtr(ios->createStrand("OgreRenderer")));
    renderer->initialize("", false);

    MeshViewCamera* cam = new MeshViewCamera(renderer);
    cam->attach("", 0, 0, Vector4f(.7,.7,.7,1), 0);
    cam->setPosition(Vector3d(0, 0, 2));

    MeshViewEntity* ent = new MeshViewEntity(renderer, GetOptionValue<String>("screenshot"));
    ent->setOgrePosition(Vector3d(0, 0, 0));
    ent->setOgreOrientation(Quaternion::identity());
    renderer->addObject(ent, Transfer::URI(GetOptionValue<String>("mesh")));

    ctx->add(ctx);
    ctx->add(renderer);
    ctx->run(1);

    delete ent;
    delete cam;
    delete renderer;

    ctx->cleanup();
    trace->prepareShutdown();

    delete ctx;

    trace->shutdown();
    delete trace;

    delete iostrand;
    delete ios;

    Transfer::TransferMediator::destroy();

    plugins.gc();

    Sirikata::Logging::finishLog();

    DaemonCleanup();
    return 0;
}
示例#7
0
int main(int argc, char** argv) {
    using namespace Sirikata;

    DynamicLibrary::Initialize();

    InitOptions();
    Trace::Trace::InitOptions();
    InitPintoOptions();
    ParseOptions(argc, argv);

    PluginManager plugins;
    plugins.loadList( GetOptionValue<String>(OPT_PLUGINS));
    plugins.loadList( GetOptionValue<String>(OPT_PINTO_PLUGINS));

    // Currently not distributed, so we just use any ID
    String trace_file = GetPerServerFile(STATS_TRACE_FILE, (ServerID)0);
    Trace::Trace* trace = new Trace::Trace(trace_file);

    // Compute the starting date/time
    String start_time_str = GetOptionValue<String>("wait-until");
    Time start_time = start_time_str.empty() ? Timer::now() : Timer::getSpecifiedDate( start_time_str );

    Duration duration = GetOptionValue<Duration>("duration")
                        + GetOptionValue<Duration>("wait-additional");

    Network::IOService* ios = Network::IOServiceFactory::makeIOService();
    Network::IOStrand* mainStrand = ios->createStrand();

    PintoContext* pinto_context = new PintoContext(ios, mainStrand, trace, start_time, duration);

    PintoManager* pinto = new PintoManager(pinto_context);

    srand( GetOptionValue<uint32>("rand-seed") );

    ///////////Go go go!! start of simulation/////////////////////

    srand(time(NULL));

    pinto_context->add(pinto_context);
    pinto_context->add(pinto);

    pinto_context->run(1);

    pinto_context->cleanup();

    if (GetOptionValue<bool>(PROFILE)) {
        pinto_context->profiler->report();
    }

    trace->prepareShutdown();

    delete pinto;

    trace->shutdown();
    delete trace;
    trace = NULL;

    delete pinto_context;
    pinto_context = NULL;

    delete mainStrand;
    Network::IOServiceFactory::destroyIOService(ios);

    plugins.gc();

    return 0;
}