add more modules to new mod loader macros/api.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5404 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-06-20 07:53:33 +00:00
parent 008777e95e
commit ae02cbef83
10 changed files with 55 additions and 214 deletions

View File

@ -267,7 +267,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
#define SWITCH_ADD_API(api_int, int_name, descript, funcptr, syntax_string) \
for (;;) { \
api_int = switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE); \
api_int = (switch_api_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_API_INTERFACE); \
api_int->interface_name = int_name; \
api_int->desc = descript; \
api_int->function = funcptr; \
@ -277,7 +277,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
#define SWITCH_ADD_CHAT(chat_int, int_name, funcptr) \
for (;;) { \
chat_int = switch_loadable_module_create_interface(*module_interface, SWITCH_CHAT_INTERFACE); \
chat_int = (switch_chat_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_CHAT_INTERFACE); \
chat_int->chat_send = funcptr; \
chat_int->interface_name = int_name; \
break; \
@ -285,7 +285,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
#define SWITCH_ADD_APP(app_int, int_name, short_descript, long_descript, funcptr, syntax_string, app_flags) \
for (;;) { \
app_int = switch_loadable_module_create_interface(*module_interface, SWITCH_APPLICATION_INTERFACE); \
app_int = (switch_application_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_APPLICATION_INTERFACE); \
app_int->interface_name = int_name; \
app_int->application_function = funcptr; \
app_int->short_desc = short_descript; \
@ -297,7 +297,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
#define SWITCH_ADD_DIALPLAN(dp_int, int_name, funcptr) \
for (;;) { \
dp_int = switch_loadable_module_create_interface(*module_interface, SWITCH_DIALPLAN_INTERFACE); \
dp_int = (switch_dialplan_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_DIALPLAN_INTERFACE); \
dp_int->hunt_function = funcptr; \
dp_int->interface_name = int_name; \
break; \

View File

@ -68,56 +68,6 @@ static const switch_state_handler_table_t state_handlers = {
/*.on_transmit */ NULL
};
static switch_api_interface_t modcdr_show_available_api = {
/*.interface_name */ "modcdr_show_available",
/*.desc */ "Displays the currently compiled-in mod_cdr backend loggers.",
/*.function */ modcdr_show_available,
/*.syntax */ "modcdr_queue_show_available",
/*.next */ 0
};
static switch_api_interface_t modcdr_show_active_api = {
/*.interface_name */ "modcdr_show_active",
/*.desc */ "Displays the currently active mod_cdr backend loggers.",
/*.function */ modcdr_show_active,
/*.syntax */ "modcdr_queue_show_active",
/*.next */ &modcdr_show_available_api
};
static switch_api_interface_t modcdr_queue_resume_api = {
/*.interface_name */ "modcdr_queue_resume",
/*.desc */ "Manually resumes the popping of objects from the queue.",
/*.function */ modcdr_queue_resume,
/*.syntax */ "modcdr_queue_resume",
/*.next */ &modcdr_show_active_api
};
static switch_api_interface_t modcdr_queue_pause_api = {
/*.interface_name */ "modcdr_queue_pause",
/*.desc */ "Manually pauses the popping of objects from the queue. (DANGER: Can suck your memory away rather quickly.)",
/*.function */ modcdr_queue_pause,
/*.syntax */ "modcdr_queue_pause",
/*.next */ &modcdr_queue_resume_api
};
static switch_api_interface_t modcdr_reload_interface_api = {
/*.interface_name */ "modcdr_reload",
/*.desc */ "Reload mod_cdr's configuration",
/*.function */ modcdr_reload,
/*.syntax */ "modcdr_reload",
/*.next */ &modcdr_queue_pause_api
};
static switch_loadable_module_interface_t cdr_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/* api_interface */ &modcdr_reload_interface_api
};
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_thread_rwlock_rdlock(cdr_rwlock);
@ -126,18 +76,25 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
return SWITCH_STATUS_SUCCESS;
}
#define AVAIL_DESCR "Displays the currently compiled-in mod_cdr backend loggers."
#define ACTIVE_DESCR "Displays the currently active mod_cdr backend loggers."
#define RESUME_DESCR "Manually resumes the popping of objects from the queue."
#define PAUSE_DESCR "Manually pauses the popping of objects from the queue. (DANGER: Can suck your memory away rather quickly.)"
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_load)
{
switch_api_interface_t *api_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &cdr_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "modcdr_reload", "Reload mod_cdr's configuration", modcdr_reload, "");
SWITCH_ADD_API(api_interface, "modcdr_queue_pause", PAUSE_DESCR, modcdr_queue_pause, "");
SWITCH_ADD_API(api_interface, "modcdr_queue_resume", RESUME_DESCR, modcdr_queue_resume, "");
SWITCH_ADD_API(api_interface, "modcdr_show_active", ACTIVE_DESCR, modcdr_show_active, "");
SWITCH_ADD_API(api_interface, "modcdr_show_available", AVAIL_DESCR, modcdr_show_available, "");
switch_core_add_state_handler(&state_handlers);
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH - Can't swim, no pool\n");
return SWITCH_STATUS_TERM;
}
module_pool = pool;
switch_thread_rwlock_create(&cdr_rwlock,module_pool);
newcdrcontainer = new CDRContainer(module_pool); // Instantiates the new object, automatically loads config

