Yate Community Forum

General Category => Yate users hangout place => Topic started by: ganapathi on November 25, 2018, 12:44:22 PM

Title: Custom API - NamedList
Post by: ganapathi on November 25, 2018, 12:44:22 PM
Hi,

As i am working on to develop custom API through cpp module.

Plan :

Because some module like chan.notify /call.answered doesn't have much information to process next message but at the same time need some message other than common value like billid,caller,called etc.

So in this cases in which class header( Whether YATE_API NamedList public section?) i need to define or initialize the named list . So that assign and access through out module.

NamedList Creation:

Code: [Select]
NamedList* customdataList = new NamedList("");

CustomDriver NamedList Assign:
Code: [Select]
CustomDriver::msgExecute(Message& msg)
customdataList->addparam("customheader","customvalue");


CustomChannelHandler Function :
Here have doubt on access the NamedList out of these two.
Code: [Select]
customdataList->getValue("customheader");

or
NamedList* tmp = YOBJECT(NamedList,"customdataList");
tmp ->getValue("customheader");

or
NamedPointer* ss = new NamedPointer("customdataList");
NamedList* tmp = YOBJECT(NamedList,ss);
tmp ->getValue("customheader");


I know i mis-understand some functionalities.  Second parameter of YOBJECT required pointer, but i don't know how to create pointer with specific string.I tried exact string, YSTRING but everything gives me error as well or no output.
Title: Re: Custom API - NamedList
Post by: marian on November 29, 2018, 01:38:02 AM
Please describe more accurate what do you want to do and its purpose.

If you want to add a NamedList parameter to a Message keep in mind that only your module will handle it.
Title: Re: Custom API - NamedList
Post by: ganapathi on November 29, 2018, 02:11:42 AM
As I want to store some value . For example need to assign  caller,called, queuename,source, greeting etc like some parameter value from CustomDriver in one of the module. And need to access these value from MessageHandler section from same module or from different module.

And I thought by using NamedList we can create one variable with list of value with key=>value basis.

Simply by adding custom handler on call.execute/call.preroute/route etc. then gather values and inserting to my variable then access it whenever I required by calling API function.
Title: Re: Custom API - NamedList
Post by: ganapathi on November 29, 2018, 02:19:45 AM
QueueOutDriver::msgExecute()
{
..
Here I will catch source,greeting, caller,called value then emit chan.attach with source with notify parameter.
..
}
QueueOutHandler::received(Message& msg)
{
..
..
If Message is chan.notify then emit message with greeting. Also I need to emit some extra message need to dispatch. here I need to use some parameter value which I used on preroute/route. Or I will assign the value on my module whatever I want.
Here also I need to assign some value then access it on another Handler such as MailHandler::received.
}
Title: Re: Custom API - NamedList
Post by: marian on November 29, 2018, 02:21:16 AM
You can use a NamedList to manage your own parameters but you won't be able to access them from other modules like regexroute.

Adding:
NamedList* nl = new NamedList("");
// ... fill 'nl' params
// Add it to a Message
msg.setParam(new NamedPointer("customdataList",nl));

Retrieve from Message:

NamedList* nl = YOBJECT(NamedList,msg.getParam("customdataList"));
if (nl) {
    // Handle it
}
else {
   // Parameter not present or not a NamedList object
}
Title: Re: Custom API - NamedList
Post by: ganapathi on November 29, 2018, 02:31:37 AM
It's look like assign on message then handle the same message on handler side ?. am I right.

if I assign on chan.attach then I cant access through chan.notify also .

So what would be the right way to access the values from through out the messages for the particular channel . Even am expecting through out all the related channel for the single call. Like for sig/1 if I created then qin/1, qout/1 ,vmail/1 then need to access those necessary information all the channels is my main point. or atleast on each channel with API calling. bcs need to push common value on every important message to database.
Title: Re: Custom API - NamedList
Post by: ganapathi on November 29, 2018, 05:03:59 AM
Module : Qout
Channel : qout/1
Caller channel: sig/1

