Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
test_stasis_state.c File Reference
#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/conversions.h"
#include "asterisk/module.h"
#include "asterisk/stasis_state.h"
#include "asterisk/test.h"
Include dependency graph for test_stasis_state.c:

Go to the source code of this file.

Data Structures

struct  foo_data
 
struct  publishers
 
struct  subscriptions
 

Macros

#define MANAGER_TOPIC   "foo"
 
#define test_category   "/stasis/core/state/"
 
#define TOPIC_COUNT   500
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (explicit_publish)
 
 AST_TEST_DEFINE (implicit_publish)
 
static struct stasis_messagecreate_foo_type_message (const char *id)
 
static int explicit_publish_cb (const char *id, struct stasis_message *msg, void *user_data)
 
struct stasis_message_typefoo_type (void)
 
static void foo_type_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void handle_validate (const char *id, struct stasis_state_subscriber *sub)
 
static int implicit_publish_cb (const char *id, struct stasis_message *msg, void *user_data)
 
static int load_module (void)
 
static int publish (struct stasis_state_manager *manager, on_stasis_state cb, void *user_data)
 
static int publishers_create (struct stasis_state_manager *manager, struct publishers *pubs)
 
static int publishers_destroy (struct stasis_state_manager *manager, struct publishers *pubs)
 
 STASIS_MESSAGE_TYPE_DEFN (foo_type)
 
static int subscriptions_create (struct stasis_state_manager *manager, struct subscriptions *subs)
 
static int subscriptions_destroy (struct stasis_state_manager *manager, struct subscriptions *subs)
 
static int unload_module (void)
 
static int validate_data (const char *id, struct foo_data *foo)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Stasis state testing" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static int expect_null
 
struct stasis_state_observer foo_observer
 
static size_t running_total
 
static size_t sum_total
 

Macro Definition Documentation

◆ MANAGER_TOPIC

#define MANAGER_TOPIC   "foo"

Definition at line 36 of file test_stasis_state.c.

◆ test_category

#define test_category   "/stasis/core/state/"

Definition at line 32 of file test_stasis_state.c.

◆ TOPIC_COUNT

#define TOPIC_COUNT   500

Definition at line 34 of file test_stasis_state.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 470 of file test_stasis_state.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 470 of file test_stasis_state.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 470 of file test_stasis_state.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( explicit_publish  )

Definition at line 403 of file test_stasis_state.c.

404{
405 RAII_VAR(struct stasis_state_manager *, manager, NULL, ao2_cleanup);
406 struct subscriptions subs;
407 struct publishers pubs;
408 int rc = AST_TEST_PASS;
409
410 switch (cmd) {
411 case TEST_INIT:
412 info->name = __func__;
413 info->category = test_category;
414 info->summary = "Test explicit publishing of stasis state";
415 info->description = info->summary;
416 return AST_TEST_NOT_RUN;
417 case TEST_EXECUTE:
418 break;
419 }
420
422 ast_test_validate(test, manager != NULL);
423
424 ast_test_validate(test, !subscriptions_create(manager, &subs));
425 ast_test_validate_cleanup(test, !publishers_create(manager, &pubs), rc, cleanup);
426
427 ast_test_validate_cleanup(test, !publish(manager, explicit_publish_cb, &pubs),
428 rc, cleanup);
429
430cleanup:
431 if (subscriptions_destroy(manager, &subs) || publishers_destroy(manager, &pubs)) {
432 return AST_TEST_FAIL;
433 }
434
435 /*
436 * State subscriptions add a ref a state. The state in turn adds a ref
437 * to the manager. So if more than one ref is held on the manager before
438 * exiting, there is a ref leak some place.
439 */
440 if (ao2_ref(manager, 0) != 1) {
441 ast_log(LOG_ERROR, "Memory leak - Too many references held on manager\n");
442 return AST_TEST_FAIL;
443 }
444
445 return rc;
446}
#define ast_log
Definition astobj2.c:42
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define LOG_ERROR
unsigned char publish
static void cleanup(void)
Clean up any old apps that we don't need any more.
Definition res_stasis.c:327
#define NULL
Definition resample.c:96
struct stasis_state_manager * stasis_state_manager_create(const char *topic_name)
Create a stasis state manager.
@ TEST_INIT
Definition test.h:200
@ TEST_EXECUTE
Definition test.h:201
@ AST_TEST_PASS
Definition test.h:195
@ AST_TEST_FAIL
Definition test.h:196
@ AST_TEST_NOT_RUN
Definition test.h:194
#define MANAGER_TOPIC
static int publishers_destroy(struct stasis_state_manager *manager, struct publishers *pubs)
#define test_category
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)
static int subscriptions_destroy(struct stasis_state_manager *manager, struct subscriptions *subs)
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.
Definition utils.h:978

