Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
92ca961d
Commit
92ca961d
authored
9 years ago
by
Matt Jordan
Committed by
Gerrit Code Review
9 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res/res_stasis_device_state: Allow for subscribing to 'all' device state"
parents
6f719bb4
47813cc5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
res/res_stasis_device_state.c
+44
-10
44 additions, 10 deletions
res/res_stasis_device_state.c
with
44 additions
and
10 deletions
res/res_stasis_device_state.c
+
44
−
10
View file @
92ca961d
...
@@ -44,6 +44,9 @@ ASTERISK_REGISTER_FILE()
...
@@ -44,6 +44,9 @@ ASTERISK_REGISTER_FILE()
/*! Number of hash buckets for device state subscriptions */
/*! Number of hash buckets for device state subscriptions */
#define DEVICE_STATE_BUCKETS 37
#define DEVICE_STATE_BUCKETS 37
/*! The key used for tracking a subscription to all device states */
#define DEVICE_STATE_ALL "__AST_DEVICE_STATE_ALL_TOPIC"
/*! Container for subscribed device states */
/*! Container for subscribed device states */
static
struct
ao2_container
*
device_state_subscriptions
;
static
struct
ao2_container
*
device_state_subscriptions
;
...
@@ -112,11 +115,17 @@ static void device_state_subscription_destroy(void *obj)
...
@@ -112,11 +115,17 @@ static void device_state_subscription_destroy(void *obj)
static
struct
device_state_subscription
*
device_state_subscription_create
(
static
struct
device_state_subscription
*
device_state_subscription_create
(
const
struct
stasis_app
*
app
,
const
char
*
device_name
)
const
struct
stasis_app
*
app
,
const
char
*
device_name
)
{
{
struct
device_state_subscription
*
sub
=
ao2_alloc
(
struct
device_state_subscription
*
sub
;
sizeof
(
*
sub
),
device_state_subscription_destroy
);
const
char
*
app_name
=
stasis_app_name
(
app
);
const
char
*
app_name
=
stasis_app_name
(
app
);
size_t
size
=
strlen
(
device_name
)
+
strlen
(
app_name
)
+
2
;
size_t
size
;
if
(
ast_strlen_zero
(
device_name
))
{
device_name
=
DEVICE_STATE_ALL
;
}
size
=
strlen
(
device_name
)
+
strlen
(
app_name
)
+
2
;
sub
=
ao2_alloc
(
sizeof
(
*
sub
),
device_state_subscription_destroy
);
if
(
!
sub
)
{
if
(
!
sub
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -314,25 +323,50 @@ static void *find_device_state(const struct stasis_app *app, const char *name)
...
@@ -314,25 +323,50 @@ static void *find_device_state(const struct stasis_app *app, const char *name)
static
int
is_subscribed_device_state
(
struct
stasis_app
*
app
,
const
char
*
name
)
static
int
is_subscribed_device_state
(
struct
stasis_app
*
app
,
const
char
*
name
)
{
{
RAII_VAR
(
struct
device_state_subscription
*
,
sub
,
struct
device_state_subscription
*
sub
;
find_device_state_subscription
(
app
,
name
),
ao2_cleanup
);
return
sub
!=
NULL
;
sub
=
find_device_state_subscription
(
app
,
DEVICE_STATE_ALL
);
if
(
sub
)
{
ao2_ref
(
sub
,
-
1
);
return
1
;
}
sub
=
find_device_state_subscription
(
app
,
name
);
if
(
sub
)
{
ao2_ref
(
sub
,
-
1
);
return
1
;
}
return
0
;
}
}
static
int
subscribe_device_state
(
struct
stasis_app
*
app
,
void
*
obj
)
static
int
subscribe_device_state
(
struct
stasis_app
*
app
,
void
*
obj
)
{
{
struct
device_state_subscription
*
sub
=
obj
;
struct
device_state_subscription
*
sub
=
obj
;
struct
stasis_topic
*
topic
;
if
(
!
sub
)
{
sub
=
device_state_subscription_create
(
app
,
NULL
);
if
(
!
sub
)
{
return
-
1
;
}
}
ast_debug
(
3
,
"Subscribing to device %s"
,
sub
->
device_name
);
if
(
strcmp
(
sub
->
device_name
,
DEVICE_STATE_ALL
))
{
topic
=
ast_device_state_topic
(
sub
->
device_name
);
}
else
{
topic
=
ast_device_state_topic_all
();
}
if
(
is_subscribed_device_state
(
app
,
sub
->
device_name
))
{
if
(
is_subscribed_device_state
(
app
,
sub
->
device_name
))
{
ast_debug
(
3
,
"App %s is already subscribed to %s
\n
"
,
stasis_app_name
(
app
),
sub
->
device_name
);
ast_debug
(
3
,
"App %s is already subscribed to %s
\n
"
,
stasis_app_name
(
app
),
sub
->
device_name
);
return
0
;
return
0
;
}
}
if
(
!
(
sub
->
sub
=
stasis_subscribe_pool
(
ast_debug
(
3
,
"Subscribing to device %s
\n
"
,
sub
->
device_name
);
ast_device_state_topic
(
sub
->
device_name
),
device_state_cb
,
sub
)))
{
sub
->
sub
=
stasis_subscribe_pool
(
topic
,
device_state_cb
,
sub
);
if
(
!
sub
->
sub
)
{
ast_log
(
LOG_ERROR
,
"Unable to subscribe to device %s
\n
"
,
ast_log
(
LOG_ERROR
,
"Unable to subscribe to device %s
\n
"
,
sub
->
device_name
);
sub
->
device_name
);
return
-
1
;
return
-
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment