Browse code

sbc: removed static factory members, use the singleton instance instead

Raphael Coeffic authored on 14/01/2013 09:33:33
Showing 6 changed files
... ...
@@ -339,7 +339,7 @@ string replaceParameters(const string& s,
339 339
 	  string mapping_name = map_str.substr(spos+2);
340 340
 
341 341
 	  string map_res; 
342
-	  if (SBCFactory::regex_mappings.
342
+	  if (SBCFactory::instance()->regex_mappings.
343 343
 	      mapRegex(mapping_name, map_val_replaced.c_str(), map_res)) {
344 344
 	    DBG("matched regex mapping '%s' (orig '%s) in '%s'\n",
345 345
 		map_val_replaced.c_str(), map_val.c_str(), mapping_name.c_str());
... ...
@@ -57,10 +57,6 @@ using std::map;
57 57
 
58 58
 #define MOD_NAME "sbc"
59 59
 
60
-AmConfigReader SBCFactory::cfg;
61
-AmSessionEventHandlerFactory* SBCFactory::session_timer_fact = NULL;
62
-RegexMapper SBCFactory::regex_mappings;
63
-AmEventQueueProcessor SBCFactory::subnot_processor;
64 60
 
65 61
 EXPORT_MODULE_FACTORY(SBCFactory);
66 62
 DEFINE_MODULE_INSTANCE(SBCFactory, MOD_NAME);
... ...
@@ -85,19 +85,19 @@ class SBCFactory: public AmSessionFactory,
85 85
 
86 86
   void onOoDRequest(const AmSipRequest& req);
87 87
 
88
-  static AmConfigReader cfg;
89
-  static AmSessionEventHandlerFactory* session_timer_fact;
88
+  AmConfigReader cfg;
89
+  AmSessionEventHandlerFactory* session_timer_fact;
90 90
 
91 91
   // hack for routing of OoD (e.g. REGISTER) messages
92
-  static AmDynInvokeFactory* gui_fact;
92
+  AmDynInvokeFactory* gui_fact;
93 93
 
94
-  static RegexMapper regex_mappings;
94
+  RegexMapper regex_mappings;
95 95
 
96
-  static AmEventQueueProcessor subnot_processor;
96
+  AmEventQueueProcessor subnot_processor;
97 97
 
98 98
   // DI
99 99
   // DI factory
100
-  AmDynInvoke* getInstance() { return instance(); }
100
+  AmDynInvoke* getInstance() { return this; }
101 101
   // DI API
102 102
   void invoke(const string& method, 
103 103
 	      const AmArg& args, AmArg& ret);
... ...
@@ -240,17 +240,20 @@ int SBCCallLeg::applySSTCfg(AmConfigReader& sst_cfg,
240 240
 			   const AmSipRequest* p_req)
241 241
 {
242 242
   DBG("Enabling SIP Session Timers\n");  
243
-  if (NULL == SBCFactory::session_timer_fact) {
243
+  if (NULL == SBCFactory::instance()->session_timer_fact) {
244 244
     ERROR("session_timer module not loaded - "
245 245
 	  "unable to create call with SST\n");
246 246
     return -1;
247 247
   }
248 248
     
249
-  if (p_req && !SBCFactory::session_timer_fact->onInvite(*p_req, sst_cfg)) {
249
+  if (p_req && !SBCFactory::instance()->session_timer_fact->
250
+      onInvite(*p_req, sst_cfg)) {
250 251
     return -1;
251 252
   }
252 253
 
253
-  AmSessionEventHandler* h = SBCFactory::session_timer_fact->getHandler(this);
254
+  AmSessionEventHandler* h = SBCFactory::instance()->session_timer_fact->
255
+    getHandler(this);
256
+
254 257
   if (!h) {
255 258
     ERROR("could not get a session timer event handler\n");
256 259
     return -1;
... ...
@@ -193,12 +193,13 @@ bool SBCCallProfile::readFromConfiguration(const string& name,
193 193
       dstcfg.setParameter(cfgkey, cfg.getParameter(cfgprefix cfgkey));	\
194 194
     } else if (cfg.hasParameter(cfgkey)) {				\
195 195
       dstcfg.setParameter(cfgkey, cfg.getParameter(cfgkey));		\
196
-    } else if (SBCFactory::cfg.hasParameter(cfgkey)) {			\
197
-      dstcfg.setParameter(cfgkey, SBCFactory::cfg.getParameter(cfgkey)); \
196
+    } else if (SBCFactory::instance()->cfg.hasParameter(cfgkey)) {	\
197
+      dstcfg.setParameter(cfgkey, SBCFactory::instance()->		\
198
+			  cfg.getParameter(cfgkey));			\
198 199
     }
199 200
 
200 201
   if (sst_enabled.size() && sst_enabled != "no") {
201
-    if (NULL == SBCFactory::session_timer_fact) {
202
+    if (NULL == SBCFactory::instance()->session_timer_fact) {
202 203
       ERROR("session_timer module not loaded thus SST not supported, but "
203 204
 	    "required for profile '%s' (%s)\n", name.c_str(), profile_file_name.c_str());
204 205
       return false;
... ...
@@ -337,7 +337,7 @@ int SBCSimpleRelay::start(const AmSipRequest& req, const SBCCallProfile& cp)
337 337
   }
338 338
 
339 339
   // must be added to the same worker thread
340
-  EventQueueWorker* worker = SBCFactory::subnot_processor.getWorker();
340
+  EventQueueWorker* worker = SBCFactory::instance()->subnot_processor.getWorker();
341 341
   if(!worker) return -1;
342 342
 
343 343
   worker->startEventQueue(a_leg);