Author: abroekhuis
Date: Mon May 30 05:48:15 2011
New Revision: 1128996

URL: http://svn.apache.org/viewvc?rev=1128996&view=rev
Log:
Pushed APR initialization to the launcher to be able to use it throughout the 
code. replaced strdup with apr_pstrdup.

Modified:
    incubator/celix/trunk/celix_test/framework_test.c
    incubator/celix/trunk/framework/private/include/bundle.h
    incubator/celix/trunk/framework/private/include/framework.h
    incubator/celix/trunk/framework/private/include/headers.h
    incubator/celix/trunk/framework/private/include/module.h
    incubator/celix/trunk/framework/private/src/bundle.c
    incubator/celix/trunk/framework/private/src/bundle_archive.c
    incubator/celix/trunk/framework/private/src/bundle_cache.c
    incubator/celix/trunk/framework/private/src/bundle_revision.c
    incubator/celix/trunk/framework/private/src/framework.c
    incubator/celix/trunk/framework/private/src/module.c
    incubator/celix/trunk/launcher/launcher.c
    incubator/celix/trunk/mongoose/activator.c

Modified: incubator/celix/trunk/celix_test/framework_test.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/celix_test/framework_test.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/celix_test/framework_test.c (original)
+++ incubator/celix/trunk/celix_test/framework_test.c Mon May 30 05:48:15 2011
@@ -29,7 +29,17 @@
 
 void test_framework_create(void) {
        struct framework * framework;
-       framework_create(&framework);
+       apr_pool_t *memoryPool;
+
+       apr_status_t rv = apr_initialize();
+    if (rv != APR_SUCCESS) {
+        CU_FAIL("Could not initialize APR");
+        return;
+    }
+
+    apr_pool_create(&memoryPool, NULL);
+
+       framework_create(&framework, memoryPool);
 
 
        CU_ASSERT(framework == NULL);

Modified: incubator/celix/trunk/framework/private/include/bundle.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle.h?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle.h Mon May 30 
05:48:15 2011
@@ -47,7 +47,7 @@ MANIFEST bundle_getManifest(BUNDLE bundl
 void bundle_setManifest(BUNDLE bundle, MANIFEST manifest);
 BUNDLE_CONTEXT bundle_getContext(BUNDLE bundle);
 void bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context);
-celix_status_t bundle_getEntry(BUNDLE bundle, char * name, char **entry);
+celix_status_t bundle_getEntry(BUNDLE bundle, char * name, apr_pool_t *pool, 
char **entry);
 
 void startBundle(BUNDLE bundle, int options);
 celix_status_t bundle_update(BUNDLE bundle, char *inputFile);

Modified: incubator/celix/trunk/framework/private/include/framework.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/framework.h?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/framework.h (original)
+++ incubator/celix/trunk/framework/private/include/framework.h Mon May 30 
05:48:15 2011
@@ -33,14 +33,14 @@
 #include "array_list.h"
 #include "celix_errno.h"
 
-celix_status_t framework_create(FRAMEWORK *framework);
+celix_status_t framework_create(FRAMEWORK *framework, apr_pool_t *memoryPool);
 celix_status_t framework_destroy(FRAMEWORK framework);
 
 celix_status_t fw_init(FRAMEWORK framework);
 
 celix_status_t fw_installBundle(FRAMEWORK framework, BUNDLE * bundle, char * 
location);
 
-celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, 
char *name, char **entry);
+celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, 
char *name, apr_pool_t *pool, char **entry);
 
 celix_status_t fw_startBundle(FRAMEWORK framework, BUNDLE bundle, int options);
 celix_status_t framework_updateBundle(FRAMEWORK framework, BUNDLE bundle, char 
*inputFile);

Modified: incubator/celix/trunk/framework/private/include/headers.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/headers.h?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/headers.h (original)
+++ incubator/celix/trunk/framework/private/include/headers.h Mon May 30 
05:48:15 2011
@@ -41,7 +41,9 @@
 #include "bundle_state.h"
 #include "bundle_cache.h"
 
-#include "apr_general.h"
+#include <apr_general.h>
+#include <apr_thread_cond.h>
+#include <apr_thread_mutex.h>
 
 #if defined(__GNUC__)
 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
