summaryrefslogtreecommitdiff
path: root/main/stasis_endpoints.c
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-08-01 13:49:34 +0000
committerDavid M. Lee <dlee@digium.com>2013-08-01 13:49:34 +0000
commite1b959ccbb4e47421b37a0f75a2bf89ccd34dcb1 (patch)
tree3026c96da713bafcf1126c77bde6994f348280bb /main/stasis_endpoints.c
parent5c1396946929ab19e94c117f8ad3db5f78a450bc (diff)
Split caching out from the stasis_caching_topic.
In working with res_stasis, I discovered a significant limitation to the current structure of stasis_caching_topics: you cannot subscribe to cache updates for a single channel/bridge/endpoint/etc. To address this, this patch splits the cache away from the stasis_caching_topic, making it a first class object. The stasis_cache object is shared amongst individual stasis_caching_topics that are created per channel/endpoint/etc. These are still forwarded to global whatever_all_cached topics, so their use from most of the code does not change. In making these changes, I noticed that we frequently used a similar pattern for bridges, endpoints and channels: single_topic ----------------> all_topic ^ | single_topic_cached ----+----> all_topic_cached | +----> cache This pattern was extracted as the 'Stasis Caching Pattern', defined in stasis_caching_pattern.h. This avoids a lot of duplicate code between the different domain objects. Since the cache is now disassociated from its upstream caching topics, this also necessitated a change to how the 'guaranteed' flag worked for retrieving from a cache. The code for handling the caching guarantee was extracted into a 'stasis_topic_wait' function, which works for any stasis_topic. (closes issue ASTERISK-22002) Review: https://reviewboard.asterisk.org/r/2672/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395954 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis_endpoints.c')
-rw-r--r--main/stasis_endpoints.c86
1 files changed, 41 insertions, 45 deletions
diff --git a/main/stasis_endpoints.c b/main/stasis_endpoints.c
index a6756182c..831b4aee0 100644
--- a/main/stasis_endpoints.c
+++ b/main/stasis_endpoints.c
@@ -73,6 +73,28 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
</managerEvent>
***/
+static struct stasis_cp_all *endpoint_cache_all;
+
+struct stasis_cp_all *ast_endpoint_cache_all(void)
+{
+ return endpoint_cache_all;
+}
+
+struct stasis_cache *ast_endpoint_cache(void)
+{
+ return stasis_cp_all_cache(endpoint_cache_all);
+}
+
+struct stasis_topic *ast_endpoint_topic_all(void)
+{
+ return stasis_cp_all_topic(endpoint_cache_all);
+}
+
+struct stasis_topic *ast_endpoint_topic_all_cached(void)
+{
+ return stasis_cp_all_topic_cached(endpoint_cache_all);
+}
+
static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *msg);
STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_snapshot_type);
@@ -80,10 +102,6 @@ STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_state_type,
.to_ami = peerstatus_to_ami,
);
-static struct stasis_topic *endpoint_topic_all;
-
-static struct stasis_caching_topic *endpoint_topic_all_cached;
-
static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *msg)
{
struct ast_endpoint_blob *obj = stasis_message_data(msg);
@@ -168,16 +186,6 @@ void ast_endpoint_blob_publish(struct ast_endpoint *endpoint, struct stasis_mess
}
}
-struct stasis_topic *ast_endpoint_topic_all(void)
-{
- return endpoint_topic_all;
-}
-
-struct stasis_caching_topic *ast_endpoint_topic_all_cached(void)
-{
- return endpoint_topic_all_cached;
-}
-
struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
const char *name, unsigned int guaranteed)
{
@@ -190,8 +198,12 @@ struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
return NULL;
}
- msg = stasis_cache_get_extended(ast_endpoint_topic_all_cached(),
- ast_endpoint_snapshot_type(), id, guaranteed);
+ if (guaranteed) {
+ stasis_topic_wait(ast_endpoint_topic_all_cached());
+ }
+
+ msg = stasis_cache_get(ast_endpoint_cache(),
+ ast_endpoint_snapshot_type(), id);
if (!msg) {
return NULL;
}
@@ -267,44 +279,28 @@ struct ast_json *ast_endpoint_snapshot_to_json(
return ast_json_ref(json);
}
-static void endpoints_stasis_shutdown(void)
+static void endpoints_stasis_cleanup(void)
{
- stasis_caching_unsubscribe_and_join(endpoint_topic_all_cached);
- endpoint_topic_all_cached = NULL;
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_snapshot_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_endpoint_state_type);
- ao2_cleanup(endpoint_topic_all);
- endpoint_topic_all = NULL;
+ ao2_cleanup(endpoint_cache_all);
+ endpoint_cache_all = NULL;
}
int ast_endpoint_stasis_init(void)
{
- ast_register_atexit(endpoints_stasis_shutdown);
-
- if (STASIS_MESSAGE_TYPE_INIT(ast_endpoint_snapshot_type) != 0) {
- return -1;
- }
+ int res = 0;
+ ast_register_cleanup(endpoints_stasis_cleanup);
- if (!endpoint_topic_all) {
- endpoint_topic_all = stasis_topic_create("endpoint_topic_all");
- }
-
- if (!endpoint_topic_all) {
+ endpoint_cache_all = stasis_cp_all_create("endpoint_topic_all",
+ endpoint_snapshot_get_id);
+ if (!endpoint_cache_all) {
return -1;
}
- if (!endpoint_topic_all_cached) {
- endpoint_topic_all_cached =
- stasis_caching_topic_create(
- endpoint_topic_all, endpoint_snapshot_get_id);
- }
-
- if (!endpoint_topic_all_cached) {
- return -1;
- }
-
- if (STASIS_MESSAGE_TYPE_INIT(ast_endpoint_state_type) != 0) {
- return -1;
- }
+ res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_snapshot_type);
+ res |= STASIS_MESSAGE_TYPE_INIT(ast_endpoint_state_type);
- return 0;
+ return res;
}