Stefan Schuermans commited on 2011-12-22 12:48:03
Showing 9 changed files, with 396 additions and 0 deletions.
| ... | ... |
@@ -7,6 +7,7 @@ |
| 7 | 7 |
#define BLINKER_MGRS_H |
| 8 | 8 |
|
| 9 | 9 |
#include "CallMgr.h" |
| 10 |
+#include "OpMgr.h" |
|
| 10 | 11 |
#include "StreamMgr.h" |
| 11 | 12 |
|
| 12 | 13 |
namespace Blinker {
|
| ... | ... |
@@ -15,6 +16,7 @@ namespace Blinker {
|
| 15 | 16 |
struct Mgrs |
| 16 | 17 |
{
|
| 17 | 18 |
CallMgr m_callMgr; ///< call manager |
| 19 |
+ OpMgr m_opMgr; ///< operator connection manager |
|
| 18 | 20 |
StreamMgr m_streamMgr; ///< stream manager |
| 19 | 21 |
}; // struct Mgrs |
| 20 | 22 |
|
| ... | ... |
@@ -0,0 +1,53 @@ |
| 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 "OpConn.h" |
|
| 9 |
+#include "OpConnIf.h" |
|
| 10 |
+ |
|
| 11 |
+namespace Blinker {
|
|
| 12 |
+ |
|
| 13 |
+/** |
|
| 14 |
+ * @brief constructor |
|
| 15 |
+ * @param[in] pConnIf connection interface of this side |
|
| 16 |
+ */ |
|
| 17 |
+OpConn::OpConn(OpConnIf *pConnIf): |
|
| 18 |
+ m_pConnIf(pConnIf), |
|
| 19 |
+ m_pRemote(NULL) |
|
| 20 |
+{
|
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+/// destructor |
|
| 24 |
+OpConn::~OpConn() |
|
| 25 |
+{
|
|
| 26 |
+ // think twice before putting something here |
|
| 27 |
+ // might be explicitly deconstructed by remote side |
|
| 28 |
+} |
|
| 29 |
+ |
|
| 30 |
+/// close connection |
|
| 31 |
+void OpConn::close() |
|
| 32 |
+{
|
|
| 33 |
+ // inform remote side |
|
| 34 |
+ if (m_pRemote) |
|
| 35 |
+ m_pRemote->m_pConnIf->opConnClose(m_pRemote); |
|
| 36 |
+ |
|
| 37 |
+ // destroy local and remote connection objects |
|
| 38 |
+ if (m_pRemote) |
|
| 39 |
+ delete m_pRemote; |
|
| 40 |
+ delete this; |
|
| 41 |
+} |
|
| 42 |
+ |
|
| 43 |
+/** |
|
| 44 |
+ * @brief set remote side of connection |
|
| 45 |
+ * @param[in] pRemote remote side connection object |
|
| 46 |
+ */ |
|
| 47 |
+void OpConn::setRemote(OpConn *pRemote) |
|
| 48 |
+{
|
|
| 49 |
+ m_pRemote = pRemote; |
|
| 50 |
+} |
|
| 51 |
+ |
|
| 52 |
+} // namespace Blinker |
|
| 53 |
+ |
| ... | ... |
@@ -0,0 +1,57 @@ |
| 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_OPCONN_H |
|
| 7 |
+#define BLINKER_OPCONN_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+#include "OpConnIf.h" |
|
| 12 |
+ |
|
| 13 |
+namespace Blinker {
|
|
| 14 |
+ |
|
| 15 |
+/// operator connection |
|
| 16 |
+class OpConn |
|
| 17 |
+{
|
|
| 18 |
+protected: |
|
| 19 |
+ /** |
|
| 20 |
+ * @brief constructor |
|
| 21 |
+ * @param[in] pConnIf connection interface of this side |
|
| 22 |
+ */ |
|
| 23 |
+ OpConn(OpConnIf *pConnIf); |
|
| 24 |
+ |
|
| 25 |
+public: |
|
| 26 |
+ /// destructor |
|
| 27 |
+ ~OpConn(); |
|
| 28 |
+ |
|
| 29 |
+private: |
|
| 30 |
+ /// copy constructor disabled |
|
| 31 |
+ OpConn(const OpConn &that); |
|
| 32 |
+ |
|
| 33 |
+ /// assignment operator disabled |
|
| 34 |
+ const OpConn & operator=(const OpConn &that); |
|
| 35 |
+ |
|
| 36 |
+public: |
|
| 37 |
+ /// close connection |
|
| 38 |
+ void close(); |
|
| 39 |
+ |
|
| 40 |
+protected: |
|
| 41 |
+ /** |
|
| 42 |
+ * @brief set remote side of connection |
|
| 43 |
+ * @param[in] pRemote remote side connection object |
|
| 44 |
+ */ |
|
| 45 |
+ void setRemote(OpConn *pRemote); |
|
| 46 |
+ |
|
| 47 |
+protected: |
|
| 48 |
+ OpConnIf *m_pConnIf; ///< connection interface of this side |
|
| 49 |
+ OpConn *m_pRemote; ///< remote side connection object |
|
| 50 |
+ |
|
| 51 |
+ friend class OpMgr; |
|
| 52 |
+}; // class OpConn |
|
| 53 |
+ |
|
| 54 |
+} // namespace Blinker |
|
| 55 |
+ |
|
| 56 |
+#endif // #ifndef BLINKER_OPCONN_H |
|
| 57 |
+ |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 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 "OpConn.h" |
|
| 9 |
+ |
|
| 10 |
+namespace Blinker {
|
|
| 11 |
+ |
|
| 12 |
+/// constructor |
|
| 13 |
+OpConnIf::OpConnIf() |
|
| 14 |
+{
|
|
| 15 |
+} |
|
| 16 |
+ |
|
| 17 |
+/// virtual destructor |
|
| 18 |
+OpConnIf::~OpConnIf() |
|
| 19 |
+{
|
|
| 20 |
+} |
|
| 21 |
+ |
|
| 22 |
+} // namespace Blinker |
|
| 23 |
+ |
| ... | ... |
@@ -0,0 +1,36 @@ |
| 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_OPCONNIF_H |
|
| 7 |
+#define BLINKER_OPCONNIF_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+namespace Blinker {
|
|
| 12 |
+ |
|
| 13 |
+class OpConn; |
|
| 14 |
+ |
|
| 15 |
+/// operator connection interface |
|
| 16 |
+class OpConnIf |
|
| 17 |
+{
|
|
| 18 |
+public: |
|
| 19 |
+ /// constructor |
|
| 20 |
+ OpConnIf(); |
|
| 21 |
+ |
|
| 22 |
+ /// virtual destructor |
|
| 23 |
+ virtual ~OpConnIf(); |
|
| 24 |
+ |
|
| 25 |
+public: |
|
| 26 |
+ /** |
|
| 27 |
+ * @brief operator connection is closed |
|
| 28 |
+ * @param[in] pConn operator connection object |
|
| 29 |
+ */ |
|
| 30 |
+ virtual void opConnClose(OpConn *pConn) = 0; |
|
| 31 |
+}; // class OpConnIf |
|
| 32 |
+ |
|
| 33 |
+} // namespace Blinker |
|
| 34 |
+ |
|
| 35 |
+#endif // #ifndef BLINKER_OPCONNIF_H |
|
| 36 |
+ |
| ... | ... |
@@ -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 <map> |
|
| 7 |
+#include <string> |
|
| 8 |
+ |
|
| 9 |
+#include "OpConn.h" |
|
| 10 |
+#include "OpConnIf.h" |
|
| 11 |
+#include "OpMgr.h" |
|
| 12 |
+#include "OpReqIf.h" |
|
| 13 |
+ |
|
| 14 |
+namespace Blinker {
|
|
| 15 |
+ |
|
| 16 |
+/// constructor |
|
| 17 |
+OpMgr::OpMgr() |
|
| 18 |
+{
|
|
| 19 |
+} |
|
| 20 |
+ |
|
| 21 |
+/// destructor |
|
| 22 |
+OpMgr::~OpMgr() |
|
| 23 |
+{
|
|
| 24 |
+} |
|
| 25 |
+ |
|
| 26 |
+/** |
|
| 27 |
+ * @brief open operator interface |
|
| 28 |
+ * @param[in] name operator interface name |
|
| 29 |
+ * @param[in] pOpReqIf interface to call on incoming operator request |
|
| 30 |
+ * @return if operator interface could be opened |
|
| 31 |
+ */ |
|
| 32 |
+bool OpMgr::open(const std::string &name, OpReqIf *pOpReqIf) |
|
| 33 |
+{
|
|
| 34 |
+ if (m_reqIfs.find(name) != m_reqIfs.end()) |
|
| 35 |
+ return false; // already open |
|
| 36 |
+ m_reqIfs[name] = pOpReqIf; |
|
| 37 |
+ return true; |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+/** |
|
| 41 |
+ * @brief close operator interface |
|
| 42 |
+ * @param[in] name operator interface name |
|
| 43 |
+ * @return if interface name was open before |
|
| 44 |
+ */ |
|
| 45 |
+bool OpMgr::close(const std::string &name) |
|
| 46 |
+{
|
|
| 47 |
+ ReqIfMap::iterator itReqIf = m_reqIfs.find(name); |
|
| 48 |
+ if (itReqIf == m_reqIfs.end()) |
|
| 49 |
+ return false; // was not open |
|
| 50 |
+ m_reqIfs.erase(itReqIf); |
|
| 51 |
+ return true; |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+/** |
|
| 55 |
+ * @brief connect to operator interface |
|
| 56 |
+ * @param[in] name operator interface to connect to |
|
| 57 |
+ * @param[in] pOpConnIf interface to call on connection events |
|
| 58 |
+ * @return operator connection object (or NULL on error) |
|
| 59 |
+ */ |
|
| 60 |
+OpConn * OpMgr::connect(const std::string &name, OpConnIf *pOpConnIf) |
|
| 61 |
+{
|
|
| 62 |
+ // find requested interface |
|
| 63 |
+ ReqIfMap::iterator itReqIf = m_reqIfs.find(name); |
|
| 64 |
+ if (itReqIf == m_reqIfs.end()) |
|
| 65 |
+ return NULL; // not open |
|
| 66 |
+ |
|
| 67 |
+ // check with server side if new connection is accepted |
|
| 68 |
+ if (!itReqIf->second->acceptNewOpConn(name)) |
|
| 69 |
+ return NULL; // not accepted |
|
| 70 |
+ |
|
| 71 |
+ // create new connection |
|
| 72 |
+ OpConn *pConnCli = new OpConn(pOpConnIf); |
|
| 73 |
+ OpConn *pConnSrv = new OpConn(itReqIf->second); |
|
| 74 |
+ pConnCli->setRemote(pConnSrv); |
|
| 75 |
+ pConnSrv->setRemote(pConnCli); |
|
| 76 |
+ |
|
| 77 |
+ // deliver new connection |
|
| 78 |
+ itReqIf->second->newOpConn(name, pConnSrv); |
|
| 79 |
+ return pConnCli; |
|
| 80 |
+} |
|
| 81 |
+ |
|
| 82 |
+} // namespace Blinker |
|
| 83 |
+ |
| ... | ... |
@@ -0,0 +1,71 @@ |
| 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_OPMGR_H |
|
| 7 |
+#define BLINKER_OPMGR_H |
|
| 8 |
+ |
|
| 9 |
+#include <map> |
|
| 10 |
+#include <string> |
|
| 11 |
+ |
|
| 12 |
+#include "OpConn.h" |
|
| 13 |
+#include "OpConnIf.h" |
|
| 14 |
+#include "OpReqIf.h" |
|
| 15 |
+ |
|
| 16 |
+namespace Blinker {
|
|
| 17 |
+ |
|
| 18 |
+/// operator connection manager |
|
| 19 |
+class OpMgr |
|
| 20 |
+{
|
|
| 21 |
+protected: |
|
| 22 |
+ /// map of open operator interfaces |
|
| 23 |
+ typedef std::map<std::string, OpReqIf *> ReqIfMap; |
|
| 24 |
+ |
|
| 25 |
+public: |
|
| 26 |
+ /// constructor |
|
| 27 |
+ OpMgr(); |
|
| 28 |
+ |
|
| 29 |
+ /// destructor |
|
| 30 |
+ ~OpMgr(); |
|
| 31 |
+ |
|
| 32 |
+private: |
|
| 33 |
+ /// copy constructor disabled |
|
| 34 |
+ OpMgr(const OpMgr &that); |
|
| 35 |
+ |
|
| 36 |
+ /// assignment operator disabled |
|
| 37 |
+ const OpMgr & operator=(const OpMgr &that); |
|
| 38 |
+ |
|
| 39 |
+public: |
|
| 40 |
+ /** |
|
| 41 |
+ * @brief open operator interface |
|
| 42 |
+ * @param[in] name operator interface name |
|
| 43 |
+ * @param[in] pOpReqIf interface to call on incoming operator request |
|
| 44 |
+ * @return if operator interface could be opened |
|
| 45 |
+ */ |
|
| 46 |
+ bool open(const std::string &name, OpReqIf *pOpReqIf); |
|
| 47 |
+ |
|
| 48 |
+ /** |
|
| 49 |
+ * @brief close operator interface |
|
| 50 |
+ * @param[in] name operator interface name |
|
| 51 |
+ * @return if interface name was open before |
|
| 52 |
+ */ |
|
| 53 |
+ bool close(const std::string &name); |
|
| 54 |
+ |
|
| 55 |
+ /** |
|
| 56 |
+ * @brief connect to operator interface |
|
| 57 |
+ * @param[in] name operator interface to connect to |
|
| 58 |
+ * @param[in] pOpConnIf interface to call on connection events |
|
| 59 |
+ * @return operator connection object (or NULL on error) |
|
| 60 |
+ */ |
|
| 61 |
+ OpConn * connect(const std::string &name, OpConnIf *pOpConnIf); |
|
| 62 |
+ |
|
| 63 |
+protected: |
|
| 64 |
+ /// map of open operator interfaces |
|
| 65 |
+ ReqIfMap m_reqIfs; |
|
| 66 |
+}; // class OpMgr |
|
| 67 |
+ |
|
| 68 |
+} // namespace Blinker |
|
| 69 |
+ |
|
| 70 |
+#endif // #ifndef BLINKER_OPMGR_H |
|
| 71 |
+ |
| ... | ... |
@@ -0,0 +1,25 @@ |
| 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 "OpConn.h" |
|
| 9 |
+#include "OpConnIf.h" |
|
| 10 |
+#include "OpReqIf.h" |
|
| 11 |
+ |
|
| 12 |
+namespace Blinker {
|
|
| 13 |
+ |
|
| 14 |
+/// constructor |
|
| 15 |
+OpReqIf::OpReqIf() |
|
| 16 |
+{
|
|
| 17 |
+} |
|
| 18 |
+ |
|
| 19 |
+/// virtual destructor |
|
| 20 |
+OpReqIf::~OpReqIf() |
|
| 21 |
+{
|
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+} // namespace Blinker |
|
| 25 |
+ |
| ... | ... |
@@ -0,0 +1,46 @@ |
| 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_OPREQIF_H |
|
| 7 |
+#define BLINKER_OPREQIF_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+#include "OpConnIf.h" |
|
| 12 |
+ |
|
| 13 |
+namespace Blinker {
|
|
| 14 |
+ |
|
| 15 |
+class OpConn; |
|
| 16 |
+ |
|
| 17 |
+/// operator connection request interface |
|
| 18 |
+class OpReqIf: public OpConnIf |
|
| 19 |
+{
|
|
| 20 |
+public: |
|
| 21 |
+ /// constructor |
|
| 22 |
+ OpReqIf(); |
|
| 23 |
+ |
|
| 24 |
+ /// virtual destructor |
|
| 25 |
+ virtual ~OpReqIf(); |
|
| 26 |
+ |
|
| 27 |
+public: |
|
| 28 |
+ /** |
|
| 29 |
+ * @brief check if accepting new operator connction is possible |
|
| 30 |
+ * @param[in] name operator interface name |
|
| 31 |
+ * @return if accepting new connection is possible |
|
| 32 |
+ */ |
|
| 33 |
+ virtual bool acceptNewOpConn(const std::string &name) = 0; |
|
| 34 |
+ |
|
| 35 |
+ /** |
|
| 36 |
+ * @brief new operator connection |
|
| 37 |
+ * @param[in] name operator interface name |
|
| 38 |
+ * @param[in] pConn operator connection object |
|
| 39 |
+ */ |
|
| 40 |
+ virtual void newOpConn(const std::string &name, OpConn *pConn) = 0; |
|
| 41 |
+}; // class OpReqIf |
|
| 42 |
+ |
|
| 43 |
+} // namespace Blinker |
|
| 44 |
+ |
|
| 45 |
+#endif // #ifndef BLINKER_OPREQIF_H |
|
| 46 |
+ |
|
| 0 | 47 |