From f1ee578b506d67c6c0105f9510344aec50f3adfb Mon Sep 17 00:00:00 2001 From: scottmk Date: Thu, 29 Jul 2010 14:24:58 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1984 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_message.h | 4 ++++ src/libopensrf/osrf_message.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/opensrf/osrf_message.h b/include/opensrf/osrf_message.h index 265ec68..592c039 100644 --- a/include/opensrf/osrf_message.h +++ b/include/opensrf/osrf_message.h @@ -108,10 +108,14 @@ void osrf_message_set_status_info( osrfMessage*, 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 ); diff --git a/src/libopensrf/osrf_message.c b/src/libopensrf/osrf_message.c index a24b9ff..f6e2b62 100644 --- a/src/libopensrf/osrf_message.c +++ b/src/libopensrf/osrf_message.c @@ -13,7 +13,6 @@ #include #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 @@ void osrf_message_set_status_info( osrfMessage* msg, /** - @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. @@ -249,6 +248,22 @@ void osrf_message_set_result_content( osrfMessage* msg, const char* json_string } +/** + @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 @@ char* osrf_message_serialize(const osrfMessage* msg) { 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"); -- 2.43.2