From 40824bc41a95ffef6062da7e7624e506d99dbd48 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Dec 2005 19:53:29 +0000 Subject: [PATCH] add event system git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@128 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- Makefile.am | 6 +++-- Makefile.in | 17 +++++++++--- modules.conf | 1 + src/include/config.h.in | 53 +------------------------------------- src/include/switch.h | 2 +- src/include/switch_core.h | 1 + src/include/switch_types.h | 15 +++++++++++ src/switch.c | 1 + src/switch_core.c | 17 +++++++++++- 9 files changed, 54 insertions(+), 59 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4bf53d80dd..d6ea4b4f8e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,8 @@ src/switch_console.c \ src/switch_core.c \ src/switch_loadable_module.c \ src/switch_mutex.c \ -src/switch_utils.c +src/switch_utils.c \ +src/switch_event.c #bindir = $(PREFIX)/bin #libdir = $(PREFIX)/lib @@ -62,7 +63,8 @@ library_include_HEADERS = src/include/switch.h \ src/include/switch_types.h \ src/include/switch_utils.h \ src/include/switch_caller.h \ - src/include/switch_buffer.h + src/include/switch_buffer.h \ + src/include/switch_event.h lib_LTLIBRARIES = libfreeswitch.la libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g diff --git a/Makefile.in b/Makefile.in index 1067f7f59d..6931eabf49 100644 --- a/Makefile.in +++ b/Makefile.in @@ -75,7 +75,8 @@ am_libfreeswitch_la_OBJECTS = libfreeswitch_la-switch_buffer.lo \ libfreeswitch_la-switch_core.lo \ libfreeswitch_la-switch_loadable_module.lo \ libfreeswitch_la-switch_mutex.lo \ - libfreeswitch_la-switch_utils.lo + libfreeswitch_la-switch_utils.lo \ + libfreeswitch_la-switch_event.lo libfreeswitch_la_OBJECTS = $(am_libfreeswitch_la_OBJECTS) binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) @@ -252,7 +253,8 @@ src/switch_console.c \ src/switch_core.c \ src/switch_loadable_module.c \ src/switch_mutex.c \ -src/switch_utils.c +src/switch_utils.c \ +src/switch_event.c #bindir = $(PREFIX)/bin @@ -270,7 +272,8 @@ library_include_HEADERS = src/include/switch.h \ src/include/switch_types.h \ src/include/switch_utils.h \ src/include/switch_caller.h \ - src/include/switch_buffer.h + src/include/switch_buffer.h \ + src/include/switch_event.h lib_LTLIBRARIES = libfreeswitch.la libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g @@ -406,6 +409,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_config.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_console.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_core.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_event.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_loadable_module.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_mutex.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfreeswitch_la-switch_utils.Plo@am__quote@ @@ -494,6 +498,13 @@ libfreeswitch_la-switch_utils.lo: src/switch_utils.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_utils.lo `test -f 'src/switch_utils.c' || echo '$(srcdir)/'`src/switch_utils.c +libfreeswitch_la-switch_event.lo: src/switch_event.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -MT libfreeswitch_la-switch_event.lo -MD -MP -MF "$(DEPDIR)/libfreeswitch_la-switch_event.Tpo" -c -o libfreeswitch_la-switch_event.lo `test -f 'src/switch_event.c' || echo '$(srcdir)/'`src/switch_event.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libfreeswitch_la-switch_event.Tpo" "$(DEPDIR)/libfreeswitch_la-switch_event.Plo"; else rm -f "$(DEPDIR)/libfreeswitch_la-switch_event.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/switch_event.c' object='libfreeswitch_la-switch_event.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfreeswitch_la_CFLAGS) $(CFLAGS) -c -o libfreeswitch_la-switch_event.lo `test -f 'src/switch_event.c' || echo '$(srcdir)/'`src/switch_event.c + freeswitch-switch.o: src/switch.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(freeswitch_CFLAGS) $(CFLAGS) -MT freeswitch-switch.o -MD -MP -MF "$(DEPDIR)/freeswitch-switch.Tpo" -c -o freeswitch-switch.o `test -f 'src/switch.c' || echo '$(srcdir)/'`src/switch.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/freeswitch-switch.Tpo" "$(DEPDIR)/freeswitch-switch.Po"; else rm -f "$(DEPDIR)/freeswitch-switch.Tpo"; exit 1; fi diff --git a/modules.conf b/modules.conf index 7c00f2874b..1a10c37ecf 100644 --- a/modules.conf +++ b/modules.conf @@ -12,3 +12,4 @@ mod_rawaudio mod_iaxchan #mod_opalchan mod_codec_g729 +mod_event_test diff --git a/src/include/config.h.in b/src/include/config.h.in index 75786f81fb..5f449b963e 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -1,7 +1,4 @@ -/* config.h.in. Generated from configure.in by autoheader. */ - -/* Define to 1 if you have the header file. */ -#undef HAVE_ARPA_INET_H +/* src/include/config.h.in. Generated from configure.in by autoheader. */ /* Define to 1 if you have the header file, and it defines `DIR'. */ @@ -10,61 +7,28 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H -/* Define to 1 if you have the header file. */ -#undef HAVE_FCNTL_H - /* Define to 1 if you have the `gethostname' function. */ #undef HAVE_GETHOSTNAME -/* Define to 1 if you have the `gettimeofday' function. */ -#undef HAVE_GETTIMEOFDAY - /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the `localtime_r' function. */ -#undef HAVE_LOCALTIME_R - /* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */ #undef HAVE_MALLOC -/* Define to 1 if you have the `memmove' function. */ -#undef HAVE_MEMMOVE - /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H -/* Define to 1 if you have the `memset' function. */ -#undef HAVE_MEMSET - /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_NDIR_H -/* Define to 1 if you have the header file. */ -#undef HAVE_NETDB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IN_H - -/* Define to 1 if you have the `socket' function. */ -#undef HAVE_SOCKET - /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H -/* Define to 1 if you have the `strcasecmp' function. */ -#undef HAVE_STRCASECMP - -/* Define to 1 if you have the `strchr' function. */ -#undef HAVE_STRCHR - -/* Define to 1 if you have the `strdup' function. */ -#undef HAVE_STRDUP - /* Define to 1 if you have the `strftime' function. */ #undef HAVE_STRFTIME @@ -74,32 +38,17 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H -/* Define to 1 if you have the `strncasecmp' function. */ -#undef HAVE_STRNCASECMP - -/* Define to 1 if you have the `strstr' function. */ -#undef HAVE_STRSTR - /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_SYS_DIR_H -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_IOCTL_H - /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_SYS_NDIR_H -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SOCKET_H - /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TIME_H - /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H diff --git a/src/include/switch.h b/src/include/switch.h index acb0d6a5a6..217ef666f3 100644 --- a/src/include/switch.h +++ b/src/include/switch.h @@ -116,7 +116,7 @@ extern "C" { #include #include #include - +#include #ifdef __cplusplus } diff --git a/src/include/switch_core.h b/src/include/switch_core.h index eacb3c330e..4146cfc4c0 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -119,6 +119,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_read_codec(switch_core_ses SWITCH_DECLARE(switch_status) switch_core_session_set_write_codec(switch_core_session *session, switch_codec *codec); SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_session *session); SWITCH_DECLARE(void) pbx_core_session_signal_state_change(switch_core_session *session); +SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup); #ifdef __cplusplus } diff --git a/src/include/switch_types.h b/src/include/switch_types.h index eff3592fc2..211cb9b7ab 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -122,6 +122,21 @@ typedef enum { SWITCH_IO_FLAG_NOOP = 0, } switch_io_flag; +/* make sure this is synced with the EVENT_NAMES array in switch_event.c + also never put any new ones before EVENT_ALL +*/ +typedef enum { + SWITCH_EVENT_CUSTOM, + SWITCH_EVENT_INBOUND_CHAN, + SWITCH_EVENT_OUTBOUND_CHAN, + SWITCH_EVENT_ANSWER_CHAN, + SWITCH_EVENT_HANGUP_CHAN, + SWITCH_EVENT_STARTUP, + SWITCH_EVENT_ALL +} switch_event_t; + +typedef struct switch_event_node switch_event_node; +typedef void (*switch_event_callback_t)(switch_event_t, int, char *); typedef struct switch_loadable_module switch_loadable_module; typedef struct switch_frame switch_frame; typedef struct switch_channel switch_channel; diff --git a/src/switch.c b/src/switch.c index 7eae62fc3c..b3b3841455 100644 --- a/src/switch.c +++ b/src/switch.c @@ -51,6 +51,7 @@ int main(int argc, char *argv[]) { exit(-1); } + switch_event_fire(SWITCH_EVENT_STARTUP, "Ready"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_GLOBAL_VERSION); /* wait for console input */ diff --git a/src/switch_core.c b/src/switch_core.c index 0a62a795c9..dcfc7bf2f8 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -422,6 +422,20 @@ SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session *session, return duped; } + +SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup) +{ + char *duped = NULL; + + assert(pool != NULL); + assert(todup != NULL); + + if (todup && (duped = apr_palloc(pool, strlen(todup)+1))) { + strcpy(duped, todup); + } + return duped; +} + SWITCH_DECLARE(void *) switch_core_session_get_private(switch_core_session *session) { assert(session != NULL); @@ -1500,7 +1514,8 @@ SWITCH_DECLARE(switch_status) switch_core_init(void) return SWITCH_STATUS_MEMERR; } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Allocated memory pool.\n"); - + switch_event_init(runtime.memory_pool); + #ifdef EMBED_PERL if (! (my_perl = perl_alloc())) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate perl intrepreter\n");