summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-18 15:58:17 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-18 15:58:17 +0200
commitdb5ad2e09a6b38e841463dbe7eb076492b62c948 (patch)
tree5907f6416e35cbd25432a5f1f6dc9664d36aa73c /src/Client
parent5da7b0847bac2a5abec95b9ac1701b74baae8964 (diff)
downloadmad-db5ad2e09a6b38e841463dbe7eb076492b62c948.tar
mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.zip
Mad funktioniert jetzt unter Windows
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/Application.h4
-rw-r--r--src/Client/CMakeLists.txt14
-rw-r--r--src/Client/CommandParser.h4
-rw-r--r--src/Client/InformationManager.cpp8
-rw-r--r--src/Client/InformationManager.h6
-rw-r--r--src/Client/PasswordReader.cpp70
-rw-r--r--src/Client/PasswordReader.h41
-rw-r--r--src/Client/Requests/CMakeLists.txt8
-rw-r--r--src/Client/Requests/DaemonCommandRequest.h4
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h4
-rw-r--r--src/Client/Requests/DaemonListRequest.h2
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h4
-rw-r--r--src/Client/SystemCommands.cpp7
-rw-r--r--src/Client/SystemCommands.h4
-rw-r--r--src/Client/UserCommands.cpp30
-rw-r--r--src/Client/UserCommands.h4
-rw-r--r--src/Client/export.h11
17 files changed, 171 insertions, 54 deletions
diff --git a/src/Client/Application.h b/src/Client/Application.h
index 7ba6370..6a0b14f 100644
--- a/src/Client/Application.h
+++ b/src/Client/Application.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_APPLICATION_H_
#define MAD_CLIENT_APPLICATION_H_
+#include "export.h"
+
#include <Common/Application.h>
namespace Mad {
@@ -27,7 +29,7 @@ namespace Client {
class InformationManager;
-class Application : public Common::Application {
+class MAD_CLIENT_EXPORT Application : public Common::Application {
private:
InformationManager *informationManager;
diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt
index 6d7ba4c..fcd6f6b 100644
--- a/src/Client/CMakeLists.txt
+++ b/src/Client/CMakeLists.txt
@@ -1,12 +1,18 @@
-add_subdirectory(Requests)
-
include_directories(${INCLUDES})
-add_library(Client
+mad_library(Client
+ export.h
+
+ Requests/DaemonCommandRequest.h Requests/DaemonCommandRequest.cpp
+ Requests/DaemonFSInfoRequest.h Requests/DaemonFSInfoRequest.cpp
+ Requests/DaemonListRequest.h
+ Requests/DaemonStatusRequest.h Requests/DaemonStatusRequest.cpp
+
Application.cpp Application.h
CommandParser.cpp CommandParser.h
InformationManager.cpp InformationManager.h
+ PasswordReader.cpp PasswordReader.h
SystemCommands.cpp SystemCommands.h
UserCommands.cpp UserCommands.h
)
-target_link_libraries(Client ClientRequests Common)
+target_link_libraries(Client Common)
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 82808c8..ca168f3 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_COMMANDPARSER_H_
#define MAD_CLIENT_COMMANDPARSER_H_
+#include "export.h"
+
#include <Common/HostInfo.h>
#include <Common/XmlPacket.h>
@@ -42,7 +44,7 @@ class Application;
class SystemCommands;
class UserCommands;
-class CommandParser {
+class MAD_CLIENT_EXPORT CommandParser {
private:
friend class SystemCommands;
friend class UserCommands;
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
index 459408b..59d8836 100644
--- a/src/Client/InformationManager.cpp
+++ b/src/Client/InformationManager.cpp
@@ -37,9 +37,9 @@ void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::s
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->get<Common::HostInfo::State>("state"));
+ host->second.setState(static_cast<Common::HostInfo::State>(packet->get<long>("state")));
else
- getApplication()->log(Core::LoggerBase::WARNING, "Received a state update for an unknown host.");
+ getApplication()->log(Core::LoggerBase::LOG_WARNING, "Received a state update for an unknown host.");
}
ret->setType("OK");
@@ -72,7 +72,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo
boost::lock_guard<boost::mutex> lock(mutex);
if(!packet || error) {
- application->logf(Core::LoggerBase::CRITICAL, "Host list request failed: %s", error.strerror().c_str());
+ application->logf(Core::LoggerBase::LOG_CRITICAL, "Host list request failed: %s", error.strerror().c_str());
}
else {
const Common::XmlPacket::List *list = packet->getList("hosts");
@@ -84,7 +84,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo
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"));
+ info.setState(static_cast<Common::HostInfo::State>(entry->get<long>("state")));
daemons.insert(std::make_pair(info.getName(), info));
}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
index d0e26a3..5f68bc2 100644
--- a/src/Client/InformationManager.h
+++ b/src/Client/InformationManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_INFORMATIONMANAGER_H_
#define MAD_CLIENT_INFORMATIONMANAGER_H_
+#include "export.h"
+
#include <map>
#include <memory>
@@ -37,9 +39,9 @@ namespace Client {
class Application;
-class InformationManager : private boost::noncopyable {
+class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable {
private:
- class DaemonStateUpdateRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
+ class MAD_CLIENT_EXPORT DaemonStateUpdateRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
private:
void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
diff --git a/src/Client/PasswordReader.cpp b/src/Client/PasswordReader.cpp
new file mode 100644
index 0000000..d5c4fe8
--- /dev/null
+++ b/src/Client/PasswordReader.cpp
@@ -0,0 +1,70 @@
+/*
+ * PasswordReader.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "PasswordReader.h"
+
+#include <iostream>
+
+#ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#else
+# include <termios.h>
+# include <unistd.h>
+#endif
+
+namespace Mad {
+namespace Client {
+
+std::string PasswordReader::readPassword(const std::string &prompt) {
+ std::string password;
+
+#ifdef _WIN32
+ DWORD mode;
+ HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
+ GetConsoleMode(handle, &mode);
+ SetConsoleMode(handle, mode & ~(ENABLE_ECHO_INPUT));
+
+ std::cout << prompt << std::flush;
+ std::getline(std::cin, password);
+ std::cout << std::endl;
+
+ SetConsoleMode(handle, mode);
+
+#else
+ struct termios termold, termnew;
+
+ tcgetattr(STDIN_FILENO, &termold);
+
+ termnew = termold;
+ termnew.c_lflag &= ~ECHO;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew);
+
+ std::cout << prompt << std::flush;
+ std::getline(std::cin, password);
+ std::cout << std::endl;
+
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold);
+#endif
+
+ return password;
+}
+
+}
+}
diff --git a/src/Client/PasswordReader.h b/src/Client/PasswordReader.h
new file mode 100644
index 0000000..35487c4
--- /dev/null
+++ b/src/Client/PasswordReader.h
@@ -0,0 +1,41 @@
+/*
+ * PasswordReader.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_PASSWORDREADER_H_
+#define MAD_CLIENT_PASSWORDREADER_H_
+
+#include "export.h"
+
+#include <string>
+
+namespace Mad {
+namespace Client {
+
+class MAD_CLIENT_EXPORT PasswordReader {
+ private:
+ PasswordReader();
+
+ public:
+ static std::string readPassword(const std::string &prompt);
+};
+
+}
+}
+
+#endif /* MAD_CLIENT_PASSWORDREADER_H_ */ \ No newline at end of file
diff --git a/src/Client/Requests/CMakeLists.txt b/src/Client/Requests/CMakeLists.txt
deleted file mode 100644
index 86acaf5..0000000
--- a/src/Client/Requests/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(ClientRequests STATIC
- DaemonCommandRequest.cpp DaemonCommandRequest.h
- DaemonFSInfoRequest.cpp DaemonFSInfoRequest.h
- DaemonListRequest.h
- DaemonStatusRequest.cpp DaemonStatusRequest.h
-)
diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h
index abe9bf7..04e0304 100644
--- a/src/Client/Requests/DaemonCommandRequest.h
+++ b/src/Client/Requests/DaemonCommandRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -27,7 +29,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonCommandRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonCommandRequest : public Common::Request {
private:
std::string daemon;
bool reboot;
diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index e96cd3f..50c0783 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
#define MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -28,7 +30,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonFSInfoRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonFSInfoRequest : public Common::Request {
private:
std::string daemon;
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 76f85cd..85fc4e1 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
+#include "../export.h"
+
#include <Common/Requests/SimpleRequest.h>
namespace Mad {
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
index 262cdb6..1cdc82e 100644
--- a/src/Client/Requests/DaemonStatusRequest.h
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
#define MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -28,7 +30,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonStatusRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonStatusRequest : public Common::Request {
private:
std::string daemon;
diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp
index c26be54..1cc9bc4 100644
--- a/src/Client/SystemCommands.cpp
+++ b/src/Client/SystemCommands.cpp
@@ -30,7 +30,7 @@
#include <Common/Requests/StatusRequest.h>
#include <iostream>
-
+#include <algorithm>
namespace Mad {
namespace Client {
@@ -74,9 +74,12 @@ void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlPacket> &pac
nameString += "\n\t";
nameString.resize(nameString.length() + 32, ' ');
}
+
+ 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(), std::min(100*used/(used+available), 100.0f));
+ std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), percent);
}
}
diff --git a/src/Client/SystemCommands.h b/src/Client/SystemCommands.h
index 3d78151..74b1a62 100644
--- a/src/Client/SystemCommands.h
+++ b/src/Client/SystemCommands.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_SYSTEMCOMMANDS_H_
#define MAD_CLIENT_SYSTEMCOMMANDS_H_
+#include "export.h"
+
#include <Common/XmlPacket.h>
#include <vector>
@@ -31,7 +33,7 @@ namespace Client {
class CommandParser;
-class SystemCommands {
+class MAD_CLIENT_EXPORT SystemCommands {
private:
SystemCommands();
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index 21259d0..166a54d 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -20,12 +20,12 @@
#include "UserCommands.h"
#include "Application.h"
#include "CommandParser.h"
+#include "PasswordReader.h"
#include <Common/RequestManager.h>
#include <Common/UserManager.h>
#include <iostream>
-#include <termios.h>
namespace Mad {
@@ -511,32 +511,8 @@ void UserCommands::setPasswordCommand(CommandParser *commandParser, const std::v
return;
}
- // TODO Extract this as a method
- struct termios termold, termnew;
-
- if(tcgetattr(STDIN_FILENO, &termold) != 0) {
- std::cerr << "Unable to set up terminal for password entry." << std::endl;
- return;
- }
-
- termnew = termold;
- termnew.c_lflag &= ~ECHO;
- if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew) != 0) {
- std::cerr << "Unable to set up terminal for password entry." << std::endl;
- return;
- }
-
- std::string password, password2;
-
- std::cout << "Password: " << std::flush;
- std::getline(std::cin, password);
- std::cout << std::endl;
-
- std::cout << "Verify password: " << std::flush;
- std::getline(std::cin, password2);
- std::cout << std::endl;
-
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold);
+ std::string password = PasswordReader::readPassword("Password: ");
+ std::string password2 = PasswordReader::readPassword("Verify password: ");
if(password != password2) {
std::cerr << "Passwords do not match." << std::endl;
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index d5422da..640b5b4 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_USERCOMMANDS_H_
#define MAD_CLIENT_USERCOMMANDS_H_
+#include "export.h"
+
#include <string>
#include <vector>
@@ -28,7 +30,7 @@ namespace Client {
class CommandParser;
-class UserCommands {
+class MAD_CLIENT_EXPORT UserCommands {
private:
UserCommands();
diff --git a/src/Client/export.h b/src/Client/export.h
new file mode 100644
index 0000000..c52e49d
--- /dev/null
+++ b/src/Client/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_CLIENT_EXPORT
+# ifdef _WIN32
+# ifdef MAD_CLIENT_EXPORTS
+# define MAD_CLIENT_EXPORT _declspec(dllexport)
+# else
+# define MAD_CLIENT_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_CLIENT_EXPORT
+# endif
+#endif