You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2011/07/19 14:07:20 UTC

svn commit: r1148287 [3/3] - in /incubator/celix/trunk: ./ dependency_manager/ documents/ framework/ framework/private/include/ framework/private/src/ launcher/ shell/

Added: incubator/celix/trunk/documents/memory_pools.png
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/documents/memory_pools.png?rev=1148287&view=auto
==============================================================================
Files incubator/celix/trunk/documents/memory_pools.png (added) and incubator/celix/trunk/documents/memory_pools.png Tue Jul 19 12:07:16 2011 differ

Modified: incubator/celix/trunk/framework/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/CMakeLists.txt?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/CMakeLists.txt (original)
+++ incubator/celix/trunk/framework/CMakeLists.txt Tue Jul 19 12:07:16 2011
@@ -42,4 +42,4 @@ include_directories("${PROJECT_SOURCE_DI
 add_library(framework SHARED ${SRC})
 target_link_libraries(framework utils ${ZLIB_LIBRARY} ${APR_LIBRARY} ${CURL_LIBRARY})
 
-install(TARGETS framework LIBRARY DESTINATION lib ARCHIVE DESTINATION lib COMPONENT framework)
+install(TARGETS framework DESTINATION lib COMPONENT framework)

Modified: incubator/celix/trunk/framework/private/include/attribute.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/attribute.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/attribute.h (original)
+++ incubator/celix/trunk/framework/private/include/attribute.h Tue Jul 19 12:07:16 2011
@@ -37,7 +37,5 @@ struct attribute {
 typedef struct attribute * ATTRIBUTE;
 
 celix_status_t attribute_create(char * key, char * value, apr_pool_t *memory_pool, ATTRIBUTE *attribute);
-void attribute_destroy(ATTRIBUTE attribute);
-
 
 #endif /* ATTRIBUTE_H_ */

Modified: incubator/celix/trunk/framework/private/include/bundle.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle.h Tue Jul 19 12:07:16 2011
@@ -74,7 +74,7 @@ BUNDLE_STATE bundle_getState(BUNDLE bund
 bool bundle_isLockable(BUNDLE bundle);
 pthread_t bundle_getLockingThread(BUNDLE bundle);
 bool bundle_lock(BUNDLE bundle);
-bool bundle_unlock(BUNDLE bundle);
+celix_status_t bundle_unlock(BUNDLE bundle, bool *unlocked);
 
 celix_status_t bundle_closeAndDelete(BUNDLE bundle);
 celix_status_t bundle_close(BUNDLE bundle);

Modified: incubator/celix/trunk/framework/private/include/bundle_archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_archive.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_archive.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_archive.h Tue Jul 19 12:07:16 2011
@@ -39,24 +39,25 @@ celix_status_t bundleArchive_create(char
 celix_status_t bundleArchive_destroy(BUNDLE_ARCHIVE archive);
 celix_status_t bundleArchive_createSystemBundleArchive(apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive);
 celix_status_t bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive);
-long bundleArchive_getId(BUNDLE_ARCHIVE archive);
-char * bundleArchive_getLocation(BUNDLE_ARCHIVE archive);
-char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_getId(BUNDLE_ARCHIVE archive, long *id);
+celix_status_t bundleArchive_getLocation(BUNDLE_ARCHIVE archive, char **location);
+celix_status_t bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive, char **archiveRoot);
 
-void bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location, char *inputFile);
-bool bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive);
-BUNDLE_REVISION bundleArchive_getRevision(BUNDLE_ARCHIVE archive, long revNr);
-BUNDLE_REVISION bundleArchive_getCurrentRevision(BUNDLE_ARCHIVE archive);
-long bundleArchive_getCurrentRevisionNumber(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location, char *inputFile);
+celix_status_t bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive, bool *rolledback);
+celix_status_t bundleArchive_getRevision(BUNDLE_ARCHIVE archive, long revNr, BUNDLE_REVISION *revision);
+celix_status_t bundleArchive_getCurrentRevision(BUNDLE_ARCHIVE archive, BUNDLE_REVISION *revision);
+celix_status_t bundleArchive_getCurrentRevisionNumber(BUNDLE_ARCHIVE archive, long *revisionNumber);
 
-long bundleArchive_getRefreshCount(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_getRefreshCount(BUNDLE_ARCHIVE archive, long *refreshCount);
+celix_status_t bundleArchive_setRefreshCount(BUNDLE_ARCHIVE archive);
 
-void bundleArchive_close(BUNDLE_ARCHIVE archive);
-void bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_close(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive);
 
-void bundleArchive_setLastModified(BUNDLE_ARCHIVE archive, time_t lastModifiedTime);
-time_t bundleArchive_getLastModified(BUNDLE_ARCHIVE archive);
-void bundleArchive_setPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE state);
-BUNDLE_STATE bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_setLastModified(BUNDLE_ARCHIVE archive, time_t lastModifiedTime);
+celix_status_t bundleArchive_getLastModified(BUNDLE_ARCHIVE archive, time_t *lastModified);
+celix_status_t bundleArchive_setPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE state);
+celix_status_t bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE *state);
 
 #endif /* BUNDLE_ARCHIVE_H_ */

Modified: incubator/celix/trunk/framework/private/include/bundle_revision.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle_revision.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle_revision.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle_revision.h Tue Jul 19 12:07:16 2011
@@ -16,9 +16,9 @@
 typedef struct bundleRevision * BUNDLE_REVISION;
 
 celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, apr_pool_t *pool, BUNDLE_REVISION *bundle_revision);
-void bundleRevision_destroy(BUNDLE_REVISION revision);
-long bundleRevision_getNumber(BUNDLE_REVISION revision);
-char * bundleRevision_getLocation(BUNDLE_REVISION revision);
-char * bundleRevision_getRoot(BUNDLE_REVISION revision);
+celix_status_t bundleRevision_destroy(BUNDLE_REVISION revision);
+celix_status_t bundleRevision_getNumber(BUNDLE_REVISION revision, long *revisionNr);
+celix_status_t bundleRevision_getLocation(BUNDLE_REVISION revision, char **location);
+celix_status_t bundleRevision_getRoot(BUNDLE_REVISION revision, char **root);
 
 #endif /* BUNDLE_REVISION_H_ */

Modified: incubator/celix/trunk/framework/private/include/component.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/component.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/component.h (original)
+++ incubator/celix/trunk/framework/private/include/component.h Tue Jul 19 12:07:16 2011
@@ -26,9 +26,9 @@
 #ifndef COMPONENT_H_
 #define COMPONENT_H_
 
-void start();
+void start(void);
 
-void stop();
+void stop(void);
 
 
 #endif /* COMPONENT_H_ */

