combined AmArg and AmArgArray into one class

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@383 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 19 years ago
parent 2063ae879a
commit 29cc0cf236

@ -95,7 +95,7 @@ DIDial::DIDial() {
DIDial::~DIDial() { }
void DIDial::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
void DIDial::invoke(const string& method, const AmArg& args, AmArg& ret)
{
if(method == "dial"){
ret.push(dialout(args.get(0).asCStr(),

@ -43,5 +43,5 @@ class DIDial : public AmDynInvoke
DIDial();
~DIDial();
static DIDial* instance();
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
};

@ -38,7 +38,7 @@ int DILog::onLoad() {
DILog::~DILog() { }
void DILog::invoke(const string& method, const AmArgArray& args, AmArgArray& ret) {
void DILog::invoke(const string& method, const AmArg& args, AmArg& ret) {
if(method == "dumplog") {
ret.push(dumpLog().c_str());
} else if(method == "dumplogtodisk") {

@ -22,7 +22,7 @@ class DILog : public AmLoggingFacility, public AmDynInvoke, public AmDynInvokeFa
AmDynInvoke* getInstance() { return instance(); }
// DI API
static DILog* instance();
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
int onLoad();

@ -37,7 +37,7 @@ CCAcc::CCAcc() {
CCAcc::~CCAcc() { }
void CCAcc::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
void CCAcc::invoke(const string& method, const AmArg& args, AmArg& ret)
{
if(method == "getCredit"){
ret.push(getCredit(args.get(0).asCStr()));

@ -23,5 +23,5 @@ class CCAcc : public AmDynInvoke
CCAcc();
~CCAcc();
static CCAcc* instance();
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
};

@ -123,7 +123,7 @@ void MyCCDialog::onDtmf(int event, int duration) {
pin +=int2str(event);
DBG("pin is now '%s'\n", pin.c_str());
} else {
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(pin.c_str());
cc_acc->invoke("getCredit", di_args, ret);
credit = ret.get(0).asInt();
@ -195,7 +195,7 @@ void MyCCDialog::onOtherReply(const AmSipReply& reply) {
startAccounting();
setInOut(NULL, NULL);
// set the call timer
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(TIMERID_CREDIT_TIMEOUT);
di_args.push(credit); // in seconds
di_args.push(dlg.local_tag.c_str());
@ -244,7 +244,7 @@ void MyCCDialog::stopAccounting() {
if (now.tv_usec>500000) now.tv_sec++;
DBG("Call lasted %ld seconds\n", now.tv_sec);
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(pin.c_str());
di_args.push((int)now.tv_sec);
cc_acc->invoke("subtractCredit", di_args, ret);

@ -134,9 +134,9 @@ void XMLRPC2DIServer::registerMethods(const std::string& iface) {
iface.c_str());
return;
}
AmArgArray dummy, fct_list;
AmArg dummy, fct_list;
di->invoke("_list", dummy, fct_list);
for (unsigned int i=0;i<fct_list.size();i++) {
string method = fct_list.get(i).asCStr();
// see whether method already registered
@ -165,7 +165,7 @@ void XMLRPC2DIServer::registerMethods(const std::string& iface) {
} catch (AmDynInvoke::NotImplemented& e) {
ERROR("Not implemented in interface '%s': '%s'\n",
iface.c_str(), e.what.c_str());
} catch (const AmArgArray::OutOfBoundsException& e) {
} catch (const AmArg::OutOfBoundsException& e) {
ERROR("Out of bounds exception occured while exporting interface '%s'\n",
iface.c_str());
} catch (...) {
@ -218,7 +218,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
fact_name.c_str(), fct_name.c_str());
// get args
AmArgArray args;
AmArg args;
XMLRPC2DIServer::xmlrpcval2amarg(params, args, 2);
AmDynInvokeFactory* di_f = AmPlugIn::instance()->getFactory4Di(fact_name);
@ -229,7 +229,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
if(!di){
throw XmlRpcException("could not get instance from factory", 500);
}
AmArgArray ret;
AmArg ret;
di->invoke(fct_name, args, ret);
XMLRPC2DIServer::amarg2xmlrpcval(ret, result);
@ -240,8 +240,8 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
} catch (const AmDynInvoke::NotImplemented& e) {
throw XmlRpcException("Exception: AmDynInvoke::NotImplemented: "
+ e.what, 504);
} catch (const AmArgArray::OutOfBoundsException& e) {
throw XmlRpcException("Exception: AmArgArray out of bounds - paramter number mismatch.", 300);
} catch (const AmArg::OutOfBoundsException& e) {
throw XmlRpcException("Exception: AmArg out of bounds - paramter number mismatch.", 300);
} catch (const string& e) {
throw XmlRpcException("Exception: "+e, 500);
} catch (...) {
@ -249,7 +249,7 @@ void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result)
}
}
void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a,
void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArg& a,
unsigned int start_index) {
if (v.valid()) {
for (int i=start_index; i<v.size();i++) {
@ -264,45 +264,25 @@ void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a,
}
}
void XMLRPC2DIServer::amarg2xmlrpcval(AmArgArray& a,
void XMLRPC2DIServer::amarg2xmlrpcval(AmArg& a,
XmlRpcValue& result) {
if (a.size()) {
result.setSize(a.size());
for (unsigned int i=0;i<a.size();i++) {
const AmArg& r = a.get(i);
amarg2xmlrpcval(r, result, i);
}
}
}
// WARNING: AmArgArrays are deleted by this function!
void XMLRPC2DIServer::amarg2xmlrpcval(const AmArg& a, XmlRpcValue& result,
unsigned int pos) {
switch (a.getType()) {
case AmArg::CStr:
result[pos]= string(a.asCStr()); break;
result = string(a.asCStr()); break;
case AmArg::Int:
result[pos]=a.asInt(); break;
result=a.asInt(); break;
case AmArg::Double:
result[pos]=a.asDouble(); break;
result=a.asDouble(); break;
case AmArg::AObject: {
AmArgArray* arr = dynamic_cast<AmArgArray*>(a.asObject());
if (NULL != arr) {
result[pos].setSize(arr->size());
for (unsigned int i=0;i<arr->size();i++) {
const AmArg& r = arr->get(i);
amarg2xmlrpcval(r, result[pos], i);
}
delete arr;
} else {
WARN("unsupported return value type of parameter %d (not AmArgArray)\n", pos);
case AmArg::Array:
result.setSize(a.size());
for (size_t i=0;i<a.size();i++) {
// duh... recursion...
amarg2xmlrpcval(a.get(i), result[i]);
}
} break;
break;
default: { WARN("unsupported return value type %d\n", a.getType()); } break;
// TODO: do sth with the data here ?
}
@ -330,7 +310,7 @@ void DIMethodProxy::execute(XmlRpcValue& params,
throw XmlRpcException("could not get instance from factory", 500);
}
AmArgArray args, ret;
AmArg args, ret;
XMLRPC2DIServer::xmlrpcval2amarg(params, args);
DBG("XMLRPC2DI '%s': function '%s'\n",
@ -346,8 +326,8 @@ void DIMethodProxy::execute(XmlRpcValue& params,
} catch (const AmDynInvoke::NotImplemented& e) {
throw XmlRpcException("Exception: AmDynInvoke::NotImplemented: "
+ e.what, 504);
} catch (const AmArgArray::OutOfBoundsException& e) {
throw XmlRpcException("Exception: AmArgArray out of bounds - paramter number mismatch.", 300);
} catch (const AmArg::OutOfBoundsException& e) {
throw XmlRpcException("Exception: AmArg out of bounds - paramter number mismatch.", 300);
} catch (const string& e) {
throw XmlRpcException("Exception: "+e, 500);
} catch (...) {

@ -89,15 +89,11 @@ class XMLRPC2DIServer : public AmThread {
void run();
void on_stop();
static void xmlrpcval2amarg(XmlRpcValue& v, AmArgArray& a,
static void xmlrpcval2amarg(XmlRpcValue& v, AmArg& a,
unsigned int start_index = 0);
/** convert all args in a into result*/
static void amarg2xmlrpcval(AmArgArray& a, XmlRpcValue& result);
/** convert arg a result[pos] */
static void amarg2xmlrpcval(const AmArg& a, XmlRpcValue& result,
unsigned int pos);
static void amarg2xmlrpcval(AmArg& a, XmlRpcValue& result);
};

@ -380,7 +380,7 @@ static PyObject* IvrDialogBase_setTimer(IvrDialogBase* self, PyObject* args)
return NULL;
}
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(id);
di_args.push(interval);
di_args.push(self->p_dlg->getLocalTag().c_str());
@ -405,7 +405,7 @@ static PyObject* IvrDialogBase_removeTimer(IvrDialogBase* self, PyObject* args)
return NULL;
}
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(id);
di_args.push(self->p_dlg->getLocalTag().c_str());
@ -421,7 +421,7 @@ static PyObject* IvrDialogBase_removeTimers(IvrDialogBase* self, PyObject* args)
{
assert(self->p_dlg);
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(self->p_dlg->getLocalTag().c_str());
self->p_dlg->user_timer->

@ -396,7 +396,7 @@ void SIPRegistrarClient::onNewRegistration(SIPNewRegistrationEvent* new_reg) {
DBG("enabling UAC Auth for new registration.\n");
// get a sessionEventHandler from uac_auth
AmArgArray di_args,ret;
AmArg di_args,ret;
AmArg a;
a.setBorrowedPointer(reg);
di_args.push(a);
@ -553,8 +553,8 @@ bool SIPRegistrarClient::getRegistrationState(const string& handle,
return res;
}
void SIPRegistrarClient::invoke(const string& method, const AmArgArray& args,
AmArgArray& ret)
void SIPRegistrarClient::invoke(const string& method, const AmArg& args,
AmArg& ret)
{
if(method == "createRegistration"){
ret.push(createRegistration(args.get(0).asCStr(),

@ -175,7 +175,7 @@ public:
// DI API
static SIPRegistrarClient* instance();
void invoke(const string& method,
const AmArgArray& args, AmArgArray& ret);
const AmArg& args, AmArg& ret);
bool onSipReply(const AmSipReply& rep);
int onLoad();

@ -535,7 +535,7 @@ void AnswerMachineDialog::process(AmEvent* event)
case 0:
playlist.addToPlaylist(new AmPlaylistItem(NULL,&a_msg));
{AmArgArray di_args,ret;
{AmArg di_args,ret;
di_args.push(RECORD_TIMER);
di_args.push(AnswerMachineFactory::MaxRecordTime);
di_args.push(getLocalTag().c_str());

@ -17,13 +17,13 @@ bool ConferenceRoomParticipant::expired(const struct timeval& now) {
(unsigned int)diff.tv_sec > PARTICIPANT_EXPIRED_DELAY;
}
AmArgArray* ConferenceRoomParticipant::asArgArray() {
AmArgArray* res = new AmArgArray();
res->push(AmArg(localtag.c_str()));
res->push(AmArg(number.c_str()));
res->push(AmArg((int)status));
res->push(AmArg(last_reason.c_str()));
res->push(AmArg((int)muted));
AmArg ConferenceRoomParticipant::asArgArray() {
AmArg res;
res.push(AmArg(localtag.c_str()));
res.push(AmArg(number.c_str()));
res.push(AmArg((int)status));
res.push(AmArg(last_reason.c_str()));
res.push(AmArg((int)muted));
return res;
}
@ -55,14 +55,12 @@ void ConferenceRoom::cleanExpired() {
}
}
AmArgArray* ConferenceRoom::asArgArray() {
AmArg ConferenceRoom::asArgArray() {
cleanExpired();
AmArgArray* res = new AmArgArray();
AmArg res;
for (list<ConferenceRoomParticipant>::iterator it=participants.begin();
it != participants.end(); it++) {
AmArg r;
r.setBorrowedPointer(it->asArgArray());
res->push(r);
res.push(it->asArgArray());
}
return res;
}

@ -48,7 +48,7 @@ struct ConferenceRoomParticipant {
inline void setMuted(int mute);
AmArgArray* asArgArray();
AmArg asArgArray();
};
struct ConferenceRoom {
@ -61,7 +61,7 @@ struct ConferenceRoom {
void cleanExpired();
AmArgArray* asArgArray();
AmArg asArgArray();
void newParticipant(const string& localtag, const string& number);

@ -213,8 +213,8 @@ AmSession* WebConferenceFactory::onInvite(const AmSipRequest& req,
}
void WebConferenceFactory::invoke(const string& method,
const AmArgArray& args,
AmArgArray& ret)
const AmArg& args,
AmArg& ret)
{
if(method == "roomCreate"){
roomCreate(args, ret);
@ -251,7 +251,7 @@ string WebConferenceFactory::getRandomPin() {
return res;
}
void WebConferenceFactory::roomCreate(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::roomCreate(const AmArg& args, AmArg& ret) {
string room = args.get(0).asCStr();
rooms_mut.lock();
map<string, ConferenceRoom>::iterator it = rooms.find(room);
@ -268,7 +268,7 @@ void WebConferenceFactory::roomCreate(const AmArgArray& args, AmArgArray& ret) {
rooms_mut.unlock();
}
void WebConferenceFactory::roomInfo(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::roomInfo(const AmArg& args, AmArg& ret) {
string room = args.get(0).asCStr();
string adminpin = args.get(1).asCStr();;
@ -278,21 +278,16 @@ void WebConferenceFactory::roomInfo(const AmArgArray& args, AmArgArray& ret) {
ret.push(1);
ret.push("wrong adminpin");
// for consistency, add an empty array
AmArgArray* a = new AmArgArray();
AmArg res;
res.setBorrowedPointer(a);
ret.push(res);
ret.push(AmArg());
} else {
ret.push(0);
ret.push("OK");
AmArg res;
res.setBorrowedPointer(r->asArgArray());
ret.push(res);
ret.push(r->asArgArray());
}
rooms_mut.unlock();
}
void WebConferenceFactory::dialout(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) {
string room = args.get(0).asCStr();
string adminpin = args.get(1).asCStr();
string callee = args.get(2).asCStr();
@ -343,7 +338,7 @@ void WebConferenceFactory::dialout(const AmArgArray& args, AmArgArray& ret) {
}
}
void WebConferenceFactory::postConfEvent(const AmArgArray& args, AmArgArray& ret,
void WebConferenceFactory::postConfEvent(const AmArg& args, AmArg& ret,
int id, int mute) {
string room = args.get(0).asCStr();
string adminpin = args.get(1).asCStr();
@ -376,19 +371,19 @@ void WebConferenceFactory::postConfEvent(const AmArgArray& args, AmArgArray& ret
}
}
void WebConferenceFactory::kickout(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::kickout(const AmArg& args, AmArg& ret) {
postConfEvent(args, ret, WebConferenceEvent::Kick, -1);
}
void WebConferenceFactory::mute(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::mute(const AmArg& args, AmArg& ret) {
postConfEvent(args, ret, WebConferenceEvent::Mute, 1);
}
void WebConferenceFactory::unmute(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::unmute(const AmArg& args, AmArg& ret) {
postConfEvent(args, ret, WebConferenceEvent::Unmute, 0);
}
void WebConferenceFactory::serverInfo(const AmArgArray& args, AmArgArray& ret) {
void WebConferenceFactory::serverInfo(const AmArg& args, AmArg& ret) {
ret.push("Not yet implemented");
}

@ -87,7 +87,7 @@ class WebConferenceFactory
/** returns NULL if adminpin wrong */
ConferenceRoom* getRoom(const string& room,
const string& adminpin);
void postConfEvent(const AmArgArray& args, AmArgArray& ret,
void postConfEvent(const AmArg& args, AmArg& ret,
int id, int mute);
regex_t direct_room_re;
@ -116,16 +116,16 @@ public:
WebConferenceFactory* getInstance(){
return _instance;
}
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
// DI functions
void roomCreate(const AmArgArray& args, AmArgArray& ret);
void roomInfo(const AmArgArray& args, AmArgArray& ret);
void dialout(const AmArgArray& args, AmArgArray& ret);
void kickout(const AmArgArray& args, AmArgArray& ret);
void mute(const AmArgArray& args, AmArgArray& ret);
void unmute(const AmArgArray& args, AmArgArray& ret);
void serverInfo(const AmArgArray& args, AmArgArray& ret);
void roomCreate(const AmArg& args, AmArg& ret);
void roomInfo(const AmArg& args, AmArg& ret);
void dialout(const AmArg& args, AmArg& ret);
void kickout(const AmArg& args, AmArg& ret);
void mute(const AmArg& args, AmArg& ret);
void unmute(const AmArg& args, AmArg& ret);
void serverInfo(const AmArg& args, AmArg& ret);
};
class WebConferenceDialog

@ -33,7 +33,7 @@
AmDynInvoke::AmDynInvoke() {}
AmDynInvoke::~AmDynInvoke() {}
void AmDynInvoke::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
void AmDynInvoke::invoke(const string& method, const AmArg& args, AmArg& ret)
{
throw NotImplemented(method);
}

@ -56,7 +56,7 @@ class AmDynInvoke
AmDynInvoke();
virtual ~AmDynInvoke();
virtual void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
virtual void invoke(const string& method, const AmArg& args, AmArg& ret);
};
/**

@ -0,0 +1,115 @@
/*
* $Id: AmArg.h 368 2007-06-12 18:24:33Z sayer $
*
* Copyright (C) 2002-2003 Fhg Fokus
*
* This file is part of sems, a free SIP media server.
*
* sems is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* For a license to use the ser software under conditions
* other than those described here, or to purchase support for this
* software, please contact iptel.org by e-mail at the following addresses:
* info@iptel.org
*
* sems is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "AmArg.h"
AmArg::AmArg(const AmArg& v)
{
type = Undef;
if (this != &v) {
invalidate();
type = v.type;
switch(type){
case Int: { v_int = v.v_int; } break;
case Double: { v_double = v.v_double; } break;
case CStr: { v_cstr = strdup(v.v_cstr); } break;
case AObject:{ v_obj = v.v_obj; } break;
case Array: { v_array = new ValueArray(*v.v_array); } break;
case Undef: break;
default: assert(0);
}
}
}
void AmArg::assertArray() {
if (Array == type)
return;
if (Undef == type) {
type = Array;
v_array = new ValueArray();
return;
}
throw TypeMismatchException();
}
void AmArg::assertArray() const {
if (Array != type)
throw TypeMismatchException();
}
void AmArg::assertArray(size_t s) {
if (Undef == type) {
type = Array;
v_array = new ValueArray();
} else if (Array != type) {
throw TypeMismatchException();
}
if (v_array->size() < s)
v_array->resize(s);
}
void AmArg::invalidate() {
if(type == CStr) { free((void*)v_cstr); }
if(type == Array) { delete v_array; }
type = Undef;
}
void AmArg::push(const AmArg& a) {
assertArray();
v_array->push_back(a);
}
const size_t AmArg::size() {
assertArray();
return v_array->size();
}
AmArg& AmArg::get(size_t idx) {
assertArray();
if (idx >= v_array->size())
throw OutOfBoundsException();
return (*v_array)[idx];
}
AmArg& AmArg::get(size_t idx) const {
assertArray();
if (idx >= v_array->size())
throw OutOfBoundsException();
return (*v_array)[idx];
}
AmArg& AmArg::operator[](size_t idx) {
assertArray(idx+1);
return (*v_array)[idx];
}

@ -34,7 +34,7 @@
#include <vector>
using std::vector;
/** base for Objects as @see AmArg parameter*/
/** base for Objects as @see AmArg parameter, not owned by AmArg (!) */
class ArgObject {
public:
ArgObject() { }
@ -52,9 +52,20 @@ class AmArg
Int,
Double,
CStr,
AObject,
APointer // for passing pointers that are not owned by AmArg
AObject, // for passing pointers to objects not owned by AmArg
Array
};
struct OutOfBoundsException {
OutOfBoundsException() { }
};
struct TypeMismatchException {
TypeMismatchException() { }
};
typedef std::vector<AmArg> ValueArray;
private:
// type
@ -62,40 +73,37 @@ class AmArg
// value
union {
int v_int;
double v_double;
const char* v_cstr;
ArgObject* v_obj;
void* v_ptr;
int v_int;
double v_double;
const char* v_cstr;
ArgObject* v_obj;
ValueArray* v_array;
};
public:
AmArg(const AmArg& v)
: type(v.type){
switch(type){
case Int: v_int = v.v_int; break;
case Double: v_double = v.v_double; break;
case CStr: v_cstr = strdup(v.v_cstr); break;
case AObject: v_obj = v.v_obj; break;
case APointer: v_ptr = v.v_ptr; break;
default: assert(0);
}
}
void assertArray();
void assertArray() const;
void assertArray(size_t s);
void invalidate();
public:
AmArg()
: type(Undef)
{}
{ }
AmArg(const AmArg& v);
AmArg(const int& v)
: type(Int),
v_int(v)
{}
{ }
AmArg(const double& v)
: type(Double),
v_double(v)
{}
{ }
AmArg(const char* v)
: type(CStr)
@ -103,57 +111,39 @@ class AmArg
v_cstr = strdup(v);
}
AmArg(void* v)
: type(APointer),
v_ptr(v)
{ }
~AmArg() {
if(type == CStr) free((void*)v_cstr);
}
~AmArg() { invalidate(); }
short getType() const { return type; }
#define isArgArray(a) (AmArg::Array == a.getType())
#define isArgDouble(a) (AmArg::Array == a.getType())
#define isArgInt(a) (AmArg::Int == a.getType())
#define isArgCStr(a) (AmArg::CStr == a.getType())
#define isArgAObject(a) (AmArg::AObject == a.getType())
void setBorrowedPointer(ArgObject* v) {
type = AObject;
v_obj = v;
}
int asInt() const { return v_int; }
double asDouble() const { return v_double; }
const char* asCStr() const { return v_cstr; }
ArgObject* asObject() const { return v_obj; }
void* asPointer() const { return v_ptr; }
};
/** \brief array of variable args for DI APIs*/
class AmArgArray
: public ArgObject
{
vector<AmArg> v;
public:
struct OutOfBoundsException {
OutOfBoundsException() { }
};
// operations on arrays
void push(const AmArg& a);
const size_t size();
AmArgArray() : v() {}
AmArgArray(const AmArgArray& a) : v(a.v) {}
void push(const AmArg& a){
v.push_back(a);
}
/** throws OutOfBoundsException if array too small */
AmArg& get(size_t idx);
const AmArg& get(size_t idx) const {
if (idx >= v.size())
throw OutOfBoundsException();
// assert(idx < v.size());
return v[idx];
}
/** throws OutOfBoundsException if array too small */
AmArg& get(size_t idx) const;
size_t size() { return v.size(); }
/** resizes array if too small */
AmArg& operator[](size_t idx);
};
#endif

@ -52,12 +52,12 @@ struct AmEvent
struct AmPluginEvent: public AmEvent
{
string name;
AmArgArray data;
AmArg data;
AmPluginEvent(const string& n)
: AmEvent(E_PLUGIN), name(n), data() {}
AmPluginEvent(const string& n, const AmArgArray& d)
AmPluginEvent(const string& n, const AmArg& d)
: AmEvent(E_PLUGIN), name(n), data(d) {}
};

@ -174,7 +174,7 @@ void UserTimer::removeUserTimers(const string& session_id) {
timers_mut.unlock();
}
void UserTimer::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
void UserTimer::invoke(const string& method, const AmArg& args, AmArg& ret)
{
if(method == "setTimer"){
setTimer(args.get(0).asInt(),

@ -96,7 +96,7 @@ class UserTimer: public AmDynInvoke
void on_stop();
#endif
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
};
#endif //AM_SESSION_TIMER_H

@ -306,7 +306,7 @@ int StatsUDPServer::execute(char* msg_buf, string& reply,
s_args.push_back(string(cmd_str.substr(p, p2-p)));
p=p2+1;
}
AmArgArray args;
AmArg args;
for (vector<string>::iterator it = s_args.begin();
it != s_args.end(); it++) {
args.push(it->c_str());
@ -325,7 +325,7 @@ int StatsUDPServer::execute(char* msg_buf, string& reply,
reply = "could not get DI instance from factory\n";
return 0;
}
AmArgArray ret;
AmArg ret;
di->invoke(fct_name, args, ret);
if (ret.size()) {

@ -47,7 +47,7 @@ UACAuthFactory* UACAuthFactory::instance()
return _instance;
}
void UACAuthFactory::invoke(const string& method, const AmArgArray& args, AmArgArray& ret)
void UACAuthFactory::invoke(const string& method, const AmArg& args, AmArg& ret)
{
if(method == "getHandler"){
CredentialHolder* c = dynamic_cast<CredentialHolder*>(args.get(0).asObject());

@ -75,7 +75,7 @@ class UACAuthFactory
static UACAuthFactory* instance();
AmDynInvoke* getInstance() { return instance(); }
void invoke(const string& method, const AmArgArray& args, AmArgArray& ret);
void invoke(const string& method, const AmArg& args, AmArg& ret);
};
struct SIPRequestInfo {

@ -50,7 +50,7 @@ example code
AmDynInvokeFactory* di_f = AmPlugIn::instance()->
getFactory4Di("registrar_client");
AmArgArray di_args,ret;
AmArg di_args,ret;
di_args.push(domain.c_str());
di_args.push(user.c_str());
di_args.push(display_name.c_str()); // display name

Loading…
Cancel
Save