void ToggleDebugCommand::execute() { DebugManager* dm = dynamic_cast<DebugManager*>(cg::Registry::instance()->get("DebugManager")); Camera* camera = dynamic_cast<Camera*>( cg::Registry::instance()->get("Camera")); if(dm->isDebugModeActive()) camera->mainCamera(); else camera->freeCamera(); dm->toggleDebugMode(); static_cast<Scene*>(cg::Registry::instance()->get("Scene"))->switchDebug(); static_cast<MainApp*>(cg::Manager::instance()->getApp())->unpause(); }
DebugMode::DebugMode () { DebugManager *debugManager = (DebugManager*)cg::Registry::instance()->get("DEBUG_MANAGER"); debugManager->addObjectDebug(this); }
void LevelManager::loadLevel(Level* lvl) { printf("STARTING TO LOAD LEVEL \n" ); std::cout << "Entities::start " << cg::Registry::instance()->size() << "\n"; _currentLevel = lvl; _currentClues = 0; static_cast<Scene*>(cg::Registry::instance()->get("Scene"))->reset(); MaterialManager* materialManager = dynamic_cast<MaterialManager*>(cg::Registry::instance()->get("MaterialManager")); TextureManager* textureManager = dynamic_cast<TextureManager*>(cg::Registry::instance()->get("TextureManager")); materialManager->clear(); std::list<Material*>::iterator matit; for(matit = lvl->getMaterials()->begin(); matit != lvl->getMaterials()->end(); matit++) { materialManager->add(*matit); } textureManager->clear(); std::list<Texture*>::iterator texit; textureManager->addMap(lvl->getMapTex()); for(texit = lvl->getTextures()->begin(); texit != lvl->getTextures()->end(); texit++) { textureManager->add(*texit); } printf("LEVEL MANAGER: REMOVING PREVIOUS ENTITIES\n"); //clearing old ones (if there are any) cg::View* v1 = static_cast<cg::View*>(cg::Registry::instance()->get("view1")); std::list<std::string>::iterator entitiesit; for(entitiesit = _currentEntities->begin(); entitiesit != _currentEntities->end(); entitiesit++) { v1->unlinkEntity(*entitiesit); cg::Registry::instance()->remove(*entitiesit); } std::cout << "Entities::after_unlink " << cg::Registry::instance()->size() << "\n"; DebugManager* dm = static_cast<DebugManager*>(cg::Registry::instance()->get("DebugManager")); std::cout << "Debugmanager::Before " << dm->getListsSize() << "\n"; printf("LEVEL MANAGER: REMOVING DEBUG LISTENERS\n"); //removing everything registered for Debug (Ninja is always there) //DebugManager* dm = static_cast<DebugManager*>(cg::Registry::instance()->get("DebugManager")); dm->dispose(); dm->disableDebug(); std::cout << "Debugmanager::After " << dm->getListsSize() << "\n"; CollisionManager* cm = static_cast<CollisionManager*>(cg::Registry::instance()->get("CollisionManager")); std::cout << "Collision::Before " << cm->getListsSize() << "\n"; printf("LEVEL MANAGER: REMOVING COLLISION LISTENERS\n"); //removing everything except Ninja from Collisions //CollisionManager* cm = static_cast<CollisionManager*>(cg::Registry::instance()->get("CollisionManager")); cm->dispose(); std::cout << "Collision::After " << cm->getListsSize() << "\n"; std::cout << "Entities::after_managers " << cg::Registry::instance()->size() << "\n"; _currentEntities->clear(); std::cout << "Entities::after_clean_entities " << cg::Registry::instance()->size() << "\n"; printf("LEVEL MANAGER: STARTING TO LOAD HEIGHT MAP\n"); ImageLoaderHeightMap* ilhm = static_cast<ImageLoaderHeightMap*>(cg::Registry::instance()->get("mappedterrain")); if(ilhm != NULL) ilhm->setHeightMap(LEVEL_PATH + _currentLevel->getHeightMap()); else { ilhm = new ImageLoaderHeightMap("mappedterrain", LEVEL_PATH + _currentLevel->getHeightMap()); cg::Registry::instance()->add(ilhm); } std::cout << "Entities::after_heightmap " << cg::Registry::instance()->size() << "\n"; printf("LEVEL MANAGER: STARTING TO LOAD ITEM MAP\n"); ImageLoaderItemMap* ilim = static_cast<ImageLoaderItemMap*>(cg::Registry::instance()->get("mappeditems")); if(ilim != NULL) ilim->setItemMap(LEVEL_PATH + _currentLevel->getHeightMap(), LEVEL_PATH + _currentLevel->getItemMap()); else { ilim = new ImageLoaderItemMap("mappeditems", LEVEL_PATH + _currentLevel->getHeightMap(), LEVEL_PATH + _currentLevel->getItemMap()); cg::Registry::instance()->add(ilim); } for(entitiesit = _currentEntities->begin(); entitiesit != _currentEntities->end(); entitiesit++) { cg::Registry::instance()->get(*entitiesit)->init(); } //reset ninja position printf("LEVEL MANAGER: RESETING NINJA POSITION\n"); Ninja* ninja = dynamic_cast<Ninja*>(cg::Registry::instance()->get("Ninja")); ninja->reset(); static_cast<Camera*>(cg::Registry::instance()->get("Camera"))->mainCamera(); std::cout << "Entities::after_itemmap " << cg::Registry::instance()->size() << "\n"; std::cout << "Debugmanager::After " << dm->getListsSize() << "\n"; std::cout << "Collision::After " << cm->getListsSize() << "\n"; printf("LEVEL LOADED\n"); }
int run_haggle() { srand(time(NULL)); #ifdef ENABLE_DEBUG_MANAGER DebugManager *db = NULL; #endif ApplicationManager *am = NULL; DataManager *dm = NULL; // SW: START: SendPriorityManager SendPriorityManager *spm = NULL; // SW: END: SendPriorityManager NodeManager *nm = NULL; ProtocolManager *pm = NULL; ForwardingManager *fm = NULL; SecurityManager *sm = NULL; ConnectivityManager *cm = NULL; LossEstimateManager *lm = NULL; NetworkCodingManager* networkCodingManager = NULL; FragmentationManager* fragmentationManager = NULL; //JM ReplicationManager *replicationManager = NULL; BenchmarkManager *bm = NULL; ResourceManager *rm = NULL; // SW: START: interest manager InterestManager *im = NULL; // SW: END: interest manager ProtocolSocket *p = NULL; #ifdef OS_WINDOWS_MOBILE // For testing we force the deletion of the data store //recreateDataStore = true; #endif int retval = EXIT_FAILURE; #if defined(OS_ANDROID) //mallopt(-1, -1); // MOS - avoid trimming #elif defined(OS_LINUX) mallopt(M_TRIM_THRESHOLD, -1); // MOS - avoid trimming #endif xmlInitParser(); // MOS - this need to be called here for thread-safe libxml use #ifdef DEBUG Trace::trace.enableFileTrace(); #endif HAGGLE_LOG("\n\n****************** HAGGLE STARTUP *********************\n\n"); if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) { HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH); return -1; } retval = write_pid_file(getpid()); if (retval != HAGGLE_PROCESS_NO_ERROR) { switch (retval) { case HAGGLE_PROCESS_BAD_PID: HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_CANNOT_WRITE_PID: HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_ALREADY_RUNNING: HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str()); break; default: HAGGLE_ERR("Unknown PID file error\n"); } shouldCleanupPidFile = false; return -1; } #if defined(OS_UNIX) && !defined(OS_ANDROID) setrawtty(); #endif /* Seed the random number generator */ prng_init(); // SW: START CONFIG PATH (instead of hardcoded ~/.Haggle/config.xml), if (useMemoryDB) { kernel = new HaggleKernel(configFile, new MemoryDataStore(recreateDataStore)); } else { kernel = new HaggleKernel(configFile, new SQLDataStore(recreateDataStore)); } // SW: END CONFIG PATH. if (!kernel || !kernel->init()) { fprintf(stderr, "Kernel initialization error!\n"); return -1; } // Build a Haggle configuration am = new ApplicationManager(kernel); if (!am || !am->init()) { HAGGLE_ERR("Could not initialize application manager\n"); goto finish; } dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate); if (!dm || !dm->init()) { HAGGLE_ERR("Could not initialize data manager\n"); goto finish; } // SW: START: SendPriorityManager spm = new SendPriorityManager(kernel); if (!spm || !spm->init()) { HAGGLE_ERR("Could not initialize send priority manager\n"); goto finish; } // SW: END: SendPriorityManager nm = new NodeManager(kernel); if (!nm || !nm->init()) { HAGGLE_ERR("Could not initialize node manager\n"); goto finish; } pm = new ProtocolManager(kernel); if (!pm || !pm->init()) { HAGGLE_ERR("Could not initialize protocol manager\n"); goto finish; } fm = new ForwardingManager(kernel); if (!fm || !fm->init()) { HAGGLE_ERR("Could not initialize forwarding manager\n"); goto finish; } sm = new SecurityManager(kernel, securityLevel); if (!sm || !sm->init()) { HAGGLE_ERR("Could not initialize security manager\n"); goto finish; } fragmentationManager = new FragmentationManager(kernel); if(!fragmentationManager || !fragmentationManager->init()) { HAGGLE_ERR("Could not initialize fragmentationManager\n"); goto finish; } networkCodingManager = new NetworkCodingManager(kernel); if(!networkCodingManager || !networkCodingManager->init()) { HAGGLE_ERR("Could not initialize networkCodingManager \n"); goto finish; } //JM replicationManager = new ReplicationManager(kernel); if (!replicationManager || !replicationManager->init()) { HAGGLE_ERR("Could not initialize replication manager\n"); goto finish; } lm = new LossEstimateManager(kernel); if(!lm || !lm->init()){ HAGGLE_ERR("Could not initialize LossEstimateManager \n"); goto finish; } #ifdef USE_UNIX_APPLICATION_SOCKET p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm); if (!p || !p->init()) { HAGGLE_ERR("Could not initialize LOCAL protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); #endif p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm); /* Add ConnectivityManager last since it will start to * discover interfaces and generate events. At that * point the other managers should already be * running. */ if (!p || !p->init()) { HAGGLE_ERR("Could not initialize UDP Application protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); // SW: start interest manager im = new InterestManager(kernel); if (!im || !im->init()) { HAGGLE_ERR("Could not initialize interest manager\n"); goto finish; } // SW: end interest manager /* MOS - disable resource mananager due high cpu utilization bug on Android rm = new ResourceManager(kernel); if (!rm || !rm->init()) { HAGGLE_ERR("Could not initialize resource manager\n"); goto finish; } */ if (!isBenchmarking) { cm = new ConnectivityManager(kernel); if (!cm || !cm->init()) { HAGGLE_ERR("Could not initialize connectivity manager\n"); goto finish; } } else { bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num); if (!bm || !bm->init()) { HAGGLE_ERR("Could not initialize benchmark manager\n"); goto finish; } } #if defined(ENABLE_DEBUG_MANAGER) // It seems as if there can be only one accept() per // thread... we need to make the DebugManager register // protocol or something with the ProtocolTCPServer // somehow db = new DebugManager(kernel, runAsInteractive); if (!db || !db->init()) { HAGGLE_ERR("Could not initialize debug manager\n"); /* Treat as non critical error. */ } #endif HAGGLE_DBG("Starting Haggle...\n"); #ifdef OS_WINDOWS_MOBILE if (platform_type(current_platform()) == platform_windows_mobile_professional) tray_notification_add(g_hInstance, kernel); #endif kernel->run(); if(kernel->hasFatalError()) retval = EXIT_FAILURE; else retval = EXIT_SUCCESS; HAGGLE_DBG("Haggle finished...\n"); finish: if (bm) delete bm; if (lm) delete lm; if (fragmentationManager) { delete fragmentationManager; fragmentationManager = NULL; } if (networkCodingManager) delete networkCodingManager; //JM if (replicationManager) delete replicationManager; if (cm) delete cm; if (sm) delete sm; if (fm) delete fm; if (pm) delete pm; if (nm) delete nm; if (dm) delete dm; // SW: START: SendPriorityManager if (spm) delete spm; // SW: END: SendPriorityManager if (am) delete am; // SW: start interest manager if (im) delete im; // SW: end interest manager #if defined(ENABLE_DEBUG_MANAGER) if (db) delete db; #endif if (rm) delete rm; #ifdef OS_WINDOWS_MOBILE tray_notification_remove(); #endif delete kernel; kernel = NULL; xmlCleanupParser(); // MOS return retval; }
int run_haggle() { #ifdef ENABLE_DEBUG_MANAGER DebugManager *db = NULL; #endif ApplicationManager *am = NULL; DataManager *dm = NULL; NodeManager *nm = NULL; ProtocolManager *pm = NULL; ForwardingManager *fm = NULL; SecurityManager *sm = NULL; ConnectivityManager *cm = NULL; #ifdef BENCHMARK BenchmarkManager *bm = NULL; //recreateDataStore = true; #endif ResourceManager *rm = NULL; ProtocolSocket *p = NULL; #ifdef OS_WINDOWS_MOBILE // For testing we force the deletion of the data store //recreateDataStore = true; #endif int retval = EXIT_FAILURE; if (!create_path(HAGGLE_DEFAULT_STORAGE_PATH)) { HAGGLE_ERR("Could not create Haggle storage path : %s\n", HAGGLE_DEFAULT_STORAGE_PATH); return -1; } retval = write_pid_file(getpid()); if (retval != HAGGLE_PROCESS_NO_ERROR) { switch (retval) { case HAGGLE_PROCESS_BAD_PID: HAGGLE_ERR("Cannot read PID file %s.\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_CANNOT_WRITE_PID: HAGGLE_ERR("Cannot write PID file %s\n", PID_FILE.c_str()); break; case HAGGLE_PROCESS_ALREADY_RUNNING: HAGGLE_ERR("PID file %s indicates that Haggle is already running.\n", PID_FILE.c_str()); break; default: HAGGLE_ERR("Unknown PID file error\n"); } shouldCleanupPidFile = false; return -1; } #if defined(OS_UNIX) && !defined(OS_ANDROID) setrawtty(); #endif /* Seed the random number generator */ prng_init(); kernel = new HaggleKernel(new SQLDataStore(recreateDataStore)); if (!kernel || !kernel->init()) { fprintf(stderr, "Kernel initialization error!\n"); return -1; } // Build a Haggle configuration am = new ApplicationManager(kernel); if (!am || !am->init()) { HAGGLE_ERR("Could not initialize application manager\n"); goto finish; } dm = new DataManager(kernel, setCreateTimeOnBloomfilterUpdate); if (!dm || !dm->init()) { HAGGLE_ERR("Could not initialize data manager\n"); goto finish; } nm = new NodeManager(kernel); if (!nm || !nm->init()) { HAGGLE_ERR("Could not initialize node manager\n"); goto finish; } pm = new ProtocolManager(kernel); if (!pm || !pm->init()) { HAGGLE_ERR("Could not initialize protocol manager\n"); goto finish; } fm = new ForwardingManager(kernel); if (!fm || !fm->init()) { HAGGLE_ERR("Could not initialize forwarding manager\n"); goto finish; } sm = new SecurityManager(kernel, securityLevel); if (!sm || !sm->init()) { HAGGLE_ERR("Could not initialize security manager\n"); goto finish; } #ifdef USE_UNIX_APPLICATION_SOCKET p = new ProtocolLOCAL(kernel->getStoragePath() + "/" + HAGGLE_LOCAL_SOCKET, pm); if (!p || !p->init()) { HAGGLE_ERR("Could not initialize LOCAL protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); #endif p = new ProtocolUDP("127.0.0.1", HAGGLE_SERVICE_DEFAULT_PORT, pm); /* Add ConnectivityManager last since it will start to * discover interfaces and generate events. At that * point the other managers should already be * running. */ if (!p || !p->init()) { HAGGLE_ERR("Could not initialize UDP Application protocol\n"); goto finish; } p->setFlag(PROT_FLAG_APPLICATION); p->registerWithManager(); rm = new ResourceManager(kernel); if (!rm || !rm->init()) { HAGGLE_ERR("Could not initialize resource manager\n"); goto finish; } #ifdef BENCHMARK if (!isBenchmarking) { #endif cm = new ConnectivityManager(kernel); if (!cm || !cm->init()) { HAGGLE_ERR("Could not initialize connectivity manager\n"); goto finish; } #ifdef BENCHMARK } else { bm = new BenchmarkManager(kernel, Benchmark_DataObjects_Attr, Benchmark_Nodes_Attr, Benchmark_Attr_Num, Benchmark_DataObjects_Num, Benchmark_Test_Num); if (!bm || !bm->init()) { HAGGLE_ERR("Could not initialize benchmark manager\n"); goto finish; } } #endif #if defined(ENABLE_DEBUG_MANAGER) // It seems as if there can be only one accept() per // thread... we need to make the DebugManager register // protocol or something with the ProtocolTCPServer // somehow db = new DebugManager(kernel, runAsInteractive); if (!db || !db->init()) { HAGGLE_ERR("Could not initialize debug manager\n"); /* Treat as non critical error. */ } #endif HAGGLE_DBG("Starting Haggle...\n"); #ifdef OS_WINDOWS_MOBILE if (platform_type(current_platform()) == platform_windows_mobile_professional) tray_notification_add(g_hInstance, kernel); #endif kernel->run(); retval = EXIT_SUCCESS; HAGGLE_DBG("Haggle finished...\n"); finish: #ifdef BENCHMARK if (bm) delete bm; #endif if (cm) delete cm; if (sm) delete sm; if (fm) delete fm; if (pm) delete pm; if (nm) delete nm; if (dm) delete dm; if (am) delete am; #if defined(ENABLE_DEBUG_MANAGER) if (db) delete db; #endif if (rm) delete rm; #ifdef OS_WINDOWS_MOBILE tray_notification_remove(); #endif delete kernel; kernel = NULL; return retval; }