implemented specialized setting files for different data types, simplified input/output stream handling in modules
Stefan Schuermans

Stefan Schuermans commited on 2011-12-04 20:10:37
Showing 35 changed files, with 871 additions and 670 deletions.

... ...
@@ -14,8 +14,9 @@
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16 16
 #include "Format.h"
17
+#include "FormatFile.h"
17 18
 #include "Module.h"
18
-#include "SettingFile.h"
19
+#include "OutStreamFile.h"
19 20
 #include "StreamMgr.h"
20 21
 #include "StreamRecv.h"
21 22
 
... ...
@@ -31,22 +32,19 @@ Canvas::Canvas(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase)
31 32
   Module(callMgr, streamMgr, dirBase),
32 33
   m_fileFormat(dirBase.getFile("format")),
33 34
   m_dirInputs(dirBase.getSubdir("inputs")),
34
-  m_fileOutStream(dirBase.getFile("outstream")),
35
+  m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
35 36
   m_pCanvas(NULL),
36
-  m_canvasHasFrame(false),
37
-  m_pOutStream(NULL)
37
+  m_canvasHasFrame(false)
38 38
 {
39 39
   // set up
40 40
   createCanvas();
41 41
   updateInListFull();
42
-  getOutStream();
43 42
 }
44 43
 
45 44
 /// virtual destructor
46 45
 Canvas::~Canvas()
47 46
 {
48 47
   // clean up
49
-  releaseOutStream();
50 48
   while (!m_inList.empty()) {
51 49
     delete m_inList.back().m_pInput;
52 50
     m_inList.pop_back();
... ...
@@ -69,27 +67,26 @@ void Canvas::updateConfig()
69 67
     updateInListLight();
70 68
 
71 69
   // output stream name file was modified -> re-get output stream
72
-  if (m_fileOutStream.checkModified()) {
73
-    releaseOutStream();
74
-    getOutStream();
75
-  }
70
+  if (m_fileOutStream.checkModified())
71
+    m_fileOutStream.update();
76 72
 }
77 73
 
78 74
 /// (re-)create canvas
79 75
 void Canvas::createCanvas()
80 76
 {
81
-  std::string strFormat;
82
-
83 77
   // get rid of old canvas
84 78
   destroyCanvas();
85 79
 
86 80
   // read format from format file
87
-  if (!m_fileFormat.getStr(strFormat) || !m_format.fromStr(strFormat))
81
+  m_fileFormat.update();
82
+  if (!m_fileFormat.m_valid)
88 83
     return;
89 84
 
90 85
   // create frame
91
-  m_pCanvas = BlinkenFrameNew(m_format.m_height, m_format.m_width,
92
-                              m_format.m_channels, m_format.m_maxval, 1);
86
+  m_pCanvas = BlinkenFrameNew(m_fileFormat.m_obj.m_height,
87
+                              m_fileFormat.m_obj.m_width,
88
+                              m_fileFormat.m_obj.m_channels,
89
+                              m_fileFormat.m_obj.m_maxval, 1);
93 90
   m_canvasHasFrame = false;
94 91
 }
95 92
 
... ...
@@ -158,31 +155,6 @@ void Canvas::updateInListFull()
158 155
   } // while itSubdir itIn
159 156
 }
160 157
 
161
-/// get output stream
162
-void Canvas::getOutStream()
163
-{
164
-  // get name of output stream
165
-  m_fileOutStream.getStr(m_nameOutStream);
166
-
167
-  // get output stream
168
-  m_pOutStream = &m_streamMgr.refStream(m_nameOutStream);
169
-
170
-  // send current frame to stream
171
-  sendFrame();
172
-}
173
-
174
-/// release output stream
175
-void Canvas::releaseOutStream()
176
-{
177
-  // send no frame information
178
-  if (m_pOutStream)
179
-    m_pOutStream->setFrame(NULL);
180
-
181
-  // unreference output stream
182
-  m_pOutStream = NULL;
183
-  m_streamMgr.unrefStream(m_nameOutStream);
184
-}
185
-
186 158
 /// notfication to redraw (called by inputs)
187 159
 void Canvas::redraw()
