Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions
parking_devicestate.c File Reference

Call Parking Device State Management. More...

#include "asterisk.h"
#include "asterisk/logger.h"
#include "res_parking.h"
#include "asterisk/devicestate.h"
Include dependency graph for parking_devicestate.c:

Go to the source code of this file.

Data Structures

struct  parking_lot_extension_inuse_search
 

Functions

int load_parking_devstate (void)
 Register Parking devstate handler. More...
 
static enum ast_device_state metermaidstate (const char *data)
 
static int parking_lot_search_context_extension_inuse (void *obj, void *arg, int flags)
 
void parking_notify_metermaids (int exten, const char *context, enum ast_device_state state)
 Notify metermaids that we've changed an extension. More...
 
static int retrieve_parked_user_targeted (void *obj, void *arg, int flags)
 
void unload_parking_devstate (void)
 Unregister Parking devstate handler. More...
 

Detailed Description

Call Parking Device State Management.

Author
Jonathan Rose jrose[email protected]@dig[email protected]ium.c[email protected]om

Definition in file parking_devicestate.c.

Function Documentation

◆ load_parking_devstate()

int load_parking_devstate ( void  )

Register Parking devstate handler.

Since
12.0.0

Definition at line 121 of file parking_devicestate.c.

References ast_devstate_prov_add(), and metermaidstate().

Referenced by load_module().

122 {
123  return ast_devstate_prov_add("Park", metermaidstate);
124 }
static enum ast_device_state metermaidstate(const char *data)
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
Definition: devicestate.c:391

◆ metermaidstate()

static enum ast_device_state metermaidstate ( const char *  data)
static

Definition at line 77 of file parking_devicestate.c.

References ao2_callback, ao2_cleanup, ast_debug, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, ast_strdupa, ast_strlen_zero, parking_lot_extension_inuse_search::context, parking_lot_extension_inuse_search::exten, get_parking_lot_container(), NULL, parking_lot_search_context_extension_inuse(), RAII_VAR, and strsep().

Referenced by load_parking_devstate().

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 
89  if (ast_strlen_zero(context) || ast_strlen_zero(exten)) {
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) {
102  return AST_DEVICE_NOT_INUSE;
103  }
104 
105  return AST_DEVICE_INUSE;
106 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define NULL
Definition: resample.c:96
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:596
static int parking_lot_search_context_extension_inuse(void *obj, void *arg, int flags)
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#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:911
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
char * strsep(char **str, const char *delims)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Generic container type.
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ parking_lot_search_context_extension_inuse()

static int parking_lot_search_context_extension_inuse ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 47 of file parking_devicestate.c.

References ao2_callback, ao2_cleanup, ao2_lock, ao2_unlock, parking_lot::cfg, CMP_MATCH, parking_lot_extension_inuse_search::context, parking_lot_extension_inuse_search::exten, NULL, PARK_UNSET, parking_lot::parked_users, parking_lot_cfg::parking_con, parking_lot_cfg::parking_start, parking_lot_cfg::parking_stop, RAII_VAR, and retrieve_parked_user_targeted().

Referenced by metermaidstate().

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 
66  ao2_lock(user);
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 }
struct ao2_container * parked_users
Definition: res_parking.h:95
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
const ast_string_field parking_con
Definition: res_parking.h:89
#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:911
#define ao2_lock(a)
Definition: astobj2.h:718
structure to hold users read from users.conf
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static int retrieve_parked_user_targeted(void *obj, void *arg, int flags)
struct parking_lot_cfg * cfg
Definition: res_parking.h:96

◆ parking_notify_metermaids()

void parking_notify_metermaids ( int  exten,
const char *  context,
enum ast_device_state  state 
)

Notify metermaids that we've changed an extension.

Since
12.0.0
Parameters
extenExtension of the call parked/unparked
contextContext of the call parked/unparked
statenew device state

Definition at line 108 of file parking_devicestate.c.

References ast_debug, ast_devstate2str(), AST_DEVSTATE_CACHABLE, and ast_devstate_changed().

Referenced by bridge_parking_pull(), and bridge_parking_push().

109 {
110  ast_debug(4, "Notification of state change to metermaids %[email protected]%s\n to state '%s'\n",
112 
114 }
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
Definition: devicestate.c:237
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
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
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ retrieve_parked_user_targeted()

static int retrieve_parked_user_targeted ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 36 of file parking_devicestate.c.

References CMP_MATCH, and parked_user::parking_space.

Referenced by parking_lot_search_context_extension_inuse().

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 }
int parking_space
Definition: res_parking.h:107
structure to hold users read from users.conf

◆ unload_parking_devstate()

void unload_parking_devstate ( void  )

Unregister Parking devstate handler.

Since
12.0.0

Definition at line 116 of file parking_devicestate.c.

References ast_devstate_prov_del().

Referenced by unload_module().

117 {
118  ast_devstate_prov_del("Park");
119 }
int ast_devstate_prov_del(const char *label)
Remove device state provider.
Definition: devicestate.c:418