2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Jonathan Rose <jrose@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Call Parking Device State Management
23 * \author Jonathan Rose <jrose@digium.com>
27 #include "asterisk/logger.h"
28 #include "res_parking.h"
29 #include "asterisk/devicestate.h"
31 struct parking_lot_extension_inuse_search {
36 static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
39 struct parked_user *user = obj;
40 if (user->parking_space == *target) {
47 static int parking_lot_search_context_extension_inuse(void *obj, void *arg, int flags)
49 struct parking_lot *lot = obj;
50 struct parking_lot_extension_inuse_search *search = arg;
51 RAII_VAR(struct parked_user *, user, NULL, ao2_cleanup);
53 if (strcmp(lot->cfg->parking_con, search->context)) {
57 if ((search->exten < lot->cfg->parking_start) || (search->exten > lot->cfg->parking_stop)) {
61 user = ao2_callback(lot->parked_users, 0, retrieve_parked_user_targeted, &search->exten);
67 if (user->resolution != PARK_UNSET) {
68 /* The parked user isn't in an answerable state. */
77 static enum ast_device_state metermaidstate(const char *data)
79 struct ao2_container *global_lots = get_parking_lot_container();
80 RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
83 struct parking_lot_extension_inuse_search search = {};
85 context = ast_strdupa(data);
87 exten = strsep(&context, "@");
89 if (ast_strlen_zero(context) || ast_strlen_zero(exten)) {
90 return AST_DEVICE_INVALID;
93 search.context = context;
94 if (sscanf(exten, "%d", &search.exten) != 1) {
95 return AST_DEVICE_INVALID;
98 ast_debug(4, "Checking state of exten %d in context %s\n", search.exten, context);
100 lot = ao2_callback(global_lots, 0, parking_lot_search_context_extension_inuse, &data);
102 return AST_DEVICE_NOT_INUSE;
105 return AST_DEVICE_INUSE;
108 void parking_notify_metermaids(int exten, const char *context, enum ast_device_state state)
110 ast_debug(4, "Notification of state change to metermaids %d@%s\n to state '%s'\n",
111 exten, context, ast_devstate2str(state));
113 ast_devstate_changed(state, AST_DEVSTATE_CACHABLE, "park:%d@%s", exten, context);
116 void unload_parking_devstate(void)
118 ast_devstate_prov_del("Park");
121 int load_parking_devstate(void)
123 return ast_devstate_prov_add("Park", metermaidstate);