went one step further with macrotisation of DSM modules

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1542 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 17 years ago
parent f08a1e7416
commit 97c0229406

@ -267,4 +267,60 @@ void splitCmd(const string& from_str,
return false; \
}
#define DECLARE_MODULE(mod_cls_name) \
class mod_cls_name \
: public DSMModule { \
\
public: \
mod_cls_name() { } \
~mod_cls_name() { } \
\
DSMAction* getAction(const string& from_str); \
DSMCondition* getCondition(const string& from_str); \
};
#define DECLARE_MODULE_BEGIN(mod_cls_name) \
class mod_cls_name \
: public DSMModule { \
\
public: \
mod_cls_name() { } \
~mod_cls_name() { } \
\
DSMAction* getAction(const string& from_str); \
DSMCondition* getCondition(const string& from_str);
#define DECLARE_MODULE_END \
}
#define MOD_ACTIONEXPORT_BEGIN(mod_cls_name) \
DSMAction* mod_cls_name::getAction(const string& from_str) { \
string cmd; \
string params; \
splitCmd(from_str, cmd, params);
#define MOD_ACTIONEXPORT_END \
return NULL; \
}
#define MOD_CONDITIONEXPORT_NONE(mod_cls_name) \
DSMCondition* mod_cls_name::getCondition(const string& from_str) { \
return NULL; \
}
#define MOD_CONDITIONEXPORT_BEGIN(mod_cls_name) \
DSMCondition* mod_cls_name::getCondition(const string& from_str) { \
string cmd; \
string params; \
splitCmd(from_str, cmd, params);
#define MOD_CONDITIONEXPORT_END \
return NULL; \
} \
#endif

@ -36,21 +36,12 @@
#include <fstream>
SC_EXPORT(SCAwsModule);
SC_EXPORT(MOD_CLS_NAME);
ConnectionPool<S3ConnectionPtr>* SCAwsModule::s3ConnectionPool = NULL;
ConnectionPool<SQSConnectionPtr>* SCAwsModule::sqsConnectionPool = NULL;
SCAwsModule::SCAwsModule() {
}
SCAwsModule::~SCAwsModule() {
}
DSMAction* SCAwsModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("aws.s3.put", SCS3PutFileAction);
DEF_CMD("aws.s3.putArray", SCS3PutMultiFileAction);
@ -62,22 +53,9 @@ DSMAction* SCAwsModule::getAction(const string& from_str) {
DEF_CMD("aws.sqs.receiveMessage", SCSQSReceiveMessageAction);
DEF_CMD("aws.sqs.deleteMessage", SCSQSDeleteMessageAction);
return NULL;
}
DSMCondition* SCAwsModule::getCondition(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
// if (cmd == "mysql.hasResult") {
// return new MyHasResultCondition(params, false);
// }
return NULL;
}
} MOD_ACTIONEXPORT_END;
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
int SCAwsModule::preload() {
AmConfigReader cfg;

@ -38,21 +38,26 @@ using namespace aws;
#define DSM_ERRNO_AWS_DELETE "53"
#define DSM_ERRNO_AWS_SEND "54"
class SCAwsModule
: public DSMModule {
#define MOD_CLS_NAME SCAwsModule
public:
SCAwsModule();
~SCAwsModule();
DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
/* class SCAwsModule */
/* : public DSMModule { */
/* public: */
/* SCAwsModule(); */
/* ~SCAwsModule(); */
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
/* DSMAction* getAction(const string& from_str); */
/* DSMCondition* getCondition(const string& from_str); */
int preload();
static ConnectionPool<S3ConnectionPtr>* s3ConnectionPool;
static ConnectionPool<SQSConnectionPtr>* sqsConnectionPool;
};
DECLARE_MODULE_END;
/* }; */
DEF_ACTION_1P(SCS3CreateBucketAction);

@ -34,64 +34,20 @@
#include "DSMSession.h"
#include "ModConference.h"
SC_EXPORT(ConfModule);
ConfModule::ConfModule() {
}
ConfModule::~ConfModule() {
}
void splitCmd(const string& from_str,
string& cmd, string& params) {
size_t b_pos = from_str.find('(');
if (b_pos != string::npos) {
cmd = from_str.substr(0, b_pos);
params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
} else
cmd = from_str;
}
DSMAction* ConfModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
#define DEF_CMD(cmd_name, class_name) \
\
if (cmd == cmd_name) { \
class_name * a = \
new class_name(params); \
a->name = from_str; \
return a; \
}
SC_EXPORT(MOD_CLS_NAME);
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("conference.join", ConfJoinAction);
DEF_CMD("conference.postEvent", ConfPostEventAction);
DEF_CMD("conference.setPlayoutType", ConfSetPlayoutTypeAction);
return NULL;
}
DSMCondition* ConfModule::getCondition(const string& from_str) {
return NULL;
}
#define GET_SCSESSION() \
DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
if (!sc_sess) { \
ERROR("wrong session type\n"); \
return false; \
}
} MOD_ACTIONEXPORT_END;
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
CONST_ACTION_2P(ConfPostEventAction, ',', true);
bool ConfPostEventAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(ConfPostEventAction) {
string channel_id = resolveVars(par1, sess, sc_sess, event_params);
string ev_id = resolveVars(par2, sess, sc_sess, event_params);
@ -102,17 +58,11 @@ bool ConfPostEventAction::execute(AmSession* sess,
}
AmConferenceStatus::postConferenceEvent(channel_id, ev, sess->getLocalTag());
return false;
}
} EXEC_ACTION_END;
CONST_ACTION_2P(ConfJoinAction, ',', true);
bool ConfJoinAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(ConfJoinAction) {
string channel_id = resolveVars(par1, sess, sc_sess, event_params);
string mode = resolveVars(par2, sess, sc_sess, event_params);
@ -147,16 +97,10 @@ bool ConfJoinAction::execute(AmSession* sess,
sc_sess->addToPlaylist(new AmPlaylistItem(play_item, rec_item));
sc_sess->transferOwnership(dsm_chan);
} EXEC_ACTION_END;
return false;
}
bool ConfSetPlayoutTypeAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(ConfSetPlayoutTypeAction) {
string playout_type = resolveVars(arg, sess, sc_sess, event_params);
if (playout_type == "adaptive")
sess->rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
@ -164,6 +108,4 @@ bool ConfSetPlayoutTypeAction::execute(AmSession* sess,
sess->rtp_str.setPlayoutType(JB_PLAYOUT);
else
sess->rtp_str.setPlayoutType(SIMPLE_PLAYOUT);
return false;
}
} EXEC_ACTION_END;

