[asterisk-commits] branch crichter/0.4.0 r37326 - in
/team/crichter/0.4.0/channels: ./ misdn/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Jul 10 05:21:16 MST 2006
Author: crichter
Date: Mon Jul 10 07:21:15 2006
New Revision: 37326
URL: http://svn.digium.com/view/asterisk?rev=37326&view=rev
Log:
Introducing a new way for the l1watcher thread using the ast_sched way. Now l1watcher timeouts can be configured separately for every portgroup.
Modified:
team/crichter/0.4.0/channels/chan_misdn.c
team/crichter/0.4.0/channels/misdn/chan_misdn_config.h
team/crichter/0.4.0/channels/misdn/isdn_lib.c
team/crichter/0.4.0/channels/misdn/isdn_lib.h
team/crichter/0.4.0/channels/misdn_config.c
Modified: team/crichter/0.4.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/chan_misdn.c?rev=37326&r1=37325&r2=37326&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Mon Jul 10 07:21:15 2006
@@ -59,6 +59,7 @@
#include <asterisk/app.h>
#include <asterisk/features.h>
#include <asterisk/term.h>
+#include <asterisk/sched.h>
#include <chan_misdn_config.h>
#include <isdn_lib.h>
@@ -100,12 +101,6 @@
available data is returned and the return value indicates the number
of data. */
int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
-
-
-
-
-/* BEGIN: chan_misdn.h */
-
enum misdn_chan_state {
@@ -250,6 +245,10 @@
}
+/* the main schedule context for stuff like l1 watcher, overlap dial, ... */
+static struct sched_context *misdn_tasks = NULL;
+static pthread_t misdn_tasks_thread;
+
static void chan_misdn_log(int level, int port, char *tmpl, ...);
static struct ast_channel *misdn_new(struct chan_list *cl, int state, char *exten, char *callerid, int format, int port, int c);
@@ -430,6 +429,53 @@
}
}
/*************** Helpers END *************/
+
+static void* misdn_tasks_thread_func (void *data)
+{
+ int wait;
+ while (1) {
+ wait = ast_sched_wait(misdn_tasks);
+ if (wait < 0)
+ wait = 4000;
+ poll(NULL, 0, wait);
+ ast_sched_runq(misdn_tasks);
+ }
+ return NULL;
+}
+
+static void misdn_tasks_init (void)
+{
+ chan_misdn_log(4, 0, "Starting misdn_tasks thread\n");
+ misdn_tasks = sched_context_create();
+ pthread_create(&misdn_tasks_thread, NULL, misdn_tasks_thread_func, NULL);
+}
+
+static void misdn_tasks_destroy (void)
+{
+ if (misdn_tasks) {
+ chan_misdn_log(4, 0, "Killing misdn_tasks thread\n");
+ if ( pthread_cancel(misdn_tasks_thread) == 0 ) {
+ cb_log(4, 0, "Joining misdn_tasks thread\n");
+ pthread_join(misdn_tasks_thread, NULL);
+ }
+ sched_context_destroy(misdn_tasks);
+ }
+}
+
+static void misdn_tasks_add (int timeout, ast_sched_cb callback, void *data)
+{
+ if (!misdn_tasks)
+ misdn_tasks_init();
+ ast_sched_add(misdn_tasks, timeout, callback, data);
+ ast_sched_runq(misdn_tasks);
+}
+
+static int misdn_l1_task (void *data)
+{
+ misdn_lib_isdn_l1watcher((int)data);
+ chan_misdn_log(5, (int)data, "L1watcher timeout\n");
+ return 1;
+}
static void send_digit_to_chan(struct chan_list *cl, char digit )
{
@@ -627,7 +673,7 @@
ok = 1;
}
if ((argc == 4) || ((argc == 5) && !strcmp(argv[4], "ports"))) {
- for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_CFG_LAST; ++elem) {
+ for (elem = MISDN_CFG_FIRST + 1; elem < MISDN_CFG_LAST - 1 /* the ptp hack, remove the -1 when ptp is gone */; ++elem) {
show_config_description(fd, elem);
ast_cli(fd, "\n");
}
@@ -4129,10 +4175,10 @@
int load_module(void)
{
- int i;
+ int i, port;
char ports[256]="";
-
+
max_ports=misdn_lib_maxports_get();
if (max_ports<=0) {
@@ -4173,10 +4219,6 @@
misdn_cfg_update_ptp();
misdn_cfg_get_ports_string(ports);
-
- int l1watcher_timeout=0;
- misdn_cfg_get( 0, MISDN_GEN_L1_TIMEOUT, &l1watcher_timeout, sizeof(int));
-
if (strlen(ports))
chan_misdn_log(0, 0, "Got: %s from get_ports\n",ports);
@@ -4185,7 +4227,6 @@
.cb_event = cb_events,
.cb_log = chan_misdn_log,
.cb_jb_empty = chan_misdn_jb_empty,
- .l1watcher_timeout=l1watcher_timeout,
};
if (misdn_lib_init(ports, &iface, NULL))
@@ -4253,6 +4294,17 @@
reload_config();
+ /* start the l1 watchers */
+
+ for (port = misdn_cfg_get_next_port(0); port >= 0; port = misdn_cfg_get_next_port(port)) {
+ int l1timeout;
+ misdn_cfg_get(port, MISDN_CFG_L1_TIMEOUT, &l1timeout, sizeof(l1timeout));
+ if (l1timeout) {
+ chan_misdn_log(4, 0, "Adding L1watcher task: port:%d timeout:%ds\n", port, l1timeout);
+ misdn_tasks_add(l1timeout * 1000, misdn_l1_task, (void*)port);
+ }
+ }
+
chan_misdn_log(0, 0, "-- mISDN Channel Driver Registred -- (BE AWARE THIS DRIVER IS EXPERIMENTAL!)\n");
return 0;
@@ -4264,6 +4316,8 @@
{
/* First, take us out of the channel loop */
ast_log(LOG_VERBOSE, "-- Unregistering mISDN Channel Driver --\n");
+
+ misdn_tasks_destroy();
if (!g_config_initialized) return 0;
Modified: team/crichter/0.4.0/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/chan_misdn_config.h?rev=37326&r1=37325&r2=37326&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/chan_misdn_config.h (original)
+++ team/crichter/0.4.0/channels/misdn/chan_misdn_config.h Mon Jul 10 07:21:15 2006
@@ -59,6 +59,8 @@
MISDN_CFG_MAX_IN, /* int */
MISDN_CFG_MAX_OUT, /* int */
MISDN_CFG_FAXDETECT, /* char[] */
+ MISDN_CFG_L1_TIMEOUT, /* int */
+ MISDN_CFG_OVERLAP_DIAL, /* int */
MISDN_CFG_MSNS, /* char[] */
MISDN_CFG_PTP, /* int (bool) */
MISDN_CFG_LAST,
@@ -74,7 +76,6 @@
MISDN_GEN_DYNAMIC_CRYPT, /* int (bool) */
MISDN_GEN_CRYPT_PREFIX, /* char[] */
MISDN_GEN_CRYPT_KEYS, /* char[] */
- MISDN_GEN_L1_TIMEOUT, /* int */
MISDN_GEN_NTDEBUGFLAGS, /* int */
MISDN_GEN_NTDEBUGFILE, /* char[] */
MISDN_GEN_LAST
Modified: team/crichter/0.4.0/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/isdn_lib.c?rev=37326&r1=37325&r2=37326&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.4.0/channels/misdn/isdn_lib.c Mon Jul 10 07:21:15 2006
@@ -108,12 +108,9 @@
int midev;
int midev_nt;
- pthread_t l1watcher_thread;
pthread_t event_thread;
pthread_t event_handler_thread;
- int l1watcher_timeout;
-
void *user_data;
msg_queue_t upqueue;
@@ -163,7 +160,6 @@
unsigned char tone_425_flip[TONE_425_SIZE];
unsigned char tone_silence_flip[TONE_SILENCE_SIZE];
-static void misdn_lib_isdn_l1watcher(void *arg);
static void misdn_lib_isdn_event_catcher(void *arg);
static int handle_event_nt(void *dat, void *arg);
@@ -2803,30 +2799,20 @@
return NULL;
}
-static void misdn_lib_isdn_l1watcher(void *arg)
-{
- struct misdn_lib *mgr = arg;
+void misdn_lib_isdn_l1watcher(int port)
+{
struct misdn_stack *stack;
- while (1) {
- sleep(mgr->l1watcher_timeout);
-
- /* look out for l1 which are down
- and try to pull the up.
-
- We might even try to pull the l2 up in the
- ptp case.
- */
- for (stack = mgr->stack_list;
- stack;
- stack = stack->next) {
- cb_log(4,stack->port,"Checking L1 State\n");
- if (!stack->l1link) {
- cb_log(4,stack->port,"L1 State Down, trying to get it up again\n");
- misdn_lib_get_short_status(stack);
- misdn_lib_get_l1_up(stack);
- misdn_lib_get_l2_up(stack);
- }
+ for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next)
+ ;
+
+ if (stack) {
+ cb_log(4, port, "Checking L1 State\n");
+ if (!stack->l1link) {
+ cb_log(4, port, "L1 State Down, trying to get it up again\n");
+ misdn_lib_get_short_status(stack);
+ misdn_lib_get_l1_up(stack);
+ misdn_lib_get_l2_up(stack);
}
}
}
@@ -3660,7 +3646,7 @@
if (sem_init(&mgr->new_msg, 1, 0)<0)
sem_init(&mgr->new_msg, 0, 0);
-
+
for (tok=strtok_r(plist," ,",&tokb );
tok;
tok=strtok_r(NULL," ,",&tokb)) {
@@ -3683,20 +3669,20 @@
exit(1);
}
+ {
+ int i;
+ for(i=0;i<stack->b_num; i++) {
+ int r;
+ if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
+ cb_log(-1, port, "Got Err @ init_bc :%d\n",r);
+ exit(1);
+ }
+ }
+ }
+
if (stack && first) {
mgr->stack_list=stack;
first=0;
- {
- int i;
- for(i=0;i<stack->b_num; i++) {
- int r;
- if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "", 1))<0) {
- cb_log(-1, port, "Got Err @ init_bc :%d\n",r);
- exit(1);
- }
- }
- }
-
continue;
}
@@ -3704,20 +3690,7 @@
struct misdn_stack * help;
for ( help=mgr->stack_list; help; help=help->next )
if (help->next == NULL) break;
-
-
help->next=stack;
-
- {
- int i;
- for(i=0;i<stack->b_num; i++) {
- int r;
- if ((r=init_bc(stack, &stack->bc[i], stack->midev,port,i, "",1 ))<0) {
- cb_log(-1, port, "Got Err @ init_bc :%d\n",r);
- exit(1);
- }
- }
- }
}
}
@@ -3734,12 +3707,6 @@
cb_log(4, 0, "Event Catcher started\n");
- if (iface->l1watcher_timeout > 0) {
- mgr->l1watcher_timeout=iface->l1watcher_timeout;
- cb_log(4, 0, "Starting L1 watcher\n");
- pthread_create( &mgr->l1watcher_thread, NULL, (void*)misdn_lib_isdn_l1watcher, mgr);
- }
-
global_state= MISDN_INITIALIZED;
return (mgr == NULL);
Modified: team/crichter/0.4.0/channels/misdn/isdn_lib.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/isdn_lib.h?rev=37326&r1=37325&r2=37326&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/isdn_lib.h (original)
+++ team/crichter/0.4.0/channels/misdn/isdn_lib.h Mon Jul 10 07:21:15 2006
@@ -337,12 +337,9 @@
int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len);
struct misdn_lib_iface {
-
enum event_response_e (*cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data);
void (*cb_log)(int level, int port, char *tmpl, ...);
int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len);
-
- int l1watcher_timeout;
};
/***** USER IFACE **********/
@@ -352,6 +349,8 @@
int misdn_lib_init(char *portlist, struct misdn_lib_iface* iface, void *user_data);
int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event );
void misdn_lib_destroy(void);
+
+void misdn_lib_isdn_l1watcher(int port);
void misdn_lib_log_ies(struct misdn_bchannel *bc);
Modified: team/crichter/0.4.0/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn_config.c?rev=37326&r1=37325&r2=37326&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn_config.c (original)
+++ team/crichter/0.4.0/channels/misdn_config.c Mon Jul 10 07:21:15 2006
@@ -253,6 +253,19 @@
"\texceeding calls will be rejected" },
{ "faxdetect", MISDN_CFG_FAXDETECT, MISDN_CTYPE_STR, "no", NONE,
"Context to jump into if we detect an incoming fax." },
+ { "l1watcher_timeout", MISDN_CFG_L1_TIMEOUT, MISDN_CTYPE_BOOLINT, "0", 4,
+ "Watches the layer 1. If the layer 1 is down, it tries to\n"
+ "\tget it up. The timeout is given in seconds. with 0 as value it\n"
+ "\tdoes not watch the l1 at all\n"
+ "\n"
+ "\tThis option is only read at loading time of chan_misdn, which\n"
+ "\tmeans you need to unload and load chan_misdn to change the value,\n"
+ "\tan Asterisk restart should do the trick." },
+ { "overlap_dial", MISDN_CFG_OVERLAP_DIAL, MISDN_CTYPE_BOOLINT, "0", 4,
+ "Enables overlap dial for the given amount of seconds.\n"
+ "\tPossible values are positive integers or:\n"
+ "\t yes (= 4 seconds)\n"
+ "\t no (= 0 seconds = disabled)" },
{ "msns", MISDN_CFG_MSNS, MISDN_CTYPE_MSNLIST, NO_DEFAULT, NONE,
"MSN's for TE ports, listen on those numbers on the above ports, and\n"
"\tindicate the incoming calls to Asterisk.\n"
@@ -284,18 +297,10 @@
{ "crypt_keys", MISDN_GEN_CRYPT_KEYS, MISDN_CTYPE_STR, NO_DEFAULT, NONE,
"Keys for cryption, you reference them in the dialplan\n"
"\tLater also in dynamic encr." },
- { "l1watcher_timeout", MISDN_GEN_L1_TIMEOUT, MISDN_CTYPE_INT, "0", NONE,
- "Watches the L1s of every port. If one l1 is down it tries to\n"
- "\tget it up. The timeout is given in seconds. with 0 as value it\n"
- "\tdoes not watch the l1 at all\n"
- "\n"
- "\tThis option is only read at loading time of chan_misdn, which\n"
- "\tmeans you need to unload and load chan_misdn to change the value,\n"
- "\tan Asterisk restart should do the trick." },
{ "ntdebugflags", MISDN_GEN_NTDEBUGFLAGS, MISDN_CTYPE_INT, "0", NONE,
- "No description yet." },
+ "No description yet." },
{ "ntdebugfile", MISDN_GEN_NTDEBUGFILE, MISDN_CTYPE_STR, "/var/log/misdn-nt.log", NONE,
- "No description yet" }
+ "No description yet." }
};
/* array of port configs, default is at position 0. */
More information about the asterisk-commits
mailing list