]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add optional pool arguement to outgoing channel to allow pre-created pools to be...
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 2 Mar 2006 14:49:23 +0000 (14:49 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 2 Mar 2006 14:49:23 +0000 (14:49 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@726 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/include/switch_module_interfaces.h
src/mod/applications/mod_bridgecall/mod_bridgecall.c
src/mod/endpoints/mod_exosip/mod_exosip.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
src/mod/endpoints/mod_woomera/mod_woomera.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_core.c

index 3b2fc327b3dbca55b9f477b4c6b8b0e04c596d71..e5249da357a861a2978931851a72b151498e38e2 100644 (file)
@@ -345,12 +345,15 @@ SWITCH_DECLARE(void) switch_core_service_session(switch_core_session *session, s
   \param endpoint_name the name of the module to use for the new session
   \param caller_profile the originator's caller profile
   \param new_session a NULL pointer to aim at the newly created session
+  \param pool optional existing memory pool to donate to the session (WILL BE KEPT)
   \return SWITCH_STATUS_SUCCESS if the session was created
+  \note if the pool arguement is not null the pool will be adopted by the session and your pointer will be nulled
 */
 SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session,
-                                                                                        char *endpoint_name,
-                                                                                        switch_caller_profile *caller_profile,
-                                                                                        switch_core_session **new_session);
+                                                                                                                                  char *endpoint_name,
+                                                                                                                                  switch_caller_profile *caller_profile,
+                                                                                                                                  switch_core_session **new_session,
+                                                                                                                                  switch_memory_pool **pool);
 
 /*! 
   \brief Answer the channel of a given session
index 1bad60b166a6bbca342c6e044230c69c1ab8b613..a8ea0d1819e18d5dfc12e98f22c5875eed16a465 100644 (file)
@@ -150,7 +150,7 @@ struct switch_io_event_hooks {
 /*! \brief A table of i/o routines that an endpoint interface can implement */
 struct switch_io_routines {
        /*! creates an outgoing session from given session, caller profile */
-       switch_status (*outgoing_channel)(switch_core_session *, switch_caller_profile *, switch_core_session **);
+       switch_status (*outgoing_channel)(switch_core_session *, switch_caller_profile *, switch_core_session **, switch_memory_pool *);
        /*! answers the given session's channel */
        switch_status (*answer_channel)(switch_core_session *);
        /*! read a frame from a session */
index 3f064020bffd3296ccd6a3c7d15c7f48228f272d..49de324f27301f684581eec284594e421e600d3c 100644 (file)
@@ -63,7 +63,7 @@ static void audio_bridge_function(switch_core_session *session, char *data)
 
 
 
-       if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) !=
+       if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) !=
                SWITCH_STATUS_SUCCESS) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Create Outgoing Channel!\n");
                switch_channel_hangup(caller_channel);
index 23d6c30b63083a37de947cfac341c54778b97a08..d301b24d5935505e061a6bbe5bdbbe2a965f1013 100644 (file)
@@ -156,7 +156,7 @@ static switch_status exosip_on_hangup(switch_core_session *session);
 static switch_status exosip_on_loopback(switch_core_session *session);
 static switch_status exosip_on_transmit(switch_core_session *session);
 static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                        switch_core_session **new_session);
+                                                                                        switch_core_session **new_session, switch_memory_pool *pool);
 static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
                                                                           switch_io_flag flags, int stream_id);
 static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
@@ -878,9 +878,9 @@ static const switch_loadable_module_interface exosip_module_interface = {
 };
 
 static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                        switch_core_session **new_session)
+                                                                                        switch_core_session **new_session, switch_memory_pool *pool)
 {
-       if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL)) != 0) {
+       if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, pool)) != 0) {
                struct private_object *tech_pvt;
                switch_channel *channel;
 
index 5168df50a7f2a796ca6d79c4164f915e2ff8ef7f..d8f7cd83b0d5b935d7f7266c3466e3727b99912a 100644 (file)
@@ -393,7 +393,7 @@ static switch_status channel_on_ring(switch_core_session *session);
 static switch_status channel_on_loopback(switch_core_session *session);
 static switch_status channel_on_transmit(switch_core_session *session);
 static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                         switch_core_session **new_session);
+                                                                                         switch_core_session **new_session, switch_memory_pool *pool);
 static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
                                                                                switch_io_flag flags, int stream_id);
 static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
@@ -709,9 +709,9 @@ static const switch_loadable_module_interface channel_module_interface = {
 that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
 static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                         switch_core_session **new_session)
+                                                                                         switch_core_session **new_session, switch_memory_pool *pool)
 {
-       if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
+       if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
                struct private_object *tech_pvt;
                switch_channel *channel;
                switch_caller_profile *caller_profile;
index 48f251691a3e20a0885c284acb10e12f68b2cbbb..24e539ff8cfe9844218e77de619018e73ecba0cf 100644 (file)
@@ -105,7 +105,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
         static switch_status channel_on_transmit(switch_core_session *session);
         static switch_status channel_outgoing_channel(switch_core_session *session,
                                                                                                   switch_caller_profile *outbound_profile,
-                                                                                                  switch_core_session **new_session);
+                                                                                                  switch_core_session **new_session, switch_memory_pool *pool);
         static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
                                                                                         switch_io_flag flags, int stream_id);
         static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
@@ -476,9 +476,9 @@ static const switch_loadable_module_interface channel_module_interface = {
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
 static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                         switch_core_session **new_session)
