提交 aaeebc8a authored 作者: João Mesquita's avatar João Mesquita

We now bind to events and treat the ringing event.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@16104 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 34c7fd1e
#include "fshost.h" #include "fshost.h"
/* Declare it globally */
FSHost g_FSHost;
FSHost::FSHost(QObject *parent) : FSHost::FSHost(QObject *parent) :
QThread(parent) QThread(parent)
{ {
...@@ -25,6 +28,12 @@ void FSHost::run(void) ...@@ -25,6 +28,12 @@ void FSHost::run(void)
} }
printf("Everything OK, Entering runtime loop.\n"); 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(); emit ready();
/* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set /* 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 * If its false, it initializes the libedit for the console, then does the same thing
...@@ -32,8 +41,36 @@ void FSHost::run(void) ...@@ -32,8 +41,36 @@ void FSHost::run(void)
switch_core_runtime_loop(!console); switch_core_runtime_loop(!console);
fflush(stdout); fflush(stdout);
switch_event_unbind_callback(eventHandlerCallback);
/* When the runtime loop exits, its time to shutdown */ /* When the runtime loop exits, its time to shutdown */
destroy_status = switch_core_destroy(); 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 FSHost::sendCmd(const char *cmd, const char *args, QString *res)
......
...@@ -10,13 +10,30 @@ Q_OBJECT ...@@ -10,13 +10,30 @@ Q_OBJECT
public: public:
explicit FSHost(QObject *parent = 0); explicit FSHost(QObject *parent = 0);
switch_status_t sendCmd(const char *cmd, const char *args, QString *res); switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event);
protected: protected:
void run(void); void run(void);
signals: signals:
void ready(void); 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 #endif // FSHOST_H
...@@ -6,21 +6,21 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -6,21 +6,21 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); 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->paDevlistBtn, SIGNAL(clicked()), this, SLOT(paDevlist()));
connect(ui->showCodecsBtn, SIGNAL(clicked()), this, SLOT(showCodecs())); connect(ui->showCodecsBtn, SIGNAL(clicked()), this, SLOT(showCodecs()));
this->fshost->start(); g_FSHost.start();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
QString res; QString res;
this->fshost->sendCmd("fsctl", "shutdown", &res); g_FSHost.sendCmd("fsctl", "shutdown", &res);
this->fshost->wait(); g_FSHost.wait();
} }
void MainWindow::fshostReady() void MainWindow::fshostReady()
...@@ -31,7 +31,7 @@ void MainWindow::fshostReady() ...@@ -31,7 +31,7 @@ void MainWindow::fshostReady()
void MainWindow::paDevlist() void MainWindow::paDevlist()
{ {
QString result; 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"); ui->textEdit->setText("Error sending that command");
} }
...@@ -41,13 +41,18 @@ void MainWindow::paDevlist() ...@@ -41,13 +41,18 @@ void MainWindow::paDevlist()
void MainWindow::showCodecs() void MainWindow::showCodecs()
{ {
QString result; 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("Error sending that command");
} }
ui->textEdit->setText(result); 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) void MainWindow::changeEvent(QEvent *e)
{ {
QMainWindow::changeEvent(e); QMainWindow::changeEvent(e);
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <fshost.h>
#include <switch.h> #include <switch.h>
#include <fshost.h>
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
...@@ -54,10 +54,10 @@ private slots: ...@@ -54,10 +54,10 @@ private slots:
void fshostReady(); void fshostReady();
void paDevlist(); void paDevlist();
void showCodecs(); void showCodecs();
void ringing(QString, QString, QString);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
FSHost *fshost;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论