From: Maxim Mamontov Date: Mon, 22 Sep 2014 12:02:22 +0000 (+0300) Subject: Implemented parser registry. X-Git-Tag: 2.409~261 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/7df336e60c959c440b2c330f7a7ca9b0251db2a1 Implemented parser registry. Conflicts: projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h --- diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 847e1ebc..7052ecc2 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -22,6 +22,14 @@ #include "conn.h" +#include "parser_server_info.h" +#include "parser_admins.h" +#include "parser_tariffs.h" +#include "parser_users.h" +#include "parser_message.h" +#include "parser_user_info.h" +#include "parser_auth_by.h" + #include "stg/common.h" #include "stg/logger.h" @@ -37,6 +45,8 @@ #include #include +namespace SP = STG::PARSER; + namespace { @@ -68,6 +78,10 @@ CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) m_stopped(true), m_logger(l), m_listenSocket(-1) +{ +} + +CONFIGPROTO::~CONFIGPROTO() { std::for_each(m_conns.begin(), m_conns.end(), RemoveConn()); } @@ -119,6 +133,8 @@ int CONFIGPROTO::Prepare() return -1; } + RegisterParsers(); + m_running = true; m_stopped = false; return 0; @@ -174,6 +190,40 @@ void CONFIGPROTO::Run() m_stopped = true; } +void CONFIGPROTO::RegisterParsers() +{ + assert(m_settings != NULL); + assert(m_store != NULL); + assert(m_admins != NULL); + assert(m_users != NULL); + assert(m_tariffs != NULL); + + SP::GET_SERVER_INFO::FACTORY::Register(m_registry, *m_settings, *m_users, *m_tariffs); + + SP::GET_ADMINS::FACTORY::Register(m_registry, *m_admins); + SP::ADD_ADMIN::FACTORY::Register(m_registry, *m_admins); + SP::DEL_ADMIN::FACTORY::Register(m_registry, *m_admins); + SP::CHG_ADMIN::FACTORY::Register(m_registry, *m_admins); + + SP::GET_TARIFFS::FACTORY::Register(m_registry, *m_tariffs); + SP::ADD_TARIFF::FACTORY::Register(m_registry, *m_tariffs); + SP::DEL_TARIFF::FACTORY::Register(m_registry, *m_tariffs, *m_users); + SP::CHG_TARIFF::FACTORY::Register(m_registry, *m_tariffs); + + SP::GET_USERS::FACTORY::Register(m_registry, *m_users); + SP::GET_USER::FACTORY::Register(m_registry, *m_users); + SP::ADD_USER::FACTORY::Register(m_registry, *m_users); + SP::DEL_USER::FACTORY::Register(m_registry, *m_users); + SP::CHG_USER::FACTORY::Register(m_registry, *m_users, *m_store, *m_tariffs); + SP::CHECK_USER::FACTORY::Register(m_registry, *m_users); + + SP::SEND_MESSAGE::FACTORY::Register(m_registry, *m_users); + + SP::AUTH_BY::FACTORY::Register(m_registry, *m_users); + + SP::USER_INFO::FACTORY::Register(m_registry, *m_users); +} + int CONFIGPROTO::MaxFD() const { int maxFD = m_listenSocket; @@ -225,14 +275,11 @@ void CONFIGPROTO::AcceptConnection() return; } - assert(m_settings != NULL); assert(m_admins != NULL); - assert(m_users != NULL); - assert(m_tariffs != NULL); try { - m_conns.push_back(new STG::Conn(*m_settings, *m_admins, *m_users, *m_tariffs, sock, outerAddr)); + m_conns.push_back(new STG::Conn(m_registry, *m_admins, sock, outerAddr)); printfd(__FILE__, "New connection from %s:%d\n", inet_ntostring(m_conns.back()->IP()).c_str(), m_conns.back()->Port()); } catch (const STG::Conn::Error & error) diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index b10cc938..6e296836 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -22,6 +22,8 @@ #ifndef CONFIGPROTO_H #define CONFIGPROTO_H +#include "parser.h" + #include "stg/module_settings.h" #include "stg/os_int.h" @@ -36,6 +38,7 @@ class SETTINGS; class ADMINS; class TARIFFS; class USERS; +class STORE; class PLUGIN_LOGGER; namespace STG @@ -48,12 +51,14 @@ class Conn; class CONFIGPROTO { public: CONFIGPROTO(PLUGIN_LOGGER & l); + ~CONFIGPROTO(); void SetPort(uint16_t port) { m_port = port; } void SetSettings(const SETTINGS * settings) { m_settings = settings; } void SetAdmins(ADMINS * admins) { m_admins = admins; } void SetTariffs(TARIFFS * tariffs) { m_tariffs = tariffs; } void SetUsers(USERS * users) { m_users = users; } + void SetStore(STORE * store) { m_store = store; } int Prepare(); int Stop(); @@ -68,6 +73,7 @@ private: ADMINS * m_admins; TARIFFS * m_tariffs; USERS * m_users; + STORE * m_store; uint16_t m_port; bool m_running; @@ -77,8 +83,11 @@ private: std::string m_errorStr; + BASE_PARSER::REGISTRY m_registry; std::vector m_conns; + void RegisterParsers(); + int MaxFD() const; void BuildFDSet(fd_set & fds) const; void CleanupConns(); diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp index ead809f0..1d5d0aff 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.cpp @@ -20,26 +20,14 @@ #include "conn.h" -#include "parser.h" - -#include "parser_server_info.h" -#include "parser_admins.h" -#include "parser_tariffs.h" -#include "parser_users.h" -#include "parser_message.h" -#include "parser_auth_by.h" -#include "parser_user_info.h" - -#include "stg/settings.h" #include "stg/admins.h" -#include "stg/users.h" -#include "stg/tariffs.h" #include "stg/admin.h" #include "stg/blowfish.h" #include "stg/bfstream.h" #include "stg/common.h" #include +#include #include #include @@ -54,15 +42,10 @@ const char Conn::ERR_LOGIN[] = "ERLG"; const char Conn::OK_LOGINS[] = "OKLS"; const char Conn::ERR_LOGINS[] = "ERLS"; -Conn::Conn(const SETTINGS & settings, - ADMINS & admins, - USERS & users, - TARIFFS & tariffs, - int sock, const sockaddr_in& addr) - : m_settings(settings), +Conn::Conn(const BASE_PARSER::REGISTRY & registry, + ADMINS & admins, int sock, const sockaddr_in& addr) + : m_registry(registry), m_admins(admins), - m_users(users), - m_tariffs(tariffs), m_admin(NULL), m_sock(sock), m_addr(addr), @@ -110,9 +93,6 @@ Conn::~Conn() shutdown(m_sock, SHUT_RDWR); close(m_sock); - /*std::map::iterator it(m_parsers.begin()); - for (; it != m_parsers.end(); ++it) - delete it->second;*/ XML_ParserFree(m_xmlParser); } @@ -139,19 +119,12 @@ bool Conn::WriteAnswer(const void* buffer, size_t size) return true; } -BASE_PARSER * Conn::GetParser(const std::string & tag) +BASE_PARSER * Conn::GetParser(const std::string & tag) const { - if (strcasecmp(tag.c_str(), "getserverinfo") == 0) - return new STG::PARSER::GET_SERVER_INFO(*m_admin, m_settings, m_users, m_tariffs); - if (strcasecmp(tag.c_str(), "getadmins") == 0) - return new STG::PARSER::GET_ADMINS(*m_admin, m_admins); - if (strcasecmp(tag.c_str(), "addadmin") == 0) - return new STG::PARSER::ADD_ADMIN(*m_admin, m_admins); - if (strcasecmp(tag.c_str(), "deladmin") == 0) - return new STG::PARSER::DEL_ADMIN(*m_admin, m_admins); - if (strcasecmp(tag.c_str(), "chgadmin") == 0) - return new STG::PARSER::CHG_ADMIN(*m_admin, m_admins); - return NULL; + BASE_PARSER::REGISTRY::const_iterator it = m_registry.find(tag); + if (it == m_registry.end()) + return NULL; + return it->second->create(*m_admin); } bool Conn::HandleBuffer(size_t size) diff --git a/projects/stargazer/plugins/configuration/sgconfig/conn.h b/projects/stargazer/plugins/configuration/sgconfig/conn.h index 902cd394..7825d4f9 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/conn.h +++ b/projects/stargazer/plugins/configuration/sgconfig/conn.h @@ -21,12 +21,13 @@ #ifndef __STG_SGCONFIG_CONN_H__ #define __STG_SGCONFIG_CONN_H__ +#include "parser.h" + #include "stg/os_int.h" #include "stg/const.h" #include #include -#include #include @@ -52,11 +53,8 @@ class Conn Error(const std::string& message) : runtime_error(message.c_str()) {} }; - Conn(const SETTINGS & settings, - ADMINS & admins, - USERS & users, - TARIFFS & tariffs, - int sock, const sockaddr_in& addr); + Conn(const BASE_PARSER::REGISTRY & registry, + ADMINS & admins, int sock, const sockaddr_in& addr); ~Conn(); int Sock() const { return m_sock; } @@ -79,10 +77,9 @@ class Conn static const char OK_LOGINS[5]; static const char ERR_LOGINS[5]; - const SETTINGS & m_settings; + const BASE_PARSER::REGISTRY & m_registry; + ADMINS & m_admins; - USERS & m_users; - TARIFFS & m_tariffs; ADMIN * m_admin; @@ -104,7 +101,7 @@ class Conn char m_data[1024]; STG::DECRYPT_STREAM * m_stream; - BASE_PARSER * GetParser(const std::string & tag); + BASE_PARSER * GetParser(const std::string & tag) const; bool HandleBuffer(size_t size); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.h b/projects/stargazer/plugins/configuration/sgconfig/parser.h index 0cda75b6..af77158d 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.h @@ -22,6 +22,7 @@ #define PARSER_H #include +#include class ADMIN; @@ -30,8 +31,9 @@ class BASE_PARSER public: struct FACTORY { - virtual BASE_PARSER * create() = 0; + virtual BASE_PARSER * create(const ADMIN & admin) = 0; }; + typedef std::map REGISTRY; BASE_PARSER(const ADMIN & admin, const std::string & t) : m_currAdmin(admin), diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp index 60ceaaa8..d9b6cfc9 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp @@ -31,6 +31,11 @@ using STG::PARSER::ADD_ADMIN; using STG::PARSER::DEL_ADMIN; using STG::PARSER::CHG_ADMIN; +const char * GET_ADMINS::tag = "GetAdmins"; +const char * ADD_ADMIN::tag = "AddAdmin"; +const char * DEL_ADMIN::tag = "DelAdmin"; +const char * CHG_ADMIN::tag = "ChgAdmin"; + void GET_ADMINS::CreateAnswer() { const PRIV * priv = m_currAdmin.GetPriv(); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h index 7cce32ad..c68789c2 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admins.h @@ -42,17 +42,18 @@ class GET_ADMINS: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const ADMINS & admins) - : m_admin(admin), m_admins(admins) - {} - virtual BASE_PARSER * create() { return new GET_ADMINS(m_admin, m_admins); } + FACTORY(const ADMINS & admins) : m_admins(admins) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_ADMINS(admin, m_admins); } + static void Register(REGISTRY & registry, const ADMINS & admins) + { registry[tag] = new FACTORY(admins); } private: - const ADMIN & m_admin; const ADMINS & m_admins; }; + static const char * tag; + GET_ADMINS(const ADMIN & admin, const ADMINS & admins) - : BASE_PARSER(admin, "GetAdmins"), m_admins(admins) {} + : BASE_PARSER(admin, tag), m_admins(admins) {} private: const ADMINS & m_admins; @@ -66,17 +67,18 @@ class ADD_ADMIN: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, ADMINS & admins) - : m_admin(admin), m_admins(admins) - {} - virtual BASE_PARSER * create() { return new ADD_ADMIN(m_admin, m_admins); } + FACTORY(ADMINS & admins) : m_admins(admins) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_ADMIN(admin, m_admins); } + static void Register(REGISTRY & registry, ADMINS & admins) + { registry[tag] = new FACTORY(admins); } private: - const ADMIN & m_admin; ADMINS & m_admins; }; + static const char * tag; + ADD_ADMIN(const ADMIN & admin, ADMINS & admins) - : BASE_PARSER(admin, "AddAdmin"), m_admins(admins) {} + : BASE_PARSER(admin, tag), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); private: @@ -92,17 +94,18 @@ class DEL_ADMIN: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, ADMINS & admins) - : m_admin(admin), m_admins(admins) - {} - virtual BASE_PARSER * create() { return new DEL_ADMIN(m_admin, m_admins); } + FACTORY(ADMINS & admins) : m_admins(admins) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_ADMIN(admin, m_admins); } + static void Register(REGISTRY & registry, ADMINS & admins) + { registry[tag] = new FACTORY(admins); } private: - const ADMIN & m_admin; ADMINS & m_admins; }; + static const char * tag; + DEL_ADMIN(const ADMIN & admin, ADMINS & admins) - : BASE_PARSER(admin, "DelAdmin"), m_admins(admins) {} + : BASE_PARSER(admin, tag), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); private: @@ -118,17 +121,18 @@ class CHG_ADMIN: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, ADMINS & admins) - : m_admin(admin), m_admins(admins) - {} - virtual BASE_PARSER * create() { return new CHG_ADMIN(m_admin, m_admins); } + FACTORY(ADMINS & admins) : m_admins(admins) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_ADMIN(admin, m_admins); } + static void Register(REGISTRY & registry, ADMINS & admins) + { registry[tag] = new FACTORY(admins); } private: - const ADMIN & m_admin; ADMINS & m_admins; }; + static const char * tag; + CHG_ADMIN(const ADMIN & admin, ADMINS & admins) - : BASE_PARSER(admin, "ChgAdmin"), m_admins(admins) {} + : BASE_PARSER(admin, tag), m_admins(admins) {} int Start(void * data, const char * el, const char ** attr); private: diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp index 2137ef6b..ab1cabdf 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.cpp @@ -25,6 +25,8 @@ using STG::PARSER::AUTH_BY; +const char * AUTH_BY::tag = "GetUserAuthBy"; + int AUTH_BY::Start(void * /*data*/, const char *el, const char **attr) { if (strcasecmp(el, m_tag.c_str()) != 0) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h index 61d25e4d..d36ca1c4 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h @@ -39,17 +39,18 @@ class AUTH_BY : public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new AUTH_BY(m_admin, m_users); } + FACTORY(const USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new AUTH_BY(admin, m_users); } + static void Register(REGISTRY & registry, const USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; const USERS & m_users; }; + static const char * tag; + AUTH_BY(const ADMIN & admin, const USERS & users) - : BASE_PARSER(admin, "GetUserAuthBy"), m_users(users) {} + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); private: diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp index 2e41fcc9..c93ac437 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp @@ -28,6 +28,8 @@ extern volatile time_t stgTime; // So sad... using STG::PARSER::SEND_MESSAGE; +const char * SEND_MESSAGE::tag = "Message"; + int SEND_MESSAGE::Start(void *, const char *el, const char **attr) { if (strcasecmp(el, m_tag.c_str()) != 0) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_message.h b/projects/stargazer/plugins/configuration/sgconfig/parser_message.h index 2df1edc8..6a5f8f4e 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_message.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_message.h @@ -19,8 +19,8 @@ * Author : Maxim Mamontov */ -#ifndef __STG_SGCONFIG_PARSER_USERS_H__ -#define __STG_SGCONFIG_PARSER_USERS_H__ +#ifndef __STG_SGCONFIG_PARSER_SEND_MESSAGE_H__ +#define __STG_SGCONFIG_PARSER_SEND_MESSAGE_H__ #include "parser.h" @@ -43,17 +43,18 @@ class SEND_MESSAGE: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new SEND_MESSAGE(m_admin, m_users); } + FACTORY(USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new SEND_MESSAGE(admin, m_users); } + static void Register(REGISTRY & registry, USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; USERS & m_users; }; + static const char * tag; + SEND_MESSAGE(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "Message"), m_users(users), m_result(res_ok), m_user(NULL) {} + : BASE_PARSER(admin, tag), m_users(users), m_result(res_ok), m_user(NULL) {} int Start(void *data, const char *el, const char **attr); int End(void *data, const char *el); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp index 1287bf51..299b520c 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp @@ -32,6 +32,8 @@ using STG::PARSER::GET_SERVER_INFO; +const char * GET_SERVER_INFO::tag = "GetServerInfo"; + void GET_SERVER_INFO::CreateAnswer() { struct utsname utsn; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.h b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.h index 2aabf473..cc71c73a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_server_info.h @@ -33,11 +33,27 @@ namespace PARSER class GET_SERVER_INFO: public BASE_PARSER { public: + class FACTORY : public BASE_PARSER::FACTORY + { + public: + FACTORY(const SETTINGS & settings, const USERS & users, const TARIFFS & tariffs) + : m_settings(settings), m_users(users), m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_SERVER_INFO(admin, m_settings, m_users, m_tariffs); } + static void Register(REGISTRY & registry, const SETTINGS & settings, const USERS & users, const TARIFFS & tariffs) + { registry[tag] = new FACTORY(settings, users, tariffs); } + private: + const SETTINGS & m_settings; + const USERS & m_users; + const TARIFFS & m_tariffs; + }; + + static const char * tag; + GET_SERVER_INFO(const ADMIN & admin, const SETTINGS & settings, const USERS & users, const TARIFFS & tariffs) - : BASE_PARSER(admin, "GetServerInfo"), + : BASE_PARSER(admin, tag), m_settings(settings), m_users(users), m_tariffs(tariffs) diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp index 2e8d1ff3..5088ee9d 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp @@ -34,6 +34,11 @@ using STG::PARSER::ADD_TARIFF; using STG::PARSER::DEL_TARIFF; using STG::PARSER::CHG_TARIFF; +const char * GET_TARIFFS::tag = "GetTariffs"; +const char * ADD_TARIFF::tag = "AddTariff"; +const char * DEL_TARIFF::tag = "DelTariff"; +const char * CHG_TARIFF::tag = "SetTariff"; + namespace { diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h index f31257df..5dad5eff 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h @@ -43,17 +43,18 @@ class GET_TARIFFS: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new GET_TARIFFS(m_admin, m_tariffs); } + FACTORY(const TARIFFS & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_TARIFFS(admin, m_tariffs); } + static void Register(REGISTRY & registry, const TARIFFS & tariffs) + { registry[tag] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; const TARIFFS & m_tariffs; }; + static const char * tag; + GET_TARIFFS(const ADMIN & admin, const TARIFFS & tariffs) - : BASE_PARSER(admin, "GetTariffs"), m_tariffs(tariffs) {} + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} private: const TARIFFS & m_tariffs; @@ -67,17 +68,18 @@ class ADD_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new ADD_TARIFF(m_admin, m_tariffs); } + FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_TARIFF(admin, m_tariffs); } + static void Register(REGISTRY & registry, TARIFFS & tariffs) + { registry[tag] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; TARIFFS & m_tariffs; }; + static const char * tag; + ADD_TARIFF(const ADMIN & admin, TARIFFS & tariffs) - : BASE_PARSER(admin, "AddTariff"), m_tariffs(tariffs) {} + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: @@ -93,18 +95,19 @@ class DEL_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs, const USERS & users) - : m_admin(admin), m_tariffs(tariffs), m_users(users) - {} - virtual BASE_PARSER * create() { return new DEL_TARIFF(m_admin, m_users, m_tariffs); } + FACTORY(TARIFFS & tariffs, const USERS & users) : m_tariffs(tariffs), m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_TARIFF(admin, m_users, m_tariffs); } + static void Register(REGISTRY & registry, TARIFFS & tariffs, const USERS & users) + { registry[tag] = new FACTORY(tariffs, users); } private: - const ADMIN & m_admin; TARIFFS & m_tariffs; const USERS & m_users; }; + static const char * tag; + DEL_TARIFF(const ADMIN & admin, const USERS & users, TARIFFS & tariffs) - : BASE_PARSER(admin, "DelTariff"), m_users(users), m_tariffs(tariffs) {} + : BASE_PARSER(admin, tag), m_users(users), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: @@ -121,17 +124,18 @@ class CHG_TARIFF: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, TARIFFS & tariffs) - : m_admin(admin), m_tariffs(tariffs) - {} - virtual BASE_PARSER * create() { return new CHG_TARIFF(m_admin, m_tariffs); } + FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_TARIFF(admin, m_tariffs); } + static void Register(REGISTRY & registry, TARIFFS & tariffs) + { registry[tag] = new FACTORY(tariffs); } private: - const ADMIN & m_admin; TARIFFS & m_tariffs; }; + static const char * tag; + CHG_TARIFF(const ADMIN & admin, TARIFFS & tariffs) - : BASE_PARSER(admin, "SetTariff"), m_tariffs(tariffs) {} + : BASE_PARSER(admin, tag), m_tariffs(tariffs) {} int Start(void * data, const char * el, const char ** attr); private: diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp index 797b4c46..c9a2e3d3 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp @@ -38,6 +38,13 @@ using STG::PARSER::DEL_USER; using STG::PARSER::CHG_USER; using STG::PARSER::CHECK_USER; +const char * GET_USERS::tag = "GetUsers"; +const char * GET_USER::tag = "GetUser"; +const char * ADD_USER::tag = "AddUser"; +const char * CHG_USER::tag = "SetUser"; +const char * DEL_USER::tag = "DelUser"; +const char * CHECK_USER::tag = "CheckUser"; + namespace { diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h index f5db4e7b..4d03b7e8 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_users.h +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_users.h @@ -47,17 +47,18 @@ class GET_USERS: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new GET_USERS(m_admin, m_users); } + FACTORY(USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USERS(admin, m_users); } + static void Register(REGISTRY & registry, USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; USERS & m_users; }; + static const char * tag; + GET_USERS(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "GetUsers"), m_users(users), + : BASE_PARSER(admin, tag), m_users(users), m_lastUserUpdateTime(0) {} int Start(void * data, const char * el, const char ** attr); @@ -74,17 +75,18 @@ class GET_USER: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new GET_USER(m_admin, m_users); } + FACTORY(const USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USER(admin, m_users); } + static void Register(REGISTRY & registry, const USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; const USERS & m_users; }; + static const char * tag; + GET_USER(const ADMIN & admin, const USERS & users) - : BASE_PARSER(admin, "GetUser"), m_users(users) {} + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); private: @@ -100,17 +102,18 @@ class ADD_USER: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new ADD_USER(m_admin, m_users); } + FACTORY(USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_USER(admin, m_users); } + static void Register(REGISTRY & registry, USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; USERS & m_users; }; + static const char * tag; + ADD_USER(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "AddUser"), m_users(users) {} + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); private: @@ -126,20 +129,23 @@ class CHG_USER: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, USERS & users, STORE & store, const TARIFFS & tariffs) - : m_admin(admin), m_users(users), m_store(store), m_tariffs(tariffs) + FACTORY(USERS & users, STORE & store, const TARIFFS & tariffs) + : m_users(users), m_store(store), m_tariffs(tariffs) {} - virtual BASE_PARSER * create() { return new CHG_USER(m_admin, m_users, m_store, m_tariffs); } + virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_USER(admin, m_users, m_store, m_tariffs); } + static void Register(REGISTRY & registry, USERS & users, STORE & store, const TARIFFS & tariffs) + { registry[tag] = new FACTORY(users, store, tariffs); } private: - const ADMIN & m_admin; USERS & m_users; STORE & m_store; const TARIFFS & m_tariffs; }; + static const char * tag; + CHG_USER(const ADMIN & admin, USERS & users, STORE & store, const TARIFFS & tariffs) - : BASE_PARSER(admin, "SetUser"), + : BASE_PARSER(admin, tag), m_users(users), m_store(store), m_tariffs(tariffs), @@ -171,17 +177,18 @@ class DEL_USER: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new DEL_USER(m_admin, m_users); } + FACTORY(USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_USER(admin, m_users); } + static void Register(REGISTRY & registry, USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; USERS & m_users; }; + static const char * tag; + DEL_USER(const ADMIN & admin, USERS & users) - : BASE_PARSER(admin, "DelUser"), m_users(users), res(0), u(NULL) {} + : BASE_PARSER(admin, tag), m_users(users), res(0), u(NULL) {} int Start(void * data, const char * el, const char ** attr); int End(void * data, const char * el); @@ -199,17 +206,18 @@ class CHECK_USER: public BASE_PARSER class FACTORY : public BASE_PARSER::FACTORY { public: - FACTORY(const ADMIN & admin, const USERS & users) - : m_admin(admin), m_users(users) - {} - virtual BASE_PARSER * create() { return new CHECK_USER(m_admin, m_users); } + FACTORY(const USERS & users) : m_users(users) {} + virtual BASE_PARSER * create(const ADMIN & admin) { return new CHECK_USER(admin, m_users); } + static void Register(REGISTRY & registry, const USERS & users) + { registry[tag] = new FACTORY(users); } private: - const ADMIN & m_admin; const USERS & m_users; }; + static const char * tag; + CHECK_USER(const ADMIN & admin, const USERS & users) - : BASE_PARSER(admin, "CheckUser"), m_users(users) {} + : BASE_PARSER(admin, tag), m_users(users) {} int Start(void * data, const char * el, const char ** attr); int End(void * data, const char * el); diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 6afd5340..0e344e81 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -50,7 +50,7 @@ public: void SetUsers(USERS * users) { config.SetUsers(users); } void SetTariffs(TARIFFS * tariffs) { config.SetTariffs(tariffs); } void SetAdmins(ADMINS * admins) { config.SetAdmins(admins); } - void SetStore(STORE *) {} + void SetStore(STORE * store) { config.SetStore(store); } void SetStgSettings(const SETTINGS * s) { config.SetSettings(s); } void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings();