spring cleaning 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4796 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-03-29 22:34:40 +00:00
parent 3a54126261
commit e6a60a20bc
25 changed files with 9878 additions and 0 deletions
+149
View File
@@ -0,0 +1,149 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* switch_core.h -- Core Library Private Data (not to be installed into the system)
* If the last line didn't make sense, stop reading this file, go away!,
* this file does not exist!!!!
*
*/
#ifndef WIN32
#include <switch_private.h>
#endif
/* for apr_pool_create and apr_pool_destroy */
/* functions only used in this file so not exposed */
#include <apr_pools.h>
/* for apr_hash_make, apr_hash_pool_get, apr_hash_set */
/* functions only used in this file so not exposed */
#include <apr_hash.h>
/* for apr_pvsprintf */
/* function only used in this file so not exposed */
#include <apr_strings.h>
/* for apr_initialize and apr_terminate */
/* function only used in this file so not exposed */
#include <apr_general.h>
#include <apr_portable.h>
typedef apr_os_thread_t switch_thread_id_t;
#define switch_thread_self apr_os_thread_current
#ifdef HAVE_MLOCKALL
#include <sys/mman.h>
#endif
/* #define DEBUG_ALLOC */
#define DO_EVENTS
#ifdef CRASH_PROT
#define __CP "ENABLED"
#else
#define __CP "DISABLED"
#endif
#define SWITCH_EVENT_QUEUE_LEN 256
#define SWITCH_MESSAGE_QUEUE_LEN 256
#define SWITCH_SQL_QUEUE_LEN 2000
#define SWITCH_BUFFER_BLOCK_FRAMES 25
#define SWITCH_BUFFER_START_FRAMES 50
typedef enum {
SSF_NONE = 0,
SSF_DESTROYED = (1 << 0)
} switch_session_flag_t;
struct switch_core_session {
uint32_t id;
char name[80];
switch_session_flag_t flags;
int thread_running;
switch_memory_pool_t *pool;
switch_channel_t *channel;
switch_thread_t *thread;
const switch_endpoint_interface_t *endpoint_interface;
switch_io_event_hooks_t event_hooks;
switch_codec_t *read_codec;
switch_codec_t *write_codec;
switch_buffer_t *raw_write_buffer;
switch_frame_t raw_write_frame;
switch_frame_t enc_write_frame;
uint8_t raw_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
uint8_t enc_write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_buffer_t *raw_read_buffer;
switch_frame_t raw_read_frame;
switch_frame_t enc_read_frame;
uint8_t raw_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
uint8_t enc_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_audio_resampler_t *read_resampler;
switch_audio_resampler_t *write_resampler;
switch_mutex_t *mutex;
switch_thread_cond_t *cond;
switch_thread_rwlock_t *rwlock;
void *streams[SWITCH_MAX_STREAMS];
int stream_count;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
void *private_info;
switch_queue_t *event_queue;
switch_queue_t *message_queue;
switch_queue_t *private_event_queue;
switch_thread_rwlock_t *bug_rwlock;
switch_media_bug_t *bugs;
};
struct switch_media_bug {
switch_buffer_t *raw_write_buffer;
switch_buffer_t *raw_read_buffer;
switch_frame_t *replace_frame_in;
switch_frame_t *replace_frame_out;
switch_media_bug_callback_t callback;
switch_mutex_t *read_mutex;
switch_mutex_t *write_mutex;
switch_core_session_t *session;
void *user_data;
uint32_t flags;
uint8_t ready;
struct switch_media_bug *next;
};
SWITCH_DECLARE(void) switch_core_sqldb_start(switch_memory_pool_t *pool);
SWITCH_DECLARE(void) switch_core_sqldb_stop(void);
SWITCH_DECLARE(void) switch_core_session_init(switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_memory_pool_t *) switch_core_memory_init(void);
+281
View File
@@ -0,0 +1,281 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
* switch_core_event_hook.h Core Event Hooks
*
*/
#ifndef SWITCH_EVENT_HOOKS_H
#define SWITCH_EVENT_HOOKS_H
#include <switch.h>
SWITCH_BEGIN_EXTERN_C typedef struct switch_io_event_hooks switch_io_event_hooks_t;
typedef struct switch_io_event_hook_outgoing_channel switch_io_event_hook_outgoing_channel_t;
typedef struct switch_io_event_hook_answer_channel switch_io_event_hook_answer_channel_t;
typedef struct switch_io_event_hook_receive_message switch_io_event_hook_receive_message_t;
typedef struct switch_io_event_hook_receive_event switch_io_event_hook_receive_event_t;
typedef struct switch_io_event_hook_read_frame switch_io_event_hook_read_frame_t;
typedef struct switch_io_event_hook_write_frame switch_io_event_hook_write_frame_t;
typedef struct switch_io_event_hook_kill_channel switch_io_event_hook_kill_channel_t;
typedef struct switch_io_event_hook_waitfor_read switch_io_event_hook_waitfor_read_t;
typedef struct switch_io_event_hook_waitfor_write switch_io_event_hook_waitfor_write_t;
typedef struct switch_io_event_hook_send_dtmf switch_io_event_hook_send_dtmf_t;
typedef struct switch_io_event_hook_state_change switch_io_event_hook_state_change_t;
typedef switch_status_t (*switch_outgoing_channel_hook_t) (switch_core_session_t *, switch_caller_profile_t *,
switch_core_session_t *);
typedef switch_status_t (*switch_answer_channel_hook_t) (switch_core_session_t *);
typedef switch_status_t (*switch_receive_message_hook_t) (switch_core_session_t *, switch_core_session_message_t *);
typedef switch_status_t (*switch_receive_event_hook_t) (switch_core_session_t *, switch_event_t *);
typedef switch_status_t (*switch_read_frame_hook_t) (switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t,
int);
typedef switch_status_t (*switch_write_frame_hook_t) (switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t,
int);
typedef switch_status_t (*switch_kill_channel_hook_t) (switch_core_session_t *, int);
typedef switch_status_t (*switch_waitfor_read_hook_t) (switch_core_session_t *, int, int);
typedef switch_status_t (*switch_waitfor_write_hook_t) (switch_core_session_t *, int, int);
typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, char *);
typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *);
/*! \brief Node in which to store custom outgoing channel callback hooks */
struct switch_io_event_hook_outgoing_channel {
/*! the outgoing channel callback hook */
switch_outgoing_channel_hook_t outgoing_channel;
struct switch_io_event_hook_outgoing_channel *next;
};
/*! \brief Node in which to store custom answer channel callback hooks */
struct switch_io_event_hook_answer_channel {
/*! the answer channel callback hook */
switch_answer_channel_hook_t answer_channel;
struct switch_io_event_hook_answer_channel *next;
};
/*! \brief Node in which to store custom receive message callback hooks */
struct switch_io_event_hook_receive_message {
/*! the answer channel callback hook */
switch_receive_message_hook_t receive_message;
struct switch_io_event_hook_receive_message *next;
};
/*! \brief Node in which to store custom receive message callback hooks */
struct switch_io_event_hook_receive_event {
/*! the answer channel callback hook */
switch_receive_event_hook_t receive_event;
struct switch_io_event_hook_receive_event *next;
};
/*! \brief Node in which to store custom read frame channel callback hooks */
struct switch_io_event_hook_read_frame {
/*! the read frame channel callback hook */
switch_read_frame_hook_t read_frame;
struct switch_io_event_hook_read_frame *next;
};
/*! \brief Node in which to store custom write_frame channel callback hooks */
struct switch_io_event_hook_write_frame {
/*! the write_frame channel callback hook */
switch_write_frame_hook_t write_frame;
struct switch_io_event_hook_write_frame *next;
};
/*! \brief Node in which to store custom kill channel callback hooks */
struct switch_io_event_hook_kill_channel {
/*! the kill channel callback hook */
switch_kill_channel_hook_t kill_channel;
struct switch_io_event_hook_kill_channel *next;
};
/*! \brief Node in which to store custom waitfor read channel callback hooks */
struct switch_io_event_hook_waitfor_read {
/*! the waitfor read channel callback hook */
switch_waitfor_read_hook_t waitfor_read;
struct switch_io_event_hook_waitfor_read *next;
};
/*! \brief Node in which to store custom waitfor write channel callback hooks */
struct switch_io_event_hook_waitfor_write {
/*! the waitfor write channel callback hook */
switch_waitfor_write_hook_t waitfor_write;
struct switch_io_event_hook_waitfor_write *next;
};
/*! \brief Node in which to store custom send dtmf channel callback hooks */
struct switch_io_event_hook_send_dtmf {
/*! the send dtmf channel callback hook */
switch_send_dtmf_hook_t send_dtmf;
struct switch_io_event_hook_send_dtmf *next;
};
/*! \brief Node in which to store state change callback hooks */
struct switch_io_event_hook_state_change {
/*! the send dtmf channel callback hook */
switch_state_change_hook_t state_change;
struct switch_io_event_hook_state_change *next;
};
/*! \brief A table of lists of io_event_hooks to store the event hooks associated with a session */
struct switch_io_event_hooks {
/*! a list of outgoing channel hooks */
switch_io_event_hook_outgoing_channel_t *outgoing_channel;
/*! a list of answer channel hooks */
switch_io_event_hook_answer_channel_t *answer_channel;
/*! a list of receive message hooks */
switch_io_event_hook_receive_message_t *receive_message;
/*! a list of queue message hooks */
switch_io_event_hook_receive_event_t *receive_event;
/*! a list of read frame hooks */
switch_io_event_hook_read_frame_t *read_frame;
/*! a list of write frame hooks */
switch_io_event_hook_write_frame_t *write_frame;
/*! a list of kill channel hooks */
switch_io_event_hook_kill_channel_t *kill_channel;
/*! a list of wait for read hooks */
switch_io_event_hook_waitfor_read_t *waitfor_read;
/*! a list of wait for write hooks */
switch_io_event_hook_waitfor_write_t *waitfor_write;
/*! a list of send dtmf hooks */
switch_io_event_hook_send_dtmf_t *send_dtmf;
/*! a list of state change hooks */
switch_io_event_hook_state_change_t *state_change;
};
extern switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_session_t *session);
///\defgroup shooks Session Hook Callbacks
///\ingroup core1
///\{
/*!
\brief Add an event hook to be executed when a session requests an outgoing extension
\param session session to bind hook to
\param outgoing_channel hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_outgoing_channel(switch_core_session_t *session,
switch_outgoing_channel_hook_t
outgoing_channel);
/*!
\brief Add an event hook to be executed when a session answers a channel
\param session session to bind hook to
\param answer_channel hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_answer_channel(switch_core_session_t *session,
switch_answer_channel_hook_t answer_channel);
/*!
\brief Add an event hook to be executed when a session sends a message
\param session session to bind hook to
\param receive_message hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_receive_message(switch_core_session_t *session,
switch_receive_message_hook_t
receive_message);
/*!
\brief Add an event hook to be executed when a session reads a frame
\param session session to bind hook to
\param read_frame hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_read_frame(switch_core_session_t *session,
switch_read_frame_hook_t read_frame);
/*!
\brief Add an event hook to be executed when a session writes a frame
\param session session to bind hook to
\param write_frame hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_write_frame(switch_core_session_t *session,
switch_write_frame_hook_t write_frame);
/*!
\brief Add an event hook to be executed when a session kills a channel
\param session session to bind hook to
\param kill_channel hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_kill_channel(switch_core_session_t *session,
switch_kill_channel_hook_t kill_channel);
/*!
\brief Add an event hook to be executed when a session waits for a read event
\param session session to bind hook to
\param waitfor_read hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_read(switch_core_session_t *session,
switch_waitfor_read_hook_t waitfor_read);
/*!
\brief Add an event hook to be executed when a session waits for a write event
\param session session to bind hook to
\param waitfor_write hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_waitfor_write(switch_core_session_t *session,
switch_waitfor_write_hook_t waitfor_write);
/*!
\brief Add an event hook to be executed when a session sends dtmf
\param session session to bind hook to
\param send_dtmf hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_send_dtmf(switch_core_session_t *session,
switch_send_dtmf_hook_t send_dtmf);
/*!
\brief Add an event hook to be executed when a session receives a state change signal
\param session session to bind hook to
\param state_change hook to bind
\return SWITCH_STATUS_SUCCESS on suceess
*/
SWITCH_DECLARE(switch_status_t) switch_core_event_hook_add_state_change(switch_core_session_t *session,
switch_answer_channel_hook_t state_change);
///\}
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/
+107
View File
@@ -0,0 +1,107 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthmct@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
*
*
* switch_scheduler.h -- Scheduler Engine
*
*/
#ifndef SWITCH_SCHEDULER_H
#define SWITCH_SCHEDULER_H
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
///\defgroup sched1 Scheduler
///\ingroup core1
///\{
struct switch_scheduler_task {
time_t created;
time_t runtime;
uint32_t cmd_id;
char *group;
void *cmd_arg;
uint32_t task_id;
};
/*!
\brief Schedule a task in the future
\param runtime the time in epoch seconds to execute the task.
\param func the callback function to execute when the task is executed.
\param desc an arbitrary description of the task.
\param group a group id tag to link multiple tasks to a single entity.
\param cmd_id an arbitrary index number be used in the callback.
\param cmd_arg user data to be passed to the callback.
\param flags flags to alter behaviour
\return the id of the task
*/
SWITCH_DECLARE(uint32_t) switch_scheduler_add_task(time_t task_runtime,
switch_scheduler_func_t func,
char *desc,
char *group,
uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags);
/*!
\brief Delete a scheduled task
\param task_id the id of the task
\return SWITCH_STATUS_SUCCESS if the task was deleted.
*/
SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_id(uint32_t task_id);
/*!
\brief Delete a scheduled task based on the group name
\param group the group name
\return SWITCH_STATUS_SUCCESS if any tasks were deleted
*/
SWITCH_DECLARE(switch_status_t) switch_scheduler_del_task_group(char *group);
/*!
\brief Start the scheduler system
*/
SWITCH_DECLARE(void) switch_scheduler_task_thread_start(void);
/*!
\brief Stop the scheduler system
*/
SWITCH_DECLARE(void) switch_scheduler_task_thread_stop(void);
///\}
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/