188 160
 {
... ...
@@ -207,14 +179,12 @@ void Canvas::redraw()
207 179
 /// send current frame to output stream
208 180
 void Canvas::sendFrame()
209 181
 {
210
-  if (m_pOutStream) {
211 182
   // frame available -> send it
212 183
   if (m_canvasHasFrame)
213
-      m_pOutStream->setFrame(m_pCanvas);
184
+    m_fileOutStream.setFrame(m_pCanvas);
214 185
   // no frame available -> send this information
215 186
   else
216
-      m_pOutStream->setFrame(NULL);
217
-  }
187
+    m_fileOutStream.setFrame(NULL);
218 188
 }
219 189
 
220 190
 /* ###################
... ...
@@ -15,8 +15,9 @@
15 15
 #include "Directory.h"
16 16
 #include "File.h"
17 17
 #include "Format.h"
18
+#include "FormatFile.h"
18 19
 #include "Module.h"
19
-#include "SettingFile.h"
20
+#include "OutStreamFile.h"
20 21
 #include "StreamMgr.h"
21 22
 
22 23
 namespace Blinker {
... ...
@@ -74,12 +75,6 @@ protected:
74 75
   /// full update of input list, i.e. scan subdirs in input list directory
75 76
   void updateInListFull();
76 77
 
77
-  /// get output stream
78
-  void getOutStream();
79
-
80
-  /// release output stream
81
-  void releaseOutStream();
82
-
83 78
   /// notfication to redraw (called by inputs)
84 79
   void redraw();
85 80
 
... ...
@@ -87,15 +82,12 @@ protected:
87 82
   void sendFrame();
88 83
 
89 84
 protected:
90
-  SettingFile    m_fileFormat;     ///< canvas format file
85
+  FormatFile     m_fileFormat;     ///< canvas format file
91 86
   Directory      m_dirInputs;      ///< input stream directory
92
-  SettingFile    m_fileOutStream;  ///< output stream name file
93
-  Format         m_format;         ///< canvas format
87
+  OutStreamFile  m_fileOutStream;  ///< output stream name file
94 88
   stBlinkenFrame *m_pCanvas;       ///< canvas to put streams on
95 89
   bool           m_canvasHasFrame; ///< if there is >= 1 frame on canvas
96 90
   InList         m_inList;         ///< current input list
97
-  std::string    m_nameOutStream;  ///< name of output stream
98
-  Stream         *m_pOutStream;    ///< output stream
99 91
 }; // class Canvas
100 92
 
101 93
 } // namespace Blinker
... ...
@@ -11,9 +11,11 @@
11 11
 #include "CanvasInput.h"
12 12
 #include "Directory.h"
13 13
 #include "File.h"
14
+#include "InStreamFile.h"
14 15
 #include "Position.h"
15
-#include "SettingFile.h"
16
+#include "PositionFile.h"
16 17
 #include "Size.h"
18
+#include "SizeFile.h"
17 19
 #include "StreamMgr.h"
18 20
 #include "StreamRecv.h"
19 21
 
... ...
@@ -26,27 +28,23 @@ namespace Blinker {
26 28
  */
27 29
 Canvas::Input::Input(Canvas &canvas, const Directory &dirBase):
28 30
   m_canvas(canvas),
29
-  m_fileInStream(dirBase.getFile("instream")),
31
+  m_fileInStream(dirBase.getFile("instream"), canvas.m_streamMgr),
30 32
   m_fileSrcPos(dirBase.getFile("srcpos")),
31 33
   m_fileSize(dirBase.getFile("size")),
32
-  m_fileDestPos(dirBase.getFile("destpos")),
33
-  m_pInStream(NULL),
34
-  m_haveSrcPos(false),
35
-  m_haveSize(false),
36
-  m_haveDestPos(false)
34
+  m_fileDestPos(dirBase.getFile("destpos"))
37 35
 {
38
-  // get settings and attach to input stream
36
+  // set up
39 37
   getSrcPos();
40 38
   getSize();
41 39
   getDestPos();
42
-  getInStream();
40
+  m_fileInStream.setStreamRecv(this);
43 41
 }
44 42
 
45 43
 /// virtual destructor
46 44
 Canvas::Input::~Input()
47 45
 {
48
-  // detach from input stream and release it
49
-  releaseInStream();
46
+  // clean up
47
+  m_fileInStream.setStreamRecv(NULL);
50 48
 }
51 49
 
52 50
 /// check for update of configuration
... ...
@@ -54,8 +52,8 @@ void Canvas::Input::updateConfig()
54 52
 {
55 53
   // input stream name file was modified -> re-get input stream
56 54
   if (m_fileInStream.checkModified()) {
57
-    releaseInStream();
58
-    getInStream();
55
+    m_fileInStream.update();
56
+    m_canvas.redraw(); // notify canvas to redraw
59 57
   }
60 58
 
61 59
   // position/size files were modified -> re-get position/size
... ...
@@ -88,75 +86,50 @@ void Canvas::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
88 86
 bool Canvas::Input::draw()
89 87
 {
90 88
   stBlinkenFrame *pFrame;
89
+  int destx, desty, srcx, srcy, width, height;
91 90
 
92 91
   // no destination position or no canvas -> leave
93
-  if (!m_haveDestPos || !m_canvas.m_pCanvas)
92
+  if (!m_fileDestPos.m_valid || !m_canvas.m_pCanvas)
94 93
     return false;
94
+  destx = m_fileDestPos.m_obj.m_x;
95
+  desty = m_fileDestPos.m_obj.m_y;
95 96
 
96 97
   // get current frame from stream (leave if no stream or no frame)
97
-  if (!m_pInStream)
98
-    return false;
99
-  pFrame = m_pInStream->getCurFrame();
98
+  pFrame = m_fileInStream.getCurFrame();
100 99
   if (!pFrame)
101 100
     return false;
102 101
 
103 102
   // no source position -> use top left
104
-  if (!m_haveSrcPos) {
105
-    m_srcPos.m_x = 0;
106
-    m_srcPos.m_y = 0;
103
+  if (m_fileSrcPos.m_valid) {
104
+    srcx = m_fileSrcPos.m_obj.m_x;
105
+    srcy = m_fileSrcPos.m_obj.m_y;
106
+  } else {
107
+    srcx = 0;
108
+    srcy = 0;
107 109
   }
108 110
 
109 111
   // no size -> use entire source frame
110 112
   //            (BlinkenLib will clip this if too large)
111
-  if (!m_haveSize) {
112
-    m_size.m_width = BlinkenFrameGetWidth(pFrame);
113
-    m_size.m_height = BlinkenFrameGetHeight(pFrame);
113
+  if (m_fileSize.m_valid) {
114
+    width = m_fileSize.m_obj.m_width;
115
+    height = m_fileSize.m_obj.m_height;
116
+  } else {
117
+    width = BlinkenFrameGetWidth(pFrame);
118
+    height = BlinkenFrameGetHeight(pFrame);
114 119
   }
115 120
 
116 121
   // draw rectangular area to canvas
117
-  BlinkenFrameCopyRect(m_canvas.m_pCanvas, m_destPos.m_y, m_destPos.m_x,
118
-                       pFrame, m_srcPos.m_y, m_srcPos.m_x,
119
-                       m_size.m_height, m_size.m_width);
122
+  BlinkenFrameCopyRect(m_canvas.m_pCanvas, desty, destx,
123
+                       pFrame, srcy, srcx, height, width);
120 124
 
121 125
   return true;
122 126
 }
123 127
 
124
-/// get input stream and attach to it
125
-void Canvas::Input::getInStream()
126
-{
127
-  // get input stream
128
-  m_fileInStream.getStr(m_nameInStream);
129
-  m_pInStream = &m_canvas.m_streamMgr.refStream(m_nameInStream);
130
-
131
-  // attach to input stream
132
-  if (m_pInStream)
133
-    m_pInStream->attach(this);
134
-
135
-  // redrawing canvas will happen automatically because stream will set frame
136
-}
137
-
138
-/// detach from input stream and release it
139
-void Canvas::Input::releaseInStream()
140
-{
141
-  // detach from input stream
142
-  if (m_pInStream)
143
-    m_pInStream->detach(this);
144
-
145
-  // unreference stream
146
-  m_pInStream = NULL;
147
-  m_canvas.m_streamMgr.unrefStream(m_nameInStream);
148
-
149
-  // notify canvas to redraw
150
-  m_canvas.redraw();
151
-}
152
-
153 128
 /// (re-)get position of area to copy from stream
154 129
 void Canvas::Input::getSrcPos()
155 130
 {
156
-  std::string strPos;
157
-
158
-  // read source position from file and parse it
159
-  m_haveSrcPos = m_fileSrcPos.getStr(strPos) && m_srcPos.fromStr(strPos);
131
+  // read source position from file
132
+  m_fileSrcPos.update();
160 133
 
161 134
   // notify canvas to redraw
162 135
   m_canvas.redraw();
... ...
@@ -165,10 +138,8 @@ void Canvas::Input::getSrcPos()
165 138
 /// (re-)get size of area to copy from stream
166 139
 void Canvas::Input::getSize()
167 140
 {
168
-  std::string strSize;
169
-
170
-  // read size from file and parse it
171
-  m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize);
141
+  // read size from file
142
+  m_fileSize.update();
172 143
 
173 144
   // notify canvas to redraw
174 145
   m_canvas.redraw();
... ...
@@ -177,10 +148,8 @@ void Canvas::Input::getSize()
177 148
 /// (re-)get destination position on canvas
178 149
 void Canvas::Input::getDestPos()
179 150
 {
180
-  std::string strPos;
181
-
182
-  // read destination position from file and parse it
183
-  m_haveDestPos = m_fileDestPos.getStr(strPos) && m_destPos.fromStr(strPos);
151
+  // read destination position from file
152
+  m_fileDestPos.update();
184 153
 
185 154
   // notify canvas to redraw
186 155
   m_canvas.redraw();
... ...
@@ -13,9 +13,11 @@
13 13
 #include "Canvas.h"
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16
+#include "InStreamFile.h"
16 17
 #include "Position.h"
17
-#include "SettingFile.h"
18
+#include "PositionFile.h"
18 19
 #include "Size.h"
20
+#include "SizeFile.h"
19 21
 #include "StreamMgr.h"
20 22
 #include "StreamRecv.h"
21 23
 
... ...
@@ -60,12 +62,6 @@ public:
60 62
   bool draw();
61 63
 
62 64
 protected:
63
-  /// get input stream and attach to it
64
-  void getInStream();
65
-
66
-  /// detach from input stream and release it
67
-  void releaseInStream();
68
-
69 65
   /// (re-)get position of area to copy from stream
70 66
   void getSrcPos();
71 67
 
... ...
@@ -77,18 +73,10 @@ protected:
77 73
 
78 74
 protected:
79 75
   Canvas       &m_canvas;      ///< owning canvas
80
-  SettingFile    m_fileInStream; ///< input stream name file
81
-  SettingFile    m_fileSrcPos;   ///< source position file
82
-  SettingFile    m_fileSize;     ///< size file
83
-  SettingFile    m_fileDestPos;  ///< destination position file
84
-  std::string    m_nameInStream; ///< name of input stream
85
-  Stream         *m_pInStream;   ///< input stream
86
-  bool           m_haveSrcPos;   ///< if copy-area src position is defined
87
-  Position       m_srcPos;       ///< copy-area position in source
88
-  bool           m_haveSize;     ///< if copy-area size is defined
89
-  Size           m_size;         ///< copy-area size
90
-  bool           m_haveDestPos;  ///< if copy-area dest position is defined
91
-  Position       m_destPos;      ///< copy-area position on canvas (i.e. dest)
76
+  InStreamFile m_fileInStream; ///< input stream name file
77
+  PositionFile m_fileSrcPos;   ///< source position file
78
+  SizeFile     m_fileSize;     ///< size file
79
+  PositionFile m_fileDestPos;  ///< destination position file
92 80
 }; // class Canvas::Input
93 81
 
94 82
 } // namespace Blinker
... ...
@@ -0,0 +1,20 @@
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 FORMATFILE_H
7
+#define FORMATFILE_H
8
+
9
+#include "Format.h"
10
+#include "SettingFile_impl.h"
11
+
12
+namespace Blinker {
13
+
14
+/// setting file containting frame format
15
+typedef SettingFile<Format> FormatFile;
16
+
17
+} // namespace Blinker
18
+
19
+#endif // #ifndef FORMATFILE_H
20
+
... ...
@@ -0,0 +1,104 @@
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
+#include "File.h"
7
+#include "InStreamFile.h"
8
+#include "Stream.h"
9
+#include "StreamFile.h"
10
+#include "StreamMgr.h"
11
+#include "StreamRecv.h"
12
+
13
+namespace Blinker {
14
+
15
+/**
16
+ * @brief constructor from path
17
+ * @param[in] path path to file
18
+ * @param[in] streamMgr stream manager
19
+ */
20
+InStreamFile::InStreamFile(const std::string &path, StreamMgr &streamMgr):
21
+  StreamFile(path, streamMgr),
22
+  m_pStreamRecv(NULL)
23
+{
24
+  update();
25
+}
26
+
27
+/**
28
+ * @brief constructor from basic file
29
+ * @param[in] file basic file object
30
+ * @param[in] streamMgr stream manager
31
+ */
32
+InStreamFile::InStreamFile(const File &file, StreamMgr &streamMgr):
33
+  StreamFile(file, streamMgr),
34
+  m_pStreamRecv(NULL)
35
+{
36
+  update();
37
+}
38
+
39
+/// destructor
40
+InStreamFile::~InStreamFile()
41
+{
42
+  detach();
43
+  // unreferencing stream happens in destructor of StreamFile
44
+}
45
+
46
+/**
47
+ * @brief assignment operator
48
+ * @param[in] file basic file object
49
+ */
50
+const InStreamFile & InStreamFile::operator=(const File &file)
51
+{
52
+  detach();
53
+  StreamFile::operator=(file);
54
+  attach();
55
+  return *this;
56
+}
57
+
58
+/**
59
+ * @brief set stream receiver
60
+ * @param[in] pStreamRecv stream reciver (NULL if none)
61
+ */
62
+void InStreamFile::setStreamRecv(StreamRecv *pStreamRecv)
63
+{
64
+  detach();
65
+  m_pStreamRecv = pStreamRecv;
66
+  attach();
67
+}
68
+
69
+/// update, i.e. (re-)read file and attach to new stream
70
+void InStreamFile::update()
71
+{
72
+  detach();
73
+  StreamFile::update();
74
+  attach();
75
+}
76
+
77
+/**
78
+ * @brief get current frame
79
+ * @return current frame (NULL for none)
80
+ */
81
+stBlinkenFrame * InStreamFile::getCurFrame() const
82
+{
83
+  if (m_pStream)
84
+    return m_pStream->getCurFrame();
85
+  else
86
+    return NULL;
87
+}
88
+
89
+/// attach to stream
90
+void InStreamFile::attach()
91
+{
92
+  if (m_pStream && m_pStreamRecv)
93
+    m_pStream->attach(m_pStreamRecv);
94
+}
95
+
96
+/// detach from stream
97
+void InStreamFile::detach()
98
+{
99
+  if (m_pStream && m_pStreamRecv)
100
+    m_pStream->detach(m_pStreamRecv);
101
+}
102
+
103
+} // namespace Blinker
104
+
... ...
@@ -0,0 +1,73 @@
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 INSTREAMFILE_H
7
+#define INSTREAMFILE_H
8
+
9
+#include "File.h"
10
+#include "StreamFile.h"
11
+#include "StreamMgr.h"
12
+#include "StreamRecv.h"
13
+
14
+namespace Blinker {
15
+
16
+/// setting file containting a name of an input stream
17
+class InStreamFile: public StreamFile
18
+{
19
+public:
20
+  /**
21
+   * @brief constructor from path
22
+   * @param[in] path path to file
23
+   * @param[in] streamMgr stream manager
24
+   */
25
+  InStreamFile(const std::string &path, StreamMgr &streamMgr);
26
+
27
+  /**
28
+   * @brief constructor from basic file
29
+   * @param[in] file basic file object
30
+   * @param[in] streamMgr stream manager
31
+   */
32
+  InStreamFile(const File &file, StreamMgr &streamMgr);
33
+
34
+  /// destructor
35
+  ~InStreamFile();
36
+
37
+  /**
38
+   * @brief assignment operator
39
+   * @param[in] file basic file object
40
+   */
41
+  const InStreamFile & operator=(const File &file);
42
+
43
+public:
44
+  /**
45
+   * @brief set stream receiver
46
+   * @param[in] pStreamRecv stream reciver (NULL if none)
47
+   */
48
+  void setStreamRecv(StreamRecv *pStreamRecv);
49
+
50
+  /// update, i.e. (re-)read file and attach to new stream
51
+  void update();
52
+
53
+  /**
54
+   * @brief get current frame
55
+   * @return current frame (NULL for none)
56
+   */
57
+  stBlinkenFrame * getCurFrame() const;
58
+
59
+protected:
60
+  /// attach to stream
61
+  void attach();
62
+
63
+  /// detach from stream
64
+  void detach();
65
+
66
+protected:
67
+  StreamRecv *m_pStreamRecv; ///< stream receiver to attach to input stream
68
+}; // class InStreamFile
69
+
70
+} // namespace Blinker
71
+
72
+#endif // #ifndef INSTREAMFILE_H
73
+
... ...
@@ -0,0 +1,38 @@
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
+#include <string>
7
+
8
+#include "Name.h"
9
+
10
+namespace Blinker {
11
+
12
+/// constructor
13
+Name::Name()
14
+{
15
+}
16
+
17
+/**
18
+ * @brief parse from string format
19
+ * @param[in] str string format
20
+ * @return if parsing was successful
21
+ */
22
+bool Name::fromStr(const std::string &str)
23
+{
24
+  m_str = str;
25
+  return !m_str.empty();
26
+}
27
+
28
+/**
29
+ * @brief convert to string format
30
+ * @return string format
31
+ */
32
+std::string Name::toStr() const
33
+{
34
+  return m_str;
35
+}
36
+
37
+} // namespace Blinker
38
+
... ...
@@ -0,0 +1,41 @@
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 NAME_H
7
+#define NAME_H
8
+
9
+#include <string>
10
+
11
+namespace Blinker {
12
+
13
+/// a name (a wrapper for std::string to use it as templ param of SettingFile)
14
+class Name
15
+{
16
+public:
17
+  /// constructor
18
+  Name();
19
+
20
+public:
21
+  /**
22
+   * @brief parse from string format
23
+   * @param[in] str string format
24
+   * @return if parsing was successful
25
+   */
26
+  bool fromStr(const std::string &str);
27
+
28
+  /**
29
+   * @brief convert to string format
30
+   * @return string format
31
+   */
32
+  std::string toStr() const;
33
+
34
+public:
35
+  std::string m_str; ///< name string
36
+}; // class Name
37
+
38
+} // namespace Blinker
39
+
40
+#endif // #ifndef NAME_H
41
+
... ...
@@ -0,0 +1,20 @@
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 NAMEFILE_H
7
+#define NAMEFILE_H
8
+
9
+#include "Name.h"
10
+#include "SettingFile_impl.h"
11
+
12
+namespace Blinker {
13
+
14
+/// setting file containting a name
15
+typedef SettingFile<Name> NameFile;
16
+
17
+} // namespace Blinker
18
+
19
+#endif // #ifndef NAMEFILE_H
20
+
... ...
@@ -0,0 +1,72 @@
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
+#include "File.h"
7
+#include "OutStreamFile.h"
8
+#include "Stream.h"
9
+#include "StreamFile.h"
10
+#include "StreamMgr.h"
11
+
12
+namespace Blinker {
13
+
14
+/**
15
+ * @brief constructor from path
16
+ * @param[in] path path to file
17
+ * @param[in] streamMgr stream manager
18
+ */
19
+OutStreamFile::OutStreamFile(const std::string &path, StreamMgr &streamMgr):
20
+  StreamFile(path, streamMgr)
21
+{
22
+  update();
23
+}
24
+
25
+/**
26
+ * @brief constructor from basic file
27
+ * @param[in] file basic file object
28
+ * @param[in] streamMgr stream manager
29
+ */
30
+OutStreamFile::OutStreamFile(const File &file, StreamMgr &streamMgr):
31
+  StreamFile(file, streamMgr)
32
+{
33
+  update();
34
+}
35
+
36
+/// destructor
37
+OutStreamFile::~OutStreamFile()
38
+{
39
+  setFrame(NULL); // set empty frame (stream is ending)
40
+  // unreferencing stream happens in destructor of StreamFile
41
+}
42
+
43
+/**
44
+ * @brief assignment operator
45
+ * @param[in] file basic file object
46
+ */
47
+const OutStreamFile & OutStreamFile::operator=(const File &file)
48
+{
49
+  setFrame(NULL); // set empty frame (stream is ending)
50
+  StreamFile::operator=(file);
51
+  return *this;
52
+}
53
+
54
+/// update, i.e. (re-)read file and reference new stream
55
+void OutStreamFile::update()
56
+{
57
+  setFrame(NULL); // set empty frame (stream is ending)
58
+  StreamFile::update();
59
+}
60
+
61
+/**
62
+ * @brief set current frame
63
+ * @param[in] pFrame current frame (NULL for none)
64
+ */
65
+void OutStreamFile::setFrame(stBlinkenFrame *pFrame)
66
+{
67
+  if (m_pStream)
68
+    m_pStream->setFrame(pFrame);
69
+}
70
+
71
+} // namespace Blinker
72
+
... ...
@@ -0,0 +1,58 @@
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 OUTSTREAMFILE_H
7
+#define OUTSTREAMFILE_H
8
+
9
+#include <BlinkenLib/BlinkenFrame.h>
10
+
11
+#include "File.h"
12
+#include "StreamFile.h"
13
+#include "StreamMgr.h"
14
+
15
+namespace Blinker {
16
+
17
+/// setting file containting a name of an output stream
18
+class OutStreamFile: public StreamFile
19
+{
20
+public:
21
+  /**
22
+   * @brief constructor from path
23
+   * @param[in] path path to file
24
+   * @param[in] streamMgr stream manager
25
+   */
26
+  OutStreamFile(const std::string &path, StreamMgr &streamMgr);
27
+
28
+  /**
29
+   * @brief constructor from basic file
30
+   * @param[in] file basic file object
31
+   * @param[in] streamMgr stream manager
32
+   */
33
+  OutStreamFile(const File &file, StreamMgr &streamMgr);
34
+
35
+  /// destructor
36
+  ~OutStreamFile();
37
+
38
+  /**
39
+   * @brief assignment operator
40
+   * @param[in] file basic file object
41
+   */
42
+  const OutStreamFile & operator=(const File &file);
43
+
44
+public:
45
+  /// update, i.e. (re-)read file and reference new stream
46
+  void update();
47
+
48
+  /**
49
+   * @brief set current frame
50
+   * @param[in] pFrame current frame (NULL for none)
51
+   */
52
+  void setFrame(stBlinkenFrame *pFrame);
53
+}; // class OutStreamFile
54
+
55
+} // namespace Blinker
56
+
57
+#endif // #ifndef OUTSTREAMFILE_H
58
+
... ...
@@ -13,8 +13,8 @@
13 13
 #include "Directory.h"
14 14
 #include "File.h"
15 15
 #include "Module.h"
16
+#include "OutStreamFile.h"
16 17
 #include "Player.h"
17
-#include "SettingFile.h"
18 18
 #include "StreamMgr.h"
19 19
 #include "Time.h"
20 20
 #include "TimeCallee.h"
... ...
@@ -30,16 +30,12 @@ namespace Blinker {
30 30
 Player::Player(CallMgr &callMgr, StreamMgr &streamMgr,
31 31
                const Directory &dirBase):
32 32
   Module(callMgr, streamMgr, dirBase),
33
-  m_fileOutStream(dirBase.getFile("outstream")),
33
+  m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
34 34
   m_dirPlaylist(dirBase.getSubdir("playlist")),
35
-  m_pOutStream(NULL),
36 35
   m_curValid(false),
37 36
   m_curEntry(m_playlist.begin()),
38 37
   m_curFrame(0)
39 38
 {
40
-  // get output stream
41
-  getOutStream();
42
-
43 39
   // load playlist
44 40
   updatePlaylistFull();
45 41
 }
... ...
@@ -55,9 +51,6 @@ Player::~Player()
55 51
     m_playlist.back().freeMovie();
56 52
     m_playlist.pop_back();
57 53
   }
58
-
59
-  // release output stream
60
-  releaseOutStream();
61 54
 }
62 55
 
63 56
 /// check for update of configuration
... ...
@@ -65,8 +58,8 @@ void Player::updateConfig()
65 58
 {
66 59
   // output stream name file was modified -> re-get output stream
67 60
   if (m_fileOutStream.checkModified()) {
68
-    releaseOutStream();
69
-    getOutStream();
61
+    m_fileOutStream.update();
62
+    sendFrame();
70 63
   }
71 64
 
72 65
   // playlist update (directory modified -> full, otherwise -> light)
... ...
@@ -194,31 +187,6 @@ void Player::updatePlaylistFull()
194 187
   }
195 188
 }
196 189
 
197
-/// get output stream
198
-void Player::getOutStream()
199
-{
200
-  // get name of output stream
201
-  m_fileOutStream.getStr(m_nameOutStream);
202
-
203
-  // get output stream
204
-  m_pOutStream = &m_streamMgr.refStream(m_nameOutStream);
205
-
206
-  // send current frame to stream
207
-  sendFrame();
208
-}
209
-
210
-/// release output stream
211
-void Player::releaseOutStream()
212
-{
213
-  // send no frame information
214
-  if (m_pOutStream)
215
-    m_pOutStream->setFrame(NULL);
216
-
217
-  // unreference output stream
218
-  m_pOutStream = NULL;
219
-  m_streamMgr.unrefStream(m_nameOutStream);
220
-}
221
-
222 190
 /// process current frame
223 191
 void Player::procFrame()
224 192
 {
... ...
@@ -267,17 +235,15 @@ void Player::procFrame()
267 235
 /// send current frame to output stream
268 236
 void Player::sendFrame()
269 237
 {
270
-  if (m_pOutStream) {
271 238
   // frame avalable -> send it
272 239
   if (m_curValid) {
273 240
     stBlinkenFrame *pFrame =
274 241
       BlinkenMovieGetFrame(m_curEntry->m_pMovie, m_curFrame);
275
-      m_pOutStream->setFrame(pFrame);
242
+    m_fileOutStream.setFrame(pFrame);
276 243
   }
277 244
   // no frame available -> send this information
278 245
   else
279
-      m_pOutStream->setFrame(NULL);
280
-  }
246
+    m_fileOutStream.setFrame(NULL);
281 247
 }
282 248
 
283 249
 /* #################
... ...
@@ -15,7 +15,7 @@
15 15
 #include "Directory.h"
16 16
 #include "File.h"
17 17
 #include "Module.h"
18
-#include "SettingFile.h"
18
+#include "OutStreamFile.h"
19 19
 #include "StreamMgr.h"
20 20
 #include "Time.h"
21 21
 #include "TimeCallee.h"
... ...
@@ -72,12 +72,6 @@ protected:
72 72
   /// full update of playlist, i.e. scan files in playlist directory
73 73
   void updatePlaylistFull();
74 74
 
75
-  /// get output stream
76
-  void getOutStream();
77
-
78
-  /// release output stream
79
-  void releaseOutStream();
80
-
81 75
   /// process current frame
82 76
   void procFrame();
83 77
 
... ...
@@ -85,10 +79,8 @@ protected:
85 79
   void sendFrame();
86 80
 
87 81
 protected:
88
-  SettingFile              m_fileOutStream; ///< output stream name file
82
+  OutStreamFile            m_fileOutStream; ///< output stream name file
89 83
   Directory                m_dirPlaylist;   ///< playlist directory
90
-  std::string              m_nameOutStream; ///< name of output stream
91
-  Stream                   *m_pOutStream;   ///< output stream
92 84
   Playlist                 m_playlist;      ///< current playlist
93 85
   bool                     m_curValid;      ///< if there is a current frame
94 86
   Playlist::const_iterator m_curEntry;      ///< current playlist entry
... ...
@@ -0,0 +1,20 @@
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 POSITIONFILE_H
7
+#define POSITIONFILE_H
8
+
9
+#include "Position.h"
10
+#include "SettingFile_impl.h"
11
+
12
+namespace Blinker {
13
+
14
+/// setting file containting a position in a frame
15
+typedef SettingFile<Position> PositionFile;
16
+
17
+} // namespace Blinker
18
+
19
+#endif // #ifndef POSITIONFILE_H
20
+
... ...
@@ -13,9 +13,9 @@
13 13
 #include "CallMgr.h"
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16
+#include "InStreamFile.h"
16 17
 #include "Module.h"
17 18
 #include "Printer.h"
18
-#include "SettingFile.h"
19 19
 #include "StreamMgr.h"
20 20
 #include "StreamRecv.h"
21 21
 
... ...
@@ -30,28 +30,25 @@ namespace Blinker {
30 30
 Printer::Printer(CallMgr &callMgr, StreamMgr &streamMgr,
31 31
                  const Directory &dirBase):
32 32
   Module(callMgr, streamMgr, dirBase),
33
-  m_fileInStream(dirBase.getFile("instream")),
34
-  m_pInStream(NULL)
33
+  m_fileInStream(dirBase.getFile("instream"), streamMgr)
35 34
 {
36
-  // get input stream and attach to it
37
-  getInStream();
35
+  // set up
36
+  m_fileInStream.setStreamRecv(this);
38 37
 }
39 38
 
40 39
 /// virtual destructor
41 40
 Printer::~Printer()
42 41
 {
43
-  // detach from input stream and release it
44
-  releaseInStream();
42
+  // clean up
43
+  m_fileInStream.setStreamRecv(NULL);
45 44
 }
46 45
 
47 46
 /// check for update of configuration
48 47
 void Printer::updateConfig()
49 48
 {
50 49
   // input stream name file was modified -> re-get input stream
51
-  if (m_fileInStream.checkModified()) {
52
-    releaseInStream();
53
-    getInStream();
54
-  }
50
+  if (m_fileInStream.checkModified())
51
+    m_fileInStream.update();
55 52
 }
56 53
 
57 54
 /**
... ...
@@ -73,29 +70,5 @@ void Printer::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
73 70
   (void)stream; // unused
74 71
 }
75 72
 
76
-/// get input stream and attach to it
77
-void Printer::getInStream()
78
-{
79
-  // get input stream
80
-  m_fileInStream.getStr(m_nameInStream);
81
-  m_pInStream = &m_streamMgr.refStream(m_nameInStream);
82
-
83
-  // attach to input stream
84
-  if (m_pInStream)
85
-    m_pInStream->attach(this);
86
-}
87
-
88
-/// detach from input stream and release it
89
-void Printer::releaseInStream()
90
-{
91
-  // detach from input stream
92
-  if (m_pInStream)
93
-    m_pInStream->detach(this);
94
-
95
-  // unreference stream
96
-  m_pInStream = NULL;
97
-  m_streamMgr.unrefStream(m_nameInStream);
98
-}
99
-
100 73
 } // namespace Blinker
101 74
 
... ...
@@ -13,8 +13,8 @@
13 13
 #include "CallMgr.h"
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16
+#include "InStreamFile.h"
16 17
 #include "Module.h"
17
-#include "SettingFile.h"
18 18
 #include "StreamMgr.h"
19 19
 #include "StreamRecv.h"
20 20
 
... ...
@@ -54,16 +54,7 @@ public:
54 54
   virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame);
55 55
 
56 56
 protected:
57
-  /// get input stream and attach to it
58
-  void getInStream();
59
-
60
-  /// detach from input stream and release it
61
-  void releaseInStream();
62
-
63
-protected:
64
-  SettingFile m_fileInStream; ///< input stream name file
65
-  std::string m_nameInStream; ///< name of input stream
66
-  Stream      *m_pInStream;   ///< input stream
57
+  InStreamFile m_fileInStream; ///< input stream name file
67 58
 }; // class Printer
68 59
 
69 60
 } // namespace Blinker
... ...
@@ -14,7 +14,7 @@
14 14
 #include "Module.h"
15 15
 #include "Priority.h"
16 16
 #include "PriorityInput.h"
17
-#include "SettingFile.h"
17
+#include "OutStreamFile.h"
18 18
 #include "StreamMgr.h"
19 19
 #include "StreamRecv.h"
20 20
 
... ...
@@ -26,23 +26,21 @@ namespace Blinker {
26 26
  * @param[in] streamMgr stream manager
27 27
  * @param[in] dirBase base directory
28 28
  */
29
-Priority::Priority(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase):
29
+Priority::Priority(CallMgr &callMgr, StreamMgr &streamMgr,
30
+                   const Directory &dirBase):
30 31
   Module(callMgr, streamMgr, dirBase),
31 32
   m_dirInputs(dirBase.getSubdir("inputs")),
32
-  m_fileOutStream(dirBase.getFile("outstream")),
33
-  m_itCurIn(m_inList.rend()),
34
-  m_pOutStream(NULL)
33
+  m_fileOutStream(dirBase.getFile("outstream"), streamMgr),
34
+  m_itCurIn(m_inList.rend())
35 35
 {
36 36
   // set up
37 37
   updateInListFull();
38
-  getOutStream();
39 38
 }
40 39
 
41 40
 /// virtual destructor
42 41
 Priority::~Priority()
43 42
 {
44 43
   // clean up
45
-  releaseOutStream();
46 44
   while (!m_inList.empty()) {
47 45
     delete m_inList.back().m_pInput;
48 46
     m_inList.pop_back();
... ...
@@ -59,10 +57,8 @@ void Priority::updateConfig()
59 57
     updateInListLight();
60 58
 
61 59
   // output stream name file was modified -> re-get output stream
62
-  if (m_fileOutStream.checkModified()) {
63
-    releaseOutStream();
64
-    getOutStream();
65
-  }
60
+  if (m_fileOutStream.checkModified())
61
+    m_fileOutStream.update();
66 62
 }
67 63
 
68 64
 /// light update of input list, i.e. check all entries in current input list
... ...
@@ -121,31 +117,6 @@ void Priority::updateInListFull()
121 117
   } // while itSubdir itIn
122 118
 }
123 119
 
124
-/// get output stream
125
-void Priority::getOutStream()
126
-{
127
-  // get name of output stream
128
-  m_fileOutStream.getStr(m_nameOutStream);
129
-
130
-  // get output stream
131
-  m_pOutStream = &m_streamMgr.refStream(m_nameOutStream);
132
-
133
-  // send current frame to stream
134
-  curFrame();
135
-}
136
-
137
-/// release output stream
138
-void Priority::releaseOutStream()
139
-{
140
-  // send no frame information
141
-  if (m_pOutStream)
142
-    m_pOutStream->setFrame(NULL);
143
-
144
-  // unreference output stream
145
-  m_pOutStream = NULL;
146
-  m_streamMgr.unrefStream(m_nameOutStream);
147
-}
148
-
149 120
 /**
150 121
  * @brief select specific input (called by inputs)
151 122
  * @param[in] input input to select
... ...
@@ -171,7 +142,7 @@ void Priority::selectLower()
171 142
     // check for frame
172 143
     if ((pFrame = m_itCurIn->m_pInput->getCurFrame())) {
173 144
       // frame found -> keep this input as current, send frame
174
-      frame(pFrame);
145
+      m_fileOutStream.setFrame(pFrame);
175 146
       return;
176 147
     }
177 148
     // try next input
... ...
@@ -179,7 +150,7 @@ void Priority::selectLower()
179 150
   }
180 151
 
181 152
   // no input has got a frame -> send no frame
182
-  frame(NULL);
153
+  m_fileOutStream.setFrame(NULL);
183 154
 }
184 155
 
185 156
 /// send current frame to output stream
... ...
@@ -190,20 +161,10 @@ void Priority::curFrame()
190 161
   // current input available and frame it it available -> send frame
191 162
   if (m_itCurIn != m_inList.rend() &&
192 163
       (pFrame = m_itCurIn->m_pInput->getCurFrame()))
193
-    frame(pFrame);
164
+    m_fileOutStream.setFrame(pFrame);
194 165
   // no frame available -> send this information
195 166
   else
196
-    frame(NULL);
197
-}
198
-
199
-/**
200
- * @brief set current frame (also called by inputs)
201
- * @param[in] pFrame new frame to use (NULL for none)
202
- */
203
-void Priority::frame(stBlinkenFrame *pFrame)
204
-{
205
-  if (m_pOutStream)
206
-    m_pOutStream->setFrame(pFrame);
167
+    m_fileOutStream.setFrame(NULL);
207 168
 }
208 169
 
209 170
 /* #####################
... ...
@@ -15,7 +15,7 @@
15 15
 #include "Directory.h"
16 16
 #include "File.h"
17 17
 #include "Module.h"
18
-#include "SettingFile.h"
18
+#include "OutStreamFile.h"
19 19
 #include "StreamMgr.h"
20 20
 
21 21
 namespace Blinker {
... ...
@@ -70,12 +70,6 @@ protected:
70 70
   /// full update of input list, i.e. scan subdirs in input list directory
71 71
   void updateInListFull();
72 72
 
73
-  /// get output stream
74
-  void getOutStream();
75
-
76
-  /// release output stream
77
-  void releaseOutStream();
78
-
79 73
   /**
80 74
    * @brief select specific input (called by inputs)
81 75
    * @param[in] input input to select
... ...
@@ -88,19 +82,11 @@ protected:
88 82
   /// send current frame to output stream
89 83
   void curFrame();
90 84
 
91
-  /**
92
-   * @brief set current frame (also called by inputs)
93
-   * @param[in] pFrame new frame to use (NULL for none)
94
-   */
95
-  void frame(stBlinkenFrame *pFrame);
96
-
97 85
 protected:
98 86
   Directory     m_dirInputs;      ///< input stream directory
99
-  SettingFile    m_fileOutStream;  ///< output stream name file
87
+  OutStreamFile m_fileOutStream;  ///< output stream name file
100 88
   InList        m_inList;         ///< current input list
101 89
   InListIt      m_itCurIn;        ///< current input
102
-  std::string    m_nameOutStream;  ///< name of output stream
103
-  Stream         *m_pOutStream;    ///< output stream
104 90
 }; // class Priority
105 91
 
106 92
 } // namespace Blinker