View File

@ -176,25 +176,12 @@ static void event_handler(switch_event_t *event)
}
static switch_loadable_module_interface_t event_test_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
};
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
{
memset(&globals, 0, sizeof(globals));
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
module_pool = pool;
switch_core_hash_init(&globals.event_hash, module_pool);
@ -231,10 +218,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
return SWITCH_STATUS_TERM;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &event_test_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {

View File

@ -161,7 +161,7 @@ static void event_handler(switch_event_t *event)
switch_mutex_unlock(listen_list.mutex);
}
static void socket_function(switch_core_session_t *session, char *data)
SWITCH_STANDARD_APP(socket_function)
{
char *host, *port_name;
switch_socket_t *new_sock;
@ -251,28 +251,6 @@ static void socket_function(switch_core_session_t *session, char *data)
}
static switch_application_interface_t socket_application_interface = {
/*.interface_name */ "socket",
/*.application_function */ socket_function,
/* long_desc */ "Connect to a socket",
/* short_desc */ "Connect to a socket",
/* syntax */ "<ip>[:<port>]",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ NULL
};
static switch_loadable_module_interface_t event_socket_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ &socket_application_interface
};
static void close_socket(switch_socket_t ** sock)
{
switch_mutex_lock(listen_list.sock_mutex);
@ -303,11 +281,13 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_socket_shutdown)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_event_socket_load)
{
switch_application_interface_t *app_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &event_socket_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "socket", "Connect to a socket", "Connect to a socket", socket_function, "<ip>[:<port>]", SAF_SUPPORT_NOMEDIA);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;

View File

@ -71,20 +71,8 @@ static void event_handler(switch_event_t *event)
}
}
static switch_loadable_module_interface_t event_test_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
};
#define MY_EVENT_COOL "test::cool"
#ifdef TORTURE_ME
#define TTHREADS 500
static int THREADS = 0;
@ -128,14 +116,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
SWITCH_MODULE_LOAD_FUNCTION(mod_event_test_load)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &event_test_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if (switch_event_reserve_subclass(MY_EVENT_COOL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_event_bind(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}

View File

@ -391,19 +391,10 @@ static void xmpp_connect(char *jabber_id, char *pass)
}
static switch_loadable_module_interface_t xmpp_event_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
};
SWITCH_MODULE_LOAD_FUNCTION(mod_xmpp_event_load)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xmpp_event_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;

View File

@ -237,16 +237,6 @@ static switch_status_t load_config(void)
}
static switch_loadable_module_interface_t zeroconf_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
};
#define MY_EVENT_PUBLISH "zeroconf::broadcast"
#define MY_EVENT_UNPUBLISH "zeroconf::unbroadcast"
@ -266,10 +256,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_zeroconf_load)
memset(&globals, 0, sizeof(globals));
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
module_pool = pool;
switch_mutex_init(&globals.zc_lock, SWITCH_MUTEX_NESTED, module_pool);
@ -293,7 +280,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_zeroconf_load)
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &zeroconf_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;

