summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoredwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-07-14 17:58:38 (GMT)
committer edwin <edwin@99606f1f-bbb2-4562-8e6b-387ddef1dc61>2010-07-14 17:58:38 (GMT)
commit2edd55ee919cd1dd73f5b775c185220c8a6a4c01 (patch)
treea6ff4ababf419699345a95f90d8d51d031dfc8e6
parent9d316332c8f193564dd8273fe1550eb37a4db969 (diff)
major namespace cleanup
git-svn-id: https://open.syn3.nl/syn3/svndav/default/trunk/projects/synapse@369 99606f1f-bbb2-4562-8e6b-387ddef1dc61
-rw-r--r--ccall.cpp4
-rw-r--r--ccall.h4
-rw-r--r--ccallman.cpp3
-rw-r--r--ccallman.h4
-rw-r--r--cevent.cpp4
-rw-r--r--cevent.h7
-rw-r--r--cgroup.cpp4
-rw-r--r--cgroup.h4
-rw-r--r--clog.cpp5
-rw-r--r--clog.h6
-rw-r--r--cmessageman.cpp3
-rw-r--r--cmessageman.h5
-rw-r--r--cmodule.cpp6
-rw-r--r--cmodule.h16
-rw-r--r--cmsg.cpp2
-rw-r--r--cmsg.h48
-rw-r--r--common.h4
-rw-r--r--csession.cpp5
-rw-r--r--csession.h16
-rw-r--r--cuser.cpp3
-rw-r--r--cuser.h5
-rw-r--r--cuserman.cpp4
-rw-r--r--cuserman.h5
-rw-r--r--cvar.cpp5
-rw-r--r--cvar.h7
-rw-r--r--main.cpp24
-rw-r--r--modules/asterisk.module/cgroup.cpp74
-rw-r--r--modules/asterisk.module/cgroup.h52
-rw-r--r--modules/asterisk.module/csession.cpp35
-rw-r--r--modules/asterisk.module/csession.h45
-rw-r--r--modules/asterisk.module/module.cpp147
-rw-r--r--modules/core.module/module.cpp4
-rw-r--r--modules/timer.module/module.cpp2
-rw-r--r--synapse.h7
34 files changed, 404 insertions, 165 deletions
diff --git a/ccall.cpp b/ccall.cpp
index 56faaf5..04bdfc6 100644
--- a/ccall.cpp
+++ b/ccall.cpp
@@ -10,7 +10,8 @@
//
//
#include "ccall.h"
-
+namespace synapse
+{
Ccall::~Ccall()
{
}
@@ -29,3 +30,4 @@ Ccall::Ccall(const CmsgPtr & msg,const CsessionPtr & dst, FsoHandler soHandler)
}
+}
diff --git a/ccall.h b/ccall.h
index 8df53d2..8a86012 100644
--- a/ccall.h
+++ b/ccall.h
@@ -15,6 +15,8 @@
#include "cmsg.h"
#include <boost/thread/thread.hpp>
+namespace synapse
+{
typedef shared_ptr<thread> CthreadPtr;
/**
@@ -33,5 +35,5 @@ public:
CthreadPtr threadPtr;
};
-
+}
#endif
diff --git a/ccallman.cpp b/ccallman.cpp
index 3893504..1d1df52 100644
--- a/ccallman.cpp
+++ b/ccallman.cpp
@@ -12,6 +12,8 @@
#include "ccallman.h"
#include "clog.h"
using namespace boost;
+namespace synapse
+{
CcallMan::CcallMan()
{
@@ -156,3 +158,4 @@ bool CcallMan::interruptAll()
}
return false;
}
+}
diff --git a/ccallman.h b/ccallman.h
index 057534b..e0b51fc 100644
--- a/ccallman.h
+++ b/ccallman.h
@@ -18,6 +18,8 @@
/**
@author
*/
+namespace synapse
+{
typedef list<Ccall> CcallList;
@@ -38,5 +40,5 @@ public:
CcallList callList;
};
-
+}
#endif
diff --git a/cevent.cpp b/cevent.cpp
index 3de77e0..35f58f7 100644
--- a/cevent.cpp
+++ b/cevent.cpp
@@ -12,6 +12,8 @@
#include "clog.h"
#include "cevent.h"
#include <iostream>
+namespace synapse
+{
Cevent::Cevent(const CgroupPtr & modifyGroup, const CgroupPtr & sendGroup, const CgroupPtr & recvGroup )
@@ -116,3 +118,5 @@ void Cevent::print()
DEB("sendGroup =" << sendGroup->getName());
DEB("modifyGroup=" << modifyGroup->getName());
}
+
+}
diff --git a/cevent.h b/cevent.h
index 97ebf2a..acc15c2 100644
--- a/cevent.h
+++ b/cevent.h
@@ -16,11 +16,14 @@
#include "cuser.h"
#include <boost/shared_ptr.hpp>
+
+namespace synapse
+{
+
using namespace boost;
using namespace std;
-
/**
@author
*/
@@ -55,4 +58,6 @@ private:
typedef shared_ptr<Cevent> CeventPtr;
+}
+
#endif
diff --git a/cgroup.cpp b/cgroup.cpp
index 7f95536..99a24c4 100644
--- a/cgroup.cpp
+++ b/cgroup.cpp
@@ -10,6 +10,8 @@
//
//
#include "cgroup.h"
+namespace synapse
+{
Cgroup::Cgroup(const string & name)
{
@@ -31,3 +33,5 @@ string Cgroup::getName()
{
return (name);
}
+
+}
diff --git a/cgroup.h b/cgroup.h
index 31193a7..adfa2ec 100644
--- a/cgroup.h
+++ b/cgroup.h
@@ -13,6 +13,8 @@
#define CGROUP_H
#include <boost/shared_ptr.hpp>
#include <string>
+namespace synapse
+{
using namespace boost;
using namespace std;
@@ -31,5 +33,5 @@ private:
};
typedef shared_ptr<Cgroup> CgroupPtr;
-
+}
#endif
diff --git a/clog.cpp b/clog.cpp
index 0036b38..a7116be 100644
--- a/clog.cpp
+++ b/clog.cpp
@@ -13,4 +13,9 @@
#include <iostream>
#include <boost/thread/mutex.hpp>
+namespace synapse
+{
+
boost::mutex logMutex;
+
+}
diff --git a/clog.h b/clog.h
index 34ce387..9d794b9 100644
--- a/clog.h
+++ b/clog.h
@@ -17,6 +17,8 @@
#include <iostream>
#include <boost/thread/thread.hpp>
+namespace synapse
+{
extern boost::mutex logMutex;
//colors and ansi stuff (we dont want ncurses YET)
@@ -37,7 +39,7 @@ extern boost::mutex logMutex;
stringstream log_buff; \
log_buff << s; \
{ \
- boost::lock_guard<boost::mutex> lock(logMutex); \
+ boost::lock_guard<boost::mutex> lock(synapse::logMutex); \
cout << log_buff.rdbuf(); \
} \
}
@@ -64,6 +66,6 @@ extern boost::mutex logMutex;
#define LOG_RECV(s) LOG(boost::this_thread::get_id() << " " << TERM_RECV_MESSAGE << s << TERM_NORMAL << endl)
-
+}
#endif
diff --git a/cmessageman.cpp b/cmessageman.cpp
index 58933b7..586deff 100644
--- a/cmessageman.cpp
+++ b/cmessageman.cpp
@@ -22,6 +22,8 @@
#include <boost/foreach.hpp>
#include "cevent.h"
+namespace synapse
+{
using namespace boost;
CmessageMan::CmessageMan()
@@ -702,3 +704,4 @@ void CmessageMan::getMapping(string mapFrom, Cvar & var)
var.list().push_back(event);
}
}
+}
diff --git a/cmessageman.h b/cmessageman.h
index 150b3e2..957e07d 100644
--- a/cmessageman.h
+++ b/cmessageman.h
@@ -26,6 +26,9 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread/recursive_mutex.hpp>
+namespace synapse
+{
+
/*
This is the main object.
@@ -124,6 +127,6 @@ private:
};
-
+}
#endif
diff --git a/cmodule.cpp b/cmodule.cpp
index 4c050b3..e671e73 100644
--- a/cmodule.cpp
+++ b/cmodule.cpp
@@ -14,6 +14,8 @@
#include <dlfcn.h>
#include <boost/regex.hpp>
#include <boost/foreach.hpp>
+namespace synapse
+{
@@ -248,4 +250,6 @@ void Cmodule::getEvents(Cvar & var)
{
var[handler.first]=1;
}
-} \ No newline at end of file
+}
+
+}
diff --git a/cmodule.h b/cmodule.h
index 93cd1ba..be31d41 100644
--- a/cmodule.h
+++ b/cmodule.h
@@ -12,19 +12,27 @@
#ifndef CMODULE_H
#define CMODULE_H
+
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
//#include <hash_map.h>
#include "common.h"
-using namespace boost;
-using namespace std;
+namespace synapse
+{
+ using namespace boost;
+ using namespace std;
-typedef shared_ptr<class Cmodule> CmodulePtr;
+ typedef shared_ptr<class Cmodule> CmodulePtr;
+}
#include "cmsg.h"
#include "csession.h"
+namespace synapse
+{
+using namespace boost;
+using namespace std;
//MODULE STUFF
#define SYNAPSE_API_VERSION 2
@@ -97,6 +105,6 @@ public:
};
-
+}
#endif
diff --git a/cmsg.cpp b/cmsg.cpp
index b51739f..cbf7257 100644
--- a/cmsg.cpp
+++ b/cmsg.cpp
@@ -74,3 +74,5 @@ bool Cmsg::fromJson(string & jsonStr)
return false;
}
}
+
+
diff --git a/cmsg.h b/cmsg.h
index d0c62f0..625c875 100644
--- a/cmsg.h
+++ b/cmsg.h
@@ -20,8 +20,7 @@
#include "cvar.h"
//#include "cmessageman.h"
-using namespace std;
-using namespace boost;
+
@@ -52,28 +51,37 @@ typical route of a cmsg object
/**
@author
*/
-class Cmsg : public Cvar {
-public:
- Cmsg();
- ~Cmsg();
- int src;
- int dst;
- string event;
- //this function is only implemented in the .so object module
- //so if you use it in the core you will get linker errors :)
- string send(int cookie=0);
- void returnError(string description);
- void returnWarning(string description);
- bool returnIfOtherThan(char * keys, ...);
+namespace synapse
+{
+ using namespace std;
+
+
+ class Cmsg : public Cvar {
+ public:
+ Cmsg();
+ ~Cmsg();
+ int src;
+ int dst;
+ string event;
+
+ //this function is only implemented in the .so object module
+ //so if you use it in the core you will get linker errors :)
+ string send(int cookie=0);
+ void returnError(string description);
+ void returnWarning(string description);
+ bool returnIfOtherThan(char * keys, ...);
+
+ //json stuff
+ void toJson(string & jsonStr);
+ bool fromJson(string & jsonStr);
- //json stuff
- void toJson(string & jsonStr);
- bool fromJson(string & jsonStr);
+ };
-};
+ typedef shared_ptr<Cmsg> CmsgPtr;
-typedef shared_ptr<Cmsg> CmsgPtr;
+}
+typedef synapse::Cmsg Cmsg;
#endif
diff --git a/common.h b/common.h
index 8f5c8a0..5e58459 100644
--- a/common.h
+++ b/common.h
@@ -2,9 +2,12 @@
#define COMMON_H
#include <string>
+namespace synapse
+{
using namespace std;
+
struct eqstr
{
bool operator()(string s1, string s2) const
@@ -13,5 +16,6 @@ struct eqstr
}
};
+}
#endif
diff --git a/csession.cpp b/csession.cpp
index 0885099..9f2db67 100644
--- a/csession.cpp
+++ b/csession.cpp
@@ -14,6 +14,9 @@
#include "cmodule.h"
#include <iostream>
+namespace synapse
+{
+
Csession::Csession(const CuserPtr &user, const CmodulePtr &module, int cookie)
{
this->user=user;
@@ -70,3 +73,5 @@ void Csession::endThread()
currentThreads--;
assert(currentThreads>=0);
}
+
+}
diff --git a/csession.h b/csession.h
index 4ed11c3..fc30067 100644
--- a/csession.h
+++ b/csession.h
@@ -13,14 +13,22 @@
#define CSESSION_H
#include <boost/shared_ptr.hpp>
-using namespace boost;
-using namespace std;
+namespace synapse
+{
+ using namespace boost;
+ using namespace std;
+
-typedef shared_ptr<class Csession> CsessionPtr;
+ typedef shared_ptr<class Csession> CsessionPtr;
+}
#include "cmodule.h"
#include "cuser.h"
+namespace synapse
+{
+using namespace boost;
+using namespace std;
/*
disabled sessions have id SESSION_DISABLED (-1)
broadcasts go to sessions id 0
@@ -55,5 +63,5 @@ private:
};
-
+}
#endif
diff --git a/cuser.cpp b/cuser.cpp
index 606c4e0..f79db21 100644
--- a/cuser.cpp
+++ b/cuser.cpp
@@ -11,6 +11,8 @@
//
#include "cuser.h"
#include "clog.h"
+namespace synapse
+{
Cuser::Cuser(const string &name, const string &password="")
{
@@ -96,3 +98,4 @@ void Cuser::print()
}
}
+}
diff --git a/cuser.h b/cuser.h
index 1c523ab..fdef131 100644
--- a/cuser.h
+++ b/cuser.h
@@ -15,10 +15,12 @@
#include <string>
#include <list>
#include <boost/shared_ptr.hpp>
+
+namespace synapse
+{
using namespace boost;
using namespace std;
-
/**
@author
*/
@@ -42,5 +44,6 @@ private:
typedef shared_ptr<Cuser> CuserPtr;
+}
#endif
diff --git a/cuserman.cpp b/cuserman.cpp
index f53398c..404505c 100644
--- a/cuserman.cpp
+++ b/cuserman.cpp
@@ -16,6 +16,8 @@
#include "cmodule.h"
#include "clog.h"
+namespace synapse
+{
using namespace std;
CuserMan::CuserMan()
@@ -300,3 +302,5 @@ string CuserMan::login(const int & sessionId, const string & userName, const str
}
}
}
+
+}
diff --git a/cuserman.h b/cuserman.h
index a9f74fd..c35824f 100644
--- a/cuserman.h
+++ b/cuserman.h
@@ -18,6 +18,10 @@
#include <boost/shared_ptr.hpp>
#include <list>
+
+namespace synapse
+{
+
using namespace std;
using namespace boost;
@@ -53,5 +57,6 @@ private:
int sessionMaxPerUser;
};
+}
#endif
diff --git a/cvar.cpp b/cvar.cpp
index 1d7c260..dd2831c 100644
--- a/cvar.cpp
+++ b/cvar.cpp
@@ -14,6 +14,9 @@
#include <boost/lexical_cast.hpp>
#include "clog.h"
+namespace synapse
+{
+
/// COMMON STUFF
Cvar::Cvar()
@@ -437,3 +440,5 @@ bool Cvar::fromJson(string & jsonStr)
return false;
}
}
+
+}
diff --git a/cvar.h b/cvar.h
index 7cf479c..57c1ff9 100644
--- a/cvar.h
+++ b/cvar.h
@@ -12,12 +12,15 @@
#ifndef CVAR_H
#define CVAR_H
+
#include "clog.h"
#include <string>
#include "boost/variant.hpp"
#include <map>
#include "json_spirit.h"
+namespace synapse
+{
using namespace std;
using namespace boost;
using namespace json_spirit;
@@ -94,5 +97,9 @@ protected:
private:
variant <void *,CvarMap , long double, string, CvarList> value;
};
+}
+
+typedef synapse::Cvar Cvar;
+
#endif
diff --git a/main.cpp b/main.cpp
index 5249883..45a184c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,17 +5,19 @@
#include "cmessageman.h"
-int main(int argc, char *argv[])
-{
- CmessageMan messageMan;
- if (argc==2)
+ int main(int argc, char *argv[])
{
- return (messageMan.run("modules/core.module/libcore.so",argv[1]));
+ using namespace synapse;
+ CmessageMan messageMan;
+ if (argc==2)
+ {
+ return (messageMan.run("modules/core.module/libcore.so",argv[1]));
+ }
+ else
+ {
+ INFO("Usage: ./synapse <initialmodule.so>\n");
+ return (1);
+ }
}
- else
- {
- INFO("Usage: ./synapse <initialmodule.so>\n");
- return (1);
- }
-}
+
diff --git a/modules/asterisk.module/cgroup.cpp b/modules/asterisk.module/cgroup.cpp
new file mode 100644
index 0000000..c34bb27
--- /dev/null
+++ b/modules/asterisk.module/cgroup.cpp
@@ -0,0 +1,74 @@
+/*
+ * cgroup.cpp
+ *
+ * Created on: Jul 14, 2010
+ * Author: psy
+ */
+
+#include "cgroup.h"
+#include <string.h>
+//groups: most times a tennant is considered a group.
+//After authenticating, a session points to a group.'
+//All devices of a specific tennant also point to this group
+//events are only sent to Csessions that are member of the same group as the corresponding device.
+namespace asterisk
+{
+ Cgroup::Cgroup()
+ {
+ }
+
+ void Cgroup::setId(string id)
+ {
+ this->id=id;
+ }
+
+ string Cgroup::getId()
+ {
+ return(id);
+ }
+
+ //sends msg after applying group filtering.
+ //message will only be sended or broadcasted to sessions that belong to this group.
+ void Cgroup::send(CsessionMap & sessionMap, Cmsg & msg)
+ {
+ //broadcast?
+ if (msg.dst==0)
+ {
+ //we cant simply broadcast it, we need to check group membership session by session
+ for (CsessionMap::iterator I=sessionMap.begin(); I!=sessionMap.end(); I++)
+ {
+ if (I->second->getGroupPtr().get()==this)
+ {
+ msg.dst=I->first;
+ msg.send();
+ }
+ }
+ //restore dst value:
+ msg.dst=0;
+ }
+ else
+ {
+ CsessionMap::iterator I=sessionMap.find(msg.dst);
+ if (I!=sessionMap.end())
+ {
+ if (I->second->getGroupPtr().get()!=this)
+ {
+ //dont: WARNING("Cant send message to session " << msg.dst << ", it doesnt belong to group: " << getId());
+ return;
+ }
+ msg.send();
+ }
+ }
+
+ }
+
+ string Cgroup::getStatus(string prefix)
+ {
+ return (
+ prefix+"Group "+id
+ );
+ }
+
+
+
+}
diff --git a/modules/asterisk.module/cgroup.h b/modules/asterisk.module/cgroup.h
new file mode 100644
index 0000000..fe1453d
--- /dev/null
+++ b/modules/asterisk.module/cgroup.h
@@ -0,0 +1,52 @@
+/*
+ * cgroup.h
+ *
+ * Created on: Jul 14, 2010
+ * Author: psy
+ */
+
+#ifndef CGROUP_H_
+#define CGROUP_H_
+
+#include <boost/shared_ptr.hpp>
+#include <string>
+#include "cmsg.h"
+
+namespace asterisk
+{
+ using namespace boost;
+ using namespace std;
+ using namespace asterisk;
+ typedef shared_ptr<class Cgroup> CgroupPtr;
+ typedef map<string, CgroupPtr> CgroupMap;
+}
+
+#include "csession.h"
+
+namespace asterisk
+{
+ using namespace boost;
+ using namespace std;
+ using namespace asterisk;
+
+ //groups: most times a tennant is considered a group.
+ //After authenticating, a session points to a group.'
+ //All devices of a specific tennant also point to this group
+ //events are only sent to Csessions that are member of the same group as the corresponding device.
+ class Cgroup
+ {
+ private:
+ string id;
+
+ public:
+ Cgroup();
+ void setId(string id);
+ string getId();
+ void send(CsessionMap & sessionMap, Cmsg & msg);
+ string getStatus(string prefix);
+ };
+
+
+}
+
+#endif /* CGROUP_H_ */
diff --git a/modules/asterisk.module/csession.cpp b/modules/asterisk.module/csession.cpp
new file mode 100644
index 0000000..fb5505b
--- /dev/null
+++ b/modules/asterisk.module/csession.cpp
@@ -0,0 +1,35 @@
+/*
+ * csession.cpp
+ *
+ * Created on: Jul 14, 2010
+ * Author: psy
+ */
+#include "cgroup.h"
+namespace asterisk
+{
+
+ //sessions: every synapse session has a corresponding session object here
+ Csession::Csession(int id)
+ {
+ this->id=id;
+ }
+
+
+ void Csession::setGroupPtr(CgroupPtr groupPtr)
+ {
+ this->groupPtr=groupPtr;
+ }
+
+ CgroupPtr Csession::getGroupPtr()
+ {
+ return (groupPtr);
+ }
+
+ string Csession::getStatus(string prefix)
+ {
+ stringstream s;
+ s << prefix << "Session " << id << ":\n" << groupPtr->getStatus(prefix+" ");
+ return(s.str());
+ }
+
+}
diff --git a/modules/asterisk.module/csession.h b/modules/asterisk.module/csession.h
new file mode 100644
index 0000000..e189c74
--- /dev/null
+++ b/modules/asterisk.module/csession.h
@@ -0,0 +1,45 @@
+/*
+ * csession.h
+ *
+ * Created on: Jul 14, 2010
+ * Author: psy
+ */
+
+#ifndef CSESSION_H_
+#define CSESSION_H_
+
+//#include "cgroup_types.h"
+
+namespace asterisk
+{
+ using namespace std;
+ using namespace boost;
+ using namespace asterisk;
+ typedef shared_ptr<class Csession> CsessionPtr;
+ typedef map<int, CsessionPtr> CsessionMap;
+}
+
+#include "cgroup.h"
+
+namespace asterisk
+{
+ using namespace std;
+ using namespace boost;
+ using namespace asterisk;
+
+ //sessions: every synapse session has a corresponding session object here
+ class Csession
+ {
+ private:
+ int id;
+ CgroupPtr groupPtr;
+
+ public:
+ Csession(int id);
+ void setGroupPtr(CgroupPtr groupPtr);
+ CgroupPtr getGroupPtr();
+ string getStatus(string prefix);
+ };
+
+}
+#endif /* CSESSION_H_ */
diff --git a/modules/asterisk.module/module.cpp b/modules/asterisk.module/module.cpp
index 36146d3..8bb8207 100644
--- a/modules/asterisk.module/module.cpp
+++ b/modules/asterisk.module/module.cpp
@@ -50,11 +50,18 @@ To setup a fake server replaying this:
#include <boost/regex.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
+#include "./csession.h"
+//#include "./cgroup.h"
+//#include "./csession_types.h"
+//#include "./cgroup_types.h"
#define ASTERISK_AUTH "999"
namespace asterisk
{
+ using namespace std;
+ using namespace boost;
+
typedef long int TauthCookie;
struct drand48_data randomBuffer;
@@ -159,14 +166,8 @@ namespace asterisk
}
}
- class Csession;
- typedef shared_ptr<class Csession> CsessionPtr;
- typedef map<int, CsessionPtr> CsessionMap;
CsessionMap sessionMap;
- class Cgroup;
- typedef shared_ptr<class Cgroup> CgroupPtr;
- typedef map<string, CgroupPtr> CgroupMap;
CgroupMap groupMap;
typedef shared_ptr<class Cdevice> CdevicePtr;
@@ -178,110 +179,12 @@ namespace asterisk
typedef map<int, class Cserver> CserverMap;
CserverMap serverMap;
- //sessions: every synapse session has a corresponding session object here
- class Csession
- {
- private:
-// int id;
-// bool authenticated;
- CgroupPtr groupPtr;
-
- public:
- Csession()
- {
-// authenticated=false;
- }
-
-// void setId(int id)
-// {
-// this->id=id;
-//
-// }
-
- void setGroupPtr(CgroupPtr groupPtr)
- {
- this->groupPtr=groupPtr;
- }
- CgroupPtr getGroupPtr()
- {
- return (groupPtr);
- }
- };
- //groups: most times a tennant is considered a group.
- //After authenticating, a session points to a group.'
- //All devices of a specific tennant also point to this group
- //events are only sent to Csessions that are member of the same group as the corresponding device.
- class Cgroup
- {
- private:
- string id;
- public:
- Cgroup()
- {
- }
-
- void setId(string id)
- {
- this->id=id;
- }
-
- string getId()
- {
- return(id);
- }
-
- //sends msg after applying group filtering.
- //message will only be sended or broadcasted to sessions that belong to this group.
- void send(Cmsg & msg)
- {
- //broadcast?
- if (msg.dst==0)
- {
- //we cant simply broadcast it, we need to check group membership session by session
- for (CsessionMap::iterator I=sessionMap.begin(); I!=sessionMap.end(); I++)
- {
- if (I->second->getGroupPtr().get()==this)
- {
- msg.dst=I->first;
- msg.send();
- }
- }
- //restore dst value:
- msg.dst=0;
- }
- else
- {
- CsessionMap::iterator I=sessionMap.find(msg.dst);
- if (I!=sessionMap.end())
- {
- if (I->second->getGroupPtr().get()!=this)
- {
- //dont: WARNING("Cant send message to session " << msg.dst << ", it doesnt belong to group: " << getId());
- return;
- }
- msg.send();
- }
- }
-
- }
-
- string getStatus(string prefix)
- {
- return (
- prefix+"Group "+id
- );
- }
-
- };
-
-
-
//devices: these can be sip devices, misdn, local channels, agent-stuff etc
@@ -393,7 +296,7 @@ namespace asterisk
out["groupId"]=groupPtr->getId();
}
- groupPtr->send(out);
+ groupPtr->send(sessionMap,out);
return(true);
}
@@ -431,7 +334,7 @@ namespace asterisk
out["id"]=id;
if (groupPtr!=NULL)
- groupPtr->send(out);
+ groupPtr->send(sessionMap,out);
}
@@ -480,7 +383,7 @@ namespace asterisk
msg.dst=0;
msg.src=0;
- devicePtr->getGroupPtr()->send(msg);
+ devicePtr->getGroupPtr()->send(sessionMap,msg);
return (true);
}
@@ -663,7 +566,7 @@ namespace asterisk
out["firstExtension"]=firstExtension;
- devicePtr->getGroupPtr()->send(out);
+ devicePtr->getGroupPtr()->send(sessionMap,out);
return (true);
}
@@ -694,7 +597,7 @@ namespace asterisk
{
out["deviceId"]=devicePtr->getId();
}
- devicePtr->getGroupPtr()->send(out);
+ devicePtr->getGroupPtr()->send(sessionMap,out);
}
}
@@ -824,18 +727,20 @@ namespace asterisk
if (status==AUTHENTICATING)
s=s+"authenticating...";
if (status==AUTHENTICATED)
- s=s+"authenticating";
+ s=s+"authenticated";
s=s+"\n";
+ s=s+prefix+" Channels:\n";
for (CchannelMap::iterator I=channelMap.begin(); I!=channelMap.end(); I++)
{
- s= s + I->second->getStatus(prefix+" ") + "\n";
+ s= s + I->second->getStatus(prefix+" ") + "\n";
}
+ s=s+prefix+" Devices:\n";
for (CdeviceMap::iterator I=deviceMap.begin(); I!=deviceMap.end(); I++)
{
- s=s + I->second->getStatus(prefix+" ")+"\n";
+ s=s + I->second->getStatus(prefix+" ")+"\n";
}
return (s);
@@ -854,17 +759,29 @@ namespace asterisk
out.event="asterisk_Status";
out.dst=msg.src;
out["status"]="";
- for (CserverMap::iterator I=serverMap.begin(); I!=serverMap.end(); I++)
+
+ out["status"].str()+="Sessions:\n";
+ for (CsessionMap::iterator I=sessionMap.begin(); I!=sessionMap.end(); I++)
{
- out["status"].str()+= I->second.getStatus(" ");
+ stringstream id;
+ id << I->first;
+ out["status"].str()+=I->second->getStatus(" ")+"\n";
}
+
out["status"].str()+="Groups:\n";
for (CgroupMap::iterator I=groupMap.begin(); I!=groupMap.end(); I++)
{
out["status"].str()+=I->second->getStatus(" ")+"\n";
}
+ out["status"].str()+="Servers:\n";
+ for (CserverMap::iterator I=serverMap.begin(); I!=serverMap.end(); I++)
+ {
+ out["status"].str()+= I->second.getStatus(" ");
+ }
+
+
out.send();
}
@@ -1311,7 +1228,7 @@ namespace asterisk
//create a Csession object for the src session?
if (sessionMap.find(msg.src) == sessionMap.end())
{
- sessionMap[msg.src]=CsessionPtr(new Csession());
+ sessionMap[msg.src]=CsessionPtr(new Csession(msg.src));
}
//deviceId + correct authCookie ?
diff --git a/modules/core.module/module.cpp b/modules/core.module/module.cpp
index 0498daf..dba56db 100644
--- a/modules/core.module/module.cpp
+++ b/modules/core.module/module.cpp
@@ -23,6 +23,9 @@ Look in the files section for more info..
#include "synapse.h"
#include <signal.h>
+namespace synapse
+{
+
//Dont forget you can only do things to core-objects after locking the core!
//Also dont forget you CANT send() while holding the core-lock. (it will deadlock)
@@ -943,3 +946,4 @@ SYNAPSE_REGISTER(core_DelMapping)
out.send();
}
+}
diff --git a/modules/timer.module/module.cpp b/modules/timer.module/module.cpp
index 52d0f6e..7fcba5e 100644
--- a/modules/timer.module/module.cpp
+++ b/modules/timer.module/module.cpp
@@ -14,6 +14,8 @@ This is a simple timer module, to send delayed events or repeat events with a in
namespace timer
{
+using namespace std;
+
bool shutdown;
diff --git a/synapse.h b/synapse.h
index ff26796..1c5e427 100644
--- a/synapse.h
+++ b/synapse.h
@@ -9,6 +9,9 @@
#include <boost/foreach.hpp>
#include <stdarg.h>
+namespace synapse
+{
+
#ifdef SYNAPSE_HAS_INIT
void init();
@@ -32,7 +35,7 @@ list<string> synapseAutoReg::handlers;
//This stores the handler in a list by constructing a dummy object:
#define SYNAPSE_REGISTER(name) \
- synapseAutoReg BOOST_PP_CAT(synapse_autoreg_, name)(#name); \
+ synapse::synapseAutoReg BOOST_PP_CAT(synapse_autoreg_, name)(#name); \
SYNAPSE_HANDLER(name)
@@ -125,3 +128,5 @@ bool Cmsg::returnIfOtherThan(char * keys, ...)
return false;
}
+
+}