... ...
@@ -9,9 +9,9 @@
9 9
 
10 10
 #include "Directory.h"
11 11
 #include "File.h"
12
+#include "InStreamFile.h"
12 13
 #include "Priority.h"
13 14
 #include "PriorityInput.h"
14
-#include "SettingFile.h"
15 15
 #include "StreamMgr.h"
16 16
 #include "StreamRecv.h"
17 17
 
... ...
@@ -27,19 +27,18 @@ Priority::Input::Input(Priority &priority, const std::string &name,
27 27
                        const Directory &dirBase):
28 28
   m_priority(priority),
29 29
   m_name(name),
30
-  m_fileInStream(dirBase.getFile("instream")),
31
-  m_pInStream(NULL),
30
+  m_fileInStream(dirBase.getFile("instream"), priority.m_streamMgr),
32 31
   m_pFrame(NULL)
33 32
 {
34
-  // attach to input stream
35
-  getInStream();
33
+  // set up
34
+  m_fileInStream.setStreamRecv(this);
36 35
 }
37 36
 
38 37
 /// virtual destructor
39 38
 Priority::Input::~Input()
40 39
 {
41
-  // detach from input stream and release it
42
-  releaseInStream();
40
+  // clean up
41
+  m_fileInStream.setStreamRecv(NULL);
43 42
 }