QueueOutDriver::msgExecute()
{
..
Assign value1,value2,value3.etc.
..
}
QueueOutHandler::received(Message& msg)
{
..
..
Access value1,value2,value3 on every message(chan.connected/chan.notify or other message handler which is installed.
}

Module : Vmail
Channel : vmail/1
Caller channel: sig/1

VmailHandler::received(Message& msg)
{
..
Access value1,value2,value3 which I assigned from QueueOutHandler.
}

Like this I need to access variable. What would be right way if NamedList is not helpful. Or any other to use namedlist to get this done.
Title: Re: Custom API - NamedList
Post by: marian on November 29, 2018, 05:34:17 AM
Currently there is no mechanism to set arbitrary parameters to messages sent by Channel.

This is a custom application.
What I understand is you want something cdrbuild module is already doing: store configured parameters and put them in call.cdr messages.

You must write your own application (module) who must:
1. track call legs from creation to destruction
2. store associated parameters
3. intercept channel messages with message handlers at high priority and fill them with stored parameters
Title: Re: Custom API - NamedList
Post by: ganapathi on November 29, 2018, 06:07:53 AM
Yes. Am trying to do the same job what cdrbuild module doing now. But there is no API available on CDR module as you said earlier. If API available then may be easy to do.

Also trying to use Channel API for this but channel API is only able to call with userData. everytime need to use chan.locate to get that.
that's why trying on other common API which may be if available.

Title: Re: Custom API - NamedList
Post by: ganapathi on December 05, 2018, 05:00:35 AM
As i am trying to keep track of call leg by using separate module but don't have clue to keep track where every handler is look like new call for module.

http://dpaste.com/2VE4YBQ

Title: Re: Custom API - NamedList
Post by: ganapathi on December 09, 2018, 11:48:43 AM
Can you point me best way to store associated parameters on the single module but various class. Define a variable under namespace instead of class would give access I think but need to keep different set of list for each call.

declare variable;

Call 1: Active
variable = { "key1" => "value1" , "key2" = "value2" } // Kind of List with named key.
Call 2: Active
variable = { "key3" => "value3" , "key2" = "value4" } // Kind of List with named key.

But at the same time module should keep multiple list for each call. Means each list need to track by billid.

I just read ObjList as well but don't know how named pair of value append and retrieval from there.
Title: Re: Custom API - NamedList
Post by: marian on December 10, 2018, 12:40:20 AM
You may take a look at modules/cdrbuild.cpp
It tracks call legs and update parameters associated with them.
Title: Re: Custom API - NamedList
Post by: ganapathi on December 10, 2018, 02:03:04 AM
I was looking into that one only earlier as well. But couldn't get some points.

ObjList defined under namespace
Code: [Select]
namespace {
static ObjList s_cdrs;
..

Object pointer created with ID and append into ObjList
Code: [Select]
String id(msg.getValue(YSTRING("id")));
b = new CdrBuilder(id);
s_cdrs.append(b);

Get the Object Pointer with ID
Code: [Select]
String id(msg.getValue(YSTRING("id")));
CdrBuilder *b = CdrBuilder::find(id);

Remove Object pointer from ObjList
Code: [Select]
s_cdrs.remove(this);
But didn't find where NamedList with value storing into id object and retrieval from that. any sample syntax push namedlist into pointer and access from tht would be more helpful
Title: Re: Custom API - NamedList
Post by: marian on December 10, 2018, 02:08:18 AM
You should take a look at
CdrBuilder class
and
CdrBuilder::update(const Message& msg ...) method.
Title: Re: Custom API - NamedList
Post by: ganapathi on December 10, 2018, 07:57:08 AM
If am not wrong then is this correct ?.

Code: [Select]
const NamedString* s = msg.getParam(i);
String* str = getParam(s->name());
addParam(s->name(),*s);

Adding and gather like normal NamedList generation (addParam,getParam).

But here there is no NamedList variable mentioned, if not mentioned then by default it would take as "name" ?. right ?
Title: Re: Custom API - NamedList
Post by: ganapathi on December 10, 2018, 11:55:51 PM
Please Ignore it. I get this done.