From 7234fe326d16d6bf9f4374a09ddc6ef790e6723f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Jun 2009 22:03:02 +0200 Subject: Globale Variablen durch Application-Klasse ersetzt --- src/Client/UserCommands.cpp | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/Client/UserCommands.cpp') diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index 97ea27b..a1cfd0f 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -18,9 +18,9 @@ */ #include "UserCommands.h" +#include "Application.h" #include "CommandParser.h" -#include #include #include @@ -35,34 +35,34 @@ namespace Mad { namespace Client { -void UserCommands::userInfoCommand(const std::vector &args, Common::Connection *connection) { +void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() == 1) { - Core::Logger::logf(Core::Logger::ERROR, "%s: No user id given.", args[0].c_str()); - CommandParser::printUsage("user_info"); + std::cerr << args[0] << ": No user id given." << std::endl; + commandParser->printUsage("user_info"); return; } if(args.size() > 2) { - Core::Logger::logf(Core::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); - CommandParser::printUsage("user_info"); + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("user_info"); return; } char *endptr; unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); if(args[1].empty() || *endptr != '\0') { - Core::Logger::logf(Core::Logger::ERROR, "%s: Unable to parse user id.", args[0].c_str()); - CommandParser::printUsage("user_info"); + std::cerr << args[0] << ": Unable to parse user id." << std::endl; + commandParser->printUsage("user_info"); return; } - boost::shared_ptr request(new Common::Requests::UserInfoRequest(uid)); - Common::RequestManager::get()->sendRequest(connection, request); + boost::shared_ptr request(new Common::Requests::UserInfoRequest(commandParser->application, uid)); + commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { - Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str()); + std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { const Common::XmlPacket &packet = *result.first; @@ -72,16 +72,16 @@ void UserCommands::userInfoCommand(const std::vector &args, Common: } } -void UserCommands::listUsersCommand(const std::vector &args _UNUSED_PARAMETER_, Common::Connection *connection) { - boost::shared_ptr request(new Common::Requests::UserListRequest); +void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector &args _UNUSED_PARAMETER_) { + boost::shared_ptr request(new Common::Requests::UserListRequest(commandParser->application)); - Common::RequestManager::get()->sendRequest(connection, request); + commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { - Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str()); + std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { const Common::XmlPacket::Element &users = (*result.first)["users"]; @@ -101,34 +101,34 @@ void UserCommands::listUsersCommand(const std::vector &args _UNUSED } } -void UserCommands::listUserGroupsCommand(const std::vector &args, Common::Connection *connection) { +void UserCommands::listUserGroupsCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() == 1) { - Core::Logger::logf(Core::Logger::ERROR, "%s: No user id given.", args[0].c_str()); - CommandParser::printUsage("list_user_groups"); + std::cerr << args[0] << ": No user id given." << std::endl; + commandParser->printUsage("list_user_groups"); return; } if(args.size() > 2) { - Core::Logger::logf(Core::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); - CommandParser::printUsage("list_user_groups"); + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("list_user_groups"); return; } char *endptr; unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); if(args[1].empty() || *endptr != '\0') { - Core::Logger::logf(Core::Logger::ERROR, "%s: Unable to parse user id.", args[0].c_str()); - CommandParser::printUsage("list_user_groups"); + std::cerr << args[0] << ": Unable to parse user id." << std::endl; + commandParser->printUsage("list_user_groups"); return; } - boost::shared_ptr request(new Common::Requests::UserGroupListRequest(uid)); - Common::RequestManager::get()->sendRequest(connection, request); + boost::shared_ptr request(new Common::Requests::UserGroupListRequest(commandParser->application, uid)); + commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { - Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str()); + std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { const Common::XmlPacket::Element &groups = (*result.first)["groups"]; @@ -149,16 +149,16 @@ void UserCommands::listUserGroupsCommand(const std::vector &args, C } } -void UserCommands::listGroupsCommand(const std::vector &args _UNUSED_PARAMETER_, Common::Connection *connection) { - boost::shared_ptr request(new Common::Requests::GroupListRequest); +void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::vector &args _UNUSED_PARAMETER_) { + boost::shared_ptr request(new Common::Requests::GroupListRequest(commandParser->application)); - Common::RequestManager::get()->sendRequest(connection, request); + commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { - Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str()); + std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { const Common::XmlPacket::Element &groups = (*result.first)["groups"]; @@ -178,34 +178,34 @@ void UserCommands::listGroupsCommand(const std::vector &args _UNUSE } } -void UserCommands::listGroupUsersCommand(const std::vector &args, Common::Connection *connection) { +void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std::vector &args) { if(args.size() == 1) { - Core::Logger::logf(Core::Logger::ERROR, "%s: No group id given.", args[0].c_str()); - CommandParser::printUsage("list_group_users"); + std::cerr << args[0] << ": No group id given." << std::endl; + commandParser->printUsage("list_group_users"); return; } if(args.size() > 2) { - Core::Logger::logf(Core::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); - CommandParser::printUsage("list_group_users"); + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("list_group_users"); return; } char *endptr; unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); if(args[1].empty() || *endptr != '\0') { - Core::Logger::logf(Core::Logger::ERROR, "%s: Unable to parse group id.", args[0].c_str()); - CommandParser::printUsage("list_group_users"); + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("list_group_users"); return; } - boost::shared_ptr request(new Common::Requests::GroupUserListRequest(gid)); - Common::RequestManager::get()->sendRequest(connection, request); + boost::shared_ptr request(new Common::Requests::GroupUserListRequest(commandParser->application, gid)); + commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request); request->wait(); std::pair, Core::Exception> result = request->getResult(); if(!result.first || result.second) { - Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str()); + std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl; } else { const Common::XmlPacket::Element &users = (*result.first)["users"]; -- cgit v1.2.3