44 43
 
45 44
 /// check for update of configuration
... ...
@@ -47,8 +46,8 @@ void Priority::Input::updateConfig()
47 46
 {
48 47
   // input stream name file was modified -> re-get input stream
49 48
   if (m_fileInStream.checkModified()) {
50
-    releaseInStream();
51
-    getInStream();
49
+    frame(NULL); // unset frame to force priority reevalulation
50
+    m_fileInStream.update();
52 51
   }
53 52
 }
54 53
 
... ...
@@ -72,35 +71,6 @@ stBlinkenFrame * Priority::Input::getCurFrame()
72 71
   return m_pFrame;
73 72
 }
74 73
 
75
-/// get input stream and attach to it
76
-void Priority::Input::getInStream()
77
-{
78
-  // get input stream
79
-  m_fileInStream.getStr(m_nameInStream);
80
-  m_pInStream = &m_priority.m_streamMgr.refStream(m_nameInStream);
81
-
82
-  // attach to input stream
83
-  if (m_pInStream)
84
-    m_pInStream->attach(this);
85
-
86
-  // processing of frame will happen automatically when stream sets frame
87
-}
88
-
89
-/// detach from input stream and release it
90
-void Priority::Input::releaseInStream()
91
-{
92
-  // set current frame to none
93
-  frame(NULL);
94
-
95
-  // detach from input stream
96
-  if (m_pInStream)
97
-    m_pInStream->detach(this);
98
-
99
-  // unreference stream
100
-  m_pInStream = NULL;
101
-  m_priority.m_streamMgr.unrefStream(m_nameInStream);
102
-}
103
-
104 74
 /**
105 75
  * @brief set current frame
106 76
  * @param[in] pFrame current frame (NULL for none)
... ...
@@ -117,7 +87,7 @@ void Priority::Input::frame(stBlinkenFrame *pFrame)
117 87
     if (m_priority.m_itCurIn != m_priority.m_inList.rend() &&
118 88
         m_priority.m_itCurIn->m_pInput == this)
119 89
       // pass on frame
120
-      m_priority.frame(pFrame);
90
+      m_priority.m_fileOutStream.setFrame(pFrame);
121 91
 
122 92
     // we have a higher priority than current input
123 93
     if (m_priority.m_itCurIn == m_priority.m_inList.rend() ||
... ...
@@ -11,8 +11,8 @@
11 11
 #include <BlinkenLib/BlinkenFrame.h>
12 12
 
13 13
 #include "File.h"
14
+#include "InStreamFile.h"
14 15
 #include "Priority.h"
15
-#include "SettingFile.h"
16 16
 #include "StreamMgr.h"
17 17
 #include "StreamRecv.h"
18 18
 
... ...
@@ -59,12 +59,6 @@ public:
59 59
   stBlinkenFrame * getCurFrame();
60 60
 
61 61
 protected:
62
-  /// get input stream and attach to it
63
-  void getInStream();
64
-
65
-  /// detach from input stream and release it
66
-  void releaseInStream();
67
-
68 62
   /**
69 63
    * @brief set current frame
70 64
    * @param[in] pFrame current frame (NULL for none)
... ...
@@ -74,9 +68,8 @@ protected:
74 68
 protected:
75 69
   Priority       &m_priority;    ///< owning priority based selector
76 70
   std::string    m_name;         ///< name of input (i.e. priority)
77
-  SettingFile    m_fileInStream; ///< input stream name file
71
+  InStreamFile   m_fileInStream; ///< input stream name file
78 72
   std::string    m_nameInStream; ///< name of input stream
79
-  Stream         *m_pInStream;   ///< input stream
80 73
   stBlinkenFrame *m_pFrame;      ///< current frame
81 74
 }; // class Priority::Input
82 75
 
... ...
@@ -0,0 +1,20 @@
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 PROTOCOLFILE_H
7
+#define PROTOCOLFILE_H
8
+
9
+#include "Protocol.h"
10
+#include "SettingFile_impl.h"
11
+
12
+namespace Blinker {
13
+
14
+/// setting file containting a Blinken protocol
15
+typedef SettingFile<Protocol> ProtocolFile;
16
+
17
+} // namespace Blinker
18
+
19
+#endif // #ifndef PROTOCOLFILE_H
20
+
... ...
@@ -13,9 +13,11 @@
13 13
 #include "Directory.h"
14 14
 #include "File.h"
15 15
 #include "Format.h"
16
+#include "FormatFile.h"
17
+#include "InStreamFile.h"
16 18
 #include "Module.h"
19
+#include "OutStreamFile.h"
17 20
 #include "Resizer.h"
18
-#include "SettingFile.h"
19 21
 #include "StreamMgr.h"
20 22
 #include "StreamRecv.h"
21 23
 
... ...
@@ -30,42 +32,32 @@ namespace Blinker {
30 32
 Resizer::Resizer(CallMgr &callMgr, StreamMgr &streamMgr,
31 33
                  const Directory &dirBase):
32 34
   Module(callMgr, streamMgr, dirBase),
33
-  m_fileInStream(dirBase.getFile("instream")),
35
+  m_fileInStream(dirBase.getFile("instream"), streamMgr),
34 36
   m_fileFormat(dirBase.getFile("format")),
35
-  m_fileOutStream(dirBase.getFile("outstream")),
36
-  m_pInStream(NULL),
37
-  m_haveFormat(false),
38
-  m_pOutStream(NULL)
37
+  m_fileOutStream(dirBase.getFile("outstream"), streamMgr)
39 38
 {
40 39
   // set up
41
-  getInStream();
42 40
   getFormat();
43
-  getOutStream();
41
+  m_fileInStream.setStreamRecv(this);
44 42
 }
45 43
 
46 44
 /// virtual destructor
47 45
 Resizer::~Resizer()
48 46
 {
49 47
   // clean up
50
-  releaseInStream();
51
-  releaseOutStream();
48
+  m_fileInStream.setStreamRecv(NULL);
52 49
 }
53 50
 
54 51
 /// check for update of configuration
55 52
 void Resizer::updateConfig()
56 53
 {
57 54
   // stream name or format file was modified -> re-get stream or format
58
-  if (m_fileInStream.checkModified()) {
59
-    releaseInStream();
60
-    getInStream();
61
-  }
62
-  if (m_fileFormat.checkModified()) {
55
+  if (m_fileInStream.checkModified())
56
+    m_fileInStream.update();
57
+  if (m_fileFormat.checkModified())
63 58
     getFormat();
64
-  }
65
-  if (m_fileOutStream.checkModified()) {
66
-    releaseOutStream();
67
-    getOutStream();
68
-  }
59
+  if (m_fileOutStream.checkModified())
60
+    m_fileOutStream.update();
69 61
 }
70 62
 
71 63
 /**
... ...
@@ -79,76 +71,21 @@ void Resizer::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
79 71
   (void)stream; // unused
80 72
 }
81 73
 
82
-/// get input stream and attach to it
83
-void Resizer::getInStream()
84
-{
85
-  // get input stream
86
-  m_fileInStream.getStr(m_nameInStream);
87
-  m_pInStream = &m_streamMgr.refStream(m_nameInStream);
88
-
89
-  // attach to input stream
90
-  if (m_pInStream)
91
-    m_pInStream->attach(this);
92
-}
93
-
94
-/// detach from input stream and release it
95
-void Resizer::releaseInStream()
96
-{
97
-  // detach from input stream
98
-  if (m_pInStream)
99
-    m_pInStream->detach(this);
100
-
101
-  // unreference stream
102
-  m_pInStream = NULL;
103
-  m_streamMgr.unrefStream(m_nameInStream);
104
-}
105
-
106 74
 /// (re-)get format to resize to
107 75
 void Resizer::getFormat()
108 76
 {
109
-  std::string strFormat;
110
-
111 77
   // read format from format file
112
-  m_haveFormat = m_fileFormat.getStr(strFormat) && m_format.fromStr(strFormat);
113
-
114
-  // send current frame to output stream
115
-  sendFrame();
116
-}
117
-
118
-/// get output stream
119
-void Resizer::getOutStream()
120
-{
121
-  // get output stream
122
-  m_fileOutStream.getStr(m_nameOutStream);
123
-  m_pOutStream = &m_streamMgr.refStream(m_nameOutStream);
78
+  m_fileFormat.update();
124 79
 
125 80
   // send current frame to output stream
126 81
   sendFrame();
127 82
 }
128 83
 
129
-/// release output stream
130
-void Resizer::releaseOutStream()
131
-{
132
-  // send no frame information
133
-  if (m_pOutStream)
134
-    m_pOutStream->setFrame(NULL);
135
-
136
-  // unreference stream
137
-  m_pOutStream = NULL;
138
-  m_streamMgr.unrefStream(m_nameOutStream);
139
-}
140
-
141 84
 /// send current frame to output stream
142 85
 void Resizer::sendFrame()
143 86
 {
144
-  stBlinkenFrame *pFrame;
145
-
146 87
   // get current frame from input stream and process it
147
-  if (m_pInStream)
148
-    pFrame = m_pInStream->getCurFrame();
149
-  else
150
-    pFrame = NULL;
151
-  procFrame(pFrame);
88
+  procFrame(m_fileInStream.getCurFrame());
152 89
 }
153 90
 
154 91
 /**
... ...
@@ -157,40 +94,40 @@ void Resizer::sendFrame()
157 94
  */
