Browse code

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

Stefan Sayer authored on 14/10/2009 14:00:53
Showing 15 changed files
... ...
@@ -267,4 +267,60 @@ void splitCmd(const string& from_str,
267 267
   return false;					\
268 268
   }
269 269
 
270
+
271
+#define DECLARE_MODULE(mod_cls_name)			\
272
+  class mod_cls_name					\
273
+  : public DSMModule {					\
274
+							\
275
+  public:						\
276
+    mod_cls_name() { }					\
277
+ ~mod_cls_name() { }					\
278
+							\
279
+ DSMAction* getAction(const string& from_str);		\
280
+ DSMCondition* getCondition(const string& from_str);	\
281
+};
282
+
283
+#define DECLARE_MODULE_BEGIN(mod_cls_name)		\
284
+  class mod_cls_name					\
285
+  : public DSMModule {					\
286
+							\
287
+  public:						\
288
+    mod_cls_name() { }					\
289
+ ~mod_cls_name() { }					\
290
+							\
291
+ DSMAction* getAction(const string& from_str);		\
292
+ DSMCondition* getCondition(const string& from_str);	
293
+
294
+
295
+
296
+#define DECLARE_MODULE_END \
297
+  }
298
+
299
+#define MOD_ACTIONEXPORT_BEGIN(mod_cls_name)				\
300
+  DSMAction* mod_cls_name::getAction(const string& from_str) {		\
301
+  string cmd;								\
302
+  string params;							\
303
+  splitCmd(from_str, cmd, params);					
304
+
305
+#define MOD_ACTIONEXPORT_END			\
306
+  return NULL;					\
307
+  }						
308
+
309
+#define MOD_CONDITIONEXPORT_NONE(mod_cls_name)				\
310
+  DSMCondition* mod_cls_name::getCondition(const string& from_str) {	\
311
+    return NULL;							\
312
+  }
313
+
314
+
315
+#define MOD_CONDITIONEXPORT_BEGIN(mod_cls_name)				\
316
+  DSMCondition* mod_cls_name::getCondition(const string& from_str) {	\
317
+  string cmd;								\
318
+  string params;							\
319
+  splitCmd(from_str, cmd, params);
320
+
321
+#define MOD_CONDITIONEXPORT_END \
322
+  return NULL;			\
323
+  }				\
324
+
325
+
270 326
 #endif
... ...
@@ -36,21 +36,12 @@
36 36
 
37 37
 #include <fstream>
38 38
 
39
-SC_EXPORT(SCAwsModule);
39
+SC_EXPORT(MOD_CLS_NAME);
40 40
 
41 41
 ConnectionPool<S3ConnectionPtr>* SCAwsModule::s3ConnectionPool = NULL;
42 42
 ConnectionPool<SQSConnectionPtr>* SCAwsModule::sqsConnectionPool = NULL;
43 43
 
44
-SCAwsModule::SCAwsModule() {
45
-}
46
-
47
-SCAwsModule::~SCAwsModule() {
48
-}
49
-
50
-DSMAction* SCAwsModule::getAction(const string& from_str) {
51
-  string cmd;
52
-  string params;
53
-  splitCmd(from_str, cmd, params);
44
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
54 45
 
55 46
   DEF_CMD("aws.s3.put", SCS3PutFileAction);
56 47
   DEF_CMD("aws.s3.putArray", SCS3PutMultiFileAction);
... ...
@@ -62,22 +53,9 @@ DSMAction* SCAwsModule::getAction(const string& from_str) {
62 53
   DEF_CMD("aws.sqs.receiveMessage", SCSQSReceiveMessageAction);
63 54
   DEF_CMD("aws.sqs.deleteMessage", SCSQSDeleteMessageAction);
64 55
 
65
-  return NULL;
66
-}
67
-
68
-DSMCondition* SCAwsModule::getCondition(const string& from_str) {
69
-  string cmd;
70
-  string params;
71
-  splitCmd(from_str, cmd, params);
72
-
73
-//   if (cmd == "mysql.hasResult") {
74
-//     return new MyHasResultCondition(params, false);
75
-//   }
76
-
77
-
78
-  return NULL;
79
-}
56
+} MOD_ACTIONEXPORT_END;
80 57
 
