diff --git a/src/include/switch.h b/src/include/switch.h index 96f36a15b7..67a04db7ec 100644 --- a/src/include/switch.h +++ b/src/include/switch.h @@ -35,9 +35,15 @@ #ifndef SWITCH_H #define SWITCH_H -#ifdef __cplusplus -extern "C" { -#endif +#ifdef __cplusplus +#define BEGIN_EXTERN_C extern "C" { +#define END_EXTERN_C } +#else +#define BEGIN_EXTERN_C +#define END_EXTERN_C +#endif + +BEGIN_EXTERN_C //Need to include this before any other includes (MSVC Bug) #include @@ -69,9 +75,8 @@ extern "C" { #include #include #include -#ifdef __cplusplus -} -#endif + +END_EXTERN_C /** \mainpage FreeSWITCH * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index ffdf3a0bd5..29d9e38d78 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -39,12 +39,7 @@ #ifndef SWITCH_APR_H #define SWITCH_APR_H -#ifdef __cplusplus -extern "C" { -#ifdef __FORMATBUG -} -#endif -#endif +BEGIN_EXTERN_C #include #include @@ -1435,8 +1430,6 @@ SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, /** @} */ /** @} */ -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_buffer.h b/src/include/switch_buffer.h index ff05db1a6c..582fbc0f40 100644 --- a/src/include/switch_buffer.h +++ b/src/include/switch_buffer.h @@ -38,12 +38,10 @@ #ifndef SWITCH_BUFFER_H #define SWITCH_BUFFER_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /** * @defgroup switch_buffer Buffer Routines * @ingroup core1 @@ -111,10 +109,6 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_toss(switch_buffer *buffer, switch_s SWITCH_DECLARE(void) switch_buffer_zero(switch_buffer *buffer); /** @} */ - -#ifdef __cplusplus -} -#endif - +END_EXTERN_C #endif diff --git a/src/include/switch_caller.h b/src/include/switch_caller.h index 7b09ec6462..c2aeac4e22 100644 --- a/src/include/switch_caller.h +++ b/src/include/switch_caller.h @@ -53,15 +53,10 @@ #ifndef SWITCH_CALLER_H #define SWITCH_CALLER_H -#ifdef __cplusplus -extern "C" { -#endif -#ifdef _FORMATBUG -} -#endif - #include +BEGIN_EXTERN_C + /*! \brief Call Specific Data */ struct switch_caller_profile { @@ -186,10 +181,7 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_clone(switch_core_ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile *caller_profile, char *prefix, switch_event *event); - -#ifdef __cplusplus -} -#endif +END_EXTERN_C /** @} */ diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index 34c805c27c..ba6487b1d2 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -38,15 +38,10 @@ #ifndef SWITCH_CHANNEL_H #define SWITCH_CHANNEL_H -#ifdef __cplusplus -extern "C" { -#endif -#ifdef __FORMATBUG -} -#endif - #include +BEGIN_EXTERN_C + struct switch_channel_timetable { switch_time_t created; switch_time_t answered; @@ -380,8 +375,6 @@ SWITCH_DECLARE(switch_status) switch_channel_set_raw_mode (switch_channel *chann SWITCH_DECLARE(switch_status) switch_channel_get_raw_mode (switch_channel *channel, int *freq, int *bits, int *channels, int *ms, int *kbps); /** @} */ -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_config.h b/src/include/switch_config.h index f2ea148271..b645efa374 100644 --- a/src/include/switch_config.h +++ b/src/include/switch_config.h @@ -56,12 +56,10 @@ #ifndef SWITCH_CONFIG_H #define SWITCH_CONFIG_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \brief A simple file handle representing an open configuration file **/ struct switch_config { /*! FILE stream buffer to the opened file */ @@ -106,9 +104,8 @@ SWITCH_DECLARE(void) switch_config_close_file(switch_config *cfg); */ SWITCH_DECLARE(int) switch_config_next_pair(switch_config *cfg, char **var, char **val); -#ifdef __cplusplus -} -#endif +END_EXTERN_C + /** @} */ #endif diff --git a/src/include/switch_console.h b/src/include/switch_console.h index 39e1eb651f..2440f5d7fe 100644 --- a/src/include/switch_console.h +++ b/src/include/switch_console.h @@ -39,12 +39,10 @@ #ifndef SWITCH_CONSOLE_H #define SWITCH_CONSOLE_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \brief A simple comand loop that reads input from the terminal */ @@ -55,8 +53,6 @@ SWITCH_DECLARE(void) switch_console_loop(void); */ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *file, const char *func, int line, char *fmt, ...); -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9366e54d84..a9fb053895 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -38,15 +38,10 @@ #ifndef SWITCH_CORE_H #define SWITCH_CORE_H -#ifdef __cplusplus -extern "C" { -#endif -#ifdef _FORMATBUG -} -#endif - #include +BEGIN_EXTERN_C + #define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128 #define SWITCH_MAX_STREAMS 128 @@ -984,10 +979,6 @@ SWITCH_DECLARE(void) switch_core_set_globals(void); \} */ - -#ifdef __cplusplus -} -#endif - +END_EXTERN_C #endif diff --git a/src/include/switch_event.h b/src/include/switch_event.h index 604d4ee9ea..8abdddb270 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -58,12 +58,10 @@ #ifndef SWITCH_EVENT_H #define SWITCH_EVENT_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \brief An event Header */ struct switch_event_header { /*! the header name */ @@ -288,8 +286,6 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event **event); #define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__FUNCTION__, __LINE__, event, data) ///\} -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_frame.h b/src/include/switch_frame.h index a0b5b6e433..c8788b9a92 100644 --- a/src/include/switch_frame.h +++ b/src/include/switch_frame.h @@ -36,12 +36,10 @@ #ifndef SWITCH_FRAME_H #define SWITCH_FRAME_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \brief An abstraction of a data frame */ struct switch_frame { /*! a pointer to the codec information */ @@ -70,8 +68,6 @@ struct switch_frame { switch_frame_flag flags; }; -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index a3e474b993..43a63add05 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -38,12 +38,10 @@ #ifndef SWITCH_IVR_H #define SWITCH_IVR_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /** * @defgroup switch_ivr IVR Library * @ingroup core1 @@ -179,9 +177,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_session_transfer(switch_core_session *s /** @} */ -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_loadable_module.h b/src/include/switch_loadable_module.h index b63fe1e2fe..42e38e4993 100644 --- a/src/include/switch_loadable_module.h +++ b/src/include/switch_loadable_module.h @@ -41,12 +41,10 @@ #ifndef SWITCH_LOADABLE_MODULE_H #define SWITCH_LOADABLE_MODULE_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \defgroup mods Loadable Module Functions \ingroup core1 @@ -240,8 +238,6 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void); SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void); ///\} -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_log.h b/src/include/switch_log.h index 9aeb487093..a5a3f76398 100644 --- a/src/include/switch_log.h +++ b/src/include/switch_log.h @@ -38,15 +38,10 @@ #ifndef SWITCH_LOG_H #define SWITCH_LOG_H -#ifdef __cplusplus -extern "C" { -#endif -#ifdef _FORMATBUG -} -#endif - #include +BEGIN_EXTERN_C + ///\defgroup log Logger Routines ///\ingroup core1 ///\{ @@ -122,8 +117,6 @@ SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level level); SWITCH_DECLARE(switch_log_level) switch_log_str2level(const char *str); ///\} -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 74a766d635..e3ab2b911d 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -39,12 +39,10 @@ #ifndef SWITCH_MODULE_INTERFACES_H #define SWITCH_MODULE_INTERFACES_H -#ifdef __cplusplus -extern "C" { -#endif - #include +BEGIN_EXTERN_C + /*! \brief A table of functions to execute at various states */ struct switch_state_handler_table { @@ -513,8 +511,6 @@ struct switch_api_interface { const struct switch_api_interface *next; }; -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_platform.h b/src/include/switch_platform.h index 3b157ee272..db427fa11b 100644 --- a/src/include/switch_platform.h +++ b/src/include/switch_platform.h @@ -34,9 +34,7 @@ #ifndef SWITCH_PLATFORM_H #define SWITCH_PLATFORM_H -#ifdef __cplusplus -extern "C" { -#endif +BEGIN_EXTERN_C #ifdef __ICC #pragma warning (disable:810 869 981 279 1469 188) @@ -153,8 +151,6 @@ typedef unsigned long in_addr_t; #define DoxyDefine(x) #endif -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_resample.h b/src/include/switch_resample.h index a385d5ed20..d2737b8270 100644 --- a/src/include/switch_resample.h +++ b/src/include/switch_resample.h @@ -42,11 +42,9 @@ #ifndef SWITCH_RESAMPLE_H #define SWITCH_RESAMPLE_H -#ifdef __cplusplus -extern "C" { -#endif -#include #include +BEGIN_EXTERN_C +#include /*! \defgroup resamp Audio Resample Functions @@ -158,10 +156,7 @@ SWITCH_DECLARE(void) switch_swap_linear(int16_t *buf, int len); ///\} -#ifdef __cplusplus -} -#endif - +END_EXTERN_C #endif diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 350a704310..1a336f14f3 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -38,12 +38,7 @@ #ifndef SWITCH_RTP_H #define SWITCH_RTP_H -#ifdef __cplusplus -extern "C" { -#ifdef _FORMATBUG -} -#endif -#endif +BEGIN_EXTERN_C #define SWITCH_RTP_MAX_BUF_LEN 16384 @@ -328,8 +323,6 @@ SWITCH_DECLARE(void *)switch_rtp_get_private(switch_rtp *rtp_session); \} */ -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_sqlite.h b/src/include/switch_sqlite.h index cc893dce19..296eba5e23 100644 --- a/src/include/switch_sqlite.h +++ b/src/include/switch_sqlite.h @@ -35,9 +35,7 @@ #ifndef SWITCH_SQLITE_H #define SWITCH_SQLITE_H -#ifdef __cplusplus -extern "C" { -#endif +BEGIN_EXTERN_C #include @@ -1806,10 +1804,6 @@ DoxyDefine(void switch_core_db_free(char *z);) /** @} */ /** @} */ - - -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_stun.h b/src/include/switch_stun.h index 46b768d9a3..c9af3bc6d7 100644 --- a/src/include/switch_stun.h +++ b/src/include/switch_stun.h @@ -36,6 +36,9 @@ */ #ifndef _SWITCH_STUN_PARSER_H #define _SWITCH_STUN_PARSER_H + +BEGIN_EXTERN_C + #define SWITCH_STUN_DEFAULT_PORT 3478 #define SWITCH_STUN_PACKET_MIN_LEN 20 @@ -236,4 +239,7 @@ SWITCH_DECLARE(switch_status) switch_stun_lookup (char **ip, */ #define switch_stun_packet_length(packet) ntohs(packet->header.length) + sizeof(switch_stun_packet_header_t) ///\} + +END_EXTERN_C + #endif diff --git a/src/include/switch_types.h b/src/include/switch_types.h index b6c36cd74c..b0726fb697 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -34,15 +34,9 @@ #ifndef SWITCH_TYPES_H #define SWITCH_TYPES_H -#ifdef __cplusplus -extern "C" { -#ifdef _FORMATBUG -} -#endif -#endif - #include -#include + +BEGIN_EXTERN_C #ifdef WIN32 #define SWITCH_PATH_SEPARATOR "\\" @@ -681,9 +675,6 @@ struct switch_channel; /*! \brief A core session representing a call and all of it's resources */ struct switch_core_session; - -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 26629d93ac..681ba1db85 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -38,13 +38,9 @@ #ifndef SWITCH_UTILS_H #define SWITCH_UTILS_H -#ifdef __cplusplus -extern "C" { -#endif - #include - +BEGIN_EXTERN_C #ifndef snprintf #define snprintf apr_snprintf @@ -182,8 +178,6 @@ SWITCH_DECLARE(switch_status) switch_string_match(const char *string, size_t str #define SWITCH_READ_ACCEPTABLE(status) status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK -#ifdef __cplusplus -} -#endif +END_EXTERN_C #endif diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 90d65c4307..97051c1f6b 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -454,11 +454,11 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session, } } else { /* time off the channel (if you must) */ switch_frame *read_frame; - + switch_status status; while (switch_channel_test_flag(channel, CF_HOLD)) { switch_yield(10000); } - switch_status status = switch_core_session_read_frame(session, &read_frame, -1, 0); + status = switch_core_session_read_frame(session, &read_frame, -1, 0); if (!SWITCH_READ_ACCEPTABLE(status)) { break; }