[Opensrf-commits] r1144 - in trunk: include/opensrf src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Nov 26 13:39:04 EST 2007
Author: miker
Date: 2007-11-26 13:20:40 -0500 (Mon, 26 Nov 2007)
New Revision: 1144
Modified:
trunk/include/opensrf/osrf_app_session.h
trunk/src/libopensrf/osrf_app_session.c
Log:
Patch from Scott McKellar:
1. Shift toward a camel case style of identifiers.
2. Make functions static when they are not called from elsewhere.
3. Populate all members in newly-allocated structs.
4. Add a couple of consts.
Details:
1. We have two redundant typdefs. I replaced all references to the
lower_case_with_underscores version with references to the camelCase
versions (while keeping the obsolescent typedefs themselves):
osrf_app_request ==> osrfAppRequest
osrf_app_session ==> osrfAppSession
2. I deleted the prototypes of two functions that are nowhere
referenced or even defined:
_osrf_app_session_get_request()
_osrf_app_session_push_request()
3. I eliminated osrf_app_session_make_locale_req(), replacing it
with the equivalent osrfAppSessionMakeLocaleRequest function. No
other file references the former.
4. I made the following functions static, and removed their
prototypes from the header, since none is referenced from any other
file:
osrfAppSessionMakeLocaleRequest()
osrfAppSessionSendBatch()
all remaining functions with a leading underscore
5. I explicitly initialized the stateless and session_locale members
of osrfAppSession.
6. I added the const qualifier to a couple of parameters of
osrfAppSessionStatus().
Modified: trunk/include/opensrf/osrf_app_session.h
===================================================================
--- trunk/include/opensrf/osrf_app_session.h 2007-11-26 15:13:01 UTC (rev 1143)
+++ trunk/include/opensrf/osrf_app_session.h 2007-11-26 18:20:40 UTC (rev 1144)
@@ -48,7 +48,7 @@
transport_client* transport_handle;
/** Cache of active app_request objects */
- //osrf_app_request* request_queue;
+ //osrfAppRequest* request_queue;
osrfList* request_queue;
@@ -93,153 +93,94 @@
// --------------------------------------------------------------------------
/** Allocates a initializes a new app_session */
-osrf_app_session* osrfAppSessionClientInit( const char* remote_service );
-osrf_app_session* osrf_app_client_session_init( const char* remote_service );
+osrfAppSession* osrfAppSessionClientInit( const char* remote_service );
+osrfAppSession* osrf_app_client_session_init( const char* remote_service );
/** Allocates and initializes a new server session. The global session cache
* is checked to see if this session already exists, if so, it's returned
*/
-osrf_app_session* osrf_app_server_session_init(
+osrfAppSession* osrf_app_server_session_init(
const char* session_id, const char* our_app, const char* remote_id );
/** sets the default locale for a session **/
-char* osrf_app_session_set_locale( osrf_app_session*, const char* );
+char* osrf_app_session_set_locale( osrfAppSession*, const char* );
/** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( const char* session_id );
+osrfAppSession* osrf_app_session_find_session( const char* session_id );
/** Builds a new app_request object with the given payload andn returns
* the id of the request. This id is then used to perform work on the
* requeset.
*/
int osrfAppSessionMakeRequest(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings);
int osrf_app_session_make_req(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings);
-int osrfAppSessionMakeLocaleRequest(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale);
-
-int osrf_app_session_make_locale_req(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale);
-
/** Sets the given request to complete state */
-void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
+void osrf_app_session_set_complete( osrfAppSession* session, int request_id );
/** Returns true if the given request is complete */
-int osrf_app_session_request_complete( const osrf_app_session* session, int request_id );
+int osrf_app_session_request_complete( const osrfAppSession* session, int request_id );
/** Does a recv call on the given request */
osrf_message* osrfAppSessionRequestRecv(
- osrf_app_session* session, int request_id, int timeout );
+ osrfAppSession* session, int request_id, int timeout );
osrf_message* osrf_app_session_request_recv(
- osrf_app_session* session, int request_id, int timeout );
+ osrfAppSession* session, int request_id, int timeout );
/** Removes the request from the request set and frees the reqest */
-void osrf_app_session_request_finish( osrf_app_session* session, int request_id );
+void osrf_app_session_request_finish( osrfAppSession* session, int request_id );
/** Resends the orginal request with the given request id */
-int osrf_app_session_request_resend( osrf_app_session*, int request_id );
+int osrf_app_session_request_resend( osrfAppSession*, int request_id );
/** Resets the remote connection target to that of the original*/
-void osrf_app_session_reset_remote( osrf_app_session* );
+void osrf_app_session_reset_remote( osrfAppSession* );
/** Sets the remote target to 'remote_id' */
-void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id );
+void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id );
/** pushes the given message into the result list of the app_request
* whose request_id matches the messages thread_trace
*/
-int osrf_app_session_push_queue( osrf_app_session*, osrf_message* msg );
+int osrf_app_session_push_queue( osrfAppSession*, osrf_message* msg );
/** Attempts to connect to the remote service. Returns 1 on successful
* connection, 0 otherwise.
*/
-int osrf_app_session_connect( osrf_app_session* );
-int osrfAppSessionConnect( osrf_app_session* );
+int osrf_app_session_connect( osrfAppSession* );
+int osrfAppSessionConnect( osrfAppSession* );
/** Sends a disconnect message to the remote service. No response is expected */
-int osrf_app_session_disconnect( osrf_app_session* );
+int osrf_app_session_disconnect( osrfAppSession* );
/** Waits up to 'timeout' seconds for some data to arrive.
* Any data that arrives will be processed according to its
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session*, int timeout, int* recvd );
+int osrf_app_session_queue_wait( osrfAppSession*, int timeout, int* recvd );
/** Disconnects (if client), frees any attached app_reuqests, removes the session from the
* global session cache and frees the session. Needless to say, only call this when the
* session is completey done.
*/
-void osrf_app_session_destroy ( osrf_app_session* );
+void osrf_app_session_destroy ( osrfAppSession* );
void osrfAppSessionFree( osrfAppSession* );
-
-
-// --------------------------------------------------------------------------
-// --------------------------------------------------------------------------
-// Request functions
-// --------------------------------------------------------------------------
-
-/** Allocations and initializes a new app_request object */
-osrf_app_request* _osrf_app_request_init( osrf_app_session* session, osrf_message* msg );
-
-/** Frees memory used by an app_request object */
-void _osrf_app_request_free( void * req );
-
-/** Pushes the given message onto the list of 'responses' to this request */
-void _osrf_app_request_push_queue( osrf_app_request*, osrf_message* payload );
-
-/** Checks the receive queue for messages. If any are found, the first
- * is popped off and returned. Otherwise, this method will wait at most timeout
- * seconds for a message to appear in the receive queue. Once it arrives it is returned.
- * If no messages arrive in the timeout provided, null is returned.
- */
-osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout );
-
-/** Resend this requests original request message */
-int _osrf_app_request_resend( osrf_app_request* req );
-
-
/* tells the request to reset it's wait timeout */
-void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id );
+void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id );
-// --------------------------------------------------------------------------
-// --------------------------------------------------------------------------
-// Session functions
-// --------------------------------------------------------------------------
-
-/** Returns the app_request with the given thread_trace (request_id) */
-osrf_app_request* _osrf_app_session_get_request( osrf_app_session*, int thread_trace );
-
-/** frees memory held by a session. Note: We delete all requests in the request list */
-void _osrf_app_session_free( osrf_app_session* );
-
-/** adds a session to the global session cache */
-void _osrf_app_session_push_session( osrf_app_session* );
-
-/** Adds an app_request to the request set */
-void _osrf_app_session_push_request( osrf_app_session*, osrf_app_request* req );
-
-/** Removes an app_request from this session request set, freeing the request object */
-void _osrf_app_session_remove_request( osrf_app_session*, osrf_app_request* req );
-
-/** Send the given message */
-int _osrf_app_session_send( osrf_app_session*, osrf_message* msg );
-
-int osrfAppSessionSendBatch( osrf_app_session*, osrf_message* msgs[], int size );
-
-int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
+int osrfAppRequestRespond( osrfAppSession* ses, int requestId, const jsonObject* data );
int osrfAppRequestRespondComplete(
osrfAppSession* ses, int requestId, const jsonObject* data );
-int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message );
+int osrfAppSessionStatus( osrfAppSession* ses, int type,
+ const char* name, int reqId, const char* message );
void osrfAppSessionCleanup();
Modified: trunk/src/libopensrf/osrf_app_session.c
===================================================================
--- trunk/src/libopensrf/osrf_app_session.c 2007-11-26 15:13:01 UTC (rev 1143)
+++ trunk/src/libopensrf/osrf_app_session.c 2007-11-26 18:20:40 UTC (rev 1144)
@@ -1,6 +1,13 @@
#include <opensrf/osrf_app_session.h>
#include <time.h>
+/** Send the given message */
+static int _osrf_app_session_send( osrfAppSession*, osrf_message* msg );
+
+static int osrfAppSessionMakeLocaleRequest(
+ osrfAppSession* session, const jsonObject* params, const char* method_name,
+ int protocol, string_array* param_strings, char* locale );
+
/* the global app_session cache */
osrfHash* osrfAppSessionCache = NULL;
@@ -9,12 +16,12 @@
// Request API
// --------------------------------------------------------------------------
-/** Allocation and initializes a new app_request object */
-osrf_app_request* _osrf_app_request_init(
- osrf_app_session* session, osrf_message* msg ) {
+/** Allocates and initializes a new app_request object */
+static osrfAppRequest* _osrf_app_request_init(
+ osrfAppSession* session, osrf_message* msg ) {
- osrf_app_request* req =
- (osrf_app_request*) safe_malloc(sizeof(osrf_app_request));
+ osrfAppRequest* req =
+ (osrfAppRequest*) safe_malloc(sizeof(osrfAppRequest));
req->session = session;
req->request_id = msg->thread_trace;
@@ -32,10 +39,8 @@
osrfHashFree(osrfAppSessionCache);
}
-
-
/** Frees memory used by an app_request object */
-void _osrf_app_request_free( void * req ){
+static void _osrf_app_request_free( void * req ){
if( req == NULL ) return;
osrfAppRequest* r = (osrfAppRequest*) req;
if( r->payload ) osrf_message_free( r->payload );
@@ -43,7 +48,7 @@
}
/** Pushes the given message onto the list of 'responses' to this request */
-void _osrf_app_request_push_queue( osrf_app_request* req, osrf_message* result ){
+static void _osrf_app_request_push_queue( osrfAppRequest* req, osrf_message* result ){
if(req == NULL || result == NULL) return;
osrfLogDebug( OSRF_LOG_MARK, "App Session pushing request [%d] onto request queue", result->thread_trace );
if(req->result == NULL) {
@@ -63,19 +68,19 @@
/** Removes this app_request from our session request set */
void osrf_app_session_request_finish(
- osrf_app_session* session, int req_id ){
+ osrfAppSession* session, int req_id ){
if(session == NULL) return;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
if(req == NULL) return;
osrfListRemove( req->session->request_queue, req->request_id );
}
-void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id ) {
+void osrf_app_session_request_reset_timeout( osrfAppSession* session, int req_id ) {
if(session == NULL) return;
osrfLogDebug( OSRF_LOG_MARK, "Resetting request timeout %d", req_id );
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
if(req == NULL) return;
req->reset_timeout = 1;
}
@@ -85,7 +90,7 @@
* seconds for a message to appear in the receive queue. Once it arrives it is returned.
* If no messages arrive in the timeout provided, null is returned.
*/
-osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout ) {
+static osrf_message* _osrf_app_request_recv( osrfAppRequest* req, int timeout ) {
if(req == NULL) return NULL;
@@ -154,7 +159,7 @@
}
/** Resend this requests original request message */
-int _osrf_app_request_resend( osrf_app_request* req ) {
+static int _osrf_app_request_resend( osrfAppRequest* req ) {
if(req == NULL) return 0;
if(!req->complete) {
osrfLogDebug( OSRF_LOG_MARK, "Resending request [%d]", req->request_id );
@@ -171,7 +176,7 @@
// --------------------------------------------------------------------------
/** returns a session from the global session hash */
-char* osrf_app_session_set_locale( osrf_app_session* session, const char* locale ) {
+char* osrf_app_session_set_locale( osrfAppSession* session, const char* locale ) {
if (!session || !locale)
return NULL;
@@ -183,14 +188,14 @@
}
/** returns a session from the global session hash */
-osrf_app_session* osrf_app_session_find_session( const char* session_id ) {
+osrfAppSession* osrf_app_session_find_session( const char* session_id ) {
if(session_id) return osrfHashGet(osrfAppSessionCache, session_id);
return NULL;
}
/** adds a session to the global session cache */
-void _osrf_app_session_push_session( osrf_app_session* session ) {
+static void _osrf_app_session_push_session( osrfAppSession* session ) {
if(!session) return;
if( osrfAppSessionCache == NULL ) osrfAppSessionCache = osrfNewHash();
if( osrfHashGet( osrfAppSessionCache, session->session_id ) ) return;
@@ -199,18 +204,18 @@
/** Allocates and initializes a new app_session */
-osrf_app_session* osrfAppSessionClientInit( const char* remote_service ) {
+osrfAppSession* osrfAppSessionClientInit( const char* remote_service ) {
return osrf_app_client_session_init( remote_service );
}
-osrf_app_session* osrf_app_client_session_init( const char* remote_service ) {
+osrfAppSession* osrf_app_client_session_init( const char* remote_service ) {
if (!remote_service) {
osrfLogWarning( OSRF_LOG_MARK, "No remote service specified in osrf_app_client_session_init");
return NULL;
}
- osrf_app_session* session = safe_malloc(sizeof(osrf_app_session));
+ osrfAppSession* session = safe_malloc(sizeof(osrfAppSession));
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
@@ -290,16 +295,16 @@
return session;
}
-osrf_app_session* osrf_app_server_session_init(
+osrfAppSession* osrf_app_server_session_init(
const char* session_id, const char* our_app, const char* remote_id ) {
osrfLogDebug( OSRF_LOG_MARK, "Initing server session with session id %s, service %s,"
" and remote_id %s", session_id, our_app, remote_id );
- osrf_app_session* session = osrf_app_session_find_session( session_id );
+ osrfAppSession* session = osrf_app_session_find_session( session_id );
if(session) return session;
- session = safe_malloc(sizeof(osrf_app_session));
+ session = safe_malloc(sizeof(osrfAppSession));
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
@@ -323,11 +328,14 @@
#ifdef ASSUME_STATELESS
session->stateless = 1;
+ #else
+ session->stateless = 0;
#endif
session->thread_trace = 0;
session->state = OSRF_SESSION_DISCONNECTED;
session->type = OSRF_SESSION_SERVER;
+ session->session_locale = NULL;
session->userData = NULL;
session->userDataFree = NULL;
@@ -340,7 +348,7 @@
/** frees memory held by a session */
-void _osrf_app_session_free( osrf_app_session* session ){
+static void _osrf_app_session_free( osrfAppSession* session ){
if(session==NULL)
return;
@@ -359,32 +367,25 @@
}
int osrfAppSessionMakeRequest(
- osrf_app_session* session, const jsonObject* params,
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings ) {
- return osrf_app_session_make_locale_req( session, params,
+ return osrfAppSessionMakeLocaleRequest( session, params,
method_name, protocol, param_strings, NULL );
}
-int osrfAppSessionMakeLocaleRequest(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
- int protocol, string_array* param_strings, char* locale ) {
-
- return osrf_app_session_make_locale_req( session, params,
- method_name, protocol, param_strings, locale );
-}
-
-int osrf_app_session_make_req(
- osrf_app_session* session, const jsonObject* params,
+int osrf_app_session_make_req(
+ osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings) {
- return osrf_app_session_make_locale_req(session, params,
+ return osrfAppSessionMakeLocaleRequest(session, params,
method_name, protocol, param_strings, NULL);
}
-int osrf_app_session_make_locale_req(
- osrf_app_session* session, const jsonObject* params, const char* method_name,
+static int osrfAppSessionMakeLocaleRequest(
+ osrfAppSession* session, const jsonObject* params, const char* method_name,
int protocol, string_array* param_strings, char* locale ) {
+
if(session == NULL) return -1;
osrfLogMkXid();
@@ -412,7 +413,7 @@
}
}
- osrf_app_request* req = _osrf_app_request_init( session, req_msg );
+ osrfAppRequest* req = _osrf_app_request_init( session, req_msg );
if(_osrf_app_session_send( session, req_msg ) ) {
osrfLogWarning( OSRF_LOG_MARK, "Error sending request message [%d]", session->thread_trace );
return -1;
@@ -424,18 +425,18 @@
return req->request_id;
}
-void osrf_app_session_set_complete( osrf_app_session* session, int request_id ) {
+void osrf_app_session_set_complete( osrfAppSession* session, int request_id ) {
if(session == NULL)
return;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
if(req) req->complete = 1;
}
-int osrf_app_session_request_complete( const osrf_app_session* session, int request_id ) {
+int osrf_app_session_request_complete( const osrfAppSession* session, int request_id ) {
if(session == NULL)
return 0;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, request_id );
if(req)
return req->complete;
return 0;
@@ -443,7 +444,7 @@
/** Resets the remote connection id to that of the original*/
-void osrf_app_session_reset_remote( osrf_app_session* session ){
+void osrf_app_session_reset_remote( osrfAppSession* session ){
if( session==NULL )
return;
@@ -454,7 +455,7 @@
session->remote_id = strdup(session->orig_remote_id);
}
-void osrf_app_session_set_remote( osrf_app_session* session, const char* remote_id ) {
+void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id ) {
if(session == NULL)
return;
if( session->remote_id )
@@ -465,23 +466,23 @@
/** pushes the given message into the result list of the app_request
with the given request_id */
int osrf_app_session_push_queue(
- osrf_app_session* session, osrf_message* msg ){
+ osrfAppSession* session, osrf_message* msg ){
if(session == NULL || msg == NULL) return 0;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, msg->thread_trace );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, msg->thread_trace );
if(req == NULL) return 0;
_osrf_app_request_push_queue( req, msg );
return 0;
}
-int osrfAppSessionConnect( osrf_app_session* session ) {
+int osrfAppSessionConnect( osrfAppSession* session ) {
return osrf_app_session_connect(session);
}
/** Attempts to connect to the remote service */
-int osrf_app_session_connect(osrf_app_session* session){
+int osrf_app_session_connect(osrfAppSession* session){
if(session == NULL)
return 0;
@@ -522,7 +523,7 @@
/** Disconnects from the remote service */
-int osrf_app_session_disconnect( osrf_app_session* session){
+int osrf_app_session_disconnect( osrfAppSession* session){
if(session == NULL)
return 1;
@@ -547,13 +548,13 @@
return 1;
}
-int osrf_app_session_request_resend( osrf_app_session* session, int req_id ) {
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+int osrf_app_session_request_resend( osrfAppSession* session, int req_id ) {
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
return _osrf_app_request_resend( req );
}
-int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int size ) {
+static int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int size ) {
if( !(session && msgs && size > 0) ) return 0;
int retval = 0;
@@ -610,7 +611,7 @@
-int _osrf_app_session_send( osrf_app_session* session, osrf_message* msg ){
+static int _osrf_app_session_send( osrfAppSession* session, osrf_message* msg ){
if( !(session && msg) ) return 0;
osrfMessage* a[1];
a[0] = msg;
@@ -625,7 +626,7 @@
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session* session, int timeout, int* recvd ){
+int osrf_app_session_queue_wait( osrfAppSession* session, int timeout, int* recvd ){
if(session == NULL) return 0;
osrfLogDebug(OSRF_LOG_MARK, "AppSession in queue_wait with timeout %d", timeout );
return osrf_stack_entry_point(session->transport_handle, timeout, recvd);
@@ -639,7 +640,7 @@
}
-void osrf_app_session_destroy( osrf_app_session* session ){
+void osrf_app_session_destroy( osrfAppSession* session ){
if(session == NULL) return;
osrfLogDebug(OSRF_LOG_MARK, "AppSession [%s] [%s] destroying self and deleting requests",
@@ -656,14 +657,14 @@
}
osrf_message* osrfAppSessionRequestRecv(
- osrf_app_session* session, int req_id, int timeout ) {
+ osrfAppSession* session, int req_id, int timeout ) {
return osrf_app_session_request_recv( session, req_id, timeout );
}
osrf_message* osrf_app_session_request_recv(
- osrf_app_session* session, int req_id, int timeout ) {
+ osrfAppSession* session, int req_id, int timeout ) {
if(req_id < 0 || session == NULL)
return NULL;
- osrf_app_request* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
+ osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
return _osrf_app_request_recv( req, timeout );
}
@@ -716,7 +717,8 @@
return 0;
}
-int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message ) {
+int osrfAppSessionStatus( osrfAppSession* ses, int type,
+ const char* name, int reqId, const char* message ) {
if(ses) {
osrf_message* msg = osrf_message_init( STATUS, reqId, 1);
More information about the opensrf-commits
mailing list