58
+MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
81 59
 
82 60
 int SCAwsModule::preload() {
83 61
    AmConfigReader cfg;
... ...
@@ -38,21 +38,26 @@ using namespace aws;
38 38
 #define DSM_ERRNO_AWS_DELETE  "53"
39 39
 #define DSM_ERRNO_AWS_SEND    "54"
40 40
 
41
-class SCAwsModule 
42
-: public DSMModule {
41
+#define MOD_CLS_NAME SCAwsModule
43 42
 
44
- public:
45
-  SCAwsModule();
46
-  ~SCAwsModule();
43
+DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
44
+
45
+/* class SCAwsModule  */
46
+/* : public DSMModule { */
47
+
48
+/*  public: */
49
+/*   SCAwsModule(); */
50
+/*   ~SCAwsModule(); */
47 51
   
48
-  DSMAction* getAction(const string& from_str);
49
-  DSMCondition* getCondition(const string& from_str);
52
+/*   DSMAction* getAction(const string& from_str); */
53
+/*   DSMCondition* getCondition(const string& from_str); */
50 54
 
51 55
   int preload();
52 56
 
53 57
   static ConnectionPool<S3ConnectionPtr>* s3ConnectionPool;
54 58
   static ConnectionPool<SQSConnectionPtr>* sqsConnectionPool;
55
-};
59
+DECLARE_MODULE_END;
60
+/* }; */
56 61
 
57 62
 
58 63
 DEF_ACTION_1P(SCS3CreateBucketAction);
... ...
@@ -34,64 +34,20 @@
34 34
 #include "DSMSession.h"
35 35
 #include "ModConference.h"
36 36
 
37
-SC_EXPORT(ConfModule);
38
-
39
-ConfModule::ConfModule() {
40
-}
41
-
42
-ConfModule::~ConfModule() {
43
-}
44
-
45
-void splitCmd(const string& from_str, 
46
-	      string& cmd, string& params) {
47
-  size_t b_pos = from_str.find('(');
48
-  if (b_pos != string::npos) {
49
-    cmd = from_str.substr(0, b_pos);
50
-    params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
51
-  } else 
52
-    cmd = from_str;  
53
-}
54
-
55
-DSMAction* ConfModule::getAction(const string& from_str) {
56
-  string cmd;
57
-  string params;
58
-  splitCmd(from_str, cmd, params);
59
-
60
-#define DEF_CMD(cmd_name, class_name) \
61
-				      \
62
-  if (cmd == cmd_name) {	      \
63
-    class_name * a =		      \
64
-      new class_name(params);	      \
65
-    a->name = from_str;		      \
66
-    return a;			      \
67
-  }
37
+SC_EXPORT(MOD_CLS_NAME);
38
+
39
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
68 40
 
69 41
   DEF_CMD("conference.join", ConfJoinAction);
70 42
   DEF_CMD("conference.postEvent", ConfPostEventAction);
71 43
   DEF_CMD("conference.setPlayoutType", ConfSetPlayoutTypeAction);
72 44
 
73
-  return NULL;
74
-}
75
-
76
-DSMCondition* ConfModule::getCondition(const string& from_str) {
77
-  return NULL;
78
-}
79
-
80
-#define GET_SCSESSION()					 \
81
-  DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
82
-  if (!sc_sess) {					 \
83
-    ERROR("wrong session type\n");			 \
84
-    return false;					 \
85
-  }
45
+} MOD_ACTIONEXPORT_END;
86 46
 
47
+MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
87 48
 
88 49
 CONST_ACTION_2P(ConfPostEventAction, ',', true);
89
-
90
-bool ConfPostEventAction::execute(AmSession* sess, 
91
-			     DSMCondition::EventType event,
92
-			     map<string,string>* event_params) {
93
-  GET_SCSESSION();
94
-
50
+EXEC_ACTION_START(ConfPostEventAction) {
95 51
   string channel_id = resolveVars(par1, sess, sc_sess, event_params);
96 52
   string ev_id = resolveVars(par2, sess, sc_sess, event_params);
97 53
   
... ...
@@ -102,17 +58,11 @@ bool ConfPostEventAction::execute(AmSession* sess,
102 58
   }
103 59
 
104 60
   AmConferenceStatus::postConferenceEvent(channel_id, ev, sess->getLocalTag());
105
-
106
-  return false;
107
-}
61
+} EXEC_ACTION_END;
108 62
 