References ao2_cleanup, ao2_ref, ast_log, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, cleanup(), explicit_publish_cb(), LOG_ERROR, MANAGER_TOPIC, NULL, publish, publishers_create(), publishers_destroy(), RAII_VAR, stasis_state_manager_create(), subscriptions_create(), subscriptions_destroy(), test_category, TEST_EXECUTE, and TEST_INIT.

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( implicit_publish  )

Definition at line 360 of file test_stasis_state.c.

361{
362 RAII_VAR(struct stasis_state_manager *, manager, NULL, ao2_cleanup);
363 struct subscriptions subs;
364 int rc = AST_TEST_PASS;
365
366 switch (cmd) {
367 case TEST_INIT:
368 info->name = __func__;
369 info->category = test_category;
370 info->summary = "Test implicit publishing of stasis state";
371 info->description = info->summary;
372 return AST_TEST_NOT_RUN;
373 case TEST_EXECUTE:
374 break;
375 }
376
378 ast_test_validate(test, manager != NULL);
379
380 ast_test_validate(test, !subscriptions_create(manager, &subs));
381
382 ast_test_validate_cleanup(test, !publish(manager, implicit_publish_cb, manager),
383 rc, cleanup);
384
385cleanup:
386 if (subscriptions_destroy(manager, &subs) || publishers_destroy(manager, NULL)) {
387 return AST_TEST_FAIL;
388 }
389
390 /*
391 * State subscriptions add a ref a state. The state in turn adds a ref
392 * to the manager. So if more than one ref is held on the manager before
393 * exiting, there is a ref leak some place.
394 */
395 if (ao2_ref(manager, 0) != 1) {
396 ast_log(LOG_ERROR, "Memory leak - Too many references held on manager\n");
397 return AST_TEST_FAIL;
398 }
399
400 return rc;
401}
static int implicit_publish_cb(const char *id, struct stasis_message *msg, void *user_data)

References ao2_cleanup, ao2_ref, ast_log, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, cleanup(), implicit_publish_cb(), LOG_ERROR, MANAGER_TOPIC, NULL, publish, publishers_destroy(), RAII_VAR, stasis_state_manager_create(), subscriptions_create(), subscriptions_destroy(), test_category, TEST_EXECUTE, and TEST_INIT.

◆ create_foo_type_message()

static struct stasis_message * create_foo_type_message ( const char *  id)
static

Definition at line 248 of file test_stasis_state.c.

249{
250 struct stasis_message *msg;
251 struct foo_data *foo;
252 uintmax_t tmp;
253
254 foo = ao2_alloc(sizeof(*foo), NULL);
255 if (!foo) {
256 ast_log(LOG_ERROR, "Failed to allocate foo data for '%s'\n", id);
257 return NULL;
258 }
259
260 if (ast_str_to_umax(id, &tmp)) {
261 ast_log(LOG_ERROR, "Unable to convert the state's id '%s' to numeric\n", id);
262 ao2_ref(foo, -1);
263 return NULL;
264 }
265 foo->bar = (size_t) tmp;
266
268 if (!msg) {
269 ast_log(LOG_ERROR, "Failed to create stasis message for '%s'\n", id);
270 }
271
272 ao2_ref(foo, -1);
273 return msg;
274}
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
int ast_str_to_umax(const char *str, uintmax_t *res)
Convert the given string to an unsigned max size integer.
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.
struct stasis_message_type * foo_type(void)

References ao2_alloc, ao2_ref, ast_log, ast_str_to_umax(), foo_data::bar, foo_type(), LOG_ERROR, NULL, and stasis_message_create_full().

Referenced by explicit_publish_cb(), and implicit_publish_cb().

◆ explicit_publish_cb()

static int explicit_publish_cb ( const char *  id,
struct stasis_message msg,
void *  user_data 
)
static

Definition at line 297 of file test_stasis_state.c.

