Author Topic: CDRBuild - Holdtime Modification - 6.0.1  (Read 11115 times)

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
CDRBuild - Holdtime Modification - 6.0.1
« on: June 10, 2018, 01:25:16 AM »
Hi

As I trying to add holdtime in core level instead of custom patch, but almost calculated the holdtime and debug console emitting the value properly but failed to add into emitting CDR message to get it stored in Database.

Due to clear show fully operational function are hidden with “..” value.

Appreciated if Anybody help me on this.

Yate Version : 6.0.1-dev

SIP Client/IP Phone : For Making Call.

Ysipchan.cpp:


bool YateSIPConnection::reInviteProxy(SIPTransaction* t, MimeSdpBody* sdp, int invite)

{

..

..

..

 

    msg->addParam("audio_changed",String::boolText(audioChg));

    msg->addParam("mute",String::boolText(MediaStarted != m_mediaStatus));

// Holdtime Patch START

   if( MediaStarted != m_mediaStatus)

      msg->addParam("status","hold");

   else

         msg->addParam("status","unhold");

// Holdtime Patch END

    putMedia(*msg);

    Engine::enqueue(msg);

..

..

..

}

 

 

Cdrbuild.cpp:

 

Variable Initialization :

 

class CdrHandler : public MessageHandler

{

public:

    CdrHandler(const char *name, int type, int prio = 50)

                                                          : MessageHandler(name,prio,__plugin.name()),

                                                            m_type(type)

                                                          { }

    virtual bool received(Message &msg);

private:

    int m_type;

    u_int64_t

      m_holdsec,

      m_hold,

      m_unhold;                                     

};

 

 

Variable Initialization 2 :

 

class CdrBuilder : public NamedList

{

public:

..

..

..

private:

    u_int64_t

     m_start,

     m_call,

     m_ringing,

     m_answer,

     m_holdsec,                                     

     m_hangup;

..

..

..

}

 

Variable Initializations 3 :

 

CdrBuilder::CdrBuilder(const char *name)

    : NamedList(name), m_dir("unknown"), m_status("unknown"),

      m_first(true), m_write(true)

{

    m_statusTime = m_start = m_call = m_ringing = m_answer = m_hangup = m_holdsec = 0;

    m_cdrId = ++s_seq;

}

 

Hold Time Calculation On cdrbuild function :

 

bool CdrHandler::received(Message &msg)

{

    Lock lock(s_mutex);

..

..

..

 

if (m_type == CdrUpdate) {

const String* oper = msg.getParam(YSTRING("operation"));

const String* TBmute = msg.getParam(YSTRING("mute"));

if (oper && (*oper != YSTRING("cdrbuild")) )

  track = false;

  if (oper && TBmute && (*TBmute == YSTRING("true")) ) {

   track = true;

   m_hold = Time::msecNow();

  }

  if (oper && TBmute && (*TBmute == YSTRING("false") ) && m_hold && ( m_hold > 0 ) ){

   track = true;

   m_unhold =                                       Time::msecNow();

   if(m_holdsec)

     m_holdsec = m_holdsec + m_unhold - m_hold;

   else

     m_holdsec = m_unhold - m_hold;

   if(m_holdsec)

    Debug("cdrbuild",DebugAll,"TBholdtime is '%lu'",m_holdsec);

  }

}

..

..

..

}

 

Holdtime Emit Function :

 

void CdrBuilder::emit(const char *operation)

{

..

..

..

 

    m->addParam("ringtime",printTime(buf,t_answer - t_ringing));

    m->addParam("holdtime",printTime(buf,m_holdsec));   // Holdtime Emit. This is where I need value to be emit.

    m->addParam("status",m_status);

..

..

..

}

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #1 on: June 12, 2018, 01:30:43 AM »
CdrHandler::received():
You are using CdrHandler's data to update hold related status.
CdrHandler is the common message handler, for all cdr messages.

