Wed Aug 15 01:25:33 2007

Asterisk developer's documentation


smdi.h File Reference

SMDI support for Asterisk. More...

#include <termios.h>
#include <time.h>
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/astobj.h"

Include dependency graph for smdi.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_smdi_interface
 SMDI interface structure. More...
struct  ast_smdi_md_message
 An SMDI message desk message. More...
struct  ast_smdi_md_queue
 SMDI message desk message queue. More...
struct  ast_smdi_mwi_message
 An SMDI message waiting indicator message. More...
struct  ast_smdi_mwi_queue
 SMDI message waiting indicator message queue. More...

Defines

#define SMDI_MAX_FILENAME_LEN   256
#define SMDI_MAX_STATION_NUM_LEN   10
#define SMDI_MESG_DESK_NUM_LEN   3
#define SMDI_MESG_DESK_TERM_LEN   4
#define SMDI_MWI_FAIL_CAUSE_LEN   3

Functions

void ast_smdi_interface_destroy (struct ast_smdi_interface *iface)
 ast_smdi_interface destructor.
struct
ast_smdi_interface
ast_smdi_interface_find (const char *iface_name)
 Find an SMDI interface with the specified name.
void ast_smdi_md_message_destroy (struct ast_smdi_md_message *msg)
 ast_smdi_md_message destructor.
struct
ast_smdi_md_message
ast_smdi_md_message_pop (struct ast_smdi_interface *iface)
 Get the next SMDI message from the queue.
void ast_smdi_md_message_putback (struct ast_smdi_interface *iface, struct ast_smdi_md_message *msg)
 Put an SMDI message back in the front of the queue.
struct
ast_smdi_md_message
ast_smdi_md_message_wait (struct ast_smdi_interface *iface, int timeout)
 Get the next SMDI message from the queue.
void ast_smdi_mwi_message_destroy (struct ast_smdi_mwi_message *msg)
 ast_smdi_mwi_message destructor.
struct
ast_smdi_mwi_message
ast_smdi_mwi_message_pop (struct ast_smdi_interface *iface)
 Get the next SMDI message from the queue.
void ast_smdi_mwi_message_putback (struct ast_smdi_interface *iface, struct ast_smdi_mwi_message *msg)
 Put an SMDI message back in the front of the queue.
struct
ast_smdi_mwi_message
ast_smdi_mwi_message_wait (struct ast_smdi_interface *iface, int timeout)
 Get the next SMDI message from the queue.
int ast_smdi_mwi_set (struct ast_smdi_interface *iface, const char *mailbox)
 Set the MWI indicator for a mailbox.
int ast_smdi_mwi_unset (struct ast_smdi_interface *iface, const char *mailbox)
 Unset the MWI indicator for a mailbox.


Detailed Description

SMDI support for Asterisk.

Author:
Matthew A. Nicholson <mnicholson@digium.com>

Definition in file smdi.h.


Define Documentation

#define SMDI_MAX_FILENAME_LEN   256

Definition at line 43 of file smdi.h.

#define SMDI_MAX_STATION_NUM_LEN   10

Definition at line 42 of file smdi.h.

Referenced by smdi_read().

#define SMDI_MESG_DESK_NUM_LEN   3

Definition at line 39 of file smdi.h.

Referenced by smdi_read().

#define SMDI_MESG_DESK_TERM_LEN   4

Definition at line 40 of file smdi.h.

Referenced by smdi_read().

#define SMDI_MWI_FAIL_CAUSE_LEN   3

Definition at line 41 of file smdi.h.

Referenced by smdi_read().


Function Documentation

void ast_smdi_interface_destroy ( struct ast_smdi_interface iface  ) 

ast_smdi_interface destructor.

Definition at line 486 of file res_smdi.c.

Referenced by destroy_zt_pvt(), smdi_load(), smdi_read(), and unload_module().

00487 {
00488    if (iface->thread != AST_PTHREADT_NULL && iface->thread != AST_PTHREADT_STOP) {
00489       pthread_cancel(iface->thread);
00490       pthread_join(iface->thread, NULL);
00491    }
00492    
00493    iface->thread = AST_PTHREADT_STOP;
00494    
00495    if(iface->file) 
00496       fclose(iface->file);
00497    
00498    ASTOBJ_CONTAINER_DESTROYALL(&iface->md_q, ast_smdi_md_message_destroy);
00499    ASTOBJ_CONTAINER_DESTROYALL(&iface->mwi_q, ast_smdi_mwi_message_destroy);
00500    ASTOBJ_CONTAINER_DESTROY(&iface->md_q);
00501    ASTOBJ_CONTAINER_DESTROY(&iface->mwi_q);
00502    free(iface);
00503 
00504    ast_module_unref(ast_module_info->self);
00505 }

struct ast_smdi_interface* ast_smdi_interface_find ( const char *  iface_name  )  [read]

