I'm learning to use ESL in C++ to do a call control and I want to share my code with the community.<div><br><div>I had a little difficult at startup so I hope that this code can help someone.</div><div><br></div><div>The code is: <a href="http://pastebin.freeswitch.org/15418">http://pastebin.freeswitch.org/15418</a></div>
<div><br></div><div>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:</div>
<div><br></div><div> ESLchannel legA(&connection, inbound_uuid);</div><div><br></div><div> ESLchannel legB(&connection);</div><div> legB.Originate(dialstring)</div><div><br></div><div> while (1)</div><div>
{</div><div><div> ESLevent * event = connection.recvEventTimed(1000);</div><div><br></div><div> if (event)</div><div> {</div><div> const char * ename = event->getHeader("Event-Name");</div>
<div> const char * event_uuid = event->getHeader("unique-id");</div><div><br></div><div> // It's an event for LegB ?</div><div> //-------------------------</div><div> if (legB.Uuid() == event_uuid)</div>
<div> {</div><div> if (!strcmp(ename, "CHANNEL_PROGRESS_MEDIA"))</div><div> {</div><div> legA.PreAnswer();</div><div> legA.BridgeTo(legB);</div>
<div> }</div><div> else if (!strcmp(ename, "CHANNEL_ANSWER"))</div><div> {</div><div> legA.Answer();</div><div> legA.BridgeTo(legB);</div>
<div> }</div><div> else if (!strcmp(ename,"CHANNEL_HANGUP"))</div><div> {</div><div> const char * cause = event->getHeader("Hangup-Cause");</div>
<div><br></div><div> legA.Hangup(cause);</div><div> }</div><div> }</div><div> // It's an event for LegA ?</div><div> //-------------------------</div>
<div> else if (legA.Uuid() == event_uuid)</div><div> {</div><div> if (!strcmp(ename,"CHANNEL_HANGUP"))</div><div> {</div><div> const char * cause = event->getHeader("Hangup-Cause");</div>
<div><br></div><div> legB.Hangup(cause);</div><div> }</div><div> }</div><div><br></div><div> delete event;</div><div> }</div></div></div><div> }</div>