You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bn...@apache.org on 2002/01/31 19:49:51 UTC
cvs commit: apr/misc/netware libprews.c
bnicholes 02/01/31 10:49:51
Modified: misc/netware libprews.c
Log:
Added the necessary code to make APRLib into a real library NLM. Also
added support for application instance data since library NLMs do not
support this by default. This allows us to get global variables separated by
application instance.
Revision Changes Path
1.3 +97 -2 apr/misc/netware/libprews.c
Index: libprews.c
===================================================================
RCS file: /home/cvs/apr/misc/netware/libprews.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- libprews.c 23 Oct 2001 23:38:55 -0000 1.2
+++ libprews.c 31 Jan 2002 18:49:51 -0000 1.3
@@ -9,9 +9,24 @@
provide.
------------------------------------------------------------------*/
#include <netware.h>
-//#include "stddef.h"
+#include <library.h>
+#include <nks/synch.h>
#include "ws2nlm.h"
+#include "apr_pools.h"
+
+typedef struct app_data {
+ int initialized;
+} APP_DATA;
+
+/* library-private data...*/
+int gLibId = -1;
+void *gLibHandle = (void *) NULL;
+NXMutex_t *gLibLock = (NXMutex_t *) NULL;
+
+/* internal library function prototypes...*/
+int DisposeLibraryData(void *);
+
int _NonAppStart
(
void *NLMHandle,
@@ -28,6 +43,8 @@
const char **messages
)
{
+ NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
+
#pragma unused(cmdLine)
#pragma unused(loadDirPath)
#pragma unused(uninitializedDataLength)
@@ -39,16 +56,94 @@
#pragma unused(messages)
WSADATA wsaData;
+ apr_status_t status;
+ gLibId = register_library(DisposeLibraryData);
+
+ if (gLibId < -1)
+ {
+ OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
+ return -1;
+ }
+
+ gLibHandle = NLMHandle;
+
+ gLibLock = NXMutexAlloc(0, 0, &liblock);
+
+ if (!gLibLock)
+ {
+ OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
+ return -1;
+ }
+
+ apr_netware_setup_time();
+
+ if ((status = apr_pool_initialize()) != APR_SUCCESS)
+ return status;
+
return WSAStartup((WORD) MAKEWORD(2, 0), &wsaData);
}
void _NonAppStop( void )
{
+ apr_pool_terminate();
+
WSACleanup();
+
+ unregister_library(gLibId);
+ NXMutexFree(gLibLock);
}
int _NonAppCheckUnload( void )
{
- return 0;
+ return 0;
+}
+
+int register_NLM(void *NLMHandle)
+{
+ APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
+
+ NXLock(gLibLock);
+ if (!app_data) {
+ app_data = (APP_DATA*)library_malloc(gLibHandle, sizeof(APP_DATA));
+
+ if (app_data) {
+ memset (app_data, 0, sizeof(APP_DATA));
+ set_app_data(gLibId, app_data);
+ }
+ }
+
+ if (app_data && (!app_data->initialized)) {
+ app_data->initialized = 1;
+ NXUnlock(gLibLock);
+ return 0;
+ }
+
+ NXUnlock(gLibLock);
+ return 1;
}
+
+int unregister_NLM(void *NLMHandle)
+{
+ APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
+
+ NXLock(gLibLock);
+ if (app_data) {
+ app_data->initialized = 0;
+ NXUnlock(gLibLock);
+ return 0;
+ }
+ NXUnlock(gLibLock);
+ return 1;
+}
+
+int DisposeLibraryData(void *data)
+{
+ if (data)
+ {
+ library_free(data);
+ }
+
+ return 0;
+}
+