]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
adjust
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 25 Apr 2006 23:11:56 +0000 (23:11 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 25 Apr 2006 23:11:56 +0000 (23:11 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1255 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_channel.c
src/switch_core.c
src/switch_event.c

index 8f668fbdd2e17b4fb6d1e2d9b9dc896211175dde..063a3e9a89783d7f5c62f1b058d1d6492ec6b518 100644 (file)
@@ -496,7 +496,8 @@ typedef enum {
 
 <pre>
     SWITCH_EVENT_CUSTOM                                - A custom event
-    SWITCH_EVENT_CHANNEL_CREATE                - A channel has changed state
+    SWITCH_EVENT_CHANNEL_CREATE                - A channel has been created
+    SWITCH_EVENT_CHANNEL_DESTROY       - A channel has been destroyed
     SWITCH_EVENT_CHANNEL_STATE         - A channel has changed state
     SWITCH_EVENT_CHANNEL_ANSWER                - A channel has been answered
     SWITCH_EVENT_CHANNEL_HANGUP                - A channel has been hungup
@@ -520,6 +521,7 @@ typedef enum {
 typedef enum {
        SWITCH_EVENT_CUSTOM,
        SWITCH_EVENT_CHANNEL_CREATE,
+       SWITCH_EVENT_CHANNEL_DESTROY,
        SWITCH_EVENT_CHANNEL_STATE,
        SWITCH_EVENT_CHANNEL_ANSWER,
        SWITCH_EVENT_CHANNEL_HANGUP,
index e9389e3f9fe074b550bc6048b34e601e75677f3a..1bc0113eb061f913989a392a55342f12ada10752 100644 (file)
@@ -483,6 +483,8 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
 
 
        if (ok) {
+               switch_event *event;
+               
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s State Change %s -> %s\n", channel->name,
                                                          state_names[last_state], state_names[state]);
                channel->state = state;
@@ -491,6 +493,11 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
                        channel->hangup_cause = SWITCH_CAUSE_NORMAL_CLEARING;
                }
 
+               if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
+                       switch_channel_event_set_data(channel, event);
+                       switch_event_fire(&event);
+               }
+               
                if (state < CS_DONE) {
                        switch_core_session_signal_state_change(channel->session);
                }
@@ -690,8 +697,15 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_hangup(switch_channel *chann
        }
 
        if (channel->state < CS_HANGUP) {
+               switch_event *event;
+
                channel->state = CS_HANGUP;
                channel->hangup_cause = hangup_cause;
+               if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
+                       switch_channel_event_set_data(channel, event);
+                       switch_event_fire(&event);
+               }
+
                switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
                switch_core_session_signal_state_change(channel->session);
        }
index b02b31531b71abaeecbe22fdbab97d9a8d2b3a54..2c6b62d260f53e5f09588f91505c0d89bcd929f3 100644 (file)
@@ -1837,17 +1837,11 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
        switch_mutex_lock(session->mutex);
 
        while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
-               switch_event *event;
-
                if (state != laststate) {
                        int index = 0;
                        int proceed = 1;
                        midstate = state;
 
-                       if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_STATE) == SWITCH_STATUS_SUCCESS) {
-                               switch_channel_event_set_data(session->channel, event);
-                               switch_event_fire(&event);
-                       }
 
                        switch (state) {
                        case CS_NEW:            /* Just created, Waiting for first instructions */
@@ -2095,6 +2089,12 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
 SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session **session)
 {
        switch_memory_pool *pool;
+       switch_event *event;
+
+       if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DESTROY) == SWITCH_STATUS_SUCCESS) {
+               switch_channel_event_set_data(session->channel, event);
+               switch_event_fire(&event);
+       }
 
        pool = (*session)->pool;
        *session = NULL;
@@ -2336,6 +2336,11 @@ static void core_event_handler(switch_event *event)
        }
 
        switch (event->event_id) {
+
+       case SWITCH_EVENT_CHANNEL_DESTROY:
+               snprintf(buf, sizeof(buf), "delete from channels where uuid='%s'", switch_event_get_header(event, "unique-id"));
+               sql = buf;
+               break;
        case SWITCH_EVENT_CHANNEL_CREATE:
                snprintf(buf, sizeof(buf), "insert into channels (uuid,created,name,state) values('%s','%s','%s','%s')",
                                 switch_event_get_header(event, "unique-id"),
@@ -2360,8 +2365,7 @@ static void core_event_handler(switch_event *event)
 
                        switch(state_i) {
                        case CS_HANGUP:
-                               snprintf(buf, sizeof(buf), "delete from channels where uuid='%s'", switch_event_get_header(event, "unique-id"));
-                               sql = buf;
+                       case CS_DONE:
                                break;
                        case CS_RING:
                                snprintf(buf, sizeof(buf), "update channels set state='%s',cid_name='%s',cid_num='%s',ip_addr='%s',dest='%s'"
@@ -2440,6 +2444,7 @@ static void core_event_handler(switch_event *event)
                                break;
                        }
                }
+               //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL [%s]\n", sql);
        }
 }
 
index 2d52f7b1741fc96b029e98ca42dd4a7a86bae1b5..6bd49af7c030fd551f839c49fe02e1e2330e28bf 100644 (file)
@@ -85,6 +85,7 @@ also never put any new ones before EVENT_ALL
 static char *EVENT_NAMES[] = {
        "CUSTOM",
        "CHANNEL_CREATE",
+       "CHANNEL_DESTROY",
        "CHANNEL_STATE",
        "CHANNEL_ANSWER",
        "CHANNEL_HANGUP",