66 struct timeval delta = {
67 .tv_sec = timeout_millis / 1000,
68 .tv_usec = (timeout_millis % 1000) * 1000,
70 struct timeval deadline_tv =
ast_tvadd(start, delta);
71 struct timespec deadline = {
72 .tv_sec = deadline_tv.tv_sec,
73 .tv_nsec = 1000 * deadline_tv.tv_usec,
89 sink->max_messages = 4;
91 ast_malloc(
sizeof(*sink->messages) * sink->max_messages);
92 if (!sink->messages) {
130 sizeof(*new_messages) * new_max_messages);
150 int num_messages,
int timeout_millis)
158 if (r == ETIMEDOUT) {
171 int num_messages,
int timeout_millis)
179 if (r == ETIMEDOUT) {
202 if (r == ETIMEDOUT) {
214 while (!cmp_cb(sink->
messages[start], data)) {
219 &sink->
lock, &deadline);
221 if (r == ETIMEDOUT) {
226 "Unexpected condition error: %s\n",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
#define ast_malloc(len)
A wrapper for malloc()
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
struct stasis_message_type * stasis_test_message_type(void)
Gets the type of messages created by stasis_test_message_create().
struct stasis_message * stasis_test_message_create(void)
Creates a test message.
#define ast_cond_destroy(cond)
#define ast_cond_wait(cond, mutex)
#define ast_cond_init(cond, attr)
#define ast_cond_timedwait(cond, mutex, time)
#define ast_mutex_init(pmutex)
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
#define ast_mutex_destroy(a)
#define ast_cond_signal(cond)
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
struct stasis_forward * sub
int stasis_message_sink_should_stay(struct stasis_message_sink *sink, int num_messages, int timeout_millis)
Ensures that no new messages are received.
static void message_sink_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Implementation of the stasis_message_sink_cb() callback.
static struct timespec make_deadline(int timeout_millis)
static void stasis_message_sink_dtor(void *obj)
STASIS_MESSAGE_TYPE_DEFN(stasis_test_message_type)
int stasis_message_sink_wait_for_count(struct stasis_message_sink *sink, int num_messages, int timeout_millis)
Wait for a sink's num_messages field to reach a certain level.
int stasis_message_sink_wait_for(struct stasis_message_sink *sink, int start, stasis_wait_cb cmp_cb, const void *data, int timeout_millis)
Wait for a message that matches the given criteria.
static int load_module(void)
static int unload_module(void)
struct stasis_message_sink * stasis_message_sink_create(void)
Create a message sink.
stasis_subscription_cb stasis_message_sink_cb(void)
Topic callback to receive messages.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
void(* stasis_subscription_cb)(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Callback function type for Stasis subscriptions.
#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.
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.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
Test infrastructure for dealing with Stasis.
int(* stasis_wait_cb)(struct stasis_message *msg, const void *data)
Structure that collects messages from a topic.
struct stasis_message ** messages
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.