109 63
 
110 64
 CONST_ACTION_2P(ConfJoinAction, ',', true);
111
-bool ConfJoinAction::execute(AmSession* sess, 
112
-			     DSMCondition::EventType event,
113
-			     map<string,string>* event_params) {
114
-  GET_SCSESSION();
115
-
65
+EXEC_ACTION_START(ConfJoinAction) {
116 66
   string channel_id = resolveVars(par1, sess, sc_sess, event_params);
117 67
   string mode = resolveVars(par2, sess, sc_sess, event_params);
118 68
 
... ...
@@ -147,16 +97,10 @@ bool ConfJoinAction::execute(AmSession* sess,
147 97
   sc_sess->addToPlaylist(new AmPlaylistItem(play_item, rec_item));
148 98
 
149 99
   sc_sess->transferOwnership(dsm_chan);
100
+} EXEC_ACTION_END;
150 101
 
151
-  return false;
152
-}
153
-
154
-
155
-bool ConfSetPlayoutTypeAction::execute(AmSession* sess, 
156
-				       DSMCondition::EventType event,
157
-				       map<string,string>* event_params) {
158
-  GET_SCSESSION();
159 102
 
103
+EXEC_ACTION_START(ConfSetPlayoutTypeAction) {
160 104
   string playout_type = resolveVars(arg, sess, sc_sess, event_params);
161 105
   if (playout_type == "adaptive")
162 106
     sess->rtp_str.setPlayoutType(ADAPTIVE_PLAYOUT);
... ...
@@ -164,6 +108,4 @@ bool ConfSetPlayoutTypeAction::execute(AmSession* sess,
164 108
     sess->rtp_str.setPlayoutType(JB_PLAYOUT);
165 109
   else 
166 110
     sess->rtp_str.setPlayoutType(SIMPLE_PLAYOUT);
167
-
168
-  return false;
169
-}
111
+} EXEC_ACTION_END;
... ...
@@ -31,17 +31,9 @@
31 31
 #include "DSMSession.h"
32 32
 
33 33
 #include <memory>
34
+#define MOD_CLS_NAME ConfModule
34 35
 
35
-class ConfModule 
36
-: public DSMModule {
37
-
38
- public:
39
-  ConfModule();
40
-  ~ConfModule();
41
-  
42
-  DSMAction* getAction(const string& from_str);
43
-  DSMCondition* getCondition(const string& from_str);
44
-};
36
+DECLARE_MODULE(MOD_CLS_NAME);
45 37
 
46 38
 class DSMConfChannel : public DSMDisposable {
47 39
   std::auto_ptr<AmConferenceChannel> chan;
... ...
@@ -54,4 +46,5 @@ class DSMConfChannel : public DSMDisposable {
54 46
 DEF_ACTION_2P(ConfJoinAction);
55 47
 DEF_ACTION_2P(ConfPostEventAction);
56 48
 DEF_ACTION_1P(ConfSetPlayoutTypeAction);
49
+
57 50
 #endif
... ...
@@ -34,53 +34,24 @@
34 34
 #include <string.h>
35 35
 #include "AmSipHeaders.h"
36 36
 
37
-SC_EXPORT(DLGModule);
37
+SC_EXPORT(MOD_CLS_NAME);
38 38
 
39
-DLGModule::DLGModule() {
40
-}
41
-
42
-DLGModule::~DLGModule() {
43
-}
44
-
45
-void splitCmd(const string& from_str, 
46
-	      string& cmd, string& params) {
47
-  size_t b_pos = from_str.find('(');
48
-  if (b_pos != string::npos) {
49
-    cmd = from_str.substr(0, b_pos);
50
-    params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
51
-  } else 
52
-    cmd = from_str;  
53
-}
54 39
 
55
-DSMAction* DLGModule::getAction(const string& from_str) {
56
-  string cmd;
57
-  string params;
58
-  splitCmd(from_str, cmd, params);
59
-
60
-#define DEF_CMD(cmd_name, class_name) \
61
-				      \
62
-  if (cmd == cmd_name) {	      \
63
-    class_name * a =		      \
64
-      new class_name(params);	      \
65
-    a->name = from_str;		      \
66
-    return a;			      \
67
-  }
40
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
68 41
 
69 42
   DEF_CMD("dlg.reply", DLGReplyAction);
70 43
   DEF_CMD("dlg.acceptInvite", DLGAcceptInviteAction);
71 44
   DEF_CMD("dlg.bye", DLGByeAction);
72 45
   DEF_CMD("dlg.connectCalleeRelayed", DLGConnectCalleeRelayedAction);
73 46
 
74
-  return NULL;
75
-}
47
+} MOD_ACTIONEXPORT_END;
76 48
 
77
-DSMCondition* DLGModule::getCondition(const string& from_str) {
78
-  return NULL;
79
-}
49
+MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
80 50
 
81 51
 bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
82 52
   // save inivital invite to last_req 
83
-  sess->last_req.reset(new AmSipRequest(req));
53
+  // todo: save this in avar
54
+ sess->last_req.reset(new AmSipRequest(req));
84 55
   return true;
85 56
 }
86 57
 
... ...
@@ -92,12 +63,7 @@ bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
92 63
   }
93 64
 
94 65
 CONST_ACTION_2P(DLGReplyAction, ',', true);
95
-
96
-bool DLGReplyAction::execute(AmSession* sess, 
97
-			     DSMCondition::EventType event,
98
-			     map<string,string>* event_params) {
99
-  GET_SCSESSION();
100
-
66
+EXEC_ACTION_START(DLGReplyAction) {
101 67
   string code = resolveVars(par1, sess, sc_sess, event_params);
102 68
   string reason = resolveVars(par2, sess, sc_sess, event_params);
103 69
   unsigned int code_i;
... ...
@@ -117,17 +83,10 @@ bool DLGReplyAction::execute(AmSession* sess,
117 83
     sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
118 84
   else
119 85
     sc_sess->SET_ERRNO(DSM_ERRNO_OK);
120
-
121
-  return false;
122
-}
86
+} EXEC_ACTION_END;
123 87
 
124 88
 CONST_ACTION_2P(DLGAcceptInviteAction, ',', true);
125
-
126
-bool DLGAcceptInviteAction::execute(AmSession* sess, 
127
-				     DSMCondition::EventType event,
128
-				     map<string,string>* event_params) {
129
-  GET_SCSESSION();
130
-
89
+EXEC_ACTION_START(DLGAcceptInviteAction) {
131 90
   // defaults to 200 OK
132 91
   unsigned int code_i=200;
133 92
   string reason = "OK";
... ...
@@ -163,9 +122,7 @@ bool DLGAcceptInviteAction::execute(AmSession* sess,
163 122
     sess->setStopped();
164 123
     AmSipDialog::reply_error(*sc_sess->last_req.get(),e.code,e.reason);
165 124
   }
166
-
167
-  return false;
168
-}
125
+} EXEC_ACTION_END;
169 126
 
170 127
 EXEC_ACTION_START(DLGByeAction) {
171 128
   string hdrs = resolveVars(arg, sess, sc_sess, event_params);
... ...
@@ -194,5 +151,4 @@ EXEC_ACTION_START(DLGConnectCalleeRelayedAction) {
194 151
     ERROR("getting B2B session.\n");
195 152
 
196 153
   sc_sess->B2BconnectCallee(remote_party, remote_uri, true);
197
-
198 154
 } EXEC_ACTION_END;
... ...
@@ -28,18 +28,11 @@
28 28
 #define _MOD_DLG_H
29 29
 #include "DSMModule.h"
30 30
 
31
-class DLGModule 
32
-: public DSMModule {
31
+#define MOD_CLS_NAME DLGModule 
33 32
 
34
- public:
35
-  DLGModule();
36
-  ~DLGModule();
37
-  
38
-  DSMAction* getAction(const string& from_str);
39
-  DSMCondition* getCondition(const string& from_str);
40
-
41
-  bool onInvite(const AmSipRequest& req, DSMSession* sess);
42
-};
33
+DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
34
+bool onInvite(const AmSipRequest& req, DSMSession* sess);
35
+DECLARE_MODULE_END;
43 36
 
44 37
 DEF_ACTION_2P(DLGReplyAction);
45 38
 DEF_ACTION_2P(DLGAcceptInviteAction);
... ...
@@ -95,10 +95,7 @@ int SCPyModule::preload() {
95 95
   return 0;
96 96
 }
97 97
 
98
-DSMAction* SCPyModule::getAction(const string& from_str) {
99
-  string cmd;
100
-  string params;
101
-  splitCmd(from_str, cmd, params);
98
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
102 99
 
103 100
   if (NULL==dsm_module) {
104 101
     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) {
112 109
     return NULL;
113 110
   }
114 111
 
115
-  return NULL;
116
-}
112
+} MOD_ACTIONEXPORT_END;
113
+
117 114
 
118
-DSMCondition* SCPyModule::getCondition(const string& from_str) {
119
-  string cmd;
120
-  string params;
121
-  splitCmd(from_str, cmd, params);
115
+MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
122 116
 
123 117
   if (NULL==dsm_module) {
124 118
     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) {
134 128
     }
135 129
   }
136 130
 
137
-  return NULL;
138
-}
131
+} MOD_CONDITIONEXPORT_END;
139 132
 
