Mon Mar 20 08:20:16 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

app_userevent.c File Reference

UserEvent application -- send manager event. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/manager.h"

Go to the source code of this file.

Functions

char * description (void)
 Provides a description of the module.
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.
int userevent_exec (struct ast_channel *chan, void *data)

Variables

char * app = "UserEvent"
char * descrip
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
char * synopsis = "Send an arbitrary event to the manager interface"
char * tdesc = "Custom User Event Application"


Detailed Description

UserEvent application -- send manager event.

Definition in file app_userevent.c.


Function Documentation

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 122 of file app_userevent.c.

00123 {
00124    return tdesc;
00125 }

char* key void   ) 
 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 134 of file app_userevent.c.

00135 {
00136    return ASTERISK_GPL_KEY;
00137 }

int load_module void   ) 
 

Initialize the module.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.

Definition at line 117 of file app_userevent.c.

References app, ast_register_application(), descrip, synopsis, and userevent_exec().

00118 {
00119    return ast_register_application(app, userevent_exec, synopsis, descrip);
00120 }

int unload_module void   ) 
 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 106 of file app_userevent.c.

References app, and ast_unregister_application().

00107 {
00108    int res;
00109 
00110    res = ast_unregister_application(app);
00111 
00112    STANDARD_HANGUP_LOCALUSERS;
00113 
00114    return res; 
00115 }

int usecount void   ) 
 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 127 of file app_userevent.c.

References STANDARD_USECOUNT.

00128 {
00129    int res;
00130    STANDARD_USECOUNT(res);
00131    return res;
00132 }

int userevent_exec struct ast_channel chan,
void *  data
[static]
 

Definition at line 63 of file app_userevent.c.

References ast_log(), ast_strdupa, ast_strlen_zero(), EVENT_FLAG_USER, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_WARNING, manager_event(), ast_channel::name, and ast_channel::uniqueid.

Referenced by load_module().

00064 {
00065    struct localuser *u;
00066    char *info;
00067    char eventname[512];
00068    char *eventbody;
00069 
00070    if (ast_strlen_zero(data)) {
00071       ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n");
00072       return -1;
00073    }
00074 
00075    LOCAL_USER_ADD(u);
00076 
00077    info = ast_strdupa(data);
00078    if (!info) {
00079       ast_log(LOG_ERROR, "Out of memory\n");
00080       LOCAL_USER_REMOVE(u);
00081       return -1;
00082    }
00083 
00084    snprintf(eventname, sizeof(eventname), "UserEvent%s", info);
00085    eventbody = strchr(eventname, '|');
00086    if (eventbody) {
00087       *eventbody = '\0';
00088       eventbody++;
00089    }
00090    
00091    if(eventbody) {
00092             ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody);
00093             manager_event(EVENT_FLAG_USER, eventname, 
00094          "Channel: %s\r\nUniqueid: %s\r\n%s\r\n",
00095          chan->name, chan->uniqueid, eventbody);
00096    } else {
00097             ast_log(LOG_DEBUG, "Sending user event: %s\n", eventname);
00098             manager_event(EVENT_FLAG_USER, eventname, 
00099          "Channel: %s\r\nUniqueid: %s\r\n", chan->name, chan->uniqueid);
00100    }
00101 
00102    LOCAL_USER_REMOVE(u);
00103    return 0;
00104 }


Variable Documentation

char* app = "UserEvent" [static]
 

Definition at line 44 of file app_userevent.c.

Referenced by load_module(), and unload_module().

char* descrip [static]
 

Definition at line 48 of file app_userevent.c.

Referenced by load_module().

LOCAL_USER_DECL
 

Definition at line 61 of file app_userevent.c.

STANDARD_LOCAL_USER
 

Definition at line 59 of file app_userevent.c.

char* synopsis = "Send an arbitrary event to the manager interface" [static]
 

Definition at line 46 of file app_userevent.c.

Referenced by load_module().

char* tdesc = "Custom User Event Application" [static]
 

Definition at line 42 of file app_userevent.c.


Generated on Mon Mar 20 08:20:16 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1