Diff
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16103 => 16104)
--- 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)
@@ -1,5 +1,8 @@
#include "fshost.h"
+/* Declare it globally */
+FSHost g_FSHost;
+
FSHost::FSHost(QObject *parent) :
QThread(parent)
{
@@ -25,6 +28,12 @@
}
printf("Everything OK, Entering runtime loop.\n");
+
+ 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...");
+ }
+
emit ready();
/* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set
* If its false, it initializes the libedit for the console, then does the same thing
@@ -32,10 +41,38 @@
switch_core_runtime_loop(!console);
fflush(stdout);
+
+ switch_event_unbind_callback(eventHandlerCallback);
/* When the runtime loop exits, its time to shutdown */
destroy_status = switch_core_destroy();
+ if (destroy_status == SWITCH_STATUS_SUCCESS)
+ {
+ printf("We have properly shutdown the core.\n");
+ }
}
+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"));
+ }
+ }
+}
+
switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res)
{
switch_status_t status = SWITCH_STATUS_FALSE;
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h (16103 => 16104)
--- 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)
@@ -10,13 +10,30 @@
public:
explicit FSHost(QObject *parent = 0);
switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
+ void generalEventHandler(switch_event_t *event);
protected:
void run(void);
signals:
void ready(void);
+ void ringing(QString uuid, QString caller_id_name, QString caller_id_name);
};
+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);*/
+}
+
#endif // FSHOST_H
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp (16103 => 16104)
--- 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)
@@ -6,21 +6,21 @@
ui(new Ui::MainWindow)
{
ui->setupUi(this);
- this->fshost = new FSHost();
- connect(this->fshost, SIGNAL(ready()),this, SLOT(fshostReady()));
+ connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
+ connect(&g_FSHost, SIGNAL(ringing(QString,QString,QString)), this, SLOT(ringing(QString,QString,QString)));
connect(ui->paDevlistBtn, SIGNAL(clicked()), this, SLOT(paDevlist()));
connect(ui->showCodecsBtn, SIGNAL(clicked()), this, SLOT(showCodecs()));
- this->fshost->start();
+ g_FSHost.start();
}
MainWindow::~MainWindow()
{
delete ui;
QString res;
- this->fshost->sendCmd("fsctl", "shutdown", &res);
- this->fshost->wait();
+ g_FSHost.sendCmd("fsctl", "shutdown", &res);
+ g_FSHost.wait();
}
void MainWindow::fshostReady()
@@ -31,7 +31,7 @@
void MainWindow::paDevlist()
{
QString result;
- if (this->fshost->sendCmd("pa", "devlist as xml", &result) == SWITCH_STATUS_FALSE) {
+ if (g_FSHost.sendCmd("pa", "devlist as xml", &result) == SWITCH_STATUS_FALSE) {
ui->textEdit->setText("Error sending that command");
}
@@ -41,13 +41,18 @@
void MainWindow::showCodecs()
{
QString result;
- if (this->fshost->sendCmd("show", "codecs as xml", &result) == SWITCH_STATUS_FALSE) {
+ if (g_FSHost.sendCmd("show", "codecs as xml", &result) == SWITCH_STATUS_FALSE) {
ui->textEdit->setText("Error sending that command");
}
ui->textEdit->setText(result);
}
+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));
+}
+
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h (16103 => 16104)
--- 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)
@@ -34,8 +34,8 @@
#define MAINWINDOW_H
#include <QMainWindow>
+#include <switch.h>
#include <fshost.h>
-#include <switch.h>
namespace Ui {
class MainWindow;
@@ -54,10 +54,10 @@
void fshostReady();
void paDevlist();
void showCodecs();
+ void ringing(QString, QString, QString);
private:
Ui::MainWindow *ui;
- FSHost *fshost;
};
#endif // MAINWINDOW_H