[asterisk-commits] file: branch file/stasis_peerevent r389223 - in /team/file/stasis_peerevent: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 20 09:52:38 CDT 2013


Author: file
Date: Mon May 20 09:52:35 2013
New Revision: 389223

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389223
Log:
Add endpoint blob creation and a type for state changes.

Modified:
    team/file/stasis_peerevent/include/asterisk/stasis_endpoints.h
    team/file/stasis_peerevent/main/stasis_endpoints.c

Modified: team/file/stasis_peerevent/include/asterisk/stasis_endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/include/asterisk/stasis_endpoints.h?view=diff&rev=389223&r1=389222&r2=389223
==============================================================================
--- team/file/stasis_peerevent/include/asterisk/stasis_endpoints.h (original)
+++ team/file/stasis_peerevent/include/asterisk/stasis_endpoints.h Mon May 20 09:52:35 2013
@@ -79,6 +79,30 @@
 };
 
 /*!
+ * \since 12
+ * \brief Creates a \ref ast_endpoint_blob message.
+ *
+ * The given \a blob should be treated as immutable and not modified after it is
+ * put into the message.
+ *
+ * \param endpoint Endpoint blob is associated with.
+ * \param type Message type for this blob.
+ * \param blob JSON object representing the data, or \c NULL for no data. If
+ *             \c NULL, ast_json_null() is put into the object.
+ *
+ * \return \ref ast_endpoint_blob message.
+ * \return \c NULL on error
+ */
+struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint,
+	struct stasis_message_type *type, struct ast_json *blob);
+
+/*!
+ * \brief Message type for endpoint state changes.
+ * \since 12
+ */
+struct stasis_message_type *ast_endpoint_state_type(void);
+
+/*!
  * \brief Message type for \ref ast_endpoint_snapshot.
  * \since 12
  */

Modified: team/file/stasis_peerevent/main/stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/main/stasis_endpoints.c?view=diff&rev=389223&r1=389222&r2=389223
==============================================================================
--- team/file/stasis_peerevent/main/stasis_endpoints.c (original)
+++ team/file/stasis_peerevent/main/stasis_endpoints.c Mon May 20 09:52:35 2013
@@ -36,10 +36,48 @@
 #include "asterisk/stasis_endpoints.h"
 
 STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_snapshot_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_state_type);
 
 static struct stasis_topic *endpoint_topic_all;
 
 static struct stasis_caching_topic *endpoint_topic_all_cached;
+
+static void endpoint_blob_dtor(void *obj)
+{
+	struct ast_endpoint_blob *event = obj;
+	ao2_cleanup(event->snapshot);
+	ast_json_unref(event->blob);
+}
+
+struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint,
+	struct stasis_message_type *type, struct ast_json *blob)
+{
+	RAII_VAR(struct ast_endpoint_blob *, obj, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+	if (!blob) {
+		blob = ast_json_null();
+	}
+
+	if (!(obj = ao2_alloc(sizeof(*obj), endpoint_blob_dtor))) {
+		return NULL;
+	}
+
+	if (endpoint) {
+		if (!(obj->snapshot = ast_endpoint_snapshot_create(endpoint))) {
+			return NULL;
+		}
+	}
+
+	obj->blob = ast_json_ref(blob);
+
+	if (!(msg = stasis_message_create(type, obj))) {
+		return NULL;
+	}
+
+	ao2_ref(msg, +1);
+	return msg;
+}
 
 struct stasis_topic *ast_endpoint_topic_all(void)
 {
@@ -175,5 +213,9 @@
 		return -1;
 	}
 
+	if (STASIS_MESSAGE_TYPE_INIT(ast_endpoint_state_type) != 0) {
+		return -1;
+	}
+
 	return 0;
 }




More information about the asterisk-commits mailing list