@@ -59,11 +61,12 @@ struct framework {
        struct serviceRegistry * registry;
        BUNDLE_CACHE cache;
 
-       pthread_cond_t shutdownGate;
-       pthread_cond_t condition;
+       apr_thread_cond_t *shutdownGate;
+       apr_thread_cond_t *condition;
 
-       pthread_mutex_t mutex;
-       pthread_mutex_t bundleLock;
+       apr_thread_mutex_t *installRequestLock;
+       apr_thread_mutex_t *mutex;
+       apr_thread_mutex_t *bundleLock;
 
        pthread_t globalLockThread;
        ARRAY_LIST globalLockWaitersList;

Modified: incubator/celix/trunk/framework/private/include/module.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/module.h?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/module.h (original)
+++ incubator/celix/trunk/framework/private/include/module.h Mon May 30 
05:48:15 2011
@@ -33,7 +33,7 @@
 #include "manifest.h"
 
 MODULE module_create(MANIFEST headerMap, char * moduleId, BUNDLE bundle);
-MODULE module_createFrameworkModule();
+MODULE module_createFrameworkModule(BUNDLE bundle);
 
 unsigned int module_hash(void * module);
 int module_equals(void * module, void * compare);

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Mon May 30 05:48:15 
2011
@@ -25,6 +25,7 @@
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
+#include <apr_strings.h>
 
 #include "bundle.h"
 #include "framework.h"
@@ -51,7 +52,7 @@ celix_status_t bundle_create(BUNDLE * bu
        (*bundle)->state = BUNDLE_INSTALLED;
        (*bundle)->modules = arrayList_create();
 
-       MODULE module = module_createFrameworkModule();
+       MODULE module = module_createFrameworkModule((*bundle));
        bundle_addModule(*bundle, module);
        // (*bundle)->module = module;
 
@@ -144,8 +145,8 @@ void bundle_setContext(BUNDLE bundle, BU
        bundle->context = context;
 }
 
-celix_status_t bundle_getEntry(BUNDLE bundle, char * name, char **entry) {
-       return framework_getBundleEntry(bundle->framework, bundle, name, entry);
+celix_status_t bundle_getEntry(BUNDLE bundle, char * name, apr_pool_t *pool, 
char **entry) {
+       return framework_getBundleEntry(bundle->framework, bundle, name, pool, 
entry);
 }
 
 BUNDLE_STATE bundle_getState(BUNDLE bundle) {
@@ -172,7 +173,7 @@ MODULE bundle_createModule(BUNDLE bundle
         char moduleId[sizeof(bundleId) + sizeof(revision) + 2];
         sprintf(moduleId, "%ld.%d", bundleId, revision);
 
-        MODULE module = module_create(headerMap, strdup(moduleId), bundle);
+        MODULE module = module_create(headerMap, 
apr_pstrdup(bundle->memoryPool, moduleId), bundle);
 
         if (module != NULL) {
             VERSION bundleVersion = module_getVersion(module);

Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Mon May 30 
05:48:15 2011
@@ -33,6 +33,7 @@
 #include "linked_list_iterator.h"
 
 #include <apr_file_io.h>
+#include <apr_strings.h>
 
 struct bundleArchive {
        long id;
@@ -108,9 +109,6 @@ celix_status_t bundleArchive_destroy(BUN
                // closedir(archive->archiveRootDir);
                apr_dir_close(archive->archiveRootDir);
        }
-       if (archive->archiveRoot != NULL) {
-               free(archive->archiveRoot);
-       }
        if (archive->revisions != NULL) {
                LINKED_LIST_ITERATOR iter = 
linkedListIterator_create(archive->revisions, 0);
                while (linkedListIterator_hasNext(iter)) {
@@ -157,7 +155,6 @@ celix_status_t bundleArchive_recreate(ch
 
                 *bundle_archive = archive;
             }
-            free(location);
         } else {
             status = CELIX_FILE_IO_EXCEPTION;
         }
@@ -207,7 +204,7 @@ char * bundleArchive_getLocation(BUNDLE_
        apr_file_gets (location , sizeof(location) , bundleLocationFile);
        apr_file_close(bundleLocationFile);
 
-       return strdup(location);
+       return apr_pstrdup(archive->mp, location);
 }
 
 char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive) {
@@ -427,7 +424,7 @@ celix_status_t bundleArchive_getRevision
         apr_file_gets (location , sizeof(location) , revisionLocationFile);
         apr_file_close(revisionLocationFile);
 
-        *revision_location = strdup(location);
+        *revision_location = apr_pstrdup(archive->mp, location);
         status = CELIX_SUCCESS;
        } else {
            // revision file not found

Modified: incubator/celix/trunk/framework/private/src/bundle_cache.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_cache.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Mon May 30 
05:48:15 2011
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 
 #include <apr_file_io.h>
+#include <apr_strings.h>
 
 #include "bundle_cache.h"
 #include "bundle_archive.h"
@@ -124,7 +125,7 @@ celix_status_t bundleCache_getArchives(B
                     && (strcmp(dp.name, "bundle0") != 0)) {
 
                 BUNDLE_ARCHIVE archive = NULL;
-                status = bundleArchive_recreate(strdup(archiveRoot), 
cache->mp, &archive);
+                status = bundleArchive_recreate(apr_pstrdup(cache->mp, 
archiveRoot), cache->mp, &archive);
                 if (status == CELIX_SUCCESS) {
                     arrayList_add(list, archive);
                 }
@@ -152,7 +153,7 @@ celix_status_t bundleCache_createArchive
        if (cache && location && bundlePool) {
         sprintf(archiveRoot, "%s/bundle%ld",  cache->cacheDir, id);
 
-        status = bundleArchive_create(strdup(archiveRoot), id, location, 
bundlePool, bundle_archive);
+        status = bundleArchive_create(apr_pstrdup(cache->mp, archiveRoot), id, 
location, bundlePool, bundle_archive);
        }
 
        return status;

Modified: incubator/celix/trunk/framework/private/src/bundle_revision.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_revision.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_revision.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_revision.c Mon May 30 
05:48:15 2011
@@ -6,6 +6,7 @@
  */
 #include <stdlib.h>
 #include <string.h>
+#include <apr_strings.h>
 
 #include "bundle_revision.h"
 
@@ -31,8 +32,8 @@ celix_status_t bundleRevision_create(cha
 
         if (status == CELIX_SUCCESS) {
             revision->revisionNr = revisionNr;
-            revision->root = strdup(root);
-            revision->location = strdup(location);
+            revision->root = apr_pstrdup(pool, root);
+            revision->location = apr_pstrdup(pool, location);
             *bundle_revision = revision;
         }
     }
@@ -41,8 +42,6 @@ celix_status_t bundleRevision_create(cha
 }
 
 void bundleRevision_destroy(BUNDLE_REVISION revision) {
-    free(revision->root);
-    free(revision->location);
 }
 
 long bundleRevision_getNumber(BUNDLE_REVISION revision) {

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Mon May 30 05:48:15 
2011
@@ -29,10 +29,12 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <stdbool.h>
-#include <pthread.h>
 #include <math.h>
 #include <apr_file_io.h>
 #include <apr_general.h>
+#include <apr_strings.h>
+#include <apr_thread_cond.h>
+#include <apr_thread_mutex.h>
 
 #include "framework.h"
 #include "filter.h"
@@ -60,8 +62,6 @@ ARRAY_LIST m_serviceListeners;
 
 HASH_MAP m_installRequestMap;
 
-pthread_mutex_t m_installRequestLock = PTHREAD_MUTEX_INITIALIZER;
-
 celix_status_t framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE 
bundle, int state);
 celix_status_t framework_markBundleResolved(FRAMEWORK framework, MODULE 
module);
 
@@ -92,50 +92,73 @@ struct fw_refreshHelper {
     BUNDLE_STATE oldState;
 };
 
-celix_status_t framework_create(FRAMEWORK *framework) {
-       *framework = (FRAMEWORK) malloc(sizeof(**framework));
-       if (*framework == NULL) {
-               return CELIX_ENOMEM;
-       }
+celix_status_t framework_create(FRAMEWORK *framework, apr_pool_t *memoryPool) {
+    celix_status_t status = CELIX_SUCCESS;
 
-       apr_status_t rv = apr_initialize();
-       if (rv != APR_SUCCESS) {
-               return CELIX_START_ERROR;
+       *framework = (FRAMEWORK) apr_palloc(memoryPool, sizeof(**framework));
+       if (*framework == NULL) {
+               status = CELIX_ENOMEM;
+       } else {
+           apr_status_t apr_status = apr_pool_create(&(*framework)->mp, 
memoryPool);
+        if (apr_status != APR_SUCCESS) {
+            status = CELIX_FRAMEWORK_EXCEPTION;
+        } else {
+            BUNDLE bundle = NULL;
+            apr_pool_t *bundlePool;
+            apr_status_t apr_status = apr_pool_create(&bundlePool, 
(*framework)->mp);
+            if (apr_status != APR_SUCCESS) {
+                status = CELIX_FRAMEWORK_EXCEPTION;
+            } else {
+                apr_status_t apr_status = bundle_create(&bundle, bundlePool);
+                if (apr_status != CELIX_SUCCESS) {
+                    status = CELIX_FRAMEWORK_EXCEPTION;
+                } else {
+                    (*framework)->bundle = bundle;
+                    (*framework)->bundle->framework = (*framework);
+
+                    (*framework)->installedBundleMap = NULL;
+                    (*framework)->registry = NULL;
+
+                    apr_status_t apr_status = 
apr_thread_cond_create(&(*framework)->condition, (*framework)->mp);
+                    if (apr_status != APR_SUCCESS) {
+                        status = CELIX_FRAMEWORK_EXCEPTION;
+                    } else {
+                        apr_status_t apr_status = 
apr_thread_mutex_create(&(*framework)->mutex, APR_THREAD_MUTEX_UNNESTED, 
(*framework)->mp);
+                        if (apr_status != APR_SUCCESS) {
+                            status = CELIX_FRAMEWORK_EXCEPTION;
+                        } else {
+                            apr_status_t apr_status = 
apr_thread_mutex_create(&(*framework)->bundleLock, APR_THREAD_MUTEX_UNNESTED, 
(*framework)->mp);
+                            if (apr_status != APR_SUCCESS) {
+                                status = CELIX_FRAMEWORK_EXCEPTION;
+                            } else {
+                                apr_status_t apr_status = 
apr_thread_mutex_create(&(*framework)->installRequestLock, 
APR_THREAD_MUTEX_UNNESTED, (*framework)->mp);
+                                if (apr_status != APR_SUCCESS) {
+                                    status = CELIX_FRAMEWORK_EXCEPTION;
+                                } else {
+                                    (*framework)->interrupted = false;
+
+                                    (*framework)->globalLockWaitersList = 
arrayList_create();
+                                    (*framework)->globalLockCount = 0;
+                                    (*framework)->globalLockThread = NULL;
+                                    (*framework)->nextBundleId = 1l;
+                                    (*framework)->cache = NULL;
+
+                                    m_installRequestMap = 
hashMap_create(string_hash, string_hash, string_equals, string_equals);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
        }
 
-       apr_pool_create(&(*framework)->mp, NULL);
-
-       BUNDLE bundle = NULL;
-       apr_pool_t *bundlePool;
-       apr_pool_create(&bundlePool, (*framework)->mp);
-       celix_status_t rvb = bundle_create(&bundle, bundlePool);
-       if (rvb != CELIX_SUCCESS) {
-               return rvb;
-       }
-       (*framework)->bundle = bundle;
-       (*framework)->bundle->framework = (*framework);
-
-       (*framework)->installedBundleMap = NULL;
-       (*framework)->registry = NULL;
-
-       pthread_cond_init(&(*framework)->condition, NULL);
-       pthread_mutex_init(&(*framework)->mutex, NULL);
-       pthread_mutex_init(&(*framework)->bundleLock, NULL);
-
-       (*framework)->interrupted = false;
-
-       (*framework)->globalLockWaitersList = arrayList_create();
-       (*framework)->globalLockCount = 0;
-       (*framework)->globalLockThread = NULL;
-       (*framework)->nextBundleId = 1l;
-       (*framework)->cache = NULL;
-
-       m_installRequestMap = hashMap_create(string_hash, string_hash, 
string_equals, string_equals);
-
-       return CELIX_SUCCESS;
+       return status;
 }
 
 celix_status_t framework_destroy(FRAMEWORK framework) {
+    celix_status_t status = CELIX_SUCCESS;
+
        HASH_MAP_ITERATOR iterator = 
hashMapIterator_create(framework->installedBundleMap);
        while (hashMapIterator_hasNext(iterator)) {
            HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iterator);
@@ -163,9 +186,8 @@ celix_status_t framework_destroy(FRAMEWO
 
 
        apr_pool_destroy(framework->mp);
-       apr_terminate();
 
-       return CELIX_SUCCESS;
+       return status;
 }
 
 celix_status_t fw_init(FRAMEWORK framework) {
@@ -226,7 +248,7 @@ celix_status_t fw_init(FRAMEWORK framewo
 
         framework_setBundleStateAndNotify(framework, framework->bundle, 
BUNDLE_STARTING);
 
-        pthread_cond_init(&framework->shutdownGate, NULL);
+        apr_thread_cond_create(&framework->shutdownGate, framework->mp);
 
         void * handle = dlopen(NULL, RTLD_LAZY|RTLD_LOCAL);
         if (handle == NULL) {
@@ -358,7 +380,7 @@ celix_status_t fw_installBundle2(FRAMEWO
        return status;
 }
 
-celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, 
char *name, char **entry) {
+celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, 
char *name, apr_pool_t *pool, char **entry) {
        BUNDLE_REVISION revision = 
bundleArchive_getCurrentRevision(bundle_getArchive(bundle));
        if ((strlen(name) > 0) && (name[0] == '/')) {
                name++;
@@ -373,7 +395,7 @@ celix_status_t framework_getBundleEntry(
                (*entry) = NULL;
                return CELIX_SUCCESS;
        } else if (ret == APR_SUCCESS || ret == APR_INCOMPLETE) {
-               (*entry) = strdup(e);
+               (*entry) = apr_pstrdup(pool, e);
                return CELIX_SUCCESS;
        }
 
@@ -420,7 +442,7 @@ celix_status_t fw_startBundle(FRAMEWORK 
                 framework_markResolvedModules(framework, wires);
                    }
                        hashMap_destroy(wires, false, false);
-                       // no break
+                       // nb
                case BUNDLE_RESOLVED:
                        if (bundleContext_create(framework, bundle, &context) 
!= CELIX_SUCCESS) {
                                return CELIX_ENOMEM;
@@ -1014,25 +1036,25 @@ BUNDLE framework_getBundleById(FRAMEWORK
 }
 
 celix_status_t framework_acquireInstallLock(FRAMEWORK framework, char * 
location) {
-       pthread_mutex_lock(&m_installRequestLock);
+    apr_thread_mutex_lock(framework->installRequestLock);
 
        while (hashMap_get(m_installRequestMap, location) != NULL) {
-               pthread_cond_wait(&framework->condition, &m_installRequestLock);
+               apr_thread_cond_wait(framework->condition, 
framework->installRequestLock);
        }
        hashMap_put(m_installRequestMap, location, location);
 
-       pthread_mutex_unlock(&m_installRequestLock);
+       apr_thread_mutex_unlock(framework->installRequestLock);
 
        return CELIX_SUCCESS;
 }
 
 celix_status_t framework_releaseInstallLock(FRAMEWORK framework, char * 
location) {
-       pthread_mutex_lock(&m_installRequestLock);
+    apr_thread_mutex_lock(framework->installRequestLock);
 
        hashMap_remove(m_installRequestMap, location);
-       pthread_cond_broadcast(&framework->condition);
+       apr_thread_cond_broadcast(framework->condition);
 
-       pthread_mutex_unlock(&m_installRequestLock);
+       apr_thread_mutex_unlock(framework->installRequestLock);
 
        return CELIX_SUCCESS;
 }
@@ -1040,20 +1062,20 @@ celix_status_t framework_releaseInstallL
 celix_status_t framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE 
bundle, int state) {
        int ret = CELIX_SUCCESS;
 
-       int err = pthread_mutex_lock(&framework->bundleLock);
+       int err = apr_thread_mutex_lock(framework->bundleLock);
        if (err != 0) {
                celix_log("Failed to lock");
                return CELIX_BUNDLE_EXCEPTION;
        }
 
        bundle_setState(bundle, state);
-       err = pthread_cond_broadcast(&framework->condition);
+       err = apr_thread_cond_broadcast(framework->condition);
        if (err != 0) {
                celix_log("Failed to broadcast");
                ret = CELIX_BUNDLE_EXCEPTION;
        }
 
-       err = pthread_mutex_unlock(&framework->bundleLock);
+       err = apr_thread_mutex_unlock(framework->bundleLock);
        if (err != 0) {
                celix_log("Failed to unlock");
                return CELIX_BUNDLE_EXCEPTION;
@@ -1062,7 +1084,7 @@ celix_status_t framework_setBundleStateA
 }
 
 celix_status_t framework_acquireBundleLock(FRAMEWORK framework, BUNDLE bundle, 
int desiredStates) {
-       int err = pthread_mutex_lock(&framework->bundleLock);
+       int err = apr_thread_mutex_lock(framework->bundleLock);
        if (err != 0) {
                celix_log("Failed to lock");
                return CELIX_BUNDLE_EXCEPTION;
@@ -1072,51 +1094,51 @@ celix_status_t framework_acquireBundleLo
                        || ((framework->globalLockThread != NULL)
                        && (framework->globalLockThread != pthread_self()))) {
                if ((desiredStates & bundle_getState(bundle)) == 0) {
-                       pthread_mutex_unlock(&framework->bundleLock);
+                   apr_thread_mutex_unlock(framework->bundleLock);
                        return CELIX_ILLEGAL_STATE;
                } else if (framework->globalLockThread == pthread_self()
                                && (bundle_getLockingThread(bundle) != NULL)
                                && 
arrayList_contains(framework->globalLockWaitersList, 
bundle_getLockingThread(bundle))) {
                        framework->interrupted = true;
 //                     pthread_cond_signal_thread_np(&framework->condition, 
bundle_getLockingThread(bundle));
-                       pthread_cond_signal(&framework->condition);
+                       apr_thread_cond_signal(framework->condition);
                }
 
-               pthread_cond_wait(&framework->condition, 
&framework->bundleLock);
+               apr_thread_cond_wait(framework->condition, 
framework->bundleLock);
        }
 
        if ((desiredStates & bundle_getState(bundle)) == 0) {
-               pthread_mutex_unlock(&framework->bundleLock);
+           apr_thread_mutex_unlock(framework->bundleLock);
                return CELIX_ILLEGAL_STATE;
        }
 
        if (!bundle_lock(bundle)) {
-               pthread_mutex_unlock(&framework->bundleLock);
+           apr_thread_mutex_unlock(framework->bundleLock);
                return CELIX_ILLEGAL_STATE;
        }
 
-       pthread_mutex_unlock(&framework->bundleLock);
+       apr_thread_mutex_unlock(framework->bundleLock);
        return CELIX_SUCCESS;
 }
 
 bool framework_releaseBundleLock(FRAMEWORK framework, BUNDLE bundle) {
-       pthread_mutex_lock(&framework->bundleLock);
+    apr_thread_mutex_lock(framework->bundleLock);
 
        if (!bundle_unlock(bundle)) {
-               pthread_mutex_unlock(&framework->bundleLock);
+           apr_thread_mutex_unlock(framework->bundleLock);
                return false;
        }
        if (bundle_getLockingThread(bundle) == NULL) {
-               pthread_cond_broadcast(&framework->condition);
+           apr_thread_cond_broadcast(framework->condition);
        }
 
-       pthread_mutex_unlock(&framework->bundleLock);
+       apr_thread_mutex_unlock(framework->bundleLock);
 
        return true;
 }
 
 bool framework_acquireGlobalLock(FRAMEWORK framework) {
-       pthread_mutex_lock(&framework->bundleLock);
+    apr_thread_mutex_lock(framework->bundleLock);
 
        bool interrupted = false;
 
@@ -1125,9 +1147,9 @@ bool framework_acquireGlobalLock(FRAMEWO
                        && (framework->globalLockThread != pthread_self())) {
                pthread_t currentThread = pthread_self();
                arrayList_add(framework->globalLockWaitersList, currentThread);
-               pthread_cond_broadcast(&framework->condition);
+               apr_thread_cond_broadcast(framework->condition);
 
-               pthread_cond_wait(&framework->condition, 
&framework->bundleLock);
+               apr_thread_cond_wait(framework->condition, 
framework->bundleLock);
                if (framework->interrupted) {
                        interrupted = true;
                        framework->interrupted = false;
@@ -1141,14 +1163,14 @@ bool framework_acquireGlobalLock(FRAMEWO
                framework->globalLockThread = pthread_self();
        }
 
-       pthread_mutex_unlock(&framework->bundleLock);
+       apr_thread_mutex_unlock(framework->bundleLock);
 
        return !interrupted;
 }
 
 celix_status_t framework_releaseGlobalLock(FRAMEWORK framework) {
        int ret = CELIX_SUCCESS;
-       if (pthread_mutex_lock(&framework->bundleLock) != 0) {
+       if (apr_thread_mutex_lock(framework->bundleLock) != 0) {
                celix_log("Error locking framework bundle lock");
                return CELIX_FRAMEWORK_EXCEPTION;
        }
@@ -1157,7 +1179,7 @@ celix_status_t framework_releaseGlobalLo
                framework->globalLockCount--;
                if (framework->globalLockCount == 0) {
                        framework->globalLockThread = NULL;
-                       if (pthread_cond_broadcast(&framework->condition) != 0) 
{
+                       if (apr_thread_cond_broadcast(framework->condition) != 
0) {
                                celix_log("Failed to broadcast global lock 
release.");
                                ret = CELIX_FRAMEWORK_EXCEPTION;
                                // still need to unlock before returning
@@ -1167,7 +1189,7 @@ celix_status_t framework_releaseGlobalLo
                printf("The current thread does not own the global lock");
        }
 
-       if (pthread_mutex_unlock(&framework->bundleLock) != 0) {
+       if (apr_thread_mutex_unlock(framework->bundleLock) != 0) {
                celix_log("Error unlocking framework bundle lock");
                return CELIX_FRAMEWORK_EXCEPTION;
        }
@@ -1175,15 +1197,15 @@ celix_status_t framework_releaseGlobalLo
 }
 
 celix_status_t framework_waitForStop(FRAMEWORK framework) {
-       if (pthread_mutex_lock(&framework->mutex) != 0) {
+       if (apr_thread_mutex_lock(framework->mutex) != 0) {
                celix_log("Error locking the framework, shutdown gate not 
set.");
                return CELIX_FRAMEWORK_EXCEPTION;
        }
-       if (pthread_cond_wait(&framework->shutdownGate, &framework->mutex) != 
0) {
+       if (apr_thread_cond_wait(framework->shutdownGate, framework->mutex) != 
0) {
                celix_log("Error waiting for shutdown gate.");
                return CELIX_FRAMEWORK_EXCEPTION;
        }
-       if (pthread_mutex_unlock(&framework->mutex) != 0) {
+       if (apr_thread_mutex_unlock(framework->mutex) != 0) {
                celix_log("Error unlocking the framework.");
                return CELIX_FRAMEWORK_EXCEPTION;
        }
@@ -1203,16 +1225,16 @@ static void * framework_shutdown(void * 
        }
        hashMapIterator_destroy(iterator);
 
-       int err = pthread_mutex_lock(&fw->mutex);
+       int err = apr_thread_mutex_lock(fw->mutex);
        if (err != 0) {
                celix_log("Error locking the framework, cannot exit clean.");
                pthread_exit(NULL);
                return NULL;
        }
-       err = pthread_cond_broadcast(&fw->shutdownGate);
+       err = apr_thread_cond_broadcast(fw->shutdownGate);
        if (err != 0) {
                celix_log("Error waking the shutdown gate, cannot exit clean.");
-               err = pthread_mutex_unlock(&fw->mutex);
+               err = apr_thread_mutex_unlock(fw->mutex);
                if (err != 0) {
                        celix_log("Error unlocking the framework, cannot exit 
clean.");
                }
@@ -1220,7 +1242,7 @@ static void * framework_shutdown(void * 
                pthread_exit(NULL);
                return NULL;
        }
-       err = pthread_mutex_unlock(&fw->mutex);
+       err = apr_thread_mutex_unlock(fw->mutex);
        if (err != 0) {
                celix_log("Error unlocking the framework, cannot exit clean.");
        }

Modified: incubator/celix/trunk/framework/private/src/module.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/module.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/module.c (original)
+++ incubator/celix/trunk/framework/private/src/module.c Mon May 30 05:48:15 
2011
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <apr_strings.h>
 
 #include "module.h"
 #include "manifest_parser.h"
@@ -53,14 +54,14 @@ MODULE module_create(MANIFEST headerMap,
     if (headerMap != NULL) {
         MODULE module = (MODULE) malloc(sizeof(*module));
         module->headerMap = headerMap;
-        module->id = moduleId;
+        module->id = apr_pstrdup(bundle->memoryPool, moduleId);
         module->bundle = bundle;
         module->resolved = false;
 
         module->dependentImporters = arrayList_create();
 
         MANIFEST_PARSER mp = manifestParser_createManifestParser(module, 
headerMap);
-        module->symbolicName = strdup(mp->bundleSymbolicName);
+        module->symbolicName = apr_pstrdup(bundle->memoryPool, 
mp->bundleSymbolicName);
         module->version = mp->bundleVersion;
         module->capabilities = mp->capabilities;
         module->requirements = mp->requirements;
@@ -74,10 +75,10 @@ MODULE module_create(MANIFEST headerMap,
     }
 }
 
-MODULE module_createFrameworkModule() {
+MODULE module_createFrameworkModule(BUNDLE bundle) {
        MODULE module = (MODULE) malloc(sizeof(*module));
-       module->id = strdup("0");
-       module->symbolicName = strdup("framework");
+       module->id = apr_pstrdup(bundle->memoryPool, "0");
+       module->symbolicName = apr_pstrdup(bundle->memoryPool, "framework");
        module->version = version_createVersion(1, 0, 0, "");
        module->capabilities = linkedList_create();
        module->requirements = linkedList_create();
@@ -116,8 +117,6 @@ void module_destroy(MODULE module) {
        }
        module->headerMap = NULL;
 
-       free(module->symbolicName);
-       free(module->id);
        free(module);
 }
 

Modified: incubator/celix/trunk/launcher/launcher.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/launcher.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/launcher.c (original)
+++ incubator/celix/trunk/launcher/launcher.c Mon May 30 05:48:15 2011
@@ -20,6 +20,8 @@
 #include <string.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <apr_general.h>
+#include <apr_strings.h>
 
 #include "framework.h"
 #include "properties.h"
@@ -28,22 +30,31 @@
 #include "bundle.h"
 #include "linked_list_iterator.h"
 
-static void launcher_load_custom_bundles(void);
 void launcher_shutdown(int signal);
 
 int running = 0;
 
-#include <stdio.h>
-
 struct framework * framework;
+apr_pool_t *memoryPool;
 
 int main(void) {
        // Set signal handler
        (void) signal(SIGINT, launcher_shutdown);
+
+       apr_status_t rv = apr_initialize();
+    if (rv != APR_SUCCESS) {
+        return CELIX_START_ERROR;
+    }
+
+    apr_status_t s = apr_pool_create(&memoryPool, NULL);
+    if (s != APR_SUCCESS) {
+        return CELIX_START_ERROR;
+    }
+
     PROPERTIES config = properties_load("config.properties");
     char * autoStart = properties_get(config, "cosgi.auto.start.1");
     framework = NULL;
-    framework_create(&framework);
+    framework_create(&framework, memoryPool);
     fw_init(framework);
 
     // Start the system bundle
@@ -54,7 +65,7 @@ int main(void) {
     LINKED_LIST bundles = linkedList_create();
     result = strtok(autoStart, delims);
     while (result != NULL) {
-       char * location = strdup(result);
+       char * location = apr_pstrdup(memoryPool, result);
        linkedList_addElement(bundles, location);
        result = strtok(NULL, delims);
     }
@@ -85,6 +96,10 @@ int main(void) {
     framework_waitForStop(framework);
     framework_destroy(framework);
     properties_destroy(config);
+
+    apr_pool_destroy(memoryPool);
+    apr_terminate();
+
     return 0;
 }
 

Modified: incubator/celix/trunk/mongoose/activator.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/mongoose/activator.c?rev=1128996&r1=1128995&r2=1128996&view=diff
==============================================================================
--- incubator/celix/trunk/mongoose/activator.c (original)
+++ incubator/celix/trunk/mongoose/activator.c Mon May 30 05:48:15 2011
@@ -47,16 +47,22 @@ celix_status_t bundleActivator_start(voi
        struct userData * data = (struct userData *) userData;
 
        if (bundleContext_getBundle(context, &bundle) == CELIX_SUCCESS) {
-               char *entry = NULL;
-               bundle_getEntry(bundle, "root", &entry);
-
-               const char *options[] = {
-                       "document_root", entry,
-                       NULL
-               };
-               data->ctx = mg_start(NULL, options);
-
-               printf("Mongoose started on: %s\n", mg_get_option(data->ctx, 
"listening_ports"));
+           apr_pool_t *pool;
+           celix_status_t status = bundleContext_getMemoryPool(context, &pool);
+           if (status == CELIX_SUCCESS) {
+            char *entry = NULL;
+            bundle_getEntry(bundle, "root", pool, &entry);
+
+            const char *options[] = {
+                "document_root", entry,
+                NULL
+            };
+            data->ctx = mg_start(NULL, options);
+
+            printf("Mongoose started on: %s\n", mg_get_option(data->ctx, 
"listening_ports"));
+           } else {
+               status = CELIX_BUNDLE_EXCEPTION;
+           }
        } else {
                status = CELIX_START_ERROR;
        }


Reply via email to