00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2009, Digium, Inc. 00005 * 00006 * Joshua Colp <jcolp@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 Channel Bridging API 00021 * \author Joshua Colp <jcolp@digium.com> 00022 */ 00023 00024 #ifndef _ASTERISK_BRIDGING_FEATURES_H 00025 #define _ASTERISK_BRIDGING_FEATURES_H 00026 00027 #if defined(__cplusplus) || defined(c_plusplus) 00028 extern "C" { 00029 #endif 00030 00031 /*! \brief Flags used for bridge features */ 00032 enum ast_bridge_feature_flags { 00033 /*! Upon hangup the bridge should be discontinued */ 00034 AST_BRIDGE_FLAG_DISSOLVE = (1 << 0), 00035 /*! Move between bridging technologies as needed. */ 00036 AST_BRIDGE_FLAG_SMART = (1 << 1), 00037 }; 00038 00039 /*! \brief Built in features */ 00040 enum ast_bridge_builtin_feature { 00041 /*! DTMF Based Blind Transfer */ 00042 AST_BRIDGE_BUILTIN_BLINDTRANSFER = 0, 00043 /*! DTMF Based Attended Transfer */ 00044 AST_BRIDGE_BUILTIN_ATTENDEDTRANSFER, 00045 /*! DTMF Based Hangup Feature */ 00046 AST_BRIDGE_BUILTIN_HANGUP, 00047 /*! End terminator for list of built in features. Must remain last. */ 00048 AST_BRIDGE_BUILTIN_END, 00049 }; 00050 00051 struct ast_bridge; 00052 struct ast_bridge_channel; 00053 00054 /*! 00055 * \brief Features hook callback type 00056 * 00057 * \param bridge The bridge that the channel is part of 00058 * \param bridge_channel Channel executing the feature 00059 * \param hook_pvt Private data passed in when the hook was created 00060 * 00061 * \retval 0 success 00062 * \retval -1 failure 00063 */ 00064 typedef int (*ast_bridge_features_hook_callback)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt); 00065 00066 /*! 00067 * \brief Features hook pvt destructor callback 00068 * 00069 * \param hook_pvt Private data passed in when the hook was create to destroy 00070 */ 00071 typedef void (*ast_bridge_features_hook_pvt_destructor)(void *hook_pvt); 00072 00073 /*! 00074 * \brief Talking indicator callback 00075 * 00076 * \details This callback can be registered with the bridge in order 00077 * to receive updates on when a bridge_channel has started and stopped 00078 * talking 00079 * 00080 * \param bridge The bridge that the channel is part of 00081 * \param bridge_channel Channel executing the feature 00082 * 00083 * \retval 0 success 00084 * \retval -1 failure 00085 */ 00086 typedef void (*ast_bridge_talking_indicate_callback)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *pvt_data); 00087 00088 00089 typedef void (*ast_bridge_talking_indicate_destructor)(void *pvt_data); 00090 00091 /*! 00092 * \brief Maximum length of a DTMF feature string 00093 */ 00094 #define MAXIMUM_DTMF_FEATURE_STRING 8 00095 00096 /*! 00097 * \brief Structure that is the essence of a features hook 00098 */ 00099 struct ast_bridge_features_hook { 00100 /*! DTMF String that is examined during a feature hook lookup */ 00101 char dtmf[MAXIMUM_DTMF_FEATURE_STRING]; 00102 /*! Callback that is called when DTMF string is matched */ 00103 ast_bridge_features_hook_callback callback; 00104 /*! Callback to destroy hook_pvt data right before destruction. */ 00105 ast_bridge_features_hook_pvt_destructor destructor; 00106 /*! Unique data that was passed into us */ 00107 void *hook_pvt; 00108 /*! Linked list information */ 00109 AST_LIST_ENTRY(ast_bridge_features_hook) entry; 00110 }; 00111 00112 /*! 00113 * \brief Structure that contains features information 00114 */ 00115 struct ast_bridge_features { 00116 /*! Attached DTMF based feature hooks */ 00117 AST_LIST_HEAD_NOLOCK(, ast_bridge_features_hook) hooks; 00118 /*! Callback to indicate when a bridge channel has started and stopped talking */ 00119 ast_bridge_talking_indicate_callback talker_cb; 00120 /*! Callback to destroy any pvt data stored for the talker. */ 00121 ast_bridge_talking_indicate_destructor talker_destructor_cb; 00122 /*! Talker callback pvt data */ 00123 void *talker_pvt_data; 00124 /*! Feature flags that are enabled */ 00125 struct ast_flags feature_flags; 00126 /*! Bit to indicate that the hook list is useful and should be considered when looking for DTMF features */ 00127 unsigned int usable:1; 00128 /*! Bit to indicate whether the channel/bridge is muted or not */ 00129 unsigned int mute:1; 00130 /*! Bit to indicate whether DTMF should be passed into the bridge tech or not. */ 00131 unsigned int dtmf_passthrough:1; 00132 00133 }; 00134 00135 /*! 00136 * \brief Structure that contains configuration information for the blind transfer built in feature 00137 */ 00138 struct ast_bridge_features_blind_transfer { 00139 /*! Context to use for transfers */ 00140 char context[AST_MAX_CONTEXT]; 00141 }; 00142 00143 /*! 00144 * \brief Structure that contains configuration information for the attended transfer built in feature 00145 */ 00146 struct ast_bridge_features_attended_transfer { 00147 /*! DTMF string used to abort the transfer */ 00148 char abort[MAXIMUM_DTMF_FEATURE_STRING]; 00149 /*! DTMF string used to turn the transfer into a three way conference */ 00150 char threeway[MAXIMUM_DTMF_FEATURE_STRING]; 00151 /*! DTMF string used to complete the transfer */ 00152 char complete[MAXIMUM_DTMF_FEATURE_STRING]; 00153 /*! Context to use for transfers */ 00154 char context[AST_MAX_CONTEXT]; 00155 }; 00156 00157 /*! \brief Register a handler for a built in feature 00158 * 00159 * \param feature The feature that the handler will be responsible for 00160 * \param callback The callback function that will handle it 00161 * \param dtmf Default DTMF string used to activate the feature 00162 * 00163 * \retval 0 on success 00164 * \retval -1 on failure 00165 * 00166 * Example usage: 00167 * 00168 * \code 00169 * ast_bridge_features_register(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER, bridge_builtin_attended_transfer, "*1"); 00170 * \endcode 00171 * 00172 * This registers the function bridge_builtin_attended_transfer as the function responsible for the built in 00173 * attended transfer feature. 00174 */ 00175 int ast_bridge_features_register(enum ast_bridge_builtin_feature feature, ast_bridge_features_hook_callback callback, const char *dtmf); 00176 00177 /*! \brief Unregister a handler for a built in feature 00178 * 00179 * \param feature The feature to unregister 00180 * 00181 * \retval 0 on success 00182 * \retval -1 on failure 00183 * 00184 * Example usage: 00185 * 00186 * \code 00187 * ast_bridge_features_unregister(AST_BRIDGE_BUILTIN_ATTENDED_TRANSFER); 00188 * \endcode 00189 * 00190 * This unregisters the function that is handling the built in attended transfer feature. 00191 */ 00192 int ast_bridge_features_unregister(enum ast_bridge_builtin_feature feature); 00193 00194 /*! \brief Attach a custom hook to a bridge features structure 00195 * 00196 * \param features Bridge features structure 00197 * \param dtmf DTMF string to be activated upon 00198 * \param callback Function to execute upon activation 00199 * \param hook_pvt Unique data 00200 * \param Optional destructor callback for hook_pvt data 00201 * 00202 * \retval 0 on success 00203 * \retval -1 on failure 00204 * 00205 * Example usage: 00206 * 00207 * \code 00208 * struct ast_bridge_features features; 00209 * ast_bridge_features_init(&features); 00210 * ast_bridge_features_hook(&features, "#", pound_callback, NULL, NULL); 00211 * \endcode 00212 * 00213 * This makes the bridging core call pound_callback if a channel that has this 00214 * feature structure inputs the DTMF string '#'. A pointer to useful data may be 00215 * provided to the hook_pvt parameter. 00216 * 00217 * \note It is important that the callback set the bridge channel state back to 00218 * AST_BRIDGE_CHANNEL_STATE_WAIT or the bridge thread will not service the channel. 00219 */ 00220 int ast_bridge_features_hook(struct ast_bridge_features *features, 00221 const char *dtmf, 00222 ast_bridge_features_hook_callback callback, 00223 void *hook_pvt, 00224 ast_bridge_features_hook_pvt_destructor destructor); 00225 00226 /*! \brief Set a callback on the features structure to receive talking notifications on. 00227 * 00228 * \param features Bridge features structure 00229 * \param talker_cb, Callback function to execute when talking events occur in the bridge core. 00230 * \param pvt_data Optional unique data that will be passed with the talking events. 00231 * \param Optional destructor callback for pvt data. 00232 * 00233 * \retval 0, success 00234 * \retval -1, failure 00235 */ 00236 int ast_bridge_features_set_talk_detector(struct ast_bridge_features *features, 00237 ast_bridge_talking_indicate_callback talker_cb, 00238 ast_bridge_talking_indicate_destructor talker_destructor, 00239 void *pvt_data); 00240 00241 /*! \brief Enable a built in feature on a bridge features structure 00242 * 00243 * \param features Bridge features structure 00244 * \param feature Feature to enable 00245 * \param dtmf Optionally the DTMF stream to trigger the feature, if not specified it will be the default 00246 * \param config Configuration structure unique to the built in type 00247 * 00248 * \retval 0 on success 00249 * \retval -1 on failure 00250 * 00251 * Example usage: 00252 * 00253 * \code 00254 * struct ast_bridge_features features; 00255 * ast_bridge_features_init(&features); 00256 * ast_bridge_features_enable(&features, AST_BRIDGE_BUILTIN_ATTENDEDTRANSFER, NULL); 00257 * \endcode 00258 * 00259 * This enables the attended transfer DTMF option using the default DTMF string. An alternate 00260 * string may be provided using the dtmf parameter. Internally this is simply setting up a hook 00261 * to a built in feature callback function. 00262 */ 00263 int ast_bridge_features_enable(struct ast_bridge_features *features, enum ast_bridge_builtin_feature feature, const char *dtmf, void *config); 00264 00265 /*! \brief Set a flag on a bridge features structure 00266 * 00267 * \param features Bridge features structure 00268 * \param flag Flag to enable 00269 * 00270 * \retval 0 on success 00271 * \retval -1 on failure 00272 * 00273 * Example usage: 00274 * 00275 * \code 00276 * struct ast_bridge_features features; 00277 * ast_bridge_features_init(&features); 00278 * ast_bridge_features_set_flag(&features, AST_BRIDGE_FLAG_DISSOLVE); 00279 * \endcode 00280 * 00281 * This sets the AST_BRIDGE_FLAG_DISSOLVE feature to be enabled on the features structure 00282 * 'features'. 00283 */ 00284 int ast_bridge_features_set_flag(struct ast_bridge_features *features, enum ast_bridge_feature_flags flag); 00285 00286 /*! \brief Initialize bridge features structure 00287 * 00288 * \param features Bridge featues structure 00289 * 00290 * \retval 0 on success 00291 * \retval -1 on failure 00292 * 00293 * Example usage: 00294 * 00295 * \code 00296 * struct ast_bridge_features features; 00297 * ast_bridge_features_init(&features); 00298 * \endcode 00299 * 00300 * This initializes the feature structure 'features' to have nothing enabled. 00301 * 00302 * \note This MUST be called before enabling features or flags. Failure to do so 00303 * may result in a crash. 00304 */ 00305 int ast_bridge_features_init(struct ast_bridge_features *features); 00306 00307 /*! \brief Clean up the contents of a bridge features structure 00308 * 00309 * \param features Bridge features structure 00310 * 00311 * \retval 0 on success 00312 * \retval -1 on failure 00313 * 00314 * Example usage: 00315 * 00316 * \code 00317 * struct ast_bridge_features features; 00318 * ast_bridge_features_init(&features); 00319 * ast_bridge_features_cleanup(&features); 00320 * \endcode 00321 * 00322 * This cleans up the feature structure 'features'. 00323 * 00324 * \note This MUST be called after the features structure is done being used 00325 * or a memory leak may occur. 00326 */ 00327 int ast_bridge_features_cleanup(struct ast_bridge_features *features); 00328 00329 /*! \brief Play a DTMF stream into a bridge, optionally not to a given channel 00330 * 00331 * \param bridge Bridge to play stream into 00332 * \param dtmf DTMF to play 00333 * \param chan Channel to optionally not play to 00334 * 00335 * \retval 0 on success 00336 * \retval -1 on failure 00337 * 00338 * Example usage: 00339 * 00340 * \code 00341 * ast_bridge_dtmf_stream(bridge, "0123456789", NULL); 00342 * \endcode 00343 * 00344 * This sends the DTMF digits '0123456789' to all channels in the bridge pointed to 00345 * by the bridge pointer. Optionally a channel may be excluded by passing it's channel pointer 00346 * using the chan parameter. 00347 */ 00348 int ast_bridge_dtmf_stream(struct ast_bridge *bridge, const char *dtmf, struct ast_channel *chan); 00349 00350 #if defined(__cplusplus) || defined(c_plusplus) 00351 } 00352 #endif 00353 00354 #endif /* _ASTERISK_BRIDGING_FEATURES_H */