Stefan Schuermans commited on 2011-12-11 00:38:00
Showing 4 changed files, with 125 additions and 121 deletions.
... | ... |
@@ -10,6 +10,7 @@ |
10 | 10 |
|
11 | 11 |
#include "CallMgr.h" |
12 | 12 |
#include "Directory.h" |
13 |
+#include "ListTracker.h" |
|
13 | 14 |
#include "Module.h" |
14 | 15 |
#include "StreamMgr.h" |
15 | 16 |
#include "TimeCallee.h" |
... | ... |
@@ -21,17 +22,11 @@ template<typename MODULE> |
21 | 22 |
class ModuleMgr: public TimeCallee |
22 | 23 |
{ |
23 | 24 |
protected: |
24 |
- /// module list entry |
|
25 |
- struct Entry { |
|
26 |
- std::string m_name; ///< name of module |
|
27 |
- MODULE *m_pModule; ///< module object |
|
28 |
- Entry(const std::string &name); ///< constructor |
|
29 |
- void createModule(ModuleMgr &mgr); ///< create module |
|
30 |
- void destroyModule(); ///< destroy module |
|
31 |
- }; |
|
32 |
- |
|
33 |
- /// module list |
|
34 |
- typedef std::list<Entry> ModuleList; |
|
25 |
+ /// module container |
|
26 |
+ class Cntr; |
|
27 |
+ |
|
28 |
+ /// module list tracker |
|
29 |
+ typedef ListTracker<ModuleMgr, Cntr, Directory> ModuleListTracker; |
|
35 | 30 |
|
36 | 31 |
public: |
37 | 32 |
/** |
... | ... |
@@ -60,17 +55,11 @@ protected: |
60 | 55 |
/// check for update of configuration |
61 | 56 |
void updateConfig(); |
62 | 57 |
|
63 |
- /// light update of module list, i.e. call all modules in current list |
|
64 |
- void updateModuleListLight(); |
|
65 |
- |
|
66 |
- /// full update of module list, i.e. scan all subdirs in base directory |
|
67 |
- void updateModuleListFull(); |
|
68 |
- |
|
69 | 58 |
protected: |
70 | 59 |
CallMgr &m_callMgr; ///< callback manager |
71 | 60 |
StreamMgr &m_streamMgr; ///< stream manager |
72 | 61 |
Directory m_dirBase; ///< base directory |
73 |
- ModuleList m_moduleList; ///< module list |
|
62 |
+ ModuleListTracker m_moduleListTracker; ///< module list tracker |
|
74 | 63 |
}; // class ModuleMgr |
75 | 64 |
|
76 | 65 |
} // namespace Blinker |
... | ... |
@@ -0,0 +1,56 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef MODULEMGRCNTR_H |
|
7 |
+#define MODULEMGRCNTR_H |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+ |
|
11 |
+#include "Directory.h" |
|
12 |
+#include "File.h" |
|
13 |
+#include "Module.h" |
|
14 |
+#include "ModuleMgr.h" |
|
15 |
+#include "Sender.h" |
|
16 |
+#include "SettingFile.h" |
|
17 |
+ |
|
18 |
+namespace Blinker { |
|
19 |
+ |
|
20 |
+/// container for a module (used by module manager) |
|
21 |
+template<typename MODULE> |
|
22 |
+class ModuleMgr<MODULE>::Cntr |
|
23 |
+{ |
|
24 |
+public: |
|
25 |
+ /** |
|
26 |
+ * @brief constructor |
|
27 |
+ * @param[in] mgr owning module manager |
|
28 |
+ * @param[in] name name of module |
|
29 |
+ * @param[in] dirBase base directory |
|
30 |
+ */ |
|
31 |
+ Cntr(ModuleMgr &mgr, const std::string &name, const Directory &dirBase); |
|
32 |
+ |
|
33 |
+ /// destructor |
|
34 |
+ ~Cntr(); |
|
35 |
+ |
|
36 |
+private: |
|
37 |
+ /// copy constructor disabled |
|
38 |
+ Cntr(const Cntr &that); |
|
39 |
+ |
|
40 |
+ /// assignment operator disabled |
|
41 |
+ const Cntr & operator=(const Cntr &that); |
|
42 |
+ |
|
43 |
+public: |
|
44 |
+ /// check for update of configuration |
|
45 |
+ void updateConfig(); |
|
46 |
+ |
|
47 |
+protected: |
|
48 |
+ ModuleMgr &m_mgr; ///< owning module manager |
|
49 |
+ std::string m_name; ///< name of module |
|
50 |
+ MODULE m_mod; ///< module |
|
51 |
+}; // class Cntr<MODULE> |
|
52 |
+ |
|
53 |
+} // namespace Blinker |
|
54 |
+ |
|
55 |
+#endif // #ifndef MODULEMGRCNTR_H |
|
56 |
+ |
... | ... |
@@ -0,0 +1,52 @@ |
1 |
+/* Blinker |
|
2 |
+ Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> |
|
3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
4 |
+ a blinkenarea.org project */ |
|
5 |
+ |
|
6 |
+#ifndef MODULEMGRCNTR_IMPL_H |
|
7 |
+#define MODULEMGRCNTR_IMPL_H |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+ |
|
11 |
+#include "Directory.h" |
|
12 |
+#include "File.h" |
|
13 |
+#include "Module.h" |
|
14 |
+#include "ModuleMgr.h" |
|
15 |
+#include "ModuleMgrCntr.h" |
|
16 |
+#include "Sender.h" |
|
17 |
+#include "SettingFile.h" |
|
18 |
+ |
|
19 |
+namespace Blinker { |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @brief constructor |
|
23 |
+ * @param[in] mgr owning module manager |
|
24 |
+ * @param[in] name name of module |
|
25 |
+ * @param[in] dirBase base directory |
|
26 |
+ */ |
|
27 |
+template<typename MODULE> |
|
28 |
+ModuleMgr<MODULE>::Cntr::Cntr(ModuleMgr &mgr, const std::string &name, |
|
29 |
+ const Directory &dirBase): |
|
30 |
+ m_mgr(mgr), |
|
31 |
+ m_name(name), |
|
32 |
+ m_mod(mgr.m_callMgr, mgr.m_streamMgr, dirBase) |
|
33 |
+{ |
|
34 |
+} |
|
35 |
+ |
|
36 |
+/// destructor |
|
37 |
+template<typename MODULE> |
|
38 |
+ModuleMgr<MODULE>::Cntr::~Cntr() |
|
39 |
+{ |
|
40 |
+} |
|
41 |
+ |
|
42 |
+/// check for update of configuration |
|
43 |
+template<typename MODULE> |
|
44 |
+void ModuleMgr<MODULE>::Cntr::updateConfig() |
|
45 |
+{ |
|
46 |
+ m_mod.updateConfig(); |
|
47 |
+} |
|
48 |
+ |
|
49 |
+} // namespace Blinker |
|
50 |
+ |
|
51 |
+#endif // #ifndef MODULEMGRCNTR_IMPL_H |
|
52 |
+ |
... | ... |
@@ -10,8 +10,12 @@ |
10 | 10 |
|
11 | 11 |
#include "CallMgr.h" |
12 | 12 |
#include "Directory.h" |
13 |
+#include "ListTracker.h" |
|
14 |
+#include "ListTracker_impl.h" |
|
13 | 15 |
#include "Module.h" |
14 | 16 |
#include "ModuleMgr.h" |
17 |
+#include "ModuleMgrCntr.h" |
|
18 |
+#include "ModuleMgrCntr_impl.h" |
|
15 | 19 |
#include "StreamMgr.h" |
16 | 20 |
#include "TimeCallee.h" |
17 | 21 |
|
... | ... |
@@ -28,9 +32,10 @@ ModuleMgr<MODULE>::ModuleMgr(CallMgr &callMgr, StreamMgr &streamMgr, |
28 | 32 |
const Directory &dirBase): |
29 | 33 |
m_callMgr(callMgr), |
30 | 34 |
m_streamMgr(streamMgr), |
31 |
- m_dirBase(dirBase) |
|
35 |
+ m_dirBase(dirBase), |
|
36 |
+ m_moduleListTracker(*this, dirBase) |
|
32 | 37 |
{ |
33 |
- updateModuleListFull(); |
|
38 |
+ m_moduleListTracker.init(); |
|
34 | 39 |
|
35 | 40 |
// request call in 1s |
36 | 41 |
m_callMgr.requestTimeCall(this, Time::now() + Time(1)); |
... | ... |
@@ -40,11 +45,7 @@ ModuleMgr<MODULE>::ModuleMgr(CallMgr &callMgr, StreamMgr &streamMgr, |
40 | 45 |
template<typename MODULE> |
41 | 46 |
ModuleMgr<MODULE>::~ModuleMgr() |
42 | 47 |
{ |
43 |
- // free all modules |
|
44 |
- while (!m_moduleList.empty()) { |
|
45 |
- m_moduleList.back().destroyModule(); |
|
46 |
- m_moduleList.pop_back(); |
|
47 |
- } |
|
48 |
+ m_moduleListTracker.clear(); |
|
48 | 49 |
} |
49 | 50 |
|
50 | 51 |
/// callback when requested time reached |
... | ... |
@@ -61,102 +62,8 @@ void ModuleMgr<MODULE>::timeCall() |
61 | 62 |
template<typename MODULE> |
62 | 63 |
void ModuleMgr<MODULE>::updateConfig() |
63 | 64 |
{ |
64 |
- // module list update (base directory modified -> full, otherwise -> light) |
|
65 |
- if (m_dirBase.checkModified()) |
|
66 |
- updateModuleListFull(); |
|
67 |
- else |
|
68 |
- updateModuleListLight(); |
|
69 |
-} |
|
70 |
- |
|
71 |
-/// light update of module list, i.e. call all modules in current list |
|
72 |
-template<typename MODULE> |
|
73 |
-void ModuleMgr<MODULE>::updateModuleListLight() |
|
74 |
-{ |
|
75 |
- typename ModuleList::iterator itEntry; |
|
76 |
- for (itEntry = m_moduleList.begin(); itEntry != m_moduleList.end(); |
|
77 |
- ++itEntry) { |
|
78 |
- |
|
79 |
- // call module to check for changes |
|
80 |
- itEntry->m_pModule->updateConfig(); |
|
81 |
- |
|
82 |
- } // for itEntry |
|
83 |
-} |
|
84 |
- |
|
85 |
-/// full update of module list, i.e. scan all subdirs in base directory |
|
86 |
-template<typename MODULE> |
|
87 |
-void ModuleMgr<MODULE>::updateModuleListFull() |
|
88 |
-{ |
|
89 |
- // get list of subdirectories in base directory |
|
90 |
- typedef std::list<std::string> Subdirlist; |
|
91 |
- Subdirlist curSubdirs; |
|
92 |
- m_dirBase.getEntries(Directory::TypeSubdir, curSubdirs); |
|
93 |
- |
|
94 |
- // walk through current module list and subdir list simultaneously |
|
95 |
- Subdirlist::const_iterator itSubdir = curSubdirs.begin(); |
|
96 |
- typename ModuleList::iterator itEntry = m_moduleList.begin(); |
|
97 |
- while (itSubdir != curSubdirs.end() || itEntry != m_moduleList.end()) { |
|
98 |
- |
|
99 |
- // new module inserted |
|
100 |
- if (itEntry == m_moduleList.end() || |
|
101 |
- (itSubdir != curSubdirs.end() && *itSubdir < itEntry->m_name)) { |
|
102 |
- // create module |
|
103 |
- Entry entry(*itSubdir); |
|
104 |
- entry.createModule(*this); |
|
105 |
- // insert module list entry |
|
106 |
- m_moduleList.insert(itEntry, entry); |
|
107 |
- // advance to next subdir |
|
108 |
- ++itSubdir; |
|
109 |
- } |
|
110 |
- |
|
111 |
- // module removed |
|
112 |
- else if (itSubdir == curSubdirs.end() || *itSubdir > itEntry->m_name) { |
|
113 |
- // remove entry |
|
114 |
- itEntry->destroyModule(); |
|
115 |
- itEntry = m_moduleList.erase(itEntry); |
|
116 |
- // do not advance to next subdir |
|
117 |
- } |
|
118 |
- |
|
119 |
- // module stayed in list |
|
120 |
- else { |
|
121 |
- // call module to check for changes |
|
122 |
- itEntry->m_pModule->updateConfig(); |
|
123 |
- // advance to next subdir and next entry |
|
124 |
- ++itSubdir; |
|
125 |
- ++itEntry; |
|
126 |
- } |
|
127 |
- |
|
128 |
- } // while itSubdir itEntry |
|
129 |
-} |
|
130 |
- |
|
131 |
-/* #################### |
|
132 |
- # ModuleMgr::Entry # |
|
133 |
- #################### */ |
|
134 |
- |
|
135 |
-/// constructor |
|
136 |
-template<typename MODULE> |
|
137 |
-ModuleMgr<MODULE>::Entry::Entry(const std::string &name): |
|
138 |
- m_name(name), |
|
139 |
- m_pModule(NULL) |
|
140 |
-{ |
|
141 |
-} |
|
142 |
- |
|
143 |
-/// create module |
|
144 |
-template<typename MODULE> |
|
145 |
-void ModuleMgr<MODULE>::Entry::createModule(ModuleMgr &mgr) |
|
146 |
-{ |
|
147 |
- destroyModule(); |
|
148 |
- m_pModule = new MODULE(mgr.m_callMgr, mgr.m_streamMgr, |
|
149 |
- mgr.m_dirBase.getSubdir(m_name)); |
|
150 |
-} |
|
151 |
- |
|
152 |
-/// destroy module |
|
153 |
-template<typename MODULE> |
|
154 |
-void ModuleMgr<MODULE>::Entry::destroyModule() |
|
155 |
-{ |
|
156 |
- if (m_pModule) { |
|
157 |
- delete m_pModule; |
|
158 |
- m_pModule = NULL; |
|
159 |
- } |
|
65 |
+ // module list update |
|
66 |
+ m_moduleListTracker.updateConfig(); |
|
160 | 67 |
} |
161 | 68 |
|
162 | 69 |
} // namespace Blinker |
163 | 70 |