Revision
16131
Author
jmesquita
Date
2010-01-03 17:36:24 -0600 (Sun, 03 Jan 2010)

Log Message

Got part of the outgoing events working and no mem leaking (I think).

Modified Paths

Diff

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/call.h (16130 => 16131)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/call.h	2010-01-03 21:10:34 UTC (rev 16130)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/call.h	2010-01-03 23:36:24 UTC (rev 16131)
@@ -34,6 +34,12 @@
 #include <fshost.h>
 
 typedef enum {
+    FSPHONE_CALL_STATE_RINGING = 0,
+    FSPHONE_CALL_STATE_TRYING  = 1,
+    FSPHONE_CALL_STATE_ANSWERED = 2
+} fsphone_call_state_t;
+
+typedef enum {
         FSPHONE_CALL_DIRECTION_INBOUND = 0,
         FSPHONE_CALL_DIRECTION_OUTBOUND = 1
 } fsphone_call_direction_t;
@@ -49,6 +55,8 @@
     QString getUUID(void) { return _uuid; }
     void setbUUID(QString uuid) { _buuid = uuid; }
     fsphone_call_direction_t getDirection() { return _direction; }
+    fsphone_call_state_t getState() { return _state; }
+    void setState(fsphone_call_state_t state) { _state = state; }
 
 private:
     int _call_id;
@@ -57,6 +65,7 @@
     fsphone_call_direction_t _direction;
     QString _uuid;
     QString _buuid;
+    fsphone_call_state_t _state;
 };
 
 Q_DECLARE_METATYPE(Call)

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16130 => 16131)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp	2010-01-03 21:10:34 UTC (rev 16130)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp	2010-01-03 23:36:24 UTC (rev 16131)
@@ -147,19 +147,23 @@
 
 switch_status_t FSHost::processAlegEvent(switch_event_t * event, QString uuid)
 {
-    if (_active_calls.value(uuid)->getDirection() == FSPHONE_CALL_DIRECTION_INBOUND)
+    switch_status_t status = SWITCH_STATUS_SUCCESS;
+    Call * call = _active_calls.value(uuid);
+    /* Inbound call */
+    if (call->getDirection() == FSPHONE_CALL_DIRECTION_INBOUND)
     {
         switch(event->event_id) {
         case SWITCH_EVENT_CHANNEL_ANSWER:
             {
-                _active_calls.value(uuid)->setbUUID(switch_event_get_header_nil(event, "Other-Leg-Unique-ID"));
+                call->setbUUID(switch_event_get_header_nil(event, "Other-Leg-Unique-ID"));
                 _bleg_uuids.insert(switch_event_get_header_nil(event, "Other-Leg-Unique-ID"), uuid);
+                call->setState(FSPHONE_CALL_STATE_ANSWERED);
                 emit answered(uuid);
                 break;
             }
         case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
             {
-                emit hungup(uuid);
+                emit hungup(_active_calls.take(uuid));
                 break;
             }
         case SWITCH_EVENT_CHANNEL_STATE:
@@ -184,20 +188,30 @@
                 _bleg_uuids.insert(switch_event_get_header_nil(event, "Other-Leg-Unique-ID"), uuid);
                 break;
             }
+        case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
+            {
+                if (call->getState() == FSPHONE_CALL_STATE_TRYING)
+                {
+                    emit callFailed(uuid);
+                    _active_calls.take(uuid);
+                }
+                break;
+            }
         default:
+            printf("A leg: %s(%s)\n",switch_event_name(event->event_id), switch_event_get_header_nil(event, "Event-Subclass"));
             break;
         }
     }
-    return SWITCH_STATUS_SUCCESS;
+    return status;
 }
 
 switch_status_t FSHost::processBlegEvent(switch_event_t * event, QString buuid)
 {
     QString uuid = _bleg_uuids.value(buuid);
-    printf("We know this is an uuid related to our call: %s | Event: %s\n", buuid.toAscii().constData(),
-           switch_event_name(event->event_id));
+    switch_status_t status = SWITCH_STATUS_SUCCESS;
+    Call * call = _active_calls.value(uuid);
     /* Inbound call */
-    if (_active_calls.value(uuid)->getDirection() == FSPHONE_CALL_DIRECTION_INBOUND)
+    if (call->getDirection() == FSPHONE_CALL_DIRECTION_INBOUND)
     {
         qDebug() << " Inbound call";
     }
@@ -209,12 +223,31 @@
         case SWITCH_EVENT_CHANNEL_ANSWER:
             {
                 emit answered(uuid);
+                break;
             }
+        case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
+            {
+                emit hungup(_active_calls.take(uuid));
+                _bleg_uuids.take(buuid);
+                break;
+            }
+        case SWITCH_EVENT_CHANNEL_STATE:
+            {
+                if (QString(switch_event_get_header_nil(event, "Answer-State")) == "early")
+                {
+                    call->setState(FSPHONE_CALL_STATE_RINGING);
+                    emit ringing(uuid);
+                }
+                //printEventHeaders(event);
+                break;
+            }
+
         default:
+            printf("B leg: %s(%s)\n",switch_event_name(event->event_id), switch_event_get_header_nil(event, "Event-Subclass"));
             break;
         }
     }
-    return SWITCH_STATUS_SUCCESS;
+    return status;
 }
 
 void FSHost::generalEventHandler(switch_event_t *event)
@@ -248,6 +281,7 @@
                                       FSPHONE_CALL_DIRECTION_INBOUND,
                                       uuid);
                 _active_calls.insert(uuid, call);