@ -31,17 +31,9 @@
#include "DSMSession.h"
#include <memory>
#define MOD_CLS_NAME ConfModule
class ConfModule
: public DSMModule {
public:
ConfModule();
~ConfModule();
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
};
DECLARE_MODULE(MOD_CLS_NAME);
class DSMConfChannel : public DSMDisposable {
std::auto_ptr<AmConferenceChannel> chan;
@ -54,4 +46,5 @@ class DSMConfChannel : public DSMDisposable {
DEF_ACTION_2P(ConfJoinAction);
DEF_ACTION_2P(ConfPostEventAction);
DEF_ACTION_1P(ConfSetPlayoutTypeAction);
#endif

@ -34,53 +34,24 @@
#include <string.h>
#include "AmSipHeaders.h"
SC_EXPORT(DLGModule);
SC_EXPORT(MOD_CLS_NAME);
DLGModule::DLGModule() {
}
DLGModule::~DLGModule() {
}
void splitCmd(const string& from_str,
string& cmd, string& params) {
size_t b_pos = from_str.find('(');
if (b_pos != string::npos) {
cmd = from_str.substr(0, b_pos);
params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
} else
cmd = from_str;
}
DSMAction* DLGModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
#define DEF_CMD(cmd_name, class_name) \
\
if (cmd == cmd_name) { \
class_name * a = \
new class_name(params); \
a->name = from_str; \
return a; \
}
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("dlg.reply", DLGReplyAction);
DEF_CMD("dlg.acceptInvite", DLGAcceptInviteAction);
DEF_CMD("dlg.bye", DLGByeAction);
DEF_CMD("dlg.connectCalleeRelayed", DLGConnectCalleeRelayedAction);
return NULL;
}
} MOD_ACTIONEXPORT_END;
DSMCondition* DLGModule::getCondition(const string& from_str) {
return NULL;
}
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
// save inivital invite to last_req
sess->last_req.reset(new AmSipRequest(req));
// todo: save this in avar
sess->last_req.reset(new AmSipRequest(req));
return true;
}
@ -92,12 +63,7 @@ bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
}
CONST_ACTION_2P(DLGReplyAction, ',', true);
bool DLGReplyAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(DLGReplyAction) {
string code = resolveVars(par1, sess, sc_sess, event_params);
string reason = resolveVars(par2, sess, sc_sess, event_params);
unsigned int code_i;
@ -117,17 +83,10 @@ bool DLGReplyAction::execute(AmSession* sess,
sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
else
sc_sess->SET_ERRNO(DSM_ERRNO_OK);
return false;
}
} EXEC_ACTION_END;
CONST_ACTION_2P(DLGAcceptInviteAction, ',', true);
bool DLGAcceptInviteAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(DLGAcceptInviteAction) {
// defaults to 200 OK
unsigned int code_i=200;
string reason = "OK";
@ -163,9 +122,7 @@ bool DLGAcceptInviteAction::execute(AmSession* sess,
sess->setStopped();
AmSipDialog::reply_error(*sc_sess->last_req.get(),e.code,e.reason);
}
return false;
}
} EXEC_ACTION_END;
EXEC_ACTION_START(DLGByeAction) {
string hdrs = resolveVars(arg, sess, sc_sess, event_params);
@ -194,5 +151,4 @@ EXEC_ACTION_START(DLGConnectCalleeRelayedAction) {
ERROR("getting B2B session.\n");
sc_sess->B2BconnectCallee(remote_party, remote_uri, true);
} EXEC_ACTION_END;

@ -28,18 +28,11 @@
#define _MOD_DLG_H
#include "DSMModule.h"
class DLGModule
: public DSMModule {
#define MOD_CLS_NAME DLGModule
public:
DLGModule();
~DLGModule();
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
bool onInvite(const AmSipRequest& req, DSMSession* sess);
};
DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
bool onInvite(const AmSipRequest& req, DSMSession* sess);
DECLARE_MODULE_END;
DEF_ACTION_2P(DLGReplyAction);
DEF_ACTION_2P(DLGAcceptInviteAction);

@ -95,10 +95,7 @@ int SCPyModule::preload() {
return 0;
}
DSMAction* SCPyModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
if (NULL==dsm_module) {
ERROR("mod_py must be preloaded! add preload=mod_py to dsm.conf\n");
@ -112,13 +109,10 @@ DSMAction* SCPyModule::getAction(const string& from_str) {
return NULL;
}
return NULL;
}
} MOD_ACTIONEXPORT_END;
DSMCondition* SCPyModule::getCondition(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
if (NULL==dsm_module) {
ERROR("mod_py must be preloaded! add preload=mod_py to dsm.conf\n");
@ -134,8 +128,7 @@ DSMCondition* SCPyModule::getCondition(const string& from_str) {
}
}
return NULL;
}
} MOD_CONDITIONEXPORT_END;
SCPyDictArg::SCPyDictArg()
: pPyObject(NULL) {
@ -316,7 +309,7 @@ SCPyModule::~SCPyModule() {
/* Disable signal handling */
PyOS_FiniInterrupts();
PyInterpreterState_Clear(interp);
PyInterpreterState_Clear(interp);
/* Delete current thread */

@ -31,8 +31,9 @@
#include <Python.h>
#define MOD_CLS_NAME SCPyModule
class SCPyModule
class SCPyModule
: public DSMModule {
public:

@ -35,28 +35,9 @@
#include <sys/types.h>
#include <stdio.h>
SC_EXPORT(SCSysModule);
SC_EXPORT(MOD_CLS_NAME);
SCSysModule::SCSysModule() {
}
SCSysModule::~SCSysModule() {
}
void splitCmd(const string& from_str,
string& cmd, string& params) {
size_t b_pos = from_str.find('(');
if (b_pos != string::npos) {
cmd = from_str.substr(0, b_pos);
params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
} else
cmd = from_str;
}
DSMAction* SCSysModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("sys.mkdir", SCMkDirAction);
DEF_CMD("sys.mkdirRecursive", SCMkDirRecursiveAction);
@ -65,13 +46,9 @@ DSMAction* SCSysModule::getAction(const string& from_str) {
DEF_CMD("sys.unlinkArray", SCUnlinkArrayAction);
DEF_CMD("sys.tmpnam", SCTmpNamAction);
return NULL;
}
} MOD_ACTIONEXPORT_END;
DSMCondition* SCSysModule::getCondition(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
if (cmd == "sys.file_exists") {
return new FileExistsCondition(params, false);
@ -82,8 +59,7 @@ DSMCondition* SCSysModule::getCondition(const string& from_str) {
return new FileExistsCondition(params, true);
}
return NULL;
}
} MOD_CONDITIONEXPORT_END;
MATCH_CONDITION_START(FileExistsCondition) {
DBG("checking file '%s'\n", arg.c_str());

@ -28,16 +28,9 @@
#define _MOD_SYS_H
#include "DSMModule.h"
class SCSysModule
: public DSMModule {
#define MOD_CLS_NAME SCSysModule
public:
SCSysModule();
~SCSysModule();
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
};
DECLARE_MODULE(MOD_CLS_NAME);
DEF_SCCondition(FileExistsCondition);
DEF_ACTION_1P(SCMkDirAction);

@ -36,61 +36,24 @@
#include "AmUriParser.h"
SC_EXPORT(URIModule);
SC_EXPORT(MOD_CLS_NAME);
URIModule::URIModule() {
}
URIModule::~URIModule() {
}
void splitCmd(const string& from_str,
string& cmd, string& params) {
size_t b_pos = from_str.find('(');
if (b_pos != string::npos) {
cmd = from_str.substr(0, b_pos);
params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
} else
cmd = from_str;
}
DSMAction* URIModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
#define DEF_CMD(cmd_name, class_name) \
\
if (cmd == cmd_name) { \
class_name * a = \
new class_name(params); \
a->name = from_str; \
return a; \
}
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("uri.parse", URIParseAction);
DEF_CMD("uri.getHeader", URIGetHeaderAction);
return NULL;
}
} MOD_ACTIONEXPORT_END;
DSMCondition* URIModule::getCondition(const string& from_str) {
return NULL;
}
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
#define GET_SCSESSION() \
DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
if (!sc_sess) { \
ERROR("wrong session type\n"); \
return false; \
}
bool URIModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
sess->var["hdrs"] = req.hdrs;
return true;
}
CONST_ACTION_2P(URIParseAction, ',', true);
bool URIParseAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(URIParseAction) {
string uri = resolveVars(par1, sess, sc_sess, event_params);
string prefix = resolveVars(par2, sess, sc_sess, event_params);
@ -107,24 +70,14 @@ bool URIParseAction::execute(AmSession* sess,
sc_sess->var[prefix+"host"] = p.uri_host;
sc_sess->var[prefix+"param"] = p.uri_param;
return false;
}
bool URIModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
sess->var["hdrs"] = req.hdrs;
return true;
}
} EXEC_ACTION_END;
CONST_ACTION_2P(URIGetHeaderAction, ',', false);
bool URIGetHeaderAction::execute(AmSession* sess,
DSMCondition::EventType event,
map<string,string>* event_params) {
GET_SCSESSION();
EXEC_ACTION_START(URIGetHeaderAction) {
string hname = resolveVars(par1, sess, sc_sess, event_params);
string dstname = resolveVars(par2, sess, sc_sess, event_params);
sc_sess->var[dstname] = getHeader(sc_sess->var["hdrs"], hname); DBG("got header '%s' value '%s' as $%s\n",
hname.c_str(), sc_sess->var[dstname].c_str(), dstname.c_str());
return false;
}
} EXEC_ACTION_END;

