From: Maxim Mamontov Date: Mon, 7 Oct 2013 21:28:16 +0000 (+0300) Subject: Simplified SERVCONF implementation. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/84e4df4d2b7ad959ed50c298b82185481e25aad2?hp=c37a22a0581f4a211ab77721a99d2de636ec3467 Simplified SERVCONF implementation. --- 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);