fix lots of BS
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@716 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
21d221a10f
commit
7665bf3e8e
|
@ -906,6 +906,11 @@ SWITCH_DECLARE(FILE *) switch_core_get_console(void);
|
|||
\brief Launch a thread
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread *, void*), void *obj, switch_memory_pool *pool);
|
||||
|
||||
/*!
|
||||
\brief Initiate Globals
|
||||
*/
|
||||
SWITCH_DECLARE(void) switch_core_set_globals(void);
|
||||
///\}
|
||||
|
||||
#ifdef USE_PERL
|
||||
|
|
|
@ -42,9 +42,9 @@ extern "C" {
|
|||
#include <switch_platform.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define SEP "\\"
|
||||
#define SWITCH_PATH_SEPARATOR "\\"
|
||||
#else
|
||||
#define SEP "/"
|
||||
#define SWITCH_PATH_SEPARATOR "/"
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_PREFIX_DIR
|
||||
|
@ -52,23 +52,23 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#ifndef SWITCH_MOD_DIR
|
||||
#define SWITCH_MOD_DIR SWITCH_PREFIX_DIR SEP "mod"
|
||||
#define SWITCH_MOD_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod"
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_CONF_DIR
|
||||
#define SWITCH_CONF_DIR SWITCH_PREFIX_DIR SEP "conf"
|
||||
#define SWITCH_CONF_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "conf"
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_LOG_DIR
|
||||
#define SWITCH_LOG_DIR SWITCH_PREFIX_DIR SEP "log"
|
||||
#define SWITCH_LOG_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "log"
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_DB_DIR
|
||||
#define SWITCH_DB_DIR SWITCH_PREFIX_DIR SEP "db"
|
||||
#define SWITCH_DB_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "db"
|
||||
#endif
|
||||
|
||||
#ifndef SWITCH_SCRIPT_DIR
|
||||
#define SWITCH_SCRIPT_DIR SWITCH_PREFIX_DIR SEP "scripts"
|
||||
#define SWITCH_SCRIPT_DIR SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "scripts"
|
||||
#endif
|
||||
|
||||
struct switch_directories {
|
||||
|
|
|
@ -61,7 +61,7 @@ endif
|
|||
|
||||
CFLAGS += -I$(BASE)/libs/mozilla/js/src -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/js/src -I$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -I$(OS_CONFIG)_DBG.OBJ
|
||||
LDFLAGS +=-DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -Wall -Wno-format -g -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -DDEBUG -DDEBUG_root -DJS_THREADSAFE -I$(BASE)/libs/mozilla/nsprpub/dist/include/nspr -lteletone
|
||||
OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a
|
||||
OBJS=$(BASE)/libs/mozilla/js/src/$(OS_CONFIG)_DBG.OBJ/libjs.a $(BASE)/libs/mozilla/nsprpub/dist/lib/libnspr4.a -lcurl
|
||||
LINKER=$(CC)
|
||||
|
||||
|
||||
|
|
|
@ -110,6 +110,7 @@ struct teletone_obj {
|
|||
switch_core_session *session;
|
||||
switch_codec codec;
|
||||
switch_buffer *audio_buffer;
|
||||
switch_buffer *loop_buffer;
|
||||
switch_memory_pool *pool;
|
||||
switch_timer *timer;
|
||||
switch_timer timer_base;
|
||||
|
@ -762,7 +763,7 @@ static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
switch_codec *read_codec;
|
||||
switch_memory_pool *pool;
|
||||
char *timer_name = NULL;
|
||||
|
||||
|
||||
if (argc > 0) {
|
||||
if (JS_ValueToObject(cx, argv[0], &session_obj)) {
|
||||
if (!(jss = JS_GetPrivate(cx, session_obj))) {
|
||||
|
@ -882,6 +883,7 @@ static JSBool teletone_on_dtmf(JSContext *cx, JSObject *obj, uintN argc, jsval *
|
|||
static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
struct teletone_obj *tto = JS_GetPrivate(cx, obj);
|
||||
int32 loops = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
char *script;
|
||||
|
@ -893,7 +895,23 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
switch_core_thread_session thread_session;
|
||||
switch_channel *channel;
|
||||
|
||||
if (argc > 1) {
|
||||
if (!JS_ValueToInt32(cx, argv[1], &loops)) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Convert to INT\n");
|
||||
return JS_FALSE;
|
||||
}
|
||||
loops--;
|
||||
if (!tto->loop_buffer) {
|
||||
switch_buffer_create(tto->pool, &tto->loop_buffer, SWITCH_RECCOMMENDED_BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
if (tto->audio_buffer) {
|
||||
switch_buffer_zero(tto->audio_buffer);
|
||||
}
|
||||
if (tto->loop_buffer) {
|
||||
switch_buffer_zero(tto->loop_buffer);
|
||||
}
|
||||
tto->ts.debug = 1;
|
||||
tto->ts.debug_stream = switch_core_get_console();
|
||||
|
||||
|
@ -944,7 +962,21 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
}
|
||||
}
|
||||
if ((write_frame.datalen = switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
|
||||
break;
|
||||
if (loops > 0) {
|
||||
switch_buffer *tmp;
|
||||
|
||||
/* Switcharoo*/
|
||||
tmp = tto->audio_buffer;
|
||||
tto->audio_buffer = tto->loop_buffer;
|
||||
tto->loop_buffer = tmp;
|
||||
loops--;
|
||||
/* try again */
|
||||
if ((write_frame.datalen = switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
write_frame.samples = write_frame.datalen / 2;
|
||||
|
@ -954,6 +986,9 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (tto->loop_buffer && loops) {
|
||||
switch_buffer_write(tto->loop_buffer, write_frame.data, write_frame.datalen);
|
||||
}
|
||||
}
|
||||
|
||||
if (tto->timer) {
|
||||
|
|
43
src/switch.c
43
src/switch.c
|
@ -65,34 +65,30 @@ int main(int argc, char *argv[])
|
|||
char *lfile = "freeswitch.log";
|
||||
char *pfile = "freeswitch.pid";
|
||||
char path[256] = "";
|
||||
char *ppath = NULL;
|
||||
char *err = NULL;
|
||||
switch_event *event;
|
||||
int bg = 0;
|
||||
FILE *f;
|
||||
#ifdef WIN32
|
||||
char sep = '\\';
|
||||
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
||||
#else
|
||||
char sep = '/';
|
||||
int pid;
|
||||
nice(-20);
|
||||
#endif
|
||||
|
||||
if (switch_core_init(NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
fprintf(stderr, "Cannot Initilize\n");
|
||||
return 255;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
if (argv[1] && !strcmp(argv[1], "-stop")) {
|
||||
pid_t pid = 0;
|
||||
snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
|
||||
switch_core_set_globals();
|
||||
snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
|
||||
if ((f = fopen(path, "r")) == 0) {
|
||||
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||
return 255;
|
||||
}
|
||||
fscanf(f, "%d", &pid);
|
||||
if (pid > 0) {
|
||||
fprintf(stderr, "Killing %d\n", (int) pid);
|
||||
kill(pid, SIGTERM);
|
||||
}
|
||||
|
||||
|
@ -101,6 +97,23 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
if (argv[1] && !strcmp(argv[1], "-nc")) {
|
||||
bg++;
|
||||
}
|
||||
|
||||
if (bg) {
|
||||
//snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.log_dir, sep, lfile);
|
||||
ppath = lfile;
|
||||
}
|
||||
|
||||
|
||||
if (switch_core_init(ppath) != SWITCH_STATUS_SUCCESS) {
|
||||
fprintf(stderr, "Cannot Initilize\n");
|
||||
return 255;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* set signal handlers */
|
||||
(void) signal(SIGINT, (void *) handle_SIGINT);
|
||||
#ifdef SIGPIPE
|
||||
|
@ -111,9 +124,7 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
|
||||
if (argv[1] && !strcmp(argv[1], "-nc")) {
|
||||
bg++;
|
||||
}
|
||||
|
||||
|
||||
if (bg) {
|
||||
(void) signal(SIGHUP, (void *) handle_SIGHUP);
|
||||
|
@ -129,7 +140,7 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
}
|
||||
|
||||
snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
|
||||
snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
|
||||
if ((f = fopen(path, "w")) == 0) {
|
||||
fprintf(stderr, "Cannot open pid file %s.\n", path);
|
||||
return 255;
|
||||
|
@ -138,12 +149,6 @@ int main(int argc, char *argv[])
|
|||
fprintf(f, "%d", getpid());
|
||||
fclose(f);
|
||||
|
||||
if (bg) {
|
||||
snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, lfile);
|
||||
if (switch_core_set_console(path) != SWITCH_STATUS_SUCCESS) {
|
||||
err = "Cannot open log file\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!err) {
|
||||
|
@ -165,7 +170,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_VERSION_FULL);
|
||||
snprintf(path, sizeof(path), "%s%c%s", SWITCH_GLOBAL_dirs.conf_dir, sep, pfile);
|
||||
snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
|
||||
|
||||
if (bg) {
|
||||
bg = 0;
|
||||
|
|
|
@ -2180,15 +2180,13 @@ static void core_event_handler(switch_event *event)
|
|||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_init(char *console)
|
||||
SWITCH_DECLARE(void) switch_core_set_globals(void)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#define BUFSIZE 50
|
||||
char lpPathBuffer[BUFSIZE];
|
||||
DWORD dwBufSize=BUFSIZE;
|
||||
#endif
|
||||
memset(&runtime, 0, sizeof(runtime));
|
||||
|
||||
SWITCH_GLOBAL_dirs.base_dir = SWITCH_PREFIX_DIR;
|
||||
SWITCH_GLOBAL_dirs.mod_dir = SWITCH_MOD_DIR;
|
||||
SWITCH_GLOBAL_dirs.conf_dir = SWITCH_CONF_DIR;
|
||||
|
@ -2205,12 +2203,24 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console)
|
|||
SWITCH_GLOBAL_dirs.temp_dir = "/tmp/";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status) switch_core_init(char *console)
|
||||
{
|
||||
|
||||
memset(&runtime, 0, sizeof(runtime));
|
||||
|
||||
|
||||
switch_core_set_globals();
|
||||
|
||||
#ifdef EMBED_PERL
|
||||
PerlInterpreter *my_perl;
|
||||
#endif
|
||||
if(console) {
|
||||
if (*console != '/') {
|
||||
char path[265];
|
||||
snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, console);
|
||||
console = path;
|
||||
}
|
||||
switch_core_set_console(console);
|
||||
} else {
|
||||
runtime.console = stdout;
|
||||
|
|
|
@ -162,6 +162,10 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void
|
|||
switch_event_deliver(&out_event);
|
||||
}
|
||||
}
|
||||
|
||||
if (THREAD_RUNNING < 0) {
|
||||
THREAD_RUNNING--;
|
||||
}
|
||||
switch_yield(1000);
|
||||
}
|
||||
THREAD_RUNNING = 0;
|
||||
|
@ -230,10 +234,18 @@ SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner
|
|||
|
||||
SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
|
||||
{
|
||||
THREAD_RUNNING = -1;
|
||||
int x = 0, last = 0;
|
||||
|
||||
while (THREAD_RUNNING) {
|
||||
switch_yield(1000);
|
||||
if (THREAD_RUNNING > 0) {
|
||||
THREAD_RUNNING = -1;
|
||||
|
||||
while (x < 100 && THREAD_RUNNING) {
|
||||
switch_yield(1000);
|
||||
if (THREAD_RUNNING == last) {
|
||||
x++;
|
||||
}
|
||||
last = THREAD_RUNNING;
|
||||
}
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue