Stefan Schuermans commited on 2011-12-11 01:03:08
Showing 4 changed files, with 26 additions and 128 deletions.
... | ... |
@@ -19,6 +19,7 @@ |
19 | 19 |
#include "InStreamFile.h" |
20 | 20 |
#include "IoCallee.h" |
21 | 21 |
#include "Module.h" |
22 |
+#include "ListTracker.h" |
|
22 | 23 |
#include "Protocol.h" |
23 | 24 |
#include "ProtocolFile.h" |
24 | 25 |
#include "SettingFile.h" |
... | ... |
@@ -41,15 +42,8 @@ protected: |
41 | 42 |
/// static destination |
42 | 43 |
class Dest; |
43 | 44 |
|
44 |
- /// static destination list entry |
|
45 |
- struct DestEntry { |
|
46 |
- std::string m_name; ///< name of static destination |
|
47 |
- Dest *m_pDest; ///< static destination object |
|
48 |
- DestEntry(const std::string &name); ///< constructor |
|
49 |
- }; |
|
50 |
- |
|
51 |
- /// static destinations |
|
52 |
- typedef std::list<DestEntry> DestList; |
|
45 |
+ /// static destination list tracker |
|
46 |
+ typedef ListTracker<Sender, Dest, Directory> DestListTracker; |
|
53 | 47 |
|
54 | 48 |
/// dynamic destinations: address -> time of last request |
55 | 49 |
typedef std::map<ADDR, Time> DynDests; |
... | ... |
@@ -109,18 +103,6 @@ protected: |
109 | 103 |
/// destroy socket |
110 | 104 |
void destroySock(); |
111 | 105 |
|
112 |
- /** |
|
113 |
- * @brief light update of static destinations, |
|
114 |
- * i.e. stat all files in current static destination directory |
|
115 |
- */ |
|
116 |
- void updateDestsLight(); |
|
117 |
- |
|
118 |
- /** |
|
119 |
- * @brief full update of static destinations, |
|
120 |
- * i.e. scan files in playlist directory |
|
121 |
- */ |
|
122 |
- void updateDestsFull(); |
|
123 |
- |
|
124 | 106 |
/// remove timed-out dynamic destinations |
125 | 107 |
void removeTimedOutDynDests(); |
126 | 108 |
|
... | ... |
@@ -157,9 +139,8 @@ protected: |
157 | 139 |
InStreamFile m_fileInStream; ///< input stream name file |
158 | 140 |
AddrFile m_fileBind; ///< bind address file |
159 | 141 |
ProtocolFile m_fileProtocol; ///< protocol file |
160 |
- Directory m_dirDests; ///< static destinations directory |
|
161 | 142 |
SOCK *m_pSock; ///< socket to use for sending streams |
162 |
- DestList m_destList; ///< static destinations |
|
143 |
+ DestListTracker m_destListTracker; ///< static destinations tracker |
|
163 | 144 |
DynDests m_dynDests; ///< dynamic destinations |
164 | 145 |
std::string m_noFrameData; ///< "no frame" protocol data (empty if unknown) |
165 | 146 |
std::string m_data; ///< current protocol data (empty if unknown) |
... | ... |
@@ -24,12 +24,10 @@ public: |
24 | 24 |
/** |
25 | 25 |
* @brief constructor |
26 | 26 |
* @param[in] sender owning sender object |
27 |
+ * @param[in] name destination name |
|
27 | 28 |
* @param[in] dirBase base directory |
28 |
- * @param[in] pNoFrameData protocol data for "no frame" packet |
|
29 |
- * (empty if unknown) |
|
30 | 29 |
*/ |
31 |
- Dest(Sender &sender, const Directory &dirBase, |
|
32 |
- const std::string *pNoFrameData); |
|
30 |
+ Dest(Sender &sender, const std::string &name, const Directory &dirBase); |
|
33 | 31 |
|
34 | 32 |
/// destructor |
35 | 33 |
~Dest(); |
... | ... |
@@ -63,8 +61,8 @@ protected: |
63 | 61 |
|
64 | 62 |
protected: |
65 | 63 |
Sender &m_sender; ///< owning sender object |
64 |
+ std::string m_name; ///< destination name |
|
66 | 65 |
AddrFile m_fileAddr; ///< address file |
67 |
- const std::string *m_pNoFrameData; ///< protocol data for "no frame" packet |
|
68 | 66 |
const std::string *m_pData; ///< protocol data to send to address |
69 | 67 |
}; // class Sender<ADDr, SOCK>::Dest |
70 | 68 |
|
... | ... |
@@ -20,17 +20,16 @@ namespace Blinker { |
20 | 20 |
/** |
21 | 21 |
* @brief constructor |
22 | 22 |
* @param[in] sender owning sender object |
23 |
+ * @param[in] name destination name |
|
23 | 24 |
* @param[in] dirBase base directory |
24 |
- * @param[in] pNoFrameData protocol data for "no frame" packet |
|
25 |
- * (empty if unknown) |
|
26 | 25 |
*/ |
27 | 26 |
template<typename ADDR, typename SOCK> |
28 |
-Sender<ADDR, SOCK>::Dest::Dest(Sender &sender, const Directory &dirBase, |
|
29 |
- const std::string *pNoFrameData): |
|
27 |
+Sender<ADDR, SOCK>::Dest::Dest(Sender &sender, const std::string &name, |
|
28 |
+ const Directory &dirBase): |
|
30 | 29 |
m_sender(sender), |
30 |
+ m_name(name), |
|
31 | 31 |
m_fileAddr(dirBase.getFile("addr")), |
32 |
- m_pNoFrameData(pNoFrameData), |
|
33 |
- m_pData(pNoFrameData) |
|
32 |
+ m_pData(&sender.m_noFrameData) |
|
34 | 33 |
{ |
35 | 34 |
// set up |
36 | 35 |
getAddr(); |
... | ... |
@@ -41,7 +40,7 @@ template<typename ADDR, typename SOCK> |
41 | 40 |
Sender<ADDR, SOCK>::Dest::~Dest() |
42 | 41 |
{ |
43 | 42 |
// send "no frame" protocol data to old address |
44 |
- send(m_pNoFrameData); |
|
43 |
+ send(&m_sender.m_noFrameData); |
|
45 | 44 |
} |
46 | 45 |
|
47 | 46 |
/// check for update of configuration |
... | ... |
@@ -74,7 +73,7 @@ void Sender<ADDR, SOCK>::Dest::getAddr() |
74 | 73 |
std::string strAddr; |
75 | 74 |
|
76 | 75 |
// send "no frame" protocol data to old address |
77 |
- send(m_pNoFrameData); |
|
76 |
+ send(&m_sender.m_noFrameData); |
|
78 | 77 |
|
79 | 78 |
// get new address from file |
80 | 79 |
m_fileAddr.update(); |
... | ... |
@@ -18,6 +18,8 @@ |
18 | 18 |
#include "File.h" |
19 | 19 |
#include "InStreamFile.h" |
20 | 20 |
#include "IoCallee.h" |
21 |
+#include "ListTracker.h" |
|
22 |
+#include "ListTracker_impl.h" |
|
21 | 23 |
#include "Module.h" |
22 | 24 |
#include "Protocol.h" |
23 | 25 |
#include "ProtocolFile.h" |
... | ... |
@@ -45,8 +47,8 @@ Sender<ADDR, SOCK>::Sender(CallMgr &callMgr, StreamMgr &streamMgr, |
45 | 47 |
m_fileInStream(dirBase.getFile("instream"), streamMgr), |
46 | 48 |
m_fileBind(dirBase.getFile("bind")), |
47 | 49 |
m_fileProtocol(dirBase.getFile("protocol")), |
48 |
- m_dirDests(dirBase.getSubdir("destinations")), |
|
49 |
- m_pSock(NULL) |
|
50 |
+ m_pSock(NULL), |
|
51 |
+ m_destListTracker(*this, dirBase.getSubdir("destinations")) |
|
50 | 52 |
{ |
51 | 53 |
// read protocol |
52 | 54 |
readProto(); |
... | ... |
@@ -57,7 +59,7 @@ Sender<ADDR, SOCK>::Sender(CallMgr &callMgr, StreamMgr &streamMgr, |
57 | 59 |
createSock(); |
58 | 60 |
|
59 | 61 |
// load static destinations |
60 |
- updateDestsFull(); |
|
62 |
+ m_destListTracker.init(); |
|
61 | 63 |
} |
62 | 64 |
|
63 | 65 |
/// virtual destructor |
... | ... |
@@ -67,11 +69,8 @@ Sender<ADDR, SOCK>::~Sender() |
67 | 69 |
// send "no frame" to all destinations |
68 | 70 |
sendAllNoFrame(); |
69 | 71 |
|
70 |
- // free static destination lists |
|
71 |
- while (!m_destList.empty()) { |
|
72 |
- delete m_destList.back().m_pDest; |
|
73 |
- m_destList.pop_back(); |
|
74 |
- } |
|
72 |
+ // free static destinations |
|
73 |
+ m_destListTracker.clear(); |
|
75 | 74 |
|
76 | 75 |
// destroy socket |
77 | 76 |
destroySock(); |
... | ... |
@@ -100,11 +99,7 @@ void Sender<ADDR, SOCK>::updateConfig() |
100 | 99 |
readProto(); |
101 | 100 |
|
102 | 101 |
// static destinations update |
103 |
- // (directory modified -> full, otherwise -> light) |
|
104 |
- if (m_dirDests.checkModified()) |
|
105 |
- updateDestsFull(); |
|
106 |
- else |
|
107 |
- updateDestsLight(); |
|
102 |
+ m_destListTracker.updateConfig(); |
|
108 | 103 |
} |
109 | 104 |
|
110 | 105 |
/** |
... | ... |
@@ -237,70 +232,6 @@ void Sender<ADDR, SOCK>::destroySock() |
237 | 232 |
} |
238 | 233 |
} |
239 | 234 |
|
240 |
-/** |
|
241 |
- * @brief light update of static destinations, |
|
242 |
- * i.e. stat all files in current static destination directory |
|
243 |
- */ |
|
244 |
-template<typename ADDR, typename SOCK> |
|
245 |
-void Sender<ADDR, SOCK>::updateDestsLight() |
|
246 |
-{ |
|
247 |
- // walk through all files in static dest dir and check for modification |
|
248 |
- typename DestList::iterator itDest; |
|
249 |
- for (itDest = m_destList.begin(); itDest != m_destList.end(); ++itDest) |
|
250 |
- itDest->m_pDest->updateConfig(); |
|
251 |
-} |
|
252 |
- |
|
253 |
-/** |
|
254 |
- * @brief full update of static destinations, |
|
255 |
- * i.e. scan files in playlist directory |
|
256 |
- */ |
|
257 |
-template<typename ADDR, typename SOCK> |
|
258 |
-void Sender<ADDR, SOCK>::updateDestsFull() |
|
259 |
-{ |
|
260 |
- // get list of subdirs in input directory |
|
261 |
- typedef std::list<std::string> Subdirlist; |
|
262 |
- Subdirlist curSubdirs; |
|
263 |
- m_dirDests.getEntries(Directory::TypeSubdir, curSubdirs); |
|
264 |
- |
|
265 |
- // walk through current static destinations and subdir list simultaneously |
|
266 |
- Subdirlist::const_iterator itSubdir = curSubdirs.begin(); |
|
267 |
- typename DestList::iterator itDest = m_destList.begin(); |
|
268 |
- while (itSubdir != curSubdirs.end() || itDest != m_destList.end()) { |
|
269 |
- |
|
270 |
- // new static destination inserted |
|
271 |
- if (itDest == m_destList.end() || |
|
272 |
- (itSubdir != curSubdirs.end() && *itSubdir < itDest->m_name)) { |
|
273 |
- // create static destination object |
|
274 |
- DestEntry destEntry(*itSubdir); |
|
275 |
- destEntry.m_pDest = new Dest(*this, m_dirDests.getSubdir(*itSubdir), |
|
276 |
- &m_noFrameData); |
|
277 |
- if (destEntry.m_pDest) |
|
278 |
- // insert static destination entry |
|
279 |
- m_destList.insert(itDest, destEntry); |
|
280 |
- // advance to next subdir |
|
281 |
- ++itSubdir; |
|
282 |
- } |
|
283 |
- |
|
284 |
- // static destination removed |
|
285 |
- else if (itSubdir == curSubdirs.end() || *itSubdir > itDest->m_name) { |
|
286 |
- // remove static destination |
|
287 |
- delete itDest->m_pDest; |
|
288 |
- itDest = m_destList.erase(itDest); |
|
289 |
- // do not advance to next subdir |
|
290 |
- } |
|
291 |
- |
|
292 |
- // static sestination stayed in input list |
|
293 |
- else { |
|
294 |
- // check for update |
|
295 |
- itDest->m_pDest->updateConfig(); |
|
296 |
- // advance to next file and next entry |
|
297 |
- ++itSubdir; |
|
298 |
- ++itDest; |
|
299 |
- } |
|
300 |
- |
|
301 |
- } // while itSubdir itDest |
|
302 |
-} |
|
303 |
- |
|
304 | 235 |
/// remove timed-out dynamic destinations |
305 | 236 |
template<typename ADDR, typename SOCK> |
306 | 237 |
void Sender<ADDR, SOCK>::removeTimedOutDynDests() |
... | ... |
@@ -354,9 +285,10 @@ template<typename ADDR, typename SOCK> |
354 | 285 |
void Sender<ADDR, SOCK>::sendDests(const std::string *pData) |
355 | 286 |
{ |
356 | 287 |
// send data to static destinations |
357 |
- typename DestList::const_iterator itDest; |
|
358 |
- for (itDest = m_destList.begin(); itDest != m_destList.end(); ++itDest) |
|
359 |
- itDest->m_pDest->setProtoData(pData); |
|
288 |
+ typename DestListTracker::ListIt itDest; |
|
289 |
+ for (itDest = m_destListTracker.m_list.begin(); |
|
290 |
+ itDest != m_destListTracker.m_list.end(); ++itDest) |
|
291 |
+ itDest->m_pObj->setProtoData(pData); |
|
360 | 292 |
|
361 | 293 |
// send data to all dynamic destinations |
362 | 294 |
typename DynDests::const_iterator itDyn; |
... | ... |
@@ -450,18 +382,6 @@ void Sender<ADDR, SOCK>::receiveFromSock() |
450 | 382 |
|
451 | 383 |
} |
452 | 384 |
|
453 |
-/* ##################### |
|
454 |
- # Sender::DestEntry # |
|
455 |
- ##################### */ |
|
456 |
- |
|
457 |
-/// constructor |
|
458 |
-template<typename ADDR, typename SOCK> |
|
459 |
-Sender<ADDR, SOCK>::DestEntry::DestEntry(const std::string &name): |
|
460 |
- m_name(name), |
|
461 |
- m_pDest(NULL) |
|
462 |
-{ |
|
463 |
-} |
|
464 |
- |
|
465 | 385 |
} // namespace Blinker |
466 | 386 |
|
467 | 387 |
#endif // #ifndef SENDER_H |
468 | 388 |