Find an SMDI interface with the specified name.

Parameters:
iface_name the name/port of the interface to search for.
Returns:
a pointer to the interface located or NULL if none was found. This actually returns an ASTOBJ reference and should be released using ASTOBJ_UNREF(iface, ast_smdi_interface_destroy).

Definition at line 322 of file res_smdi.c.

Referenced by load_config(), and mkintf().

00323 {
00324    return (ASTOBJ_CONTAINER_FIND(&smdi_ifaces, iface_name));
00325 }

void ast_smdi_md_message_destroy ( struct ast_smdi_md_message msg  ) 

ast_smdi_md_message destructor.

Definition at line 474 of file res_smdi.c.

Referenced by ast_smdi_interface_destroy(), ast_smdi_md_message_pop(), smdi_read(), and ss_thread().

00475 {
00476    free(msg);
00477 }

struct ast_smdi_md_message* ast_smdi_md_message_pop ( struct ast_smdi_interface iface  )  [read]

Get the next SMDI message from the queue.

Parameters:
iface a pointer to the interface to use.
This function pulls the first unexpired message from the SMDI message queue on the specified interface. It will purge all expired SMDI messages before returning.

Returns:
the next SMDI message, or NULL if there were no pending messages.

Definition at line 188 of file res_smdi.c.

Referenced by ast_smdi_md_message_wait().

00189 {
00190    struct ast_smdi_md_message *md_msg = ASTOBJ_CONTAINER_UNLINK_START(&iface->md_q);
00191    struct timeval now;
00192    long elapsed = 0;
00193 
00194    /* purge old messages */
00195    now = ast_tvnow();
00196    while (md_msg) {
00197       elapsed = ast_tvdiff_ms(now, md_msg->timestamp);
00198 
00199       if (elapsed > iface->msg_expiry) {
00200          /* found an expired message */
00201          ASTOBJ_UNREF(md_msg, ast_smdi_md_message_destroy);
00202          ast_log(LOG_NOTICE, "Purged expired message from %s SMDI MD message queue.  Message was %ld milliseconds too old.\n",
00203             iface->name, elapsed - iface->msg_expiry);
00204          md_msg = ASTOBJ_CONTAINER_UNLINK_START(&iface->md_q);
00205       }
00206       else {
00207          /* good message, return it */
00208          break;
00209       }
00210    }
00211 
00212    return md_msg;
00213 }

void ast_smdi_md_message_putback ( struct ast_smdi_interface iface,
struct ast_smdi_md_message md_msg 
)

Put an SMDI message back in the front of the queue.

Parameters:
iface a pointer to the interface to use.
md_msg a pointer to the message to use.
This function puts a message back in the front of the specified queue. It should be used if a message was popped but is not going to be processed for some reason, and the message needs to be returned to the queue.

Definition at line 159 of file res_smdi.c.

00160 {
00161    ASTOBJ_CONTAINER_LINK_START(&iface->md_q, md_msg);
00162 }

struct ast_smdi_md_message* ast_smdi_md_message_wait ( struct ast_smdi_interface iface,
int  timeout 
) [read]

Get the next SMDI message from the queue.

Parameters:
iface a pointer to the interface to use.
timeout the time to wait before returning in milliseconds.
This function pulls a message from the SMDI message queue on the specified interface. If no message is available this function will wait the specified amount of time before returning.

Returns:
the next SMDI message, or NULL if there were no pending messages and the timeout has expired.

Definition at line 227 of file res_smdi.c.

Referenced by ss_thread().

00228 {
00229    struct timeval start;
00230    long diff = 0;
00231    struct ast_smdi_md_message *msg;
00232 
00233    start = ast_tvnow();
00234    while (diff < timeout) {
00235 
00236       if ((msg = ast_smdi_md_message_pop(iface)))
00237          return msg;
00238 
00239       /* check timeout */
00240       diff = ast_tvdiff_ms(ast_tvnow(), start);
00241    }
00242 
00243    return (ast_smdi_md_message_pop(iface));
00244 }

void ast_smdi_mwi_message_destroy ( struct ast_smdi_mwi_message msg  ) 

ast_smdi_mwi_message destructor.

Definition at line 480 of file res_smdi.c.

Referenced by ast_smdi_interface_destroy(), ast_smdi_mwi_message_pop(), run_externnotify(), and smdi_read().

00481 {
00482    free(msg);
00483 }

struct ast_smdi_mwi_message* ast_smdi_mwi_message_pop ( struct ast_smdi_interface iface  )  [read]

Get the next SMDI message from the queue.

Parameters:
iface a pointer to the interface to use.
This function pulls the first unexpired message from the SMDI message queue on the specified interface. It will purge all expired SMDI messages before returning.

Returns:
the next SMDI message, or NULL if there were no pending messages.

Definition at line 256 of file res_smdi.c.

Referenced by ast_smdi_mwi_message_wait().

