Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
Data Structures | Macros | Functions
stasis_message_router.c File Reference

Stasis message router implementation. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/vector.h"
Include dependency graph for stasis_message_router.c:

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_routeroute_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_routerstasis_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...
 

Detailed Description

Stasis message router implementation.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file stasis_message_router.c.

Macro Definition Documentation

◆ ROUTE_TABLE_ELEM_CLEANUP

#define ROUTE_TABLE_ELEM_CLEANUP (   elem)    ao2_cleanup((elem).message_type)

route_table vector element cleanup.

Parameters
elemElement to cleanup

Definition at line 86 of file stasis_message_router.c.

◆ ROUTE_TABLE_ELEM_CMP

#define ROUTE_TABLE_ELEM_CMP (   elem,
  value 
)    ((elem).message_type == (value))

route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED()

Parameters
elemElement to compare against
valueValue to compare with the vector element.
Returns
0 if element does not match.
Non-zero if element matches.

Definition at line 79 of file stasis_message_router.c.

Function Documentation

◆ __stasis_message_router_create()

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.

246{
247 return stasis_message_router_create_internal(topic, 0, file, lineno, func);
248}
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)

References make_ari_stubs::file, and stasis_message_router_create_internal().

◆ __stasis_message_router_create_pool()

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.

252{
253 return stasis_message_router_create_internal(topic, 1, file, lineno, func);
254}

References make_ari_stubs::file, and stasis_message_router_create_internal().

◆ find_route()

static int find_route ( struct stasis_message_router router,
struct stasis_message message,
struct stasis_message_route route_out 
)
static

Definition at line 153 of file stasis_message_router.c.

157{
158 struct stasis_message_route *route = NULL;
161
162 ast_assert(route_out != NULL);
163
165 /* Find a cache route */
168 route = route_table_find(&router->cache_routes, update->type);
169 }
170
171 if (route == NULL) {
172 /* Find a regular route */
174 }
175
176 if (route == NULL && router->default_route.callback) {
177 /* Maybe the default route, then? */
178 route = &router->default_route;
179 }
180
181 if (!route) {
182 return -1;
183 }
184
185 *route_out = *route;
186 return 0;
187}
ast_mutex_t lock
Definition: app_sla.c:331
static const char type[]
Definition: chan_ooh323.c:109
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
struct stasis_message_type * stasis_cache_update_type(void)
Message type for cache update messages.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Definition: lock.h:604
static struct stasis_message_router * router
#define NULL
Definition: resample.c:96
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
static struct stasis_message_route * route_table_find(struct route_table *table, struct stasis_message_type *message_type)
Cache update message.
Definition: stasis.h:965
stasis_subscription_cb callback
struct route_table cache_routes
struct stasis_message_route default_route
#define ast_assert(a)
Definition: utils.h:739

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().

◆ route_table_add()

static int route_table_add ( struct route_table table,
struct stasis_message_type message_type,
stasis_subscription_cb  callback,
void *  data 
)
static

Definition at line 95 of file stasis_message_router.c.

98{
99 struct stasis_message_route route;
100 int res;
101
104
105 route.message_type = ao2_bump(message_type);
106 route.callback = callback;
107 route.data = data;
108
109 res = AST_VECTOR_APPEND(table, route);
110 if (res) {
112 }
113 return res;
114}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
static char * table
Definition: cdr_odbc.c:55
#define ROUTE_TABLE_ELEM_CLEANUP(elem)
route_table vector element cleanup.
struct stasis_message_type * message_type
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

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().

◆ route_table_dtor()

static void route_table_dtor ( struct route_table table)
static

Definition at line 116 of file stasis_message_router.c.

117{
118 size_t idx;
119 struct stasis_message_route *route;
120
121 for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
122 route = AST_VECTOR_GET_ADDR(table, idx);
124 }
126}
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_GET_ADDR(vec, idx)
Get an address of element in a vector.
Definition: vector.h:668

References AST_VECTOR_FREE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, ROUTE_TABLE_ELEM_CLEANUP, and table.

Referenced by router_dtor().

◆ route_table_find()

static struct stasis_message_route * route_table_find ( struct route_table table,
struct stasis_message_type message_type 
)
static

Definition at line 48 of file stasis_message_router.c.

50{
51 size_t idx;
52 struct stasis_message_route *route;
53
54 /* While a linear search for routes may seem very inefficient, most
55 * route tables have six routes or less. For such small data, it's
56 * hard to beat a linear search. If we start having larger route
57 * tables, then we can look into containers with more efficient
58 * lookups.
59 */
60 for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
61 route = AST_VECTOR_GET_ADDR(table, idx);
62 if (route->message_type == message_type) {
63 return route;
64 }
65 }
66
67 return NULL;
68}

References AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, stasis_message_route::message_type, NULL, and table.

Referenced by find_route(), and route_table_add().

◆ route_table_remove()

static int route_table_remove ( struct route_table table,
struct stasis_message_type message_type 
)
static

Definition at line 88 of file stasis_message_router.c.

90{
93}
#define ROUTE_TABLE_ELEM_CMP(elem, value)
route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED()
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
Definition: vector.h:488

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().

