[Opensrf-commits] r1984 - in trunk: include/opensrf src/libopensrf (scottmk)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jul 29 10:25:01 EDT 2010


Author: scottmk
Date: 2010-07-29 10:24:58 -0400 (Thu, 29 Jul 2010)
New Revision: 1984

Modified:
   trunk/include/opensrf/osrf_message.h
   trunk/src/libopensrf/osrf_message.c
Log:
1. Make osrfMessageToJSON() available at global scope.

2. New function osrf_message_set_result() -- a more efficient alternative
to osrf_message_set_result_content().

Typically when using the older function, we convert a jsonObject to JSON
text, and then parse the JSON text back into a jsonObject.  With the new
function we can avoid the round trip through the text format.

M    include/opensrf/osrf_message.h
M    src/libopensrf/osrf_message.c


Modified: trunk/include/opensrf/osrf_message.h
===================================================================
--- trunk/include/opensrf/osrf_message.h	2010-07-13 06:11:14 UTC (rev 1983)
+++ trunk/include/opensrf/osrf_message.h	2010-07-29 14:24:58 UTC (rev 1984)
@@ -108,10 +108,14 @@
 
 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
 
+void osrf_message_set_result( osrfMessage* msg, const jsonObject* obj );
+
 void osrfMessageFree( osrfMessage* );
 
 char* osrf_message_to_xml( osrfMessage* );
 
+jsonObject* osrfMessageToJSON( const osrfMessage* msg );
+
 char* osrf_message_serialize(const osrfMessage*);
 
 osrfList* osrfMessageDeserialize( const char* string, osrfList* list );

Modified: trunk/src/libopensrf/osrf_message.c
===================================================================
--- trunk/src/libopensrf/osrf_message.c	2010-07-13 06:11:14 UTC (rev 1983)
+++ trunk/src/libopensrf/osrf_message.c	2010-07-29 14:24:58 UTC (rev 1984)
@@ -13,7 +13,6 @@
 #include <opensrf/osrf_message.h>
 #include "opensrf/osrf_stack.h"
 
-static jsonObject* osrfMessageToJSON( const osrfMessage* msg );
 static osrfMessage* deserialize_one_message( const jsonObject* message );
 
 static char default_locale[17] = "en-US\0\0\0\0\0\0\0\0\0\0\0\0";
@@ -234,7 +233,7 @@
 
 
 /**
-	@brief Populate the _result_content membersof an osrfMessage.
+	@brief Populate the _result_content membersof an osrfMessage from a JSON string.
 	@param msg Pointer to the osrfMessage to be populated.
 	@param json_string A JSON string encoding a result.
 
@@ -250,6 +249,22 @@
 
 
 /**
+	@brief Populate the _result_content membersof an osrfMessage from a JSON object.
+	@param msg Pointer to the osrfMessage to be populated.
+	@param obj Pointer to a jsonObject encoding a result.
+
+	Used for a RESULT message to return the results of a remote procedure call.
+*/
+void osrf_message_set_result( osrfMessage* msg, const jsonObject* obj ) {
+	if( msg == NULL || obj == NULL) return;
+	if( msg->_result_content )
+		jsonObjectFree( msg->_result_content );
+
+	msg->_result_content = jsonObjectDecodeClass( obj );
+}
+
+
+/**
 	@brief Free an osrfMessage and everything it owns.
 	@param msg Pointer to the osrfMessage to be freed.
 */
@@ -364,7 +379,7 @@
 
 	The calling code is responsible for freeing the returned jsonObject.
 */
-static jsonObject* osrfMessageToJSON( const osrfMessage* msg ) {
+jsonObject* osrfMessageToJSON( const osrfMessage* msg ) {
 
 	jsonObject* json = jsonNewObjectType(JSON_HASH);
 	jsonObjectSetClass(json, "osrfMessage");



More information about the opensrf-commits mailing list