Browse code

combined AmArg and AmArgArray into one class

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@383 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 04/07/2007 21:19:06
Showing 28 changed files
... ...
@@ -95,7 +95,7 @@ DIDial::DIDial() {
95 95
 
96 96
 DIDial::~DIDial() { }
97 97
 
98
-void DIDial::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
98
+void DIDial::invoke(const string& method, const AmArg& args, AmArg& ret)
99 99
 {
100 100
     if(method == "dial"){
101 101
        ret.push(dialout(args.get(0).asCStr(), 
... ...
@@ -43,5 +43,5 @@ class DIDial : public AmDynInvoke
43 43
   DIDial();
44 44
   ~DIDial();
45 45
   static DIDial* instance();
46
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
46
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
47 47
 };
... ...
@@ -38,7 +38,7 @@ int DILog::onLoad() {
38 38
 
39 39
 DILog::~DILog() { }
40 40
 
41
-void DILog::invoke(const string& method, const AmArgArray& args, AmArgArray& ret) {
41
+void DILog::invoke(const string& method, const AmArg& args, AmArg& ret) {
42 42
   if(method == "dumplog") {
43 43
     ret.push(dumpLog().c_str());
44 44
   } else if(method == "dumplogtodisk") {
... ...
@@ -22,7 +22,7 @@ class DILog : public AmLoggingFacility, public AmDynInvoke, public AmDynInvokeFa
22 22
   AmDynInvoke* getInstance() { return instance(); }
23 23
   // DI API
24 24
   static DILog* instance();
25
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
25
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
26 26
 
27 27
   int onLoad();
28 28
 
... ...
@@ -37,7 +37,7 @@ CCAcc::CCAcc() {
37 37
 
38 38
 CCAcc::~CCAcc() { }
39 39
 
40
-void CCAcc::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
40
+void CCAcc::invoke(const string& method, const AmArg& args, AmArg& ret)
41 41
 {
42 42
     if(method == "getCredit"){
43 43
       ret.push(getCredit(args.get(0).asCStr()));
... ...
@@ -23,5 +23,5 @@ class CCAcc : public AmDynInvoke
23 23
   CCAcc();
24 24
   ~CCAcc();
25 25
   static CCAcc* instance();
26
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
26
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
27 27
 };
... ...
@@ -123,7 +123,7 @@ void MyCCDialog::onDtmf(int event, int duration) {
123 123
       pin +=int2str(event);
124 124
       DBG("pin is now '%s'\n", pin.c_str());
125 125
     } else {
126
-      	AmArgArray di_args,ret;
126
+      	AmArg di_args,ret;
127 127
 	di_args.push(pin.c_str());
128 128
 	cc_acc->invoke("getCredit", di_args, ret);
129 129
 	credit = ret.get(0).asInt();
... ...
@@ -195,7 +195,7 @@ void MyCCDialog::onOtherReply(const AmSipReply& reply) {
195 195
 	startAccounting();
196 196
 	setInOut(NULL, NULL);
197 197
 	// set the call timer
198
-	AmArgArray di_args,ret;
198
+	AmArg di_args,ret;
199 199
 	di_args.push(TIMERID_CREDIT_TIMEOUT);
200 200
 	di_args.push(credit); // in seconds
201 201
 	di_args.push(dlg.local_tag.c_str());
... ...
@@ -244,7 +244,7 @@ void MyCCDialog::stopAccounting() {
244 244
     if (now.tv_usec>500000) now.tv_sec++;
245 245
     DBG("Call lasted %ld seconds\n", now.tv_sec);
246 246
 
247
-    AmArgArray di_args,ret;
247
+    AmArg di_args,ret;
248 248
     di_args.push(pin.c_str());
249 249
     di_args.push((int)now.tv_sec);
250 250
     cc_acc->invoke("subtractCredit", di_args, ret);
... ...
@@ -134,9 +134,9 @@ void XMLRPC2DIServer::registerMethods(const std::string& iface) {
134 134
 	    iface.c_str());
135 135
       return;
136 136
     } 
137
-    AmArgArray dummy, fct_list;
137
+    AmArg dummy, fct_list;
138 138
     di->invoke("_list", dummy, fct_list);
139
-    
139
+
140 140
     for (unsigned int i=0;i<fct_list.size();i++) {
141 141
       string method = fct_list.get(i).asCStr();
142 142
       // see whether method already registered
... ...
@@ -165,7 +165,7 @@ void XMLRPC2DIServer::registerMethods(const std::string& iface) {
165 165
   } catch (AmDynInvoke::NotImplemented& e) {
166 166
     ERROR("Not implemented in interface '%s': '%s'\n", 
167 167
 	  iface.c_str(), e.what.c_str());
168
-  } catch (const AmArgArray::OutOfBoundsException& e) {
168
+  } catch (const AmArg::OutOfBoundsException& e) {
169 169
     ERROR("Out of bounds exception occured while exporting interface '%s'\n", 
170 170
 	  iface.c_str());
171 171
   } catch (...) {
... ...
@@ -218,7 +218,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
218 218
 	fact_name.c_str(), fct_name.c_str());
219 219
 
220 220
     // get args
221
-    AmArgArray args;
221
+    AmArg args;
222 222
     XMLRPC2DIServer::xmlrpcval2amarg(params, args, 2);
223 223
   
224 224
     AmDynInvokeFactory* di_f = AmPlugIn::instance()->getFactory4Di(fact_name);
... ...
@@ -229,7 +229,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
229 229
     if(!di){
230 230
       throw XmlRpcException("could not get instance from factory", 500);
231 231
     }
232
-    AmArgArray ret;
232
+    AmArg ret;
233 233
     di->invoke(fct_name, args, ret);
234 234
   
235 235
     XMLRPC2DIServer::amarg2xmlrpcval(ret, result);
... ...
@@ -240,8 +240,8 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
240 240
   } catch (const AmDynInvoke::NotImplemented& e) {
241 241
     throw XmlRpcException("Exception: AmDynInvoke::NotImplemented: "
242 242
 			  + e.what, 504);
243
-  } catch (const AmArgArray::OutOfBoundsException& e) {
244
-    throw XmlRpcException("Exception: AmArgArray out of bounds - paramter number mismatch.", 300);
243
+  } catch (const AmArg::OutOfBoundsException& e) {
244
+    throw XmlRpcException("Exception: AmArg out of bounds - paramter number mismatch.", 300);
245 245
   } catch (const string& e) {
246 246
     throw XmlRpcException("Exception: "+e, 500);
247 247
   } catch (...) {
... ...
@@ -249,7 +249,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
249 249
   }
250 250
 }
251 251
 
252
-void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a, 
252
+void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArg& a, 
253 253
 				      unsigned int start_index) {
254 254
   if (v.valid()) {
255 255
     for (int i=start_index; i<v.size();i++) {
... ...
@@ -264,45 +264,25 @@ void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a,
264 264
   } 
265 265
 }
266 266
 
267
-void XMLRPC2DIServer::amarg2xmlrpcval(AmArgArray& a, 
267
+void XMLRPC2DIServer::amarg2xmlrpcval(AmArg& a, 
268 268
 				      XmlRpcValue& result) {
269
-  if (a.size()) {
270
-    result.setSize(a.size());
271
-    
272
-    for (unsigned int i=0;i<a.size();i++) {
273
-	const AmArg& r = a.get(i);
274
-	amarg2xmlrpcval(r, result, i);
275
-    }
276
-  }
277
-}
278
-
279
-// WARNING: AmArgArrays are deleted by this function!
280
-void XMLRPC2DIServer::amarg2xmlrpcval(const AmArg& a, XmlRpcValue& result, 
281
-				      unsigned int pos) {
282 269
   switch (a.getType()) {
283 270
   case AmArg::CStr:  
284
-    result[pos]= string(a.asCStr()); break;
271
+    result = string(a.asCStr()); break;
285 272
 
286 273
   case AmArg::Int:  
287
-    result[pos]=a.asInt(); break;
274
+    result=a.asInt(); break;
288 275
 
289 276
   case AmArg::Double: 
290
-    result[pos]=a.asDouble(); break;
277
+    result=a.asDouble(); break;
291 278
 
292
-  case AmArg::AObject: {
293
-    AmArgArray* arr = dynamic_cast<AmArgArray*>(a.asObject());
294
-    if (NULL != arr) {
295
-      result[pos].setSize(arr->size());
296
-    
297
-      for (unsigned int i=0;i<arr->size();i++) {
298
-	const AmArg& r = arr->get(i);
299
-	amarg2xmlrpcval(r, result[pos], i);
300
-      }
301
-      delete arr; 
302
-    } else {
303
-      WARN("unsupported return value type of parameter %d (not AmArgArray)\n", pos);
279
+  case AmArg::Array:
280
+    result.setSize(a.size());
281
+    for (size_t i=0;i<a.size();i++) {
282
+      // duh... recursion...
283
+      amarg2xmlrpcval(a.get(i), result[i]);
304 284
     }
305
-  } break;
285
+    break;
306 286
   default: { WARN("unsupported return value type %d\n", a.getType()); } break;
307 287
     // TODO: do sth with the data here ?
308 288
   }
... ...
@@ -330,7 +310,7 @@ void DIMethodProxy::execute(XmlRpcValue& params,
330 310
       throw XmlRpcException("could not get instance from factory", 500);
331 311
     }
332 312
     
333
-    AmArgArray args, ret;
313
+    AmArg args, ret;
334 314
     XMLRPC2DIServer::xmlrpcval2amarg(params, args);
335 315
     
336 316
     DBG("XMLRPC2DI '%s': function '%s'\n", 
... ...
@@ -346,8 +326,8 @@ void DIMethodProxy::execute(XmlRpcValue& params,
346 326
   } catch (const AmDynInvoke::NotImplemented& e) {
347 327
     throw XmlRpcException("Exception: AmDynInvoke::NotImplemented: "
348 328
 			  + e.what, 504);
349
-  } catch (const AmArgArray::OutOfBoundsException& e) {
350
-    throw XmlRpcException("Exception: AmArgArray out of bounds - paramter number mismatch.", 300);
329
+  } catch (const AmArg::OutOfBoundsException& e) {
330
+    throw XmlRpcException("Exception: AmArg out of bounds - paramter number mismatch.", 300);
351 331
   } catch (const string& e) {
352 332
     throw XmlRpcException("Exception: "+e, 500);
353 333
   } catch (...) {
... ...
@@ -89,15 +89,11 @@ class XMLRPC2DIServer : public AmThread {
89 89
   void run();
90 90
   void on_stop();
91 91
   
92
-  static void xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a, 
92
+  static void xmlrpcval2amarg(XmlRpcValue& v, AmArg& a, 
93 93
 			      unsigned int start_index = 0);
94 94
 
95 95
   /** convert all args in a into result*/
96
-  static void amarg2xmlrpcval(AmArgArray& a, XmlRpcValue& result);
97
-
98
-  /** convert arg a result[pos] */
99
-  static void amarg2xmlrpcval(const AmArg& a, XmlRpcValue& result, 
100
-			      unsigned int pos);
96
+  static void amarg2xmlrpcval(AmArg& a, XmlRpcValue& result);
101 97
 };
102 98
 
103 99
 
... ...
@@ -380,7 +380,7 @@ static PyObject* IvrDialogBase_setTimer(IvrDialogBase* self, PyObject* args)
380 380
       return NULL;
381 381
     }
382 382
 
383
-    AmArgArray di_args,ret;
383
+    AmArg di_args,ret;
384 384
     di_args.push(id);
385 385
     di_args.push(interval);
386 386
     di_args.push(self->p_dlg->getLocalTag().c_str());
... ...
@@ -405,7 +405,7 @@ static PyObject* IvrDialogBase_removeTimer(IvrDialogBase* self, PyObject* args)
405 405
       return NULL;
406 406
     }
407 407
 
408
-    AmArgArray di_args,ret;
408
+    AmArg di_args,ret;
409 409
     di_args.push(id);
410 410
     di_args.push(self->p_dlg->getLocalTag().c_str());
411 411
 
... ...
@@ -421,7 +421,7 @@ static PyObject* IvrDialogBase_removeTimers(IvrDialogBase* self, PyObject* args)
421 421
 {
422 422
     assert(self->p_dlg);
423 423
     
424
-    AmArgArray di_args,ret;
424
+    AmArg di_args,ret;
425 425
     di_args.push(self->p_dlg->getLocalTag().c_str());
426 426
 
427 427
     self->p_dlg->user_timer->
... ...
@@ -396,7 +396,7 @@ void SIPRegistrarClient::onNewRegistration(SIPNewRegistrationEvent* new_reg) {
396 396
     DBG("enabling UAC Auth for new registration.\n");
397 397
     
398 398
     // get a sessionEventHandler from uac_auth
399
-    AmArgArray di_args,ret;
399
+    AmArg di_args,ret;
400 400
     AmArg a;
401 401
     a.setBorrowedPointer(reg);
402 402
     di_args.push(a);
... ...
@@ -553,8 +553,8 @@ bool SIPRegistrarClient::getRegistrationState(const string& handle,
553 553
 	return res;
554 554
 }
555 555
 
556
-void SIPRegistrarClient::invoke(const string& method, const AmArgArray& args, 
557
-								AmArgArray& ret)
556
+void SIPRegistrarClient::invoke(const string& method, const AmArg& args, 
557
+								AmArg& ret)
558 558
 {
559 559
     if(method == "createRegistration"){
560 560
 		ret.push(createRegistration(args.get(0).asCStr(),
... ...
@@ -175,7 +175,7 @@ public:
175 175
 	// DI API
176 176
     static SIPRegistrarClient* instance();
177 177
 	void invoke(const string& method, 
178
-				const AmArgArray& args, AmArgArray& ret);
178
+				const AmArg& args, AmArg& ret);
179 179
 	
180 180
     bool onSipReply(const AmSipReply& rep);
181 181
 	int onLoad();
... ...
@@ -535,7 +535,7 @@ void AnswerMachineDialog::process(AmEvent* event)
535 535
 	    case 0:
536 536
 		playlist.addToPlaylist(new AmPlaylistItem(NULL,&a_msg));
537 537
 		
538
-		{AmArgArray di_args,ret;
538
+		{AmArg di_args,ret;
539 539
 		di_args.push(RECORD_TIMER);
540 540
 		di_args.push(AnswerMachineFactory::MaxRecordTime);
541 541
 		di_args.push(getLocalTag().c_str());
... ...
@@ -17,13 +17,13 @@ bool ConferenceRoomParticipant::expired(const struct timeval& now) {
17 17
     (unsigned int)diff.tv_sec > PARTICIPANT_EXPIRED_DELAY;
18 18
 }
19 19
 
20
-AmArgArray* ConferenceRoomParticipant::asArgArray() {
21
-  AmArgArray* res = new AmArgArray();
22
-  res->push(AmArg(localtag.c_str()));
23
-  res->push(AmArg(number.c_str()));
24
-  res->push(AmArg((int)status));
25
-  res->push(AmArg(last_reason.c_str()));
26
-  res->push(AmArg((int)muted));
20
+AmArg ConferenceRoomParticipant::asArgArray() {
21
+  AmArg res;
22
+  res.push(AmArg(localtag.c_str()));
23
+  res.push(AmArg(number.c_str()));
24
+  res.push(AmArg((int)status));
25
+  res.push(AmArg(last_reason.c_str()));
26
+  res.push(AmArg((int)muted));
27 27
   return res;
28 28
 }
29 29
 
... ...
@@ -55,14 +55,12 @@ void ConferenceRoom::cleanExpired() {
55 55
   }
56 56
 }
57 57
 
58
-AmArgArray* ConferenceRoom::asArgArray() {
58
+AmArg ConferenceRoom::asArgArray() {
59 59
   cleanExpired();
60
-  AmArgArray* res = new AmArgArray();
60
+  AmArg res;
61 61
   for (list<ConferenceRoomParticipant>::iterator it=participants.begin(); 
62 62
        it != participants.end(); it++) {
63
-    AmArg r;
64
-    r.setBorrowedPointer(it->asArgArray());
65
-    res->push(r);
63
+    res.push(it->asArgArray());
66 64
   }
67 65
   return res;
68 66
 }
... ...
@@ -48,7 +48,7 @@ struct ConferenceRoomParticipant {
48 48
 
49 49
   inline void setMuted(int mute);
50 50
   
51
-  AmArgArray* asArgArray();
51
+  AmArg asArgArray();
52 52
 };
53 53
 
54 54
 struct ConferenceRoom {
... ...
@@ -61,7 +61,7 @@ struct ConferenceRoom {
61 61
 
62 62
   void cleanExpired();
63 63
 
64
-  AmArgArray* asArgArray();
64
+  AmArg asArgArray();
65 65
 
66 66
   void newParticipant(const string& localtag, const string& number);
67 67
 
... ...
@@ -213,8 +213,8 @@ AmSession* WebConferenceFactory::onInvite(const AmSipRequest& req,
213 213
 }
214 214
 
215 215
 void WebConferenceFactory::invoke(const string& method, 
216
-				  const AmArgArray& args, 
217
-				  AmArgArray& ret)
216
+				  const AmArg& args, 
217
+				  AmArg& ret)
218 218
 {
219 219
   if(method == "roomCreate"){
220 220
     roomCreate(args, ret);
... ...
@@ -251,7 +251,7 @@ string WebConferenceFactory::getRandomPin() {
251 251
   return res;
252 252
 }
253 253
 
254
-void WebConferenceFactory::roomCreate(const AmArgArray& args, AmArgArray& ret) {
254
+void WebConferenceFactory::roomCreate(const AmArg& args, AmArg& ret) {
255 255
   string room = args.get(0).asCStr();
256 256
   rooms_mut.lock();
257 257
   map<string, ConferenceRoom>::iterator it = rooms.find(room);
... ...
@@ -268,7 +268,7 @@ void WebConferenceFactory::roomCreate(const AmArgArray& args, AmArgArray& ret) {
268 268
   rooms_mut.unlock();
269 269
 }
270 270
 
271
-void WebConferenceFactory::roomInfo(const AmArgArray& args, AmArgArray& ret) {
271
+void WebConferenceFactory::roomInfo(const AmArg& args, AmArg& ret) {
272 272
   string room = args.get(0).asCStr();
273 273
   string adminpin = args.get(1).asCStr();;
274 274
 
... ...
@@ -278,21 +278,16 @@ void WebConferenceFactory::roomInfo(const AmArgArray& args, AmArgArray& ret) {
278 278
     ret.push(1);
279 279
     ret.push("wrong adminpin");
280 280
     // for consistency, add an empty array
281
-    AmArgArray* a = new AmArgArray();
282
-    AmArg res;
283
-    res.setBorrowedPointer(a);
284
-    ret.push(res);
281
+    ret.push(AmArg());
285 282
    } else {
286 283
      ret.push(0);
287 284
      ret.push("OK");
288
-     AmArg res;
289
-     res.setBorrowedPointer(r->asArgArray());
290
-     ret.push(res);
285
+     ret.push(r->asArgArray());
291 286
    }
292 287
    rooms_mut.unlock();
293 288
 }
294 289
 
295
-void WebConferenceFactory::dialout(const AmArgArray& args, AmArgArray& ret) {
290
+void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
296 291
   string room        = args.get(0).asCStr();
297 292
   string adminpin    = args.get(1).asCStr();
298 293
   string callee      = args.get(2).asCStr();
... ...
@@ -343,7 +338,7 @@ void WebConferenceFactory::dialout(const AmArgArray& args, AmArgArray& ret) {
343 338
   }
344 339
 }
345 340
 
346
-void WebConferenceFactory::postConfEvent(const AmArgArray& args, AmArgArray& ret,
341
+void WebConferenceFactory::postConfEvent(const AmArg& args, AmArg& ret,
347 342
 					 int id, int mute) {
348 343
   string room        = args.get(0).asCStr();
349 344
   string adminpin    = args.get(1).asCStr();
... ...
@@ -376,19 +371,19 @@ void WebConferenceFactory::postConfEvent(const AmArgArray& args, AmArgArray& ret
376 371
   }
377 372
 }
378 373
 
379
-void WebConferenceFactory::kickout(const AmArgArray& args, AmArgArray& ret) {
374
+void WebConferenceFactory::kickout(const AmArg& args, AmArg& ret) {
380 375
   postConfEvent(args, ret, WebConferenceEvent::Kick, -1);
381 376
 }
382 377
 
383
-void WebConferenceFactory::mute(const AmArgArray& args, AmArgArray& ret) {
378
+void WebConferenceFactory::mute(const AmArg& args, AmArg& ret) {
384 379
   postConfEvent(args, ret, WebConferenceEvent::Mute, 1);
385 380
 }
386 381
 
387
-void WebConferenceFactory::unmute(const AmArgArray& args, AmArgArray& ret) {
382
+void WebConferenceFactory::unmute(const AmArg& args, AmArg& ret) {
388 383
   postConfEvent(args, ret, WebConferenceEvent::Unmute, 0);
389 384
 }
390 385
 
391
-void WebConferenceFactory::serverInfo(const AmArgArray& args, AmArgArray& ret) {
386
+void WebConferenceFactory::serverInfo(const AmArg& args, AmArg& ret) {
392 387
   ret.push("Not yet implemented");
393 388
 }
394 389
 
... ...
@@ -87,7 +87,7 @@ class WebConferenceFactory
87 87
   /** returns NULL if adminpin wrong */
88 88
   ConferenceRoom* getRoom(const string& room, 
89 89
 			  const string& adminpin);
90
-  void postConfEvent(const AmArgArray& args, AmArgArray& ret,
90
+  void postConfEvent(const AmArg& args, AmArg& ret,
91 91
 		     int id, int mute);
92 92
 
93 93
   regex_t direct_room_re;
... ...
@@ -116,16 +116,16 @@ public:
116 116
   WebConferenceFactory* getInstance(){
117 117
     return _instance;
118 118
   }
119
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
119
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
120 120
 
121 121
   // DI functions
122
-  void roomCreate(const AmArgArray& args, AmArgArray& ret);
123
-  void roomInfo(const AmArgArray& args, AmArgArray& ret);
124
-  void dialout(const AmArgArray& args, AmArgArray& ret);
125
-  void kickout(const AmArgArray& args, AmArgArray& ret);
126
-  void mute(const AmArgArray& args, AmArgArray& ret);
127
-  void unmute(const AmArgArray& args, AmArgArray& ret);
128
-  void serverInfo(const AmArgArray& args, AmArgArray& ret);
122
+  void roomCreate(const AmArg& args, AmArg& ret);
123
+  void roomInfo(const AmArg& args, AmArg& ret);
124
+  void dialout(const AmArg& args, AmArg& ret);
125
+  void kickout(const AmArg& args, AmArg& ret);
126
+  void mute(const AmArg& args, AmArg& ret);
127
+  void unmute(const AmArg& args, AmArg& ret);
128
+  void serverInfo(const AmArg& args, AmArg& ret);
129 129
 };
130 130
 
131 131
 class WebConferenceDialog 
... ...
@@ -33,7 +33,7 @@
33 33
 AmDynInvoke::AmDynInvoke() {}
34 34
 AmDynInvoke::~AmDynInvoke() {}
35 35
 
36
-void AmDynInvoke::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
36
+void AmDynInvoke::invoke(const string& method, const AmArg& args, AmArg& ret)
37 37
 {
38 38
   throw NotImplemented(method);
39 39
 }
... ...
@@ -56,7 +56,7 @@ class AmDynInvoke
56 56
 
57 57
   AmDynInvoke();
58 58
   virtual ~AmDynInvoke();
59
-  virtual void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
59
+  virtual void invoke(const string& method, const AmArg& args, AmArg& ret);
60 60
 };
61 61
 
62 62
 /**
63 63
new file mode 100644
... ...
@@ -0,0 +1,115 @@
1
+/*
2
+ * $Id: AmArg.h 368 2007-06-12 18:24:33Z sayer $
3
+ *
4
+ * Copyright (C) 2002-2003 Fhg Fokus
5
+ *
6
+ * This file is part of sems, a free SIP media server.
7
+ *
8
+ * sems is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * sems is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ */
27
+
28
+#include "AmArg.h"
29
+
30
+AmArg::AmArg(const AmArg& v)
31
+{  
32
+  type = Undef;
33
+
34
+  if (this != &v) {
35
+    invalidate();
36
+    
37
+    type = v.type;
38
+    switch(type){
39
+    case Int: { v_int = v.v_int; } break;
40
+    case Double: { v_double = v.v_double; } break;
41
+    case CStr: { v_cstr = strdup(v.v_cstr); } break;
42
+    case AObject:{  v_obj = v.v_obj; } break;
43
+    case Array:  { v_array = new ValueArray(*v.v_array); } break;
44
+    case Undef: break;
45
+    default: assert(0);
46
+    }
47
+  }
48
+}
49
+
50
+void AmArg::assertArray() {
51
+  if (Array == type)
52
+    return;
53
+  if (Undef == type) {
54
+    type = Array;
55
+    v_array = new ValueArray();
56
+    return;
57
+  } 
58
+  throw TypeMismatchException();
59
+}
60
+
61
+void AmArg::assertArray() const {
62
+  if (Array != type)
63
+    throw TypeMismatchException();
64
+}
65
+
66
+void AmArg::assertArray(size_t s) {
67
+    
68
+  if (Undef == type) {
69
+    type = Array;
70
+    v_array = new ValueArray();
71
+  } else if (Array != type) {
72
+    throw TypeMismatchException();
73
+  }
74
+  if (v_array->size() < s)
75
+    v_array->resize(s);
76
+}
77
+
78
+void AmArg::invalidate() {
79
+  if(type == CStr) { free((void*)v_cstr); }
80
+  if(type == Array) { delete v_array; }
81
+    
82
+  type = Undef;
83
+}
84
+
85
+void AmArg::push(const AmArg& a) {
86
+  assertArray();
87
+  v_array->push_back(a);
88
+}
89
+
90
+const size_t AmArg::size() {
91
+  assertArray();  
92
+  return v_array->size(); 
93
+}
94
+
95
+AmArg& AmArg::get(size_t idx) {
96
+  assertArray();  
97
+  if (idx >= v_array->size())
98
+    throw OutOfBoundsException();
99
+    
100
+  return (*v_array)[idx];
101
+}
102
+
103
+AmArg& AmArg::get(size_t idx) const {
104
+  assertArray();  
105
+  if (idx >= v_array->size())
106
+    throw OutOfBoundsException();
107
+    
108
+  return (*v_array)[idx];
109
+}
110
+
111
+AmArg& AmArg::operator[](size_t idx) { 
112
+  assertArray(idx+1); 
113
+  return (*v_array)[idx];
114
+}
115
+
... ...
@@ -34,7 +34,7 @@
34 34
 #include <vector>
35 35
 using std::vector;
36 36
 
37
-/** base for Objects as @see AmArg parameter*/
37
+/** base for Objects as @see AmArg parameter, not owned by AmArg (!) */
38 38
 class ArgObject {
39 39
  public:
40 40
   ArgObject() { }
... ...
@@ -52,9 +52,20 @@ class AmArg
52 52
     Int,
53 53
     Double,
54 54
     CStr,
55
-    AObject,
56
-    APointer		// for passing pointers that are not owned by AmArg
55
+    AObject,		// for passing pointers to objects not owned by AmArg
56
+    
57
+    Array
58
+  };
59
+
60
+  struct OutOfBoundsException {
61
+    OutOfBoundsException() { }
62
+  };
63
+
64
+  struct TypeMismatchException {
65
+    TypeMismatchException() { }
57 66
   };
67
+  
68
+  typedef std::vector<AmArg> ValueArray;
58 69
 
59 70
  private:
60 71
   // type
... ...
@@ -62,40 +73,37 @@ class AmArg
62 73
     
63 74
   // value
64 75
   union {
65
-    int         v_int;
66
-    double      v_double;
67
-    const char* v_cstr;
68
-    ArgObject*  v_obj;
69
-    void*	v_ptr;
76
+    int            v_int;
77
+    double         v_double;
78
+    const char*    v_cstr;
79
+    ArgObject*     v_obj;
80
+
81
+    ValueArray*    v_array;
70 82
   };
71 83
 
72
- public:
73
-  AmArg(const AmArg& v)
74
-    : type(v.type){
75
-	
76
-    switch(type){
77
-    case Int: v_int = v.v_int; break;
78
-    case Double: v_double = v.v_double; break;
79
-    case CStr: v_cstr = strdup(v.v_cstr); break;
80
-    case AObject: v_obj = v.v_obj; break;
81
-    case APointer: v_ptr = v.v_ptr; break;
82
-    default: assert(0);
83
-    }
84
-  }
85 84
 
85
+  void assertArray();
86
+  void assertArray() const;
87
+
88
+  void assertArray(size_t s);
89
+  void invalidate();
90
+
91
+ public:
86 92
   AmArg() 
87 93
     : type(Undef) 
88
-    {}
94
+    { }
89 95
 
96
+  AmArg(const AmArg& v);
97
+  
90 98
   AmArg(const int& v)
91 99
     : type(Int),
92 100
     v_int(v)
93
-    {}
101
+    { }
94 102
 
95 103
   AmArg(const double& v)
96 104
     : type(Double),
97 105
     v_double(v)
98
-    {}
106
+    { }
99 107
 
100 108
   AmArg(const char* v)
101 109
     : type(CStr)
... ...
@@ -103,57 +111,39 @@ class AmArg
103 111
       v_cstr = strdup(v);
104 112
     }
105 113
 
106
-  AmArg(void* v)
107
-    : type(APointer),
108
-    v_ptr(v)
109
-    { }
110
-
111
-  ~AmArg() {
112
-    if(type == CStr) free((void*)v_cstr);
113
-  }
114
+  ~AmArg() { invalidate(); }
114 115
 
115 116
   short getType() const { return type; }
116 117
 
118
+#define isArgArray(a) (AmArg::Array == a.getType())
119
+#define isArgDouble(a) (AmArg::Array == a.getType())
120
+#define isArgInt(a) (AmArg::Int == a.getType())
121
+#define isArgCStr(a) (AmArg::CStr == a.getType())
122
+#define isArgAObject(a) (AmArg::AObject == a.getType())
123
+
117 124
   void setBorrowedPointer(ArgObject* v) {
118 125
     type = AObject;
119 126
     v_obj = v;
120 127
   }
121
-    
122 128
 
123 129
   int         asInt()    const { return v_int; }
124 130
   double      asDouble() const { return v_double; }
125 131
   const char* asCStr()   const { return v_cstr; }
126 132
   ArgObject*  asObject() const { return v_obj; }
127
-  void*       asPointer() const { return v_ptr; }
128
-};
129
-
130
-/** \brief array of variable args for DI APIs*/
131
-class AmArgArray 
132
-: public ArgObject
133
-{
134
-  vector<AmArg> v;
135 133
 
136
- public:
137
-  struct OutOfBoundsException {
138
-    OutOfBoundsException() { }
139
-  };
134
+  // operations on arrays
135
+  void push(const AmArg& a);
136
+  
137
+  const size_t size();
140 138
 
141
-  AmArgArray() : v() {}
142
-  AmArgArray(const AmArgArray& a) : v(a.v) {}
143
-    
144
-  void push(const AmArg& a){
145
-    v.push_back(a);
146
-  }
139
+  /** throws OutOfBoundsException if array too small */
140
+  AmArg& get(size_t idx);
147 141
 
148
-  const AmArg& get(size_t idx) const {
149
-	
150
-    if (idx >= v.size())
151
-      throw OutOfBoundsException();
152
-    //	assert(idx < v.size());
153
-    return v[idx];
154
-  }
142
+  /** throws OutOfBoundsException if array too small */
143
+  AmArg& get(size_t idx) const;
155 144
 
156
-  size_t size() { return v.size(); }
145
+  /** resizes array if too small */
146
+  AmArg& operator[](size_t idx);
157 147
 };
158 148
 
159 149
 #endif
... ...
@@ -52,12 +52,12 @@ struct AmEvent
52 52
 struct AmPluginEvent: public AmEvent
53 53
 {
54 54
   string      name;
55
-  AmArgArray  data;
55
+  AmArg       data;
56 56
 
57 57
   AmPluginEvent(const string& n)
58 58
     : AmEvent(E_PLUGIN), name(n), data() {}
59 59
 
60
-  AmPluginEvent(const string& n, const AmArgArray& d)
60
+  AmPluginEvent(const string& n, const AmArg& d)
61 61
     : AmEvent(E_PLUGIN), name(n), data(d) {}
62 62
 };
63 63
 
... ...
@@ -174,7 +174,7 @@ void UserTimer::removeUserTimers(const string& session_id) {
174 174
   timers_mut.unlock();
175 175
 }
176 176
 
177
-void UserTimer::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
177
+void UserTimer::invoke(const string& method, const AmArg& args, AmArg& ret)
178 178
 {
179 179
   if(method == "setTimer"){
180 180
     setTimer(args.get(0).asInt(),
... ...
@@ -96,7 +96,7 @@ class UserTimer: public AmDynInvoke
96 96
   void on_stop();
97 97
 #endif
98 98
 
99
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
99
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
100 100
 };
101 101
 
102 102
 #endif //AM_SESSION_TIMER_H
... ...
@@ -306,7 +306,7 @@ int StatsUDPServer::execute(char* msg_buf, string& reply,
306 306
 	s_args.push_back(string(cmd_str.substr(p, p2-p)));
307 307
 	p=p2+1;
308 308
       }
309
-      AmArgArray args;
309
+      AmArg args;
310 310
       for (vector<string>::iterator it = s_args.begin(); 
311 311
 	   it != s_args.end(); it++) {
312 312
 	args.push(it->c_str());
... ...
@@ -325,7 +325,7 @@ int StatsUDPServer::execute(char* msg_buf, string& reply,
325 325
 	reply = "could not get DI instance from factory\n";
326 326
 	return 0;
327 327
       }
328
-      AmArgArray ret;
328
+      AmArg ret;
329 329
       di->invoke(fct_name, args, ret);
330 330
 			
331 331
       if (ret.size()) {
... ...
@@ -47,7 +47,7 @@ UACAuthFactory* UACAuthFactory::instance()
47 47
   return _instance;
48 48
 }
49 49
 
50
-void UACAuthFactory::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
50
+void UACAuthFactory::invoke(const string& method, const AmArg& args, AmArg& ret)
51 51
 {
52 52
   if(method == "getHandler"){
53 53
     CredentialHolder* c = dynamic_cast<CredentialHolder*>(args.get(0).asObject());
... ...
@@ -75,7 +75,7 @@ class UACAuthFactory
75 75
 
76 76
   static UACAuthFactory* instance();
77 77
   AmDynInvoke* getInstance() { return instance(); }
78
-  void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
78
+  void invoke(const string& method, const AmArg& args, AmArg& ret);
79 79
 };
80 80
 
81 81
 struct SIPRequestInfo {
... ...
@@ -50,7 +50,7 @@ example code
50 50
 	        AmDynInvokeFactory* di_f = AmPlugIn::instance()->
51 51
                  getFactory4Di("registrar_client");
52 52
 
53
-			AmArgArray di_args,ret;
53
+			AmArg di_args,ret;
54 54
 			di_args.push(domain.c_str());
55 55
 			di_args.push(user.c_str());
56 56
 			di_args.push(display_name.c_str()); // display name