summaryrefslogtreecommitdiffstats
path: root/src/Client/SystemCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/SystemCommands.cpp')
-rw-r--r--src/Client/SystemCommands.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp
index ff14cc5..d33441f 100644
--- a/src/Client/SystemCommands.cpp
+++ b/src/Client/SystemCommands.cpp
@@ -36,7 +36,7 @@ namespace Mad {
namespace Client {
void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlData> &packet) {
- const std::string units[] = {
+ const Core::String units[] = {
"kB", "MB", "GB", "TB", ""
};
@@ -50,36 +50,38 @@ void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlData> &packe
float total = fs->get<float>("totalSize");
float available = fs->get<float>("availableSize");
- while(used >= 1024 && !units[usedUnit+1].empty()) {
+ while(used >= 1024 && !units[usedUnit+1].isEmpty()) {
++usedUnit;
used /= 1024;
available /= 1024;
}
- while(total >= 1024 && !units[totalUnit+1].empty()) {
+ while(total >= 1024 && !units[totalUnit+1].isEmpty()) {
++totalUnit;
total /= 1024;
}
- std::string name = fs->get<const std::string&>("name");
- std::string mountedOn = fs->get<const std::string&>("mountedOn");
+ Core::String name = fs->get<const Core::String&>("name");
+ Core::String mountedOn = fs->get<const Core::String&>("mountedOn");
- std::string nameString = mountedOn + " (" + name + ")";
+ Core::String nameString = mountedOn + " (" + name + ")";
if(nameString.length() < 32) {
- nameString.resize(32, ' ');
+ while(nameString.length() < 32)
+ nameString.append(' ');
}
else {
nameString += "\n\t";
- nameString.resize(nameString.length() + 32, ' ');
+ for(int i = 0; i < 32; ++i)
+ nameString.append(' ');
}
float percent = 100*used/(used+available);
if(percent > 100) percent = 100;
- 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(), percent);
+ std::printf("\t%s%.*f%s", nameString.extract().c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : Core::String(" " + units[usedUnit]).extract().c_str());
+ std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].extract().c_str(), percent);
}
}
@@ -111,20 +113,20 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlData> &p
float freeMem = packet->get<unsigned long>("freeMem");
if(totalMem && freeMem) {
- const std::string units[] = {
+ const Core::String units[] = {
"kB", "MB", "GB", "TB", ""
};
unsigned unit = 0;
float usedMem = totalMem-freeMem;
- while(totalMem >= 1024 && !units[unit+1].empty()) {
+ while(totalMem >= 1024 && !units[unit+1].isEmpty()) {
++unit;
totalMem /= 1024;
usedMem /= 1024;
}
- std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str());
+ std::printf("\tMemory usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].extract().c_str());
std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem);
totalMem = packet->get<unsigned long>("totalSwap");
@@ -134,13 +136,13 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlData> &p
unit = 0;
usedMem = totalMem-freeMem;
- while(totalMem >= 1024 && !units[unit+1].empty()) {
+ while(totalMem >= 1024 && !units[unit+1].isEmpty()) {
++unit;
totalMem /= 1024;
usedMem /= 1024;
}
- std::printf("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].c_str());
+ std::printf("\tSwap usage:\t%.*f/%.*f %s", (usedMem < 10) ? 2 : 1, usedMem, (totalMem < 10) ? 2 : 1, totalMem, units[unit].extract().c_str());
std::printf(" (%.1f%%)\n", usedMem*100.0f/totalMem);
}
@@ -149,7 +151,7 @@ void SystemCommands::printHostStatus(boost::shared_ptr<const Common::XmlData> &p
}
-void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vector<Core::String> &args) {
boost::shared_ptr<Common::Request> request;
if(args.size() == 1)
@@ -180,18 +182,18 @@ void SystemCommands::fsinfoCommand(CommandParser *commandParser, const std::vect
}
}
-void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vector<Core::String> &args) {
if(args.size() < 2) {
std::cerr << args[0] << ": No host given." << std::endl;
commandParser->printUsage("reboot");
return;
}
- std::map<std::string, Common::HostInfo> hosts = commandParser->parseHostList(std::vector<std::string>(args.begin()+1, args.end()), true);
+ std::map<Core::String, Common::HostInfo> hosts = commandParser->parseHostList(std::vector<Core::String>(args.begin()+1, args.end()), true);
std::vector<boost::shared_ptr<Requests::DaemonCommandRequest> > requests;
- for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
+ for(std::map<Core::String, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
boost::shared_ptr<Requests::DaemonCommandRequest> request(new Requests::DaemonCommandRequest(commandParser->application, host->first, true));
commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
@@ -209,18 +211,18 @@ void SystemCommands::rebootCommand(CommandParser *commandParser, const std::vect
}
}
-void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::vector<Core::String> &args) {
if(args.size() < 2) {
std::cerr << args[0] << ": No host given." << std::endl;
commandParser->printUsage("shutdown");
return;
}
- std::map<std::string, Common::HostInfo> hosts = commandParser->parseHostList(std::vector<std::string>(args.begin()+1, args.end()), true);
+ std::map<Core::String, Common::HostInfo> hosts = commandParser->parseHostList(std::vector<Core::String>(args.begin()+1, args.end()), true);
std::vector<boost::shared_ptr<Requests::DaemonCommandRequest> > requests;
- for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
+ for(std::map<Core::String, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
boost::shared_ptr<Requests::DaemonCommandRequest> request(new Requests::DaemonCommandRequest(commandParser->application, host->first, false));
commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
@@ -238,7 +240,7 @@ void SystemCommands::shutdownCommand(CommandParser *commandParser, const std::ve
}
}
-void SystemCommands::statusCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+void SystemCommands::statusCommand(CommandParser *commandParser, const std::vector<Core::String> &args) {
boost::shared_ptr<Common::Request> request;
if(args.size() == 1)