summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Eefting <edwin@datux.nl>2010-11-02 23:09:56 (GMT)
committer Edwin Eefting <edwin@datux.nl>2010-11-02 23:09:56 (GMT)
commit9b93e8909b75955c9ad73fb8dc499f4575c82685 (patch)
tree973eda9b7435038334fe2bc9984faf617db680f5
parent48451e4a266d954dd3d812eb462f04a827da5182 (diff)
making core id dynamic. working on session segmentssessionoffset
-rw-r--r--cmessageman.cpp162
-rw-r--r--cmessageman.h1
-rw-r--r--cmsg.cpp2
-rw-r--r--cmsg.h4
-rw-r--r--csession.h15
-rw-r--r--cuserman.cpp16
-rw-r--r--cuserman.h15
-rw-r--r--modules/core.module/module.cpp3
8 files changed, 110 insertions, 108 deletions
diff --git a/cmessageman.cpp b/cmessageman.cpp
index f4bc988..095be41 100644
--- a/cmessageman.cpp
+++ b/cmessageman.cpp
@@ -64,6 +64,7 @@ CmessageMan::CmessageMan()
defaultModifyGroup=userMan.getGroup("modules");
defaultRecvGroup=userMan.getGroup("everyone");
+ coreId=DST_CORE; //this will be set to the correct core session id as soon as possible
activeThreads=0;
currentThreads=0;
maxActiveThreads=0;
@@ -160,61 +161,15 @@ void CmessageMan::sendMappedMessage(const CmodulePtr &module, const CmsgPtr & m
//check if destination(s) are allowed to RECEIVE:
FsoHandler soHandler;
- //destination specified:
- if (msg->dst>0)
- {
- CsessionPtr dst;
- dst=userMan.getSession(msg->dst);
- //found it?
- if (!dst)
- {
- stringstream s;
- s << "send: destination session " << msg->dst << " not found";
- throw(runtime_error(s.str().c_str()));
- }
-
- //get the handler, and does it exist?
- soHandler=dst->module->getHandler(msg->event);
- if (soHandler==NULL)
- {
- WARNING("send ignored message: no handler for " << msg->event << " found in " << dst->module->name );
- return;
- }
- //is specified destination allowed?
- if (!event->isRecvAllowed(dst->user))
- {
- stringstream s;
- s << "send: session " << msg->dst << " with user " << dst->user->getName() << " is not allowed to receive event " << msg->event;
- throw(runtime_error(s.str().c_str()));
- }
-
- if (logSends)
- {
- msgStr << msg->dst << ":" << dst->user->getName() << "@" << dst->module->name <<
- " " << msg->getPrint(" |");
- LOG_SEND(msgStr.str());
- }
-
- //all checks ok:
- //make a copy of the message and add the destionation + handler to the call queue
- callMan.addCall(msg, dst, soHandler);
-
- //wake up a thread that calls the actual handler
- threadCond.notify_one();
-
-
- return;
- }
- //destination <=0 == broadcast
- else
+ //broadcast?
+ if (msg->dst==DST_BROADCAST)
{
if (logSends)
{
msgStr << "broadcast (";
}
-
//TODO:optimize these broadcasting algoritms
CsessionPtr dst;
bool delivered=false;
@@ -264,6 +219,59 @@ void CmessageMan::sendMappedMessage(const CmodulePtr &module, const CmsgPtr & m
if (!delivered)
WARNING("broadcast " << msg->event << " was not received by anyone.");
}
+ //no broadcast or anything else, deliver to one specific session:
+ else
+ {
+ CsessionPtr dst;
+
+ //special core destination id?
+ if (msg->dst==DST_CORE)
+ dst=userMan.getSession(coreId);
+ else
+ dst=userMan.getSession(msg->dst);
+
+ //found it?
+ if (!dst)
+ {
+ stringstream s;
+ s << "send: destination session " << msg->dst << " not found";
+ throw(runtime_error(s.str().c_str()));
+ }
+
+ //get the handler, and does it exist?
+ soHandler=dst->module->getHandler(msg->event);
+ if (soHandler==NULL)
+ {
+ WARNING("send ignored message: no handler for " << msg->event << " found in " << dst->module->name );
+ return;
+ }
+
+ //is specified destination allowed?
+ if (!event->isRecvAllowed(dst->user))
+ {
+ stringstream s;
+ s << "send: session " << msg->dst << " with user " << dst->user->getName() << " is not allowed to receive event " << msg->event;
+ throw(runtime_error(s.str().c_str()));
+ }
+
+ if (logSends)
+ {
+ msgStr << msg->dst << ":" << dst->user->getName() << "@" << dst->module->name <<
+ " " << msg->getPrint(" |");
+ LOG_SEND(msgStr.str());
+ }
+
+ //all checks ok:
+ //make a copy of the message and add the destionation + handler to the call queue
+ callMan.addCall(msg, dst, soHandler);
+
+ //wake up a thread that calls the actual handler
+ threadCond.notify_one();
+
+
+ return;
+ }
+
}
/** Use this to send a message.
@@ -272,32 +280,33 @@ Internally it will result in 1 or more calls to sendMappedMessage, if the msg.ds
void CmessageMan::sendMessage(const CmodulePtr &module, const CmsgPtr & msg, int cookie)
{
- if (msg->dst >= 0)
- {
+ //FIXME: implement mapped messages differntly?
+// if (msg->dst >= 0)
+// {
sendMappedMessage(module, msg, cookie);
- }
- else
- {
- //when we're done send a special mapping message that shows us what is mapped.
- //used by the mapper GUI.
- CmsgPtr mappedMsg=CmsgPtr(new Cmsg());
- mappedMsg->event="core_MappedEvent";
- //create or find the event in the mapper list, and traverse the list
- BOOST_FOREACH(string event, eventMappers[msg->event])
- {
- //clone the message and change the event-name
- CmsgPtr mapMsg=CmsgPtr(new Cmsg(*msg));
- (*mapMsg)["synapse_mappedFrom"]=msg->event; //long synapse-name, since we dont want it to collide with the original parameters of the message.
- (*mappedMsg)["mappedTo"].list().push_back(event);
- mapMsg->event=event;
- mapMsg->dst=0;
- sendMessage(module, mapMsg, cookie);
- }
-
- (*mappedMsg)["mappedFrom"]=msg->event;
- sendMessage(module, mappedMsg, cookie);
-
- }
+// }
+// else
+// {
+// //when we're done send a special mapping message that shows us what is mapped.
+// //used by the mapper GUI.
+// CmsgPtr mappedMsg=CmsgPtr(new Cmsg());
+// mappedMsg->event="core_MappedEvent";
+// //create or find the event in the mapper list, and traverse the list
+// BOOST_FOREACH(string event, eventMappers[msg->event])
+// {
+// //clone the message and change the event-name
+// CmsgPtr mapMsg=CmsgPtr(new Cmsg(*msg));
+// (*mapMsg)["synapse_mappedFrom"]=msg->event; //long synapse-name, since we dont want it to collide with the original parameters of the message.
+// (*mappedMsg)["mappedTo"].list().push_back(event);
+// mapMsg->event=event;
+// mapMsg->dst=0;
+// sendMessage(module, mapMsg, cookie);
+// }
+//
+// (*mappedMsg)["mappedFrom"]=msg->event;
+// sendMessage(module, mappedMsg, cookie);
+//
+// }
}
void CmessageMan::operator()()
@@ -501,8 +510,9 @@ void CmessageMan::checkThread()
int CmessageMan::run(string coreName, string moduleName)
{
//load the first module as user core UNLOCKED!
- loadModule(coreName, "core");
- this->firstModuleName=moduleName;
+ coreId=loadModule(coreName, "core")->id;
+
+ firstModuleName=moduleName;
//start first thread:
checkThread();
@@ -579,7 +589,7 @@ CsessionPtr CmessageMan::loadModule(string path, string userName)
CuserPtr user(userMan.getUser(userName));
if (user)
{
- //we need a session for the init function of the core-module:
+ //create the default session of the module
CsessionPtr session(new Csession(user,module));
module->defaultSessionId=userMan.addSession(session);
session->description="module default session.";
diff --git a/cmessageman.h b/cmessageman.h
index 82cb06c..4be1c9b 100644
--- a/cmessageman.h
+++ b/cmessageman.h
@@ -103,6 +103,7 @@ public:
//initial module that user want to start, after the coremodule is started:
string firstModuleName;
+ int coreId;
//for administrator/debugging
string getStatusStr();
diff --git a/cmsg.cpp b/cmsg.cpp
index fc7b569..2078bc3 100644
--- a/cmsg.cpp
+++ b/cmsg.cpp
@@ -36,7 +36,7 @@
Cmsg::Cmsg()
{
- dst=0;
+ dst=DST_CORE;
src=0;
}
diff --git a/cmsg.h b/cmsg.h
index ae06a9e..c9b95a3 100644
--- a/cmsg.h
+++ b/cmsg.h
@@ -70,6 +70,10 @@ typical route of a cmsg object
@author
*/
+//special destinations
+#define DST_BROADCAST 0
+#define DST_CORE -1
+
namespace synapse
{
using namespace std;
diff --git a/csession.h b/csession.h
index 1c17bfc..858de81 100644
--- a/csession.h
+++ b/csession.h
@@ -15,18 +15,6 @@
You should have received a copy of the GNU General Public License
along with Synapse. If not, see <http://www.gnu.org/licenses/>. */
-
-
-
-
-
-
-
-
-
-
-
-
#ifndef CSESSION_H
#define CSESSION_H
@@ -49,9 +37,6 @@ using namespace boost;
using namespace std;
/*
disabled sessions have id SESSION_DISABLED (-1)
- broadcasts go to sessions id 0
- core always has session id 1
- rest of the world has 2 and higher.
*/
#define SESSION_DISABLED -1
diff --git a/cuserman.cpp b/cuserman.cpp
index ce77204..1713ebb 100644
--- a/cuserman.cpp
+++ b/cuserman.cpp
@@ -14,19 +14,6 @@
You should have received a copy of the GNU General Public License
along with Synapse. If not, see <http://www.gnu.org/licenses/>. */
-
-
-
-
-
-
-
-
-
-
-
-
-
#include "cuserman.h"
#include <boost/shared_ptr.hpp>
#include <iostream>
@@ -37,10 +24,13 @@
namespace synapse
{
+
+
using namespace std;
CuserMan::CuserMan()
{
sessionCounter=0;
+ sessionSegment=12;
sessionMaxPerUser=1000;
shutdown=false;
diff --git a/cuserman.h b/cuserman.h
index 2e8631b..f82645c 100644
--- a/cuserman.h
+++ b/cuserman.h
@@ -45,6 +45,13 @@ using namespace boost;
#define MAX_SESSIONS 1000
+//a session id consists of 2 x 16-bits
+// -the higer 16 bits define the segment id, to identify the synapse instance.
+// -the lower 16 bits define the local session id
+#define SESSION_GET_SEGMENT(id) id >> 16;
+#define SESSION_GET_LOCAL(id) id & 0xffff;
+#define SESSION_GET_ID(segment,local) (( segment << 16 ) | local )
+
/**
@author
*/
@@ -53,6 +60,8 @@ public:
CuserMan();
~CuserMan();
+
+
CuserPtr getUser(const string & userName);
bool addUser(const CuserPtr & user);
CgroupPtr getGroup(const string & groupName);
@@ -70,10 +79,12 @@ private:
list<CuserPtr> users;
list<CgroupPtr> groups;
//performance: we use an oldskool array, so session lookups are quick
- int sessionCounter;
CsessionPtr sessions[MAX_SESSIONS+1];
+
int sessionMaxPerUser;
-
+ int sessionCounter;
+ int sessionSegment; //every synapse instance should have a uniq segment
+
};
}
diff --git a/modules/core.module/module.cpp b/modules/core.module/module.cpp
index 5dfab6f..064cc6c 100644
--- a/modules/core.module/module.cpp
+++ b/modules/core.module/module.cpp
@@ -57,8 +57,9 @@ void init()
INFO("Synapse core v1.0 starting up...");
- //call the normal module-init to do the rest:
+ //normally the module_Init for other modules is send by us. So we have to send our own module_init our selfs.
Cmsg out;
+ out.dst=((CmodulePtr)module)->defaultSessionId;
out.event="module_Init";
out.send();