Bridging: Allow channels to define bridging hooks

This patch allows the current owner of a channel to define various
feature hooks to be made available once the channel has entered a
bridge. This includes any hooks that are setup on the
ast_bridge_features struct such as DTMF hooks, bridge event hooks
(join, leave, etc.), and interval hooks.

Review: https://reviewboard.asterisk.org/r/3649/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417361 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kinsey Moore
2014-06-26 12:43:47 +00:00
parent 22e62ac6f6
commit e977b7936b
6 changed files with 506 additions and 1 deletions

View File

@@ -10453,3 +10453,71 @@ void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval s
ast_log(LOG_DTMF, "DTMF end '%c' simulated on %s due to %s, duration %ld ms\n",
digit, ast_channel_name(chan), why, duration);
}
static void features_destroy(void *obj)
{
ast_bridge_features_destroy(obj);
}
static const struct ast_datastore_info bridge_features_info = {
.type = "bridge-features",
.destroy = features_destroy,
};
struct ast_bridge_features *ast_channel_feature_hooks_get(struct ast_channel *chan)
{
struct ast_datastore *datastore;
datastore = ast_channel_datastore_find(chan, &bridge_features_info, NULL);
if (!datastore) {
return NULL;
}
return datastore->data;
}
static int channel_feature_hooks_set_full(struct ast_channel *chan, struct ast_bridge_features *features, int replace)
{
struct ast_datastore *datastore;
struct ast_bridge_features *ds_features;
datastore = ast_channel_datastore_find(chan, &bridge_features_info, NULL);
if (datastore) {
ds_features = datastore->data;
if (replace) {
ast_bridge_features_cleanup(ds_features);
ast_bridge_features_init(ds_features);
}
if (features) {
ast_bridge_features_merge(ds_features, features);
}
return 0;
}
datastore = ast_datastore_alloc(&bridge_features_info, NULL);
if (!datastore) {
return -1;
}
ds_features = ast_bridge_features_new();
if (!ds_features) {
ast_datastore_free(datastore);
return -1;
}
if (features) {
ast_bridge_features_merge(ds_features, features);
}
datastore->data = ds_features;
ast_channel_datastore_add(chan, datastore);
return 0;
}
int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features)
{
return channel_feature_hooks_set_full(chan, features, 0);
}
int ast_channel_feature_hooks_replace(struct ast_channel *chan, struct ast_bridge_features *features)
{
return channel_feature_hooks_set_full(chan, features, 1);
}