Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:01 2009

## Asterisk developer's documentation

# app_datetime.c File Reference

Time of day - Report the time of day. More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <string.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/say.h"`

Include dependency graph for app_datetime.c:

Go to the source code of this file.

## Functions

static int | datetime_exec (struct ast_channel *chan, void *data)
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.

## Variables

static char * | app = "DateTime"
static char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Say the date and time"
static char * | tdesc = "Date and Time"

## Detailed Description

Time of day - Report the time of day.

Definition in file app_datetime.c.

## Function Documentation

static int datetime_exec | ( | struct ast_channel * | chan,
|  | void * | data |
| ) |  |  | `[static]`

Definition at line 55 of file app_datetime.c.

References ast_channel::_state, ast_answer(), ast_say_datetime(), AST_STATE_UP, ast_channel::language, LOCAL_USER_ADD, LOCAL_USER_REMOVE, and t.

Referenced by load_module().

    00056 {
    00057    int res=0;
    00058    time_t t;
    00059    struct localuser *u;
    00060    LOCAL_USER_ADD(u);
    00061    time(&t);
    00062    if (chan->_state != AST_STATE_UP)
    00063       res = ast_answer(chan);
    00064    if (!res)
    00065       res = ast_say_datetime(chan, t, "", chan->language);
    00066    LOCAL_USER_REMOVE(u);
    00067    return res;
    00068 }

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 86 of file app_datetime.c.

    00087 {
    00088    return tdesc;
    00089 }

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 98 of file app_datetime.c.

References ASTERISK_GPL_KEY.

    00099 {
    00100    return ASTERISK_GPL_KEY;
    00101 }

int load_module | ( | void |  | ) |

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
  This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.

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.

TE STUFF END

Definition at line 81 of file app_datetime.c.

References ast_register_application(), and datetime_exec().

    00082 {
    00083    return ast_register_application(app, datetime_exec, synopsis, descrip);
    00084 }

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 70 of file app_datetime.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00071 {
    00072    int res;
    00073
    00074    res = ast_unregister_application(app);
    00075
    00076    STANDARD_HANGUP_LOCALUSERS;
    00077
    00078    return res;
    00079 }

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 91 of file app_datetime.c.

References STANDARD_USECOUNT.

    00092 {
    00093    int res;
    00094    STANDARD_USECOUNT(res);
    00095    return res;
    00096 }

## Variable Documentation

char* app = "DateTime"`[static]`

Definition at line 44 of file app_datetime.c.

char* descrip`[static]`

Initial value:

    "  DateTime(): This application will say the current date and time.\n"

Definition at line 48 of file app_datetime.c.

LOCAL_USER_DECL

Definition at line 53 of file app_datetime.c.

STANDARD_LOCAL_USER

Definition at line 51 of file app_datetime.c.

char* synopsis = "Say the date and time"`[static]`

Definition at line 46 of file app_datetime.c.

char* tdesc = "Date and Time"`[static]`

Definition at line 42 of file app_datetime.c.