From 9250e16a677fc52e7338b5c0b7b405e510831259 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 21 Sep 2013 00:27:44 +0300 Subject: [PATCH] Moved SERVER_INFO parser from global scope. --- stglibs/srvconf.lib/include/stg/servconf.h | 3 +-- .../srvconf.lib/include/stg/servconf_types.h | 19 ++++++++++++++ stglibs/srvconf.lib/parser_server_info.cpp | 10 +++---- .../{include/stg => }/parser_server_info.h | 26 +++++++------------ stglibs/srvconf.lib/servconf.cpp | 9 ++++--- 5 files changed, 39 insertions(+), 28 deletions(-) rename stglibs/srvconf.lib/{include/stg => }/parser_server_info.h (73%) diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h index e55cff2c..1b4033e3 100644 --- a/stglibs/srvconf.lib/include/stg/servconf.h +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -27,7 +27,6 @@ #ifndef __STG_STGLIBS_SERVCONF_H__ #define __STG_STGLIBS_SERVCONF_H__ -#include "stg/parser_server_info.h" #include "stg/parser_check_user.h" #include "stg/parser_get_user.h" #include "stg/parser_get_users.h" @@ -55,7 +54,7 @@ public: int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data); - int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data); + int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); const std::string & GetStrError() const; diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h index 7ffc5811..17432044 100644 --- a/stglibs/srvconf.lib/include/stg/servconf_types.h +++ b/stglibs/srvconf.lib/include/stg/servconf_types.h @@ -21,6 +21,8 @@ #ifndef __STG_STGLIBS_SRVCONF_TYPES_H__ #define __STG_STGLIBS_SRVCONF_TYPES_H__ +#include "stg/const.h" // DIR_NUM + #include #include @@ -68,6 +70,23 @@ typedef std::vector INFO; typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); } // namespace AUTH_BY + +namespace SERVER_INFO +{ + +struct INFO +{ + std::string version; + int tariffNum; + int tariffType; + int usersNum; + std::string uname; + int dirNum; + std::string dirName[DIR_NUM]; +}; +typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); + +} // namespace SERVER_INFO } // namespace STG #endif diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp index 38a373b8..d4c610e0 100644 --- a/stglibs/srvconf.lib/parser_server_info.cpp +++ b/stglibs/srvconf.lib/parser_server_info.cpp @@ -19,7 +19,7 @@ * Author : Maxim Mamontov */ -#include "stg/parser_server_info.h" +#include "parser_server_info.h" #include "stg/common.h" @@ -39,7 +39,7 @@ const size_t DIRNAME_LEN = 16; } -PARSER_SERVER_INFO::PARSER_SERVER_INFO() +SERVER_INFO::PARSER::PARSER() : callback(NULL), data(NULL), depth(0), @@ -56,7 +56,7 @@ PARSER_SERVER_INFO::PARSER_SERVER_INFO() AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue); } //----------------------------------------------------------------------------- -int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr) +int SERVER_INFO::PARSER::ParseStart(const char *el, const char **attr) { depth++; if (depth == 1) @@ -69,7 +69,7 @@ else return 0; } //----------------------------------------------------------------------------- -void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/) +void SERVER_INFO::PARSER::ParseEnd(const char * /*el*/) { depth--; if (depth == 0 && parsingAnswer) @@ -81,7 +81,7 @@ if (depth == 0 && parsingAnswer) } } //----------------------------------------------------------------------------- -void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d) +void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d) { callback = f; data = d; diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/parser_server_info.h similarity index 73% rename from stglibs/srvconf.lib/include/stg/parser_server_info.h rename to stglibs/srvconf.lib/parser_server_info.h index cb57bffd..2e91106c 100644 --- a/stglibs/srvconf.lib/include/stg/parser_server_info.h +++ b/stglibs/srvconf.lib/parser_server_info.h @@ -22,32 +22,23 @@ #ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ #define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__ -#include "parser.h" +#include "stg/parser.h" -#include "property_parsers.h" -#include "stg/const.h" +#include "stg/property_parsers.h" +#include "stg/servconf_types.h" #include namespace STG { +namespace SERVER_INFO +{ -class PARSER_SERVER_INFO: public PARSER +class PARSER: public STG::PARSER { public: - struct INFO - { - std::string version; - int tariffNum; - int tariffType; - int usersNum; - std::string uname; - int dirNum; - std::string dirName[DIR_NUM]; - }; - typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data); - PARSER_SERVER_INFO(); + PARSER(); int ParseStart(const char * el, const char ** attr); void ParseEnd(const char * el); void SetCallback(CALLBACK f, void * data); @@ -61,6 +52,7 @@ private: std::string error; }; -} +} // namespace SERVER_INFO +} // namespace STG #endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index a7663f0e..0c24b38a 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -22,6 +22,7 @@ #include "netunit.h" #include "parser_auth_by.h" +#include "parser_server_info.h" #include "stg/common.h" @@ -43,7 +44,7 @@ public: int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data); int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data); int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data); - int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data); + int ServerInfo(SERVER_INFO::CALLBACK f, void * data); int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data); const std::string & GetStrError() const; @@ -54,7 +55,7 @@ private: PARSER_GET_USERS parserGetUsers; PARSER_GET_USER parserGetUser; AUTH_BY::PARSER parserAuthBy; - PARSER_SERVER_INFO parserServerInfo; + SERVER_INFO::PARSER parserServerInfo; PARSER_CHG_USER parserChgUser; PARSER_CHECK_USER parserCheckUser; PARSER_SEND_MESSAGE parserSendMessage; @@ -121,7 +122,7 @@ int SERVCONF::SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALL return pImpl->SendMessage(request, f, data); } -int SERVCONF::ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data) +int SERVCONF::ServerInfo(SERVER_INFO::CALLBACK f, void * data) { return pImpl->ServerInfo(f, data); } @@ -163,7 +164,7 @@ parserGetUsers.SetCallback(f, data); return Exec("", parserGetUsers); } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data) +int SERVCONF::IMPL::ServerInfo(SERVER_INFO::CALLBACK f, void * data) { parserServerInfo.SetCallback(f, data); return Exec("", parserServerInfo); -- 2.44.2