Modified: incubator/celix/trunk/framework/private/include/framework.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/framework.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/framework.h (original)
+++ incubator/celix/trunk/framework/private/include/framework.h Tue Jul 19 12:07:16 2011
@@ -72,9 +72,9 @@ SERVICE_REGISTRATION findRegistration(SE
 SERVICE_REFERENCE listToArray(ARRAY_LIST list);
 celix_status_t framework_markResolvedModules(FRAMEWORK framework, HASH_MAP wires);
 
-ARRAY_LIST framework_getBundles();
+ARRAY_LIST framework_getBundles(void);
 
-celix_status_t framework_waitForStop();
+celix_status_t framework_waitForStop(void);
 
 ARRAY_LIST framework_getBundles(FRAMEWORK framework);
 BUNDLE framework_getBundle(FRAMEWORK framework, char * location);

Modified: incubator/celix/trunk/framework/private/include/headers.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/headers.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/headers.h (original)
+++ incubator/celix/trunk/framework/private/include/headers.h Tue Jul 19 12:07:16 2011
@@ -31,8 +31,10 @@
 #include <pthread.h>
 
 #include <apr_general.h>
+#include <apr_thread_proc.h>
 #include <apr_thread_cond.h>
 #include <apr_thread_mutex.h>
+#include <apr_portable.h>
 
 #include "array_list.h"
 #include "properties.h"
@@ -76,6 +78,7 @@ struct framework {
 	int globalLockCount;
 
 	bool interrupted;
+	bool shutdown;
 
 	apr_pool_t *mp;
 };
@@ -105,9 +108,9 @@ struct bundle {
 	MANIFEST manifest;
 	apr_pool_t *memoryPool;
 
-	pthread_mutex_t lock;
+	apr_thread_mutex_t *lock;
 	int lockCount;
-	pthread_t lockThread;
+	apr_os_thread_t lockThread;
 
 	struct framework * framework;
 };

Modified: incubator/celix/trunk/framework/private/include/utils.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/utils.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/utils.h (original)
+++ incubator/celix/trunk/framework/private/include/utils.h Tue Jul 19 12:07:16 2011
@@ -27,10 +27,16 @@
 #define UTILS_H_
 
 #include <ctype.h>
+#include <apr_portable.h>
+
+#include "celix_errno.h"
+#include "celixbool.h"
 
 unsigned int string_hash(void * string);
 int string_equals(void * string, void * toCompare);
 char * string_ndup(const char *s, size_t n);
 char * string_trim(char * string);
 
+celix_status_t thread_equalsSelf(apr_os_thread_t thread, bool *equals);
+
 #endif /* UTILS_H_ */

Modified: incubator/celix/trunk/framework/private/include/version.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/version.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/version.h (original)
+++ incubator/celix/trunk/framework/private/include/version.h Tue Jul 19 12:07:16 2011
@@ -32,7 +32,7 @@ typedef struct version * VERSION;
 
 VERSION version_createVersion(int major, int minor, int micro, char * qualifier);
 VERSION version_createVersionFromString(char * version);
-VERSION version_createEmptyVersion();
+VERSION version_createEmptyVersion(void);
 celix_status_t version_destroy(VERSION version);
 
 int version_compareTo(VERSION version, VERSION compare);

Modified: incubator/celix/trunk/framework/private/include/version_range.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/version_range.h?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/version_range.h (original)
+++ incubator/celix/trunk/framework/private/include/version_range.h Tue Jul 19 12:07:16 2011
@@ -33,7 +33,7 @@
 typedef struct versionRange * VERSION_RANGE;
 
 VERSION_RANGE versionRange_createVersionRange(VERSION low, bool isLowInclusive, VERSION high, bool isHighInclusive);
-VERSION_RANGE versionRange_createInfiniteVersionRange();
+VERSION_RANGE versionRange_createInfiniteVersionRange(void);
 void versionRange_destroy(VERSION_RANGE range);
 
 bool versionRange_isInRange(VERSION_RANGE versionRange, VERSION version);

Modified: incubator/celix/trunk/framework/private/src/attribute.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/attribute.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/attribute.c (original)
+++ incubator/celix/trunk/framework/private/src/attribute.c Tue Jul 19 12:07:16 2011
@@ -28,21 +28,17 @@
 #include "attribute.h"
 
 celix_status_t attribute_create(char * key, char * value, apr_pool_t *memory_pool, ATTRIBUTE *attribute) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	ATTRIBUTE attr = apr_palloc(memory_pool, sizeof(*attr));
-	if (attr) {
+	if (!attr) {
+	    status = CELIX_ENOMEM;
+	} else {
         attr->key = key;
         attr->value = value;
 
 	    *attribute = attr;
-
-        return CELIX_SUCCESS;
-	} else {
-	    return CELIX_ENOMEM;
 	}
-}
 
-void attribute_destroy(ATTRIBUTE attribute) {
-	//free(attribute->key);
-	//free(attribute->value);
-	//free(attribute);
+	return status;
 }

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Tue Jul 19 12:07:16 2011
@@ -22,10 +22,11 @@
  *  Created on: Mar 23, 2010
  *      Author: alexanderb
  */
-#include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 #include <apr_strings.h>
+#include <apr_portable.h>
+#include <apr_thread_proc.h>
 
 #include "bundle.h"
 #include "framework.h"
@@ -35,8 +36,9 @@
 #include "array_list.h"
 #include "bundle_archive.h"
 #include "resolver.h"
+#include "utils.h"
 
-MODULE bundle_createModule(BUNDLE bundle);
+celix_status_t bundle_createModule(BUNDLE bundle, MODULE *module);
 celix_status_t bundle_closeRevisions(BUNDLE bundle);
 
 celix_status_t bundle_create(BUNDLE * bundle, apr_pool_t *mp) {
@@ -61,13 +63,17 @@ celix_status_t bundle_create(BUNDLE * bu
         bundle_addModule(*bundle, module);
         // (*bundle)->module = module;
 
-        pthread_mutex_init(&(*bundle)->lock, NULL);
-        (*bundle)->lockCount = 0;
-        (*bundle)->lockThread = NULL;
+        apr_status_t apr_status = apr_thread_mutex_create(&(*bundle)->lock, APR_THREAD_MUTEX_UNNESTED, (*bundle)->memoryPool);
+        if (apr_status != APR_SUCCESS) {
+        	status = CELIX_ILLEGAL_STATE;
+        } else {
+			(*bundle)->lockCount = 0;
+			(*bundle)->lockThread = NULL;
 
-        resolver_addModule(module);
+			resolver_addModule(module);
 
-        (*bundle)->manifest = NULL;
+			(*bundle)->manifest = NULL;
+        }
 	}
 
 	return status;
@@ -88,15 +94,20 @@ celix_status_t bundle_createFromArchive(
 	(*bundle)->state = BUNDLE_INSTALLED;
 	(*bundle)->modules = arrayList_create();
 
-	MODULE module = bundle_createModule(*bundle);
-	if (module != NULL) {
+	MODULE module;
+	status = bundle_createModule(*bundle, &module);
+	if (status == CELIX_SUCCESS) {
         bundle_addModule(*bundle, module);
 
-        pthread_mutex_init(&(*bundle)->lock, NULL);
-        (*bundle)->lockCount = 0;
-        (*bundle)->lockThread = NULL;
+        apr_status_t apr_status = apr_thread_mutex_create(&(*bundle)->lock, APR_THREAD_MUTEX_UNNESTED, (*bundle)->memoryPool);
+        if (apr_status != APR_SUCCESS) {
+			status = CELIX_ILLEGAL_STATE;
+		} else {
+			(*bundle)->lockCount = 0;
+			(*bundle)->lockThread = NULL;
 
-        resolver_addModule(module);
+			resolver_addModule(module);
+		}
 	} else {
 	    status = CELIX_FILE_IO_EXCEPTION;
 	}
@@ -171,43 +182,49 @@ void bundle_setManifest(BUNDLE bundle, M
 	bundle->manifest = manifest;
 }
 
-MODULE bundle_createModule(BUNDLE bundle) {
+celix_status_t bundle_createModule(BUNDLE bundle, MODULE *module) {
+	celix_status_t status = CELIX_SUCCESS;
 	MANIFEST headerMap = NULL;
-	if (getManifest(bundle->archive, &headerMap) == CELIX_SUCCESS) {
-        long bundleId = bundleArchive_getId(bundle->archive);
-        int revision = 0;
-        char moduleId[sizeof(bundleId) + sizeof(revision) + 2];
-        sprintf(moduleId, "%ld.%d", bundleId, revision);
-
-        MODULE module = module_create(headerMap, apr_pstrdup(bundle->memoryPool, moduleId), bundle);
-
-        if (module != NULL) {
-            VERSION bundleVersion = module_getVersion(module);
-            char * symName = module_getSymbolicName(module);
-
-            ARRAY_LIST bundles = framework_getBundles(bundle->framework);
-            int i;
-            for (i = 0; i < arrayList_size(bundles); i++) {
-                BUNDLE check = (BUNDLE) arrayList_get(bundles, i);
-
-                long id = bundleArchive_getId(check->archive);
-                if (id != bundleArchive_getId(bundle->archive)) {
-                    char * sym = module_getSymbolicName(bundle_getCurrentModule(check));
-                    VERSION version = module_getVersion(bundle_getCurrentModule(check));
-                    if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
-                            !version_compareTo(bundleVersion, version)) {
-                        printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, version_toString(version));
-                        return NULL;
-                    }
-                }
-            }
-            arrayList_destroy(bundles);
+	status = getManifest(bundle->archive, &headerMap);
+	if (status == CELIX_SUCCESS) {
+        long bundleId;
+        status = bundleArchive_getId(bundle->archive, &bundleId);
+        if (status == CELIX_SUCCESS) {
+			int revision = 0;
+			char moduleId[sizeof(bundleId) + sizeof(revision) + 2];
+			sprintf(moduleId, "%ld.%d", bundleId, revision);
+
+			*module = module_create(headerMap, apr_pstrdup(bundle->memoryPool, moduleId), bundle);
+
+			if (*module != NULL) {
+				VERSION bundleVersion = module_getVersion(*module);
+				char * symName = module_getSymbolicName(*module);
+
+				ARRAY_LIST bundles = framework_getBundles(bundle->framework);
+				int i;
+				for (i = 0; i < arrayList_size(bundles); i++) {
+					BUNDLE check = (BUNDLE) arrayList_get(bundles, i);
+
+					long id;
+					if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
+						if (id != bundleId) {
+							char * sym = module_getSymbolicName(bundle_getCurrentModule(check));
+							VERSION version = module_getVersion(bundle_getCurrentModule(check));
+							if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
+									!version_compareTo(bundleVersion, version)) {
+								printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, version_toString(version));
+								status = CELIX_BUNDLE_EXCEPTION;
+								break;
+							}
+						}
+					}
+				}
+				arrayList_destroy(bundles);
+			}
         }
-
-        return module;
-	} else {
-	    return NULL;
 	}
+
+	return status;
 }
 
 void startBundle(BUNDLE bundle, int options) {
@@ -267,14 +284,22 @@ celix_status_t bundle_isUsed(BUNDLE bund
 }
 
 celix_status_t bundle_revise(BUNDLE bundle, char * location, char *inputFile) {
-	bundleArchive_revise(bundle_getArchive(bundle), location, inputFile);
-	MODULE module = bundle_createModule(bundle);
-	if (module == NULL) {
-		bundleArchive_rollbackRevise(bundle_getArchive(bundle));
-		return CELIX_BUNDLE_EXCEPTION;
+	celix_status_t status = CELIX_SUCCESS;
+	status = bundleArchive_revise(bundle_getArchive(bundle), location, inputFile);
+	if (status == CELIX_SUCCESS) {
+		MODULE module;
+		status = bundle_createModule(bundle, &module);
+		if (status == CELIX_SUCCESS) {
+			status = bundle_addModule(bundle, module);
+		} else {
+			bool rolledback;
+			status = bundleArchive_rollbackRevise(bundle_getArchive(bundle), &rolledback);
+			if (status == CELIX_SUCCESS) {
+				status = CELIX_BUNDLE_EXCEPTION;
+			}
+		}
 	}
-	bundle_addModule(bundle, module);
-	return CELIX_SUCCESS;
+	return status;
 }
 
 //bool bundle_rollbackRevise(BUNDLE bundle) {
@@ -289,60 +314,73 @@ celix_status_t bundle_addModule(BUNDLE b
 }
 
 bool bundle_isSystemBundle(BUNDLE bundle) {
-	return bundleArchive_getId(bundle_getArchive(bundle)) == 0;
+	long bundleId;
+	bundleArchive_getId(bundle_getArchive(bundle), &bundleId);
+	return bundleId == 0;
 }
 
 bool bundle_isLockable(BUNDLE bundle) {
 	bool lockable = false;
-	pthread_mutex_lock(&bundle->lock);
+	apr_thread_mutex_lock(bundle->lock);
 
 	lockable = (bundle->lockCount == 0) || (bundle->lockThread == pthread_self());
 
-	pthread_mutex_unlock(&bundle->lock);
+	apr_thread_mutex_unlock(bundle->lock);
 
 	return lockable;
 }
 
 pthread_t bundle_getLockingThread(BUNDLE bundle) {
 	pthread_t lockingThread = NULL;
-	pthread_mutex_lock(&bundle->lock);
+	apr_thread_mutex_lock(bundle->lock);
 
 	lockingThread = bundle->lockThread;
 
-	pthread_mutex_unlock(&bundle->lock);
+	apr_thread_mutex_unlock(bundle->lock);
 
 	return lockingThread;
 }
 
 bool bundle_lock(BUNDLE bundle) {
-	pthread_mutex_lock(&bundle->lock);
+	apr_thread_mutex_lock(bundle->lock);
+	bool equals;
 
-	if ((bundle->lockCount > 0) && bundle->lockThread != pthread_self()) {
+	thread_equalsSelf(bundle->lockThread, &equals);
+	if ((bundle->lockCount > 0) && !equals) {
+		apr_thread_mutex_unlock(bundle->lock);
 		return false;
 	}
 	bundle->lockCount++;
-	bundle->lockThread = pthread_self();
+	bundle->lockThread = apr_os_thread_current();
 
-	pthread_mutex_unlock(&bundle->lock);
+	apr_thread_mutex_unlock(bundle->lock);
 	return true;
 }
 
-bool bundle_unlock(BUNDLE bundle) {
-	pthread_mutex_lock(&bundle->lock);
+celix_status_t bundle_unlock(BUNDLE bundle, bool *unlocked) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	bool equals;
+
+	apr_thread_mutex_lock(bundle->lock);
 
 	if ((bundle->lockCount == 0)) {
-		return false;
-	}
-	if ((bundle->lockCount > 0) && bundle->lockThread != pthread_self()) {
-		return false;
-	}
-	bundle->lockCount--;
-	if (bundle->lockCount == 0) {
-		bundle->lockThread = NULL;
+		*unlocked = false;
+	} else {
+		thread_equalsSelf(bundle->lockThread, &equals);
+		if ((bundle->lockCount > 0) && !equals) {
+			return false;
+		}
+		bundle->lockCount--;
+		if (bundle->lockCount == 0) {
+			bundle->lockThread = NULL;
+		}
+		*unlocked = true;
 	}
 
-	pthread_mutex_unlock(&bundle->lock);
-	return true;
+	apr_thread_mutex_unlock(bundle->lock);
+
+	return status;
 }
 
 celix_status_t bundle_close(BUNDLE bundle) {
@@ -388,12 +426,21 @@ celix_status_t bundle_closeModules(BUNDL
 }
 
 celix_status_t bundle_refresh(BUNDLE bundle) {
-    bundle_closeModules(bundle);
-    arrayList_clear(bundle->modules);
-    MODULE module = bundle_createModule(bundle);
-    bundle_addModule(bundle, module);
-    bundle->state = BUNDLE_INSTALLED;
-    return CELIX_SUCCESS;
+	celix_status_t status = CELIX_SUCCESS;
+	MODULE module;
+
+	status = bundle_closeModules(bundle);
+	if (status == CELIX_SUCCESS) {
+		arrayList_clear(bundle->modules);
+		status = bundle_createModule(bundle, &module);
+		if (status == CELIX_SUCCESS) {
+			status = bundle_addModule(bundle, module);
+			if (status == CELIX_SUCCESS) {
+				bundle->state = BUNDLE_INSTALLED;
+			}
+		}
+	}
+    return status;
 }
 
 

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=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Tue Jul 19 12:07:16 2011
@@ -27,13 +27,14 @@
 #include <string.h>
 #include <time.h>
 
+#include <apr_file_io.h>
+#include <apr_strings.h>
+
 #include "bundle_archive.h"
 #include "bundle_revision.h"
 #include "headers.h"
 #include "linked_list_iterator.h"
 
-#include <apr_file_io.h>
-#include <apr_strings.h>
 
 struct bundleArchive {
 	long id;
@@ -87,17 +88,17 @@ celix_status_t bundleArchive_createSyste
 }
 
 celix_status_t bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr, char **revision_location);
-void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr);
+celix_status_t bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr);
 
-void bundleArchive_initialize(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_initialize(BUNDLE_ARCHIVE archive);
 
-void bundleArchive_deleteTree(char * directory, apr_pool_t *mp);
+celix_status_t bundleArchive_deleteTree(char * directory, apr_pool_t *mp);
 
 celix_status_t bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr, BUNDLE_REVISION *bundle_revision);
-void bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile);
+celix_status_t bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile);
 
-time_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive);
-void bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive);
+celix_status_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive, time_t *time);
+celix_status_t bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive);
 
 celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp, BUNDLE_ARCHIVE *bundle_archive) {
     apr_pool_t *revisions_pool;
@@ -207,207 +208,290 @@ celix_status_t bundleArchive_recreate(ch
 	return status;
 }
 
-long bundleArchive_getId(BUNDLE_ARCHIVE archive) {
-	if (archive->id >= 0) {
-		return archive->id;
-	}
-
-	char bundleId[strlen(archive->archiveRoot) + 11];
-	strcpy(bundleId, archive->archiveRoot);
-	strcat(bundleId, "/bundle.id");
-
-	apr_file_t *bundleIdFile;
-	apr_status_t rv;
-	if ((rv = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
+celix_status_t bundleArchive_getId(BUNDLE_ARCHIVE archive, long *id) {
+	celix_status_t status = CELIX_SUCCESS;
 
+	if (archive->id < 0) {
+		char bundleId[strlen(archive->archiveRoot) + 11];
+		strcpy(bundleId, archive->archiveRoot);
+		strcat(bundleId, "/bundle.id");
+
+		apr_file_t *bundleIdFile;
+		apr_status_t rv;
+		if ((rv = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			char id[256];
+			apr_file_gets(id, sizeof(id), bundleIdFile);
+			apr_file_close(bundleIdFile);
+			sscanf(id, "%ld", &archive->id);
+		}
+	}
+	if (status == CELIX_SUCCESS) {
+		*id = archive->id;
 	}
-	char id[256];
-	apr_file_gets(id, sizeof(id), bundleIdFile);
-	apr_file_close(bundleIdFile);
 
-	return atol(id);
+	return status;
 }
 
-char * bundleArchive_getLocation(BUNDLE_ARCHIVE archive) {
-	if (archive->location != NULL) {
-		return archive->location;
-	}
-
-	char bundleLocation[strlen(archive->archiveRoot) + 16];
-	strcpy(bundleLocation,archive->archiveRoot);
-	strcat(bundleLocation, "/bundle.location");
-	apr_file_t *bundleLocationFile;
-	apr_status_t rv;
-	if ((rv = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
+celix_status_t bundleArchive_getLocation(BUNDLE_ARCHIVE archive, char **location) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (archive->location == NULL) {
+		char bundleLocation[strlen(archive->archiveRoot) + 16];
+		strcpy(bundleLocation,archive->archiveRoot);
+		strcat(bundleLocation, "/bundle.location");
+		apr_file_t *bundleLocationFile;
+		apr_status_t rv;
+		if ((rv = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			char location[256];
+			apr_file_gets (location , sizeof(location) , bundleLocationFile);
+			apr_file_close(bundleLocationFile);
 
+			archive->location = apr_pstrdup(archive->mp, location);
+		}
 	}
 
-	char location[256];
-	apr_file_gets (location , sizeof(location) , bundleLocationFile);
-	apr_file_close(bundleLocationFile);
+	if (status == CELIX_SUCCESS) {
+		*location = archive->location;
+	}
 
-	return apr_pstrdup(archive->mp, location);
+	return status;
 }
 
-char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive) {
-	return archive->archiveRoot;
+celix_status_t bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive, char **archiveRoot) {
+	*archiveRoot = archive->archiveRoot;
+	return CELIX_SUCCESS;
 }
 
-long bundleArchive_getCurrentRevisionNumber(BUNDLE_ARCHIVE archive) {
-	BUNDLE_REVISION revision = bundleArchive_getCurrentRevision(archive);
-	return bundleRevision_getNumber(revision);
+celix_status_t bundleArchive_getCurrentRevisionNumber(BUNDLE_ARCHIVE archive, long *revisionNumber) {
+	celix_status_t status = CELIX_SUCCESS;
+	*revisionNumber = -1;
+	BUNDLE_REVISION revision;
+
+	status = bundleArchive_getCurrentRevision(archive, &revision);
+	if (status == CELIX_SUCCESS) {
+		status = bundleRevision_getNumber(revision, revisionNumber);
+	}
+
+	return status;
 }
 
-BUNDLE_REVISION bundleArchive_getCurrentRevision(BUNDLE_ARCHIVE archive) {
-	return linkedList_isEmpty(archive->revisions) ? NULL : linkedList_getLast(archive->revisions);
+celix_status_t bundleArchive_getCurrentRevision(BUNDLE_ARCHIVE archive, BUNDLE_REVISION *revision) {
+	*revision = linkedList_isEmpty(archive->revisions) ? NULL : linkedList_getLast(archive->revisions);
+	return CELIX_SUCCESS;
 }
 
-BUNDLE_REVISION bundleArchive_getRevision(BUNDLE_ARCHIVE archive, long revNr) {
-	return linkedList_get(archive->revisions, revNr);
+celix_status_t bundleArchive_getRevision(BUNDLE_ARCHIVE archive, long revNr, BUNDLE_REVISION *revision) {
+	*revision = linkedList_get(archive->revisions, revNr);
+	return CELIX_SUCCESS;
 }
 
-BUNDLE_STATE bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE *state) {
+	celix_status_t status = CELIX_SUCCESS;
+	apr_status_t apr_status;
+
 	if (archive->persistentState >= 0) {
-		return archive->persistentState;
+		*state = archive->persistentState;
+	} else {
+		char persistentStateLocation[strlen(archive->archiveRoot) + 14];
+		strcpy(persistentStateLocation, archive->archiveRoot);
+		strcat(persistentStateLocation, "/bundle.state");
+		apr_file_t *persistentStateLocationFile;
+		apr_status = apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp);
+		if (apr_status != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			char stateString[256];
+			apr_file_gets(stateString , sizeof(stateString) , persistentStateLocationFile);
+			apr_file_close(persistentStateLocationFile);
+
+			if (stateString != NULL && (strcmp(stateString, "active") == 0)) {
+				archive->persistentState = BUNDLE_ACTIVE;
+			} else if (stateString != NULL && (strcmp(stateString, "starting") == 0)) {
+				archive->persistentState = BUNDLE_STARTING;
+			} else if (stateString != NULL && (strcmp(stateString, "uninstalled") == 0)) {
+				archive->persistentState = BUNDLE_UNINSTALLED;
+			} else {
+				archive->persistentState = BUNDLE_INSTALLED;
+			}
+
+			*state = archive->persistentState;
+		}
 	}
 
+	return status;
+}
+
+celix_status_t bundleArchive_setPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE state) {
+	celix_status_t status = CELIX_SUCCESS;
+	apr_status_t apr_status;
+
 	char persistentStateLocation[strlen(archive->archiveRoot) + 14];
 	strcpy(persistentStateLocation, archive->archiveRoot);
 	strcat(persistentStateLocation, "/bundle.state");
 	apr_file_t *persistentStateLocationFile;
-	apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp);
-	char state[256];
-	apr_file_gets(state , sizeof(state) , persistentStateLocationFile);
-	apr_file_close(persistentStateLocationFile);
-
-	if (state != NULL && (strcmp(state, "active") == 0)) {
-		archive->persistentState = BUNDLE_ACTIVE;
-	} else if (state != NULL && (strcmp(state, "starting") == 0)) {
-		archive->persistentState = BUNDLE_STARTING;
-	} else if (state != NULL && (strcmp(state, "uninstalled") == 0)) {
-		archive->persistentState = BUNDLE_UNINSTALLED;
+	apr_status = apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+	if (apr_status != APR_SUCCESS) {
+		status = CELIX_FILE_IO_EXCEPTION;
 	} else {
-		archive->persistentState = BUNDLE_INSTALLED;
-	}
+		char * s;
+		switch (state) {
+			case BUNDLE_ACTIVE:
+				s = "active";
+				break;
+			case BUNDLE_STARTING:
+				s = "starting";
+				break;
+			case BUNDLE_UNINSTALLED:
+				s = "uninstalled";
+				break;
+			default:
+				s = "installed";
+				break;
+		}
+		apr_file_printf(persistentStateLocationFile, "%s", s);
+		apr_file_close(persistentStateLocationFile);
 
-	return archive->persistentState;
+		archive->persistentState = state;
+	}
+	return status;
 }
 
-void bundleArchive_setPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE state) {
-	char persistentStateLocation[strlen(archive->archiveRoot) + 14];
-	strcpy(persistentStateLocation, archive->archiveRoot);
-	strcat(persistentStateLocation, "/bundle.state");
-	apr_file_t *persistentStateLocationFile;
-	apr_file_open(&persistentStateLocationFile, persistentStateLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
-	char * s;
-	switch (state) {
-		case BUNDLE_ACTIVE:
-			s = "active";
-			break;
-		case BUNDLE_STARTING:
-			s = "starting";
-			break;
-		case BUNDLE_UNINSTALLED:
-			s = "uninstalled";
-			break;
-		default:
-			s = "installed";
-			break;
-	}
-	apr_file_printf(persistentStateLocationFile, "%s", s);
-	apr_file_close(persistentStateLocationFile);
-
-	archive->persistentState = state;
-}
-
-long bundleArchive_getRefreshCount(BUNDLE_ARCHIVE archive) {
-	if (archive->refreshCount >= 0) {
-		return archive->refreshCount;
+celix_status_t bundleArchive_getRefreshCount(BUNDLE_ARCHIVE archive, long *refreshCount) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (archive->refreshCount == -1) {
+		char refreshCounter[strlen(archive->archiveRoot) + 17];
+		strcpy(refreshCounter,archive->archiveRoot);
+		strcat(refreshCounter, "/refresh.counter");
+		apr_file_t * refreshCounterFile;
+		apr_status_t rv;
+		if ((rv = apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
+			archive->refreshCount = 0;
+		} else {
+			char counterStr[256];
+			apr_file_gets(counterStr , sizeof(counterStr) , refreshCounterFile);
+			apr_file_close(refreshCounterFile);
+			sscanf(counterStr, "%ld", &archive->refreshCount);
+		}
 	}
 
-	char refreshCounter[strlen(archive->archiveRoot) + 17];
-	strcpy(refreshCounter,archive->archiveRoot);
-	strcat(refreshCounter, "/refresh.counter");
-	apr_file_t * refreshCounterFile;
-	apr_status_t rv;
-	if ((rv = apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp)) != APR_SUCCESS) {
-		archive->refreshCount = 0;
-	} else {
-		char counterStr[256];
-		apr_file_gets(counterStr , sizeof(counterStr) , refreshCounterFile);
-		apr_file_close(refreshCounterFile);
-		sscanf(counterStr, "%ld", &archive->refreshCount);
+	if (status == CELIX_SUCCESS) {
+		*refreshCount = archive->refreshCount;
 	}
-	return archive->refreshCount;
+
+	return status;
 }
 
-void bundleArchive_setRefreshCount(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_setRefreshCount(BUNDLE_ARCHIVE archive) {
+	celix_status_t status = CELIX_SUCCESS;
 	char refreshCounter[strlen(archive->archiveRoot) + 17];
 	strcpy(refreshCounter, archive->archiveRoot);
 	strcat(refreshCounter, "/refresh.counter");
 	apr_file_t * refreshCounterFile;
-	apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+	apr_status_t apr_status = apr_file_open(&refreshCounterFile, refreshCounter, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+	if (apr_status != APR_SUCCESS) {
+		status = CELIX_FILE_IO_EXCEPTION;
+	} else {
+		apr_file_printf(refreshCounterFile, "%ld", archive->refreshCount);
+		apr_file_close(refreshCounterFile);
+	}
 
-	apr_file_printf(refreshCounterFile, "%ld", archive->refreshCount);
-	apr_file_close(refreshCounterFile);
+	return status;
 }
 
-time_t bundleArchive_getLastModified(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_getLastModified(BUNDLE_ARCHIVE archive, time_t *lastModified) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	if (archive->lastModified == (time_t) NULL) {
-		archive->lastModified = bundleArchive_readLastModified(archive);
+		status = bundleArchive_readLastModified(archive, &archive->lastModified);
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*lastModified = archive->lastModified;
 	}
-	return archive->lastModified;
+
+	return status;
 }
 
-void bundleArchive_setLastModified(BUNDLE_ARCHIVE archive, time_t lastModifiedTime) {
+celix_status_t bundleArchive_setLastModified(BUNDLE_ARCHIVE archive, time_t lastModifiedTime) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	archive->lastModified = lastModifiedTime;
-	bundleArchive_writeLastModified(archive);
+	status = bundleArchive_writeLastModified(archive);
+
+	return status;
 }
 
-time_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive, time_t *time) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	char lastModified[strlen(archive->archiveRoot) + 21];
 	sprintf(lastModified, "%s/bundle.lastmodified", archive->archiveRoot);
 
 	char timeStr[20];
 	apr_file_t *lastModifiedFile;
-	apr_status_t status = apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp);
-	apr_file_gets(timeStr, sizeof(timeStr), lastModifiedFile);
-	apr_file_close(lastModifiedFile);
+	apr_status_t apr_status = apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp);
+	if (apr_status != APR_SUCCESS) {
+		status = CELIX_FILE_IO_EXCEPTION;
+	} else {
+		apr_file_gets(timeStr, sizeof(timeStr), lastModifiedFile);
+		apr_file_close(lastModifiedFile);
+
+		int year, month, day, hours, minutes, seconds;
+		sscanf(timeStr, "%d %d %d %d:%d:%d", &year, &month, &day, &hours, &minutes, &seconds);
 
-	int year, month, day, hours, minutes, seconds;
-	sscanf(timeStr, "%d %d %d %d:%d:%d", &year, &month, &day, &hours, &minutes, &seconds);
+		struct tm tm_time;
+		tm_time.tm_year = year - 1900;
+		tm_time.tm_mon = month - 1;
+		tm_time.tm_mday = day;
+		tm_time.tm_hour = hours;
+		tm_time.tm_min = minutes;
+		tm_time.tm_sec = seconds;
 
-	struct tm time;
-	time.tm_year = year - 1900;
-	time.tm_mon = month - 1;
-	time.tm_mday = day;
-	time.tm_hour = hours;
-	time.tm_min = minutes;
-	time.tm_sec = seconds;
+		*time = mktime(&tm_time);
+	}
 
-	return mktime(&time);
+	return status;
 }
 
-void bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	char lastModified[strlen(archive->archiveRoot) + 21];
 	sprintf(lastModified, "%s/bundle.lastmodified", archive->archiveRoot);
 	char timeStr[20];
 	strftime(timeStr, 20, "%Y %m %d %H:%M:%S", localtime(&archive->lastModified));
 
 	apr_file_t *lastModifiedFile;
-	apr_status_t status = apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
-	apr_file_printf(lastModifiedFile, "%s", timeStr);
-	apr_file_close(lastModifiedFile);
+	apr_status_t apr_status = apr_file_open(&lastModifiedFile, lastModified, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+	if (apr_status != APR_SUCCESS) {
+		status = CELIX_FILE_IO_EXCEPTION;
+	} else {
+		apr_file_printf(lastModifiedFile, "%s", timeStr);
+		apr_file_close(lastModifiedFile);
+	}
+
+	return status;
 }
 
-void bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location, char *inputFile) {
-	long revNr = linkedList_isEmpty(archive->revisions)
-			? 0l
-			: bundleRevision_getNumber(linkedList_getLast(archive->revisions)) + 1;
-	bundleArchive_reviseInternal(archive, false, revNr, location, inputFile);
+celix_status_t bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location, char *inputFile) {
+	celix_status_t status = CELIX_SUCCESS;
+	long revNr = 0l;
+	if (!linkedList_isEmpty(archive->revisions)) {
+		long revisionNr;
+		status = bundleRevision_getNumber(linkedList_getLast(archive->revisions), &revisionNr);
+		revNr = revisionNr + 1;
+	}
+	if (status == CELIX_SUCCESS) {
+		status = bundleArchive_reviseInternal(archive, false, revNr, location, inputFile);
+	}
+	return status;
 }
 
-void bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile) {
+celix_status_t bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile) {
     celix_status_t status;
     BUNDLE_REVISION revision = NULL;
 
@@ -419,38 +503,45 @@ void bundleArchive_reviseInternal(BUNDLE
 
 	if (status == CELIX_SUCCESS) {
         if (!isReload) {
-            bundleArchive_setRevisionLocation(archive, location, revNr);
+            status = bundleArchive_setRevisionLocation(archive, location, revNr);
         }
 
         linkedList_addElement(archive->revisions, revision);
 	}
+
+	return status;
 }
 
-bool bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive) {
-	return true;
+celix_status_t bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive, bool *rolledback) {
+	*rolledback = true;
+	return CELIX_SUCCESS;
 }
 
 celix_status_t bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr, BUNDLE_REVISION *bundle_revision) {
     celix_status_t status = CELIX_SUCCESS;
     char root[256];
-	sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
+    long refreshCount;
 
-	// TODO create revision using optional FILE *fp;
-	BUNDLE_REVISION revision = NULL;
-	apr_pool_t *pool = NULL;
-	if (apr_pool_create(&pool, archive->mp) == APR_SUCCESS) {
-	    status = bundleRevision_create(root, location, revNr, inputFile, pool, &revision);
+    status = bundleArchive_getRefreshCount(archive, &refreshCount);
+    if (status == CELIX_SUCCESS) {
+		sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, refreshCount, revNr);
+
+		BUNDLE_REVISION revision = NULL;
+		apr_pool_t *pool = NULL;
+		if (apr_pool_create(&pool, archive->mp) == APR_SUCCESS) {
+			status = bundleRevision_create(root, location, revNr, inputFile, pool, &revision);
 
-	    if (status != CELIX_SUCCESS) {
-	        apr_pool_destroy(pool);
-	    }
-	} else {
-	    status = CELIX_ENOMEM;
-	}
+			if (status != CELIX_SUCCESS) {
+				apr_pool_destroy(pool);
+			}
+		} else {
+			status = CELIX_ENOMEM;
+		}
 
-	if (status == CELIX_SUCCESS) {
-	    *bundle_revision = revision;
-	}
+		if (status == CELIX_SUCCESS) {
+			*bundle_revision = revision;
+		}
+    }
 
 	return status;
 }
@@ -458,92 +549,149 @@ celix_status_t bundleArchive_createRevis
 celix_status_t bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr, char **revision_location) {
     celix_status_t status;
 	char revisionLocation[256];
-	sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
+	long refreshCount;
 
-	apr_file_t * revisionLocationFile;
-	if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp) == APR_SUCCESS) {
-        char location[256];
-        apr_file_gets (location , sizeof(location) , revisionLocationFile);
-        apr_file_close(revisionLocationFile);
+	status = bundleArchive_getRefreshCount(archive, &refreshCount);
+	if (status == CELIX_SUCCESS) {
+		sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
 
-        *revision_location = apr_pstrdup(archive->mp, location);
-        status = CELIX_SUCCESS;
-	} else {
-	    // revision file not found
-	    printf("Failed to open revision file at: %s\n", revisionLocation);
-	    status = CELIX_FILE_IO_EXCEPTION;
+		apr_file_t * revisionLocationFile;
+		if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_READ, APR_OS_DEFAULT, archive->mp) == APR_SUCCESS) {
+			char location[256];
+			apr_file_gets (location , sizeof(location) , revisionLocationFile);
+			apr_file_close(revisionLocationFile);
+
+			*revision_location = apr_pstrdup(archive->mp, location);
+			status = CELIX_SUCCESS;
+		} else {
+			// revision file not found
+			printf("Failed to open revision file at: %s\n", revisionLocation);
+			status = CELIX_FILE_IO_EXCEPTION;
+		}
 	}
 
 	return status;
 }
 
