Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Stasis message router implementation. More...
#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Data Structures | |
struct | route_table |
struct | stasis_message_route |
struct | stasis_message_router |
Macros | |
#define | ROUTE_TABLE_ELEM_CLEANUP(elem) ao2_cleanup((elem).message_type) |
route_table vector element cleanup. More... | |
#define | ROUTE_TABLE_ELEM_CMP(elem, value) ((elem).message_type == (value)) |
route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED() More... | |
Functions | |
struct stasis_message_router * | __stasis_message_router_create (struct stasis_topic *topic, const char *file, int lineno, const char *func) |
struct stasis_message_router * | __stasis_message_router_create_pool (struct stasis_topic *topic, const char *file, int lineno, const char *func) |
static int | find_route (struct stasis_message_router *router, struct stasis_message *message, struct stasis_message_route *route_out) |
static int | route_table_add (struct route_table *table, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data) |
static void | route_table_dtor (struct route_table *table) |
static struct stasis_message_route * | route_table_find (struct route_table *table, struct stasis_message_type *message_type) |
static int | route_table_remove (struct route_table *table, struct stasis_message_type *message_type) |
static void | router_dispatch (void *data, struct stasis_subscription *sub, struct stasis_message *message) |
static void | router_dtor (void *obj) |
void | stasis_message_router_accept_formatters (struct stasis_message_router *router, enum stasis_subscription_message_formatters formatters) |
Indicate to a message router that we are interested in messages with one or more formatters. More... | |
int | stasis_message_router_add (struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data) |
Add a route to a message router. More... | |
int | stasis_message_router_add_cache_update (struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data) |
Add a route for stasis_cache_update messages to a message router. More... | |
static struct stasis_message_router * | stasis_message_router_create_internal (struct stasis_topic *topic, int use_thread_pool, const char *file, int lineno, const char *func) |
int | stasis_message_router_is_done (struct stasis_message_router *router) |
Returns whether router has received its final message. More... | |
void | stasis_message_router_publish_sync (struct stasis_message_router *router, struct stasis_message *message) |
Publish a message to a message router's subscription synchronously. More... | |
void | stasis_message_router_remove (struct stasis_message_router *router, struct stasis_message_type *message_type) |
Remove a route from a message router. More... | |
void | stasis_message_router_remove_cache_update (struct stasis_message_router *router, struct stasis_message_type *message_type) |
Remove a cache route from a message router. More... | |
int | stasis_message_router_set_congestion_limits (struct stasis_message_router *router, long low_water, long high_water) |
Set the high and low alert water marks of the stasis message router. More... | |
int | stasis_message_router_set_default (struct stasis_message_router *router, stasis_subscription_cb callback, void *data) |
Sets the default route of a router. More... | |
void | stasis_message_router_set_formatters_default (struct stasis_message_router *router, stasis_subscription_cb callback, void *data, enum stasis_subscription_message_formatters formatters) |
Sets the default route of a router with formatters. More... | |
void | stasis_message_router_unsubscribe (struct stasis_message_router *router) |
Unsubscribe the router from the upstream topic. More... | |
void | stasis_message_router_unsubscribe_and_join (struct stasis_message_router *router) |
Unsubscribe the router from the upstream topic, blocking until the final message has been processed. More... | |
Stasis message router implementation.
Definition in file stasis_message_router.c.
#define ROUTE_TABLE_ELEM_CLEANUP | ( | elem | ) | ao2_cleanup((elem).message_type) |
route_table vector element cleanup.
elem | Element to cleanup |
Definition at line 86 of file stasis_message_router.c.
route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED()
elem | Element to compare against |
value | Value to compare with the vector element. |
Definition at line 79 of file stasis_message_router.c.
struct stasis_message_router * __stasis_message_router_create | ( | struct stasis_topic * | topic, |
const char * | file, | ||
int | lineno, | ||
const char * | func | ||
) |
Definition at line 244 of file stasis_message_router.c.
References make_ari_stubs::file, and stasis_message_router_create_internal().
struct stasis_message_router * __stasis_message_router_create_pool | ( | struct stasis_topic * | topic, |
const char * | file, | ||
int | lineno, | ||
const char * | func | ||
) |
Definition at line 250 of file stasis_message_router.c.
References make_ari_stubs::file, and stasis_message_router_create_internal().
|
static |
Definition at line 153 of file stasis_message_router.c.
References ast_assert, stasis_message_router::cache_routes, stasis_message_route::callback, stasis_message_router::default_route, lock, NULL, route_table_find(), router, stasis_message_router::routes, SCOPED_AO2LOCK, stasis_cache_update_type(), stasis_message_data(), stasis_message_type(), type, and update().
Referenced by router_dispatch().
|
static |
Definition at line 95 of file stasis_message_router.c.
References ao2_bump, ast_assert, AST_VECTOR_APPEND, stasis_message_route::callback, stasis_message_route::data, stasis_message_route::message_type, NULL, ROUTE_TABLE_ELEM_CLEANUP, route_table_find(), and table.
Referenced by stasis_message_router_add(), and stasis_message_router_add_cache_update().
|
static |
Definition at line 116 of file stasis_message_router.c.
References AST_VECTOR_FREE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, ROUTE_TABLE_ELEM_CLEANUP, and table.
Referenced by router_dtor().
|
static |
Definition at line 48 of file stasis_message_router.c.
References AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, stasis_message_route::message_type, NULL, and table.
Referenced by find_route(), and route_table_add().
|
static |
Definition at line 88 of file stasis_message_router.c.
References AST_VECTOR_REMOVE_CMP_UNORDERED, stasis_message_route::message_type, ROUTE_TABLE_ELEM_CLEANUP, ROUTE_TABLE_ELEM_CMP, and table.
Referenced by stasis_message_router_remove(), and stasis_message_router_remove_cache_update().
|
static |
Definition at line 189 of file stasis_message_router.c.
References ao2_cleanup, stasis_message_route::callback, stasis_message_route::data, find_route(), router, stasis_subscription_final_message(), and sub.
Referenced by stasis_message_router_create_internal().
|
static |
Definition at line 140 of file stasis_message_router.c.
References ast_assert, stasis_message_router::cache_routes, NULL, route_table_dtor(), router, stasis_message_router::routes, stasis_subscription_is_done(), stasis_subscription_is_subscribed(), and stasis_message_router::subscription.
Referenced by stasis_message_router_create_internal().
void stasis_message_router_accept_formatters | ( | struct stasis_message_router * | router, |
enum stasis_subscription_message_formatters | formatters | ||
) |
Indicate to a message router that we are interested in messages with one or more formatters.
The formatters are passed on to the underlying subscription.
router | Router to set the formatters of. |
formatters | A bitmap of stasis_subscription_message_formatters we wish to receive. |
Definition at line 418 of file stasis_message_router.c.
References ast_assert, NULL, router, stasis_subscription_accept_formatters(), and stasis_message_router::subscription.
int stasis_message_router_add | ( | struct stasis_message_router * | router, |
struct stasis_message_type * | message_type, | ||
stasis_subscription_cb | callback, | ||
void * | data | ||
) |
Add a route to a message router.
A particular message_type may have at most one route per router. If you route stasis_cache_update messages, the callback will only receive updates for types not handled by routes added with stasis_message_router_add_cache_update().
Adding multiple routes for the same message type results in undefined behavior.
router | Router to add the route to. |
message_type | Type of message to route. |
callback | Callback to forward messages of message_type to. |
data | Data pointer to pass to callback. |
0 | on success |
-1 | on failure |
Definition at line 308 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, ast_assert, NULL, route_table_add(), router, stasis_message_router::routes, stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and stasis_message_router::subscription.
Referenced by app_create(), AST_TEST_DEFINE(), create_routes(), endpoint_internal_create(), forwards_create_endpoint(), load_general_config(), load_module(), manager_bridging_init(), manager_channels_init(), manager_confbridge_init(), manager_endpoints_init(), manager_mwi_init(), manager_subscriptions_init(), meetme_stasis_init(), pjsip_outbound_registration_metrics_init(), and setup_stasis_subs().
int stasis_message_router_add_cache_update | ( | struct stasis_message_router * | router, |
struct stasis_message_type * | message_type, | ||
stasis_subscription_cb | callback, | ||
void * | data | ||
) |
Add a route for stasis_cache_update messages to a message router.
A particular message_type may have at most one cache route per router. These are distinct from regular routes, so one could have both a regular route and a cache route for the same message_type.
Adding multiple routes for the same message type results in undefined behavior.
router | Router to add the route to. |
message_type | Subtype of cache update to route. |
callback | Callback to forward messages of message_type to. |
data | Data pointer to pass to callback. |
0 | on success |
-1 | on failure |
Definition at line 334 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, ast_assert, stasis_message_router::cache_routes, NULL, route_table_add(), router, stasis_cache_update_type(), stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and stasis_message_router::subscription.
Referenced by app_create(), and AST_TEST_DEFINE().
|
static |
Definition at line 205 of file stasis_message_router.c.
References __stasis_subscribe(), __stasis_subscribe_pool(), ao2_ref, ao2_t_alloc, AST_VECTOR_INIT, stasis_message_router::cache_routes, make_ari_stubs::file, NULL, router, router_dispatch(), router_dtor(), stasis_message_router::routes, stasis_subscription_accept_message_type(), stasis_subscription_change_type(), stasis_topic_name(), and stasis_message_router::subscription.
Referenced by __stasis_message_router_create(), and __stasis_message_router_create_pool().
int stasis_message_router_is_done | ( | struct stasis_message_router * | router | ) |
Returns whether router has received its final message.
router | Router. |
True | (non-zero) if stasis_subscription_final_message() has been received. |
False | (zero) if waiting for the end. |
Definition at line 276 of file stasis_message_router.c.
References router, stasis_subscription_is_done(), and stasis_message_router::subscription.
Referenced by endpoint_dtor().
void stasis_message_router_publish_sync | ( | struct stasis_message_router * | router, |
struct stasis_message * | message | ||
) |
Publish a message to a message router's subscription synchronously.
router | Router |
message | The Stasis Message Bus API message |
This should be used when a message needs to be published synchronously to the underlying subscription created by a message router. This is analagous to stasis_publish_sync.
Note that the caller will be blocked until the thread servicing the message on the message router's subscription completes handling of the message.
Definition at line 286 of file stasis_message_router.c.
References ao2_bump, ao2_cleanup, ast_assert, NULL, router, stasis_publish_sync(), and stasis_message_router::subscription.
Referenced by ast_cdr_engine_term(), cdr_prop_write(), cdr_read(), cdr_write(), forkcdr_exec(), and publish_app_cdr_message().
void stasis_message_router_remove | ( | struct stasis_message_router * | router, |
struct stasis_message_type * | message_type | ||
) |
Remove a route from a message router.
If a route is removed from another thread, there is no notification that all messages using this route have been processed. This typically means that the associated data
pointer for this route must be kept until the route itself is disposed of.
router | Router to remove the route from. |
message_type | Type of message to route. |
Definition at line 356 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, ast_assert, NULL, route_table_remove(), router, and stasis_message_router::routes.
Referenced by cleanup_module(), load_general_config(), and unload_module().
void stasis_message_router_remove_cache_update | ( | struct stasis_message_router * | router, |
struct stasis_message_type * | message_type | ||
) |
Remove a cache route from a message router.
If a route is removed from another thread, there is no notification that all messages using this route have been processed. This typically means that the associated data
pointer for this route must be kept until the route itself is disposed of.
router | Router to remove the route from. |
message_type | Type of message to route. |
Definition at line 370 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, ast_assert, stasis_message_router::cache_routes, NULL, route_table_remove(), and router.
int stasis_message_router_set_congestion_limits | ( | struct stasis_message_router * | router, |
long | low_water, | ||
long | high_water | ||
) |
Set the high and low alert water marks of the stasis message router.
router | Pointer to a stasis message router |
low_water | New queue low water mark. (-1 to set as 90% of high_water) |
high_water | New queue high water mark. |
0 | on success. |
-1 | on error (water marks not changed). |
Definition at line 296 of file stasis_message_router.c.
References router, stasis_subscription_set_congestion_limits(), and stasis_message_router::subscription.
Referenced by create_routes(), load_module(), and manager_subscriptions_init().
int stasis_message_router_set_default | ( | struct stasis_message_router * | router, |
stasis_subscription_cb | callback, | ||
void * | data | ||
) |
Sets the default route of a router.
router | Router to set the default route of. |
callback | Callback to forward messages which otherwise have no home. |
data | Data pointer to pass to callback. |
0 | on success |
-1 | on failure |
Definition at line 385 of file stasis_message_router.c.
References router, stasis_message_router_set_formatters_default(), and STASIS_SUBSCRIPTION_FORMATTER_NONE.
Referenced by AST_TEST_DEFINE(), load_module(), and setup_stasis_subs().
void stasis_message_router_set_formatters_default | ( | struct stasis_message_router * | router, |
stasis_subscription_cb | callback, | ||
void * | data, | ||
enum stasis_subscription_message_formatters | formatters | ||
) |
Sets the default route of a router with formatters.
router | Router to set the default route of. |
callback | Callback to forward messages which otherwise have no home. |
data | Data pointer to pass to callback. |
formatters | A bitmap of stasis_subscription_message_formatters we wish to receive. |
Definition at line 395 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, ast_assert, stasis_message_route::callback, stasis_message_route::data, stasis_message_router::default_route, NULL, router, stasis_subscription_accept_formatters(), STASIS_SUBSCRIPTION_FILTER_FORCED_NONE, STASIS_SUBSCRIPTION_FORMATTER_NONE, stasis_subscription_set_filter(), and stasis_message_router::subscription.
Referenced by app_create(), manager_subscriptions_init(), and stasis_message_router_set_default().
void stasis_message_router_unsubscribe | ( | struct stasis_message_router * | router | ) |
Unsubscribe the router from the upstream topic.
router | Router to unsubscribe. |
Definition at line 256 of file stasis_message_router.c.
References ao2_lock, ao2_unlock, router, stasis_unsubscribe(), and stasis_message_router::subscription.
Referenced by app_shutdown(), ast_endpoint_shutdown(), AST_TEST_DEFINE(), manager_confbridge_shutdown(), meetme_stasis_cleanup(), remove_stasis_subscriptions(), and setup_stasis_subs().
void stasis_message_router_unsubscribe_and_join | ( | struct stasis_message_router * | router | ) |
Unsubscribe the router from the upstream topic, blocking until the final message has been processed.
See stasis_unsubscribe_and_join() for info on when to use this vs. stasis_message_router_unsubscribe().
router | Router to unsubscribe. |
Definition at line 267 of file stasis_message_router.c.
References router, stasis_unsubscribe_and_join(), and stasis_message_router::subscription.
Referenced by AST_TEST_DEFINE(), cdr_engine_shutdown(), cleanup_module(), destroy_routes(), manager_endpoints_shutdown(), manager_shutdown(), pjsip_outbound_registration_metrics_unload_cb(), and unload_module().