summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2013-01-20 21:41:36 (GMT)
committer Edwin Eefting <edwin@datux.nl>2013-01-20 21:41:36 (GMT)
commit5f86645296effd1767541cc25698ec1a9409816b (patch)
tree7504d79bfe087a476192ba24beef1d949cf77fa1
parent3a1a42b6901e0b65c5ee510d03ae1aa4d65a86f2 (diff)
when msg.src=0 the core automaticly uses the session id of the call thats currently being handled. removed sessionstarted since its not used and confusing.
-rw-r--r--cmessageman.cpp13
-rw-r--r--cmessageman.h2
-rw-r--r--modules/core.module/module.cpp11
3 files changed, 20 insertions, 6 deletions
diff --git a/cmessageman.cpp b/cmessageman.cpp
index eba413f..b08471b 100644
--- a/cmessageman.cpp
+++ b/cmessageman.cpp
@@ -49,6 +49,7 @@
namespace synapse
{
+__thread int currentThreadDstId;
//keep this many threads left, even though we dont need them right away.
//This is to prevent useless thread destruction/creation.
@@ -58,7 +59,9 @@ using namespace boost;
CmessageMan::CmessageMan()
{
-
+ //pretent like the current thread is handling a call that was send to session id 1,
+ //so that msg.src automaticly get 1 when the core call send with msg.src=0
+ currentThreadDstId=1;
logSends=true;
logReceives=true;
// defaultOwner=userMan.getUser("module");
@@ -91,18 +94,20 @@ void CmessageMan::sendMappedMessage(const CmodulePtr &module, const CmsgPtr & m
// -msg is set by the user and only containts direct objects, and NO pointers. it cant be trusted yet!
// -our job is to verify if everything is ok and populate the call queue
// -internally the core only works with smartpointers, so most stuff thats not in msg will be a smartpointer.
+ // -cookie is checked against the session cookie. if it doesnt match an error is thrown. (this makes creating network modules easier)
//edwin: why?
// if (shutdown)
// throw(runtime_error("Shutting down, ignored message"));
- //no src session specified means use default session of module:
+ //no src session specified means we use the session the original message was send to.
+ //we do this be using the global currentThreadDstId which is thread-local storage and contains the dst-session of the current call.
//NOTE: this is the only case where modify the actual msg object.
if (!msg->src)
{
if (module->defaultSessionId!=SESSION_DISABLED)
{
- msg->src=module->defaultSessionId;
+ msg->src=currentThreadDstId;
}
else
{
@@ -380,6 +385,8 @@ void CmessageMan::operator()()
//handle call
try
{
+ //this is used in sendmessage to automagically determine the source session when its not specified.
+ currentThreadDstId=callI->dst->id;
callI->soHandler(*(callI->msg), callI->dst->id, callI->dst->cookie);
}
catch (const ios::failure& e)
diff --git a/cmessageman.h b/cmessageman.h
index b39d950..f48db1f 100644
--- a/cmessageman.h
+++ b/cmessageman.h
@@ -43,6 +43,7 @@
#include <boost/thread/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/tss.hpp>
namespace synapse
{
@@ -71,6 +72,7 @@ using namespace boost;
*/
+
class CmessageMan{
public:
CmessageMan();
diff --git a/modules/core.module/module.cpp b/modules/core.module/module.cpp
index b362de0..355454e 100644
--- a/modules/core.module/module.cpp
+++ b/modules/core.module/module.cpp
@@ -154,12 +154,13 @@ SYNAPSE_REGISTER(module_Init)
out["recvGroup"]= "anonymous";
out.send();
+/*useless..? (most modules have there own event to announch their sessions in a more meaning full way to others)
out["event"]= "module_SessionStarted"; // SEND to broadcast, on newly created session
out["modifyGroup"]= "core";
out["sendGroup"]= "core";
out["recvGroup"]= "everyone";
out.send();
-
+*/
out["event"]= "core_DelSession"; // RECV to delete src session
out["modifyGroup"]= "core";
out["sendGroup"]= "anonymous";
@@ -256,7 +257,7 @@ To the initial session of the new module. (just like any other session that is s
\P synapse_cookie Custom session cookie.
\P description Description of the session.
-\BROADCAST module_SessionStarted
+\BROADCAST module_SessionStarted (REMOVED )
Tells the world a new session is started for this module.
\P session The session id of the new session.
@@ -341,12 +342,14 @@ SYNAPSE_REGISTER(core_LoadModule)
//the module_SessionStart
startmsg.send();
+/*
//also broadcast module_SessionStarted, so other modules know that a session is started
startmsg.clear();
startmsg.event="module_SessionStarted";
startmsg["session"]=startmsg.dst;
startmsg.dst=0;
startmsg.send();
+ */
}
}
}
@@ -571,7 +574,7 @@ SYNAPSE_REGISTER(core_Login)
\arg \c description (optional) description of the session, usefull for debugging and administration.
\arg \c (other parameters) Contains all specified arguments. (without password)
-\BROADCAST module_SessionStarted:
+\BROADCAST module_SessionStarted (REMOVED):
to let the rest of the word know of the new session.
\arg \c session The session id of the new session.
*/
@@ -639,12 +642,14 @@ SYNAPSE_REGISTER(core_NewSession)
{
startmsg.send();
+/*
//also broadcast module_SessionStarted, so other modules know that a session is started
startmsg.clear();
startmsg.event="module_SessionStarted";
startmsg["session"]=startmsg.dst;
startmsg.dst=0;
startmsg.send();
+ */
}
}