First:
1. I moved the macros OSRF_LIST_DEFAULT_SIZE and OSRF_LIST_INC_SIZE
from the header into the implementation file. No other source files
reference them, nor should they.
2. I moved the OSRF_LIST_MAX_SIZE macro into the implementation file
as well, and then commented it out. It is nowhere referenced, but
out of caution I preserved it like a fly in amber.
3. I removed a leading underscore from each of the struct names
__osrfListStruct and __osrfListIteratorStruct.
4. I removed some obsolete comment text concerning osrfNewList().
5. I deleted the declaration for __osrfListSetSize(), which is
nowhere defined.
6. I made sure to explicitly initialize all struct members.
7. When allocating pointer arrays, I explicitly initialize all the
pointers to NULL.
8. I rewrote osrfNewList() as a thin wrapper for osrfNewListSize(),
to eliminate some duplication of code.
Second:
These patches eliminate the following identifiers, which have all been
replaced by their camel-case equivalents:
osrf_app_session_make_req
osrf_app_session_destroy
osrf_app_session_request_recv
osrf_app_request
osrf_system_get_transport_client
osrf_system_bootstrap_client_resc
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1205
9efc2488-bf62-4759-914b-
345cdb29e865
timeout and set this variable back to false */
int reset_timeout;
};
-typedef struct osrf_app_request_struct osrf_app_request;
typedef struct osrf_app_request_struct osrfAppRequest;
struct osrf_app_session_struct {
osrfAppSession* session, const jsonObject* params,
const char* method_name, int protocol, string_array* param_strings);
-int osrf_app_session_make_req(
- osrfAppSession* session, const jsonObject* params,
- const char* method_name, int protocol, string_array* param_strings);
-
/** Sets the given request to complete state */
void osrf_app_session_set_complete( osrfAppSession* session, int request_id );
/** Does a recv call on the given request */
osrf_message* osrfAppSessionRequestRecv(
osrfAppSession* session, int request_id, int timeout );
-osrf_message* osrf_app_session_request_recv(
- osrfAppSession* session, int request_id, int timeout );
/** Removes the request from the request set and frees the reqest */
void osrf_app_session_request_finish( osrfAppSession* session, int request_id );
/** 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.
+ * session is completely done.
*/
-void osrf_app_session_destroy ( osrfAppSession* );
void osrfAppSessionFree( osrfAppSession* );
/* tells the request to reset it's wait timeout */
#include <opensrf/utils.h>
-#define OSRF_LIST_DEFAULT_SIZE 48 /* most opensrf lists are small... */
-#define OSRF_LIST_INC_SIZE 256
-#define OSRF_LIST_MAX_SIZE 10240
-
-
#define OSRF_LIST_GET_INDEX(l, i) (!l || i >= l->size) ? NULL: l->arrlist[i]
/**
then, it will be used on any item that needs to be freed, so don't mix data
types in the list if you want magic freeing */
-struct __osrfListStruct {
+struct _osrfListStruct {
unsigned int size; /* how many items in the list including NULL items between non-NULL items */
void (*freeItem) (void* item); /* callback for freeing stored items */
void** arrlist;
int arrsize; /* how big is the currently allocated array */
};
-typedef struct __osrfListStruct osrfList;
+typedef struct _osrfListStruct osrfList;
-struct __osrfListIteratorStruct {
+struct _osrfListIteratorStruct {
const osrfList* list;
unsigned int current;
};
-typedef struct __osrfListIteratorStruct osrfListIterator;
+typedef struct _osrfListIteratorStruct osrfListIterator;
osrfList* osrfNewListSize( unsigned int size );
/**
Allocates a new list
- @param compress If true, the list will compress empty slots on delete. If item positionality
- is not important, then using this feature is reccomended to keep the list from growing indefinitely.
- if item positionality is not important.
@return The allocated list
*/
osrfList* osrfNewList();
/**
Puts the given item into the list at the specified position. If there
- is already an item at the given position and the list has it's
+ is already an item at the given position and the list has its
"freeItem" function defined, then it will be used to free said item.
If no 'freeItem' callback is defined, then the displaced item will
be returned;
*/
int osrfListFind( const osrfList* list, void* addr );
-
-void __osrfListSetSize( osrfList* list );
-
-
/**
@return The number of non-null items in the list
*/
@return 1 on successs, 0 on failure.
*/
int osrfSystemBootstrapClientResc( char* configFile, char* contextNode, char* resource );
-int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource );
/**
Bootstrap the server.
int osrfSystemBootstrap( char* hostName, char* configfile, char* contextNode );
transport_client* osrfSystemGetTransportClient( void );
-transport_client* osrf_system_get_transport_client( void );
/* disconnects and destroys the current client connection */
int osrf_system_disconnect_client();
method_name, protocol, param_strings, NULL );
}
-int osrf_app_session_make_req(
- osrfAppSession* session, const jsonObject* params,
- const char* method_name, int protocol, string_array* param_strings) {
-
- return osrfAppSessionMakeLocaleRequest(session, params,
- method_name, protocol, param_strings, NULL);
-}
-
static int osrfAppSessionMakeLocaleRequest(
osrfAppSession* session, const jsonObject* params, const char* method_name,
int protocol, string_array* param_strings, char* locale ) {
/** Disconnects (if client) and removes the given session from the global session cache
* ! This free's all attached app_requests !
*/
-void osrfAppSessionFree( osrfAppSession* ses ) {
- osrf_app_session_destroy( ses );
-}
-
-
-void osrf_app_session_destroy( osrfAppSession* session ){
+void osrfAppSessionFree( osrfAppSession* session ){
if(session == NULL) return;
osrfLogDebug(OSRF_LOG_MARK, "AppSession [%s] [%s] destroying self and deleting requests",
osrf_message* osrfAppSessionRequestRecv(
osrfAppSession* session, int req_id, int timeout ) {
- return osrf_app_session_request_recv( session, req_id, timeout );
-}
-osrf_message* osrf_app_session_request_recv(
- osrfAppSession* session, int req_id, int timeout ) {
if(req_id < 0 || session == NULL)
return NULL;
osrfAppRequest* req = OSRF_LIST_GET_INDEX( session->request_queue, req_id );
#include <opensrf/osrf_list.h>
+#define OSRF_LIST_DEFAULT_SIZE 48 /* most opensrf lists are small... */
+#define OSRF_LIST_INC_SIZE 256
+//#define OSRF_LIST_MAX_SIZE 10240
+
osrfList* osrfNewList() {
- osrfList* list;
- OSRF_MALLOC(list, sizeof(osrfList));
- list->arrsize = OSRF_LIST_DEFAULT_SIZE;
- OSRF_MALLOC(list->arrlist, list->arrsize * sizeof(void*));
- return list;
+ return osrfNewListSize( OSRF_LIST_DEFAULT_SIZE );
}
osrfList* osrfNewListSize( unsigned int size ) {
osrfList* list;
OSRF_MALLOC(list, sizeof(osrfList));
+ list->size = 0;
+ list->freeItem = NULL;
if( size <= 0 ) size = 16;
list->arrsize = size;
OSRF_MALLOC( list->arrlist, list->arrsize * sizeof(void*) );
+
+ // Nullify all pointers in the array
+
+ int i;
+ for( i = 0; i < list->arrsize; ++i )
+ list->arrlist[ i ] = NULL;
+
return list;
}
void* osrfListSet( osrfList* list, void* item, unsigned int position ) {
if(!list || position < 0) return NULL;
- int i;
int newsize = list->arrsize;
- void** newarr;
while( position >= newsize )
newsize += OSRF_LIST_INC_SIZE;
if( newsize > list->arrsize ) { /* expand the list if necessary */
+ void** newarr;
OSRF_MALLOC(newarr, newsize * sizeof(void*));
- for( i = 0; i < list->arrsize; i++ )
+
+ // Copy the old pointers, and nullify the new ones
+
+ int i;
+ for( i = 0; i < list->arrsize; i++ )
newarr[i] = list->arrlist[i];
+ for( ; i < newsize; i++ )
+ newarr[i] = NULL;
free(list->arrlist);
list->arrlist = newarr;
list->arrsize = newsize;
osrfGlobalTransportClient = NULL;
}
-transport_client* osrf_system_get_transport_client( void ) {
- return osrfGlobalTransportClient;
-}
-
int osrf_system_bootstrap_client( char* config_file, char* contextnode ) {
- return osrf_system_bootstrap_client_resc(config_file, contextnode, NULL);
-}
-
-int osrfSystemBootstrapClientResc( char* config_file, char* contextnode, char* resource ) {
- return osrf_system_bootstrap_client_resc( config_file, contextnode, resource );
+ return osrfSystemBootstrapClientResc(config_file, contextnode, NULL);
}
-
static int _osrfSystemInitCache( void ) {
jsonObject* cacheServers = osrf_settings_host_value_object("/cache/global/servers/server");
/*----------- End of routines to manage list of children --*/
-int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) {
+int osrfSystemBootstrapClientResc( char* config_file, char* contextnode, char* resource ) {
int failure = 0;