◆ router_dispatch()

static void router_dispatch ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 189 of file stasis_message_router.c.

192{
193 struct stasis_message_router *router = data;
194 struct stasis_message_route route;
195
196 if (find_route(router, message, &route) == 0) {
197 route.callback(route.data, sub, message);
198 }
199
202 }
203}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct stasis_forward * sub
Definition: res_corosync.c:240
int stasis_subscription_final_message(struct stasis_subscription *sub, struct stasis_message *msg)
Determine whether a message is the final message to be received on a subscription.
Definition: stasis.c:1174
static int find_route(struct stasis_message_router *router, struct stasis_message *message, struct stasis_message_route *route_out)

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().

◆ router_dtor()

static void router_dtor ( void *  obj)
static

Definition at line 140 of file stasis_message_router.c.

141{
142 struct stasis_message_router *router = obj;
143
146
148
151}
int stasis_subscription_is_done(struct stasis_subscription *subscription)
Returns whether subscription has received its final message.
Definition: stasis.c:1118
int stasis_subscription_is_subscribed(const struct stasis_subscription *sub)
Returns whether a subscription is currently subscribed.
Definition: stasis.c:1150
static void route_table_dtor(struct route_table *table)
struct stasis_subscription * subscription

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().

◆ stasis_message_router_accept_formatters()

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.

Warning
With direct subscriptions, adding a formatter filter is an OR operation with any message type filters. In the current implementation of message router however, it's an AND operation. Even when setting a default route, the callback will only get messages that have the formatters provides in this call.
Parameters
routerRouter to set the formatters of.
formattersA bitmap of stasis_subscription_message_formatters we wish to receive.
Since
13.25.0
16.2.0

Definition at line 418 of file stasis_message_router.c.

420{
422
424
425 return;
426}
void stasis_subscription_accept_formatters(struct stasis_subscription *subscription, enum stasis_subscription_message_formatters formatters)
Indicate to a subscription that we are interested in messages with one or more formatters.
Definition: stasis.c:1093

References ast_assert, NULL, router, stasis_subscription_accept_formatters(), and stasis_message_router::subscription.

◆ stasis_message_router_add()

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.

Parameters
routerRouter to add the route to.
message_typeType of message to route.
callbackCallback to forward messages of message_type to.
dataData pointer to pass to callback.
Return values
0on success
-1on failure
Since
12

Definition at line 308 of file stasis_message_router.c.

311{
312 int res;
313
315
316 if (!message_type) {
317 /* Cannot route to NULL type. */
318 return -1;
319 }
321 res = route_table_add(&router->routes, message_type, callback, data);
322 if (!res) {
324 /* Until a specific message type was added we would already drop the message, so being
325 * selective now doesn't harm us. If we have a default route then we are already forced
326 * to filter nothing and messages will come in regardless.
327 */
329 }
331 return res;
332}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition: stasis.h:297
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition: stasis.c:1023
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition: stasis.c:1077
static int route_table_add(struct route_table *table, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)

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().

◆ stasis_message_router_add_cache_update()

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.

Parameters
routerRouter to add the route to.
message_typeSubtype of cache update to route.
callbackCallback to forward messages of message_type to.
dataData pointer to pass to callback.
Return values
0on success
-1on failure
Since
12

Definition at line 334 of file stasis_message_router.c.

337{
338 int res;
339
341
342 if (!message_type) {
343 /* Cannot cache a route to NULL type. */
344 return -1;
345 }
347 res = route_table_add(&router->cache_routes, message_type, callback, data);
348 if (!res) {
351 }
353 return res;
354}

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().

◆ stasis_message_router_create_internal()

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 
)
static

Definition at line 205 of file stasis_message_router.c.