-void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr) {
+celix_status_t bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr) {
+	celix_status_t status = CELIX_SUCCESS;
+
 	char revisionLocation[256];
-	sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
+	long refreshCount;
+
+	status = bundleArchive_getRefreshCount(archive, &refreshCount);
+	if (status == CELIX_SUCCESS) {
+		sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, refreshCount, revNr);
+
+		apr_file_t * revisionLocationFile;
+		if (apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp) != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			apr_file_printf(revisionLocationFile, "%s", location);
+			apr_file_close(revisionLocationFile);
+		}
+	}
 
-	apr_file_t * revisionLocationFile;
-	apr_file_open(&revisionLocationFile, revisionLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
-	apr_file_printf(revisionLocationFile, "%s", location);
-	apr_file_close(revisionLocationFile);
+	return status;
 }
 
-void bundleArchive_close(BUNDLE_ARCHIVE archive) {
+celix_status_t bundleArchive_close(BUNDLE_ARCHIVE archive) {
 	// close revision
 	// not yet needed/possible
+	return CELIX_SUCCESS;
 }
 
-void bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive) {
-	bundleArchive_close(archive);
-	bundleArchive_deleteTree(archive->archiveRoot, archive->mp);
-}
+celix_status_t bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive) {
+	celix_status_t status = CELIX_SUCCESS;
 
-void bundleArchive_initialize(BUNDLE_ARCHIVE archive) {
-	if (archive->archiveRootDir != NULL) {
-		return;
+	status = bundleArchive_close(archive);
+	if (status == CELIX_SUCCESS) {
+		status = bundleArchive_deleteTree(archive->archiveRoot, archive->mp);
 	}
 
-	apr_dir_make(archive->archiveRoot, APR_UREAD|APR_UWRITE|APR_UEXECUTE, archive->mp);
-	apr_dir_open(&archive->archiveRootDir, archive->archiveRoot, archive->mp);
+	return status;
+}
 
-	char bundleId[strlen(archive->archiveRoot) + 10];
-	strcpy(bundleId, archive->archiveRoot);
-	strcat(bundleId, "/bundle.id");
-	apr_file_t *bundleIdFile;
-	apr_status_t status = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
-	apr_file_printf(bundleIdFile, "%ld", archive->id);
-	apr_file_close(bundleIdFile);
+celix_status_t bundleArchive_initialize(BUNDLE_ARCHIVE archive) {
+	celix_status_t status = CELIX_SUCCESS;
 
-	char bundleLocation[strlen(archive->archiveRoot) + 16];
-	strcpy(bundleLocation,archive->archiveRoot);
-	strcat(bundleLocation, "/bundle.location");
-	apr_file_t *bundleLocationFile;
-	status = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
-	apr_file_printf(bundleLocationFile, "%s", archive->location);
-	apr_file_close(bundleLocationFile);
+	if (archive->archiveRootDir == NULL) {
+		if (apr_dir_make(archive->archiveRoot, APR_UREAD|APR_UWRITE|APR_UEXECUTE, archive->mp) != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			apr_status_t apr_status = apr_dir_open(&archive->archiveRootDir, archive->archiveRoot, archive->mp);
+			if (apr_status != APR_SUCCESS) {
+				status = CELIX_FILE_IO_EXCEPTION;
+			} else {
+				char bundleId[strlen(archive->archiveRoot) + 10];
+				strcpy(bundleId, archive->archiveRoot);
+				strcat(bundleId, "/bundle.id");
+				apr_file_t *bundleIdFile;
+				apr_status_t apr_status = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+				if (apr_status != APR_SUCCESS) {
+					status = CELIX_FILE_IO_EXCEPTION;
+				} else {
+					apr_file_printf(bundleIdFile, "%ld", archive->id);
+					// Ignore close status, let it fail if needed again
+					apr_file_close(bundleIdFile);
+
+					char bundleLocation[strlen(archive->archiveRoot) + 16];
+					strcpy(bundleLocation,archive->archiveRoot);
+					strcat(bundleLocation, "/bundle.location");
+					apr_file_t *bundleLocationFile;
+
+					apr_status = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE, APR_OS_DEFAULT, archive->mp);
+					if (apr_status != APR_SUCCESS) {
+						status = CELIX_FILE_IO_EXCEPTION;
+					} else {
+						apr_file_printf(bundleLocationFile, "%s", archive->location);
+						// Ignore close status, let it fail if needed again
+						apr_file_close(bundleLocationFile);
+
+						status = bundleArchive_writeLastModified(archive);
+					}
+				}
+			}
+		}
+	}
 
-	bundleArchive_writeLastModified(archive);
+	return status;
 }
 
-void bundleArchive_deleteTree(char * directory, apr_pool_t *mp) {
+celix_status_t bundleArchive_deleteTree(char * directory, apr_pool_t *mp) {
+	celix_status_t status = CELIX_SUCCESS;
 	apr_dir_t *dir;
 	apr_status_t stat = apr_dir_open(&dir, directory, mp);
 	if (stat != APR_SUCCESS) {
 	    printf("ERROR opening: %d\n", stat);
-	}
-	apr_finfo_t dp;
-	while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
-		if ((strcmp((dp.name), ".") != 0) && (strcmp((dp.name), "..") != 0)) {
-			char subdir[strlen(directory) + strlen(dp.name) + 2];
-			strcpy(subdir, directory);
-			strcat(subdir, "/");
-			strcat(subdir, dp.name);
-
-			if (dp.filetype == APR_DIR) {
-				bundleArchive_deleteTree(subdir, mp);
-			} else {
-				remove(subdir);
+	    status = CELIX_FILE_IO_EXCEPTION;
+	} else {
+		apr_finfo_t dp;
+		apr_status_t apr_status;
+		while ((apr_status = apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
+			if ((strcmp((dp.name), ".") != 0) && (strcmp((dp.name), "..") != 0)) {
+				char subdir[strlen(directory) + strlen(dp.name) + 2];
+				strcpy(subdir, directory);
+				strcat(subdir, "/");
+				strcat(subdir, dp.name);
+
+				if (dp.filetype == APR_DIR) {
+					status = bundleArchive_deleteTree(subdir, mp);
+				} else {
+					if (apr_file_remove(subdir, mp) != APR_SUCCESS) {
+						status = CELIX_FILE_IO_EXCEPTION;
+						break;
+					}
+				}
 			}
 		}
+		if (apr_status != APR_SUCCESS) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		}
+		if (status == CELIX_SUCCESS) {
+			apr_file_remove(directory, mp);
+		}
 	}
-	remove(directory);
+
+	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=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_revision.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_revision.c Tue Jul 19 12:07:16 2011
@@ -25,12 +25,11 @@ celix_status_t bundleRevision_create(cha
 
 	revision = (BUNDLE_REVISION) apr_pcalloc(pool, sizeof(*revision));
     if (revision != NULL) {
-        // if (
-        apr_dir_make(root, APR_UREAD|APR_UWRITE|APR_UEXECUTE, pool);
-        //!= APR_SUCCESS);
-        //{
-        //    status = CELIX_FILE_IO_EXCEPTION;
-        //} else {
+    	// TODO: This overwrites an existing revision, is this supposed to happen?
+    	apr_status_t apr_status = apr_dir_make(root, APR_UREAD|APR_UWRITE|APR_UEXECUTE, pool);
+        if ((apr_status != APR_SUCCESS) && (apr_status != APR_EEXIST)) {
+            status = CELIX_FILE_IO_EXCEPTION;
+        } else {
             if (inputFile != NULL) {
                 status = extractBundle(inputFile, root);
             } else {
@@ -43,26 +42,42 @@ celix_status_t bundleRevision_create(cha
                 revision->location = apr_pstrdup(pool, location);
                 *bundle_revision = revision;
             }
-        //}
+        }
     }
 
 	return status;
 }
 
-void bundleRevision_destroy(BUNDLE_REVISION revision) {
+celix_status_t bundleRevision_destroy(BUNDLE_REVISION revision) {
+	return CELIX_SUCCESS;
 }
 
-long bundleRevision_getNumber(BUNDLE_REVISION revision) {
+celix_status_t bundleRevision_getNumber(BUNDLE_REVISION revision, long *revisionNr) {
+	celix_status_t status = CELIX_SUCCESS;
     if (revision == NULL) {
-        return -1L;
+        status = CELIX_ILLEGAL_ARGUMENT;
+    } else {
+    	*revisionNr = revision->revisionNr;
     }
-	return revision->revisionNr;
+	return status;
 }
 
-char * bundleRevision_getLocation(BUNDLE_REVISION revision) {
-	return revision->location;
+celix_status_t bundleRevision_getLocation(BUNDLE_REVISION revision, char **location) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (revision == NULL) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		*location = revision->location;
+	}
+	return status;
 }
 
-char * bundleRevision_getRoot(BUNDLE_REVISION revision) {
-	return revision->root;
+celix_status_t bundleRevision_getRoot(BUNDLE_REVISION revision, char **root) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (revision == NULL) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		*root = revision->root;
+	}
+	return CELIX_SUCCESS;
 }

Modified: incubator/celix/trunk/framework/private/src/capability.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/capability.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/capability.c (original)
+++ incubator/celix/trunk/framework/private/src/capability.c Tue Jul 19 12:07:16 2011
@@ -58,7 +58,6 @@ void capability_destroy(CAPABILITY capab
 	while (hashMapIterator_hasNext(attrIter)) {
 		ATTRIBUTE attr = hashMapIterator_nextValue(attrIter);
 		hashMapIterator_remove(attrIter);
-		attribute_destroy(attr);
 	}
 	hashMapIterator_destroy(attrIter);
 	hashMap_destroy(capability->attributes, false, false);

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue Jul 19 12:07:16 2011
@@ -144,6 +144,7 @@ celix_status_t framework_create(FRAMEWOR
                                     (*framework)->registry = NULL;
 
                                     (*framework)->interrupted = false;
+                                    (*framework)->shutdown = false;
 
                                     (*framework)->globalLockWaitersList = arrayList_create();
                                     (*framework)->globalLockCount = 0;
@@ -227,7 +228,9 @@ celix_status_t fw_init(FRAMEWORK framewo
 
 	framework->installedBundleMap = hashMap_create(string_hash, NULL, string_equals, NULL);
 
-	hashMap_put(framework->installedBundleMap, bundleArchive_getLocation(bundle_getArchive(framework->bundle)), framework->bundle);
+	char *location;
+	status = bundleArchive_getLocation(bundle_getArchive(framework->bundle), &location);
+	hashMap_put(framework->installedBundleMap, location, framework->bundle);
 
 	HASH_MAP wires = resolver_resolve(bundle_getCurrentModule(framework->bundle));
 	if (wires == NULL) {
@@ -248,13 +251,19 @@ celix_status_t fw_init(FRAMEWORK framewo
         int arcIdx;
         for (arcIdx = 0; arcIdx < arrayList_size(archives); arcIdx++) {
             BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) arrayList_get(archives, arcIdx);
-    		framework->nextBundleId = fmaxl(framework->nextBundleId, bundleArchive_getId(archive) + 1);
+            long id;
+            bundleArchive_getId(archive, &id);
+    		framework->nextBundleId = fmaxl(framework->nextBundleId,  id + 1);
+    		BUNDLE_STATE bundleState;
 
-            if (bundleArchive_getPersistentState(archive) == BUNDLE_UNINSTALLED) {
+    		bundleArchive_getPersistentState(archive, &bundleState);
+            if (bundleState == BUNDLE_UNINSTALLED) {
                 bundleArchive_closeAndDelete(archive);
             } else {
                 BUNDLE bundle;
-                fw_installBundle2(framework, &bundle, bundleArchive_getId(archive), bundleArchive_getLocation(archive), archive);
+                char *location;
+				status = bundleArchive_getLocation(archive, &location);
+                fw_installBundle2(framework, &bundle, id, location, archive);
             }
         }
         arrayList_destroy(archives);
@@ -335,7 +344,7 @@ celix_status_t framework_start(FRAMEWORK
 }
 
 void framework_stop(FRAMEWORK framework) {
-	fw_stopBundle(framework, framework->bundle, 0);
+	fw_stopBundle(framework, framework->bundle, true);
 }
 
 celix_status_t fw_installBundle(FRAMEWORK framework, BUNDLE * bundle, char * location) {
@@ -399,25 +408,32 @@ celix_status_t fw_installBundle2(FRAMEWO
 }
 
 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++;
-	}
+	celix_status_t status = CELIX_SUCCESS;
 
-	char *root = bundleRevision_getRoot(revision);
-	char *e = NULL;
-	apr_filepath_merge(&e, root, name, APR_FILEPATH_NOTABOVEROOT, framework->mp);
-	apr_finfo_t info;
-	apr_status_t ret = apr_stat(&info, e, APR_FINFO_DIRENT|APR_FINFO_TYPE, framework->mp);
-	if (ret == APR_ENOENT) {
-		(*entry) = NULL;
-		return CELIX_SUCCESS;
-	} else if (ret == APR_SUCCESS || ret == APR_INCOMPLETE) {
-		(*entry) = apr_pstrdup(pool, e);
-		return CELIX_SUCCESS;
+	BUNDLE_REVISION revision;
+
+	status = bundleArchive_getCurrentRevision(bundle_getArchive(bundle), &revision);
+	if (status == CELIX_SUCCESS) {
+		if ((strlen(name) > 0) && (name[0] == '/')) {
+			name++;
+		}
+
+		char *root;
+		status = bundleRevision_getRoot(revision, &root);
+		if (status == CELIX_SUCCESS) {
+			char *e = NULL;
+			apr_filepath_merge(&e, root, name, APR_FILEPATH_NOTABOVEROOT, framework->mp);
+			apr_finfo_t info;
+			apr_status_t ret = apr_stat(&info, e, APR_FINFO_DIRENT|APR_FINFO_TYPE, framework->mp);
+			if (ret == APR_ENOENT) {
+				(*entry) = NULL;
+			} else if (ret == APR_SUCCESS || ret == APR_INCOMPLETE) {
+				(*entry) = apr_pstrdup(pool, e);
+			}
+		}
 	}
 
-	return CELIX_ILLEGAL_STATE;
+	return status;
 }
 
 celix_status_t fw_startBundle(FRAMEWORK framework, BUNDLE bundle, int options ATTRIBUTE_UNUSED) {
@@ -486,10 +502,18 @@ celix_status_t fw_startBundle(FRAMEWORK 
 	#endif
 
 			char libraryPath[256];
+			long refreshCount;
+			char *archiveRoot;
+			long revisionNumber;
+
+			bundleArchive_getRefreshCount(bundle_getArchive(bundle), &refreshCount);
+			bundleArchive_getArchiveRoot(bundle_getArchive(bundle), &archiveRoot);
+			bundleArchive_getCurrentRevisionNumber(bundle_getArchive(bundle), &revisionNumber);
+
 			sprintf(libraryPath, "%s/version%ld.%ld/%s%s%s",
-					bundleArchive_getArchiveRoot(bundle_getArchive(bundle)),
-					bundleArchive_getRefreshCount(bundle_getArchive(bundle)),
-					bundleArchive_getCurrentRevisionNumber(bundle_getArchive(bundle)),
+					archiveRoot,
+					refreshCount,
+					revisionNumber,
 					library_prefix,
 					library,
 					library_extension
@@ -555,7 +579,8 @@ celix_status_t framework_updateBundle(FR
 	}
 
 	BUNDLE_STATE oldState = bundle_getState(bundle);
-	char * location = bundleArchive_getLocation(bundle_getArchive(bundle));
+	char *location;
+	bundleArchive_getLocation(bundle_getArchive(bundle), &location);
 
 	if (oldState == BUNDLE_ACTIVE) {
 		fw_stopBundle(framework, bundle, false);
@@ -571,7 +596,7 @@ celix_status_t framework_updateBundle(FR
 	bundle_revise(bundle, location, inputFile);
 	framework_releaseGlobalLock(framework);
 
-	bundleArchive_setLastModified(bundle_getArchive(bundle), time(NULL));
+	celix_status_t status = bundleArchive_setLastModified(bundle_getArchive(bundle), time(NULL));
 	framework_setBundleStateAndNotify(framework, bundle, BUNDLE_INSTALLED);
 
 	// Refresh packages?
@@ -675,7 +700,8 @@ celix_status_t fw_uninstallBundle(FRAMEW
             status = CELIX_ILLEGAL_STATE;
         } else {
             BUNDLE_ARCHIVE archive = bundle_getArchive(bundle);
-            char * location = bundleArchive_getLocation(archive);
+            char * location;
+            status = bundleArchive_getLocation(archive, &location);
             // TODO sync issues?
             BUNDLE target = (BUNDLE) hashMap_remove(framework->installedBundleMap, location);
 
@@ -694,7 +720,7 @@ celix_status_t fw_uninstallBundle(FRAMEW
             // TODO: fw_fireBundleEvent(framework BUNDLE_EVENT_UNRESOLVED, bundle);
 
             framework_setBundleStateAndNotify(framework, bundle, BUNDLE_UNINSTALLED);
-            bundleArchive_setLastModified(archive, time(NULL));
+            status = bundleArchive_setLastModified(archive, time(NULL));
         }
         framework_releaseBundleLock(framework, bundle);
 
@@ -998,13 +1024,30 @@ void fw_serviceChanged(FRAMEWORK framewo
 }
 
 celix_status_t getManifest(BUNDLE_ARCHIVE archive, MANIFEST *manifest) {
+	celix_status_t status = CELIX_SUCCESS;
 	char mf[256];
-	sprintf(mf, "%s/version%ld.%ld/MANIFEST/MANIFEST.MF",
-			bundleArchive_getArchiveRoot(archive),
-			bundleArchive_getRefreshCount(archive),
-			bundleArchive_getCurrentRevisionNumber(archive)
-			);
-	return manifest_read(mf, manifest);
+	long refreshCount;
+	char *archiveRoot;
+	long revisionNumber;
+
+	status = bundleArchive_getRefreshCount(archive, &refreshCount);
+	if (status == CELIX_SUCCESS) {
+		status = bundleArchive_getArchiveRoot(archive, &archiveRoot);
+		if (status == CELIX_SUCCESS) {
+			status = bundleArchive_getCurrentRevisionNumber(archive, &revisionNumber);
+			if (status == CELIX_SUCCESS) {
+				if (status == CELIX_SUCCESS) {
+					sprintf(mf, "%s/version%ld.%ld/MANIFEST/MANIFEST.MF",
+							archiveRoot,
+							refreshCount,
+							revisionNumber
+							);
+					status = manifest_read(mf, manifest);
+				}
+			}
+		}
+	}
+	return status;
 }
 
 long framework_getNextBundleId(FRAMEWORK framework) {
@@ -1069,7 +1112,9 @@ BUNDLE framework_getBundleById(FRAMEWORK
 	BUNDLE bundle = NULL;
 	while (hashMapIterator_hasNext(iter)) {
 		BUNDLE b = hashMapIterator_nextValue(iter);
-		if (bundleArchive_getId(bundle_getArchive(b)) == id) {
+		long bid;
+		bundleArchive_getId(bundle_getArchive(b), &bid);
+		if (bid == id) {
 			bundle = b;
 			break;
 		}
@@ -1166,8 +1211,10 @@ celix_status_t framework_acquireBundleLo
 
 bool framework_releaseBundleLock(FRAMEWORK framework, BUNDLE bundle) {
     apr_thread_mutex_lock(framework->bundleLock);
+    bool unlocked;
 
-	if (!bundle_unlock(bundle)) {
+    bundle_unlock(bundle, &unlocked);
+	if (!unlocked) {
 	    apr_thread_mutex_unlock(framework->bundleLock);
 		return false;
 	}
@@ -1244,9 +1291,13 @@ celix_status_t framework_waitForStop(FRA
 		celix_log("Error locking the framework, shutdown gate not set.");
 		return CELIX_FRAMEWORK_EXCEPTION;
 	}
-	if (apr_thread_cond_wait(framework->shutdownGate, framework->mutex) != 0) {
-		celix_log("Error waiting for shutdown gate.");
-		return CELIX_FRAMEWORK_EXCEPTION;
+	while (!framework->shutdown) {
+		apr_status_t apr_status = apr_thread_cond_wait(framework->shutdownGate, framework->mutex);
+		if (apr_status != 0) {
+			celix_log("Error waiting for shutdown gate.");
+			return CELIX_FRAMEWORK_EXCEPTION;
+		}
+		printf("Interrupted %d\n", framework->shutdown);
 	}
 	printf("waited for stop\n");
 	if (apr_thread_mutex_unlock(framework->mutex) != 0) {
@@ -1265,7 +1316,9 @@ static void *APR_THREAD_FUNC framework_s
 	while (hashMapIterator_hasNext(iterator)) {
 		BUNDLE bundle = hashMapIterator_nextValue(iterator);
 		if (bundle_getState(bundle) == BUNDLE_ACTIVE || bundle_getState(bundle) == BUNDLE_STARTING) {
-		    printf("stop bundle: %s\n", bundleArchive_getLocation(bundle_getArchive(bundle)));
+			char *location;
+			bundleArchive_getLocation(bundle_getArchive(bundle), &location);
+		    printf("stop bundle: %s\n", location);
 			fw_stopBundle(fw, bundle, 0);
 		}
 	}
@@ -1277,6 +1330,7 @@ static void *APR_THREAD_FUNC framework_s
 		apr_thread_exit(thd, APR_ENOLOCK);
 		return NULL;
 	}
+	fw->shutdown = true;
 	err = apr_thread_cond_broadcast(fw->shutdownGate);
 	if (err != 0) {
 		celix_log("Error waking the shutdown gate, cannot exit clean.");

Modified: incubator/celix/trunk/framework/private/src/requirement.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/requirement.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/requirement.c (original)
+++ incubator/celix/trunk/framework/private/src/requirement.c Tue Jul 19 12:07:16 2011
@@ -57,7 +57,6 @@ void requirement_destroy(REQUIREMENT req
 	while (hashMapIterator_hasNext(attrIter)) {
 		ATTRIBUTE attr = hashMapIterator_nextValue(attrIter);
 		hashMapIterator_remove(attrIter);
-		attribute_destroy(attr);
 	}
 	hashMapIterator_destroy(attrIter);
 	hashMap_destroy(requirement->attributes, false, false);

Modified: incubator/celix/trunk/framework/private/src/utils.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/utils.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/utils.c (original)
+++ incubator/celix/trunk/framework/private/src/utils.c Tue Jul 19 12:07:16 2011
@@ -24,6 +24,7 @@
  */
 #include <stdlib.h>
 #include <string.h>
+#include <apr_portable.h>
 
 #include "utils.h"
 
@@ -76,3 +77,14 @@ char * string_trim(char * string) {
 
 	return copy;
 }
+
+celix_status_t thread_equalsSelf(apr_os_thread_t thread, bool *equals) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	apr_os_thread_t self = apr_os_thread_current();
+	if (status == CELIX_SUCCESS) {
+		*equals = apr_os_thread_equal(self, thread);
+	}
+
+	return status;
+}

Modified: incubator/celix/trunk/launcher/launcher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/launcher.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/launcher.c (original)
+++ incubator/celix/trunk/launcher/launcher.c Tue Jul 19 12:07:16 2011
@@ -114,8 +114,8 @@ int main(void) {
 
 void launcher_shutdown(int signal) {
 	framework_stop(framework);
-	if (framework_waitForStop(framework) != CELIX_SUCCESS) {
-		celix_log("Error waiting for stop.");
-	}
-	framework_destroy(framework);
+//	if (framework_waitForStop(framework) != CELIX_SUCCESS) {
+//		celix_log("Error waiting for stop.");
+//	}
+//	framework_destroy(framework);
 }

Modified: incubator/celix/trunk/shell/install_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/install_command.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/shell/install_command.c (original)
+++ incubator/celix/trunk/shell/install_command.c Tue Jul 19 12:07:16 2011
@@ -64,7 +64,8 @@ void installCommand_execute(COMMAND comm
 			if (strlen(info) > 0) {
 				strcat(info, ", ");
 			}
-			long id = bundleArchive_getId(bundle_getArchive(bundle));
+			long id;
+			bundleArchive_getId(bundle_getArchive(bundle), &id);
 			char bundleId[sizeof(id) + 1];
 			sprintf(bundleId, "%ld", id);
 			strcat(info, bundleId);

Modified: incubator/celix/trunk/shell/ps_command.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/shell/ps_command.c?rev=1148287&r1=1148286&r2=1148287&view=diff
==============================================================================
--- incubator/celix/trunk/shell/ps_command.c (original)
+++ incubator/celix/trunk/shell/ps_command.c Tue Jul 19 12:07:16 2011
@@ -82,15 +82,16 @@ void psCommand_execute(COMMAND command, 
 		out(line);
 		for (i = 0; i < arrayList_size(bundles); i++) {
 			BUNDLE bundle = arrayList_get(bundles, i);
-			long id = bundleArchive_getId(bundle_getArchive(bundle));
+			long id;
+			bundleArchive_getId(bundle_getArchive(bundle), &id);
 			char * state = psCommand_stateString(bundle_getState(bundle));
 			char * name = module_getSymbolicName(bundle_getCurrentModule(bundle));
 			if (showLocation) {
-				name = bundleArchive_getLocation(bundle_getArchive(bundle));
+				bundleArchive_getLocation(bundle_getArchive(bundle), &name);
 			} else if (showSymbolicName) {
 				name = module_getSymbolicName(bundle_getCurrentModule(bundle));
 			} else if (showUpdateLocation) {
-				name = bundleArchive_getLocation(bundle_getArchive(bundle));
+				bundleArchive_getLocation(bundle_getArchive(bundle), &name);
 			}
 
 			sprintf(line, "  %-5ld %-12s %s\n", id, state, name);