[asterisk-commits] dlee: branch dlee/endpoints r387292 - in /team/dlee/endpoints: main/ res/ tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 2 01:10:44 CDT 2013
Author: dlee
Date: Thu May 2 01:10:42 2013
New Revision: 387292
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387292
Log:
Publish channel snapshot when added to endpoint
Modified:
team/dlee/endpoints/main/channel_internal_api.c
team/dlee/endpoints/res/res_stasis_test.c
team/dlee/endpoints/tests/test_stasis_endpoints.c
Modified: team/dlee/endpoints/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/channel_internal_api.c?view=diff&rev=387292&r1=387291&r2=387292
==============================================================================
--- team/dlee/endpoints/main/channel_internal_api.c (original)
+++ team/dlee/endpoints/main/channel_internal_api.c Thu May 2 01:10:42 2013
@@ -1396,15 +1396,30 @@
int ast_endpoint_add_channel(struct ast_endpoint *endpoint,
struct ast_channel *chan)
{
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
ast_assert(chan != NULL);
ast_assert(endpoint != NULL);
+ snapshot = ast_channel_snapshot_create(chan);
+ if (!snapshot) {
+ return -1;
+ }
+
+ msg = stasis_message_create(ast_channel_snapshot_type(), snapshot);
+ if (!msg) {
+ return -1;
+ }
+
chan->endpoint_forward =
stasis_forward_all(chan->topic, ast_endpoint_topic(endpoint));
if (chan->endpoint_forward == NULL) {
return -1;
}
+
+ stasis_publish(ast_endpoint_topic(endpoint), msg);
return 0;
}
Modified: team/dlee/endpoints/res/res_stasis_test.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/res/res_stasis_test.c?view=diff&rev=387292&r1=387291&r2=387292
==============================================================================
--- team/dlee/endpoints/res/res_stasis_test.c (original)
+++ team/dlee/endpoints/res/res_stasis_test.c Thu May 2 01:10:42 2013
@@ -61,57 +61,7 @@
sink->max_messages = 0;
}
-struct stasis_message_sink *stasis_message_sink_create(void)
-{
- RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
-
- sink = ao2_alloc(sizeof(*sink), stasis_message_sink_dtor);
- if (!sink) {
- return NULL;
- }
- ast_mutex_init(&sink->lock);
- ast_cond_init(&sink->cond, NULL);
- sink->max_messages = 4;
- sink->messages =
- ast_malloc(sizeof(*sink->messages) * sink->max_messages);
- if (!sink->messages) {
- return NULL;
- }
- ao2_ref(sink, +1);
- return sink;
-}
-
-void stasis_message_sink_cb(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
-{
- struct stasis_message_sink *sink = data;
-
- SCOPED_MUTEX(lock, &sink->lock);
-
- if (sink->num_messages == sink->max_messages) {
- size_t new_max_messages = sink->max_messages * 2;
- struct stasis_message **new_messages = ast_realloc(
- sink->messages,
- sizeof(*new_messages) * new_max_messages);
- if (!new_messages) {
- return;
- }
- sink->max_messages = new_max_messages;
- sink->messages = new_messages;
- }
-
- ao2_ref(message, +1);
- sink->messages[sink->num_messages++] = message;
-
- if (stasis_subscription_final_message(sub, message)) {
- sink->is_done = 1;
- }
-
- ast_cond_signal(&sink->cond);
-}
-
-int stasis_message_sink_wait_for(struct stasis_message_sink *sink,
- int num_messages, int timeout_millis)
+static struct timespec make_deadline(int timeout_millis)
{
struct timeval start = ast_tvnow();
struct timeval delta = {
@@ -124,6 +74,69 @@
.tv_nsec = 1000 * deadline_tv.tv_usec,
};
+ return deadline;
+}
+
+struct stasis_message_sink *stasis_message_sink_create(void)
+{
+ RAII_VAR(struct stasis_message_sink *, sink, NULL, ao2_cleanup);
+
+ sink = ao2_alloc(sizeof(*sink), stasis_message_sink_dtor);
+ if (!sink) {
+ return NULL;
+ }
+ ast_mutex_init(&sink->lock);
+ ast_cond_init(&sink->cond, NULL);
+ sink->max_messages = 4;
+ sink->messages =
+ ast_malloc(sizeof(*sink->messages) * sink->max_messages);
+ if (!sink->messages) {
+ return NULL;
+ }
+ ao2_ref(sink, +1);
+ return sink;
+}
+
+void stasis_message_sink_cb(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic, struct stasis_message *message)
+{
+ struct stasis_message_sink *sink = data;
+
+ SCOPED_MUTEX(lock, &sink->lock);
+
+ if (stasis_subscription_final_message(sub, message)) {
+ sink->is_done = 1;
+ ast_cond_signal(&sink->cond);
+ return;
+ }
+
+ if (stasis_subscription_change_type() == stasis_message_type(message)) {
+ /* Ignore subscription changes */
+ return;
+ }
+
+ if (sink->num_messages == sink->max_messages) {
+ size_t new_max_messages = sink->max_messages * 2;
+ struct stasis_message **new_messages = ast_realloc(
+ sink->messages,
+ sizeof(*new_messages) * new_max_messages);
+ if (!new_messages) {
+ return;
+ }
+ sink->max_messages = new_max_messages;
+ sink->messages = new_messages;
+ }
+
+ ao2_ref(message, +1);
+ sink->messages[sink->num_messages++] = message;
+ ast_cond_signal(&sink->cond);
+}
+
+int stasis_message_sink_wait_for(struct stasis_message_sink *sink,
+ int num_messages, int timeout_millis)
+{
+ struct timespec deadline = make_deadline(timeout_millis);
+
SCOPED_MUTEX(lock, &sink->lock);
while (sink->num_messages < num_messages) {
int r = ast_cond_timedwait(&sink->cond, &sink->lock, &deadline);
@@ -142,13 +155,7 @@
int stasis_message_sink_should_stay(struct stasis_message_sink *sink,
int num_messages, int timeout_millis)
{
- struct timeval start = ast_tvnow();
- struct timeval delta = ast_tv(0, 1000 * timeout_millis);
- struct timeval deadline_tv = ast_tvadd(start, delta);
- struct timespec deadline = {
- .tv_sec = deadline_tv.tv_sec,
- .tv_nsec = 1000 * deadline_tv.tv_usec,
- };
+ struct timespec deadline = make_deadline(timeout_millis);
SCOPED_MUTEX(lock, &sink->lock);
while (sink->num_messages == num_messages) {
Modified: team/dlee/endpoints/tests/test_stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/tests/test_stasis_endpoints.c?view=diff&rev=387292&r1=387291&r2=387292
==============================================================================
--- team/dlee/endpoints/tests/test_stasis_endpoints.c (original)
+++ team/dlee/endpoints/tests/test_stasis_endpoints.c Thu May 2 01:10:42 2013
@@ -88,8 +88,15 @@
ast_endpoint_add_channel(uut, chan);
- actual = stasis_message_sink_wait_for(sink, 2, DEFAULT_WAIT_MILLIS);
- ast_test_validate(test, 2 == actual);
+ actual = stasis_message_sink_wait_for(sink, 1, DEFAULT_WAIT_MILLIS);
+
+ for (actual = 0; actual < sink->num_messages; ++actual) {
+ struct stasis_message *msg = sink->messages[actual];
+ struct stasis_message_type *type = stasis_message_type(msg);
+ printf("%s\n", stasis_message_type_name(type));
+ }
+
+ ast_test_validate(test, 1 == actual);
safe_channel_release(chan);
chan = NULL;
More information about the asterisk-commits
mailing list