Asterisk - The Open Source Telephony Project  21.4.1
Functions | Variables
stasis_system.c File Reference

Stasis Messages and Data Types for System events. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_system.h"

Go to the source code of this file.

Functions

int ast_stasis_system_init (void)
 Initialize the system level items for Stasis Message Bus API. More...
 
void ast_system_publish_registry (const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
 Publish a channel driver outgoing registration message. More...
 
struct stasis_topicast_system_topic (void)
 A Stasis Message Bus API topic which publishes messages regarding system changes. More...
 
static struct ast_manager_event_blobcc_available_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_callerrecalling_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_callerstartmonitoring_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_callerstopmonitoring_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_failure_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_monitorfailed_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_offertimerstart_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_recallcomplete_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_requestacknowledged_to_ami (struct stasis_message *message)
 
static struct ast_manager_event_blobcc_requested_to_ami (struct stasis_message *message)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_network_change_type)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_system_registry_type,.to_ami=system_registry_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_available_type,.to_ami=cc_available_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_offertimerstart_type,.to_ami=cc_offertimerstart_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_requested_type,.to_ami=cc_requested_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_requestacknowledged_type,.to_ami=cc_requestacknowledged_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_callerstopmonitoring_type,.to_ami=cc_callerstopmonitoring_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_callerstartmonitoring_type,.to_ami=cc_callerstartmonitoring_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_callerrecalling_type,.to_ami=cc_callerrecalling_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_recallcomplete_type,.to_ami=cc_recallcomplete_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_failure_type,.to_ami=cc_failure_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cc_monitorfailed_type,.to_ami=cc_monitorfailed_to_ami,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_cluster_discovery_type)
 
static void stasis_system_cleanup (void)
 Cleanup the Stasis Message Bus API system level items.
 
static struct ast_manager_event_blobsystem_registry_to_ami (struct stasis_message *message)
 

Variables

static struct stasis_topicsystem_topic
 The Stasis Message Bus API topic for system level changes.
 

Detailed Description

Stasis Messages and Data Types for System events.

Author
Jason Parker jpark.nosp@m.er@d.nosp@m.igium.nosp@m..com

Definition in file stasis_system.c.

Function Documentation

int ast_stasis_system_init ( void  )

Initialize the system level items for Stasis Message Bus API.

Initialize the stasis system topic and message types.

Definition at line 373 of file stasis_system.c.

References ast_register_cleanup(), STASIS_MESSAGE_TYPE_INIT, stasis_system_cleanup(), and stasis_topic_create().

374 {
376 
377  system_topic = stasis_topic_create("system:all");
378  if (!system_topic) {
379  return 1;
380  }
381 
382  if (STASIS_MESSAGE_TYPE_INIT(ast_network_change_type) != 0) {
383  return -1;
384  }
385 
386  if (STASIS_MESSAGE_TYPE_INIT(ast_system_registry_type) != 0) {
387  return -1;
388  }
389 
390  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_available_type) != 0) {
391  return -1;
392  }
393 
394  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_offertimerstart_type) != 0) {
395  return -1;
396  }
397 
398  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_requested_type) != 0) {
399  return -1;
400  }
401 
402  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_requestacknowledged_type) != 0) {
403  return -1;
404  }
405 
406  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_callerstopmonitoring_type) != 0) {
407  return -1;
408  }
409 
410  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_callerstartmonitoring_type) != 0) {
411  return -1;
412  }
413 
414  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_callerrecalling_type) != 0) {
415  return -1;
416  }
417 
418  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_recallcomplete_type) != 0) {
419  return -1;
420  }
421 
422  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_failure_type) != 0) {
423  return -1;
424  }
425 
426  if (STASIS_MESSAGE_TYPE_INIT(ast_cc_monitorfailed_type) != 0) {
427  return -1;
428  }
429 
430  if (STASIS_MESSAGE_TYPE_INIT(ast_cluster_discovery_type) != 0) {
431  return -1;
432  }
433 
434  return 0;
435 }
static struct stasis_topic * system_topic
The Stasis Message Bus API topic for system level changes.
Definition: stasis_system.c:68
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static void stasis_system_cleanup(void)
Cleanup the Stasis Message Bus API system level items.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:617
void ast_system_publish_registry ( const char *  channeltype,
const char *  username,
const char *  domain,
const char *  status,
const char *  cause 
)

Publish a channel driver outgoing registration message.

Since
12
Parameters
channeltypeThe channel driver that published the message
usernameThe username that was used to register
domainThe domain that was used to register
statusThe result of the registration
causeThe reason for the result

Definition at line 118 of file stasis_system.c.

References ao2_ref, ast_json_pack(), ast_json_payload_create(), ast_json_unref(), ast_system_topic(), S_OR, stasis_message_create(), and stasis_publish().

119 {
120  struct ast_json *registry;
121  struct ast_json_payload *payload;
122  struct stasis_message *message;
123 
124  if (!ast_system_registry_type()) {
125  return;
126  }
127 
128  registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s}",
129  "type", "registry",
130  "channeltype", channeltype,
131  "username", username,
132  "domain", domain,
133  "status", status,
134  "cause", S_OR(cause, ""));
135 
136  payload = ast_json_payload_create(registry);
137  ast_json_unref(registry);
138  if (!payload) {
139  return;
140  }
141 
142  message = stasis_message_create(ast_system_registry_type(), payload);
143  ao2_ref(payload, -1);
144  if (!message) {
145  return;
146  }
147 
148  stasis_publish(ast_system_topic(), message);
149  ao2_ref(message, -1);
150 }
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
Definition: json.c:756
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1511
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
Abstract JSON element (object, array, string, int, ...).
struct stasis_topic* ast_system_topic ( void  )

A Stasis Message Bus API topic which publishes messages regarding system changes.

Since
12
Returns
stasis_topic for system level changes
Return values
NULLon error

Definition at line 347 of file stasis_system.c.

References system_topic.

Referenced by ast_system_publish_registry(), manager_system_init(), pjsip_outbound_registration_metrics_init(), publish_cluster_discovery_to_stasis_full(), and stun_monitor_request().

348 {
349  return system_topic;
350 }
static struct stasis_topic * system_topic
The Stasis Message Bus API topic for system level changes.
Definition: stasis_system.c:68