\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
#include <switch_platform.h>
#ifdef WIN32
-#define SEP "\\"
+#define SWITCH_PATH_SEPARATOR "\\"
#else
-#define SEP "/"
+#define SWITCH_PATH_SEPARATOR "/"
#endif
#ifndef SWITCH_PREFIX_DIR
#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 {
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)
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;
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))) {
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;
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();
}
}
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;
break;
}
}
+ if (tto->loop_buffer && loops) {
+ switch_buffer_write(tto->loop_buffer, write_frame.data, write_frame.datalen);
+ }
}
if (tto->timer) {
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);
}
}
#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
#endif
- if (argv[1] && !strcmp(argv[1], "-nc")) {
- bg++;
- }
+
if (bg) {
(void) signal(SIGHUP, (void *) handle_SIGHUP);
#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;
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) {
}
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;
}
}
-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;
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;
switch_event_deliver(&out_event);
}
}
+
+ if (THREAD_RUNNING < 0) {
+ THREAD_RUNNING--;
+ }
switch_yield(1000);
}
THREAD_RUNNING = 0;
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;
}