implement passing on only a part of the name in a sync information
Stefan Schuermans

Stefan Schuermans commited on 2018-09-30 17:32:40
Showing 11 changed files, with 227 additions and 2 deletions.

... ...
@@ -110,6 +110,7 @@
110 110
         <li><a href="ratelimiter.html">Rate Limiter</a></li>
111 111
         <li><a href="resizer.html">Resizer</a></li>
112 112
         <li><a href="scaler.html">Scaler</a></li>
113
+        <li><a href="syncnamesplitter.html">Synchronization Name Splitter</a></li>
113 114
         <li><a href="syncprinter.html">Synchronization Printer</a></li>
114 115
         <li><a href="transformer.html">Transformer</a></li>
115 116
         <li><a href="udp4phone.html">UDP4 Phone Connector</a></li>
... ...
@@ -0,0 +1,49 @@
1
+<html>
2
+  <head>
3
+    <title>Blinker - Synchornization Name Splitter</title>
4
+  </head>
5
+  <body>
6
+    <h1>Blinker - Synchronization Name Splitter</h1>
7
+    <p>
8
+      The synchronization name splitter module is able to extract a part of
9
+      name in a synchronization information and pass on a copy this information
10
+      with a extracted part as a name.
11
+    </p>
12
+    <h2>Configuration</h2>
13
+    <p>
14
+      The configuration of the synchronization name splitter module with name
15
+      <code>NAME</code> is located in the <code>synchnamesplitters/NAME</code>
16
+      subdirectory.
17
+    </p>
18
+    <h3>Input Synchronization Stream</h3>
19
+    <p>
20
+      The synchronization name splitter receives synchronization information
21
+      from the synchronization stream whose name is written to the file
22
+      <code>insync</code>.
23
+    </p>
24
+    <h3>Delimiter</h3>
25
+    <p>
26
+      The string read from the file <code>delimiter</code> is used for
27
+      splitting the name in the incoming synchornization information into
28
+      multiple parts.
29
+      If this file does not exists, the name is passed on unmodified.
30
+    </p>
31
+    <h3>Filed Number</h3>
32
+    <p>
33
+      The unsigned integer read from the file <code>fieldno</code> selects
34
+      which part of the split name from the incoming synchornization
35
+      information is used in the outgoing synchronization information.
36
+      The value <code>0<code> select the leftmost part.
37
+      If this file does not exists, the name is passed on unmodified.
38
+    </p>
39
+    <h3>Output Synchronization Stream</h3>
40
+    <p>
41
+      The file <code>outsync</code> contains the name of the synchronization
42
+      stream to write the modified synchronization information to.
43
+      This synchronization information has the same pause mode and time stamp
44
+      as the incoming synchronizations, but the name is replaced with a part
45
+      of the original name.
46
+    </p>
47
+  </body>
48
+</html>
49
+
... ...
@@ -1 +1 @@
1
-syncfilt
1
+syncfilt_off
... ...
@@ -0,0 +1,104 @@
1
+/* Blinker
2
+   Copyright 2011-2018 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 "File.h"
9
+#include "InSyncFile.h"
10
+#include "Mgrs.h"
11
+#include "Module.h"
12
+#include "OutSyncFile.h"
13
+#include "SyncNameSplitter.h"
14
+#include "SyncRecv.h"
15
+
16
+namespace Blinker {
17
+
18
+/**
19
+ * @brief constructor
20
+ * @param[in] name module name
21
+ * @param[in] mgrs managers
22
+ * @param[in] dirBase base directory
23
+ */
24
+SyncNameSplitter::SyncNameSplitter(const std::string &name, Mgrs &mgrs, const Directory &dirBase):
25
+  Module(name, mgrs, dirBase),
26
+  m_fileInSync(dirBase.getFile("insync"), mgrs.m_syncMgr),
27
+  m_fileDelimiter(dirBase.getFile("delimiter")),
28
+  m_fileFieldNo(dirBase.getFile("fieldno")),
29
+  m_fileOutSync(dirBase.getFile("outsync"), mgrs.m_syncMgr)
30
+{
31
+  // init
32
+  m_fileInSync.setSyncRecv(this);
33
+}
34
+
35
+/// virtual destructor
36
+SyncNameSplitter::~SyncNameSplitter()
37
+{
38
+  // cleanup
39
+  m_fileInSync.setSyncRecv(NULL);
40
+}
41
+
42
+/// check for update of configuration
43
+void SyncNameSplitter::updateConfig()
44
+{
45
+  // input sync stream name file was modified -> re-get input sync stream
46
+  if (m_fileInSync.checkModified())
47
+    m_fileInSync.update();
48
+
49
+  // delimiter file was modified -> re-get delimiter
50
+  if (m_fileDelimiter.checkModified())
51
+    m_fileDelimiter.update();
52
+
53
+  // filed number file was modified -> re-get filed number
54
+  if (m_fileFieldNo.checkModified())
55
+    m_fileFieldNo.update();
56
+
57
+  // output sync stream name file was modified -> re-get output sync stream
58
+  if (m_fileOutSync.checkModified())
59
+    m_fileOutSync.update();
60
+}
61
+
62
+/**
63
+ * @brief send synchronization information
64
+ * @param[in] sync sync stream name
65
+ * @param[in] pInfo synchronization information
66
+ */
67
+void SyncNameSplitter::sendInfo(const std::string &sync, Info &info)
68
+{
69
+
70
+  // pass on unmodified sync information if delimiter or field number invalid
71
+  if (! m_fileDelimiter.m_valid || ! m_fileFieldNo.m_valid) {
72
+    m_fileOutSync.sendInfo(info);
73
+    return;
74
+  }
75
+
76
+  // split name
77
+  const std::string &delim = m_fileDelimiter.m_obj.m_str;
78
+  unsigned int fieldNo = m_fileFieldNo.m_obj.m_uint;
79
+  std::string::size_type pos = 0;
80
+  unsigned int field = 0;
81
+  std::string splitname;
82
+  while (pos < info.name.length()) {
83
+    std::string::size_type found = info.name.find(delim, pos);
84
+    if (found == std::string::npos) {
85
+      found = info.name.length();
86
+    }
87
+    if (field == fieldNo) {
88
+      splitname = info.name.substr(pos, found - pos);
89
+      break;
90
+    }
91
+    pos = found + delim.length();
92
+    ++field;
93
+  }
94
+
95
+  // pass on sync information with split name
96
+  Info splitinfo = info;
97
+  splitinfo.name = splitname;
98
+  m_fileOutSync.sendInfo(splitinfo);
99
+
100
+  (void)sync; // unused
101
+}
102
+
103
+} // namespace Blinker
104
+
... ...
@@ -0,0 +1,65 @@
1
+/* Blinker
2
+   Copyright 2011-2018 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 BLINKER_SYNCNAMESPLITTER_H
7
+#define BLINKER_SYNCNAMESPLITTER_H
8
+
9
+#include <string>
10
+
11
+#include "File.h"
12
+#include "InSyncFile.h"
13
+#include "Mgrs.h"
14
+#include "Module.h"
15
+#include "NameFile.h"
16
+#include "OutSyncFile.h"
17
+#include "SyncRecv.h"
18
+#include "UIntFile.h"
19
+
20
+namespace Blinker {
21
+
22
+/// a synchronization name splitter
23
+class SyncNameSplitter: public Module, public SyncRecv
24
+{
25
+public:
26
+  /**
27
+   * @brief constructor
28
+   * @param[in] name module name
29
+   * @param[in] mgrs managers
30
+   * @param[in] dirBase base directory
31
+   */
32
+  SyncNameSplitter(const std::string &name, Mgrs &mgrs, const Directory &dirBase);
33
+
34
+  /// virtual destructor
35
+  virtual ~SyncNameSplitter();
36
+
37
+private:
38
+  /// copy constructor disabled
39
+  SyncNameSplitter(const SyncNameSplitter &that);
40
+
41
+  /// assignment operator disabled
42
+  const SyncNameSplitter & operator=(const SyncNameSplitter &that);
43
+
44
+public:
45
+  /// check for update of configuration
46
+  virtual void updateConfig();
47
+
48
+  /**
49
+   * @brief send synchronization information
50
+   * @param[in] sync sync stream name
51
+   * @param[in] pInfo synchronization information
52
+   */
53
+  virtual void sendInfo(const std::string &sync, Info &info);
54
+
55
+protected:
56
+  InSyncFile  m_fileInSync;    ///< input sync stream
57
+  NameFile    m_fileDelimiter; ///< delimiter string for splitting
58
+  UIntFile    m_fileFieldNo;   ///< number of field from name to pass on
59
+  OutSyncFile m_fileOutSync;   ///< output sync stream name file
60
+}; // class SyncNameSplitter
61
+
62
+} // namespace Blinker
63
+
64
+#endif // #ifndef BLINKER_SYNCNAMESPLITTER_H
65
+
... ...
@@ -24,6 +24,7 @@
24 24
 #include "RateLimiter.h"
25 25
 #include "Resizer.h"
26 26
 #include "Scaler.h"
27
+#include "SyncNameSplitter.h"
27 28
 #include "SyncPrinter.h"
28 29
 #include "Transformer.h"
29 30
 #include "Udp4Phone.h"
... ...
@@ -59,6 +60,7 @@ void run(const std::string &dirConfig)
59 60
   MODULEMGR(Resizer,          resizers);
60 61
   MODULEMGR(RateLimiter,      ratelimiters);
61 62
   MODULEMGR(Scaler,           scalers);
63
+  MODULEMGR(SyncNameSplitter, syncnamesplitters);
62 64
   MODULEMGR(SyncPrinter,      syncprinters);
63 65
   MODULEMGR(Transformer,      transformers);
64 66
   MODULEMGR(Udp4Phone,        udp4phones);
65 67