00257 {
00258    struct ast_smdi_mwi_message *mwi_msg = ASTOBJ_CONTAINER_UNLINK_START(&iface->mwi_q);
00259    struct timeval now;
00260    long elapsed = 0;
00261 
00262    /* purge old messages */
00263    now = ast_tvnow();
00264    while (mwi_msg)   {
00265       elapsed = ast_tvdiff_ms(now, mwi_msg->timestamp);
00266 
00267       if (elapsed > iface->msg_expiry) {
00268          /* found an expired message */
00269          ASTOBJ_UNREF(mwi_msg, ast_smdi_mwi_message_destroy);
00270          ast_log(LOG_NOTICE, "Purged expired message from %s SMDI MWI message queue.  Message was %ld milliseconds too old.\n",
00271             iface->name, elapsed - iface->msg_expiry);
00272          mwi_msg = ASTOBJ_CONTAINER_UNLINK_START(&iface->mwi_q);
00273       }
00274       else {
00275          /* good message, return it */
00276          break;
00277       }
00278    }
00279 
00280    return mwi_msg;
00281 }

void ast_smdi_mwi_message_putback ( struct ast_smdi_interface iface,
struct ast_smdi_mwi_message mwi_msg 
)

Put an SMDI message back in the front of the queue.

Parameters:
iface a pointer to the interface to use.
mwi_msg a pointer to the message to use.
This function puts a message back in the front of the specified queue. It should be used if a message was popped but is not going to be processed for some reason, and the message needs to be returned to the queue.

Definition at line 173 of file res_smdi.c.

00174 {
00175    ASTOBJ_CONTAINER_LINK_START(&iface->mwi_q, mwi_msg);
00176 }

struct ast_smdi_mwi_message* ast_smdi_mwi_message_wait ( struct ast_smdi_interface iface,
int  timeout 
) [read]

Get the next SMDI message from the queue.

Parameters:
iface a pointer to the interface to use.
timeout the time to wait before returning in milliseconds.
This function pulls a message from the SMDI message queue on the specified interface. If no message is available this function will wait the specified amount of time before returning.

Returns:
the next SMDI message, or NULL if there were no pending messages and the timeout has expired.

Definition at line 295 of file res_smdi.c.

Referenced by run_externnotify().

00296 {
00297    struct timeval start;
00298    long diff = 0;
00299    struct ast_smdi_mwi_message *msg;
00300 
00301    start = ast_tvnow();
00302    while (diff < timeout) {
00303 
00304       if ((msg = ast_smdi_mwi_message_pop(iface)))
00305          return msg;
00306 
00307       /* check timeout */
00308       diff = ast_tvdiff_ms(ast_tvnow(), start);
00309    }
00310 
00311    return (ast_smdi_mwi_message_pop(iface));
00312 }

int ast_smdi_mwi_set ( struct ast_smdi_interface iface,
const char *  mailbox 
)

Set the MWI indicator for a mailbox.

Parameters:
iface the interface to use.
mailbox the mailbox to use.

Definition at line 93 of file res_smdi.c.

Referenced by run_externnotify().

00094 {
00095    FILE *file;
00096    int i;
00097    
00098    file = fopen(iface->name, "w");
00099    if(!file) {
00100       ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
00101       return 1;
00102    }  
00103 
00104    ASTOBJ_WRLOCK(iface);
00105 
00106    fprintf(file, "OP:MWI ");
00107 
00108    for(i = 0; i < iface->msdstrip; i++)
00109       fprintf(file, "0");
00110 
00111    fprintf(file, "%s!\x04", mailbox);
00112    fclose(file);
00113 
00114    ASTOBJ_UNLOCK(iface);
00115    ast_log(LOG_DEBUG, "Sent MWI set message for %s on %s\n", mailbox, iface->name);
00116    return 0;
00117 }

int ast_smdi_mwi_unset ( struct ast_smdi_interface iface,
const char *  mailbox 
)

Unset the MWI indicator for a mailbox.

Parameters:
iface the interface to use.
mailbox the mailbox to use.

Definition at line 124 of file res_smdi.c.

Referenced by run_externnotify().

00125 {
00126    FILE *file;
00127    int i;
00128    
00129    file = fopen(iface->name, "w");
00130    if(!file) {
00131       ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
00132       return 1;
00133    }  
00134 
00135    ASTOBJ_WRLOCK(iface);
00136 
00137    fprintf(file, "RMV:MWI ");
00138 
00139    for(i = 0; i < iface->msdstrip; i++)
00140       fprintf(file, "0");
00141 
00142    fprintf(file, "%s!\x04", mailbox);
00143    fclose(file);
00144 
00145    ASTOBJ_UNLOCK(iface);
00146    ast_log(LOG_DEBUG, "Sent MWI unset message for %s on %s\n", mailbox, iface->name);
00147    return 0;
00148 }


Generated on Wed Aug 15 01:25:33 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3