<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16104] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16104">16104</a></dd>
<dt>Author</dt> <dd>jmesquita</dd>
<dt>Date</dt> <dd>2009-12-31 11:34:19 -0600 (Thu, 31 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>We now bind to events and treat the ringing event.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonefshostcpp">freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonefshosth">freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonemainwindowcpp">freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonemainwindowh">freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribjmesquitaFSPhonefshostcpp"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16103 => 16104)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp        2009-12-31 05:43:07 UTC (rev 16103)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp        2009-12-31 17:34:19 UTC (rev 16104)
</span><span class="lines">@@ -1,5 +1,8 @@
</span><span class="cx"> #include &quot;fshost.h&quot;
</span><span class="cx"> 
</span><ins>+/* Declare it globally */
+FSHost g_FSHost;
+
</ins><span class="cx"> FSHost::FSHost(QObject *parent) :
</span><span class="cx">     QThread(parent)
</span><span class="cx"> {
</span><span class="lines">@@ -25,6 +28,12 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     printf(&quot;Everything OK, Entering runtime loop.\n&quot;);
</span><ins>+
+    if (switch_event_bind(&quot;FSHost&quot;, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventHandlerCallback, NULL) != SWITCH_STATUS_SUCCESS) {
+            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't bind!\n&quot;);
+            printf(&quot;Something went really wrong while binding to events...&quot;);
+    }
+
</ins><span class="cx">     emit ready();
</span><span class="cx">     /* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set
</span><span class="cx">      * If its false, it initializes the libedit for the console, then does the same thing
</span><span class="lines">@@ -32,10 +41,38 @@
</span><span class="cx">     switch_core_runtime_loop(!console);
</span><span class="cx">     fflush(stdout);
</span><span class="cx"> 
</span><ins>+
+    switch_event_unbind_callback(eventHandlerCallback);
</ins><span class="cx">     /* When the runtime loop exits, its time to shutdown */
</span><span class="cx">     destroy_status = switch_core_destroy();
</span><ins>+    if (destroy_status == SWITCH_STATUS_SUCCESS)
+    {
+        printf(&quot;We have properly shutdown the core.\n&quot;);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void FSHost::generalEventHandler(switch_event_t *event)
+{
+    switch(event-&gt;event_id) {
+    case SWITCH_EVENT_CUSTOM:
+        {
+            if (strcmp(event-&gt;subclass_name, &quot;portaudio::ringing&quot;) == 0)
+            {
+                emit ringing(switch_event_get_header_nil(event, &quot;call_id&quot;), switch_event_get_header_nil(event, &quot;Caller-Caller-ID-Number&quot;), switch_event_get_header_nil(event, &quot;Caller-Caller-ID-Name&quot;));
+            }
+            else
+            {
+                printf(&quot;We got a not treated custom event: %s\n&quot;, (!zstr(event-&gt;subclass_name) ? event-&gt;subclass_name : &quot;NULL&quot;));
+            }
+            break;
+        }
+    default:
+        {
+            printf(&quot;Untreated event: %s -&gt; %s\n&quot;, switch_event_name(event-&gt;event_id), (!zstr(event-&gt;subclass_name) ? event-&gt;subclass_name : &quot;NULL&quot;));
+        }
+    }
+}
+
</ins><span class="cx"> switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res)
</span><span class="cx"> {
</span><span class="cx">     switch_status_t status = SWITCH_STATUS_FALSE;
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonefshosth"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h (16103 => 16104)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h        2009-12-31 05:43:07 UTC (rev 16103)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h        2009-12-31 17:34:19 UTC (rev 16104)
</span><span class="lines">@@ -10,13 +10,30 @@
</span><span class="cx"> public:
</span><span class="cx">     explicit FSHost(QObject *parent = 0);
</span><span class="cx">     switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
</span><ins>+    void generalEventHandler(switch_event_t *event);
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     void run(void);
</span><span class="cx"> 
</span><span class="cx"> signals:
</span><span class="cx">     void ready(void);
</span><ins>+    void ringing(QString uuid, QString caller_id_name, QString caller_id_name);
</ins><span class="cx"> 
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+extern FSHost g_FSHost;
+
+/*
+   Used to match callback from fs core. We dup the event and call the class
+   method callback to make use of the signal/slot infrastructure.
+*/
+static void eventHandlerCallback(switch_event_t *event)
+{
+    switch_event_t *clone = NULL;
+    if (switch_event_dup(&amp;clone, event) == SWITCH_STATUS_SUCCESS) {
+        g_FSHost.generalEventHandler(clone);
+    }
+    /*switch_safe_free(event);*/
+}
+
</ins><span class="cx"> #endif // FSHOST_H
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonemainwindowcpp"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp (16103 => 16104)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp        2009-12-31 05:43:07 UTC (rev 16103)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp        2009-12-31 17:34:19 UTC (rev 16104)
</span><span class="lines">@@ -6,21 +6,21 @@
</span><span class="cx">     ui(new Ui::MainWindow)
</span><span class="cx"> {
</span><span class="cx">     ui-&gt;setupUi(this);
</span><del>-    this-&gt;fshost = new FSHost();
</del><span class="cx"> 
</span><del>-    connect(this-&gt;fshost, SIGNAL(ready()),this, SLOT(fshostReady()));
</del><ins>+    connect(&amp;g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
+    connect(&amp;g_FSHost, SIGNAL(ringing(QString,QString,QString)), this, SLOT(ringing(QString,QString,QString)));
</ins><span class="cx">     connect(ui-&gt;paDevlistBtn, SIGNAL(clicked()), this, SLOT(paDevlist()));
</span><span class="cx">     connect(ui-&gt;showCodecsBtn, SIGNAL(clicked()), this, SLOT(showCodecs()));
</span><span class="cx"> 
</span><del>-    this-&gt;fshost-&gt;start();
</del><ins>+    g_FSHost.start();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> MainWindow::~MainWindow()
</span><span class="cx"> {
</span><span class="cx">     delete ui;
</span><span class="cx">     QString res;
</span><del>-    this-&gt;fshost-&gt;sendCmd(&quot;fsctl&quot;, &quot;shutdown&quot;, &amp;res);
-    this-&gt;fshost-&gt;wait();
</del><ins>+    g_FSHost.sendCmd(&quot;fsctl&quot;, &quot;shutdown&quot;, &amp;res);
+    g_FSHost.wait();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MainWindow::fshostReady()
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> void MainWindow::paDevlist()
</span><span class="cx"> {
</span><span class="cx">     QString result;
</span><del>-    if (this-&gt;fshost-&gt;sendCmd(&quot;pa&quot;, &quot;devlist as xml&quot;, &amp;result) == SWITCH_STATUS_FALSE) {
</del><ins>+    if (g_FSHost.sendCmd(&quot;pa&quot;, &quot;devlist as xml&quot;, &amp;result) == SWITCH_STATUS_FALSE) {
</ins><span class="cx">         ui-&gt;textEdit-&gt;setText(&quot;Error sending that command&quot;);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -41,13 +41,18 @@
</span><span class="cx"> void MainWindow::showCodecs()
</span><span class="cx"> {
</span><span class="cx">     QString result;
</span><del>-    if (this-&gt;fshost-&gt;sendCmd(&quot;show&quot;, &quot;codecs as xml&quot;, &amp;result) == SWITCH_STATUS_FALSE) {
</del><ins>+    if (g_FSHost.sendCmd(&quot;show&quot;, &quot;codecs as xml&quot;, &amp;result) == SWITCH_STATUS_FALSE) {
</ins><span class="cx">         ui-&gt;textEdit-&gt;setText(&quot;Error sending that command&quot;);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ui-&gt;textEdit-&gt;setText(result);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void MainWindow::ringing(QString uuid, QString caller_id_number, QString caller_id_name)
+{
+    ui-&gt;textEdit-&gt;setText(QString(&quot;call_id: %1, Number: %2, Name: %3&quot;).arg(uuid, caller_id_number, caller_id_name));
+}
+
</ins><span class="cx"> void MainWindow::changeEvent(QEvent *e)
</span><span class="cx"> {
</span><span class="cx">     QMainWindow::changeEvent(e);
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonemainwindowh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h (16103 => 16104)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h        2009-12-31 05:43:07 UTC (rev 16103)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h        2009-12-31 17:34:19 UTC (rev 16104)
</span><span class="lines">@@ -34,8 +34,8 @@
</span><span class="cx"> #define MAINWINDOW_H
</span><span class="cx"> 
</span><span class="cx"> #include &lt;QMainWindow&gt;
</span><ins>+#include &lt;switch.h&gt;
</ins><span class="cx"> #include &lt;fshost.h&gt;
</span><del>-#include &lt;switch.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace Ui {
</span><span class="cx">     class MainWindow;
</span><span class="lines">@@ -54,10 +54,10 @@
</span><span class="cx">     void fshostReady();
</span><span class="cx">     void paDevlist();
</span><span class="cx">     void showCodecs();
</span><ins>+    void ringing(QString, QString, QString);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     Ui::MainWindow *ui;
</span><del>-    FSHost *fshost;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #endif // MAINWINDOW_H
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>