Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:56 2007

Asterisk developer's documentation :: Codename Pineapple


smdi.h File Reference


Detailed Description

SMDI support for Asterisk.

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

Definition in file smdi.h.

#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.
ast_smdi_interfaceast_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.
ast_smdi_md_messageast_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.
ast_smdi_md_messageast_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.
ast_smdi_mwi_messageast_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.
ast_smdi_mwi_messageast_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.


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.


Function Documentation

void ast_smdi_interface_destroy struct ast_smdi_interface iface  ) 
 

ast_smdi_interface destructor.

Definition at line 489 of file res_smdi.c.

References ast_module_unref(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_smdi_md_message_destroy(), ast_smdi_mwi_message_destroy(), ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, ast_smdi_interface::file, free, ast_smdi_interface::md_q, ast_smdi_interface::mwi_q, and ast_smdi_interface::thread.

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

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

struct ast_smdi_interface* ast_smdi_interface_find const char *  iface_name  ) 
 

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 323 of file res_smdi.c.

References ASTOBJ_CONTAINER_FIND, and smdi_ifaces.

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

void ast_smdi_md_message_destroy struct ast_smdi_md_message msg  ) 
 

ast_smdi_md_message destructor.

Definition at line 477 of file res_smdi.c.

References free.

Referenced by ast_smdi_interface_destroy(), and ast_smdi_md_message_pop().

00478 {
00479    free(msg);
00480 }

struct ast_smdi_md_message* ast_smdi_md_message_pop struct ast_smdi_interface iface  ) 
 

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 189 of file res_smdi.c.

References ast_log(), ast_smdi_md_message_destroy(), ASTOBJ_CONTAINER_UNLINK_START, ASTOBJ_UNREF, LOG_NOTICE, ast_smdi_interface::md_q, ast_smdi_interface::msg_expiry, and ast_smdi_md_message::timestamp.

Referenced by ast_smdi_md_message_wait().

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

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 160 of file res_smdi.c.

References ASTOBJ_CONTAINER_LINK_START, and ast_smdi_interface::md_q.

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

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.

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 228 of file res_smdi.c.

References ast_smdi_md_message_pop().

Referenced by ss_thread().

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

void ast_smdi_mwi_message_destroy struct ast_smdi_mwi_message msg  ) 
 

ast_smdi_mwi_message destructor.

Definition at line 483 of file res_smdi.c.

References free.

Referenced by ast_smdi_interface_destroy(), and ast_smdi_mwi_message_pop().

00484 {
00485    free(msg);
00486 }

struct ast_smdi_mwi_message* ast_smdi_mwi_message_pop struct ast_smdi_interface iface  ) 
 

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 257 of file res_smdi.c.

References ast_log(), ast_smdi_mwi_message_destroy(), ASTOBJ_CONTAINER_UNLINK_START, ASTOBJ_UNREF, LOG_NOTICE, ast_smdi_interface::msg_expiry, ast_smdi_interface::mwi_q, and ast_smdi_mwi_message::timestamp.

Referenced by ast_smdi_mwi_message_wait().

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

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 174 of file res_smdi.c.

References ASTOBJ_CONTAINER_LINK_START, and ast_smdi_interface::mwi_q.

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

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.

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 296 of file res_smdi.c.

References ast_smdi_mwi_message_pop().

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

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 92 of file res_smdi.c.

References ast_log(), ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, file, LOG_DEBUG, LOG_ERROR, ast_smdi_interface::msdstrip, and option_debug.

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

References ast_log(), ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, file, LOG_DEBUG, LOG_ERROR, ast_smdi_interface::msdstrip, and option_debug.

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    if (option_debug)
00147       ast_log(LOG_DEBUG, "Sent MWI unset message for %s on %s\n", mailbox, iface->name);
00148    return 0;
00149 }


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen