<!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 "fshost.h"
</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("Everything OK, Entering runtime loop.\n");
</span><ins>+
+ if (switch_event_bind("FSHost", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventHandlerCallback, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+ printf("Something went really wrong while binding to events...");
+ }
+
</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("We have properly shutdown the core.\n");
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void FSHost::generalEventHandler(switch_event_t *event)
+{
+ switch(event->event_id) {
+ case SWITCH_EVENT_CUSTOM:
+ {
+ if (strcmp(event->subclass_name, "portaudio::ringing") == 0)
+ {
+ emit ringing(switch_event_get_header_nil(event, "call_id"), switch_event_get_header_nil(event, "Caller-Caller-ID-Number"), switch_event_get_header_nil(event, "Caller-Caller-ID-Name"));
+ }
+ else
+ {
+ printf("We got a not treated custom event: %s\n", (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
+ }
+ break;
+ }
+ default:
+ {
+ printf("Untreated event: %s -> %s\n", switch_event_name(event->event_id), (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
+ }
+ }
+}
+
</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(&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->setupUi(this);
</span><del>- this->fshost = new FSHost();
</del><span class="cx">
</span><del>- connect(this->fshost, SIGNAL(ready()),this, SLOT(fshostReady()));
</del><ins>+ connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
+ connect(&g_FSHost, SIGNAL(ringing(QString,QString,QString)), this, SLOT(ringing(QString,QString,QString)));
</ins><span class="cx"> connect(ui->paDevlistBtn, SIGNAL(clicked()), this, SLOT(paDevlist()));
</span><span class="cx"> connect(ui->showCodecsBtn, SIGNAL(clicked()), this, SLOT(showCodecs()));
</span><span class="cx">
</span><del>- this->fshost->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->fshost->sendCmd("fsctl", "shutdown", &res);
- this->fshost->wait();
</del><ins>+ g_FSHost.sendCmd("fsctl", "shutdown", &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->fshost->sendCmd("pa", "devlist as xml", &result) == SWITCH_STATUS_FALSE) {
</del><ins>+ if (g_FSHost.sendCmd("pa", "devlist as xml", &result) == SWITCH_STATUS_FALSE) {
</ins><span class="cx"> ui->textEdit->setText("Error sending that command");
</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->fshost->sendCmd("show", "codecs as xml", &result) == SWITCH_STATUS_FALSE) {
</del><ins>+ if (g_FSHost.sendCmd("show", "codecs as xml", &result) == SWITCH_STATUS_FALSE) {
</ins><span class="cx"> ui->textEdit->setText("Error sending that command");
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ui->textEdit->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->textEdit->setText(QString("call_id: %1, Number: %2, Name: %3").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 <QMainWindow>
</span><ins>+#include <switch.h>
</ins><span class="cx"> #include <fshost.h>
</span><del>-#include <switch.h>
</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>