From 50ff1f5fc19f4251cabc8733755e12aba1d673c4 Mon Sep 17 00:00:00 2001 From: Jonathan Rose Date: Fri, 28 Jun 2013 19:22:16 +0000 Subject: res_parking: Dynamic Parking Lots (closes issue ASTERISK-21644) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2615/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393197 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/parking/parking_applications.c | 8 ++++++++ res/parking/parking_ui.c | 10 ++++++++++ res/parking/res_parking.h | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) (limited to 'res/parking') diff --git a/res/parking/parking_applications.c b/res/parking/parking_applications.c index 2b921259f..eceeaca18 100644 --- a/res/parking/parking_applications.c +++ b/res/parking/parking_applications.c @@ -390,6 +390,9 @@ struct ast_bridge *park_common_setup(struct ast_channel *parkee, struct ast_chan } lot = parking_lot_find_by_name(lot_name); + if (!lot) { + lot = parking_create_dynamic_lot(lot_name, parkee); + } if (!lot) { ast_log(LOG_ERROR, "Could not find parking lot: '%s'\n", lot_name); @@ -451,6 +454,11 @@ int park_app_exec(struct ast_channel *chan, const char *data) int silence_announcements = 0; const char *blind_transfer; + /* Answer the channel if needed */ + if (ast_channel_state(chan) != AST_STATE_UP) { + ast_answer(chan); + } + ast_channel_lock(chan); if ((blind_transfer = pbx_builtin_getvar_helper(chan, "BLINDTRANSFER"))) { blind_transfer = ast_strdupa(blind_transfer); diff --git a/res/parking/parking_ui.c b/res/parking/parking_ui.c index 5b432b689..f3eeafa4c 100644 --- a/res/parking/parking_ui.c +++ b/res/parking/parking_ui.c @@ -66,6 +66,7 @@ static void display_parking_lot(struct parking_lot *lot, int fd) ast_cli(fd, "Comeback Dial Time : %u sec\n", lot->cfg->comebackdialtime); ast_cli(fd, "MusicOnHold Class : %s\n", lot->cfg->mohclass); ast_cli(fd, "Enabled : %s\n", (lot->mode == PARKINGLOT_DISABLED) ? "no" : "yes"); + ast_cli(fd, "Dynamic : %s\n", (lot->mode == PARKINGLOT_DYNAMIC) ? "yes" : "no"); ast_cli(fd, "\n"); } @@ -102,6 +103,14 @@ static void cli_display_parking_lot(int fd, const char *name) ast_cli(fd, "\n"); } +static void cli_display_parking_global(int fd) +{ + ast_cli(fd, "Parking General Options\n" + "-----------------------\n"); + ast_cli(fd, "Dynamic Parking : %s\n", parking_dynamic_lots_enabled() ? "yes" : "no"); + ast_cli(fd, "\n"); +} + static void cli_display_parking_lot_list(int fd) { struct ao2_container *lot_container; @@ -172,6 +181,7 @@ static char *handle_show_parking_lot_cmd(struct ast_cli_entry *e, int cmd, struc ast_cli(a->fd, "\n"); if (a->argc == 2) { + cli_display_parking_global(a->fd); cli_display_parking_lot_list(a->fd); return CLI_SUCCESS; } diff --git a/res/parking/res_parking.h b/res/parking/res_parking.h index a026be41a..2955f87e1 100644 --- a/res/parking/res_parking.h +++ b/res/parking/res_parking.h @@ -118,6 +118,7 @@ struct parked_user { * struct based on a parking lot configuration and return a reference to the new one. * * \param cfg The configuration being used as a reference to build the parking lot from. + * \param dynamic non-zero if creating a dynamic parking lot with this. Don't replace existing parking lots. Ever. * * \retval A reference to the new parking lot * \retval NULL if it was not found and could not be be allocated @@ -125,7 +126,7 @@ struct parked_user { * \note The parking lot will need to be unreffed if it ever falls out of scope * \note The parking lot will automatically be added to the parking lot container if needed as part of this process */ -struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *cfg); +struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *cfg, int dynamic); /*! * \since 12.0.0 @@ -133,10 +134,13 @@ struct parking_lot *parking_lot_build_or_update(struct parking_lot_cfg *cfg); * * \param lot Which parking lot is being checked for elimination * + * \retval 0 if the parking lot was removed + * \retval -1 if the parking lot wasn't removed. + * * \note This should generally be called when something is happening that could cause a parking lot to die such as a call being unparked or * a parking lot no longer existing in configurations. */ -void parking_lot_remove_if_unused(struct parking_lot *lot); +int parking_lot_remove_if_unused(struct parking_lot *lot); /*! * \since 12.0.0 @@ -251,6 +255,21 @@ struct ao2_container *get_parking_lot_container(void); */ struct parking_lot *parking_lot_find_by_name(const char *lot_name); +/*! + * \since 12.0.0 + * \brief Create a dynamic parking lot + * + * \param name Dynamic parking lot name to create + * \param chan Channel parkee to get dynamic parking lot parameters from + * + * \retval dynamically created parking lot on success + * \retval NULL on error + * + * \note This should be called only after verifying that the named parking lot doesn't already exist in a non-dynamic way. + * The parking lots container should be locked before verifying and remain locked until after this function is called. + */ +struct parking_lot *parking_create_dynamic_lot(const char *name, struct ast_channel *chan); + /*! * \since 12.0.0 * \brief Find parking lot name from channel @@ -398,6 +417,15 @@ void get_park_common_datastore_data(struct ast_channel *parkee, */ void parking_notify_metermaids(int exten, const char *context, enum ast_device_state state); +/*! + * \since 12.0.0 + * \brief Check global configuration to see if dynamic parking is enabled + * + * \retval 1 if dynamic parking is enabled + * \retval 0 if dynamic parking is disabled + */ +int parking_dynamic_lots_enabled(void); + /*! * \since 12.0.0 * \brief Execution function for the parking application -- cgit v1.2.3