summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandManager.cpp3
-rw-r--r--src/Client/CommandManager.h8
-rw-r--r--src/Client/CommandParser.cpp26
-rw-r--r--src/Client/CommandParser.h22
4 files changed, 41 insertions, 18 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index 08a2780..4b24782 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -32,6 +32,9 @@
namespace Mad {
namespace Client {
+CommandManager CommandManager::commandManager;
+
+
void CommandManager::printFSInfo(const Net::Packets::FSInfoPacket &packet) {
const std::string units[] = {
"kB", "MB", "GB", "TB", ""
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index 1937c0f..25b3f2e 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -38,6 +38,8 @@ class CommandManager {
private:
friend class CommandParser;
+ static CommandManager commandManager;
+
unsigned int activeRequests;
sigc::signal<void> finished;
@@ -60,9 +62,13 @@ class CommandManager {
void fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
void statusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
- public:
CommandManager() : activeRequests(0), disconnect(false) {}
+ public:
+ static CommandManager *getCommandManager() {
+ return &commandManager;
+ }
+
bool requestsActive() {return (activeRequests > 0);}
bool willDisconnect() {return disconnect;}
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index d75eb0a..c0c8d7f 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -50,6 +50,8 @@ const CommandParser::Command CommandParser::commands[] = {
{{0}, 0, 0, 0, 0}
};
+CommandParser CommandParser::commandParser;
+
const CommandParser::Command* CommandParser::findCommand(const std::string& command) {
for(int i = 0; commands[i].commands[0] != 0; ++i) {
@@ -108,16 +110,16 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
void CommandParser::fsinfoCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(commandManager, &CommandManager::fsInfoRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::FSInfoRequest(sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::fsInfoRequestFinished))));
else if(args.size() == 2)
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(commandManager, &CommandManager::daemonFSInfoRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonFSInfoRequest(args[1], sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::daemonFSInfoRequestFinished))));
else {
Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
printUsage("fsinfo");
return;
}
- commandManager.activeRequests++;
+ ++CommandManager::getCommandManager()->activeRequests;
}
void CommandParser::helpCommand(const std::vector<std::string> &args) {
@@ -212,10 +214,10 @@ void CommandParser::rebootCommand(const std::vector<std::string> &args) {
for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(
- new Requests::DaemonCommandRequest(host->first, true, sigc::mem_fun(commandManager, &CommandManager::daemonCommandRequestFinished))
+ new Requests::DaemonCommandRequest(host->first, true, sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::daemonCommandRequestFinished))
));
- commandManager.activeRequests++;
+ ++CommandManager::getCommandManager()->activeRequests;
}
}
@@ -230,31 +232,31 @@ void CommandParser::shutdownCommand(const std::vector<std::string> &args) {
for(std::map<std::string, Common::HostInfo>::iterator host = hosts.begin(); host != hosts.end(); ++host) {
Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(
- new Requests::DaemonCommandRequest(host->first, false, sigc::mem_fun(commandManager, &CommandManager::daemonCommandRequestFinished))
+ new Requests::DaemonCommandRequest(host->first, false, sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::daemonCommandRequestFinished))
));
- commandManager.activeRequests++;
+ ++CommandManager::getCommandManager()->activeRequests;
}
}
void CommandParser::statusCommand(const std::vector<std::string> &args) {
if(args.size() == 1)
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(commandManager, &CommandManager::statusRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::StatusRequest(sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::statusRequestFinished))));
else if(args.size() == 2)
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(args[1], sigc::mem_fun(commandManager, &CommandManager::daemonStatusRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(args[1], sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::daemonStatusRequestFinished))));
else {
Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
printUsage("status");
return;
}
- commandManager.activeRequests++;
+ ++CommandManager::getCommandManager()->activeRequests;
}
void CommandParser::exitCommand(const std::vector<std::string>&) {
- commandManager.activeRequests++;
+ ++CommandManager::getCommandManager()->activeRequests;
- Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::DisconnectRequest(sigc::mem_fun(commandManager, &CommandManager::disconnectRequestFinished))));
+ Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::DisconnectRequest(sigc::mem_fun(CommandManager::getCommandManager(), &CommandManager::disconnectRequestFinished))));
}
bool CommandParser::split(const std::string &str, std::vector<std::string> &ret) {
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 660f548..e08c775 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -49,7 +49,7 @@ class CommandParser {
static const Command commands[];
- CommandManager commandManager;
+ static CommandParser commandParser;
Net::Connection *connection;
@@ -68,13 +68,25 @@ class CommandParser {
void statusCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
+ CommandParser() : connection(0) {}
+
public:
- CommandParser(Net::Connection *connection0) : connection(connection0) {}
+ static CommandParser *getCommandParser() {
+ return &commandParser;
+ }
+
+ Net::Connection *getConnection() const {
+ return connection;
+ }
+
+ void setConnection(Net::Connection *con) {
+ connection = con;
+ }
- bool requestsActive() {return commandManager.requestsActive();}
- bool willDisconnect() {return commandManager.willDisconnect();}
+ bool requestsActive() {return CommandManager::getCommandManager()->requestsActive();}
+ bool willDisconnect() {return CommandManager::getCommandManager()->willDisconnect();}
- sigc::signal<void> signalFinished() const {return commandManager.signalFinished();}
+ sigc::signal<void> signalFinished() const {return CommandManager::getCommandManager()->signalFinished();}
bool parse(const std::string &cmd);