Author Topic: Custom API - NamedList  (Read 8687 times)

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Custom API - NamedList
« on: November 25, 2018, 12:44:22 PM »
Hi,

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

Plan :
  • Create Custom NamedList Variable through-out the call regardless of channel
  • Store set of value through some module like CustomDriver,CustomChannel, miscellaneous module.May be each module would push some value into customnamed list variable
  • Access through Custom module or copy parameters to new message to dispatch.

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.
« Last Edit: November 25, 2018, 01:01:32 PM by ganapathi »

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Custom API - NamedList
« Reply #1 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.

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #2 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.

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #3 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.
}

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Custom API - NamedList
« Reply #4 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
}

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #5 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.

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #6 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.

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Custom API - NamedList
« Reply #7 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

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #8 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.


ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #9 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


ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #10 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.
« Last Edit: December 09, 2018, 11:54:50 AM by ganapathi »

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Custom API - NamedList
« Reply #11 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.

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #12 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

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Custom API - NamedList
« Reply #13 on: December 10, 2018, 02:08:18 AM »
You should take a look at
CdrBuilder class
and
CdrBuilder::update(const Message& msg ...) method.

ganapathi

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
    • Optimal Сasual Dating - Authentic Damsels
Re: Custom API - NamedList
« Reply #14 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 ?