158 95
 void Resizer::procFrame(stBlinkenFrame *pFrame)
159 96
 {
97
+  int width, height, channels, maxval;
160 98
   stBlinkenFrame *pProcFrame;
161 99
 
162
-  // no output stream -> nothing to do
163
-  if (!m_pOutStream)
164
-    return;
165
-
166 100
   // no frame or no format -> pass "no frame"
167
-  if (!pFrame || !m_haveFormat) {
168
-    m_pOutStream->setFrame(NULL);
101
+  if (!pFrame || !m_fileFormat.m_valid) {
102
+    m_fileOutStream.setFrame(NULL);
169 103
     return;
170 104
   }
105
+  width = m_fileFormat.m_obj.m_width;
106
+  height = m_fileFormat.m_obj.m_height;
107
+  channels = m_fileFormat.m_obj.m_channels;
108
+  maxval = m_fileFormat.m_obj.m_maxval;
171 109
 
172 110
   // format matches -> pass frame directly
173
-  if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_format.m_width &&
174
-      (unsigned int)BlinkenFrameGetHeight(pFrame) == m_format.m_height &&
175
-      (unsigned int)BlinkenFrameGetChannels(pFrame) == m_format.m_channels &&
176
-      (unsigned int)BlinkenFrameGetMaxval(pFrame) == m_format.m_maxval) {
177
-    m_pOutStream->setFrame(pFrame);
111
+  if (BlinkenFrameGetWidth(pFrame) == width &&
112
+      BlinkenFrameGetHeight(pFrame) == height &&
113
+      BlinkenFrameGetChannels(pFrame) == channels &&
114
+      BlinkenFrameGetMaxval(pFrame) == maxval) {
115
+    m_fileOutStream.setFrame(NULL);
178 116
     return;
179 117
   }
180 118
 
181 119
   // clone frame
182 120
   pProcFrame = BlinkenFrameClone(pFrame);
183 121
   if (!pProcFrame){
184
-    m_pOutStream->setFrame(NULL);
122
+    m_fileOutStream.setFrame(NULL);
185 123
     return;
186 124
   }
187 125
 
188 126
   // resize frame
189
-  BlinkenFrameResize(pProcFrame, m_format.m_height, m_format.m_width,
190
-                                 m_format.m_channels, m_format.m_maxval);
127
+  BlinkenFrameResize(pProcFrame, height, width, channels, maxval);
191 128
 
192 129
   // pass process frame to output stream
193
-  m_pOutStream->setFrame(pProcFrame);
130
+  m_fileOutStream.setFrame(pProcFrame);
194 131
 
195 132
   // free cloned frame
196 133
   BlinkenFrameFree(pProcFrame);
... ...
@@ -14,8 +14,10 @@
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16 16
 #include "Format.h"
17
+#include "FormatFile.h"
18
+#include "InStreamFile.h"
17 19
 #include "Module.h"
18
-#include "SettingFile.h"
20
+#include "OutStreamFile.h"
19 21
 #include "StreamMgr.h"
20 22
 #include "StreamRecv.h"
21 23
 
... ...
@@ -55,21 +57,9 @@ public:
55 57
   virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame);
56 58
 
57 59
 protected:
58
-  /// get input stream and attach to it
59
-  void getInStream();
60
-
61
-  /// detach from input stream and release it
62
-  void releaseInStream();
63
-
64 60
   /// (re-)get format to resize to
65 61
   void getFormat();
66 62
 
67
-  /// get output stream
68
-  void getOutStream();
69
-
70
-  /// release output stream
71
-  void releaseOutStream();
72
-
73 63
   /// send current frame to output stream
74 64
   void sendFrame();
75 65
 
... ...
@@ -80,15 +70,9 @@ protected:
80 70
   void procFrame(stBlinkenFrame *pFrame);
81 71
 
82 72
 protected:
83
-  SettingFile m_fileInStream;  ///< input stream name file
84
-  SettingFile m_fileFormat;    ///< format file
85
-  SettingFile m_fileOutStream; ///< output stream name file
86
-  std::string m_nameInStream;  ///< name of input stream
87
-  Stream      *m_pInStream;    ///< input stream
88
-  bool        m_haveFormat;    ///< if the format to resize to is available
89
-  Format      m_format;        ///< format to resize to
90
-  std::string m_nameOutStream; ///< name of output stream
91
-  Stream      *m_pOutStream;   ///< output stream
73
+  InStreamFile  m_fileInStream;  ///< input stream name file
74
+  FormatFile    m_fileFormat;    ///< format file
75
+  OutStreamFile m_fileOutStream; ///< output stream name file
92 76
 }; // class Resizer
