[Freeswitch-users] ESL socket outbound in C++

Stephen Wilde wstephen80 at gmail.com
Fri Feb 18 19:25:32 MSK 2011


I'm learning to use ESL in C++ to do a call control and I want to share my
code with the community.

I had a little difficult at startup so I hope that this code can help
someone.

The code is: http://pastebin.freeswitch.org/15418

Using "esl_oop" module, I have implemented a basic ESL Channel class (that
can be extended) so the "main" event handling loop can be very simple, for
example for an unuseful esl bridge application, can be:

    ESLchannel legA(&connection, inbound_uuid);

    ESLchannel legB(&connection);
    legB.Originate(dialstring)

    while (1)
    {
        ESLevent * event = connection.recvEventTimed(1000);

        if (event)
        {
            const char * ename = event->getHeader("Event-Name");
            const char * event_uuid = event->getHeader("unique-id");

            // It's an event for LegB ?
            //-------------------------
            if (legB.Uuid() == event_uuid)
            {
                if (!strcmp(ename, "CHANNEL_PROGRESS_MEDIA"))
                {
                    legA.PreAnswer();
                    legA.BridgeTo(legB);
                }
                else if (!strcmp(ename, "CHANNEL_ANSWER"))
                {
                    legA.Answer();
                    legA.BridgeTo(legB);
                }
                else if (!strcmp(ename,"CHANNEL_HANGUP"))
                {
                    const char * cause = event->getHeader("Hangup-Cause");

                    legA.Hangup(cause);
                }
            }
            // It's an event for LegA ?
            //-------------------------
            else if (legA.Uuid() == event_uuid)
            {
                if (!strcmp(ename,"CHANNEL_HANGUP"))
                {
                    const char * cause = event->getHeader("Hangup-Cause");

                    legB.Hangup(cause);
                }
            }

            delete event;
        }
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110218/6180c6c3/attachment-0001.html 


More information about the FreeSWITCH-users mailing list