+                call->setState(FSPHONE_CALL_STATE_RINGING);
                 emit ringing(uuid);
             }
             else if (strcmp(event->subclass_name, "portaudio::makecall") == 0)
@@ -257,6 +291,7 @@
                                       FSPHONE_CALL_DIRECTION_OUTBOUND,
                                       uuid);
                 _active_calls.insert(uuid, call);
+                call->setState(FSPHONE_CALL_STATE_TRYING);
                 emit newOutgoingCall(uuid);
             }
             else if (strcmp(event->subclass_name, "sofia::gateway_state") == 0)
@@ -288,6 +323,8 @@
             }
             break;
         }
+    default:
+        break;
     }
 }
 
@@ -301,3 +338,13 @@
 
     return status;
 }
+
+void FSHost::printEventHeaders(switch_event_t *event)
+{
+    switch_event_header_t *hp;
+    printf("Received event: %s(%s)\n", switch_event_name(event->event_id), switch_event_get_header_nil(event, "Event-Subclass"));
+    for (hp = event->headers; hp; hp = hp->next) {
+        printf("%s=%s\n", hp->name, hp->value);
+    }
+    printf("\n\n");
+}

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h (16130 => 16131)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h	2010-01-03 21:10:34 UTC (rev 16130)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h	2010-01-03 23:36:24 UTC (rev 16131)
@@ -76,12 +76,14 @@
     void ringing(QString);
     void answered(QString);
     void newOutgoingCall(QString);
-    void hungup(QString);
+    void callFailed(QString);
+    void hungup(Call*);
     void gwStateChange(QString, int);
 
 private:
     switch_status_t processBlegEvent(switch_event_t *, QString);
     switch_status_t processAlegEvent(switch_event_t *, QString);
+    void printEventHeaders(switch_event_t *event);
     QHash<QString, Call*> _active_calls;
     QHash<QString, QString> _bleg_uuids;
 };

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp (16130 => 16131)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp	2010-01-03 21:10:34 UTC (rev 16130)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp	2010-01-03 23:36:24 UTC (rev 16131)
@@ -68,7 +68,7 @@
     connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
     connect(&g_FSHost, SIGNAL(ringing(QString)), this, SLOT(ringing(QString)));
     connect(&g_FSHost, SIGNAL(answered(QString)), this, SLOT(answered(QString)));
-    connect(&g_FSHost, SIGNAL(hungup(QString)), this, SLOT(hungup(QString)));
+    connect(&g_FSHost, SIGNAL(hungup(Call*)), this, SLOT(hungup(Call*)));
     connect(&g_FSHost, SIGNAL(newOutgoingCall(QString)), this, SLOT(newOutgoingCall(QString)));
     connect(&g_FSHost, SIGNAL(gwStateChange(QString,int)), this, SLOT(gwStateChanged(QString,int)));
     /*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/
@@ -210,6 +210,17 @@
 {
 
     Call *call = g_FSHost.getCallByUUID(uuid);
+    for (int i=0; i<ui->listCalls->count(); i++)
+    {
+        QListWidgetItem *item = ui->listCalls->item(i);
+        if (item->data(Qt::UserRole).toString() == uuid)
+        {
+            item->setText(tr("%1 - Ringing").arg(call->getCidNumber()));
+            ui->textEdit->setText(QString("Call from %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
+            return;
+        }
+    }
+
     ui->textEdit->setText(QString("Call from %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
     QListWidgetItem *item = new QListWidgetItem(tr("%1 (%2) - Ringing").arg(call->getCidName(), call->getCidNumber()));
     item->setData(Qt::UserRole, uuid);
@@ -225,8 +236,16 @@
         QListWidgetItem *item = ui->listCalls->item(i);
         if (item->data(Qt::UserRole).toString() == uuid)
         {
-            item->setText(tr("%1 (%2) - Active").arg(call->getCidName(), call->getCidNumber()));
-            break;
+            if (call->getDirection() == FSPHONE_CALL_DIRECTION_INBOUND)
+            {
+                item->setText(tr("%1 (%2) - Active").arg(call->getCidName(), call->getCidNumber()));
+                break;
+            }
+            else
+            {
+                item->setText(tr("%1 - Active").arg(call->getCidNumber()));
+                break;
+            }
         }
     }
     ui->dtmf0Btn->setEnabled(true);
@@ -243,13 +262,12 @@
     ui->dtmfPoundBtn->setEnabled(true);
 }
 
-void MainWindow::hungup(QString uuid)
+void MainWindow::hungup(Call* call)
 {
-    Call *call = g_FSHost.getCallByUUID(uuid);
     for (int i=0; i<ui->listCalls->count(); i++)
     {
         QListWidgetItem *item = ui->listCalls->item(i);
-        if (item->data(Qt::UserRole).toString() == uuid)
+        if (item->data(Qt::UserRole).toString() == call->getUUID())
         {
             delete ui->listCalls->takeItem(i);
             break;
@@ -271,6 +289,7 @@
     ui->dtmf9Btn->setEnabled(false);
     ui->dtmfAstBtn->setEnabled(false);
     ui->dtmfPoundBtn->setEnabled(false);
+    delete call;
 }
 
 void MainWindow::changeEvent(QEvent *e)

Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h (16130 => 16131)


--- freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h	2010-01-03 21:10:34 UTC (rev 16130)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.h	2010-01-03 23:36:24 UTC (rev 16131)
@@ -67,7 +67,7 @@
     void newOutgoingCall(QString);
     void ringing(QString);
     void answered(QString);
-    void hungup(QString);
+    void hungup(Call*);
 
 private:
     Ui::MainWindow *ui;