208{
209 int res;
211
213 if (!router) {
214 return NULL;
215 }
216
217 res = 0;
218 res |= AST_VECTOR_INIT(&router->routes, 0);
220 if (res) {
221 ao2_ref(router, -1);
222
223 return NULL;
224 }
225
226 if (use_thread_pool) {
228 } else {
230 }
231
232 if (!router->subscription) {
233 ao2_ref(router, -1);
234
235 return NULL;
236 }
237
238 /* We need to receive subscription change messages so we know when our subscription goes away */
240
241 return router;
242}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_t_alloc(data_size, destructor_fn, debug_msg)
Definition: astobj2.h:407
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
const char * stasis_topic_name(const struct stasis_topic *topic)
Return the name of a topic.
Definition: stasis.c:627
struct stasis_subscription * __stasis_subscribe_pool(struct stasis_topic *topic, stasis_subscription_cb callback, void *data, const char *file, int lineno, const char *func)
Create a subscription whose callbacks occur on a thread pool.
Definition: stasis.c:953
struct stasis_subscription * __stasis_subscribe(struct stasis_topic *topic, stasis_subscription_cb callback, void *data, const char *file, int lineno, const char *func)
Create a subscription.
Definition: stasis.c:942
static void router_dispatch(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static void router_dtor(void *obj)
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

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().

◆ stasis_message_router_is_done()

int stasis_message_router_is_done ( struct stasis_message_router router)

Returns whether router has received its final message.

Parameters
routerRouter.
Return values
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.

277{
278 if (!router) {
279 /* Null router is about as done as you can get */
280 return 1;
281 }
282
284}

References router, stasis_subscription_is_done(), and stasis_message_router::subscription.

Referenced by endpoint_dtor().

◆ stasis_message_router_publish_sync()

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.

Parameters
routerRouter
messageThe 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.

Since
12.1.0

Definition at line 286 of file stasis_message_router.c.

288{
290
294}
void stasis_publish_sync(struct stasis_subscription *sub, struct stasis_message *message)
Publish a message to a topic's subscribers, synchronizing on the specified subscriber.
Definition: stasis.c:1516

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().

◆ stasis_message_router_remove()

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.

Parameters
routerRouter to remove the route from.
message_typeType of message to route.
Since
12

Definition at line 356 of file stasis_message_router.c.

358{
360
361 if (!message_type) {
362 /* Cannot remove a NULL type. */
363 return;
364 }
366 route_table_remove(&router->routes, message_type);
368}
static int route_table_remove(struct route_table *table, struct stasis_message_type *message_type)

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().

◆ stasis_message_router_remove_cache_update()

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.

Parameters
routerRouter to remove the route from.
message_typeType of message to route.
Since
12

Definition at line 370 of file stasis_message_router.c.

373{
375
376 if (!message_type) {
377 /* Cannot remove a NULL type. */
378 return;
379 }
381 route_table_remove(&router->cache_routes, message_type);
383}

References ao2_lock, ao2_unlock, ast_assert, stasis_message_router::cache_routes, NULL, route_table_remove(), and router.

◆ stasis_message_router_set_congestion_limits()

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.

Since
13.10.0
Parameters
routerPointer to a stasis message router
low_waterNew queue low water mark. (-1 to set as 90% of high_water)
high_waterNew queue high water mark.
Return values
0on success.
-1on error (water marks not changed).

Definition at line 296 of file stasis_message_router.c.

298{
299 int res = -1;
300
301 if (router) {
303 low_water, high_water);
304 }
305 return res;
306}
int stasis_subscription_set_congestion_limits(struct stasis_subscription *subscription, long low_water, long high_water)
Set the high and low alert water marks of the stasis subscription.
Definition: stasis.c:1011

References router, stasis_subscription_set_congestion_limits(), and stasis_message_router::subscription.

Referenced by create_routes(), load_module(), and manager_subscriptions_init().

◆ stasis_message_router_set_default()

int stasis_message_router_set_default ( struct stasis_message_router router,
stasis_subscription_cb  callback,
void *  data 
)

Sets the default route of a router.

Parameters
routerRouter to set the default route of.
callbackCallback to forward messages which otherwise have no home.
dataData pointer to pass to callback.
Return values
0on success
-1on failure
Since
12
Note
Setting a default callback will automatically cause the underlying subscription to receive all messages and not be filtered. If filtering is desired then a specific route for each message type should be provided.

Definition at line 385 of file stasis_message_router.c.

388{
390
391 /* While this implementation can never fail, it used to be able to */
392 return 0;
393}
@ STASIS_SUBSCRIPTION_FORMATTER_NONE
Definition: stasis.h:309
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.

References router, stasis_message_router_set_formatters_default(), and STASIS_SUBSCRIPTION_FORMATTER_NONE.

Referenced by AST_TEST_DEFINE(), load_module(), and setup_stasis_subs().

◆ stasis_message_router_set_formatters_default()

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.

Parameters
routerRouter to set the default route of.
callbackCallback to forward messages which otherwise have no home.
dataData pointer to pass to callback.
formattersA bitmap of stasis_subscription_message_formatters we wish to receive.
Since
13.26.0
16.3.0
Note
If formatters are specified then the message router will remain in a selective filtering state. Any explicit routes will receive messages of their message type and the default callback will only receive messages that have one of the given formatters. Explicit routes will not be filtered according to the given formatters.

Definition at line 395 of file stasis_message_router.c.

399{
401 ast_assert(callback != NULL);
402
404
406 router->default_route.callback = callback;
407 router->default_route.data = data;
409
410 if (formatters == STASIS_SUBSCRIPTION_FORMATTER_NONE) {
411 /* Formatters govern what messages the default callback get, so it is only if none is
412 * specified that we accept all messages regardless.
413 */
415 }
416}
@ STASIS_SUBSCRIPTION_FILTER_FORCED_NONE
Definition: stasis.h:296

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().

◆ stasis_message_router_unsubscribe()

void stasis_message_router_unsubscribe ( struct stasis_message_router router)

Unsubscribe the router from the upstream topic.

Parameters
routerRouter to unsubscribe.
Since
12

Definition at line 256 of file stasis_message_router.c.

257{
258 if (!router) {
259 return;
260 }
261
265}
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition: stasis.c:971

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().

◆ stasis_message_router_unsubscribe_and_join()

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().

Parameters
routerRouter to unsubscribe.
Since
12

Definition at line 267 of file stasis_message_router.c.

269{
270 if (!router) {
271 return;
272 }
274}
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Definition: stasis.c:1134

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().