140 133
 SCPyDictArg::SCPyDictArg() 
141 134
  : pPyObject(NULL) {
... ...
@@ -316,7 +309,7 @@ SCPyModule::~SCPyModule() {
316 309
   /* Disable signal handling */
317 310
   PyOS_FiniInterrupts();
318 311
 
319
-    PyInterpreterState_Clear(interp);
312
+  PyInterpreterState_Clear(interp);
320 313
   
321 314
   
322 315
   /* Delete current thread */
... ...
@@ -31,8 +31,9 @@
31 31
 
32 32
 #include <Python.h>
33 33
 
34
+#define MOD_CLS_NAME SCPyModule
34 35
 
35
-class SCPyModule 
36
+class SCPyModule
36 37
 : public DSMModule {
37 38
 
38 39
  public:
... ...
@@ -35,28 +35,9 @@
35 35
 #include <sys/types.h>
36 36
 #include <stdio.h>
37 37
 
38
-SC_EXPORT(SCSysModule);
38
+SC_EXPORT(MOD_CLS_NAME);
39 39
 
40
-SCSysModule::SCSysModule() {
41
-}
42
-
43
-SCSysModule::~SCSysModule() {
44
-}
45
-
46
-void splitCmd(const string& from_str, 
47
-	      string& cmd, string& params) {
48
-  size_t b_pos = from_str.find('(');
49
-  if (b_pos != string::npos) {
50
-    cmd = from_str.substr(0, b_pos);
51
-    params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
52
-  } else 
53
-    cmd = from_str;  
54
-}
55
-
56
-DSMAction* SCSysModule::getAction(const string& from_str) {
57
-  string cmd;
58
-  string params;
59
-  splitCmd(from_str, cmd, params);
40
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
60 41
 
61 42
   DEF_CMD("sys.mkdir", SCMkDirAction);
62 43
   DEF_CMD("sys.mkdirRecursive", SCMkDirRecursiveAction);
... ...
@@ -65,13 +46,9 @@ DSMAction* SCSysModule::getAction(const string& from_str) {
65 46
   DEF_CMD("sys.unlinkArray", SCUnlinkArrayAction);
66 47
   DEF_CMD("sys.tmpnam", SCTmpNamAction);
67 48
 
68
-  return NULL;
69
-}
49
+} MOD_ACTIONEXPORT_END;
70 50
 
71
-DSMCondition* SCSysModule::getCondition(const string& from_str) {
72
-  string cmd;
73
-  string params;
74
-  splitCmd(from_str, cmd, params);
51
+MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
75 52
 
76 53
   if (cmd == "sys.file_exists") {
77 54
     return new FileExistsCondition(params, false);
... ...
@@ -82,8 +59,7 @@ DSMCondition* SCSysModule::getCondition(const string& from_str) {
82 59
     return new FileExistsCondition(params, true);
83 60
   }
84 61
 
85
-  return NULL;
86
-}
62
+} MOD_CONDITIONEXPORT_END;
87 63
 
88 64
 MATCH_CONDITION_START(FileExistsCondition) {
89 65
   DBG("checking file '%s'\n", arg.c_str());
... ...
@@ -28,16 +28,9 @@
28 28
 #define _MOD_SYS_H
29 29
 #include "DSMModule.h"
30 30
 
31
-class SCSysModule 
32
-: public DSMModule {
31
+#define MOD_CLS_NAME SCSysModule
33 32
 
34
- public:
35
-  SCSysModule();
36
-  ~SCSysModule();
37
-  
38
-  DSMAction* getAction(const string& from_str);
39
-  DSMCondition* getCondition(const string& from_str);
40
-};
33
+DECLARE_MODULE(MOD_CLS_NAME);
41 34
 
42 35
 DEF_SCCondition(FileExistsCondition);
43 36
 DEF_ACTION_1P(SCMkDirAction);
... ...
@@ -36,61 +36,24 @@
36 36
 
37 37
 #include "AmUriParser.h"
38 38
 
39
-SC_EXPORT(URIModule);
39
+SC_EXPORT(MOD_CLS_NAME);
40 40
 
41
-URIModule::URIModule() {
42
-}
43
-
44
-URIModule::~URIModule() {
45
-}
46
-
47
-void splitCmd(const string& from_str, 
48
-	      string& cmd, string& params) {
49
-  size_t b_pos = from_str.find('(');
50
-  if (b_pos != string::npos) {
51
-    cmd = from_str.substr(0, b_pos);
52
-    params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
53
-  } else 
54
-    cmd = from_str;  
55
-}
56
-
57
-DSMAction* URIModule::getAction(const string& from_str) {
58
-  string cmd;
59
-  string params;
60
-  splitCmd(from_str, cmd, params);
61
-
62
-#define DEF_CMD(cmd_name, class_name) \
63
-				      \
64
-  if (cmd == cmd_name) {	      \
65
-    class_name * a =		      \
66
-      new class_name(params);	      \
67
-    a->name = from_str;		      \
68
-    return a;			      \
69
-  }
41
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
70 42
 
71 43
   DEF_CMD("uri.parse", URIParseAction);
72 44
   DEF_CMD("uri.getHeader", URIGetHeaderAction);
73 45
 
74
-  return NULL;
75
-}
46
+} MOD_ACTIONEXPORT_END;
76 47
 
77
-DSMCondition* URIModule::getCondition(const string& from_str) {
78
-  return NULL;
79
-}
48
+MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
80 49
 
81
-#define GET_SCSESSION()					 \
82
-  DSMSession* sc_sess = dynamic_cast<DSMSession*>(sess); \
83
-  if (!sc_sess) {					 \
84
-    ERROR("wrong session type\n");			 \
85
-    return false;					 \
86
-  }
50
+bool URIModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
51
+  sess->var["hdrs"] = req.hdrs;
52
+  return true;
53
+}
87 54
 
88 55
 CONST_ACTION_2P(URIParseAction, ',', true);
89
-
90
-bool URIParseAction::execute(AmSession* sess, 
91
-			     DSMCondition::EventType event,
92
-			     map<string,string>* event_params) {
93
-  GET_SCSESSION();
56
+EXEC_ACTION_START(URIParseAction) {
94 57
 
95 58
   string uri = resolveVars(par1, sess, sc_sess, event_params);
96 59
   string prefix = resolveVars(par2, sess, sc_sess, event_params);
... ...
@@ -107,24 +70,14 @@ bool URIParseAction::execute(AmSession* sess,
107 70
   sc_sess->var[prefix+"host"]         = p.uri_host;
108 71
   sc_sess->var[prefix+"param"]        = p.uri_param;
109 72
 
110
-  return false;
111
-}
112
-
113
-bool URIModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
114
-  sess->var["hdrs"] = req.hdrs;
115
-  return true;
116
-}
73
+} EXEC_ACTION_END;
117 74
 
118 75
 CONST_ACTION_2P(URIGetHeaderAction, ',', false);
119
-bool URIGetHeaderAction::execute(AmSession* sess, 
120
-				 DSMCondition::EventType event,
121
-				 map<string,string>* event_params) {
122
-  GET_SCSESSION();
76
+EXEC_ACTION_START(URIGetHeaderAction) {
123 77
 
124 78
   string hname  = resolveVars(par1, sess, sc_sess, event_params);
125 79
   string dstname = resolveVars(par2, sess, sc_sess, event_params);
126 80
 
127 81
   sc_sess->var[dstname] = getHeader(sc_sess->var["hdrs"], hname);  DBG("got header '%s' value '%s' as $%s\n", 
128 82
       hname.c_str(), sc_sess->var[dstname].c_str(), dstname.c_str());
129
-  return false;
130
-}
83
+} EXEC_ACTION_END;
... ...
@@ -28,18 +28,11 @@
28 28
 #define _MOD_SYS_H
29 29
 #include "DSMModule.h"
30 30
 
31
-class URIModule 
32
-: public DSMModule {
31
+#define MOD_CLS_NAME URIModule
33 32
 
34
- public:
35
-  URIModule();
36
-  ~URIModule();
37
-  
38
-  DSMAction* getAction(const string& from_str);
39
-  DSMCondition* getCondition(const string& from_str);
40
-
41
-  bool onInvite(const AmSipRequest& req, DSMSession* sess);
42
-};
33
+DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
34
+bool onInvite(const AmSipRequest& req, DSMSession* sess);
35
+DECLARE_MODULE_END;
43 36
 
44 37
 DEF_ACTION_2P(URIParseAction);
45 38
 DEF_ACTION_2P(URIGetHeaderAction);
... ...
@@ -34,28 +34,9 @@
34 34
 #include "DSMSession.h"
35 35
 #include "AmSession.h"
36 36
 
37
-SC_EXPORT(SCUtilsModule);
37
+SC_EXPORT(MOD_CLS_NAME);
38 38
 
39
-SCUtilsModule::SCUtilsModule() {
40
-}
41
-
42
-SCUtilsModule::~SCUtilsModule() {
43
-}
44
-
45
-void splitCmd(const string& from_str, 
46
-	      string& cmd, string& params) {
47
-  size_t b_pos = from_str.find('(');
48
-  if (b_pos != string::npos) {
49
-    cmd = from_str.substr(0, b_pos);
50
-    params = from_str.substr(b_pos + 1, from_str.rfind(')') - b_pos -1);
51
-  } else 
52
-    cmd = from_str;  
53
-}
54
-
55
-DSMAction* SCUtilsModule::getAction(const string& from_str) {
56
-  string cmd;
57
-  string params;
58
-  splitCmd(from_str, cmd, params);
39
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
59 40
 
60 41
   DEF_CMD("utils.playCountRight", SCUPlayCountRightAction);
61 42
   DEF_CMD("utils.playCountLeft",  SCUPlayCountLeftAction);
... ...
@@ -64,16 +45,10 @@ DSMAction* SCUtilsModule::getAction(const string& from_str) {
64 45
   DEF_CMD("utils.rand", SCURandomAction);
65 46
   DEF_CMD("utils.srand", SCUSRandomAction);
66 47
 
67
-  return NULL;
68
-}
69 48
 
70
-DSMCondition* SCUtilsModule::getCondition(const string& from_str) {
71
-  string cmd;
72
-  string params;
73
-  splitCmd(from_str, cmd, params);
49
+} MOD_ACTIONEXPORT_END;
74 50
 
75
-  return NULL;
76
-}
51
+MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
77 52
 
78 53
 bool utils_play_count(DSMSession* sc_sess, unsigned int cnt, 
79 54
 		      const string& basedir, const string& suffix, bool right) {
... ...
@@ -28,16 +28,9 @@
28 28
 #define _MOD_UTILS_H
29 29
 #include "DSMModule.h"
30 30
 
31
-class SCUtilsModule 
32
-: public DSMModule {
31
+#define MOD_CLS_NAME SCUtilsModule
33 32
 
34
- public:
35
-  SCUtilsModule();
36
-  ~SCUtilsModule();
37
-  
38
-  DSMAction* getAction(const string& from_str);
39
-  DSMCondition* getCondition(const string& from_str);
40
-};
33
+DECLARE_MODULE(MOD_CLS_NAME);
41 34
 
42 35
 DEF_ACTION_2P(SCUPlayCountRightAction);
43 36
 DEF_ACTION_2P(SCUPlayCountLeftAction);