Stefan Schuermans commited on 2011-12-11 12:11:15
Showing 4 changed files, with 23 additions and 100 deletions.
| ... | ... |
@@ -16,6 +16,8 @@ |
| 16 | 16 |
#include "Format.h" |
| 17 | 17 |
#include "FormatFile.h" |
| 18 | 18 |
#include "Module.h" |
| 19 |
+#include "ListTracker.h" |
|
| 20 |
+#include "ListTracker_impl.h" |
|
| 19 | 21 |
#include "OutStreamFile.h" |
| 20 | 22 |
#include "StreamMgr.h" |
| 21 | 23 |
#include "StreamRecv.h" |
| ... | ... |
@@ -31,24 +33,21 @@ namespace Blinker {
|
| 31 | 33 |
Canvas::Canvas(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): |
| 32 | 34 |
Module(callMgr, streamMgr, dirBase), |
| 33 | 35 |
m_fileFormat(dirBase.getFile("format")),
|
| 34 |
- m_dirInputs(dirBase.getSubdir("inputs")),
|
|
| 35 | 36 |
m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
|
| 36 | 37 |
m_pCanvas(NULL), |
| 37 |
- m_canvasHasFrame(false) |
|
| 38 |
+ m_canvasHasFrame(false), |
|
| 39 |
+ m_inListTracker(*this, dirBase.getSubdir("inputs"))
|
|
| 38 | 40 |
{
|
| 39 | 41 |
// set up |
| 40 | 42 |
createCanvas(); |
| 41 |
- updateInListFull(); |
|
| 43 |
+ m_inListTracker.init(); |
|
| 42 | 44 |
} |
| 43 | 45 |
|
| 44 | 46 |
/// virtual destructor |
| 45 | 47 |
Canvas::~Canvas() |
| 46 | 48 |
{
|
| 47 | 49 |
// clean up |
| 48 |
- while (!m_inList.empty()) {
|
|
| 49 |
- delete m_inList.back().m_pInput; |
|
| 50 |
- m_inList.pop_back(); |
|
| 51 |
- } |
|
| 50 |
+ m_inListTracker.clear(); |
|
| 52 | 51 |
destroyCanvas(); |
| 53 | 52 |
} |
| 54 | 53 |
|
| ... | ... |
@@ -60,11 +59,8 @@ void Canvas::updateConfig() |
| 60 | 59 |
createCanvas(); |
| 61 | 60 |
} |
| 62 | 61 |
|
| 63 |
- // input list update (directory modified -> full, otherwise -> light) |
|
| 64 |
- if (m_dirInputs.checkModified()) |
|
| 65 |
- updateInListFull(); |
|
| 66 |
- else |
|
| 67 |
- updateInListLight(); |
|
| 62 |
+ // input list update |
|
| 63 |
+ m_inListTracker.updateConfig(); |
|
| 68 | 64 |
|
| 69 | 65 |
// output stream name file was modified -> re-get output stream |
| 70 | 66 |
if (m_fileOutStream.checkModified()) |
| ... | ... |
@@ -100,61 +96,6 @@ void Canvas::destroyCanvas() |
| 100 | 96 |
} |
| 101 | 97 |
} |
| 102 | 98 |
|
| 103 |
-/// light update of input list, i.e. check all entries in current input list |
|
| 104 |
-void Canvas::updateInListLight() |
|
| 105 |
-{
|
|
| 106 |
- // walk through all inputs in input list and check for modification |
|
| 107 |
- InList::iterator itIn; |
|
| 108 |
- for (itIn = m_inList.begin(); itIn != m_inList.end(); ++itIn) |
|
| 109 |
- itIn->m_pInput->updateConfig(); |
|
| 110 |
-} |
|
| 111 |
- |
|
| 112 |
-/// full update of input list, i.e. scan subdirs in input list directory |
|
| 113 |
-void Canvas::updateInListFull() |
|
| 114 |
-{
|
|
| 115 |
- // get list of subdirs in input directory |
|
| 116 |
- typedef std::list<std::string> Subdirlist; |
|
| 117 |
- Subdirlist curSubdirs; |
|
| 118 |
- m_dirInputs.getEntries(Directory::TypeSubdir, curSubdirs); |
|
| 119 |
- |
|
| 120 |
- // walk through current input list and subdir list simultaneously |
|
| 121 |
- Subdirlist::const_iterator itSubdir = curSubdirs.begin(); |
|
| 122 |
- InList::iterator itIn = m_inList.begin(); |
|
| 123 |
- while (itSubdir != curSubdirs.end() || itIn != m_inList.end()) {
|
|
| 124 |
- |
|
| 125 |
- // new input inserted |
|
| 126 |
- if (itIn == m_inList.end() || |
|
| 127 |
- (itSubdir != curSubdirs.end() && *itSubdir < itIn->m_name)) {
|
|
| 128 |
- // create input object |
|
| 129 |
- InEntry inEntry(*itSubdir); |
|
| 130 |
- inEntry.m_pInput = new Input(*this, m_dirInputs.getSubdir(*itSubdir)); |
|
| 131 |
- if (inEntry.m_pInput) |
|
| 132 |
- // insert input list entry |
|
| 133 |
- m_inList.insert(itIn, inEntry); |
|
| 134 |
- // advance to next subdir |
|
| 135 |
- ++itSubdir; |
|
| 136 |
- } |
|
| 137 |
- |
|
| 138 |
- // input removed |
|
| 139 |
- else if (itSubdir == curSubdirs.end() || *itSubdir > itIn->m_name) {
|
|
| 140 |
- // remove input |
|
| 141 |
- delete itIn->m_pInput; |
|
| 142 |
- itIn = m_inList.erase(itIn); |
|
| 143 |
- // do not advance to next subdir |
|
| 144 |
- } |
|
| 145 |
- |
|
| 146 |
- // input stayed in input list |
|
| 147 |
- else {
|
|
| 148 |
- // check for update |
|
| 149 |
- itIn->m_pInput->updateConfig(); |
|
| 150 |
- // advance to next file and next entry |
|
| 151 |
- ++itSubdir; |
|
| 152 |
- ++itIn; |
|
| 153 |
- } |
|
| 154 |
- |
|
| 155 |
- } // while itSubdir itIn |
|
| 156 |
-} |
|
| 157 |
- |
|
| 158 | 99 |
/// notfication to redraw (called by inputs) |
| 159 | 100 |
void Canvas::redraw() |
| 160 | 101 |
{
|
| ... | ... |
@@ -167,9 +108,10 @@ void Canvas::redraw() |
| 167 | 108 |
m_canvasHasFrame = false; // no frame on canvas yet |
| 168 | 109 |
|
| 169 | 110 |
// tell all inputs to draw on canvas |
| 170 |
- InList::iterator itIn; |
|
| 171 |
- for (itIn = m_inList.begin(); itIn != m_inList.end(); ++itIn) |
|
| 172 |
- if (itIn->m_pInput->draw()) |
|
| 111 |
+ InListTracker::ListIt itIn; |
|
| 112 |
+ for (itIn = m_inListTracker.m_list.begin(); |
|
| 113 |
+ itIn != m_inListTracker.m_list.end(); ++itIn) |
|
| 114 |
+ if (itIn->m_pObj->draw()) |
|
| 173 | 115 |
m_canvasHasFrame = true; // drawing successful -> there is a frame now |
| 174 | 116 |
|
| 175 | 117 |
// send current frame to stream |
| ... | ... |
@@ -187,16 +129,5 @@ void Canvas::sendFrame() |
| 187 | 129 |
m_fileOutStream.setFrame(NULL); |
| 188 | 130 |
} |
| 189 | 131 |
|
| 190 |
-/* ################### |
|
| 191 |
- # Canvas::InEntry # |
|
| 192 |
- ################### */ |
|
| 193 |
- |
|
| 194 |
-/// constructor |
|
| 195 |
-Canvas::InEntry::InEntry(const std::string &name): |
|
| 196 |
- m_name(name), |
|
| 197 |
- m_pInput(NULL) |
|
| 198 |
-{
|
|
| 199 |
-} |
|
| 200 |
- |
|
| 201 | 132 |
} // namespace Blinker |
| 202 | 133 |
|
| ... | ... |
@@ -16,6 +16,7 @@ |
| 16 | 16 |
#include "File.h" |
| 17 | 17 |
#include "Format.h" |
| 18 | 18 |
#include "FormatFile.h" |
| 19 |
+#include "ListTracker.h" |
|
| 19 | 20 |
#include "Module.h" |
| 20 | 21 |
#include "OutStreamFile.h" |
| 21 | 22 |
#include "StreamMgr.h" |
| ... | ... |
@@ -29,15 +30,8 @@ protected: |
| 29 | 30 |
/// input to canvas |
| 30 | 31 |
class Input; |
| 31 | 32 |
|
| 32 |
- /// input list entry |
|
| 33 |
- struct InEntry {
|
|
| 34 |
- std::string m_name; ///< name of input list entry |
|
| 35 |
- Input *m_pInput; ///< input object |
|
| 36 |
- InEntry(const std::string &name); ///< constructor |
|
| 37 |
- }; |
|
| 38 |
- |
|
| 39 |
- /// input list |
|
| 40 |
- typedef std::list<InEntry> InList; |
|
| 33 |
+ /// input list tracker |
|
| 34 |
+ typedef ListTracker<Canvas, Input, Directory> InListTracker; |
|
| 41 | 35 |
|
| 42 | 36 |
public: |
| 43 | 37 |
/** |
| ... | ... |
@@ -69,12 +63,6 @@ protected: |
| 69 | 63 |
/// tear down canvas |
| 70 | 64 |
void destroyCanvas(); |
| 71 | 65 |
|
| 72 |
- /// light update of input list, i.e. check all entries in current input list |
|
| 73 |
- void updateInListLight(); |
|
| 74 |
- |
|
| 75 |
- /// full update of input list, i.e. scan subdirs in input list directory |
|
| 76 |
- void updateInListFull(); |
|
| 77 |
- |
|
| 78 | 66 |
/// notfication to redraw (called by inputs) |
| 79 | 67 |
void redraw(); |
| 80 | 68 |
|
| ... | ... |
@@ -83,11 +71,10 @@ protected: |
| 83 | 71 |
|
| 84 | 72 |
protected: |
| 85 | 73 |
FormatFile m_fileFormat; ///< canvas format file |
| 86 |
- Directory m_dirInputs; ///< input stream directory |
|
| 87 | 74 |
OutStreamFile m_fileOutStream; ///< output stream name file |
| 88 | 75 |
stBlinkenFrame *m_pCanvas; ///< canvas to put streams on |
| 89 | 76 |
bool m_canvasHasFrame; ///< if there is >= 1 frame on canvas |
| 90 |
- InList m_inList; ///< current input list |
|
| 77 |
+ InListTracker m_inListTracker; ///< input list tracker |
|
| 91 | 78 |
}; // class Canvas |
| 92 | 79 |
|
| 93 | 80 |
} // namespace Blinker |
| ... | ... |
@@ -24,10 +24,13 @@ namespace Blinker {
|
| 24 | 24 |
/** |
| 25 | 25 |
* @brief constructor |
| 26 | 26 |
* @param[in] canvas owning canvas |
| 27 |
+ * @param[in] name name of input |
|
| 27 | 28 |
* @param[in] dirBase base directory |
| 28 | 29 |
*/ |
| 29 |
-Canvas::Input::Input(Canvas &canvas, const Directory &dirBase): |
|
| 30 |
+Canvas::Input::Input(Canvas &canvas, const std::string &name, |
|
| 31 |
+ const Directory &dirBase): |
|
| 30 | 32 |
m_canvas(canvas), |
| 33 |
+ m_name(name), |
|
| 31 | 34 |
m_fileInStream(dirBase.getFile("instream"), canvas.m_streamMgr),
|
| 32 | 35 |
m_fileSrcPos(dirBase.getFile("srcpos")),
|
| 33 | 36 |
m_fileSize(dirBase.getFile("size")),
|
| ... | ... |
@@ -30,9 +30,10 @@ public: |
| 30 | 30 |
/** |
| 31 | 31 |
* @brief constructor |
| 32 | 32 |
* @param[in] canvas owning canvas |
| 33 |
+ * @param[in] name name of input |
|
| 33 | 34 |
* @param[in] dirBase base directory |
| 34 | 35 |
*/ |
| 35 |
- Input(Canvas &canvas, const Directory &dirBase); |
|
| 36 |
+ Input(Canvas &canvas, const std::string &name, const Directory &dirBase); |
|
| 36 | 37 |
|
| 37 | 38 |
/// virtual destructor |
| 38 | 39 |
virtual ~Input(); |
| ... | ... |
@@ -73,6 +74,7 @@ protected: |
| 73 | 74 |
|
| 74 | 75 |
protected: |
| 75 | 76 |
Canvas &m_canvas; ///< owning canvas |
| 77 |
+ std::string m_name; ///< name of input |
|
| 76 | 78 |
InStreamFile m_fileInStream; ///< input stream name file |
| 77 | 79 |
PositionFile m_fileSrcPos; ///< source position file |
| 78 | 80 |
SizeFile m_fileSize; ///< size file |
| 79 | 81 |