77
88std::map<std::string, WSJCppEmployBase*> *g_pWSJCppEmployees = nullptr ;
99std::vector<std::string> *g_pWSJCppInitEmployees = nullptr ;
10+ std::vector<std::string> *g_pWSJCppInitWith = nullptr ;
1011
1112// ---------------------------------------------------------------------
1213
@@ -19,15 +20,21 @@ void WSJCppEmployees::initGlobalVariables() {
1920 // WSJCppLog::info(std::string(), "Create init employees vector");
2021 g_pWSJCppInitEmployees = new std::vector<std::string>();
2122 }
23+ if (g_pWSJCppInitWith == nullptr ) {
24+ // WSJCppLog::info(std::string(), "Create init employees vector");
25+ g_pWSJCppInitWith = new std::vector<std::string>();
26+ }
2227}
2328
2429// ---------------------------------------------------------------------
2530
2631void WSJCppEmployees::deinitGlobalVariables () {
32+ const std::string TAG = " WSJCppEmployees::deinit" ;
2733 if (g_pWSJCppEmployees != nullptr ) {
2834 std::map<std::string, WSJCppEmployBase*>::iterator it;
2935 for (it = g_pWSJCppEmployees->begin (); it != g_pWSJCppEmployees->end (); ++it) {
30- std::string sName = it->first ;
36+ std::string sEmployName = it->first ;
37+ WSJCppLog::ok (TAG, sEmployName + " ... UNREGISTERED" );
3138 delete it->second ;
3239 it->second = nullptr ;
3340 }
@@ -41,6 +48,12 @@ void WSJCppEmployees::deinitGlobalVariables() {
4148 delete g_pWSJCppInitEmployees;
4249 g_pWSJCppInitEmployees = nullptr ;
4350 }
51+
52+ if (g_pWSJCppInitWith != nullptr ) {
53+ g_pWSJCppInitWith->clear ();
54+ delete g_pWSJCppInitWith;
55+ g_pWSJCppInitWith = nullptr ;
56+ }
4457}
4558
4659// ---------------------------------------------------------------------
@@ -59,12 +72,14 @@ void WSJCppEmployees::addEmploy(const std::string &sName, WSJCppEmployBase* pEmp
5972
6073bool WSJCppEmployees::init (const std::vector<std::string> &vStart) {
6174 WSJCppEmployees::initGlobalVariables ();
75+ std::string TAG = " WSJCppEmployees::init" ;
6276
6377 for (unsigned int i = 0 ; i < vStart.size (); i++) {
6478 g_pWSJCppInitEmployees->push_back (vStart[i]);
79+ g_pWSJCppInitWith->push_back (vStart[i]);
80+ WSJCppLog::info (TAG, " with " + vStart[i]);
6581 }
66-
67- std::string TAG = " Employees_init" ;
82+
6883 bool bRepeat = true ;
6984 while (bRepeat) {
7085 bRepeat = false ;
@@ -86,18 +101,64 @@ bool WSJCppEmployees::init(const std::vector<std::string> &vStart) {
86101 }
87102 if (pEmploy->loadAfter ().size () == nRequireLoaded) {
88103 if (!pEmploy->init ()) {
89- WSJCppLog::err (TAG, " Init " + sEmployName + " ... FAIL " );
104+ WSJCppLog::err (TAG, sEmployName + " ... INIT_FAIL " );
90105 return false ;
91106 }
92107 g_pWSJCppInitEmployees->push_back (sEmployName );
93108 bRepeat = true ;
94- WSJCppLog::ok (TAG, " Init " + sEmployName + " ... OK " );
109+ WSJCppLog::ok (TAG, sEmployName + " ... INIT_OK " );
95110 }
96111 }
97112 }
98113 return true ;
99114}
100115
116+ // ---------------------------------------------------------------------
117+
118+ bool WSJCppEmployees::deinit () {
119+ const std::string TAG = " WSJCppEmployees::deinit" ;
120+ if (g_pWSJCppInitEmployees == nullptr
121+ || g_pWSJCppInitWith == nullptr
122+ || g_pWSJCppEmployees == nullptr
123+ ) {
124+ WSJCppLog::err (TAG, " You must call WSJCppEmployees::init before deinit" );
125+ return false ;
126+ }
127+
128+ int nInitedCount = g_pWSJCppInitEmployees->size ();
129+ for (int i = nInitedCount-1 ; i >= 0 ; i--) {
130+ std::string sEmployName = g_pWSJCppInitEmployees->at (i);
131+ if (std::find (g_pWSJCppInitWith->begin (), g_pWSJCppInitWith->end (), sEmployName ) != g_pWSJCppInitWith->end ()) {
132+ WSJCppLog::info (TAG, sEmployName + " ... SKIP_INIT_WITH" );
133+ continue ;
134+ }
135+
136+ std::map<std::string, WSJCppEmployBase*>::iterator it;
137+ it = g_pWSJCppEmployees->find (sEmployName );
138+ if (it == g_pWSJCppEmployees->end ()) {
139+ WSJCppLog::err (TAG, sEmployName + " ... DEINIT_NOT_FOUND" );
140+ return false ;
141+ }
142+ WSJCppEmployBase *pEmploy = it->second ;
143+ if (pEmploy->deinit ()) {
144+ WSJCppLog::ok (TAG, sEmployName + " ... DEINIT_OK" );
145+ } else {
146+ WSJCppLog::err (TAG, sEmployName + " ... DEINIT_FAIL" );
147+ return false ;
148+ }
149+ };
150+
151+ g_pWSJCppInitEmployees->clear ();
152+ delete g_pWSJCppInitEmployees;
153+ g_pWSJCppInitEmployees = nullptr ;
154+
155+ g_pWSJCppInitWith->clear ();
156+ delete g_pWSJCppInitWith;
157+ g_pWSJCppInitWith = nullptr ;
158+ return true ;
159+ }
160+
161+
101162// ---------------------------------------------------------------------
102163
103164// WSJCppEmployBase
@@ -119,19 +180,6 @@ WSJCppEmployBase::~WSJCppEmployBase() {
119180
120181// ---------------------------------------------------------------------
121182
122- bool WSJCppEmployBase::init () {
123- // nothing
124- return true ;
125- }
126-
127- // ---------------------------------------------------------------------
128-
129- void WSJCppEmployBase::deinit () {
130- // nothing
131- }
132-
133- // ---------------------------------------------------------------------
134-
135183const std::vector<std::string> &WSJCppEmployBase::loadAfter () {
136184 return m_vLoadAfter;
137185}
@@ -160,6 +208,15 @@ bool WJSCppEmployRuntimeGlobalCache::init() {
160208
161209// ---------------------------------------------------------------------
162210
211+ bool WJSCppEmployRuntimeGlobalCache::deinit () {
212+ // checking settings
213+ WSJCppLog::info (TAG, " deinit" );
214+ m_sStringMap.clear ();
215+ return true ;
216+ }
217+
218+ // ---------------------------------------------------------------------
219+
163220void WJSCppEmployRuntimeGlobalCache::set (const std::string &sName , const std::string &sValue ) {
164221 m_sStringMap[sName ] = sValue ;
165222}
0 commit comments