From 186fb2b18b89a0280b8cc4b5ea8f7a59d3bd0853 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Tue, 27 May 2014 20:07:32 +0300 Subject: [PATCH] Some refactoring. --- projects/sgconf/main.cpp | 69 +++------------------------------------- projects/sgconf/xml.cpp | 25 +++++++++++++++ projects/sgconf/xml.h | 7 ++++ 3 files changed, 37 insertions(+), 64 deletions(-) diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 625e8564..6a71f652 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -30,44 +30,16 @@ #include "actions.h" #include "config.h" -#include "stg/servconf.h" -#include "stg/user_conf.h" -#include "stg/user_stat.h" -#include "stg/common.h" - -#include -#include -#include -#include -#include #include -#include +#include -#include -#include -#include -#include +#include // getenv +#include // basename -namespace -{ - -template -struct ARRAY_TYPE -{ -typedef typename T::value_type type; -}; +#include // access -template -struct ARRAY_TYPE -{ -typedef T type; -}; - -template -struct ARRAY_TYPE +namespace { -typedef T type; -}; template struct nullary_function @@ -144,26 +116,6 @@ CONST_METHOD1_ADAPTER Method1Adapt(R (C::* func)(A) const, C & obj) return CONST_METHOD1_ADAPTER(func, obj); } -template -bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE::type & value) -{ -size_t pos = 0; -if (str2x(index, pos)) - return false; -array[pos] = value; -return true; -} - -void RawXMLCallback(bool result, const std::string & reason, const std::string & response, void * /*data*/) -{ -if (!result) - { - std::cerr << "Failed to get raw XML response. Reason: '" << reason << "'." << std::endl; - return; - } -SGCONF::PrintXML(response); -} - void Version(const std::string & self) { std::cout << self << ", version: 2.0.0-alpha.\n"; @@ -396,17 +348,6 @@ ACTION * MakeAPIAction(COMMANDS & commands, return new API_ACTION(commands, "", false, funPtr); } -bool RawXMLFunction(const SGCONF::CONFIG & config, - const std::string & arg, - const std::map & /*options*/) -{ - STG::SERVCONF proto(config.server.data(), - config.port.data(), - config.userName.data(), - config.userPass.data()); - return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok; -} - } // namespace SGCONF time_t stgTime; diff --git a/projects/sgconf/xml.cpp b/projects/sgconf/xml.cpp index bf5589fe..ec8b9178 100644 --- a/projects/sgconf/xml.cpp +++ b/projects/sgconf/xml.cpp @@ -1,5 +1,9 @@ #include "xml.h" +#include "config.h" + +#include "stg/servconf.h" + #include #include @@ -48,6 +52,16 @@ if (el != NULL) std::cout << Indent(state->level) << "\n"; } +void RawXMLCallback(bool result, const std::string & reason, const std::string & response, void * /*data*/) +{ +if (!result) + { + std::cerr << "Failed to get raw XML response. Reason: '" << reason << "'." << std::endl; + return; + } +SGCONF::PrintXML(response); +} + } void SGCONF::PrintXML(const std::string& xml) @@ -66,3 +80,14 @@ if (XML_Parse(parser, xml.c_str(), xml.length(), true) == XML_STATUS_ERROR) XML_ParserFree(parser); } + +bool SGCONF::RawXMLFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) +{ + STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.userName.data(), + config.userPass.data()); + return proto.RawXML(arg, RawXMLCallback, NULL) == STG::st_ok; +} diff --git a/projects/sgconf/xml.h b/projects/sgconf/xml.h index 25ee35c3..549a69b3 100644 --- a/projects/sgconf/xml.h +++ b/projects/sgconf/xml.h @@ -22,12 +22,19 @@ #define __STG_SGCONF_XML_H__ #include +#include namespace SGCONF { +struct CONFIG; + void PrintXML(const std::string& xml); +bool RawXMLFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/); + } #endif -- 2.43.2