void go() { mSuccess = false; Persistence::Protocol::ReadWriteSet rws; Persistence::Protocol::IStorageElement el = rws.add_reads(); el.set_field_name("ObjectList"); // el.set_object_uuid(UUID::null()); // el.set_field_id(0); RoutableMessageHeader hdr; hdr.set_source_object(ObjectReference::spaceServiceID()); hdr.set_source_port(mPort); hdr.set_destination_port(Services::PERSISTENCE); hdr.set_destination_object(ObjectReference::spaceServiceID()); std::string body; rws.SerializeToString(&body); mObjectHost->processMessage(hdr, MemoryReference(body)); }
~UUIDLister() { mObjectHost->unregisterService(mPort); }
UUIDLister(ObjectHost*oh, const SpaceID &space) : mObjectHost(oh), mSpace(space), mPort(Services::REGISTRATION) { mObjectHost->registerService(mPort, this); }
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; }
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; }
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; }