#include <termios.h>
#include <time.h>
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/astobj.h"
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. |
Definition in file smdi.h.
#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 |
void ast_smdi_interface_destroy | ( | struct ast_smdi_interface * | iface | ) |
ast_smdi_interface destructor.
Definition at line 486 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_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.
iface_name | the name/port of the interface to search for. |
Definition at line 322 of file res_smdi.c.
References ASTOBJ_CONTAINER_FIND, and smdi_ifaces.
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.
References free.
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.
iface | a pointer to the interface to use. |
Definition at line 188 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().
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.
iface | a pointer to the interface to use. | |
md_msg | a pointer to the message to use. |
Definition at line 159 of file res_smdi.c.
References ASTOBJ_CONTAINER_LINK_START, and ast_smdi_interface::md_q.
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.
iface | a pointer to the interface to use. | |
timeout | the time to wait before returning in milliseconds. |
Definition at line 227 of file res_smdi.c.
References ast_smdi_md_message_pop().
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.
References free.
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.
iface | a pointer to the interface to use. |
Definition at line 256 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().
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.
iface | a pointer to the interface to use. | |
mwi_msg | a pointer to the message to use. |
Definition at line 173 of file res_smdi.c.
References ASTOBJ_CONTAINER_LINK_START, and ast_smdi_interface::mwi_q.
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.
iface | a pointer to the interface to use. | |
timeout | the time to wait before returning in milliseconds. |
Definition at line 295 of file res_smdi.c.
References ast_smdi_mwi_message_pop().
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.
iface | the interface to use. | |
mailbox | the mailbox to use. |
Definition at line 93 of file res_smdi.c.
References ast_log(), ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, errno, file, LOG_DEBUG, LOG_ERROR, and ast_smdi_interface::msdstrip.
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.
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, errno, file, LOG_DEBUG, LOG_ERROR, and ast_smdi_interface::msdstrip.
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 }