+                                                                                         switch_core_session **new_session, switch_memory_pool *pool)
 {
-       if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
+       if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
                struct private_object *tech_pvt;
                switch_channel *channel;
                switch_caller_profile *caller_profile;
index 281dd54422aa6503a077862585a46ed41eac81de..9d68075c6204e2fc4ada045f173ec76b8ea17470 100644 (file)
@@ -193,7 +193,7 @@ static switch_status wanpipe_on_hangup(switch_core_session *session);
 static switch_status wanpipe_on_loopback(switch_core_session *session);
 static switch_status wanpipe_on_transmit(switch_core_session *session);
 static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                         switch_core_session **new_session);
+                                                                                         switch_core_session **new_session, switch_memory_pool *pool);
 static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
                                                                                switch_io_flag flags, int stream_id);
 static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
@@ -356,7 +356,7 @@ static switch_status wanpipe_on_transmit(switch_core_session *session)
 }
 
 static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                         switch_core_session **new_session)
+                                                                                         switch_core_session **new_session, switch_memory_pool *pool)
 {
        if (!globals.configured_spans) {
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error No Spans Configured.\n");
@@ -364,7 +364,7 @@ static switch_status wanpipe_outgoing_channel(switch_core_session *session, swit
        }
 
 
-       if ((*new_session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) {
+       if ((*new_session = switch_core_session_request(&wanpipe_endpoint_interface, pool))) {
                struct private_object *tech_pvt;
                switch_channel *channel;
 
index a605c2286d70bb9218966123ea32f510c87670bb..bf26a21c2c9d42a890dace37de17b53e6294e6cf 100644 (file)
@@ -169,7 +169,7 @@ static switch_status woomerachan_on_ring(switch_core_session *session);
 static switch_status woomerachan_on_loopback(switch_core_session *session);
 static switch_status woomerachan_on_transmit(switch_core_session *session);
 static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                                 switch_core_session **new_session);
+                                                                                                 switch_core_session **new_session, switch_memory_pool *pool);
 static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
                                                                                        switch_io_flag flags, int stream_id);
 static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
@@ -466,9 +466,9 @@ static const switch_loadable_module_interface woomerachan_module_interface = {
    that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
 */
 static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
-                                                                                                 switch_core_session **new_session)
+                                                                                                 switch_core_session **new_session, switch_memory_pool *pool)
 {
-       if ((*new_session = switch_core_session_request(&woomerachan_endpoint_interface, NULL)) != 0) {
+       if ((*new_session = switch_core_session_request(&woomerachan_endpoint_interface, pool)) != 0) {
                struct private_object *tech_pvt;
                switch_channel *channel;
 
index 1e9ce2fc23c75bbd300934746f8bfb397339fb61..cab5289f787e03198ae898185e71eac1be1fae43 100644 (file)
@@ -106,7 +106,6 @@ struct js_session {
        switch_core_session *session;
        JSContext *cx;
        JSObject *obj;
-       switch_memory_pool *pool;
        unsigned int flags;
 };
 
@@ -922,16 +921,13 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
                }
 
                caller_profile = switch_caller_profile_new(pool, dialplan, cid_name, cid_num, network_addr, ani, ani2, dest);
-               if (switch_core_session_outgoing_channel(session, channel_type, caller_profile, &peer_session) == SWITCH_STATUS_SUCCESS) {
+               if (switch_core_session_outgoing_channel(session, channel_type, caller_profile, &peer_session, &pool) == SWITCH_STATUS_SUCCESS) {
                        jss = switch_core_session_alloc(peer_session, sizeof(*jss));
                        jss->session = peer_session;
                        jss->flags = 0;
                        jss->cx = cx;
                        jss->obj = obj;
                        JS_SetPrivate(cx, obj, jss);
-                       if (need_pool) {
-                               jss->pool = pool;
-                       }
                        switch_core_session_thread_launch(peer_session);
                        switch_set_flag(jss, S_HUP);
                        
@@ -943,7 +939,7 @@ static JSBool session_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
                switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Missing Args\n");
        }
 
-       if (need_pool) {
+       if (pool) {
                switch_core_destroy_memory_pool(&pool);
        }
        return JS_FALSE;
@@ -955,10 +951,6 @@ static void session_destroy(JSContext *cx, JSObject *obj)
        
        if (cx && obj) {
                if ((jss = JS_GetPrivate(cx, obj))) {
-                       if (jss->pool) {
-                               switch_core_destroy_memory_pool(&jss->pool);
-                       }
-       
                        if (switch_test_flag(jss, S_HUP)) {
                                switch_channel *channel;
 
index 7a15a8dc7e64c842c83ad0be0648f6e75848527b..9ded65f2f1efdd4433d3cc18707fde8ce8b41538 100644 (file)
@@ -779,7 +779,8 @@ SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session *se
 SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session,
                                                                                                                                   char *endpoint_name,
                                                                                                                                   switch_caller_profile *caller_profile,
-                                                                                                                                  switch_core_session **new_session)
+                                                                                                                                  switch_core_session **new_session,
+                                                                                                                                  switch_memory_pool **pool)
 {
        struct switch_io_event_hook_outgoing_channel *ptr;
        switch_status status = SWITCH_STATUS_FALSE;
@@ -793,7 +794,9 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s
        if (endpoint_interface->io_routines->outgoing_channel) {
                if ((status =
                         endpoint_interface->io_routines->outgoing_channel(session, caller_profile,
-                                                                                                                          new_session)) == SWITCH_STATUS_SUCCESS) {
+                                                                                                                          new_session, *pool)) == SWITCH_STATUS_SUCCESS) {
+                       /* session has adopted this pool we cant touch it now */
+                       *pool = NULL;
                        if (session) {
                                for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
                                        if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) {