93 77
 
94 78
 } // namespace Blinker
... ...
@@ -12,9 +12,10 @@
12 12
 #include "CallMgr.h"
13 13
 #include "Directory.h"
14 14
 #include "File.h"
15
+#include "InStreamFile.h"
15 16
 #include "Module.h"
17
+#include "OutStreamFile.h"
16 18
 #include "Scaler.h"
17
-#include "SettingFile.h"
18 19
 #include "Size.h"
19 20
 #include "StreamMgr.h"
20 21
 #include "StreamRecv.h"
... ...
@@ -30,42 +31,32 @@ namespace Blinker {
30 31
 Scaler::Scaler(CallMgr &callMgr, StreamMgr &streamMgr,
31 32
                  const Directory &dirBase):
32 33
   Module(callMgr, streamMgr, dirBase),
33
-  m_fileInStream(dirBase.getFile("instream")),
34
+  m_fileInStream(dirBase.getFile("instream"), streamMgr),
34 35
   m_fileSize(dirBase.getFile("size")),
35
-  m_fileOutStream(dirBase.getFile("outstream")),
36
-  m_pInStream(NULL),
37
-  m_haveSize(false),
38
-  m_pOutStream(NULL)
36
+  m_fileOutStream(dirBase.getFile("outstream"), streamMgr)
39 37
 {
40 38
   // set up
41
-  getInStream();
42 39
   getSize();
43
-  getOutStream();
40
+  m_fileInStream.setStreamRecv(this);
44 41
 }
45 42
 
46 43
 /// virtual destructor
47 44
 Scaler::~Scaler()
48 45
 {
49 46
   // clean up
50
-  releaseInStream();
51
-  releaseOutStream();
47
+  m_fileInStream.setStreamRecv(NULL);
52 48
 }
53 49
 
54 50
 /// check for update of configuration
55 51
 void Scaler::updateConfig()
56 52
 {
57 53
   // stream name or size file was modified -> re-get stream or size
58
-  if (m_fileInStream.checkModified()) {
59
-    releaseInStream();
60
-    getInStream();
61
-  }
62
-  if (m_fileSize.checkModified()) {
54
+  if (m_fileInStream.checkModified())
55
+    m_fileInStream.update();
56
+  if (m_fileSize.checkModified())
63 57
     getSize();
64
-  }
65
-  if (m_fileOutStream.checkModified()) {
66
-    releaseOutStream();
67
-    getOutStream();
68
-  }
58
+  if (m_fileOutStream.checkModified())
59
+    m_fileOutStream.update();
69 60
 }
70 61
 
71 62
 /**
... ...
@@ -79,76 +70,21 @@ void Scaler::setFrame(const std::string &stream, stBlinkenFrame *pFrame)
79 70
   (void)stream; // unused
80 71
 }
81 72
 
82
-/// get input stream and attach to it
83
-void Scaler::getInStream()
84
-{
85
-  // get input stream
86
-  m_fileInStream.getStr(m_nameInStream);
87
-  m_pInStream = &m_streamMgr.refStream(m_nameInStream);
88
-
89
-  // attach to input stream
90
-  if (m_pInStream)
91
-    m_pInStream->attach(this);
92
-}
93
-
94
-/// detach from input stream and release it
95
-void Scaler::releaseInStream()
96
-{
97
-  // detach from input stream
98
-  if (m_pInStream)
99
-    m_pInStream->detach(this);
100
-
101
-  // unreference stream
102
-  m_pInStream = NULL;
103
-  m_streamMgr.unrefStream(m_nameInStream);
104
-}
105
-
106 73
 /// (re-)get size to scale to
107 74
 void Scaler::getSize()
108 75
 {
109
-  std::string strSize;
110
-
111 76
   // read size from size file
112
-  m_haveSize = m_fileSize.getStr(strSize) && m_size.fromStr(strSize);
113
-
114
-  // send current frame to output stream
115
-  sendFrame();
116
-}
117
-
118
-/// get output stream
119
-void Scaler::getOutStream()
120
-{
121
-  // get output stream
122
-  m_fileOutStream.getStr(m_nameOutStream);
123
-  m_pOutStream = &m_streamMgr.refStream(m_nameOutStream);
77
+  m_fileSize.update();
124 78
 
125 79
   // send current frame to output stream
126 80
   sendFrame();
127 81
 }
128 82
 
129
-/// release output stream
130
-void Scaler::releaseOutStream()
131
-{
132
-  // send no frame information
133
-  if (m_pOutStream)
134
-    m_pOutStream->setFrame(NULL);
135
-
136
-  // unreference stream
137
-  m_pOutStream = NULL;
138
-  m_streamMgr.unrefStream(m_nameOutStream);
139
-}
140
-
141 83
 /// send current frame to output stream
142 84
 void Scaler::sendFrame()
143 85
 {
144
-  stBlinkenFrame *pFrame;
145
-
146 86
   // get current frame from input stream and process it
147
-  if (m_pInStream)
148
-    pFrame = m_pInStream->getCurFrame();
149
-  else
150
-    pFrame = NULL;
151
-  procFrame(pFrame);
87
+  procFrame(m_fileInStream.getCurFrame());
152 88
 }
153 89
 
154 90
 /**
... ...
@@ -157,37 +93,36 @@ void Scaler::sendFrame()
157 93
  */
158 94
 void Scaler::procFrame(stBlinkenFrame *pFrame)
159 95
 {
96
+  int width, height;
160 97
   stBlinkenFrame *pProcFrame;
161 98
 
162
-  // no output stream -> nothing to do
163
-  if (!m_pOutStream)
164
-    return;
165
-
166 99
   // no frame or no size -> pass "no frame"
167
-  if (!pFrame || !m_haveSize) {
168
-    m_pOutStream->setFrame(NULL);
100
+  if (!pFrame || !m_fileSize.m_valid) {
101
+    m_fileOutStream.setFrame(NULL);
169 102
     return;
170 103
   }
104
+  width = m_fileSize.m_obj.m_width;
105
+  height = m_fileSize.m_obj.m_height;
171 106
 
172 107
   // size matches -> pass frame directly
173
-  if ((unsigned int)BlinkenFrameGetWidth(pFrame) == m_size.m_width &&
174
-      (unsigned int)BlinkenFrameGetHeight(pFrame) == m_size.m_height) {
175
-    m_pOutStream->setFrame(pFrame);
108
+  if (BlinkenFrameGetWidth(pFrame) == width &&
109
+      BlinkenFrameGetHeight(pFrame) == height ) {
110
+    m_fileOutStream.setFrame(pFrame);
176 111
     return;
177 112
   }
178 113
 
179 114
   // clone frame
180 115
   pProcFrame = BlinkenFrameClone(pFrame);
181 116
   if (!pProcFrame) {
182
-    m_pOutStream->setFrame(NULL);
117
+    m_fileOutStream.setFrame(NULL);
183 118
     return;
184 119
   }
185 120
 
186 121
   // scale frame
187
-  BlinkenFrameScale(pProcFrame, m_size.m_height, m_size.m_width);
122
+  BlinkenFrameScale(pProcFrame, height, width);
188 123
 
189 124
   // pass process frame to output stream
190
-  m_pOutStream->setFrame(pProcFrame);
125
+  m_fileOutStream.setFrame(pProcFrame);
191 126
 
192 127
   // free cloned frame
193 128
   BlinkenFrameFree(pProcFrame);
... ...
@@ -13,9 +13,11 @@
13 13
 #include "CallMgr.h"
14 14
 #include "Directory.h"
15 15
 #include "File.h"
16
+#include "InStreamFile.h"
16 17
 #include "Module.h"
17
-#include "SettingFile.h"
18
+#include "OutStreamFile.h"
18 19
 #include "Size.h"
20
+#include "SizeFile.h"
19 21
 #include "StreamMgr.h"
20 22
 #include "StreamRecv.h"
21 23
 
... ...
@@ -55,21 +57,9 @@ public:
55 57
   virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame);
56 58
 
57 59
 protected:
58
-  /// get input stream and attach to it
59
-  void getInStream();
60
-
61
-  /// detach from input stream and release it
62
-  void releaseInStream();
63
-
64 60
   /// (re-)get size to scale to
65 61
   void getSize();
66 62
 
67
-  /// get output stream
68
-  void getOutStream();
69
-
70
-  /// release output stream
71
-  void releaseOutStream();
72
-
73 63
   /// send current frame to output stream
74 64
   void sendFrame();
75 65
 
... ...
@@ -80,15 +70,9 @@ protected:
80 70
   void procFrame(stBlinkenFrame *pFrame);
81 71
 
82 72
 protected:
83
-  SettingFile m_fileInStream;  ///< input stream name file
84
-  SettingFile m_fileSize;      ///< size file
85
-  SettingFile m_fileOutStream; ///< output stream name file
86
-  std::string m_nameInStream;  ///< name of input stream
87
-  Stream      *m_pInStream;    ///< input stream
88
-  bool        m_haveSize;      ///< if the size to scale to is available
89
-  Size        m_size;          ///< size to scale to
90
-  std::string m_nameOutStream; ///< name of output stream
91
-  Stream      *m_pOutStream;   ///< output stream
73
+  InStreamFile  m_fileInStream;  ///< input stream name file
74
+  SizeFile      m_fileSize;      ///< size file
75
+  OutStreamFile m_fileOutStream; ///< output stream name file
92 76
 }; // class Scaler
93 77
 
94 78
 } // namespace Blinker
... ...
@@ -16,9 +16,11 @@
16 16
 #include "CallMgr.h"
17 17
 #include "Directory.h"
18 18
 #include "File.h"
19
+#include "InStreamFile.h"
19 20
 #include "IoCallee.h"
20 21
 #include "Module.h"
21 22
 #include "Protocol.h"
23
+#include "ProtocolFile.h"
22 24
 #include "SettingFile.h"
23 25
 #include "StreamMgr.h"
24 26
 #include "StreamRecv.h"
... ...
@@ -33,6 +35,9 @@ class Sender: public IoCallee, public Module, public StreamRecv,
33 35
               public TimeCallee
34 36
 {
35 37
 protected:
38
+  /// type for address setting file
39
+  typedef SettingFile<ADDR> AddrFile;
40
+
36 41
   /// static destination
37 42
   class Dest;
38 43
 
... ...
@@ -98,12 +103,6 @@ protected:
98 103
   /// (re-)read protocol
99 104
   void readProto();
100 105
 
101
-  /// get input stream and attach to it
102
-  void getInStream();
103
-
104
-  /// detach from input stream and release it
105
-  void releaseInStream();
106
-
107 106
   /// create socket and bind it
108 107
   void createSock();
109 108
 
... ...
@@ -155,15 +154,11 @@ protected:
155 154
   void receiveFromSock();
156 155
 
157 156
 protected:
158
-  SettingFile m_fileInStream; ///< input stream name file
159
-  SettingFile m_fileBind;     ///< bind address file
160
-  SettingFile m_fileProtocol; ///< protocol file
157
+  InStreamFile m_fileInStream; ///< input stream name file
158
+  AddrFile     m_fileBind;     ///< bind address file
159
+  ProtocolFile m_fileProtocol; ///< protocol file
161 160
   Directory    m_dirDests;     ///< static destinations directory
162
-  std::string m_nameInStream; ///< name of input stream
163
-  Stream      *m_pInStream;   ///< input stream
164 161
   SOCK         *m_pSock;       ///< socket to use for sending streams
165
-  Protocol    m_protocol;     ///< protocol
166
-  bool        m_haveProtocol; ///< if protocol is known
167 162
   DestList     m_destList;     ///< static destinations
168 163
   DynDests     m_dynDests;     ///< dynamic destinations
169 164
   std::string  m_noFrameData;  ///< "no frame" protocol data (empty if unknown)
... ...
@@ -63,9 +63,7 @@ protected:
63 63
 
64 64
 protected:
65 65
   Sender            &m_sender;       ///< owning sender object
66
-  SettingFile       m_fileAddr;      ///< address file
67
-  ADDR              m_addr;          ///< address
68
-  bool              m_haveAddr;      ///< if address is available
66
+  AddrFile          m_fileAddr;      ///< address file
69 67
   const std::string *m_pNoFrameData; ///< protocol data for "no frame" packet
70 68
   const std::string *m_pData;        ///< protocol data to send to address
71 69
 }; // class Sender<ADDr, SOCK>::Dest
... ...
@@ -29,7 +29,6 @@ Sender<ADDR, SOCK>::Dest::Dest(Sender &sender, const Directory &dirBase,
29 29
                                const std::string *pNoFrameData):
30 30
   m_sender(sender),
31 31
   m_fileAddr(dirBase.getFile("addr")),
32
-  m_haveAddr(false),
33 32
   m_pNoFrameData(pNoFrameData),
34 33
   m_pData(pNoFrameData)
35 34
 {
... ...
@@ -77,8 +76,8 @@ void Sender<ADDR, SOCK>::Dest::getAddr()
77 76
   // send "no frame" protocol data to old address
78 77
   send(m_pNoFrameData);
79 78
 
80
-  // parse new address from file
81
-  m_haveAddr = m_fileAddr.getStr(strAddr) && m_addr.fromStr(strAddr);
79
+  // get new address from file
80
+  m_fileAddr.update();
82 81
 
83 82
   // send current protocol data to new address
84 83
   send(m_pData);
... ...
@@ -91,8 +90,8 @@ void Sender<ADDR, SOCK>::Dest::getAddr()
91 90
 template<typename ADDR, typename SOCK>
92 91
 void Sender<ADDR, SOCK>::Dest::send(const std::string *pData)
93 92
 {
94
-  if (m_sender.m_pSock && m_haveAddr && !pData->empty())
95
-    m_sender.m_pSock->send(*pData, m_addr);
93
+  if (m_sender.m_pSock && m_fileAddr.m_valid && !pData->empty())
94
+    m_sender.m_pSock->send(*pData, m_fileAddr.m_obj);
96 95
 }
97 96
 
98 97
 } // namespace Blinker
... ...
@@ -16,9 +16,11 @@
16 16
 #include "CallMgr.h"
17 17
 #include "Directory.h"
18 18
 #include "File.h"
19
+#include "InStreamFile.h"
19 20
 #include "IoCallee.h"
20 21
 #include "Module.h"
21 22
 #include "Protocol.h"
23
+#include "ProtocolFile.h"
22 24
 #include "Sender.h"
23 25
 #include "SenderDest.h"
24 26
 #include "SenderDest_impl.h"
... ...
@@ -40,19 +42,17 @@ template<typename ADDR, typename SOCK>
40 42
 Sender<ADDR, SOCK>::Sender(CallMgr &callMgr, StreamMgr &streamMgr,
41 43
                            const Directory &dirBase):
42 44
   Module(callMgr, streamMgr, dirBase),
43
-  m_fileInStream(dirBase.getFile("instream")),
45
+  m_fileInStream(dirBase.getFile("instream"), streamMgr),
44 46
   m_fileBind(dirBase.getFile("bind")),
45 47
   m_fileProtocol(dirBase.getFile("protocol")),
46 48
   m_dirDests(dirBase.getSubdir("destinations")),
47
-  m_pInStream(NULL),
48
-  m_pSock(NULL),
49
-  m_haveProtocol(false)
49
+  m_pSock(NULL)
50 50
 {
51 51
   // read protocol
52 52
   readProto();
53 53
 
54
-  // get input stream and attach to it
55
-  getInStream();
54
+  // attac to input stream
55
+  m_fileInStream.setStreamRecv(this);
56 56
   // create and bind socket
57 57
   createSock();
58 58
 
... ...
@@ -75,8 +75,8 @@ Sender<ADDR, SOCK>::~Sender()
75 75
 
76 76
   // destroy socket
77 77
   destroySock();
78
-  // detach from input stream and release it
79
-  releaseInStream();
78
+  // detach from input stream
79
+  m_fileInStream.setStreamRecv(NULL);
80 80
   // cancel time callback
81 81
   m_callMgr.cancelTimeCall(this);
82 82
 }
... ...
@@ -86,10 +86,8 @@ template<typename ADDR, typename SOCK>
86 86
 void Sender<ADDR, SOCK>::updateConfig()
87 87
 {
88 88
   // input stream name file was modified -> re-get input stream
89
-  if (m_fileInStream.checkModified()) {
90
-    releaseInStream();
91
-    getInStream();
92
-  }
89
+  if (m_fileInStream.checkModified())
90
+    m_fileInStream.update();
93 91
 
94 92
   // bind address file was modified -> re-create socket
95 93
   if (m_fileBind.checkModified()) {
... ...
@@ -161,8 +159,6 @@ void Sender<ADDR, SOCK>::ioWriteCall(Io *io)
161 159
 template<typename ADDR, typename SOCK>
162 160
 void Sender<ADDR, SOCK>::readProto()
163 161
 {
164
-  std::string strProto;
165
-
166 162
   // send "no frame" to all destinations
167 163
   // (stream with old protocol will stop now)
168 164
   sendAllNoFrame();
... ...
@@ -176,55 +172,20 @@ void Sender<ADDR, SOCK>::readProto()
176 172
   m_data.clear();
177 173
 
178 174
   // read new protocol from file
179
-  m_haveProtocol = m_fileProtocol.getStr(strProto) &&
180
-                   m_protocol.fromStr(strProto);
175
+  m_fileProtocol.update();
181 176
 
182 177
   // create new no frame protocol data and new protocol data
183
-  if (m_haveProtocol) {
184 178
   frame2data(NULL, m_noFrameData);
185
-    if (m_pInStream)
186
-      frame2data(m_pInStream->getCurFrame(), m_data);
187
-    else
188
-      frame2data(NULL, m_data);
189
-  }
179
+  frame2data(m_fileInStream.getCurFrame(), m_data);
190 180
 
191 181
   // send current protocol data to all destinations
192 182
   sendAllProto();
193 183
 }
194 184
 
195
-/// get input stream and attach to it
196
-template<typename ADDR, typename SOCK>
197
-void Sender<ADDR, SOCK>::getInStream()
198
-{
199
-  // get input stream
200
-  m_fileInStream.getStr(m_nameInStream);
201
-  m_pInStream = &m_streamMgr.refStream(m_nameInStream);
202
-
203
-  // attach to input stream
204
-  if (m_pInStream)
205
-    m_pInStream->attach(this);
206
-}
207
-
208
-/// detach from input stream and release it
209
-template<typename ADDR, typename SOCK>
210
-void Sender<ADDR, SOCK>::releaseInStream()
211
-{
212
-  // detach from input stream
213
-  if (m_pInStream)
214
-    m_pInStream->detach(this);
215
-
216
-  // unreference stream
217
-  m_pInStream = NULL;
218
-  m_streamMgr.unrefStream(m_nameInStream);
219
-}
220
-
221 185
 /// create socket and bind it
222 186
 template<typename ADDR, typename SOCK>
223 187
 void Sender<ADDR, SOCK>::createSock()
224 188
 {
225
-  std::string strAddr;
226
-  ADDR addr;
227
-
228 189
   // create socket
229 190
   if (!m_pSock) {
230 191
     m_pSock = new SOCK();
... ...
@@ -233,14 +194,15 @@ void Sender<ADDR, SOCK>::createSock()
233 194
   }
234 195
 
235 196
   // get bind address from bind address setting file
236
-  if (!m_fileBind.getStr(strAddr) || !addr.fromStr(strAddr)) {
197
+  m_fileBind.update();
198
+  if (!m_fileBind.m_valid) {
237 199
     delete m_pSock;
238 200
     m_pSock = NULL;
239 201
     return;
240 202
   }
241 203
 
242 204
   // bind socket
243
-  if (!m_pSock->bind(addr)) {
205
+  if (!m_pSock->bind(m_fileBind.m_obj)) {
244 206
     delete m_pSock;
245 207
     m_pSock = NULL;
246 208
     return;
... ...
@@ -424,20 +386,22 @@ template<typename ADDR, typename SOCK>
424 386
 void Sender<ADDR, SOCK>::frame2data(stBlinkenFrame *pFrame,
425 387
                                     std::string &data) const
426 388
 {
389
+  etBlinkenProto proto;
427 390
   char buf[65536];
428 391
   int len;
429 392
 
430 393
   // no protocol -> leave with empty data
431
-  if (!m_haveProtocol) {
394
+  if (!m_fileProtocol.m_valid) {
432 395
     data.clear();
433 396
     return;
434 397
   }
398
+  proto = m_fileProtocol.m_obj.m_proto;
435 399
 
436 400
   // convert frame to protcol data
437 401
   if (pFrame)
438
-    len = BlinkenFrameToNetwork(pFrame, m_protocol.m_proto, buf, sizeof(buf));
402
+    len = BlinkenFrameToNetwork(pFrame, proto, buf, sizeof(buf));
439 403
   else
440
-    len = BlinkenProtoMakePacket(m_protocol.m_proto, BlinkenPacketStreamEnd,
404
+    len = BlinkenProtoMakePacket(proto, BlinkenPacketStreamEnd,
441 405
                                  buf, sizeof(buf));
442 406
   if (len < 0)
443 407
     len = 0;
... ...
@@ -464,7 +428,7 @@ void Sender<ADDR, SOCK>::receiveFromSock()
464 428
   // detect packet type and protocol
465 429
   BlinkenProtoDetectPacket(data.c_str(), data.size(), &proto, &packet);
466 430
 
467
-  if (m_haveProtocol && proto == m_protocol.m_proto) {
431
+  if (m_fileProtocol.m_valid && proto == m_fileProtocol.m_obj.m_proto) {
468 432
     switch (packet) {
469 433
 
470 434
       // request -> add to dynamic destinations and send current frame
... ...
@@ -482,7 +446,7 @@ void Sender<ADDR, SOCK>::receiveFromSock()
482 446
         break;
483 447
 
484 448
     } // switch (packet)
485
-  } // if (m_haveProtocol ...
449
+  } // if (m_fileProtocol.m_valid ...
486 450
 
487 451
 }
488 452
 
... ...
@@ -13,6 +13,7 @@
13 13
 namespace Blinker {
14 14
 
15 15
 /// file containting a single setting
16
+template<typename TYPE>
16 17
 class SettingFile: public File
17 18
 {
18 19
 public:
... ...
@@ -35,13 +36,20 @@ public:
35 36
   const SettingFile & operator=(const File &file);
36 37
 
37 38
 public:
39
+  /// update, i.e. (re-)read file
40
+  void update();
41
+
42
+protected:
38 43
   /**
39 44
    * @brief get setting as string
40 45
    * @param[out] val setting read from file
41
-   * @param[in] def default setting (to return on error)
42 46
    * @return if setting was successfully read from file
43 47
    */
44
-  bool getStr(std::string& val, const std::string& def = "") const;
48
+  bool getStr(std::string& val) const;
49
+
50
+public:
51
+  TYPE m_obj;   ///< setting object read from file
52
+  bool m_valid; ///< if setting object could be read and parsed
45 53
 }; // class SettingFile
46 54
 
47 55
 } // namespace Blinker
... ...
@@ -3,6 +3,9 @@
3 3
    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
    a blinkenarea.org project */
5 5
 
6
+#ifndef SETTINGFILE_IMPL_H
7
+#define SETTINGFILE_IMPL_H
8
+
6 9
 #include <fstream>
7 10
 #include <string>
8 11
 
... ...
@@ -15,50 +18,60 @@ namespace Blinker {
15 18
  * @brief constructor from path
16 19
  * @param[in] path path to file
17 20
  */
18
-SettingFile::SettingFile(const std::string &path):
21
+template<typename TYPE>
22
+SettingFile<TYPE>::SettingFile(const std::string &path):
19 23
   File(path)
20 24
 {
25
+  update();
21 26
 }
22 27
 
23 28
 /**
24 29
  * @brief constructor from basic file
25 30
  * @param[in] file basic file object
26 31
  */
27
-SettingFile::SettingFile(const File &file):
32
+template<typename TYPE>
33
+SettingFile<TYPE>::SettingFile(const File &file):
28 34
   File(file)
29 35
 {
36
+  update();
30 37
 }
31 38
 
32 39
 /**
33 40
  * @brief assignment operator
34 41
  * @param[in] file basic file object
35 42
  */
36
-const SettingFile & SettingFile::operator=(const File &file)
43
+template<typename TYPE>
44
+const SettingFile<TYPE> & SettingFile<TYPE>::operator=(const File &file)
37 45
 {
38 46
   File::operator=(file);
47
+  update();
39 48
   return *this;
40 49
 }
41 50
 
51
+/// update, i.e. (re-)read file
52
+template<typename TYPE>
53
+void SettingFile<TYPE>::update()
54
+{
55
+  std::string strSize;
56
+
57
+  m_valid = getStr(strSize) && m_obj.fromStr(strSize);
58
+}
59
+
42 60
 /**
43 61
  * @brief get setting as string
44 62
  * @param[out] val setting read from file
45
- * @param[in] def default setting (to return on error)
46 63
  * @return if setting was successfully read from file
47 64
  */
48
-bool SettingFile::getStr(std::string &val,
49
-                         const std::string &def /*= ""*/) const
65
+template<typename TYPE>
66
+bool SettingFile<TYPE>::getStr(std::string &val) const
50 67
 {
51 68
   std::ifstream ifstrm(m_path.c_str(), std::ios::in);
52
-  if (!ifstrm.is_open()) {
53
-    val = def;
69
+  if (!ifstrm.is_open())
54 70
     return false;
55
-  }
56 71
 
57 72
   std::getline(ifstrm, val);
58
-  if (ifstrm.fail()) {
59
-    val = def;
73
+  if (ifstrm.fail())
60 74
     return false;
61
-  }
62 75
 
63 76
   ifstrm.close();
64 77
 
... ...
@@ -67,3 +80,5 @@ bool SettingFile::getStr(std::string &val,
67 80
 
68 81
 } // namespace Blinker
69 82
 
83
+#endif // #ifndef SETTINGFILE_IMPL_H
84
+
... ...
@@ -0,0 +1,20 @@
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 SIZEFILE_H
7
+#define SIZEFILE_H
8
+
9
+#include "SettingFile_impl.h"
10
+#include "Size.h"
11
+
12
+namespace Blinker {
13
+
14
+/// setting file containting frame size
15
+typedef SettingFile<Size> SizeFile;
16
+
17
+} // namespace Blinker
18
+
19
+#endif // #ifndef SIZEFILE_H
20
+
... ...
@@ -0,0 +1,83 @@
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
+#include "File.h"
7
+#include "NameFile.h"
8
+#include "Stream.h"
9
+#include "StreamFile.h"
10
+#include "StreamMgr.h"
11
+
12
+namespace Blinker {
13
+
14
+/**
15
+ * @brief constructor from path
16
+ * @param[in] path path to file
17
+ * @param[in] streamMgr stream manager
18
+ */
19
+StreamFile::StreamFile(const std::string &path, StreamMgr &streamMgr):
20
+  NameFile(path),
21
+  m_streamMgr(streamMgr),
22
+  m_pStream(NULL)
23
+{
24
+  update();
25
+}
26
+
27
+/**
28
+ * @brief constructor from basic file
29
+ * @param[in] file basic file object
30
+ * @param[in] streamMgr stream manager
31
+ */
32
+StreamFile::StreamFile(const File &file, StreamMgr &streamMgr):
33
+  NameFile(file),
34
+  m_streamMgr(streamMgr),
35
+  m_pStream(NULL)
36
+{
37
+  update();
38
+}
39
+
40
+/// destructor
41
+StreamFile::~StreamFile()
42
+{
43
+  unref();
44
+}
45
+
46
+/**
47
+ * @brief assignment operator
48
+ * @param[in] file basic file object
49
+ */
50
+const StreamFile & StreamFile::operator=(const File &file)
51
+{
52
+  unref();
53
+  NameFile::operator=(file);
54
+  ref();
55
+  return *this;
56
+}
57
+
58
+/// update, i.e. (re-)read file and reference new stream
59
+void StreamFile::update()
60
+{
61
+  unref();
62
+  NameFile::update();
63
+  ref();
64
+}
65
+
66
+/// unreference stream
67
+void StreamFile::unref()
68
+{
69
+  if (m_pStream) {
70
+    m_streamMgr.unrefStream(m_obj.m_str);
71
+    m_pStream = NULL;
72
+  }
73
+}
74
+
75
+/// reference stream
76
+void StreamFile::ref()
77
+{
78
+  if (m_valid)
79
+    m_pStream = &m_streamMgr.refStream(m_obj.m_str);
80
+}
81
+
82
+} // namespace Blinker
83
+
... ...
@@ -0,0 +1,62 @@
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 STREAMFILE_H
7
+#define STREAMFILE_H
8
+
9
+#include "File.h"
10
+#include "NameFile.h"
11
+#include "Stream.h"
12
+#include "StreamMgr.h"
13
+
14
+namespace Blinker {
15
+
16
+/// setting file containting a name of a stream
17
+class StreamFile: public NameFile
18
+{
19
+public:
20
+  /**
21
+   * @brief constructor from path
22
+   * @param[in] path path to file
23
+   * @param[in] streamMgr stream manager
24
+   */
25
+  StreamFile(const std::string &path, StreamMgr &streamMgr);
26
+
27
+  /**
28
+   * @brief constructor from basic file
29
+   * @param[in] file basic file object
30
+   * @param[in] streamMgr stream manager
31
+   */
32
+  StreamFile(const File &file, StreamMgr &streamMgr);
33
+
34
+  /// destructor
35
+  ~StreamFile();
36
+
37
+  /**
38
+   * @brief assignment operator
39
+   * @param[in] file basic file object
40
+   */
41
+  const StreamFile & operator=(const File &file);
42
+
43
+public:
44
+  /// update, i.e. (re-)read file and reference new stream
45
+  void update();
46
+
47
+protected:
48
+  /// unreference stream
49
+  void unref();
50
+
51
+  /// reference stream
52
+  void ref();
53
+
54
+protected:
55
+  StreamMgr &m_streamMgr; ///< stream manager
56
+  Stream    *m_pStream;   ///< stream
57
+}; // class StreamFile
58
+
59
+} // namespace Blinker
60
+
61
+#endif // #ifndef STREAMFILE_H
62
+
0 63