298{
299 /* For each state object create and publish new state data */
300 struct publishers *pubs = user_data;
301 struct stasis_state_publisher *pub = NULL;
302 struct foo_data *foo = stasis_message_data(msg);
303 size_t i;
304
305 if (validate_data(id, foo)) {
306 return CMP_STOP;
307 }
308
309 msg = create_foo_type_message(id);
310 if (!msg) {
311 return CMP_STOP;
312 }
313
314 for (i = 0; i < AST_VECTOR_SIZE(pubs); ++i) {
315 if (!strcmp(stasis_state_publisher_id(AST_VECTOR_GET(pubs, i)), id)) {
316 pub = AST_VECTOR_GET(pubs, i);
317 break;
318 }
319 }
320
321 if (!pub) {
322 ast_log(LOG_ERROR, "Unable to locate publisher for id '%s'\n", id);
323 return CMP_STOP;
324 }
325
326 stasis_state_publish(pub, msg);
327 ao2_ref(msg, -1);
328
329 return 0;
330}
@ CMP_STOP
Definition astobj2.h:1028
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const char * stasis_state_publisher_id(const struct stasis_state_publisher *pub)
Retrieve the publisher's underlying state's unique id.
void stasis_state_publish(struct stasis_state_publisher *pub, struct stasis_message *msg)
Publish to a managed state (topic) using a publisher.
static struct stasis_message * create_foo_type_message(const char *id)
static int validate_data(const char *id, struct foo_data *foo)
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

References ao2_ref, ast_log, AST_VECTOR_GET, AST_VECTOR_SIZE, CMP_STOP, create_foo_type_message(), LOG_ERROR, NULL, stasis_message_data(), stasis_state_publish(), stasis_state_publisher_id(), and validate_data().

Referenced by AST_TEST_DEFINE().

◆ foo_type()

struct stasis_message_type * foo_type ( void  )

◆ foo_type_cb()

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

Definition at line 110 of file test_stasis_state.c.

111{
112 /* No op since we are not really testing stasis topic handling here */
113}

Referenced by subscriptions_create().

◆ handle_validate()

static void handle_validate ( const char *  id,
struct stasis_state_subscriber sub 
)
static

Definition at line 98 of file test_stasis_state.c.

99{
101 validate_data(id, foo);
102 ao2_cleanup(foo);
103}
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
void * stasis_state_subscriber_data(struct stasis_state_subscriber *sub)
Retrieve the last known state stasis message payload for the subscriber.

References ao2_cleanup, stasis_state_subscriber_data(), sub, and validate_data().

◆ implicit_publish_cb()

static int implicit_publish_cb ( const char *  id,
struct stasis_message msg,
void *  user_data 
)
static

Definition at line 276 of file test_stasis_state.c.

277{
278 /* For each state object create and publish new state data */
279 struct foo_data *foo = stasis_message_data(msg);
280
281 if (validate_data(id, foo)) {
282 return CMP_STOP;
283 }
284
285 msg = create_foo_type_message(id);
286 if (!msg) {
287 return CMP_STOP;
288 }
289
290 /* Now publish it on the managed state object */
291 stasis_state_publish_by_id(user_data, id, NULL, msg);
292 ao2_ref(msg, -1);
293
294 return 0;
295}
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.

References ao2_ref, CMP_STOP, create_foo_type_message(), NULL, stasis_message_data(), stasis_state_publish_by_id(), and validate_data().

Referenced by AST_TEST_DEFINE().

◆ load_module()

static int load_module ( void  )
static

Definition at line 458 of file test_stasis_state.c.

459{
461 return -1;
462 }
463
464 AST_TEST_REGISTER(implicit_publish);
465 AST_TEST_REGISTER(explicit_publish);
466
468}
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition stasis.h:1493
#define AST_TEST_REGISTER(cb)
Definition test.h:127

References AST_MODULE_LOAD_SUCCESS, AST_TEST_REGISTER, foo_type(), and STASIS_MESSAGE_TYPE_INIT.

◆ publish()

static int publish ( struct stasis_state_manager manager,
on_stasis_state  cb,
void *  user_data 
)
static

Definition at line 332 of file test_stasis_state.c.