Use CdrBuilder's data !

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #2 on: June 12, 2018, 01:20:03 PM »
So you meant to say my calculation in cdrhandler: received function needs to do on cdrbuilder:emit function itself before emitting the variable with help of cdrbuilder's current data? .

Let me try that then

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #3 on: June 13, 2018, 12:01:32 AM »
Hi

As suggested modified the cdrbuilder emit function like mentioned below. 

   m->addParam("ringtime",printTime(buf,t_answer - t_ringing));

   //HoldTime Calculation
   if (String(m_status) == YSTRING("hold") ) {
      m_hold = Time::msecNow();
   }
   if (String(m_status) == YSTRING("unhold") && m_hold && ( m_hold > 0 ) ){
      m_unhold =   Time::msecNow();
      if(m_holdsec)
      m_holdsec = m_holdsec + m_unhold - m_hold;
      else
      m_holdsec = m_unhold - m_hold;
   }

   m->addParam("holdtime",printTime(buf,m_holdsec));   
   //
    m->addParam("status",m_status);

It should work ?

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #4 on: June 13, 2018, 12:11:45 AM »
Sorry, can't follow!
Please post a diff from svn.
You may use:
svn diff -x -p

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #5 on: June 13, 2018, 12:39:27 AM »
Hi

unable to use svn patch due to that ,Attached git patch.

I hope it's should be same as i guess.

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #6 on: June 13, 2018, 12:59:22 AM »
You may want to change:
if (String(operation) == YSTRING("update") && !s_cdrUpdates && String(m_status) == YSTRING("hold") && String(m_status) == YSTRING("unhold"))
to
if (String(operation) == YSTRING("update") && !s_cdrUpdates && m_status != YSTRING("hold") && m_status != YSTRING("unhold"))

I suppose you want not to return for status=hold/unhold

You may also want to handle call termination while on hold: the 'unhold' status won't be received!

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #7 on: June 13, 2018, 02:54:21 AM »
Ooh. i forgot that scenario.

So am planning to put condition for that, Finalize operation is the correct option to identify the call is terminated in emit function.?

With that Modified the condition. As i hope it would match those necessary condition properly.

marian

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #8 on: June 13, 2018, 03:09:26 AM »
I think you should test it.

A suggestion:
m_unhold = Time::msecNow();
if(m_holdsec)
    m_holdsec = m_holdsec + m_unhold - m_hold;
else
    m_holdsec = m_unhold - m_hold;

may just be (simpler, you don't need an extra variable):
m_holdsec += Time::msecNow() - m_hold;

Question: m_holdsec is in seconds? if so, use Time::secNow() instead of Time::msecNow()

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #9 on: June 13, 2018, 04:23:34 AM »
Thanks .

Will modify as you suggested.That would save some. At initial stage it was used to check some more condition and validation.

Update you the status once tested.

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #10 on: June 13, 2018, 09:05:56 AM »
Hi

As i tested and it's working fine as i excepted. But identified some more mistake hold time value not passed to both direction of  call. only one leg whether incoming,outgoing leg only available. How to copy that variable into both leg of same call like billtime.

Sniffer Output :

  param['duration'] = '37.652'
  param['billtime'] = '21.992'
  param['ringtime'] = '3.653'
  param['holdtime'] = '7.510'
  param['status'] = 'answered'
  param['out_leg.duration'] = '37.642'
  param['out_leg.billtime'] = '21.987'
  param['out_leg.ringtime'] = '3.653'
  param['out_leg.holdtime'] = '0.000'

ganapathi

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: CDRBuild - Holdtime Modification - 6.0.1
« Reply #11 on: June 13, 2018, 12:24:44 PM »
Sorry misunderstanding.

Due to behaviour of Hold initiation from SIP channel i assigned status as hold/unhold only. And i don't have idea to copy, it should be hard to do tht i think.

Will try to adjust on db side.

Anyway thanks . i was tried to get this done so long, had no clue earlier...