Thu Oct 8 21:56:33 2009

Asterisk developer's documentation


res_watchdog.c File Reference

#include "asterisk.h"
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <netinet/in.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/options.h>
#include <asterisk/module.h>
#include <asterisk/translate.h>
#include <asterisk/say.h>
#include <asterisk/features.h>
#include <asterisk/musiconhold.h>
#include <asterisk/config.h>
#include <asterisk/cli.h>
#include <asterisk/manager.h>
#include <asterisk/utils.h>
#include <asterisk/lock.h>
#include <asterisk/adsi.h>

Include dependency graph for res_watchdog.c:

Go to the source code of this file.

Data Structures

struct  watchdog_pvt

Functions

 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,"Watchdog Resource",.load=load_module,.unload=unload_module,)
static void * do_watchdog_thread (void *data)
static int load_module (void)
static int unload_module (void)

Variables

static struct watchdog_pvtwatchdogs = NULL


Function Documentation

AST_MODULE_INFO ( ASTERISK_GPL_KEY  ,
AST_MODFLAG_GLOBAL_SYMBOLS  ,
"Watchdog Resource"  ,
load = load_module,
unload = unload_module 
)

static void* do_watchdog_thread ( void *  data  )  [static]

Definition at line 52 of file res_watchdog.c.

References watchdog_pvt::fd, and watchdog_pvt::interval.

Referenced by load_module().

00052                                             {
00053     struct watchdog_pvt *woof = (struct watchdog_pvt *)data;
00054     for (;;) {
00055    if (woof->fd) {
00056        write(woof->fd, "PING\n", 5);
00057    }
00058    usleep(woof->interval * 1000);
00059     }
00060     return NULL;
00061 }

static int load_module ( void   )  [static]

Definition at line 64 of file res_watchdog.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_log(), ast_pthread_create, ast_variable_retrieve(), watchdog_pvt::device, do_watchdog_thread(), watchdog_pvt::fd, watchdog_pvt::interval, LOG_ERROR, LOG_WARNING, malloc, watchdog_pvt::next, watchdog_pvt::type, and watchdog_pvt::watchdog_thread.

00065 {
00066    int res = 0;
00067    const char *cat, *utype, *udevice, *uinterval;
00068    struct ast_config *cfg;
00069    struct watchdog_pvt *woof = NULL;
00070 
00071    cfg = ast_config_load("watchdog.conf");
00072    if (cfg) {
00073        cat = ast_category_browse(cfg, NULL);
00074        while(cat) {
00075       cat = ast_category_browse(cfg, cat);
00076       utype = ast_variable_retrieve(cfg, cat, "type");
00077 /*    if (utype) {
00078           ast_log(LOG_NOTICE, "type = %s\n", utype);
00079       } */
00080       udevice = ast_variable_retrieve(cfg, cat, "device");
00081 /*    if (udevice) {
00082           ast_log(LOG_NOTICE, "device = %s\n", udevice);
00083       } */
00084       uinterval = ast_variable_retrieve(cfg, cat, "interval");
00085 /*    if (uinterval) {
00086           ast_log(LOG_NOTICE, "interval = %s\n", uinterval);
00087       } */
00088       if (uinterval && udevice && utype) {
00089           woof = malloc(sizeof(struct watchdog_pvt));
00090           if (!woof) {
00091          ast_log(LOG_ERROR, "unable to malloc!\n");
00092          return -1;
00093           }
00094           memset(woof, 0x0, sizeof(struct watchdog_pvt));
00095           strncpy(woof->device, udevice, sizeof(woof->device) - 1);
00096           
00097           woof->interval = atoi(uinterval);;
00098           woof->next = watchdogs;
00099           watchdogs = woof;
00100           woof->fd = open(woof->device, O_WRONLY | O_SYNC);
00101           if (woof->fd) {
00102          if (!strncmp(utype, "isdnguard", sizeof(utype))) {
00103              woof->type = 1;
00104              write(woof->fd, "START\n", 6);
00105          }
00106          ast_pthread_create(&woof->watchdog_thread, NULL, do_watchdog_thread, woof);
00107           } else {
00108          ast_log(LOG_WARNING, "error opening watchdog device %s !\n", woof->device);
00109           }
00110       }
00111        }
00112           ast_config_destroy(cfg);
00113    }
00114    return res;
00115 }

static int unload_module ( void   )  [static]

Definition at line 118 of file res_watchdog.c.

References watchdog_pvt::fd, free, watchdog_pvt::next, and watchdog_pvt::watchdog_thread.

00119 {
00120    struct watchdog_pvt *dogs, *woof;
00121    dogs = watchdogs;
00122    while (dogs) {
00123        pthread_cancel(dogs->watchdog_thread);
00124        pthread_join(dogs->watchdog_thread, NULL);
00125        close(dogs->fd);
00126        woof = dogs->next;
00127        free(dogs);
00128        dogs = woof;
00129    }
00130    return 0;
00131 }


Variable Documentation

struct watchdog_pvt* watchdogs = NULL [static]

Definition at line 41 of file res_watchdog.c.


Generated on Thu Oct 8 21:56:33 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6