diff options
Diffstat (limited to 'src/Client')
-rw-r--r-- | src/Client/InformationManager.cpp | 20 | ||||
-rw-r--r-- | src/Client/Requests/DaemonCommandRequest.cpp | 4 | ||||
-rw-r--r-- | src/Client/Requests/DaemonFSInfoRequest.cpp | 2 | ||||
-rw-r--r-- | src/Client/Requests/DaemonStatusRequest.cpp | 2 | ||||
-rw-r--r-- | src/Client/SystemCommands.cpp | 78 | ||||
-rw-r--r-- | src/Client/UserCommands.cpp | 47 |
6 files changed, 81 insertions, 72 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index a4a63fb..a618eb3 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -35,9 +35,9 @@ void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::s { boost::lock_guard<boost::mutex> lock(informationManager->mutex); - std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find((*packet)["name"]); + std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find(packet->get<const std::string&>("name")); if(host != informationManager->daemons.end()) - host->second.setState((*packet)["state"]); + host->second.setState(packet->get<Common::HostInfo::State>("state")); else getApplication()->log(Core::LoggerBase::WARNING, "Received a state update for an unknown host."); } @@ -75,17 +75,19 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo application->logf(Core::LoggerBase::CRITICAL, "Host list request failed: %s", error.strerror().c_str()); } else { - const Common::XmlPacket::Element &hostInfo = (*packet)["hosts"]; + const Common::XmlPacket::List *list = packet->getList("hosts"); daemons.clear(); - for(size_t i = 0; i < hostInfo.getSize(); ++i) { - Common::HostInfo info; - info.setName(hostInfo[i]["name"]); - info.setIP(hostInfo[i]["address"]); - info.setState(hostInfo[i]["state"]); + if(list) { + for(Common::XmlPacket::List::const_iterator entry = list->begin(); entry != list->end(); ++entry) { + Common::HostInfo info; + info.setName(entry->get<const std::string&>("name")); + info.setIP(entry->get<const std::string&>("address")); + info.setState(entry->get<Common::HostInfo::State>("state")); - daemons.insert(std::make_pair(info.getName(), info)); + daemons.insert(std::make_pair(info.getName(), info)); + } } } diff --git a/src/Client/Requests/DaemonCommandRequest.cpp b/src/Client/Requests/DaemonCommandRequest.cpp index 45a346b..a6b3bb4 100644 --- a/src/Client/Requests/DaemonCommandRequest.cpp +++ b/src/Client/Requests/DaemonCommandRequest.cpp @@ -26,8 +26,8 @@ namespace Requests { void DaemonCommandRequest::sendRequest() { Common::XmlPacket packet; packet.setType("DaemonCommand"); - packet.add("command", reboot ? "reboot" : "shutdown"); - packet.add("daemon", daemon); + packet.set("command", reboot ? "reboot" : "shutdown"); + packet.set("daemon", daemon); sendPacket(packet); } diff --git a/src/Client/Requests/DaemonFSInfoRequest.cpp b/src/Client/Requests/DaemonFSInfoRequest.cpp index 5d77850..6189ec5 100644 --- a/src/Client/Requests/DaemonFSInfoRequest.cpp +++ b/src/Client/Requests/DaemonFSInfoRequest.cpp @@ -26,7 +26,7 @@ namespace Requests { void DaemonFSInfoRequest::sendRequest() { Common::XmlPacket packet; packet.setType("DaemonFSInfo"); - packet.add("daemon", daemon); + packet.set("daemon", daemon); sendPacket(packet); } diff --git a/src/Client/Requests/DaemonStatusRequest.cpp b/src/Client/Requests/DaemonStatusRequest.cpp index ff1cda3..baec42d 100644 --- a/src/Client/Requests/DaemonStatusRequest.cpp +++ b/src/Client/Requests/DaemonStatusRequest.cpp @@ -26,7 +26,7 @@ namespace Requests { void DaemonStatusRequest::sendRequest() { Common::XmlPacket packet; packet.setType("GetDaemonStatus"); - packet.add("daemon", daemon); + packet.set("daemon", daemon); sendPacket(packet); } diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp index 5b2d4e5..6c0f91d 100644 --- a/src/Client/SystemCommands.cpp +++ b/src/Client/SystemCommands.cpp @@ -40,53 +40,53 @@ void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlPacket> &pac "kB", "MB", "GB", "TB", "" }; - for(size_t i = 0; i < (*packet)["filesystems"].getSize(); ++i) { - const Common::XmlPacket::Entry &fs = (*packet)["filesystems"][i]; + const Common::XmlPacket::List *list = packet->getList("filesystems"); - unsigned usedUnit = 0, totalUnit = 0; + if(list) { + for(Common::XmlPacket::List::const_iterator fs = list->begin(); fs != list->end(); ++fs) { + unsigned usedUnit = 0, totalUnit = 0; - float used = fs["usedSize"]; - float total = fs["totalSize"]; - float available = fs["availableSize"]; + float used = fs->get<float>("usedSize"); + float total = fs->get<float>("totalSize"); + float available = fs->get<float>("availableSize"); - while(used >= 1024 && !units[usedUnit+1].empty()) { - ++usedUnit; - used /= 1024; - available /= 1024; - } + while(used >= 1024 && !units[usedUnit+1].empty()) { + ++usedUnit; + used /= 1024; + available /= 1024; + } - while(total >= 1024 && !units[totalUnit+1].empty()) { - ++totalUnit; - total /= 1024; - } + while(total >= 1024 && !units[totalUnit+1].empty()) { + ++totalUnit; + total /= 1024; + } - std::string name = fs["name"]; - std::string mountedOn = fs["mountedOn"]; + std::string name = fs->get<const std::string&>("name"); + std::string mountedOn = fs->get<const std::string&>("mountedOn"); - std::string nameString = mountedOn + " (" + name + ")"; + std::string nameString = mountedOn + " (" + name + ")"; - if(nameString.length() < 32) { - nameString.resize(32, ' '); - } - else { - nameString += "\n\t"; - nameString.resize(nameString.length() + 32, ' '); - } + if(nameString.length() < 32) { + nameString.resize(32, ' '); + } + else { + nameString += "\n\t"; + nameString.resize(nameString.length() + 32, ' '); + } - std::printf("\t%s%.*f%s", nameString.c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : (" " + units[usedUnit]).c_str()); - std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), std::min(100*used/(used+available), 100.0f)); + std::printf("\t%s%.*f%s", nameString.c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : (" " + units[usedUnit]).c_str()); + std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), std::min(100*used/(used+available), 100.0f)); + } } std::printf("\n"); } void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlPacket> &packet) { - unsigned long uptime = (*packet)["uptime"]; + unsigned long uptime = packet->get<unsigned long>("uptime"); if(uptime) { - unsigned long uptime = (*packet)["uptime"]; - unsigned long days = uptime/86400; unsigned long hours = (uptime%86400)/3600; unsigned long minutes = (uptime%3600)/60; @@ -97,18 +97,23 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlPacket> std::printf("%lu:%02lu", hours, minutes); - std::printf(" (load average: %.2f %.2f %.2f, %lu processes)", (float)(*packet)["loadAvg1"], (float)(*packet)["loadAvg5"], (float)(*packet)["loadAvg15"], (unsigned long)(*packet)["nProcesses"]); + std::printf(" (load average: %.2f %.2f %.2f, %lu processes)", + packet->get<float>("loadAvg1"), packet->get<float>("loadAvg5"), + packet->get<float>("loadAvg15"), packet->get<unsigned long>("nProcesses")); std::printf("\n\n"); } - if((unsigned long)(*packet)["totalMem"] && (unsigned long)(*packet)["freeMem"]) { + float totalMem = packet->get<unsigned long>("totalMem"); + float freeMem = packet->get<unsigned long>("freeMem"); + + if(totalMem && freeMem) { const std::string units[] = { "kB", "MB", "GB", "TB", "" }; unsigned unit = 0; - float totalMem = (*packet)["totalMem"], usedMem = totalMem-(float)(*packet)["freeMem"]; + float usedMem = totalMem-freeMem; while(totalMem >= 1024 && !units[unit+1].empty()) { ++unit; @@ -119,9 +124,12 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlPacket> std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str()); std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem); - if((unsigned long)(*packet)["totalSwap"] && (unsigned long)(*packet)["freeSwap"]) { + totalMem = packet->get<unsigned long>("totalSwap"); + freeMem = packet->get<unsigned long>("freeSwap"); + + if(totalMem && freeMem) { unit = 0; - totalMem = (*packet)["totalSwap"]; usedMem = totalMem-(float)(*packet)["freeSwap"]; + usedMem = totalMem-freeMem; while(totalMem >= 1024 && !units[unit+1].empty()) { ++unit; diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index a1cfd0f..de5b7ea 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -67,8 +67,8 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect else { const Common::XmlPacket &packet = *result.first; - std::cout << " " << (unsigned long)packet["uid"] << ", " << (unsigned long)packet["gid"] << ", " << (const std::string&)packet["username"] << ", " - << (const std::string&)packet["fullName"] << std::endl << std::endl; + std::cout << " " << packet.get<unsigned long>("uid") << ", " << packet.get<unsigned long>("gid") << ", " + << packet.get<const std::string&>("username") << ", " << packet.get<const std::string&>("fullName") << std::endl << std::endl; } } @@ -84,17 +84,18 @@ void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vec std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { - const Common::XmlPacket::Element &users = (*result.first)["users"]; + const Common::XmlPacket::List *users = result.first->getList("users"); - if(users.isEmpty()) { + if(!users || users->isEmpty()) { std::cout << "User list is empty." << std::endl; } else { - std::cout << "Found " << users.getSize() << " user" << (users.getSize()==1 ? "" : "s") << ":" << std::endl; + std::cout << "Found " << users->getSize() << " user" << (users->getSize()==1 ? "" : "s") << ":" << std::endl; - for(size_t i = 0; i < users.getSize(); ++i) - std::cout << " " << (unsigned long)users[i]["uid"] << ", " << (unsigned long)users[i]["gid"] << ", " << (const std::string&)users[i]["username"] << ", " << (const std::string&)users[i]["fullName"] << std::endl; + for(Common::XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) + std::cout << " " << user->get<unsigned long>("uid") << ", " << user->get<unsigned long>("gid") + << ", " << user->get<const std::string&>("username") << ", " << user->get<const std::string&>("fullName") << std::endl; } std::cout << std::endl; @@ -131,18 +132,17 @@ void UserCommands::listUserGroupsCommand(CommandParser *commandParser, const std std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { - const Common::XmlPacket::Element &groups = (*result.first)["groups"]; + const Common::XmlPacket::List *groups = result.first->getList("groups"); - if(groups.isEmpty()) { + if(!groups || groups->isEmpty()) { std::cout << "The user isn't member of any group." << std::endl; } else { + std::cout << "User is member of " << groups->getSize() << " group" << (groups->getSize()==1 ? "" : "s") << ":" << std::endl; - std::cout << "User is member of " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl; - - for(size_t i = 0; i < groups.getSize(); ++i) - std::cout << " " << (unsigned long)groups[i]["gid"] << std::endl; + for(Common::XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) + std::cout << " " << group->get<unsigned long>("gid") << std::endl; } std::cout << std::endl; @@ -161,17 +161,17 @@ void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::ve std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { - const Common::XmlPacket::Element &groups = (*result.first)["groups"]; + const Common::XmlPacket::List *groups = result.first->getList("groups"); - if(groups.isEmpty()) { + if(!groups || groups->isEmpty()) { std::cout << "Group list is empty." << std::endl; } else { - std::cout << "Found " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl; + std::cout << "Found " << groups->getSize() << " group" << (groups->getSize()==1 ? "" : "s") << ":" << std::endl; - for(size_t i = 0; i < groups.getSize(); ++i) - std::cout << " " << (unsigned long)groups[i]["gid"] << ", " << (const std::string&)groups[i]["name"] << std::endl; + for(Common::XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group) + std::cout << " " << group->get<unsigned long>("gid") << ", " << group->get<const std::string&>("name") << std::endl; } std::cout << std::endl; @@ -208,18 +208,17 @@ void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { - const Common::XmlPacket::Element &users = (*result.first)["users"]; + const Common::XmlPacket::List *users = result.first->getList("users"); - if(users.isEmpty()) { + if(!users || users->isEmpty()) { std::cout << "The group doesn't have any members." << std::endl; } else { - - std::cout << "The group has " << users.getSize() << " member" << (users.getSize()==1 ? "" : "s") << ":" << std::endl; + std::cout << "The group has " << users->getSize() << " member" << (users->getSize()==1 ? "" : "s") << ":" << std::endl; - for(size_t i = 0; i < users.getSize(); ++i) - std::cout << " " << (unsigned long)users[i]["uid"] << std::endl; + for(Common::XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user) + std::cout << " " << user->get<unsigned long>("uid") << std::endl; } std::cout << std::endl; |