View File

@ -138,34 +138,10 @@ static switch_status_t native_file_file_get_string(switch_file_handle_t *handle,
static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
static switch_file_interface_t native_file_file_interface = {
/*.interface_name */ modname,
/*.file_open */ native_file_file_open,
/*.file_close */ native_file_file_close,
/*.file_read */ native_file_file_read,
/*.file_write */ native_file_file_write,
/*.file_seek */ native_file_file_seek,
/*.file_set_string */ native_file_file_set_string,
/*.file_get_string */ native_file_file_get_string,
/*.extens */ NULL,
/*.next */ NULL,
};
static switch_loadable_module_interface_t native_file_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ &native_file_file_interface
};
SWITCH_MODULE_LOAD_FUNCTION(mod_native_file_load)
{
switch_file_interface_t *file_interface;
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
uint32_t num_codecs = switch_loadable_module_get_codecs(NULL, codecs, sizeof(codecs) / sizeof(codecs[0]));
@ -175,9 +151,17 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_native_file_load)
supported_formats[x] = codecs[x]->iananame;
}
/* connect my internal structure to the blank pointer passed to me */
native_file_file_interface.extens = supported_formats;
*module_interface = &native_file_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
file_interface->interface_name = modname;
file_interface->extens = supported_formats;
file_interface->file_open = native_file_file_open;
file_interface->file_close = native_file_file_close;
file_interface->file_read = native_file_file_read;
file_interface->file_write = native_file_file_write;
file_interface->file_seek = native_file_file_seek;
file_interface->file_set_string = native_file_file_set_string;
file_interface->file_get_string = native_file_file_get_string;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;

View File

@ -253,30 +253,6 @@ static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, swi
static char **supported_formats;
static switch_file_interface_t sndfile_file_interface = {
/*.interface_name */ modname,
/*.file_open */ sndfile_file_open,
/*.file_close */ sndfile_file_close,
/*.file_read */ sndfile_file_read,
/*.file_write */ sndfile_file_write,
/*.file_seek */ sndfile_file_seek,
/*.file_set_string */ sndfile_file_set_string,
/*.file_get_string */ sndfile_file_get_string,
/*.extens */ NULL,
/*.next */ NULL,
};
static switch_loadable_module_interface_t sndfile_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ &sndfile_file_interface
};
static switch_status_t setup_formats(void)
{
SF_FORMAT_INFO info;
@ -364,6 +340,7 @@ static switch_status_t setup_formats(void)
SWITCH_MODULE_LOAD_FUNCTION(mod_sndfile_load)
{
switch_file_interface_t *file_interface;
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
@ -377,8 +354,17 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sndfile_load)
}
/* connect my internal structure to the blank pointer passed to me */
sndfile_file_interface.extens = supported_formats;
*module_interface = &sndfile_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
file_interface->interface_name = modname;
file_interface->extens = supported_formats;
file_interface->file_open = sndfile_file_open;
file_interface->file_close = sndfile_file_close;
file_interface->file_read = sndfile_file_read;
file_interface->file_write = sndfile_file_write;
file_interface->file_seek = sndfile_file_seek;
file_interface->file_set_string = sndfile_file_set_string;
file_interface->file_get_string = sndfile_file_get_string;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;

View File

@ -56,19 +56,6 @@ static const char *COLORS[] = { SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRE
};
#endif
static switch_loadable_module_interface_t console_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
static switch_memory_pool_t *module_pool = NULL;
static switch_hash_t *log_hash = NULL;
static switch_hash_t *name_hash = NULL;
@ -192,14 +179,10 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
SWITCH_MODULE_LOAD_FUNCTION(mod_console_load)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
module_pool = pool;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &console_module_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
/* setup my logger function */
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);