summaryrefslogtreecommitdiff
path: root/main/devicestate.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/devicestate.c')
-rw-r--r--main/devicestate.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/main/devicestate.c b/main/devicestate.c
index 1199e68ab..3580b1af7 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -224,9 +224,12 @@ static struct stasis_caching_topic *device_state_topic_cached;
static struct stasis_topic_pool *device_state_topic_pool;
static struct ast_manager_event_blob *devstate_to_ami(struct stasis_message *msg);
+static struct ast_event *devstate_to_event(struct stasis_message *msg);
+
STASIS_MESSAGE_TYPE_DEFN(ast_device_state_message_type,
.to_ami = devstate_to_ami,
+ .to_event = devstate_to_event,
);
/* Forward declarations */
@@ -925,3 +928,33 @@ static struct ast_manager_event_blob *devstate_to_ami(struct stasis_message *msg
"State: %s\r\n",
dev_state->device, ast_devstate_str(dev_state->state));
}
+
+/*! \brief Convert a \ref stasis_message to a \ref ast_event */
+static struct ast_event *devstate_to_event(struct stasis_message *message)
+{
+ struct ast_event *event;
+ struct ast_device_state_message *device_state;
+
+ if (!message) {
+ return NULL;
+ }
+
+ device_state = stasis_message_data(message);
+
+ if (device_state->eid) {
+ event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device_state->device,
+ AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, device_state->state,
+ AST_EVENT_IE_CACHABLE, AST_EVENT_IE_PLTYPE_UINT, device_state->cachable,
+ AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW, device_state->eid, sizeof(*device_state->eid),
+ AST_EVENT_IE_END);
+ } else {
+ event = ast_event_new(AST_EVENT_DEVICE_STATE,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device_state->device,
+ AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, device_state->state,
+ AST_EVENT_IE_CACHABLE, AST_EVENT_IE_PLTYPE_UINT, device_state->cachable,
+ AST_EVENT_IE_END);
+ }
+
+ return event;
+}