From 84e4df4d2b7ad959ed50c298b82185481e25aad2 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Tue, 8 Oct 2013 00:28:16 +0300 Subject: [PATCH 1/1] Simplified SERVCONF implementation. --- stglibs/srvconf.lib/servconf.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 8b4e259b..62266871 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -70,7 +70,8 @@ private: std::string errorMsg; XML_Parser parser; - int Exec(const std::string & request, PARSER & cp); + template + int Exec(const std::string & request, C callback, void * data); static bool AnsRecv(void * data, const std::string & chunk, bool final); }; @@ -153,44 +154,37 @@ nt.SetRxCallback(this, AnsRecv); //----------------------------------------------------------------------------- int SERVCONF::IMPL::GetUser(const std::string & login, GET_USER::CALLBACK f, void * data) { -GET_USER::PARSER parser(f, data); -return Exec("", parser); +return Exec("", f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data) { -AUTH_BY::PARSER parser(f, data); -return Exec("", parser); +return Exec("", f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::GetUsers(GET_USERS::CALLBACK f, void * data) { -GET_USERS::PARSER parser(f, data); -return Exec("", parser); +return Exec("", f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::ServerInfo(SERVER_INFO::CALLBACK f, void * data) { -SERVER_INFO::PARSER parser(f, data); -return Exec("", parser); +return Exec("", f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::ChgUser(const std::string & request, CHG_USER::CALLBACK f, void * data) { -CHG_USER::PARSER parser(f, data); -return Exec(request, parser); +return Exec(request, f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data) { -SEND_MESSAGE::PARSER parser(f, data); -return Exec(request, parser); +return Exec(request, f, data); } //----------------------------------------------------------------------------- int SERVCONF::IMPL::CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data) { -CHECK_USER::PARSER parser(f, data); -return Exec("", parser); +return Exec("", f, data); } //----------------------------------------------------------------------------- void SERVCONF::IMPL::Start(void * data, const char * el, const char ** attr) @@ -210,8 +204,10 @@ const std::string & SERVCONF::IMPL::GetStrError() const return errorMsg; } //----------------------------------------------------------------------------- -int SERVCONF::IMPL::Exec(const std::string & request, PARSER & cp) +template +int SERVCONF::IMPL::Exec(const std::string & request, C callback, void * data) { +P cp(callback, data); XML_ParserReset(parser, NULL); XML_SetElementHandler(parser, Start, End); XML_SetUserData(parser, &cp); -- 2.44.2