32#define test_category "/stasis/core/state/"
34#define TOPIC_COUNT 500
36#define MANAGER_TOPIC "foo"
69 ast_log(
LOG_ERROR,
"Unable to convert the state's id '%s' to numeric\n",
id);
90 if (foo->
bar != num) {
125 ast_log(
LOG_ERROR,
"Failed to destroy all subscriptions: running=%zu, sum=%zu\n",
150 if (snprintf(
id, 10,
"%zu", i) == -1) {
157 ast_log(
LOG_ERROR,
"Failed to create a state subscriber for id '%s'\n",
id);
172 ast_log(
LOG_ERROR,
"Failed to create all subscriptions: running=%zu, sum=%zu\n",
196 if (snprintf(
id, 10,
"%zu", i) == -1) {
220 if (snprintf(
id, 10,
"%zu", i) == -1) {
233 ast_log(
LOG_ERROR,
"Failed to add to publisher to vector for id '%s'\n",
id);
261 ast_log(
LOG_ERROR,
"Unable to convert the state's id '%s' to numeric\n",
id);
368 info->name = __func__;
370 info->summary =
"Test implicit publishing of stasis state";
378 ast_test_validate(
test, manager !=
NULL);
395 if (
ao2_ref(manager, 0) != 1) {
412 info->name = __func__;
414 info->summary =
"Test explicit publishing of stasis state";
422 ast_test_validate(
test, manager !=
NULL);
440 if (
ao2_ref(manager, 0) != 1) {
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
Conversion utility functions.
int ast_str_to_umax(const char *str, uintmax_t *res)
Convert the given string to an unsigned max size integer.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
static void * cleanup(void *unused)
struct stasis_forward * sub
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message * stasis_message_create_full(struct stasis_message_type *type, void *data, const struct ast_eid *eid)
Create a new message for an entity.
void stasis_state_callback_all(struct stasis_state_manager *manager, on_stasis_state handler, void *data)
For each managed state call the given handler.
struct stasis_state_manager * stasis_state_manager_create(const char *topic_name)
Create a stasis state manager.
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.
int(* on_stasis_state)(const char *id, struct stasis_message *msg, void *user_data)
The delegate called for each managed state.
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).
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 fr...
int stasis_state_add_observer(struct stasis_state_manager *manager, struct stasis_state_observer *observer)
Add an observer to receive managed state related events.
const char * stasis_state_publisher_id(const struct stasis_state_publisher *pub)
Retrieve the publisher's underlying state's unique id.
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.
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.
void stasis_state_publish(struct stasis_state_publisher *pub, struct stasis_message *msg)
Publish to a managed state (topic) using a publisher.
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.
void * stasis_state_subscriber_data(struct stasis_state_subscriber *sub)
Retrieve the last known state stasis message payload for the subscriber.
Managed stasis state event interface.
void(* on_subscribe)(const char *id, struct stasis_state_subscriber *sub)
Raised when any managed state is being subscribed.
#define AST_TEST_REGISTER(cb)
#define AST_TEST_UNREGISTER(cb)
static void handle_validate(const char *id, struct stasis_state_subscriber *sub)
struct stasis_message_type * foo_type(void)
static int publishers_destroy(struct stasis_state_manager *manager, struct publishers *pubs)
static int implicit_publish_cb(const char *id, struct stasis_message *msg, void *user_data)
AST_TEST_DEFINE(implicit_publish)
static void foo_type_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static struct stasis_message * create_foo_type_message(const char *id)
struct stasis_state_observer foo_observer
static int publishers_create(struct stasis_state_manager *manager, struct publishers *pubs)
static int explicit_publish_cb(const char *id, struct stasis_message *msg, void *user_data)
STASIS_MESSAGE_TYPE_DEFN(foo_type)
static int load_module(void)
static size_t running_total
static int unload_module(void)
static int subscriptions_destroy(struct stasis_state_manager *manager, struct subscriptions *subs)
static int publish(struct stasis_state_manager *manager, on_stasis_state cb, void *user_data)
static int validate_data(const char *id, struct foo_data *foo)
static int subscriptions_create(struct stasis_state_manager *manager, struct subscriptions *subs)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
#define AST_VECTOR(name, type)
Define a vector structure.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.