X-Git-Url: http://git.asterisk.org/gitweb/?p=asterisk%2Fasterisk.git;a=blobdiff_plain;f=apps%2Fapp_skel.c;h=8ca411305b9e33589af60768707016dbeae7d873;hp=e766d1142bd7b3a3d93317b9004ac978d06c6e09;hb=5f97dfdf3448265efaa21443f7f8c1ee25aeaad7;hpb=42d4c7991cc648294965070cc0f053a4611408e1 diff --git a/apps/app_skel.c b/apps/app_skel.c index e766d11..8ca4113 100755 --- a/apps/app_skel.c +++ b/apps/app_skel.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -22,63 +23,32 @@ #include -static pthread_mutex_t skellock = PTHREAD_MUTEX_INITIALIZER; - -static int usecnt=0; static char *tdesc = "Trivial skeleton Application"; static char *app = "skel"; -struct skeluser { - struct ast_channel *chan; - struct skeluser *next; -} *users = NULL; +STANDARD_LOCAL_USER; + +LOCAL_USER_DECL; static int skel_exec(struct ast_channel *chan, void *data) { int res=0; - struct skeluser *u, *ul=NULL; + struct localuser *u; if (!data) { ast_log(LOG_WARNING, "skel requires an argument (filename)\n"); return -1; } - if (!(u=malloc(sizeof(struct skeluser)))) { - ast_log(LOG_WARNING, "Out of memory\n"); - return -1; - } - pthread_mutex_lock(&skellock); - u->chan = chan; - u->next = users; - users = u; - usecnt++; - pthread_mutex_unlock(&skellock); + LOCAL_USER_ADD(u); /* Do our thing here */ - pthread_mutex_lock(&skellock); - u = users; - while(u) { - if (ul) - ul->next = u->next; - else - users = u->next; - u = u->next; - } - usecnt--; - pthread_mutex_unlock(&skellock); + LOCAL_USER_REMOVE(u); return res; } int unload_module(void) { - struct skeluser *u; - pthread_mutex_lock(&skellock); - u = users; - while(u) { - /* Hang up anybody who is using us */ - ast_softhangup(u->chan); - u = u->next; - } - pthread_mutex_unlock(&skellock); + STANDARD_HANGUP_LOCALUSERS; return ast_unregister_application(app); } @@ -95,8 +65,11 @@ char *description(void) int usecount(void) { int res; - pthread_mutex_lock(&skellock); - res = usecnt; - pthread_mutex_unlock(&skellock); + STANDARD_USECOUNT(res); return res; } + +char *key() +{ + return ASTERISK_GPL_KEY; +}