int main() { cout << "ApplicationManager" << endl; // prints ApplicationManager ApplicationManager am; Benchmark bench(&am); SocketManager sm(&am); am.Start(); return 0; }
void createModules() { ApplicationManager *appManager = ApplicationManager::getInstance(); #ifdef EXTENSION_MODULES_ENABLED // appManager->addModule( createModule< AnnotationModule >() ); appManager->addModule( createModule< ShoulderMeasurementModule >() ); // appManager->addModule( createModule< OrganSegmentationModule >() ); #endif }
AppIdDesktopFile DBusWindowStack::GetAppIdFromPid(unsigned int pid) { AppIdDesktopFile res; ApplicationManager *appMgr = static_cast<ApplicationManager*>(parent()); const Application *app = appMgr->findApplicationWithPid(pid); if (app) { res.app_id = app->appId(); res.desktop_file = app->desktopFile(); } return res; }
QList<WindowInfo> DBusWindowStack::GetWindowStack() { QList<WindowInfo> res; ApplicationManager *appMgr = static_cast<ApplicationManager*>(parent()); const QList<Application*> &applications = appMgr->list(); Q_FOREACH(Application* app, applications) { WindowInfo wi; wi.window_id = 0; wi.app_id = app->appId(); wi.focused = app->focused(); wi.stage = 0; res << wi; }
void NetworkManager::setProperties(const std::vector<char> &data) { ProjectProperties properties; ByteBuffer buffer(&data[0], data.size()); char chr; buffer >> chr; buffer >> properties.scaleMode; buffer >> properties.logicalWidth; buffer >> properties.logicalHeight; int scaleCount; buffer >> scaleCount; properties.imageScales.resize(scaleCount); for (int i = 0; i < scaleCount; ++i) { buffer >> properties.imageScales[i].first; buffer >> properties.imageScales[i].second; } buffer >> properties.orientation; buffer >> properties.fps; buffer >> properties.retinaDisplay; buffer >> properties.autorotation; buffer >> properties.mouseToTouch; buffer >> properties.touchToMouse; buffer >> properties.mouseTouchOrder; application_->setProjectProperties(properties); }
int main() { ActionType ActType; ApplicationManager AppManager; do { // Read user action ActType = AppManager.GetUserAction(); // Exexute the action AppManager.ExecuteAction(ActType); // Update the drawing window AppManager.UpdateInterface(); } while (ActType != EXIT); return 0; }
int main() { ActionType ActType; //Create an object of ApplicationManager ApplicationManager AppManager; do { //Step I - Read user input (action) ActType = AppManager.GetUserAction(); //Steps II & III - Create & Exexute the action AppManager.ExecuteAction(ActType); //Step IV - Update the interface AppManager.UpdateInterface(); }while(ActType != EXIT); return 0; }
void NetworkManager::setProjectName(const std::vector<char> &data) { ByteBuffer buffer(&data[0], data.size()); char chr; buffer >> chr; std::string str; buffer >> str; application_->setProjectName(str.c_str()); }
void NetworkManager::play(const std::vector<char> &data) { std::vector<std::string> luafiles; ByteBuffer buffer(&data[0], data.size()); char chr; buffer >> chr; while (buffer.eob() == false) { std::string str; buffer >> str; luafiles.push_back(str); } application_->play(luafiles); }
std::string evalute::evalute_elapsed(Watch* watch) { ApplicationManager* app = boost::get<ApplicationManager*>(watch->Object); return IntToStr(app->getElapsed()); }
int main( int argc, char** argv ) { //std::ofstream logFile( "Log.txt" ); //SET_LOUT( logFile ); //D_COMMAND( std::ofstream debugFile( "Debug.txt" ); ); //SET_DOUT( debugFile ); //XInitThreads(); ApplicationManager appManager; boost::filesystem::path executablePath(argv[0]); boost::filesystem::path dataDirName = GET_SETTINGS( "application.data_directory", std::string, (boost::filesystem::path(argv[0]).parent_path() / "data").string() ); //If we cannot locate data directory - try other posiible locations if (!boost::filesystem::exists(dataDirName) || !boost::filesystem::is_directory(dataDirName)) { std::vector<boost::filesystem::path> possibleDataDirs; possibleDataDirs.push_back(boost::filesystem::current_path() / "data"); possibleDataDirs.push_back(executablePath.parent_path() / "data"); possibleDataDirs.push_back(executablePath.parent_path().parent_path() / "data"); std::vector<boost::filesystem::path>::const_iterator it = possibleDataDirs.begin(); bool found = false; LOG( "Trying to locate 'data' directory:" ); while (!found && it != possibleDataDirs.end()) { LOG_CONT( "\tChecking: " << it->string() << " ... "); if (boost::filesystem::exists(*it) && boost::filesystem::is_directory(*it)) { dataDirName = *it; SET_SETTINGS( "application.data_directory", std::string, dataDirName.string() ); found = true; LOG( "SUCCESS" ); } else { LOG( "FAILED" ); } ++it; } if (!found) { BOOST_THROW_EXCEPTION( M4D::ErrorHandling::EDirNotFound() ); } } boost::filesystem::path dirName = GET_SETTINGS( "gui.icons_directory", std::string, ( dataDirName / "icons" ).string() ); appManager.setIconsDirectory(dirName); appManager.initialize( argc, argv ); try { //processCommandLine( argc, argv ); ViewerWindow viewer; appManager.setMainWindow( viewer ); createModules(); appManager.loadModules(); viewer.showMaximized(); return appManager.exec(); } catch ( std::exception &e ) { QMessageBox::critical ( NULL, "Exception", QString( e.what() ) ); } catch (...) { QMessageBox::critical ( NULL, "Exception", "Unknown error" ); } return 1; }
void NetworkManager::stop() { application_->stop(); }
void NetworkManager::tick() { int dataTotal = 0; while (true) { if(!openProject_.empty()){ application_->openProject(openProject_.c_str()); openProject_.clear(); } int dataSent0 = server_->dataSent(); int dataReceived0 = server_->dataReceived(); NetworkEvent event; server_->tick(&event); int dataSent1 = server_->dataSent(); int dataReceived1 = server_->dataReceived(); if (event.eventCode == eDataReceived) { const std::vector<char>& data = event.data; switch (data[0]) { case 0: createFolder(data); break; case 1: createFile(data); break; case 2:{ const char* absfilename = g_pathForFile("../luafiles.txt"); FILE* fos = fopen(absfilename, "wb"); fwrite(&data[0], data.size(), 1, fos); fclose(fos); play(data); } break; case 3: stop(); break; case 7: sendFileList(); break; case 8: setProjectName(data); break; case 9: deleteFile(data); break; case 11:{ const char* absfilename = g_pathForFile("../properties.bin"); FILE* fos = fopen(absfilename, "wb"); fwrite(&data[0], data.size(), 1, fos); fclose(fos); setProperties(data); } break; } } int dataDelta = (dataSent1 - dataSent0) + (dataReceived1 - dataReceived0); dataTotal += dataDelta; if (dataDelta == 0 || dataTotal > 1024) break; } }
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; }