adsi.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2012, Digium, Inc.
00005  *
00006  * Mark Michelson <mmichelson@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief ADSI Support (built upon Caller*ID)
00021  */
00022 
00023 #include "asterisk.h"
00024 
00025 #include "asterisk/adsi.h"
00026 #include "asterisk/lock.h"
00027 
00028 static const struct adsi_funcs *installed_funcs;
00029 static const int current_adsi_version = AST_ADSI_VERSION;
00030 AST_RWLOCK_DEFINE_STATIC(func_lock);
00031 
00032 int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
00033 {
00034    int res = 0;
00035    ast_rwlock_rdlock(&func_lock);
00036    if (installed_funcs && installed_funcs->begin_download) {
00037       res = installed_funcs->begin_download(chan, service, fdn, sec, version);
00038    }
00039    ast_rwlock_unlock(&func_lock);
00040    return res;
00041 }
00042 
00043 int ast_adsi_end_download(struct ast_channel *chan)
00044 {
00045    int res = 0;
00046    ast_rwlock_rdlock(&func_lock);
00047    if (installed_funcs && installed_funcs->end_download) {
00048       res = installed_funcs->end_download(chan);
00049    }
00050    ast_rwlock_unlock(&func_lock);
00051    return res;
00052 }
00053 
00054 int ast_adsi_channel_restore(struct ast_channel *chan)
00055 {
00056    int res = 0;
00057    ast_rwlock_rdlock(&func_lock);
00058    if (installed_funcs && installed_funcs->channel_restore) {
00059       res = installed_funcs->channel_restore(chan);
00060    }
00061    ast_rwlock_unlock(&func_lock);
00062    return res;
00063 }
00064 
00065 int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice)
00066 {
00067    int res = 0;
00068    ast_rwlock_rdlock(&func_lock);
00069    if (installed_funcs && installed_funcs->print) {
00070       res = installed_funcs->print(chan, lines, align, voice);
00071    }
00072    ast_rwlock_unlock(&func_lock);
00073    return res;
00074 }
00075 
00076 int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
00077 {
00078    int res = 0;
00079    ast_rwlock_rdlock(&func_lock);
00080    if (installed_funcs && installed_funcs->load_session) {
00081       res = installed_funcs->load_session(chan, app, ver, data);
00082    }
00083    ast_rwlock_unlock(&func_lock);
00084    return res;
00085 }
00086 
00087 int ast_adsi_unload_session(struct ast_channel *chan)
00088 {
00089    int res = 0;
00090    ast_rwlock_rdlock(&func_lock);
00091    if (installed_funcs && installed_funcs->unload_session) {
00092       res = installed_funcs->unload_session(chan);
00093    }
00094    ast_rwlock_unlock(&func_lock);
00095    return res;
00096 }
00097 
00098 int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
00099 {
00100    int res = 0;
00101    ast_rwlock_rdlock(&func_lock);
00102    if (installed_funcs && installed_funcs->transmit_message) {
00103       res = installed_funcs->transmit_message(chan, msg, msglen, msgtype);
00104    }
00105    ast_rwlock_unlock(&func_lock);
00106    return res;
00107 }
00108 
00109 int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
00110 {
00111    int res = 0;
00112    ast_rwlock_rdlock(&func_lock);
00113    if (installed_funcs && installed_funcs->transmit_message_full) {
00114       res = installed_funcs->transmit_message_full(chan, msg, msglen, msgtype, dowait);
00115    }
00116    ast_rwlock_unlock(&func_lock);
00117    return res;
00118 }
00119 
00120 int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
00121 {
00122    int res = 0;
00123    ast_rwlock_rdlock(&func_lock);
00124    if (installed_funcs && installed_funcs->read_encoded_dtmf) {
00125       res = installed_funcs->read_encoded_dtmf(chan, buf, maxlen);
00126    }
00127    ast_rwlock_unlock(&func_lock);
00128    return res;
00129 }
00130 
00131 int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
00132 {
00133    int res = 0;
00134    ast_rwlock_rdlock(&func_lock);
00135    if (installed_funcs && installed_funcs->connect_session) {
00136       res = installed_funcs->connect_session(buf, fdn, ver);
00137    }
00138    ast_rwlock_unlock(&func_lock);
00139    return res;
00140 }
00141 
00142 int ast_adsi_query_cpeid(unsigned char *buf)
00143 {
00144    int res = 0;
00145    ast_rwlock_rdlock(&func_lock);
00146    if (installed_funcs && installed_funcs->query_cpeid) {
00147       res = installed_funcs->query_cpeid(buf);
00148    }
00149    ast_rwlock_unlock(&func_lock);
00150    return res;
00151 }
00152 
00153 int ast_adsi_query_cpeinfo(unsigned char *buf)
00154 {
00155    int res = 0;
00156    ast_rwlock_rdlock(&func_lock);
00157    if (installed_funcs && installed_funcs->query_cpeinfo) {
00158       res = installed_funcs->query_cpeinfo(buf);
00159    }
00160    ast_rwlock_unlock(&func_lock);
00161    return res;
00162 }
00163 
00164 int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
00165 {
00166    int res = 0;
00167    ast_rwlock_rdlock(&func_lock);
00168    if (installed_funcs && installed_funcs->get_cpeid) {
00169       res = installed_funcs->get_cpeid(chan, cpeid, voice);
00170    }
00171    ast_rwlock_unlock(&func_lock);
00172    return res;
00173 }
00174 
00175 int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
00176 {
00177    int res = 0;
00178    ast_rwlock_rdlock(&func_lock);
00179    if (installed_funcs && installed_funcs->get_cpeinfo) {
00180       res = installed_funcs->get_cpeinfo(chan, width, height, buttons, voice);
00181    }
00182    ast_rwlock_unlock(&func_lock);
00183    return res;
00184 }
00185 
00186 int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
00187 {
00188    int res = 0;
00189    ast_rwlock_rdlock(&func_lock);
00190    if (installed_funcs && installed_funcs->download_connect) {
00191       res = installed_funcs->download_connect(buf, service, fdn, sec, ver);
00192    }
00193    ast_rwlock_unlock(&func_lock);
00194    return res;
00195 }
00196 
00197 int ast_adsi_disconnect_session(unsigned char *buf)
00198 {
00199    int res = 0;
00200    ast_rwlock_rdlock(&func_lock);
00201    if (installed_funcs && installed_funcs->disconnect_session) {
00202       res = installed_funcs->disconnect_session(buf);
00203    }
00204    ast_rwlock_unlock(&func_lock);
00205    return res;
00206 }
00207 
00208 int ast_adsi_download_disconnect(unsigned char *buf)
00209 {
00210    int res = 0;
00211    ast_rwlock_rdlock(&func_lock);
00212    if (installed_funcs && installed_funcs->download_disconnect) {
00213       res = installed_funcs->download_disconnect(buf);
00214    }
00215    ast_rwlock_unlock(&func_lock);
00216    return res;
00217 }
00218 
00219 int ast_adsi_data_mode(unsigned char *buf)
00220 {
00221    int res = 0;
00222    ast_rwlock_rdlock(&func_lock);
00223    if (installed_funcs && installed_funcs->data_mode) {
00224       res = installed_funcs->data_mode(buf);
00225    }
00226    ast_rwlock_unlock(&func_lock);
00227    return res;
00228 }
00229 
00230 int ast_adsi_clear_soft_keys(unsigned char *buf)
00231 {
00232    int res = 0;
00233    ast_rwlock_rdlock(&func_lock);
00234    if (installed_funcs && installed_funcs->clear_soft_keys) {
00235       res = installed_funcs->clear_soft_keys(buf);
00236    }
00237    ast_rwlock_unlock(&func_lock);
00238    return res;
00239 }
00240 
00241 int ast_adsi_clear_screen(unsigned char *buf)
00242 {
00243    int res = 0;
00244    ast_rwlock_rdlock(&func_lock);
00245    if (installed_funcs && installed_funcs->clear_screen) {
00246       res = installed_funcs->clear_screen(buf);
00247    }
00248    ast_rwlock_unlock(&func_lock);
00249    return res;
00250 }
00251 
00252 int ast_adsi_voice_mode(unsigned char *buf, int when)
00253 {
00254    int res = 0;
00255    ast_rwlock_rdlock(&func_lock);
00256    if (installed_funcs && installed_funcs->voice_mode) {
00257       res = installed_funcs->voice_mode(buf, when);
00258    }
00259    ast_rwlock_unlock(&func_lock);
00260    return res;
00261 }
00262 
00263 int ast_adsi_available(struct ast_channel *chan)
00264 {
00265    int res = 0;
00266    ast_rwlock_rdlock(&func_lock);
00267    if (installed_funcs && installed_funcs->available) {
00268       res = installed_funcs->available(chan);
00269    }
00270    ast_rwlock_unlock(&func_lock);
00271    return res;
00272 }
00273 
00274 int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
00275 {
00276    int res = 0;
00277    ast_rwlock_rdlock(&func_lock);
00278    if (installed_funcs && installed_funcs->display) {
00279       res = installed_funcs->display(buf, page, line, just, wrap, col1, col2);
00280    }
00281    ast_rwlock_unlock(&func_lock);
00282    return res;
00283 }
00284 
00285 int ast_adsi_set_line(unsigned char *buf, int page, int line)
00286 {
00287    int res = 0;
00288    ast_rwlock_rdlock(&func_lock);
00289    if (installed_funcs && installed_funcs->set_line) {
00290       res = installed_funcs->set_line(buf, page, line);
00291    }
00292    ast_rwlock_unlock(&func_lock);
00293    return res;
00294 }
00295 
00296 int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
00297 {
00298    int res = 0;
00299    ast_rwlock_rdlock(&func_lock);
00300    if (installed_funcs && installed_funcs->load_soft_key) {
00301       res = installed_funcs->load_soft_key(buf, key, llabel, slabel, ret, data);
00302    }
00303    ast_rwlock_unlock(&func_lock);
00304    return res;
00305 }
00306 
00307 int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
00308 {
00309    int res = 0;
00310    ast_rwlock_rdlock(&func_lock);
00311    if (installed_funcs && installed_funcs->set_keys) {
00312       res = installed_funcs->set_keys(buf, keys);
00313    }
00314    ast_rwlock_unlock(&func_lock);
00315    return res;
00316 }
00317 
00318 int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
00319 {
00320    int res = 0;
00321    ast_rwlock_rdlock(&func_lock);
00322    if (installed_funcs && installed_funcs->input_control) {
00323       res = installed_funcs->input_control(buf, page, line, display, format, just);
00324    }
00325    ast_rwlock_unlock(&func_lock);
00326    return res;
00327 }
00328 
00329 int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
00330 {
00331    int res = 0;
00332    ast_rwlock_rdlock(&func_lock);
00333    if (installed_funcs && installed_funcs->input_format) {
00334       res = installed_funcs->input_format(buf, num, dir, wrap, format1, format2);
00335    }
00336    ast_rwlock_unlock(&func_lock);
00337    return res;
00338 }
00339 
00340 void ast_adsi_install_funcs(const struct adsi_funcs *funcs)
00341 {
00342    if (funcs && funcs->version < current_adsi_version) {
00343       ast_log(LOG_WARNING, "Cannot install ADSI function pointers due to version mismatch."
00344             "Ours: %d, Theirs: %u\n", current_adsi_version, funcs->version);
00345       return;
00346    }
00347 
00348    ast_rwlock_wrlock(&func_lock);
00349    installed_funcs = funcs;
00350    ast_rwlock_unlock(&func_lock);
00351 }

Generated on Thu Apr 16 06:27:06 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6