Asterisk - The Open Source Telephony Project GIT-master-f36a736
parking_devicestate.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Jonathan Rose <jrose@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief Call Parking Device State Management
22 *
23 * \author Jonathan Rose <jrose@digium.com>
24 */
25
26#include "asterisk.h"
27#include "asterisk/logger.h"
28#include "res_parking.h"
30
32 char *context;
33 int exten;
34};
35
36static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
37{
38 int *target = arg;
39 struct parked_user *user = obj;
40 if (user->parking_space == *target) {
41 return CMP_MATCH;
42 }
43
44 return 0;
45}
46
47static int parking_lot_search_context_extension_inuse(void *obj, void *arg, int flags)
48{
49 struct parking_lot *lot = obj;
50 struct parking_lot_extension_inuse_search *search = arg;
52
53 if (strcmp(lot->cfg->parking_con, search->context)) {
54 return 0;
55 }
56
57 if ((search->exten < lot->cfg->parking_start) || (search->exten > lot->cfg->parking_stop)) {
58 return 0;
59 }
60
62 if (!user) {
63 return 0;
64 }
65
67 if (user->resolution != PARK_UNSET) {
68 /* The parked user isn't in an answerable state. */
70 return 0;
71 }
73
74 return CMP_MATCH;
75}
76
77static enum ast_device_state metermaidstate(const char *data)
78{
79 struct ao2_container *global_lots = get_parking_lot_container();
80 RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
81 char *context;
82 char *exten;
83 struct parking_lot_extension_inuse_search search = {};
84
85 context = ast_strdupa(data);
86
87 exten = strsep(&context, "@");
88
90 return AST_DEVICE_INVALID;
91 }
92
93 search.context = context;
94 if (sscanf(exten, "%d", &search.exten) != 1) {
95 return AST_DEVICE_INVALID;
96 }
97
98 ast_debug(4, "Checking state of exten %d in context %s\n", search.exten, context);
99
100 lot = ao2_callback(global_lots, 0, parking_lot_search_context_extension_inuse, &data);
101 if (!lot) {
103 }
104
105 return AST_DEVICE_INUSE;
106}
107
109{
110 ast_debug(4, "Notification of state change to metermaids %d@%s\n to state '%s'\n",
112
114}
115
117{
118 ast_devstate_prov_del("Park");
119}
120
122{
124}
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
@ CMP_MATCH
Definition: astobj2.h:1027
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
Device state management.
int ast_devstate_prov_del(const char *label)
Remove device state provider.
Definition: devicestate.c:418
@ AST_DEVSTATE_CACHABLE
Definition: devicestate.h:70
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:510
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
Definition: devicestate.c:237
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
Definition: devicestate.c:391
ast_device_state
Device States.
Definition: devicestate.h:52
@ AST_DEVICE_INUSE
Definition: devicestate.h:55
@ AST_DEVICE_INVALID
Definition: devicestate.h:57
@ AST_DEVICE_NOT_INUSE
Definition: devicestate.h:54
char * strsep(char **str, const char *delims)
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
void parking_notify_metermaids(int exten, const char *context, enum ast_device_state state)
Notify metermaids that we've changed an extension.
int load_parking_devstate(void)
Register Parking devstate handler.
static enum ast_device_state metermaidstate(const char *data)
void unload_parking_devstate(void)
Unregister Parking devstate handler.
static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
static int parking_lot_search_context_extension_inuse(void *obj, void *arg, int flags)
Call Parking Resource Internal API.
@ PARK_UNSET
Definition: res_parking.h:41
struct ao2_container * get_parking_lot_container(void)
Get a pointer to the parking lot container for purposes such as iteration.
Definition: res_parking.c:597
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Generic container type.
const ast_string_field parking_con
Definition: res_parking.h:89
struct parking_lot_cfg * cfg
Definition: res_parking.h:96
struct ao2_container * parked_users
Definition: res_parking.h:95
structure to hold users read from users.conf
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941