[asterisk-commits] dlee: branch dlee/endpoints r386458 - in /team/dlee/endpoints: include/asteri...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 24 16:00:10 CDT 2013
Author: dlee
Date: Wed Apr 24 16:00:07 2013
New Revision: 386458
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386458
Log:
That looks about right
Modified:
team/dlee/endpoints/include/asterisk/stasis.h
team/dlee/endpoints/main/endpoints.c
team/dlee/endpoints/main/stasis_cache.c
Modified: team/dlee/endpoints/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis.h?view=diff&rev=386458&r1=386457&r2=386458
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis.h Wed Apr 24 16:00:07 2013
@@ -431,6 +431,22 @@
};
/*!
+ * \brief Cache clear message.
+ */
+struct stasis_cache_clear {
+ /*! Type of object being cleared from the cache */
+ struct stasis_message_type *type;
+ /*! Id of the object being cleared from the cache */
+ char id[];
+};
+
+/*!
+ * \brief Message type for \ref stasis_cache_clear.
+ * \since 12
+ */
+struct stasis_message_type *stasis_cache_clear_type(void);
+
+/*!
* \brief A message which instructs the caching topic to remove an entry from its cache.
* \param type Message type.
* \param id Unique id of the snapshot to clear.
Modified: team/dlee/endpoints/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/endpoints.c?view=diff&rev=386458&r1=386457&r2=386458
==============================================================================
--- team/dlee/endpoints/main/endpoints.c (original)
+++ team/dlee/endpoints/main/endpoints.c Wed Apr 24 16:00:07 2013
@@ -34,9 +34,13 @@
#include "asterisk/astobj2.h"
#include "asterisk/endpoints.h"
#include "asterisk/stasis.h"
+#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stringfields.h"
+
+/*! Buckets for endpoint->channel mappings. Keep it prime! */
+#define ENDPOINT_BUCKETS 127
struct ast_endpoint {
AST_DECLARE_STRING_FIELDS(
@@ -56,6 +60,8 @@
struct stasis_subscription *forward;
/*! Router for handling this endpoint's messages */
struct stasis_message_router *router;
+ /*! ast_str_container of channels associated with this endpoint */
+ struct ao2_container *channel_ids;
};
static void endpoint_publish_snapshot(struct ast_endpoint *endpoint)
@@ -102,15 +108,30 @@
struct stasis_subscription *sub, struct stasis_topic *topic,
struct stasis_message *message)
{
- struct stasis_endpoint *endpoint = data;
- struct ast_channel_snapshot *snapshot =
+ struct ast_endpoint *endpoint = data;
+ struct ast_channel_snapshot *snapshot = stasis_message_data(message);
+
+ ao2_lock(endpoint);
+ if (!ao2_find(endpoint->channel_ids, snapshot->uniqueid, OBJ_NODATA)) {
+ ast_str_container_add(endpoint->channel_ids,
+ snapshot->uniqueid);
+ }
+ ao2_unlock(endpoint);
+ endpoint_publish_snapshot(endpoint);
}
static void endpoint_cache_clear(void *data,
struct stasis_subscription *sub, struct stasis_topic *topic,
struct stasis_message *message)
{
- struct stasis_endpoint *endpoint = data;
+ struct ast_endpoint *endpoint = data;
+ struct stasis_cache_clear *clear = stasis_message_data(message);
+
+ ao2_lock(endpoint);
+ ao2_find(endpoint->channel_ids, clear->id,
+ OBJ_NODATA | OBJ_UNLINK);
+ ao2_unlock(endpoint);
+ endpoint_publish_snapshot(endpoint);
}
static void endpoint_default(void *data,
@@ -128,6 +149,7 @@
{
RAII_VAR(struct ast_endpoint *, endpoint, NULL, ao2_cleanup);
RAII_VAR(struct ast_str *, full_name, NULL, ast_free);
+ int r = 0;
endpoint = ao2_alloc(sizeof(*endpoint), endpoint_dtor);
if (!endpoint) {
@@ -145,6 +167,12 @@
ast_string_field_set(endpoint, resource, resource);
ast_str_set(&full_name, 0, "endpoint:%s/%s", tech, resource);
+
+ endpoint->channel_ids = ast_str_container_alloc(ENDPOINT_BUCKETS);
+ if (!endpoint->channel_ids) {
+ return NULL;
+ }
+
endpoint->topic = stasis_topic_create(ast_str_buffer(full_name));
if (!endpoint->topic) {
return NULL;
@@ -160,6 +188,14 @@
if (!endpoint->router) {
return NULL;
}
+ r |= stasis_message_router_add(endpoint->router,
+ ast_channel_snapshot_type(), endpoint_channel_snapshot,
+ endpoint);
+ r |= stasis_message_router_add(endpoint->router,
+ stasis_cache_clear_type(), endpoint_cache_clear,
+ endpoint);
+ r |= stasis_message_router_set_default(endpoint->router,
+ endpoint_default, endpoint);
endpoint_publish_snapshot(endpoint);
Modified: team/dlee/endpoints/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/stasis_cache.c?view=diff&rev=386458&r1=386457&r2=386458
==============================================================================
--- team/dlee/endpoints/main/stasis_cache.c (original)
+++ team/dlee/endpoints/main/stasis_cache.c Wed Apr 24 16:00:07 2013
@@ -240,54 +240,45 @@
return cache_dump.cached;
}
-static struct stasis_message_type *__cache_clear_data;
-
-static struct stasis_message_type *cache_clear_data(void)
-{
- ast_assert(__cache_clear_data != NULL);
- return __cache_clear_data;
-}
-
-static struct stasis_message_type *__cache_update;
+static struct stasis_message_type *cache_clear_type;
+
+struct stasis_message_type *stasis_cache_clear_type(void)
+{
+ ast_assert(cache_clear_type != NULL);
+ return cache_clear_type;
+}
+
+static struct stasis_message_type *cache_update_type;
struct stasis_message_type *stasis_cache_update_type(void)
{
- ast_assert(__cache_update != NULL);
- return __cache_update;
-}
-
-struct cache_clear_data {
- struct stasis_message_type *type;
- char *id;
-};
-
-static void cache_clear_data_dtor(void *obj)
-{
- struct cache_clear_data *ev = obj;
- ast_free(ev->id);
- ev->id = NULL;
+ ast_assert(cache_update_type != NULL);
+ return cache_update_type;
+}
+
+static void cache_clear_dtor(void *obj)
+{
+ struct stasis_cache_clear *ev = obj;
ao2_cleanup(ev->type);
ev->type = NULL;
}
struct stasis_message *stasis_cache_clear_create(struct stasis_message_type *type, const char *id)
{
- RAII_VAR(struct cache_clear_data *, ev, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_cache_clear *, ev, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
- ev = ao2_alloc(sizeof(*ev), cache_clear_data_dtor);
+ ev = ao2_alloc(sizeof(*ev) + strlen(id) + 1, cache_clear_dtor);
if (!ev) {
return NULL;
}
- ev->id = ast_strdup(id);
- if (!ev->id) {
- return NULL;
- }
+ /* strcpy safe */
+ strcpy(ev->id, id);
ao2_ref(type, +1);
ev->type = type;
- msg = stasis_message_create(cache_clear_data(), ev);
+ msg = stasis_message_create(stasis_cache_clear_type(), ev);
if (!msg) {
return NULL;
@@ -363,10 +354,10 @@
}
/* Handle cache clear event */
- if (cache_clear_data() == stasis_message_type(message)) {
+ if (stasis_cache_clear_type() == stasis_message_type(message)) {
RAII_VAR(struct stasis_message *, old_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, update, NULL, ao2_cleanup);
- struct cache_clear_data *clear = stasis_message_data(message);
+ struct stasis_cache_clear *clear = stasis_message_data(message);
ast_assert(clear->type != NULL);
ast_assert(clear->id != NULL);
old_snapshot = cache_put(caching_topic, clear->type, clear->id, NULL);
@@ -449,28 +440,28 @@
static void stasis_cache_exit(void)
{
- ao2_cleanup(__cache_clear_data);
- __cache_clear_data = NULL;
- ao2_cleanup(__cache_update);
- __cache_update = NULL;
+ ao2_cleanup(cache_clear_type);
+ cache_clear_type = NULL;
+ ao2_cleanup(cache_update_type);
+ cache_update_type = NULL;
}
int stasis_cache_init(void)
{
ast_register_atexit(stasis_cache_exit);
- if (__cache_clear_data || __cache_update) {
+ if (cache_clear_type || cache_update_type) {
ast_log(LOG_ERROR, "Stasis cache double initialized\n");
return -1;
}
- __cache_update = stasis_message_type_create("stasis_cache_update");
- if (!__cache_update) {
+ cache_update_type = stasis_message_type_create("stasis_cache_update");
+ if (!cache_update_type) {
return -1;
}
- __cache_clear_data = stasis_message_type_create("StasisCacheClear");
- if (!__cache_clear_data) {
+ cache_clear_type = stasis_message_type_create("StasisCacheClear");
+ if (!cache_clear_type) {
return -1;
}
return 0;
More information about the asterisk-commits
mailing list