MatrixManager::~MatrixManager() { stop(); ::sailor::WriteLocker instance_locker(&_instance_lock); ::sailor::WriteLocker expect_locker(&_expect_lock); // delete instance clear_instance_list(); // delete expect if (_expect_list != NULL) { delete _expect_list; _expect_list = NULL; } }
int main_menu(void) { MENU *my_menu = NULL; ITEM **my_items = NULL; struct tool_instance *list = NULL; const char *ret_msg = NULL; // Init at refresh for first loop. int c = 'R'; do { switch (c) { // Navigate in the menu case KEY_DOWN: case KEY_RIGHT: menu_driver(my_menu, REQ_DOWN_ITEM); break ; case KEY_UP: case KEY_LEFT: menu_driver(my_menu, REQ_UP_ITEM); break ; // Select a migration to monitor case ' ': case 13: // Enter key { if (item_count(my_menu) > 0) { ITEM *curitem = current_item(my_menu); if (view_instance(item_description(curitem)) != EXIT_SUCCESS) { ret_msg = "An error occured while trying to display the tool's data."; } } } // No break here to allow refreshing the list // when coming out of the instance display. // Refresh the list. case 'r': case 'R': if (list) clear_instance_list(list); list = get_instance_list(); if (list == NULL) mvprintw(0, 0, "cloudmig-view: No cloudmig tool is running at the moment.\n"); if (my_menu) clear_menu(my_menu, my_items); my_items = NULL; my_menu = NULL; if (fill_menu(list, &my_items, &my_menu)) return EXIT_FAILURE; post_menu(my_menu); break; // Leave the monitor case 'q': case 'Q': break ; // Ignore the others default: break ; } mvprintw(LINES - 4, 0, "Use <SPACE> or <ENTER> to select the process to monitor."); mvprintw(LINES - 3, 0, " <q> or <Q> to quit this program."); mvprintw(LINES - 2, 0, " <r> or <R> to see refresh the list manually."); if (ret_msg) { mvprintw(LINES -6, 0, "%.*s", COLS, ret_msg); ret_msg = NULL; } refresh(); } while ((c = getch()) != 'q'); return EXIT_FAILURE; }
bool MatrixManager::load_instance_from_file() { assert(g_config); // private so not need to lock. if (!_instance_list.empty()) { LOG.warn("MatrixManager: instance_list is not empty, could not load from file."); } _host_info.init_used_resource(); _current_generation = 0; DIR * dir = NULL; struct dirent dire, *dirp = NULL; bool ret = true; errno = 0; std::vector<uint64_t> tmp_generation_list; dir = opendir(g_config->META_PATH); if (NULL == dir) { LOG.error("MatrixManager: open dir %s fail: %d.", g_config->META_PATH, errno); return false; } memset(&dire, 0, sizeof(dire)); errno = 0; while (readdir_r(dir, &dire, &dirp) == 0) { if (dirp == NULL) { LOG.trace("MatrixManager: load_instance_from_file no more entry to read"); break; } std::string name = dire.d_name; if (name == "." || name == "..") { LOG.trace("MatrixManager: load_instance_from_file skip %s", name.c_str()); continue; } LOG.info("MatrixManager: load_instance_from_file %s.", name.c_str()); Instance* slot = NULL; try { slot = new Instance(name); } catch (std::exception& e) { LOG.error("MatrixManager: failed to load instance: %s", e.what()); ret = false; break; } const InstanceInfo& instance_info = slot->get_instance_info(); // check dup instance_name if (_instance_list.find(instance_info.get_instance_name()) != _instance_list.end()) { LOG.error("MatrixManager: dup service meta find (dup instance name) %s", name.c_str()); delete slot; ret = false; break; } // check dup generation if (std::find(tmp_generation_list.begin(), tmp_generation_list.end(), slot->get_generation()) != tmp_generation_list.end()) { LOG.error("MatrixManager: dup service meta find (dup generation) %s", name.c_str()); delete slot; ret = false; break; } _instance_list.insert(std::pair<std::string, Instance*>(instance_info.get_instance_name(), slot)); _host_info.use_resource(instance_info.get_instance_meta()._resource); tmp_generation_list.push_back(slot->get_generation()); if (slot->get_generation() >= _current_generation) { _current_generation = slot->get_generation() + 1; } } if (errno != 0) { ret = false; LOG.error("MatrixManager: failed to read dir %s, errno: %d", g_config->META_PATH, errno); } closedir(dir); if (!ret) { clear_instance_list(); _host_info.init_used_resource(); _current_generation = 0; } return ret; }