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