//TODO: check nested applications too void ApplicationModel::getApplicationBounds(Goocanvas::Bounds& bounds) { ModulePContainer modules = parentWindow->manager.getKnowledgeBase()->getModules(application); CnnContainer connections = parentWindow->manager.getKnowledgeBase()->getConnections(application); ApplicaitonPContainer applications = parentWindow->manager.getKnowledgeBase()->getApplications(application); ModulePIterator itr; bounds.set_x1(0); bounds.set_x2(0); bounds.set_y1(0); bounds.set_y2(0); for(itr=modules.begin(); itr!=modules.end(); itr++) { Module* module = (*itr); //if(module->owner() == application) //{ if(module->getModelBase().points.size()>0) { if((bounds.get_x1() == 0) || (module->getModelBase().points[0].x < bounds.get_x1()) ) bounds.set_x1(module->getModelBase().points[0].x); if((bounds.get_x2() == 0) || (module->getModelBase().points[0].x > bounds.get_x1()) ) bounds.set_x2(module->getModelBase().points[0].x); if((bounds.get_y1() == 0) || (module->getModelBase().points[0].y < bounds.get_y1()) ) bounds.set_y1(module->getModelBase().points[0].y); if((bounds.get_y2() == 0) || (module->getModelBase().points[0].y > bounds.get_y2()) ) bounds.set_y2(module->getModelBase().points[0].y); } //} } CnnIterator citr; for(citr=connections.begin(); citr<connections.end(); citr++) { Connection baseCon = *citr; //if(baseCon.owner() == application) //{ GraphicModel model = baseCon.getModelBase(); int size = model.points.size(); for(int i=0; i<size; i++) { if((bounds.get_x1() == -1) || (model.points[i].x < bounds.get_x1()) ) bounds.set_x1(model.points[i].x); if((bounds.get_x2() == -1) || (model.points[i].x > bounds.get_x2()) ) bounds.set_x2(model.points[i].x); if((bounds.get_y1() == -1) || (model.points[i].y < bounds.get_y1()) ) bounds.set_y1(model.points[i].y); if((bounds.get_y2() == -1) || (model.points[i].y > bounds.get_y2()) ) bounds.set_y2(model.points[i].y); } //} } }
bool SafeManager::prepare(Manager* lazy, yarp::os::Property* pConfig, ApplicationEvent* event) { eventReceiver = event; m_pConfig = pConfig; if(pConfig->find("watchdog").asString() == "yes") enableWatchDog(); else disableWatchod(); if(pConfig->find("auto_dependency").asString() == "yes") enableAutoDependency(); else disableAutoDependency(); if(pConfig->find("auto_connect").asString() == "yes") enableAutoConnect(); else disableAutoConnect(); // making manager from lazy manager KnowledgeBase* lazy_kb = lazy->getKnowledgeBase(); ModulePContainer mods = lazy_kb->getModules(); for(ModulePIterator itr=mods.begin(); itr!=mods.end(); itr++) getKnowledgeBase()->addModule((*itr)); ResourcePContainer res = lazy_kb->getResources(); for(ResourcePIterator itr=res.begin(); itr!=res.end(); itr++) getKnowledgeBase()->addResource((*itr)); ApplicaitonPContainer apps = lazy_kb->getApplications(); for(ApplicationPIterator itr=apps.begin(); itr!=apps.end(); itr++) getKnowledgeBase()->addApplication((*itr)); return true; }
void ApplicationModel::findInputOutputData(Connection& cnn, ModulePContainer &modules, InputData* &input_, OutputData* &output_) { input_ = NULL; output_ = NULL; string strTo = cnn.to(); string strFrom = cnn.from(); ModulePIterator itr; for(itr=modules.begin(); itr!=modules.end(); itr++) { Module* module = (*itr); if(module->owner() == application) { for(int i=0; i<module->inputCount(); i++) { InputData &input = module->getInputAt(i); string strInput = string(module->getPrefix()) + string(input.getPort()); if(strTo == strInput) { input_ = &input; break; } } for(int i=0; i<module->outputCount(); i++) { OutputData &output = module->getOutputAt(i); string strOutput = string(module->getPrefix()) + string(output.getPort()); if(strFrom == strOutput) { output_ = &output; break; } } } } }
ApplicationModel::ApplicationModel(ApplicationWindow* parentWnd, Application* app) : GroupModel() { parentWindow = parentWnd; application = app; app->setModel(this); // adding application name text = Goocanvas::TextModel::create(app->getName()); #ifdef GLIBMM_PROPERTIES_ENABLED text->property_font() = FONT_DESC; text->property_alignment().set_value(Pango::ALIGN_CENTER); #endif PangoLayout *layout = gtk_widget_create_pango_layout((GtkWidget*)parentWindow->gobj(), app->getName()); PangoFontDescription *fontdesc = pango_font_description_from_string(FONT_DESC); pango_layout_set_font_description (layout, fontdesc); pango_layout_get_pixel_size (layout, &text_w, &text_h); text->property_x().set_value(TEXT_MARGINE); text->property_y().set_value(text_h/2.0); poly = Goocanvas::PolylineModel::create(0,0,0,0); poly->property_close_path().set_value(true); poly->property_line_width().set_value(1.2); //poly->property_fill_color().set_value(APPLICATION_COLOR); poly->property_fill_color_rgba().set_value(APPLICATION_COLOR); poly->property_stroke_color().set_value("DodgerBlue3"); //GooCanvasLineDash *dash = goo_canvas_line_dash_new (2, 3.0, 3.0); //g_object_set(poly->gobj(), "line-dash", dash, NULL); shadow = Goocanvas::PolylineModel::create(0,0,0,0); shadow->property_close_path().set_value(false); shadow->property_line_width().set_value(3.0); shadow->property_stroke_color().set_value("gray"); getApplicationBounds(bounds); width = MAX(MIN_WIDTH + text_w, bounds.get_x2()-bounds.get_x1() + 2*ITEMS_MARGIE); height = MAX(MIN_HEIGHT, bounds.get_y2()-bounds.get_y1() + 2*ITEMS_MARGIE + text_h); Goocanvas::Points points(6); points.set_coordinate(0, 0, 0); points.set_coordinate(1, text_w+TEXT_MARGINE*2, 0); points.set_coordinate(2, text_w+TEXT_MARGINE*2, text_h+TEXT_MARGINE); points.set_coordinate(3, width, text_h+TEXT_MARGINE); points.set_coordinate(4, width, height); points.set_coordinate(5, 0, height); poly->property_points().set_value(points); Goocanvas::Points points3(3); points3.set_coordinate(0, width, text_h+TEXT_MARGINE); points3.set_coordinate(1, width, height); points3.set_coordinate(2, 0, height); shadow->property_points().set_value(points3); shadow->translate(1,1); this->add_child(shadow); this->add_child(poly); this->add_child(text); ModulePContainer modules = parentWindow->manager.getKnowledgeBase()->getModules(application); CnnContainer connections = parentWindow->manager.getKnowledgeBase()->getConnections(application); ApplicaitonPContainer applications = parentWindow->manager.getKnowledgeBase()->getApplications(application); int index = 0; ModulePIterator itr; for(itr=modules.begin(); itr!=modules.end(); itr++) { Module* module = (*itr); Glib::RefPtr<ModuleModel> mod = ModuleModel::create(parentWindow, module, true); this->add_child(mod); double x, y; x = (module->getModelBase().points.size()>0) ? module->getModelBase().points[0].x : index%900+10; y = (module->getModelBase().points.size()>0) ? module->getModelBase().points[0].y : ((index+=300)/900)*100+10; x -= bounds.get_x1(); x += ITEMS_MARGIE; y -= bounds.get_y1(); y += ITEMS_MARGIE + text_h + TEXT_MARGINE; mod->translate(x, y); double end_x, end_y; Goocanvas::Points points = poly->property_points().get_value(); points.get_coordinate(4, end_x, end_y); if((x + mod->getWidth() + ITEMS_MARGIE) >= end_x) width = x + mod->getWidth() + ITEMS_MARGIE; if((y + mod->getHeight() + ITEMS_MARGIE) >= end_y) height = y + mod->getHeight() + ITEMS_MARGIE; //points.set_coordinate(0, 0, 0); //points.set_coordinate(1, text_w+TEXT_MARGINE*2, 0); //points.set_coordinate(2, text_w+TEXT_MARGINE*2, text_h+TEXT_MARGINE); points.set_coordinate(3, width, text_h+TEXT_MARGINE); points.set_coordinate(4, width, height); points.set_coordinate(5, 0, height); poly->property_points().set_value(points); Goocanvas::Points points3(3); points3.set_coordinate(0, width, text_h+TEXT_MARGINE); points3.set_coordinate(1, width, height); points3.set_coordinate(2, 0, height); shadow->property_points().set_value(points3); } }
bool YConsoleManager::process(const vector<string> &cmdList) { if (!cmdList.size() || cmdList[0] == "") return true; /** * help */ if((cmdList.size() == 1) && (cmdList[0] == "help")) { help(); return true; } /** * add application */ if((cmdList.size() == 3) && (cmdList[0] == "add") && (cmdList[1] == "app")) { if(addApplication(cmdList[2].c_str())) cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl; reportErrors(); #ifdef WITH_READLINE updateAppNames(&appnames); #endif return true; } /** * add module */ if((cmdList.size() == 3) && (cmdList[0] == "add") && (cmdList[1] == "mod")) { if(addModule(cmdList[2].c_str())) cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl; reportErrors(); return true; } /** * add resource */ if((cmdList.size() == 3) && (cmdList[0] == "add") && (cmdList[1] == "res")) { if(addResource(cmdList[2].c_str())) cout<<INFO<<cmdList[2]<<" is successfully added."<<ENDC<<endl; reportErrors(); return true; } /** * load application */ if((cmdList.size() == 3) && (cmdList[0] == "load") && (cmdList[1] == "app")) { if(loadApplication(cmdList[2].c_str())) { //cout<<cmdList[2]<<" is successfully loaded."<<endl; which(); } reportErrors(); return true; } /** * load module */ /* if((cmdList.size() >= 3) && (cmdList[0] == "load") && (cmdList[1] == "mod")) { if(cmdList.size() > 3) { if(manager.loadModule(cmdList[2].c_str(), cmdList[3].c_str())) cout<<cmdList[2]<<" is successfully loaded."<<endl; } else if(manager.loadModule(cmdList[2].c_str())) cout<<cmdList[2]<<" is successfully loaded."<<endl; reportErrors(); return true; } */ /** * run */ if((cmdList.size() == 1) && (cmdList[0] == "run")) { bShouldRun = run(); reportErrors(); return true; } if((cmdList.size() >= 2) && (cmdList[0] == "run")) { bShouldRun = false; for(unsigned int i=1; i<cmdList.size(); i++) bShouldRun |= run(atoi(cmdList[i].c_str())); reportErrors(); return true; } /** * stop */ if((cmdList.size() == 1) && (cmdList[0] == "stop")) { bShouldRun = false; stop(); reportErrors(); return true; } if((cmdList.size() >= 2) && (cmdList[0] == "stop")) { //bShouldRun = false; for(unsigned int i=1; i<cmdList.size(); i++) stop(atoi(cmdList[i].c_str())); bShouldRun = !suspended(); reportErrors(); return true; } /** * kill */ if((cmdList.size() == 1) && (cmdList[0] == "kill")) { bShouldRun = false; kill(); reportErrors(); return true; } if((cmdList.size() >= 2) && (cmdList[0] == "kill")) { //bShouldRun = false; for(unsigned int i=1; i<cmdList.size(); i++) kill(atoi(cmdList[i].c_str())); bShouldRun = !suspended(); reportErrors(); return true; } /** * connect */ if((cmdList.size() == 1) && (cmdList[0] == "connect")) { connect(); reportErrors(); return true; } if((cmdList.size() >= 2) && (cmdList[0] == "connect")) { for(unsigned int i=1; i<cmdList.size(); i++) connect(atoi(cmdList[i].c_str())); reportErrors(); return true; } /** * disconnect */ if((cmdList.size() == 1) && (cmdList[0] == "disconnect")) { disconnect(); reportErrors(); return true; } if((cmdList.size() >= 2) && (cmdList[0] == "disconnect")) { for(unsigned int i=1; i<cmdList.size(); i++) disconnect(atoi(cmdList[i].c_str())); reportErrors(); return true; } /** * which */ if((cmdList.size() == 1) && (cmdList[0] == "which")) { which(); return true; } /** * check for dependencies */ if((cmdList.size() == 2) && (cmdList[0] == "check") && (cmdList[1] == "dep")) { if(checkDependency()) cout<<INFO<<"All of resource dependencies are satisfied."<<ENDC<<endl; reportErrors(); return true; } /** * check for running state */ if((cmdList.size() == 3) && (cmdList[0] == "check") && (cmdList[1] == "state")) { ExecutablePContainer modules = getExecutables(); unsigned int id = (unsigned int)atoi(cmdList[2].c_str()); if(id>=modules.size()) { cout<<FAIL<<"ERROR: "<<INFO<<"Module id is out of range."<<ENDC<<endl; return true; } if(running(id)) cout<<OKGREEN<<"<RUNNING> "; else cout<<FAIL<<"<STOPPED> "; cout<<INFO<<"("<<id<<") "; cout<<modules[id]->getCommand(); cout<<" ["<<modules[id]->getHost()<<"]"<<ENDC<<endl; reportErrors(); return true; } if((cmdList.size() == 2) && (cmdList[0] == "check") && (cmdList[1] == "state")) { checkStates(); reportErrors(); return true; } /** * check for connection state */ if((cmdList.size() == 3) && (cmdList[0] == "check") && (cmdList[1] == "con")) { CnnContainer connections = getConnections(); unsigned int id = (unsigned int)atoi(cmdList[2].c_str()); if(id>=connections.size()) { cout<<FAIL<<"ERROR: "<<INFO<<"Connection id is out of range."<<ENDC<<endl; return true; } if(connected(id)) cout<<OKGREEN<<"<CONNECTED> "; else cout<<FAIL<<"<DISCONNECTED> "; cout<<INFO<<"("<<id<<") "; cout<<connections[id].from()<<" - "<<connections[id].to(); cout<<" ["<<connections[id].carrier()<<"]"<<ENDC<<endl; reportErrors(); return true; } if((cmdList.size() == 2) && (cmdList[0] == "check") && (cmdList[1] == "con")) { checkConnections(); return true; } /** * list available modules */ if((cmdList.size() == 2) && (cmdList[0] == "list") && (cmdList[1] == "mod")) { KnowledgeBase* kb = getKnowledgeBase(); ModulePContainer mods = kb->getModules(); int id = 0; for(ModulePIterator itr=mods.begin(); itr!=mods.end(); itr++) { string fname; string fpath = (*itr)->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos) fname = fpath.substr(pos); else fname = fpath; cout<<INFO<<"("<<id++<<") "; cout<<OKBLUE<<(*itr)->getName()<<ENDC; cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl; } return true; } /** * list available applications */ if((cmdList.size() == 2) && (cmdList[0] == "list") && (cmdList[1] == "app")) { KnowledgeBase* kb = getKnowledgeBase(); ApplicaitonPContainer apps = kb->getApplications(); int id = 0; for(ApplicationPIterator itr=apps.begin(); itr!=apps.end(); itr++) { string fname; string fpath = (*itr)->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos) fname = fpath.substr(pos); else fname = fpath; cout<<INFO<<"("<<id++<<") "; cout<<OKBLUE<<(*itr)->getName()<<ENDC; cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl; } return true; } /** * list available resources */ if((cmdList.size() == 2) && (cmdList[0] == "list") && (cmdList[1] == "res")) { KnowledgeBase* kb = getKnowledgeBase(); ResourcePContainer resources = kb->getResources(); int id = 0; for(ResourcePIterator itr=resources.begin(); itr!=resources.end(); itr++) { Computer* comp = dynamic_cast<Computer*>(*itr); if(comp) { string fname; string fpath = comp->getXmlFile(); size_t pos = fpath.rfind(PATH_SEPERATOR); if(pos!=string::npos) fname = fpath.substr(pos); else fname = fpath; cout<<INFO<<"("<<id++<<") "; if(comp->getDisable()) cout<<WARNING<<comp->getName()<<ENDC; else cout<<OKBLUE<<comp->getName()<<ENDC; cout<<INFO<<" ["<<fname<<"]"<<ENDC<<endl; } } return true; } /** * export knowledgebase graph */ if((cmdList.size() == 2) && (cmdList[0] == "export") ) { if(!exportDependencyGraph(cmdList[1].c_str())) cout<<FAIL<<"ERROR: "<<INFO<<"Cannot export graph to "<<cmdList[1]<<"."<<ENDC<<endl; return true; } /** * show module's information */ if((cmdList.size() == 3) && (cmdList[0] == "show") && (cmdList[1] == "mod")) { KnowledgeBase* kb = getKnowledgeBase(); if(!kb->getModule(cmdList[2].c_str())) { cout<<FAIL<<"ERROR: "<<INFO<<"'"<<cmdList[2].c_str()<<"' not found."<<ENDC<<endl; return true; } cout<<INFO; PRINT_MODULE(kb->getModule(cmdList[2].c_str())); cout<<ENDC; return true; } /** * set an option */ if((cmdList.size() == 3) && (cmdList[0] == "set")) { config.unput(cmdList[1].c_str()); config.put(cmdList[1].c_str(), cmdList[2].c_str()); if(cmdList[1] == string("watchdog")) { if(cmdList[2] == string("yes")) enableWatchDog(); else disableWatchod(); } if(cmdList[1] == string("auto_dependency")) { if(cmdList[2] == string("yes")) enableAutoDependency(); else disableAutoDependency(); } if(cmdList[1] == string("auto_connect")) { if(cmdList[2] == string("yes")) enableAutoConnect(); else disableAutoConnect(); } if(cmdList[1] == string("color_theme")) { if(cmdList[2] == string("dark")) setColorTheme(THEME_DARK); else if(cmdList[2] == string("light")) setColorTheme(THEME_LIGHT); else setColorTheme(THEME_NONE); } return true; } /** * get an option */ if((cmdList.size() == 2) && (cmdList[0] == "get")) { if(config.check(cmdList[1].c_str())) { cout<<OKBLUE<<cmdList[1]<<INFO<<" = "; cout<<OKGREEN<<config.find(cmdList[1].c_str()).asString()<<ENDC<<endl; } else cout<<FAIL<<"ERROR: "<<INFO<<"'"<<cmdList[1].c_str()<<"' not found."<<ENDC<<endl; return true; } /** * load balancing */ if((cmdList.size() == 2) && (cmdList[0] == "assign") && (cmdList[1] == "hosts")) { loadBalance(); reportErrors(); return true; } return false; }