@ -28,18 +28,11 @@
#define _MOD_SYS_H
#include "DSMModule.h"
class URIModule
: public DSMModule {
#define MOD_CLS_NAME URIModule
public:
URIModule();
~URIModule();
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
bool onInvite(const AmSipRequest& req, DSMSession* sess);
};
DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
bool onInvite(const AmSipRequest& req, DSMSession* sess);
DECLARE_MODULE_END;
DEF_ACTION_2P(URIParseAction);
DEF_ACTION_2P(URIGetHeaderAction);

@ -34,28 +34,9 @@
#include "DSMSession.h"
#include "AmSession.h"
SC_EXPORT(SCUtilsModule);
SC_EXPORT(MOD_CLS_NAME);
SCUtilsModule::SCUtilsModule() {
}
SCUtilsModule::~SCUtilsModule() {
}
void splitCmd(const string& from_str,
string& cmd, string& params) {
size_t b_pos = from_str.find('(');
if (b_pos != string::npos) {
cmd = from_str.substr(0, b_pos);
params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
} else
cmd = from_str;
}
DSMAction* SCUtilsModule::getAction(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
DEF_CMD("utils.playCountRight", SCUPlayCountRightAction);
DEF_CMD("utils.playCountLeft", SCUPlayCountLeftAction);
@ -64,16 +45,10 @@ DSMAction* SCUtilsModule::getAction(const string& from_str) {
DEF_CMD("utils.rand", SCURandomAction);
DEF_CMD("utils.srand", SCUSRandomAction);
return NULL;
}
DSMCondition* SCUtilsModule::getCondition(const string& from_str) {
string cmd;
string params;
splitCmd(from_str, cmd, params);
} MOD_ACTIONEXPORT_END;
return NULL;
}
MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
bool utils_play_count(DSMSession* sc_sess, unsigned int cnt,
const string& basedir, const string& suffix, bool right) {

@ -28,16 +28,9 @@
#define _MOD_UTILS_H
#include "DSMModule.h"
class SCUtilsModule
: public DSMModule {
#define MOD_CLS_NAME SCUtilsModule
public:
SCUtilsModule();
~SCUtilsModule();
DSMAction* getAction(const string& from_str);
DSMCondition* getCondition(const string& from_str);
};
DECLARE_MODULE(MOD_CLS_NAME);
DEF_ACTION_2P(SCUPlayCountRightAction);
DEF_ACTION_2P(SCUPlayCountLeftAction);

Loading…
Cancel
Save