Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Go to the source code of this file.
Data Structures | |
struct | stasis_state |
struct | stasis_state_manager |
struct | stasis_state_proxy |
struct | stasis_state_publisher |
struct | stasis_state_subscriber |
Macros | |
#define | STATE_BUCKETS 57 |
#define | state_find_or_add(manager, state_topic, id) __state_find_or_add(manager, state_topic, id, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Functions | |
static struct stasis_state * | __state_find_or_add (struct stasis_state_manager *manager, struct stasis_topic *state_topic, const char *id, const char *file, int line, const char *func) |
AO2_STRING_FIELD_CMP_FN (stasis_state_proxy, id) | |
AO2_STRING_FIELD_HASH_FN (stasis_state_proxy, id) | |
static int | handle_stasis_state (struct stasis_state *state, on_stasis_state handler, void *data) |
static int | handle_stasis_state_proxy (void *obj, void *arg, void *data, int flags) |
static int | handle_stasis_state_subscribed (void *obj, void *arg, void *data, int flags) |
static void | publisher_dtor (void *obj) |
int | stasis_state_add_observer (struct stasis_state_manager *manager, struct stasis_state_observer *observer) |
Add an observer to receive managed state related events. More... | |
struct stasis_state_publisher * | stasis_state_add_publisher (struct stasis_state_manager *manager, const char *id) |
Add a publisher to the managed state for the given id. More... | |
struct stasis_state_subscriber * | stasis_state_add_subscriber (struct stasis_state_manager *manager, const char *id) |
Add a subscriber to the managed stasis state for the given id. More... | |
struct stasis_topic * | stasis_state_all_topic (struct stasis_state_manager *manager) |
Retrieve the manager's topic (the topic that all state topics get forwarded to) More... | |
void | stasis_state_callback_all (struct stasis_state_manager *manager, on_stasis_state handler, void *data) |
For each managed state call the given handler. More... | |
void | stasis_state_callback_subscribed (struct stasis_state_manager *manager, on_stasis_state handler, void *data) |
For each managed, and explicitly subscribed state call the given handler. More... | |
struct stasis_state_manager * | stasis_state_manager_create (const char *topic_name) |
Create a stasis state manager. More... | |
void | stasis_state_publish (struct stasis_state_publisher *pub, struct stasis_message *msg) |
Publish to a managed state (topic) using a publisher. More... | |
void | stasis_state_publish_by_id (struct stasis_state_manager *manager, const char *id, const struct ast_eid *eid, struct stasis_message *msg) |
Publish to a managed named by id topic, and add an implicit subscriber. More... | |
const char * | stasis_state_publisher_id (const struct stasis_state_publisher *pub) |
Retrieve the publisher's underlying state's unique id. More... | |
struct stasis_topic * | stasis_state_publisher_topic (struct stasis_state_publisher *pub) |
Retrieve the publisher's topic. More... | |
void | stasis_state_remove_observer (struct stasis_state_manager *manager, struct stasis_state_observer *observer) |
Remove an observer (will no longer receive managed state related events). More... | |
void | stasis_state_remove_publish_by_id (struct stasis_state_manager *manager, const char *id, const struct ast_eid *eid, struct stasis_message *msg) |
Publish to a managed named by id topic, and remove an implicit publisher. More... | |
struct stasis_state_subscriber * | stasis_state_subscribe_pool (struct stasis_state_manager *manager, const char *id, stasis_subscription_cb callback, void *data) |
Add a subscriber, and subscribe to its underlying stasis topic. More... | |
void * | stasis_state_subscriber_data (struct stasis_state_subscriber *sub) |
Retrieve the last known state stasis message payload for the subscriber. More... | |
const char * | stasis_state_subscriber_id (const struct stasis_state_subscriber *sub) |
Retrieve the underlying subscribed to state's unique id. More... | |
struct stasis_subscription * | stasis_state_subscriber_subscription (struct stasis_state_subscriber *sub) |
Retrieve the stasis topic subscription if available. More... | |
struct stasis_topic * | stasis_state_subscriber_topic (struct stasis_state_subscriber *sub) |
Retrieve the subscriber's topic. More... | |
struct stasis_topic * | stasis_state_topic (struct stasis_state_manager *manager, const char *id) |
Retrieve a managed topic creating one if not currently managed. More... | |
void * | stasis_state_unsubscribe (struct stasis_state_subscriber *sub) |
Unsubscribe from the stasis topic and stasis state. More... | |
void * | stasis_state_unsubscribe_and_join (struct stasis_state_subscriber *sub) |
Unsubscribe from the stasis topic, block until the final message is received, and then unsubscribe from stasis state. More... | |
static struct stasis_state * | state_alloc (struct stasis_state_manager *manager, struct stasis_topic *state_topic, const char *id, const char *file, int line, const char *func) |
static void | state_dtor (void *obj) |
static void | state_find_and_remove_eid (struct stasis_state *state, const struct ast_eid *eid) |
static void | state_find_or_add_eid (struct stasis_state *state, const struct ast_eid *eid) |
static const char * | state_id_by_topic (struct stasis_topic *manager_topic, const struct stasis_topic *state_topic) |
static void | state_manager_dtor (void *obj) |
static void | state_proxy_dtor (void *obj) |
static void | state_proxy_sub_cb (void *obj, void *data) |
static void | subscriber_dtor (void *obj) |
#define STATE_BUCKETS 57 |
The number of buckets to use for managed states
Definition at line 77 of file stasis_state.c.
#define state_find_or_add | ( | manager, | |
state_topic, | |||
id | |||
) | __state_find_or_add(manager, state_topic, id, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Definition at line 271 of file stasis_state.c.
|
static |
Definition at line 272 of file stasis_state.c.
References stasis_state_manager::all_topic, ao2_lock, ao2_unlock, ao2_weakproxy_find, ast_strlen_zero(), make_ari_stubs::file, stasis_state::manager, OBJ_NOLOCK, OBJ_SEARCH_KEY, state, state_alloc(), state_id_by_topic(), and stasis_state_manager::states.
AO2_STRING_FIELD_CMP_FN | ( | stasis_state_proxy | , |
id | |||
) |
AO2_STRING_FIELD_HASH_FN | ( | stasis_state_proxy | , |
id | |||
) |
|
static |
Definition at line 709 of file stasis_state.c.
References ao2_bump, ao2_cleanup, ao2_lock, ao2_unlock, stasis_message::data, and handler().
Referenced by handle_stasis_state_proxy(), and handle_stasis_state_subscribed().
|
static |
Definition at line 727 of file stasis_state.c.
References ao2_ref, ao2_weakproxy_get_object, and handle_stasis_state().
Referenced by stasis_state_callback_all().
|
static |
Definition at line 750 of file stasis_state.c.
References ao2_cleanup, ao2_weakproxy_get_object, and handle_stasis_state().
Referenced by stasis_state_callback_subscribed().
|
static |
Definition at line 525 of file stasis_state.c.
References ao2_ref, and stasis_state_publisher::state.
Referenced by stasis_state_add_publisher().
int stasis_state_add_observer | ( | struct stasis_state_manager * | manager, |
struct stasis_state_observer * | observer | ||
) |
Add an observer to receive managed state related events.
manager | The state manager |
observer | The observer handling events |
0 | if successfully registered |
-1 | on failure |
Definition at line 689 of file stasis_state.c.
References AST_VECTOR_APPEND, AST_VECTOR_RW_UNLOCK, AST_VECTOR_RW_WRLOCK, stasis_state::manager, and observer.
Referenced by ast_mwi_add_observer(), and subscriptions_create().
struct stasis_state_publisher * stasis_state_add_publisher | ( | struct stasis_state_manager * | manager, |
const char * | id | ||
) |
Add a publisher to the managed state for the given id.
Adds a publisher to a managed state based on id. If managed state does not already exists for the given id then new managed state is created. Otherwise the existing state is used.
manager | The manager object |
id | The unique id of a managed state |
A | stasis state publisher |
NULL | if an error occurred |
Definition at line 532 of file stasis_state.c.
References stasis_state_manager::all_topic, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, ast_log, LOG_ERROR, NULL, publisher_dtor(), stasis_topic_name(), stasis_state_publisher::state, and state_find_or_add.
Referenced by ast_mwi_add_publisher(), and publishers_create().
struct stasis_state_subscriber * stasis_state_add_subscriber | ( | struct stasis_state_manager * | manager, |
const char * | id | ||
) |
Add a subscriber to the managed stasis state for the given id.
Adds a subscriber to a managed state based on id. If managed state does not already exists for the given id then new managed state is created. Otherwise the existing state is subscribed to.
manager | The manager object |
id | The unique id of a managed state |
A | stasis state subscriber |
NULL | if an error occurred |
Definition at line 413 of file stasis_state.c.
References stasis_state_manager::all_topic, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_lock, ao2_ref, ao2_unlock, ast_log, AST_VECTOR_GET, AST_VECTOR_RW_RDLOCK, AST_VECTOR_RW_UNLOCK, AST_VECTOR_SIZE, LOG_ERROR, NULL, stasis_topic_name(), state_find_or_add, sub, and subscriber_dtor().
Referenced by ast_mwi_add_subscriber(), and stasis_state_subscribe_pool().
struct stasis_topic * stasis_state_all_topic | ( | struct stasis_state_manager * | manager | ) |
Retrieve the manager's topic (the topic that all state topics get forwarded to)
manager | The manager object |
The | manager's topic. |
Definition at line 365 of file stasis_state.c.
References stasis_state_manager::all_topic.
Referenced by ast_mwi_topic_all().
void stasis_state_callback_all | ( | struct stasis_state_manager * | manager, |
on_stasis_state | handler, | ||
void * | data | ||
) |
For each managed state call the given handler.
manager | The state manager |
handler | The handler to call for each managed state |
data | User to data to pass on to the handler |
Definition at line 741 of file stasis_state.c.
References ao2_callback_data, ast_assert, handle_stasis_state_proxy(), handler(), stasis_state::manager, NULL, OBJ_MULTIPLE, OBJ_NODATA, and stasis_state_manager::states.
Referenced by ast_mwi_state_callback_all(), and publish().
void stasis_state_callback_subscribed | ( | struct stasis_state_manager * | manager, |
on_stasis_state | handler, | ||
void * | data | ||
) |
For each managed, and explicitly subscribed state call the given handler.
manager | The state manager |
handler | The handler to call for each managed state |
data | User to data to pass on to the handler |
Definition at line 764 of file stasis_state.c.
References ao2_callback_data, ast_assert, handle_stasis_state_subscribed(), handler(), stasis_state::manager, NULL, OBJ_MULTIPLE, OBJ_NODATA, and stasis_state_manager::states.
Referenced by ast_mwi_state_callback_subscribed().
struct stasis_state_manager * stasis_state_manager_create | ( | const char * | topic_name | ) |
Create a stasis state manager.
topic_name | The name of the topic to create that all state topics get forwarded to |
A | stasis state manager |
NULL | if an error occurred |
Definition at line 325 of file stasis_state.c.
References stasis_state_manager::all_topic, AO2_ALLOC_OPT_LOCK_MUTEX, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_container_alloc_hash, ao2_container_register(), ao2_ref, ast_alloca, AST_VECTOR_RW_INIT, NULL, stasis_topic_create(), stasis_topic_name(), STATE_BUCKETS, state_manager_dtor(), and stasis_state_manager::states.
Referenced by AST_TEST_DEFINE(), and mwi_init().
void stasis_state_publish | ( | struct stasis_state_publisher * | pub, |
struct stasis_message * | msg | ||
) |
Publish to a managed state (topic) using a publisher.
pub | The publisher to use to publish the message |
msg | The message to publish |
Definition at line 563 of file stasis_state.c.
References ao2_lock, ao2_replace, ao2_unlock, stasis_state::msg, stasis_publish(), stasis_state_publisher::state, and stasis_state::topic.
Referenced by ast_mwi_publish(), and explicit_publish_cb().
void stasis_state_publish_by_id | ( | struct stasis_state_manager * | manager, |
const char * | id, | ||
const struct ast_eid * | eid, | ||
struct stasis_message * | msg | ||
) |
Publish to a managed named by id topic, and add an implicit subscriber.
This creates an implicit publisher keyed off the eid. This ability was mainly implemented in order to maintain compatibility with already established code. Allowing the creation of an implicit publisher made is so less changes were required when stasis state module was initially added.
There should only ever be one publisher for a specifically named managed topic within the system. This being the case we can use the eid to implicitly track the publisher. However once publishing is no longer needed for a topic a call to stasis_state_remove_publish_by_id is required in order to remove the implicit publisher. Thus allowing for its eventual destruction. Without the call to remove a memory leak will occur.
manager | The state manager |
id | A state's unique id |
eid | The unique system id |
msg | The message to publish |
Definition at line 639 of file stasis_state.c.
References ao2_lock, ao2_ref, ao2_replace, ao2_unlock, stasis_state::manager, stasis_state::msg, NULL, stasis_publish(), state, state_find_or_add, and state_find_or_add_eid().
Referenced by ast_mwi_publish_by_mailbox(), and implicit_publish_cb().
const char * stasis_state_publisher_id | ( | const struct stasis_state_publisher * | pub | ) |
Retrieve the publisher's underlying state's unique id.
pub | A stasis state publisher |
The | managed state's id |
Definition at line 553 of file stasis_state.c.
References stasis_state::id, and stasis_state_publisher::state.
Referenced by ast_mwi_publish(), and explicit_publish_cb().
struct stasis_topic * stasis_state_publisher_topic | ( | struct stasis_state_publisher * | pub | ) |
Retrieve the publisher's topic.
pub | A stasis state publisher |
The | publisher's topic |
Definition at line 558 of file stasis_state.c.
References stasis_state_publisher::state, and stasis_state::topic.
void stasis_state_remove_observer | ( | struct stasis_state_manager * | manager, |
struct stasis_state_observer * | observer | ||
) |
Remove an observer (will no longer receive managed state related events).
manager | The state manager |
observer | The observer being removed |
Definition at line 701 of file stasis_state.c.
References AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_ELEM_UNORDERED, AST_VECTOR_RW_UNLOCK, AST_VECTOR_RW_WRLOCK, stasis_state::manager, and observer.
Referenced by ast_mwi_remove_observer(), and subscriptions_destroy().
void stasis_state_remove_publish_by_id | ( | struct stasis_state_manager * | manager, |
const char * | id, | ||
const struct ast_eid * | eid, | ||
struct stasis_message * | msg | ||
) |
Publish to a managed named by id topic, and remove an implicit publisher.
This function should be called after calling stasis_state_publish_by_id at least once for the same manager, id, and eid. If the given stasis message is NULL then the implicit publisher is removed, but no last message is published.
See note and description on stasis_state_publish_by_id for more details about if, and when this function should be used.
manager | The state manager |
id | A state's unique id |
eid | The unique system id |
msg | The message to publish (can be NULL) |
Definition at line 659 of file stasis_state.c.
References ao2_lock, ao2_ref, ao2_unlock, ao2_weakproxy_find, ast_debug, stasis_state::manager, stasis_state::msg, OBJ_SEARCH_KEY, stasis_publish(), state_find_and_remove_eid(), and stasis_state_manager::states.
Referenced by ast_delete_mwi_state_full(), and publishers_destroy().
struct stasis_state_subscriber * stasis_state_subscribe_pool | ( | struct stasis_state_manager * | manager, |
const char * | id, | ||
stasis_subscription_cb | callback, | ||
void * | data | ||
) |
Add a subscriber, and subscribe to its underlying stasis topic.
Adds a subscriber to a managed state based on id. If managed state does not already exists for the given id then new managed state is created. Otherwise the existing state is subscribed to. If the state is successfully subscribed to then a stasis subscription is subsequently created as well.
manager | The manager object |
id | The unique id of a managed state |
callback | The stasis subscription callback |
data | A user data object passed to the stasis subscription |
A | stasis state subscriber |
NULL | if an error occurred |
Definition at line 447 of file stasis_state.c.
References ao2_ref, ast_debug, NULL, stasis_state_add_subscriber(), stasis_subscribe_pool, stasis_topic_name(), and sub.
Referenced by ast_mwi_subscribe_pool(), and subscriptions_create().
void * stasis_state_subscriber_data | ( | struct stasis_state_subscriber * | sub | ) |
Retrieve the last known state stasis message payload for the subscriber.
If a stasis message has been published to this state, this function returns that message's payload object. If no stasis message has been published on the state, or the message's payload does not exist then NULL is returned.
sub | A stasis state subscriber |
The | subscriber's state message data |
NULL | if no data has been published yet |
Definition at line 498 of file stasis_state.c.
References ao2_bump, ao2_lock, ao2_unlock, stasis_message_data(), and sub.
Referenced by ast_mwi_subscriber_data(), and handle_validate().
const char * stasis_state_subscriber_id | ( | const struct stasis_state_subscriber * | sub | ) |
Retrieve the underlying subscribed to state's unique id.
sub | A stasis state subscriber |
The | managed state's id |
Definition at line 488 of file stasis_state.c.
References sub.
Referenced by ast_mwi_subscriber_data().
struct stasis_subscription * stasis_state_subscriber_subscription | ( | struct stasis_state_subscriber * | sub | ) |
Retrieve the stasis topic subscription if available.
sub | A stasis state subscriber |
The | subscriber's stasis subscription |
NULL | if no subscription available |
Definition at line 514 of file stasis_state.c.
References sub.
Referenced by ast_mwi_subscriber_subscription().
struct stasis_topic * stasis_state_subscriber_topic | ( | struct stasis_state_subscriber * | sub | ) |
Retrieve the subscriber's topic.
sub | A stasis state subscriber |
The | subscriber's topic |
Definition at line 493 of file stasis_state.c.
References sub.
Referenced by ast_mwi_subscriber_topic().
struct stasis_topic * stasis_state_topic | ( | struct stasis_state_manager * | manager, |
const char * | id | ||
) |
Retrieve a managed topic creating one if not currently managed.
WARNING This function should not be called before adding a publisher or subscriber or it will cause a memory leak within the stasis state manager. This function is here in order to allow for compatibility with how things used to work.
Also much like the similar functionality from before it returns the stasis topic, but does not bump its reference.
manager | The manager object |
id | The unique id of/for the topic |
A | managed stasis topic. |
NULL | if an error occurred |
Definition at line 370 of file stasis_state.c.
References ao2_ref, stasis_state::manager, NULL, state, state_find_or_add, and stasis_state::topic.
Referenced by ast_mwi_topic().
void * stasis_state_unsubscribe | ( | struct stasis_state_subscriber * | sub | ) |
Unsubscribe from the stasis topic and stasis state.
sub | A stasis state subscriber |
NULL |
Definition at line 471 of file stasis_state.c.
References ao2_ref, NULL, stasis_unsubscribe(), and sub.
Referenced by ast_mwi_unsubscribe().
void * stasis_state_unsubscribe_and_join | ( | struct stasis_state_subscriber * | sub | ) |
Unsubscribe from the stasis topic, block until the final message is received, and then unsubscribe from stasis state.
sub | A stasis state subscriber |
NULL |
Definition at line 478 of file stasis_state.c.
References ao2_ref, NULL, stasis_unsubscribe_and_join(), and sub.
Referenced by ast_mwi_unsubscribe_and_join(), and subscriptions_destroy().
|
static |
Definition at line 168 of file stasis_state.c.
References __ao2_alloc(), stasis_state_manager::all_topic, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_bump, ao2_cleanup, ao2_link_flags, ao2_ref, ao2_t_weakproxy_alloc, ao2_t_weakproxy_set_object, ao2_weakproxy_subscribe(), ast_asprintf, ast_assert, ast_free, ast_log, AST_VECTOR_INIT, make_ari_stubs::file, stasis_state_proxy::id, LOG_ERROR, stasis_state_proxy::manager, stasis_state::manager, name, NULL, OBJ_NOLOCK, stasis_forward_all(), stasis_topic_create(), stasis_topic_name(), state, state_dtor(), state_id_by_topic(), state_proxy_dtor(), state_proxy_sub_cb(), and stasis_state_manager::states.
Referenced by __state_find_or_add().
|
static |
Definition at line 121 of file stasis_state.c.
References ao2_cleanup, ast_assert, AST_VECTOR_FREE, AST_VECTOR_SIZE, NULL, and stasis_forward_cancel().
Referenced by state_alloc().
|
static |
Definition at line 621 of file stasis_state.c.
References ao2_ref, ast_eid_cmp(), ast_eid_default, AST_VECTOR_GET_ADDR, AST_VECTOR_REMOVE_UNORDERED, and AST_VECTOR_SIZE.
Referenced by stasis_state_remove_publish_by_id().
|
static |
Definition at line 587 of file stasis_state.c.
References ao2_ref, ast_eid_cmp(), ast_eid_default, AST_VECTOR_APPEND, AST_VECTOR_GET_ADDR, and AST_VECTOR_SIZE.
Referenced by stasis_state_publish_by_id().
|
static |
Definition at line 104 of file stasis_state.c.
References ast_assert, ast_begins_with(), id, manager_topic, NULL, and stasis_topic_name().
Referenced by __state_find_or_add(), and state_alloc().
|
static |
Definition at line 293 of file stasis_state.c.
References stasis_state_manager::all_topic, ao2_cleanup, ao2_container_unregister(), ast_alloca, AST_VECTOR_RW_FREE, NULL, stasis_topic_name(), and stasis_state_manager::states.
Referenced by stasis_state_manager_create().
|
static |
Definition at line 136 of file stasis_state.c.
References ao2_cleanup, and stasis_state_proxy::manager.
Referenced by state_alloc().
|
static |
Definition at line 142 of file stasis_state.c.
References ao2_unlink, stasis_state_proxy::manager, and stasis_state_manager::states.
Referenced by state_alloc().
|
static |
Definition at line 392 of file stasis_state.c.
References ao2_lock, ao2_ref, ao2_unlock, AST_VECTOR_GET, AST_VECTOR_RW_RDLOCK, AST_VECTOR_RW_UNLOCK, AST_VECTOR_SIZE, and sub.
Referenced by stasis_state_add_subscriber().