Stefan Schuermans commited on 2011-12-23 13:54:52
Showing 6 changed files, with 130 additions and 1 deletions.
| ... | ... |
@@ -30,6 +30,13 @@ |
| 30 | 30 |
<code>sound</code>. |
| 31 | 31 |
If this file does not exists, no sound is requested to be played. |
| 32 | 32 |
</p> |
| 33 |
+ <h3>Maximum Number of Connections</h3> |
|
| 34 |
+ <p> |
|
| 35 |
+ The maximum number of simultaneous connections can be limited |
|
| 36 |
+ by writing the limit to the file <code>maxconn</code>. |
|
| 37 |
+ If this file does not exists, the number of simultaneous connections |
|
| 38 |
+ is not limited. |
|
| 39 |
+ </p> |
|
| 33 | 40 |
<h3>Extensions / Phone Numbers</h3> |
| 34 | 41 |
<p> |
| 35 | 42 |
The virtual extensions (i.e. phone numbers) that can be called |
| ... | ... |
@@ -21,6 +21,7 @@ |
| 21 | 21 |
#include "SettingFile.h" |
| 22 | 22 |
#include "Time.h" |
| 23 | 23 |
#include "TimeCallee.h" |
| 24 |
+#include "UIntFile.h" |
|
| 24 | 25 |
|
| 25 | 26 |
namespace Blinker {
|
| 26 | 27 |
|
| ... | ... |
@@ -34,6 +35,7 @@ OpSplitter::OpSplitter(const std::string &name, Mgrs &mgrs, |
| 34 | 35 |
const Directory &dirBase): |
| 35 | 36 |
Module(name, mgrs, dirBase), |
| 36 | 37 |
m_fileSound(dirBase.getFile("sound")),
|
| 38 |
+ m_fileMaxConn(dirBase.getFile("maxconn")),
|
|
| 37 | 39 |
m_extListTracker(*this, dirBase.getSubdir("extensions"))
|
| 38 | 40 |
{
|
| 39 | 41 |
// load extensions |
| ... | ... |
@@ -80,6 +82,10 @@ void OpSplitter::updateConfig() |
| 80 | 82 |
if (m_fileSound.checkModified()) |
| 81 | 83 |
m_fileSound.update(); |
| 82 | 84 |
|
| 85 |
+ // max. number of conn. file was modified -> re-read max. number of conn. |
|
| 86 |
+ if (m_fileMaxConn.checkModified()) |
|
| 87 |
+ m_fileMaxConn.update(); |
|
| 88 |
+ |
|
| 83 | 89 |
// extensions update |
| 84 | 90 |
m_extListTracker.updateConfig(); |
| 85 | 91 |
} |
| ... | ... |
@@ -105,7 +111,11 @@ void OpSplitter::timeCall() |
| 105 | 111 |
*/ |
| 106 | 112 |
bool OpSplitter::acceptNewOpConn(const std::string &name) |
| 107 | 113 |
{
|
| 108 |
- return true; // TODO |
|
| 114 |
+ // if maximum number of connections if limited, check it |
|
| 115 |
+ if (m_fileMaxConn.m_valid && |
|
| 116 |
+ m_mapLocal.size() + m_mapInOut.size() >= m_fileMaxConn.m_obj.m_uint) |
|
| 117 |
+ return false; // too many connection |
|
| 118 |
+ return true; |
|
| 109 | 119 |
(void)name; // unused |
| 110 | 120 |
} |
| 111 | 121 |
|
| ... | ... |
@@ -21,6 +21,7 @@ |
| 21 | 21 |
#include "SettingFile.h" |
| 22 | 22 |
#include "Time.h" |
| 23 | 23 |
#include "TimeCallee.h" |
| 24 |
+#include "UIntFile.h" |
|
| 24 | 25 |
|
| 25 | 26 |
namespace Blinker {
|
| 26 | 27 |
|
| ... | ... |
@@ -152,6 +153,7 @@ protected: |
| 152 | 153 |
|
| 153 | 154 |
protected: |
| 154 | 155 |
NameFile m_fileSound; ///< file containing sound name |
| 156 |
+ UIntFile m_fileMaxConn; ///< file containing max. number of conn. |
|
| 155 | 157 |
ExtListTracker m_extListTracker; ///< extension tracker |
| 156 | 158 |
ExtMap m_extMap; ///< map of extensions to call |
| 157 | 159 |
MapLocal m_mapLocal; ///< localy handled connections |
| ... | ... |
@@ -0,0 +1,49 @@ |
| 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 <sstream> |
|
| 7 |
+#include <string> |
|
| 8 |
+ |
|
| 9 |
+#include "UInt.h" |
|
| 10 |
+#include "StringParser.h" |
|
| 11 |
+ |
|
| 12 |
+namespace Blinker {
|
|
| 13 |
+ |
|
| 14 |
+/// constructor |
|
| 15 |
+UInt::UInt(): |
|
| 16 |
+ m_uint(0) |
|
| 17 |
+{
|
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+/** |
|
| 21 |
+ * @brief parse from string format |
|
| 22 |
+ * @param[in] str string format |
|
| 23 |
+ * @return if parsing was successful |
|
| 24 |
+ */ |
|
| 25 |
+bool UInt::fromStr(const std::string &str) |
|
| 26 |
+{
|
|
| 27 |
+ StringParser parser(str); |
|
| 28 |
+ unsigned int uint; |
|
| 29 |
+ |
|
| 30 |
+ if (!parser.uintNo(uint) || |
|
| 31 |
+ !parser.isDone()) |
|
| 32 |
+ return false; |
|
| 33 |
+ m_uint = uint; |
|
| 34 |
+ return true; |
|
| 35 |
+} |
|
| 36 |
+ |
|
| 37 |
+/** |
|
| 38 |
+ * @brief convert to string format |
|
| 39 |
+ * @return string format |
|
| 40 |
+ */ |
|
| 41 |
+std::string UInt::toStr() const |
|
| 42 |
+{
|
|
| 43 |
+ std::stringstream strm; |
|
| 44 |
+ strm << m_uint; |
|
| 45 |
+ return strm.str(); |
|
| 46 |
+} |
|
| 47 |
+ |
|
| 48 |
+} // namespace Blinker |
|
| 49 |
+ |
| ... | ... |
@@ -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 BLINKER_UINT_H |
|
| 7 |
+#define BLINKER_UINT_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+namespace Blinker {
|
|
| 12 |
+ |
|
| 13 |
+/// an unsigned integer |
|
| 14 |
+class UInt |
|
| 15 |
+{
|
|
| 16 |
+public: |
|
| 17 |
+ /// constructor |
|
| 18 |
+ UInt(); |
|
| 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 |
+ unsigned int m_uint; ///< unsigned int number |
|
| 36 |
+}; // class UInt |
|
| 37 |
+ |
|
| 38 |
+} // namespace Blinker |
|
| 39 |
+ |
|
| 40 |
+#endif // #ifndef BLINKER_UINT_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 BLINKER_UINTFILE_H |
|
| 7 |
+#define BLINKER_UINTFILE_H |
|
| 8 |
+ |
|
| 9 |
+#include "SettingFile_impl.h" |
|
| 10 |
+#include "UInt.h" |
|
| 11 |
+ |
|
| 12 |
+namespace Blinker {
|
|
| 13 |
+ |
|
| 14 |
+/// setting file containting unsigned integer |
|
| 15 |
+typedef SettingFile<UInt> UIntFile; |
|
| 16 |
+ |
|
| 17 |
+} // namespace Blinker |
|
| 18 |
+ |
|
| 19 |
+#endif // #ifndef BLINKER_UINTFILE_H |
|
| 20 |
+ |
|
| 0 | 21 |