[asterisk-commits] jrose: branch jrose/bridge_projects r386542 - /team/jrose/bridge_projects/res...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 25 13:40:48 CDT 2013
Author: jrose
Date: Thu Apr 25 13:40:45 2013
New Revision: 386542
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386542
Log:
Clean up datastore code and start on the huge conversion to create parking spaces in the bridge push function
Modified:
team/jrose/bridge_projects/res/parking/parking_applications.c
team/jrose/bridge_projects/res/parking/parking_bridge_features.c
team/jrose/bridge_projects/res/parking/parking_controller.c
team/jrose/bridge_projects/res/parking/res_parking.h
Modified: team/jrose/bridge_projects/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_applications.c?view=diff&rev=386542&r1=386541&r2=386542
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_applications.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_applications.c Thu Apr 25 13:40:45 2013
@@ -221,6 +221,71 @@
return 0;
}
+struct ast_bridge *park_common_setup_blargfish(struct ast_channel *parkee, const char *parker_uuid, const char *app_data)
+{
+ int use_ringing = 0;
+ int randomize = 0;
+ int time_limit = -1;
+ char *lot_name;
+
+ int silence_announcements = 0;
+
+ struct ast_bridge *parking_bridge;
+ RAII_VAR(char *, comeback_override, NULL, ast_free);
+ RAII_VAR(char *, lot_name_app_arg, NULL, ast_free);
+ RAII_VAR(struct ast_channel *, parker, NULL, ao2_cleanup);
+ RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
+
+ /* Try to get the parker channel based on uuid. If that fails, we have a problem. */
+ parker = ast_channel_get_by_name(parker_uuid);
+
+ if (!parker) {
+ ast_log(LOG_NOTICE, "Could not find the alleged parker by uniqueid '%s' to park '%s'\n",
+ parker_uuid, ast_channel_name(parkee));
+ return NULL;
+ }
+
+ if (app_data) {
+ park_app_parse_data(app_data, &silence_announcements, &use_ringing, &randomize, &time_limit, &comeback_override, &lot_name_app_arg);
+ }
+
+ lot_name = lot_name_app_arg;
+
+ /* If the name of the aprking lot isn't specified in the arguments, find it based on the channel. */
+ if (ast_strlen_zero(lot_name)) {
+ ast_channel_lock(parker);
+ lot_name = ast_strdupa(find_channel_parking_lot_name(parker));
+ ast_channel_unlock(parker);
+
+ /* If the name couldn't be pulled from that either, use the default parking lot name. */
+ if (ast_strlen_zero(lot_name)) {
+ lot_name = DEFAULT_PARKING_LOT;
+ }
+ }
+
+ lot = parking_lot_find_by_name(lot_name);
+
+ if (!lot) {
+ ast_log(LOG_ERROR, "Could not find parking lot: '%s'\n", lot_name);
+ return NULL;
+ }
+
+ ao2_lock(lot);
+ parking_bridge = parking_lot_get_bridge(lot);
+ ao2_unlock(lot);
+
+ if (parking_bridge) {
+ /* Apply relevant bridge roles and such to the parking channel */
+ parking_channel_set_roles(parkee, lot, use_ringing);
+ return parking_bridge;
+ }
+
+
+
+ /* Couldn't get the parking bridge. Epic failure. */
+ return NULL;
+}
+
int park_common_setup(struct parking_lot **lot, struct ast_bridge **parking_bridge,
struct parked_user **pu, int *silence_announcements,
struct ast_channel *parker, struct ast_channel *parkee, const char *app_data)
@@ -235,6 +300,7 @@
/* parse the app data if we have it */
if (app_data) {
park_app_parse_data(app_data, silence_announcements, &use_ringing, &randomize, &time_limit, &comeback_override, &lot_name_app_arg);
+
}
lot_name = lot_name_app_arg;
Modified: team/jrose/bridge_projects/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_bridge_features.c?view=diff&rev=386542&r1=386541&r2=386542
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_bridge_features.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_bridge_features.c Thu Apr 25 13:40:45 2013
@@ -44,8 +44,8 @@
};
struct parked_subscription_data {
- const char *parker_uuid;
- const char *parkee_uuid;
+ char *parkee_uuid;
+ char parker_uuid[0];
};
static void parked_subscription_datastore_destroy(void *data)
@@ -136,31 +136,31 @@
}
}
-static struct parked_subscription_datastore *fetch_parked_subscription_datastore(struct ast_channel *chan)
-{
- struct ast_datastore *datastore = NULL;
+static void wipe_subscription_datastore(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore;
ast_channel_lock(chan);
- if (!(datastore = ast_channel_datastore_find(chan, &parked_subscription_info, NULL))) {
- ast_channel_unlock(chan);
- return NULL;
+
+ datastore = ast_channel_datastore_find(chan, &parked_subscription_info, NULL);
+ if (datastore) {
+ ast_channel_datastore_remove(chan, datastore);
+ ast_datastore_free(datastore);
}
ast_channel_unlock(chan);
- return datastore->data;
}
static int create_parked_subscription(struct ast_channel *chan, const char *parkee_uuid)
{
- struct ast_datastore *datastore = NULL;
+ struct ast_datastore *datastore;
struct parked_subscription_datastore *parked_datastore;
struct parked_subscription_data *subscription_data;
+ char *parker_uuid = ast_strdupa(ast_channel_uniqueid(chan));
+ size_t parker_uuid_size = strlen(parker_uuid) + 1;
+
/* If there is already a subscription, get rid of it. */
- if ((parked_datastore = fetch_parked_subscription_datastore(chan))) {
- stasis_unsubscribe(parked_datastore->parked_subscription);
- parked_datastore->parked_subscription = NULL;
- goto datastore_exists;
- }
+ wipe_subscription_datastore(chan);
if (!(datastore = ast_datastore_alloc(&parked_subscription_info, NULL))) {
return -1;
@@ -171,24 +171,20 @@
return -1;
}
-datastore_exists:
-
- if (!(subscription_data = ast_calloc(1, sizeof(*subscription_data))))
- {
+ if (!(subscription_data = ast_calloc(1, sizeof(*subscription_data) + parker_uuid_size + strlen(parkee_uuid) + 1))) {
ast_datastore_free(datastore);
ast_free(parked_datastore);
}
- subscription_data->parker_uuid = ast_strdup(ast_channel_uniqueid(chan));
- subscription_data->parkee_uuid = ast_strdup(parkee_uuid);
+ subscription_data->parkee_uuid = subscription_data->parker_uuid + parker_uuid_size;
+
+ strcpy(subscription_data->parkee_uuid, parkee_uuid);
+ strcpy(subscription_data->parker_uuid, parker_uuid);
if (!(parked_datastore->parked_subscription = stasis_subscribe(ast_parking_topic(), parker_update_cb, subscription_data)))
- /* If the parked_datastore already exists, there is no need to relink it. */
- if (datastore) {
- datastore->data = parked_datastore;
- ast_channel_datastore_add(chan, datastore);
- }
+ datastore->data = parked_datastore;
+ ast_channel_datastore_add(chan, datastore);
return 0;
}
Modified: team/jrose/bridge_projects/res/parking/parking_controller.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_controller.c?view=diff&rev=386542&r1=386541&r2=386542
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_controller.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_controller.c Thu Apr 25 13:40:45 2013
@@ -301,6 +301,56 @@
void reset_parked_time(struct parked_user *pu)
{
pu->start = ast_tvnow();
+}
+
+static void park_common_datastore_destroy(void *data)
+{
+ struct park_common_datastore *datastore = data;
+ ast_free(datastore->parker_uuid);
+}
+
+static const struct ast_datastore_info park_common_info = {
+ .type = "park entry data",
+ .destroy = park_common_datastore_destroy,
+};
+
+static void wipe_park_common_datastore(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore;
+
+ ast_channel_lock(chan);
+ datastore = ast_channel_datastore_find(chan, &park_common_info, NULL);
+ if (datastore) {
+ ast_channel_datastore_remove(chan, datastore);
+ ast_datastore_free(datastore);
+ }
+ ast_channel_unlock(chan);
+}
+
+int setup_park_common_datastore(struct ast_channel *parkee, const char *parker_uuid, int randomize, int time_limit)
+{
+ struct ast_datastore *datastore = NULL;
+ struct park_common_datastore *park_datastore;
+
+ wipe_park_common_datastore(parkee);
+
+ if (!(datastore = ast_datastore_alloc(&park_common_info, NULL))) {
+ return -1;
+ }
+
+ if (!(park_datastore = ast_calloc(1, sizeof(*park_datastore)))) {
+ ast_datastore_free(datastore);
+ return -1;
+ }
+
+ park_datastore->parker_uuid = ast_strdup(parker_uuid);
+ park_datastore->randomize = randomize;
+ park_datastore->time_limit = time_limit;
+
+ datastore->data = park_datastore;
+ ast_channel_datastore_add(parkee, datastore);
+
+ return 0;
}
struct parked_user *generate_parked_user(struct parking_lot *lot, struct ast_channel *chan, struct ast_channel *parker, int use_random_space, int time_limit)
Modified: team/jrose/bridge_projects/res/parking/res_parking.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/res_parking.h?view=diff&rev=386542&r1=386541&r2=386542
==============================================================================
--- team/jrose/bridge_projects/res/parking/res_parking.h (original)
+++ team/jrose/bridge_projects/res/parking/res_parking.h Thu Apr 25 13:40:45 2013
@@ -359,6 +359,16 @@
int park_common_setup(struct parking_lot **lot, struct ast_bridge **parking_bridge, struct parked_user **pu,
int *silence_announcements, struct ast_channel *parker, struct ast_channel *parkee, const char *app_data);
+struct ast_bridge *park_common_setup_blargfish(struct ast_channel *parkee, const char *parker_uuid, const char *app_data);
+
+struct park_common_datastore {
+ char *parker_uuid; /*!< Unique ID of the channel parking the call. */
+ int randomize; /*!< Pick a parking space to enter on at random */
+ int time_limit; /*!< time limit override. -1 values don't override, 0 for unlimited time, >0 for custom time limit in seconds */
+};
+
+int setup_park_common_datastore(struct ast_channel *parkee, const char *parker_uuid, int randomize, int time_limit);
+
/*!
* \since 12
* \brief Execution function for the parking application
More information about the asterisk-commits
mailing list