fhq-server  v0.2.33
Documentation for fhq-server. FreeHackQuest is an open source platform for competitions of computer security.
wsjcpp_employees.h
Go to the documentation of this file.
1 #ifndef WSJCPP_EMPLOYEES_H
2 #define WSJCPP_EMPLOYEES_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <mutex>
8 #include <wsjcpp_core.h>
9 
10 // ---------------------------------------------------------------------
11 // base employ class
12 
14 public:
16  const std::string &sName,
17  const std::vector<std::string> &vLoadAfter
18  );
19  virtual ~WsjcppEmployBase();
20  virtual bool init() = 0;
21  virtual bool deinit() = 0;
22  const std::vector<std::string> &loadAfter();
23 
24 private:
25  std::string TAG;
26  std::string m_sName;
27  std::vector<std::string> m_vLoadAfter;
28 };
29 
30 // ---------------------------------------------------------------------
31 // public employees
32 
33 extern std::map<std::string, WsjcppEmployBase*> *g_pWsjcppEmployees;
34 extern std::vector<std::string> *g_pWsjcppInitEmployees;
35 
37  public:
38  static void initGlobalVariables();
39  static void deinitGlobalVariables();
40  static void addEmploy(const std::string &sName, WsjcppEmployBase* pEmploy);
41  static bool init(const std::vector<std::string> &vLoadAfter);
42  static bool deinit();
43 };
44 
45 // ---------------------------------------------------------------------
46 // RegistryEmploy
47 #define REGISTRY_WJSCPP_EMPLOY( classname ) \
48  static classname * pWJSCppRegistryEmploy ## classname = new classname(); \
49 
50 // ---------------------------------------------------------------------
51 // findWsjcppEmploy
52 
53 template <class T> T* findWsjcppEmploy() {
55  std::string TAG = "findWsjcppEmploy";
56  std::string sEmployName = T::name();
57  WsjcppEmployBase *pEmploy = NULL;
58  if (g_pWsjcppEmployees->count(sEmployName)) {
59  pEmploy = g_pWsjcppEmployees->at(sEmployName);
60  }
61  if (pEmploy == NULL) {
62  WsjcppLog::throw_err(TAG, "Not found employ " + sEmployName);
63  }
64  T *pTEmploy = dynamic_cast<T*>(pEmploy);
65  if (pTEmploy == NULL) {
66  WsjcppLog::throw_err(TAG, "Employ could not cast to T [" + sEmployName + "]");
67  }
68  return pTEmploy;
69 }
70 
71 // ---------------------------------------------------------------------
72 // WJSCppEmployRuntimeGlobalCache
73 
75  public:
77  static std::string name() { return "WJSCppEmployRuntimeGlobalCache"; }
78  virtual bool init() override;
79  virtual bool deinit() override;
80  void set(const std::string &sName, const std::string &sValue);
81  bool has(const std::string &sName);
82  std::string get(const std::string &sName);
83 
84  private:
85  std::string TAG;
86  std::map<std::string, std::string> m_sStringMap;
87 };
88 
89 #endif // WSJCPP_EMPLOYEES_H
WsjcppEmployBase(const std::string &sName, const std::vector< std::string > &vLoadAfter)
Definition: wsjcpp_employees.cpp:165
std::vector< std::string > m_vLoadAfter
Definition: wsjcpp_employees.h:27
Definition: wsjcpp_employees.h:74
std::string TAG
Definition: wsjcpp_employees.h:25
T * findWsjcppEmploy()
Definition: wsjcpp_employees.h:53
std::vector< std::string > * g_pWsjcppInitEmployees
Definition: wsjcpp_employees.cpp:9
static void initGlobalVariables()
Definition: wsjcpp_employees.cpp:14
std::map< std::string, WsjcppEmployBase * > * g_pWsjcppEmployees
Definition: wsjcpp_employees.cpp:8
Definition: wsjcpp_employees.h:13
Definition: wsjcpp_employees.h:36
std::string m_sName
Definition: wsjcpp_employees.h:26
virtual bool deinit()=0
std::map< std::string, std::string > m_sStringMap
Definition: wsjcpp_employees.h:86
const std::vector< std::string > & loadAfter()
Definition: wsjcpp_employees.cpp:183
static std::string name()
Definition: wsjcpp_employees.h:77
virtual ~WsjcppEmployBase()
Definition: wsjcpp_employees.cpp:177
std::string TAG
Definition: wsjcpp_employees.h:85
virtual bool init()=0
static void throw_err(const std::string &sTag, const std::string &sMessage)
Definition: wsjcpp_core.cpp:1122