334{
335 /* First time there is no state data */
336 expect_null = 1;
337
338 running_total = 0;
339 stasis_state_callback_all(manager, cb, user_data);
340
341 if (running_total != sum_total) {
342 ast_log(LOG_ERROR, "Failed manager_callback (1): running=%zu, sum=%zu\n",
344 return -1;
345 }
346
347 /* Second time check valid state data exists */
349 stasis_state_callback_all(manager, cb, user_data);
350
351 if (running_total != sum_total) {
352 ast_log(LOG_ERROR, "Failed manager_callback (2): running=%zu, sum=%zu\n",
354 return -1;
355 }
356
357 return 0;
358}
void stasis_state_callback_all(struct stasis_state_manager *manager, on_stasis_state handler, void *data)
For each managed state call the given handler.
static int expect_null
static size_t sum_total
static size_t running_total

References ast_log, expect_null, LOG_ERROR, running_total, stasis_state_callback_all(), and sum_total.

◆ publishers_create()

static int publishers_create ( struct stasis_state_manager manager,
struct publishers pubs 
)
static

Definition at line 207 of file test_stasis_state.c.

209{
210 size_t i;
211
212 if (AST_VECTOR_INIT(pubs, TOPIC_COUNT)) {
213 return -1;
214 }
215
216 for (i = 0; i < TOPIC_COUNT; ++i) {
217 struct stasis_state_publisher *pub;
218 char id[32];
219
220 if (snprintf(id, 10, "%zu", i) == -1) {
221 ast_log(LOG_ERROR, "Unable to convert publisher id to string\n");
222 break;
223 }
224
225 /* Create the state publisher */
226 pub = stasis_state_add_publisher(manager, id);
227 if (!pub) {
228 ast_log(LOG_ERROR, "Failed to create a state publisher for id '%s'\n", id);
229 break;
230 }
231
232 if (AST_VECTOR_APPEND(pubs, pub)) {
233 ast_log(LOG_ERROR, "Failed to add to publisher to vector for id '%s'\n", id);
234 ao2_ref(pub, -1);
235 break;
236 }
237 }
238
239 if (i != TOPIC_COUNT) {
240 ast_log(LOG_ERROR, "Failed to create all publishers: count=%zu\n", i);
241 publishers_destroy(manager, pubs);
242 return -1;
243 }
244
245 return 0;
246}
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.
#define TOPIC_COUNT
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References ao2_ref, ast_log, AST_VECTOR_APPEND, AST_VECTOR_INIT, LOG_ERROR, publishers_destroy(), stasis_state_add_publisher(), and TOPIC_COUNT.

Referenced by AST_TEST_DEFINE().

◆ publishers_destroy()

static int publishers_destroy ( struct stasis_state_manager manager,
struct publishers pubs 
)
static

Definition at line 181 of file test_stasis_state.c.

182{
183 size_t i;
184
185 if (pubs) {
186 /* Remove explicit publishers */
188 AST_VECTOR_FREE(pubs);
189 return 0;
190 }
191
192 for (i = 0; i < TOPIC_COUNT; ++i) {
193 char id[32];
194
195 /* Remove implicit publishers */
196 if (snprintf(id, 10, "%zu", i) == -1) {
197 ast_log(LOG_ERROR, "Unable to convert publisher id to string\n");
198 return -1;
199 }
200
202 }
203
204 return 0;
205}
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.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition vector.h:185
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition vector.h:873

References ao2_cleanup, ast_log, AST_VECTOR_CALLBACK_VOID, AST_VECTOR_FREE, LOG_ERROR, NULL, stasis_state_remove_publish_by_id(), and TOPIC_COUNT.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), and publishers_create().

◆ STASIS_MESSAGE_TYPE_DEFN()

STASIS_MESSAGE_TYPE_DEFN ( foo_type  )

foo stasis message type

◆ subscriptions_create()

static int subscriptions_create ( struct stasis_state_manager manager,
struct subscriptions subs 
)
static

Definition at line 133 of file test_stasis_state.c.

135{
136 size_t i;
137
140 return -1;
141 }
142
144 expect_null = 1;
145
146 for (i = 0; i < TOPIC_COUNT; ++i) {
148 char id[32];
149
150 if (snprintf(id, 10, "%zu", i) == -1) {
151 ast_log(LOG_ERROR, "Unable to convert subscriber id to string\n");
152 break;
153 }
154
156 if (!sub) {
157 ast_log(LOG_ERROR, "Failed to create a state subscriber for id '%s'\n", id);
158 ao2_ref(sub, -1);
159 break;
160 }
161
162 if (AST_VECTOR_APPEND(subs, sub)) {
163 ast_log(LOG_ERROR, "Failed to add to foo_sub to vector for id '%s'\n", id);
164 ao2_ref(sub, -1);
165 break;
166 }
167
168 sum_total += i;
169 }
170
171 if (i != TOPIC_COUNT || running_total != sum_total) {
172 ast_log(LOG_ERROR, "Failed to create all subscriptions: running=%zu, sum=%zu\n",
174 subscriptions_destroy(manager, subs);
175 return -1;
176 }
177
178 return 0;
179}
int stasis_state_add_observer(struct stasis_state_manager *manager, struct stasis_state_observer *observer)
Add an observer to receive managed state related events.
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 void foo_type_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_state_observer foo_observer

References ao2_ref, ast_log, AST_VECTOR_APPEND, AST_VECTOR_INIT, expect_null, foo_observer, foo_type_cb(), LOG_ERROR, NULL, running_total, stasis_state_add_observer(), stasis_state_subscribe_pool(), sub, subscriptions_destroy(), sum_total, and TOPIC_COUNT.

Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().

◆ subscriptions_destroy()

static int subscriptions_destroy ( struct stasis_state_manager manager,
struct subscriptions subs 
)
static

Definition at line 115 of file test_stasis_state.c.

116{
118
120 AST_VECTOR_FREE(subs);
121
123
124 if (running_total != sum_total) {
125 ast_log(LOG_ERROR, "Failed to destroy all subscriptions: running=%zu, sum=%zu\n",
127 return -1;
128 }
129
130 return 0;
131}
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...

References ast_log, AST_VECTOR_CALLBACK_VOID, AST_VECTOR_FREE, expect_null, foo_observer, LOG_ERROR, running_total, stasis_state_remove_observer(), stasis_state_unsubscribe_and_join(), and sum_total.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), and subscriptions_create().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 448 of file test_stasis_state.c.

449{
450 AST_TEST_UNREGISTER(implicit_publish);
451 AST_TEST_UNREGISTER(explicit_publish);
452
454
455 return 0;
456}
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition stasis.h:1515
#define AST_TEST_UNREGISTER(cb)
Definition test.h:128

References AST_TEST_UNREGISTER, foo_type(), and STASIS_MESSAGE_TYPE_CLEANUP.

◆ validate_data()

static int validate_data ( const char *  id,
struct foo_data foo 
)
static

Definition at line 63 of file test_stasis_state.c.

64{
65 size_t num;
66 uintmax_t tmp;
67
68 if (ast_str_to_umax(id, &tmp)) {
69 ast_log(LOG_ERROR, "Unable to convert the state's id '%s' to numeric\n", id);
70 return -1;
71 }
72 num = (size_t) tmp;
73
74 running_total += num;
75
76 if (!foo) {
77 if (expect_null) {
78 return 0;
79 }
80
81 ast_log(LOG_ERROR, "Expected state data for '%s'\n", id);
82 return -1;
83 }
84
85 if (expect_null) {
86 ast_log(LOG_ERROR, "Expected NULL state data for '%s'\n", id);
87 return -1;
88 }
89
90 if (foo->bar != num) {
91 ast_log(LOG_ERROR, "Unexpected state data for '%s'\n", id);
92 return -1;
93 }
94
95 return 0;
96}

References ast_log, ast_str_to_umax(), foo_data::bar, expect_null, LOG_ERROR, and running_total.

Referenced by explicit_publish_cb(), handle_validate(), and implicit_publish_cb().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Stasis state testing" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 470 of file test_stasis_state.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 470 of file test_stasis_state.c.

◆ expect_null

int expect_null
static

This value is set to check if state data is NULL before publishing

Definition at line 61 of file test_stasis_state.c.

Referenced by publish(), subscriptions_create(), subscriptions_destroy(), and validate_data().

◆ foo_observer

struct stasis_state_observer foo_observer
Initial value:
= {
.on_subscribe = handle_validate,
.on_unsubscribe = handle_validate
}
static void handle_validate(const char *id, struct stasis_state_subscriber *sub)

Definition at line 105 of file test_stasis_state.c.

105 {
106 .on_subscribe = handle_validate,
107 .on_unsubscribe = handle_validate
108};

Referenced by subscriptions_create(), and subscriptions_destroy().

◆ running_total

size_t running_total
static

Test variable that tracks the running total of state ids

Definition at line 58 of file test_stasis_state.c.

Referenced by publish(), subscriptions_create(), subscriptions_destroy(), and validate_data().

◆ sum_total

size_t sum_total
static

For testing purposes each subscribed state's id is a number. This value is the summation of all id's.

Definition at line 55 of file test_stasis_state.c.

Referenced by publish(), subscriptions_create(), and subscriptions_destroy().