incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1101360 [2/5] - in /incubator/celix/trunk: ./ .settings/ celix_test/ dependency_manager/ echo_service/client/ framework/ framework/private/include/ framework/private/src/ hello_world/ hello_world/root/ launcher/ mongoose/ mongoose/MANIFEST...
Date Tue, 10 May 2011 08:21:27 GMT
Modified: incubator/celix/trunk/framework/private/include/service_registration.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/service_registration.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/service_registration.h (original)
+++ incubator/celix/trunk/framework/private/include/service_registration.h Tue May 10 08:21:24 2011
@@ -33,6 +33,7 @@
 
 SERVICE_REGISTRATION serviceRegistration_create(SERVICE_REGISTRY registry, BUNDLE bundle, char * serviceName, long serviceId, void * serviceObject, PROPERTIES dictionary);
 bool serviceRegistration_isValid(SERVICE_REGISTRATION registration);
+void serviceRegistration_invalidate(SERVICE_REGISTRATION registration);
 void serviceRegistration_unregister(SERVICE_REGISTRATION registration);
 
 #endif /* SERVICE_REGISTRATION_H_ */

Modified: incubator/celix/trunk/framework/private/include/service_registry.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/service_registry.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/service_registry.h (original)
+++ incubator/celix/trunk/framework/private/include/service_registry.h Tue May 10 08:21:24 2011
@@ -41,6 +41,7 @@ ARRAY_LIST serviceRegistry_getServiceRef
 void * serviceRegistry_getService(SERVICE_REGISTRY registry, BUNDLE bundle, SERVICE_REFERENCE reference);
 bool serviceRegistry_ungetService(SERVICE_REGISTRY registry, BUNDLE bundle, SERVICE_REFERENCE reference);
 void serviceRegistry_ungetServices(SERVICE_REGISTRY registry, BUNDLE bundle);
+ARRAY_LIST serviceRegistry_getUsingBundles(SERVICE_REGISTRY registry, SERVICE_REFERENCE reference);
 SERVICE_REGISTRATION serviceRegistry_findRegistration(SERVICE_REGISTRY registry, SERVICE_REFERENCE reference);
 
 #endif /* SERVICE_REGISTRY_H_ */

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=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/version_range.h (original)
+++ incubator/celix/trunk/framework/private/include/version_range.h Tue May 10 08:21:24 2011
@@ -34,6 +34,7 @@ typedef struct versionRange * VERSION_RA
 
 VERSION_RANGE versionRange_createVersionRange(VERSION low, bool isLowInclusive, VERSION high, bool isHighInclusive);
 VERSION_RANGE versionRange_createInfiniteVersionRange();
+void versionRange_destroy(VERSION_RANGE range);
 
 bool versionRange_isInRange(VERSION_RANGE versionRange, VERSION version);
 

Modified: incubator/celix/trunk/framework/private/include/wire.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/wire.h?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/wire.h (original)
+++ incubator/celix/trunk/framework/private/include/wire.h Tue May 10 08:21:24 2011
@@ -34,6 +34,7 @@
 
 WIRE wire_create(MODULE importer, REQUIREMENT requirement,
 		MODULE exporter, CAPABILITY capability);
+void wire_destroy(WIRE wire);
 
 CAPABILITY wire_getCapability(WIRE wire);
 REQUIREMENT wire_getRequirement(WIRE wire);

Modified: incubator/celix/trunk/framework/private/src/attribute.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/attribute.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/attribute.c (original)
+++ incubator/celix/trunk/framework/private/src/attribute.c Tue May 10 08:21:24 2011
@@ -23,6 +23,7 @@
  *      Author: alexanderb
  */
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "attribute.h"
 
@@ -32,3 +33,9 @@ ATTRIBUTE attribute_create(char * key, c
 	attribute->value = value;
 	return attribute;
 }
+
+void attribute_destroy(ATTRIBUTE attribute) {
+	free(attribute->key);
+	free(attribute->value);
+	free(attribute);
+}

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Tue May 10 08:21:24 2011
@@ -47,9 +47,11 @@ celix_status_t bundle_create(BUNDLE * bu
 	(*bundle)->context = NULL;
 	(*bundle)->framework = NULL;
 	(*bundle)->state = BUNDLE_INSTALLED;
+	(*bundle)->modules = arrayList_create();
 
 	MODULE module = module_createFrameworkModule();
-	(*bundle)->module = module;
+	bundle_addModule(*bundle, module);
+	// (*bundle)->module = module;
 
 	pthread_mutex_init(&(*bundle)->lock, NULL);
 	(*bundle)->lockCount = 0;
@@ -57,6 +59,8 @@ celix_status_t bundle_create(BUNDLE * bu
 
 	resolver_addModule(module);
 
+	(*bundle)->manifest = NULL;
+
 	return CELIX_SUCCESS;
 }
 
@@ -70,9 +74,11 @@ celix_status_t bundle_createFromArchive(
 	(*bundle)->context = NULL;
 	(*bundle)->framework = framework;
 	(*bundle)->state = BUNDLE_INSTALLED;
+	(*bundle)->modules = arrayList_create();
 
 	MODULE module = bundle_createModule(*bundle);
-	(*bundle)->module = module;
+	bundle_addModule(*bundle, module);
+	// (*bundle)->module = module;
 
 	pthread_mutex_init(&(*bundle)->lock, NULL);
 	(*bundle)->lockCount = 0;
@@ -83,12 +89,24 @@ celix_status_t bundle_createFromArchive(
 	return CELIX_SUCCESS;
 }
 
+celix_status_t bundle_destroy(BUNDLE bundle) {
+	ARRAY_LIST_ITERATOR iter = arrayListIterator_create(bundle->modules);
+	while (arrayListIterator_hasNext(iter)) {
+		MODULE module = arrayListIterator_next(iter);
+		module_destroy(module);
+	}
+	arrayListIterator_destroy(iter);
+	arrayList_destroy(bundle->modules);
+	free(bundle);
+	return CELIX_SUCCESS;
+}
+
 BUNDLE_ARCHIVE bundle_getArchive(BUNDLE bundle) {
 	return bundle->archive;
 }
 
-MODULE bundle_getModule(BUNDLE bundle) {
-	return bundle->module;
+MODULE bundle_getCurrentModule(BUNDLE bundle) {
+	return arrayList_get(bundle->modules, arrayList_size(bundle->modules) - 1);
 }
 
 void * bundle_getHandle(BUNDLE bundle) {
@@ -115,6 +133,10 @@ 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);
+}
+
 BUNDLE_STATE bundle_getState(BUNDLE bundle) {
 	return bundle->state;
 }
@@ -123,6 +145,14 @@ void bundle_setState(BUNDLE bundle, BUND
 	bundle->state = state;
 }
 
+MANIFEST bundle_getManifest(BUNDLE bundle) {
+	return bundle->manifest;
+}
+
+void bundle_setManifest(BUNDLE bundle, MANIFEST manifest) {
+	bundle->manifest = manifest;
+}
+
 MODULE bundle_createModule(BUNDLE bundle) {
 	MANIFEST headerMap = getManifest(bundle->archive);
 	long bundleId = bundleArchive_getId(bundle->archive);
@@ -143,8 +173,8 @@ MODULE bundle_createModule(BUNDLE bundle
 
 		long id = bundleArchive_getId(check->archive);
 		if (id != bundleArchive_getId(bundle->archive)) {
-			char * sym = module_getSymbolicName(check->module);
-			VERSION version = module_getVersion(check->module);
+			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));
@@ -152,20 +182,75 @@ MODULE bundle_createModule(BUNDLE bundle
 			}
 		}
 	}
+	arrayList_destroy(bundles);
 
 	return module;
 }
 
 void startBundle(BUNDLE bundle, int options) {
 	fw_startBundle(bundle->framework, bundle, options);
+}
 
+celix_status_t bundle_update(BUNDLE bundle, char *inputFile) {
+	return framework_updateBundle(bundle->framework, bundle, inputFile);
 }
 
 void stopBundle(BUNDLE bundle, int options) {
-	fw_stopBundle(bundle->framework, bundle, options);
+	fw_stopBundle(bundle->framework, bundle, ((options & 1) == 0));
+}
+
+celix_status_t bundle_setPersistentStateInactive(BUNDLE bundle) {
+	if (!bundle_isSystemBundle(bundle)) {
+		bundleArchive_setPersistentState(bundle->archive, BUNDLE_INSTALLED);
+	}
+	return CELIX_SUCCESS;
 }
 
+celix_status_t bundle_isUsed(BUNDLE bundle, bool *used) {
+	bool unresolved = true;
+	ARRAY_LIST_ITERATOR iter = arrayListIterator_create(bundle->modules);
+	while (arrayListIterator_hasNext(iter)) {
+		MODULE module = arrayListIterator_next(iter);
+		if (module_isResolved(module)) {
+			unresolved = false;
+		}
+	}
+	arrayListIterator_destroy(iter);
+	*used = false;
+	iter = arrayListIterator_create(bundle->modules);
+	while (arrayListIterator_hasNext(iter) && !unresolved && !*used) {
+		MODULE module = arrayListIterator_next(iter);
+//		module_getD
+	}
+	arrayListIterator_destroy(iter);
+	return CELIX_SUCCESS;
+}
+
+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;
+	}
+	bundle_addModule(bundle, module);
+	return CELIX_SUCCESS;
+}
+
+//bool bundle_rollbackRevise(BUNDLE bundle) {
+//	MODULE module = arrayList_remove(bundle->modules, arrayList_set(bundle->modules) - 1);
+//	return resolver_removeModule(module);
+//}
+
+celix_status_t bundle_addModule(BUNDLE bundle, MODULE module) {
+	arrayList_add(bundle->modules, module);
+	resolver_addModule(module);
+	return CELIX_SUCCESS;
+}
 
+bool bundle_isSystemBundle(BUNDLE bundle) {
+	return bundleArchive_getId(bundle_getArchive(bundle)) == 0;
+}
 
 bool bundle_isLockable(BUNDLE bundle) {
 	bool lockable = false;
@@ -185,6 +270,8 @@ pthread_t bundle_getLockingThread(BUNDLE
 	lockingThread = bundle->lockThread;
 
 	pthread_mutex_unlock(&bundle->lock);
+
+	return lockingThread;
 }
 
 bool bundle_lock(BUNDLE bundle) {

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=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Tue May 10 08:21:24 2011
@@ -25,11 +25,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 //#include <dirent.h>
 //#include <sys/stat.h>
 
 #include "bundle_archive.h"
+#include "bundle_revision.h"
 #include "headers.h"
+#include "linked_list_iterator.h"
 
 #include <apr-1/apr_file_io.h>
 
@@ -38,7 +41,9 @@ struct bundleArchive {
 	char * location;
 	DIR * archiveRootDir;
 	char * archiveRoot;
-	char * revision;
+	LINKED_LIST revisions;
+	long refreshCount;
+	time_t lastModified;
 
 	BUNDLE_STATE persistentState;
 
@@ -50,33 +55,69 @@ BUNDLE_ARCHIVE bundleArchive_createSyste
 	archive->id = 0l;
 	archive->location = "System Bundle";
 	archive->mp = mp;
+	archive->archiveRoot = NULL;
+	archive->archiveRootDir = NULL;
+	archive->revisions = linkedList_create();
+	archive->refreshCount = -1;
+	time(&archive->lastModified);
+
 	return archive;
 }
 
-char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive /*, int revision */);
-void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location/*, int revision */);
+char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr);
+void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr);
 
 void bundleArchive_initialize(BUNDLE_ARCHIVE archive);
 
 void bundleArchive_deleteTree(char * directory, apr_pool_t *mp);
 
+BUNDLE_REVISION bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr);
+void 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);
+
 BUNDLE_ARCHIVE bundleArchive_create(char * archiveRoot, long id, char * location, apr_pool_t *mp) {
 	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
-
 	archive->id = id;
 	archive->location = location;
 	archive->archiveRootDir = NULL;
 	archive->archiveRoot = archiveRoot;
+	archive->revisions = linkedList_create();
+	archive->refreshCount = -1;
+	time(&archive->lastModified);
 
 	archive->mp = mp;
 
 	bundleArchive_initialize(archive);
 
-	bundleArchive_revise(archive, location);
+	bundleArchive_revise(archive, location, NULL);
 
 	return archive;
 }
 
+celix_status_t bundleArchive_destroy(BUNDLE_ARCHIVE archive) {
+	if (archive->archiveRootDir != NULL) {
+		closedir(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)) {
+			BUNDLE_REVISION revision = linkedListIterator_next(iter);
+			bundleRevision_destroy(revision);
+		}
+		linkedListIterator_destroy(iter);
+		linkedList_destroy(archive->revisions);
+	}
+
+	free(archive);
+	archive = NULL;
+	return CELIX_SUCCESS;
+}
+
 BUNDLE_ARCHIVE bundleArchive_recreate(char * archiveRoot, apr_pool_t *mp) {
 	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
 	archive->archiveRoot = archiveRoot;
@@ -84,10 +125,23 @@ BUNDLE_ARCHIVE bundleArchive_recreate(ch
 	archive->id = -1;
 	archive->persistentState = -1;
 	archive->location = NULL;
+	archive->revisions = linkedList_create();
 	archive->mp = mp;
+	archive->refreshCount = -1;
+	archive->lastModified = (time_t) NULL;
+
+	apr_dir_t *dir;
+	apr_status_t status = apr_dir_open(&dir, archiveRoot, mp);
+	apr_finfo_t dp;
+	while ((apr_dir_read(&dp, APR_FINFO_DIRENT|APR_FINFO_TYPE, dir))) {
+		if (dp.filetype == APR_DIR && (strncmp(dp.name, "version", 7) == 0)) {
+			long idx;
+			sscanf(dp.name, "version%*d.%ld", &idx);
+		}
+	}
 
-	char * location = bundleArchive_getRevisionLocation(archive);
-	bundleArchive_revise(archive, location);
+	char * location = bundleArchive_getRevisionLocation(archive, 0);
+	bundleArchive_revise(archive, location, NULL);
 
 	return archive;
 }
@@ -134,8 +188,17 @@ char * bundleArchive_getArchiveRoot(BUND
 	return archive->archiveRoot;
 }
 
-char * bundleArchive_getRevision(BUNDLE_ARCHIVE archive) {
-	return archive->revision;
+long bundleArchive_getCurrentRevisionNumber(BUNDLE_ARCHIVE archive) {
+	BUNDLE_REVISION revision = bundleArchive_getCurrentRevision(archive);
+	return bundleRevision_getNumber(revision);
+}
+
+BUNDLE_REVISION bundleArchive_getCurrentRevision(BUNDLE_ARCHIVE archive) {
+	return linkedList_isEmpty(archive->revisions) ? NULL : linkedList_getLast(archive->revisions);
+}
+
+BUNDLE_REVISION bundleArchive_getRevision(BUNDLE_ARCHIVE archive, long revNr) {
+	return linkedList_get(archive->revisions, revNr);
 }
 
 BUNDLE_STATE bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive) {
@@ -190,23 +253,122 @@ void bundleArchive_setPersistentState(BU
 	archive->persistentState = state;
 }
 
-void bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location) {
-	char revisionRoot[strlen(archive->archiveRoot) + 11];
-	strcpy(revisionRoot, archive->archiveRoot);
-	strcat(revisionRoot, "/version0.0");
-	mkdir(revisionRoot, 0755);
-
-	int e = extractBundle(location, revisionRoot);
-	archive->revision = "0.0";
-
-	bundleArchive_setRevisionLocation(archive, location);
-}
-
-char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive /*, int revision */) {
-	char revisionLocation[strlen(archive->archiveRoot) + 30];
-	strcpy(revisionLocation, archive->archiveRoot);
-	strcat(revisionLocation, "/version0.0");
-	strcat(revisionLocation, "/revision.location");
+long bundleArchive_getRefreshCount(BUNDLE_ARCHIVE archive) {
+	if (archive->refreshCount >= 0) {
+		return archive->refreshCount;
+	}
+
+	char refreshCounter[strlen(archive->archiveRoot) + 17];
+	strcpy(refreshCounter,archive->archiveRoot);
+	strcat(refreshCounter, "/refresh.counter");
+	FILE * refreshCounterFile = fopen(refreshCounter, "r");
+	if (refreshCounterFile != NULL) {
+		char counterStr[256];
+		fgets (counterStr , sizeof(counterStr) , refreshCounterFile);
+		fclose(refreshCounterFile);
+		sscanf(counterStr, "%ld", &archive->refreshCount);
+	} else {
+		archive->refreshCount = 0;
+	}
+	return archive->refreshCount;
+}
+
+void bundleArchive_setRefreshCount(BUNDLE_ARCHIVE archive) {
+	char refreshCounter[strlen(archive->archiveRoot) + 17];
+	strcpy(refreshCounter, archive->archiveRoot);
+	strcat(refreshCounter, "/refresh.counter");
+	FILE * refreshCounterFile = fopen(refreshCounter, "w");
+
+	fprintf(refreshCounterFile, "%ld", archive->refreshCount);
+	fclose(refreshCounterFile);
+}
+
+time_t bundleArchive_getLastModified(BUNDLE_ARCHIVE archive) {
+	if (archive->lastModified == (time_t) NULL) {
+		archive->lastModified = bundleArchive_readLastModified(archive);
+	}
+	return archive->lastModified;
+}
+
+void bundleArchive_setLastModified(BUNDLE_ARCHIVE archive, time_t lastModifiedTime) {
+	archive->lastModified = lastModifiedTime;
+	bundleArchive_writeLastModified(archive);
+}
+
+time_t bundleArchive_readLastModified(BUNDLE_ARCHIVE archive) {
+	printf("Read time\n");
+	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);
+
+	int year, month, day, hours, minutes, seconds;
+	sscanf(timeStr, "%d %d %d %d:%d:%d", &year, &month, &day, &hours, &minutes, &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;
+
+	return mktime(&time);
+}
+
+void bundleArchive_writeLastModified(BUNDLE_ARCHIVE archive) {
+	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);
+}
+
+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);
+}
+
+void bundleArchive_reviseInternal(BUNDLE_ARCHIVE archive, bool isReload, long revNr, char * location, char *inputFile) {
+	if (inputFile != NULL) {
+		location = "inputstream:";
+	}
+
+	BUNDLE_REVISION revision = bundleArchive_createRevisionFromLocation(archive, location, inputFile, revNr);
+
+	if (!isReload) {
+		bundleArchive_setRevisionLocation(archive, location, revNr);
+	}
+
+	linkedList_addElement(archive->revisions, revision);
+}
+
+bool bundleArchive_rollbackRevise(BUNDLE_ARCHIVE archive) {
+	return true;
+}
+
+BUNDLE_REVISION bundleArchive_createRevisionFromLocation(BUNDLE_ARCHIVE archive, char *location, char *inputFile, long revNr) {
+	char root[256];
+	sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
+
+	// TODO create revision using optional FILE *fp;
+	BUNDLE_REVISION revision = bundleRevision_create(root, location, revNr, inputFile);
+	return revision;
+}
+
+char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive, long revNr) {
+	char revisionLocation[256];
+	sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
 
 	FILE * revisionLocationFile = fopen(revisionLocation, "r");
 	char location[256];
@@ -216,11 +378,9 @@ char * bundleArchive_getRevisionLocation
 	return strdup(location);
 }
 
-void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location/*, int revision */) {
-	char revisionLocation[strlen(archive->archiveRoot) + 30];
-	strcpy(revisionLocation, archive->archiveRoot);
-	strcat(revisionLocation, "/version0.0");
-	strcat(revisionLocation, "/revision.location");
+void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location, long revNr) {
+	char revisionLocation[256];
+	sprintf(revisionLocation, "%s/version%ld.%ld/revision.location", archive->archiveRoot, bundleArchive_getRefreshCount(archive), revNr);
 
 	FILE * revisionLocationFile = fopen(revisionLocation, "w");
 	fprintf(revisionLocationFile, "%s", location);
@@ -262,12 +422,14 @@ void bundleArchive_initialize(BUNDLE_ARC
 	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, "%ld", archive->id);
+	apr_file_printf(bundleLocationFile, "%s", archive->location);
 	apr_file_close(bundleLocationFile);
 
 //	FILE * bundleLocationFile = fopen(bundleLocation, "w");
 //	fprintf(bundleLocationFile, "%s", archive->location);
 //	fclose(bundleLocationFile);
+
+	bundleArchive_writeLastModified(archive);
 }
 
 void bundleArchive_deleteTree(char * directory, apr_pool_t *mp) {
@@ -287,7 +449,7 @@ void bundleArchive_deleteTree(char * dir
 
 //			struct stat s;
 //			stat(dp->d_name, &s);
-			if (dp.filetype = APR_DIR) {
+			if (dp.filetype == APR_DIR) {
 //			if (S_ISDIR(s.st_mode)) {
 //			if (dp->d_type == DT_DIR) {
 				bundleCache_deleteTree(subdir, mp);

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=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Tue May 10 08:21:24 2011
@@ -78,7 +78,7 @@ void bundleCache_deleteTree(char * direc
 
 //			struct stat s;
 //			stat(dp->d_name, &s);
-			if (dp.filetype = APR_DIR) {
+			if (dp.filetype == APR_DIR) {
 //			if (S_ISDIR(s.st_mode)) {
 //			if (dp->d_type == DT_DIR) {
 				bundleCache_deleteTree(subdir, mp);
@@ -126,6 +126,8 @@ ARRAY_LIST bundleCache_getArchives(BUNDL
 		}
 	}
 
+	apr_dir_close(dir);
+
 	return list;
 }
 

Modified: incubator/celix/trunk/framework/private/src/bundle_context.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_context.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_context.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_context.c Tue May 10 08:21:24 2011
@@ -34,19 +34,40 @@
 struct bundleContext {
 	struct framework * framework;
 	struct bundle * bundle;
+	apr_pool_t *pool;
 };
 
 BUNDLE_CONTEXT bundleContext_create(FRAMEWORK framework, BUNDLE bundle) {
 	BUNDLE_CONTEXT context = malloc(sizeof(*context));
 	context->framework = framework;
 	context->bundle = bundle;
+
+	apr_pool_create(&context->pool, framework->mp);
+
 	return context;
 }
 
+void bundleContext_destroy(BUNDLE_CONTEXT context) {
+	context->bundle = NULL;
+	context->framework = NULL;
+	apr_pool_destroy(context->pool);
+	context->pool = NULL;
+	free(context);
+	context = NULL;
+}
+
+BUNDLE bundleContext_getBundle(BUNDLE_CONTEXT context) {
+	return context->bundle;
+}
+
 FRAMEWORK bundleContext_getFramework(BUNDLE_CONTEXT context) {
 	return context->framework;
 }
 
+apr_pool_t * bundleContext_getMemoryPool(BUNDLE_CONTEXT context) {
+	return context->pool;
+}
+
 BUNDLE bundleContext_installBundle(BUNDLE_CONTEXT context, char * location) {
 	BUNDLE bundle = NULL;
 	fw_installBundle(context->framework, &bundle, location);
@@ -59,16 +80,17 @@ SERVICE_REGISTRATION bundleContext_regis
 	return registration;
 }
 
-ARRAY_LIST getServiceReferences(BUNDLE_CONTEXT context, char * serviceName, char * filter) {
+ARRAY_LIST bundleContext_getServiceReferences(BUNDLE_CONTEXT context, char * serviceName, char * filter) {
 	ARRAY_LIST references = NULL;
 	fw_getServiceReferences(context->framework, &references, context->bundle, serviceName, filter);
 	return references;
 }
 
 SERVICE_REFERENCE bundleContext_getServiceReference(BUNDLE_CONTEXT context, char * serviceName) {
-	ARRAY_LIST services = getServiceReferences(context, serviceName, NULL);
-
-	return (arrayList_size(services) > 0) ? arrayList_get(services, 0) : NULL;
+	ARRAY_LIST services = bundleContext_getServiceReferences(context, serviceName, NULL);
+	SERVICE_REFERENCE reference = (arrayList_size(services) > 0) ? arrayList_get(services, 0) : NULL;
+	arrayList_destroy(services);
+	return reference;
 }
 
 void * bundleContext_getService(BUNDLE_CONTEXT context, SERVICE_REFERENCE reference) {
@@ -87,10 +109,10 @@ BUNDLE bundleContext_getBundleById(BUNDL
 	return framework_getBundleById(context->framework, id);
 }
 
-void addServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener, char * filter) {
+void bundleContext_addServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener, char * filter) {
 	fw_addServiceListener(context->bundle, listener, filter);
 }
 
-void removeServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener) {
+void bundleContext_removeServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener) {
 	fw_removeServiceListener(context->bundle, listener);
 }

Added: 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=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_revision.c (added)
+++ incubator/celix/trunk/framework/private/src/bundle_revision.c Tue May 10 08:21:24 2011
@@ -0,0 +1,53 @@
+/*
+ * bundle_revision.c
+ *
+ *  Created on: Apr 12, 2011
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "bundle_revision.h"
+
+struct bundleRevision {
+	long revisionNr;
+	char *root;
+	char *location;
+};
+
+BUNDLE_REVISION bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile) {
+	BUNDLE_REVISION revision = malloc(sizeof(*revision));
+
+	mkdir(root, 0755);
+
+	if (inputFile != NULL) {
+		printf("extract from temp file\n");
+		int e = extractBundle(inputFile, root);
+	} else {
+		printf("extract from initial file\n");
+		int e = extractBundle(location, root);
+	}
+
+	revision->revisionNr = revisionNr;
+	revision->root = strdup(root);
+	revision->location = location;
+
+	return revision;
+}
+
+void bundleRevision_destroy(BUNDLE_REVISION revision) {
+	free(revision);
+}
+
+long bundleRevision_getNumber(BUNDLE_REVISION revision) {
+	return revision->revisionNr;
+}
+
+char * bundleRevision_getLocation(BUNDLE_REVISION revision) {
+	return revision->location;
+}
+
+char * bundleRevision_getRoot(BUNDLE_REVISION revision) {
+	printf("rev root: %s\n", revision->root);
+	return revision->root;
+}

Propchange: incubator/celix/trunk/framework/private/src/bundle_revision.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/celix/trunk/framework/private/src/capability.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/capability.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/capability.c (original)
+++ incubator/celix/trunk/framework/private/src/capability.c Tue May 10 08:21:24 2011
@@ -53,6 +53,25 @@ CAPABILITY capability_create(MODULE modu
 	return capability;
 }
 
+void capability_destroy(CAPABILITY capability) {
+	HASH_MAP_ITERATOR attrIter = hashMapIterator_create(capability->attributes);
+	while (hashMapIterator_hasNext(attrIter)) {
+		ATTRIBUTE attr = hashMapIterator_nextValue(attrIter);
+		hashMapIterator_remove(attrIter);
+		attribute_destroy(attr);
+	}
+	hashMapIterator_destroy(attrIter);
+	hashMap_destroy(capability->attributes, false, false);
+	hashMap_destroy(capability->directives, false, false);
+	version_destroy(capability->version);
+
+	capability->attributes = NULL;
+	capability->directives = NULL;
+	capability->module = NULL;
+	capability->version = NULL;
+
+}
+
 char * capability_getServiceName(CAPABILITY capability) {
 	return capability->serviceName;
 }

Modified: incubator/celix/trunk/framework/private/src/filter.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/filter.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/filter.c (original)
+++ incubator/celix/trunk/framework/private/src/filter.c Tue May 10 08:21:24 2011
@@ -86,12 +86,16 @@ void filter_destroy(FILTER filter) {
 	if (filter != NULL) {
 		if (filter->operand == SUBSTRING) {
 			arrayList_clear(filter->value);
-			free(filter->value);
+			arrayList_destroy(filter->value);
+			filter->value = NULL;
 		} else {
 			free(filter->value);
+			filter->value = NULL;
 		}
 		free(filter->attribute);
+		filter->attribute = NULL;
 		free(filter);
+		filter = NULL;
 	}
 }
 
@@ -266,8 +270,7 @@ FILTER filter_parseItem(char * filterStr
 					filter->value = string;
 
 					arrayList_clear(subs);
-					free(subs);
-//					arrayList_destroy(subs);
+					arrayList_destroy(subs);
 
 					return filter;
 				}
@@ -332,6 +335,7 @@ char * filter_parseValue(char * filterSt
 			case '\\': {
 				(*pos)++;
 				c = filterString[*pos];
+				//no break
 			}
 			default: {
 				char ch[2];
@@ -383,6 +387,7 @@ ARRAY_LIST filter_parseSubstring(char * 
 			case '\\': {
 				(*pos)++;
 				c = filterString[*pos];
+				//no break
 			}
 			default: {
 				char ch[2];
@@ -518,7 +523,7 @@ int filter_compareString(OPERAND operand
 		case NOT:
 		case OR:
 		case PRESENT: {
-
+			//no break
 		}
 	}
 	return 0;

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue May 10 08:21:24 2011
@@ -31,6 +31,7 @@
 #include <stdbool.h>
 #include <pthread.h>
 #include <math.h>
+#include <apr-1/apr_file_io.h>
 
 #include "framework.h"
 #include "filter.h"
@@ -45,30 +46,29 @@
 #include "bundle_cache.h"
 #include "bundle_archive.h"
 #include "bundle_context.h"
+#include "linked_list_iterator.h"
 
 struct activator {
 	void * userData;
 	void (*start)(void * userData, BUNDLE_CONTEXT context);
 	void (*stop)(void * userData, BUNDLE_CONTEXT context);
-	void (*destroy)(void * userData);
+	void (*destroy)(void * userData, BUNDLE_CONTEXT context);
 };
 
-//struct exception_context the_exception_context[1];
-
 ARRAY_LIST m_serviceListeners;
 
 HASH_MAP m_installRequestMap;
 
 pthread_mutex_t m_installRequestLock = PTHREAD_MUTEX_INITIALIZER;
 
-void framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE bundle, int state);
+celix_status_t framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE bundle, int state);
 celix_status_t framework_markBundleResolved(FRAMEWORK framework, MODULE module);
 
 celix_status_t framework_acquireBundleLock(FRAMEWORK framework, BUNDLE bundle, int desiredStates);
 bool framework_releaseBundleLock(FRAMEWORK framework, BUNDLE bundle);
 
 bool framework_acquireGlobalLock(FRAMEWORK framework);
-void framework_releaseGlobalLock(FRAMEWORK framework);
+celix_status_t framework_releaseGlobalLock(FRAMEWORK framework);
 
 long framework_getNextBundleId(FRAMEWORK framework);
 
@@ -96,7 +96,9 @@ celix_status_t framework_create(FRAMEWOR
 	apr_pool_create(&(*framework)->mp, NULL);
 
 	BUNDLE bundle = NULL;
-	celix_status_t rvb = bundle_create(&bundle, (*framework)->mp);
+	apr_pool_t *bundlePool;
+	apr_pool_create(&bundlePool, (*framework)->mp);
+	celix_status_t rvb = bundle_create(&bundle, bundlePool);
 	if (rvb != CELIX_SUCCESS) {
 		return rvb;
 	}
@@ -122,6 +124,38 @@ celix_status_t framework_create(FRAMEWOR
 	return CELIX_SUCCESS;
 }
 
+celix_status_t framework_destroy(FRAMEWORK framework) {
+	HASH_MAP_ITERATOR iterator = hashMapIterator_create(framework->installedBundleMap);
+	while (hashMapIterator_hasNext(iterator)) {
+		BUNDLE bundle = hashMapIterator_nextValue(iterator);
+		char * location = hashMapIterator_nextKey(iterator);
+
+		// for each installed bundle, clean up memory
+		LINKED_LIST wires = module_getWires(bundle_getCurrentModule(bundle));
+		if (wires != NULL) {
+			LINKED_LIST_ITERATOR iter = linkedListIterator_create(wires, 0);
+			while (linkedListIterator_hasNext(iter)) {
+				WIRE wire = linkedListIterator_next(iter);
+				linkedListIterator_remove(iter);
+				wire_destroy(wire);
+			}
+			linkedListIterator_destroy(iter);
+			linkedList_destroy(wires);
+		}
+
+		bundleArchive_destroy(bundle->archive);
+		bundle_destroy(bundle);
+		hashMapIterator_remove(iterator);
+	}
+	hashMapIterator_destroy(iterator);
+
+
+	apr_pool_destroy(framework->mp);
+	apr_terminate();
+
+	return CELIX_SUCCESS;
+}
+
 celix_status_t fw_init(FRAMEWORK framework) {
 	celix_status_t lock = framework_acquireBundleLock(framework, framework->bundle, BUNDLE_INSTALLED|BUNDLE_RESOLVED|BUNDLE_STARTING|BUNDLE_ACTIVE);
 	if (lock != CELIX_SUCCESS) {
@@ -144,10 +178,14 @@ celix_status_t fw_init(FRAMEWORK framewo
 
 	hashMap_put(framework->installedBundleMap, bundleArchive_getLocation(bundle_getArchive(framework->bundle)), framework->bundle);
 
-	if (resolver_resolve(bundle_getModule(framework->bundle)) == NULL) {
+	HASH_MAP wires = resolver_resolve(bundle_getCurrentModule(framework->bundle));
+	if (wires == NULL) {
 		printf("Unresolved constraints in System Bundle\n");
 		framework_releaseBundleLock(framework, framework->bundle);
 		return CELIX_BUNDLE_EXCEPTION;
+	} else {
+		framework_markResolvedModules(framework, wires);
+		hashMap_destroy(wires, false, false);
 	}
 
 	// reload archives from cache
@@ -164,6 +202,7 @@ celix_status_t fw_init(FRAMEWORK framewo
 			fw_installBundle2(framework, &bundle, bundleArchive_getId(archive), bundleArchive_getLocation(archive), archive);
 		}
 	}
+	arrayList_destroy(archives);
 	framework->registry = serviceRegistry_create(fw_serviceChanged);
 
 	framework_setBundleStateAndNotify(framework, framework->bundle, BUNDLE_STARTING);
@@ -177,13 +216,16 @@ celix_status_t fw_init(FRAMEWORK framewo
 		return CELIX_START_ERROR;
 	}
 
+	BUNDLE_CONTEXT context = bundleContext_create(framework, framework->bundle);
+	bundle_setContext(framework->bundle, context);
+
 	bundle_setHandle(framework->bundle, handle);
 
 	ACTIVATOR activator = (ACTIVATOR) malloc(sizeof(*activator));
-	void * (*create)();
+	void * (*create)(BUNDLE_CONTEXT context);
 	void (*start)(void * handle, BUNDLE_CONTEXT context);
 	void (*stop)(void * handle, BUNDLE_CONTEXT context);
-	void (*destroy)(void * handle);
+	void (*destroy)(void * handle, BUNDLE_CONTEXT context);
 	create = dlsym(bundle_getHandle(framework->bundle), BUNDLE_ACTIVATOR_CREATE);
 	start = dlsym(bundle_getHandle(framework->bundle), BUNDLE_ACTIVATOR_START);
 	stop = dlsym(bundle_getHandle(framework->bundle), BUNDLE_ACTIVATOR_STOP);
@@ -193,12 +235,9 @@ celix_status_t fw_init(FRAMEWORK framewo
 	activator->destroy = destroy;
 	bundle_setActivator(framework->bundle, activator);
 
-	BUNDLE_CONTEXT context = bundleContext_create(framework, framework->bundle);
-	bundle_setContext(framework->bundle, context);
-
 	void * userData = NULL;
 	if (create != NULL) {
-		userData = create();
+		userData = create(bundle_getContext(framework->bundle));
 	}
 	activator->userData = userData;
 
@@ -270,6 +309,8 @@ celix_status_t fw_installBundle2(FRAMEWO
 		return CELIX_BUNDLE_EXCEPTION;
 	}
 
+	apr_pool_t *bundlePool;
+	apr_pool_create(&bundlePool, framework->mp);
 	celix_status_t rv = bundle_createFromArchive(bundle, framework, archive);
 	framework_releaseGlobalLock(framework);
 
@@ -277,7 +318,31 @@ celix_status_t fw_installBundle2(FRAMEWO
 
   	framework_releaseInstallLock(framework, location);
 
-	return CELIX_SUCCESS;
+  	return CELIX_SUCCESS;
+}
+
+celix_status_t framework_getBundleEntry(FRAMEWORK framework, BUNDLE bundle, char *name, char **entry) {
+	BUNDLE_REVISION revision = bundleArchive_getCurrentRevision(bundle_getArchive(bundle));
+	if ((strlen(name) > 0) && (name[0] == '/')) {
+		name++;
+	}
+
+	char *root = bundleRevision_getRoot(revision);
+	printf("Root and Entry name: %s - %s\n", root, name);
+	char *e = NULL;
+	apr_filepath_merge(&e, root, name, APR_FILEPATH_NOTABOVEROOT, framework->mp);
+	printf("Entry name: %s\n", e);
+	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) = strdup(e);
+		return CELIX_SUCCESS;
+	}
+
+	return CELIX_ILLEGAL_STATE;
 }
 
 celix_status_t fw_startBundle(FRAMEWORK framework, BUNDLE bundle, int options ATTRIBUTE_UNUSED) {
@@ -311,13 +376,20 @@ celix_status_t fw_startBundle(FRAMEWORK 
 			framework_releaseBundleLock(framework, bundle);
 			return CELIX_SUCCESS;
 		case BUNDLE_INSTALLED:
-			wires = resolver_resolve(bundle_getModule(bundle));
+			wires = resolver_resolve(bundle_getCurrentModule(bundle));
+			if (wires == NULL) {
+				framework_releaseBundleLock(framework, bundle);
+				return CELIX_BUNDLE_EXCEPTION;
+			}
 			framework_markResolvedModules(framework, wires);
+			hashMap_destroy(wires, false, false);
+			// no break
 		case BUNDLE_RESOLVED:
 			context = bundleContext_create(framework, bundle);
 			bundle_setContext(bundle, context);
 
 			MANIFEST manifest = getManifest(bundle_getArchive(bundle));
+			bundle_setManifest(bundle, manifest);
 			char * library = manifest_getValue(manifest, HEADER_LIBRARY);
 
 	#ifdef __linux__
@@ -331,17 +403,24 @@ celix_status_t fw_startBundle(FRAMEWORK 
 			 char * library_extension = ".dll";
 	#endif
 
-			char * root = bundleArchive_getArchiveRoot(bundle_getArchive(bundle));
-			char * revision = bundleArchive_getRevision(bundle_getArchive(bundle));
-			char libraryPath[strlen(root) + strlen(revision) + strlen(library) +
-							 strlen(library_prefix) + strlen(library_extension) + 10];
-			strcpy(libraryPath, root);
-			strcat(libraryPath, "/version");
-			strcat(libraryPath, revision);
-			strcat(libraryPath, "/");
-			strcat(libraryPath, library_prefix);
-			strcat(libraryPath, library);
-			strcat(libraryPath, library_extension);
+			char libraryPath[256];
+			sprintf(libraryPath, "%s/version%ld.%ld/%s%s%s",
+					bundleArchive_getArchiveRoot(bundle_getArchive(bundle)),
+					bundleArchive_getRefreshCount(bundle_getArchive(bundle)),
+					bundleArchive_getCurrentRevisionNumber(bundle_getArchive(bundle)),
+					library_prefix,
+					library,
+					library_extension
+					);
+//			strcpy(libraryPath, root);
+//			strcat(libraryPath, "/version");
+//			strcat(libraryPath, bundleArchive_getRefreshCount(bundle_getArchive(bundle)));
+//			strcat(libraryPath, ".");
+//			strcat(libraryPath, bundleArchive_getCurrentRevisionNumber(bundle_getArchive(bundle)));
+//			strcat(libraryPath, "/");
+//			strcat(libraryPath, library_prefix);
+//			strcat(libraryPath, library);
+//			strcat(libraryPath, library_extension);
 
 			handle = dlopen(libraryPath, RTLD_LAZY|RTLD_LOCAL);
 			if (handle == NULL) {
@@ -353,10 +432,10 @@ celix_status_t fw_startBundle(FRAMEWORK 
 			bundle_setHandle(bundle, handle);
 
 			ACTIVATOR activator = (ACTIVATOR) malloc(sizeof(*activator));
-			void * (*create)();
+			void * (*create)(BUNDLE_CONTEXT context, void **userData);
 			void (*start)(void * userData, BUNDLE_CONTEXT context);
 			void (*stop)(void * userData, BUNDLE_CONTEXT context);
-			void (*destroy)(void * userData);
+			void (*destroy)(void * userData, BUNDLE_CONTEXT context);
 			create = dlsym(bundle_getHandle(bundle), BUNDLE_ACTIVATOR_CREATE);
 			start = dlsym(bundle_getHandle(bundle), BUNDLE_ACTIVATOR_START);
 			stop = dlsym(bundle_getHandle(bundle), BUNDLE_ACTIVATOR_STOP);
@@ -370,7 +449,7 @@ celix_status_t fw_startBundle(FRAMEWORK 
 
 			void * userData = NULL;
 			if (create != NULL) {
-				userData = create();
+				create(bundle_getContext(bundle), &userData);
 			}
 			activator->userData = userData;
 
@@ -387,7 +466,45 @@ celix_status_t fw_startBundle(FRAMEWORK 
 	return CELIX_SUCCESS;
 }
 
-void fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, int options ATTRIBUTE_UNUSED) {
+celix_status_t framework_updateBundle(FRAMEWORK framework, BUNDLE bundle, char *inputFile) {
+	celix_status_t lock = framework_acquireBundleLock(framework, bundle, BUNDLE_INSTALLED|BUNDLE_RESOLVED|BUNDLE_ACTIVE);
+	if (lock != CELIX_SUCCESS) {
+		printf("Cannot update bundle, in wrong state");
+		framework_releaseBundleLock(framework, bundle);
+		return lock;
+	}
+
+	BUNDLE_STATE oldState = bundle_getState(bundle);
+	char * location = bundleArchive_getLocation(bundle_getArchive(bundle));
+
+	if (oldState == BUNDLE_ACTIVE) {
+		fw_stopBundle(framework, bundle, false);
+	}
+
+	bool locked = framework_acquireGlobalLock(framework);
+	if (!locked) {
+		printf("Unable to acquire the global lock to update the bundle\n");
+		framework_releaseInstallLock(framework, location);
+		return CELIX_BUNDLE_EXCEPTION;
+	}
+
+	bundle_revise(bundle, location, inputFile);
+	framework_releaseGlobalLock(framework);
+
+	bundleArchive_setLastModified(bundle_getArchive(bundle), time(NULL));
+	framework_setBundleStateAndNotify(framework, bundle, BUNDLE_INSTALLED);
+
+	// Refresh packages?
+
+	if (oldState == BUNDLE_ACTIVE) {
+		fw_startBundle(framework, bundle, 1);
+	}
+	framework_releaseBundleLock(framework, bundle);
+
+	return CELIX_SUCCESS;
+}
+
+void fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, bool record) {
 	celix_status_t lock = framework_acquireBundleLock(framework, bundle, BUNDLE_INSTALLED|BUNDLE_RESOLVED|BUNDLE_STARTING|BUNDLE_ACTIVE);
 	if (lock != CELIX_SUCCESS) {
 		printf("Cannot stop bundle");
@@ -395,6 +512,13 @@ void fw_stopBundle(FRAMEWORK framework, 
 		return;
 	}
 
+	if (record) {
+		bundle_setPersistentStateInactive(bundle);
+	}
+
+	//if (!fw_isBundlePersistentlyStarted(framework, bundle)) {
+	//}
+
 	switch (bundle_getState(bundle)) {
 		case BUNDLE_UNINSTALLED:
 			printf("Cannot stop bundle since it is uninstalled.");
@@ -419,27 +543,31 @@ void fw_stopBundle(FRAMEWORK framework, 
 
 	framework_setBundleStateAndNotify(framework, bundle, BUNDLE_STOPPING);
 
-	if (bundle_getActivator(bundle)->stop != NULL) {
-		bundle_getActivator(bundle)->stop(bundle_getActivator(bundle)->userData, bundle_getContext(bundle));
+	ACTIVATOR activator = bundle_getActivator(bundle);
+	if (activator->stop != NULL) {
+		activator->stop(activator->userData, bundle_getContext(bundle));
 	}
 
-	if (bundle_getActivator(bundle)->destroy != NULL) {
-		bundle_getActivator(bundle)->destroy(bundle_getActivator(bundle)->userData);
+	if (activator->destroy != NULL) {
+		activator->destroy(activator->userData, bundle_getContext(bundle));
 	}
 
-	if (module_getId(bundle_getModule(bundle)) != 0) {
-		bundle_getActivator(bundle)->start = NULL;
-		bundle_getActivator(bundle)->stop = NULL;
-		bundle_getActivator(bundle)->userData = NULL;
-		free(bundle_getActivator(bundle));
+	if (module_getId(bundle_getCurrentModule(bundle)) != 0) {
+		activator->start = NULL;
+		activator->stop = NULL;
+		activator->userData = NULL;
+		free(activator);
 		bundle_setActivator(bundle, NULL);
 
 		serviceRegistry_unregisterServices(framework->registry, bundle);
 		serviceRegistry_ungetServices(framework->registry, bundle);
 
-		dlclose(bundle_getHandle(bundle));
+		//dlclose(bundle_getHandle(bundle));
 	}
 
+	bundleContext_destroy(bundle_getContext(bundle));
+	manifest_destroy(bundle_getManifest(bundle));
+
 	framework_setBundleStateAndNotify(framework, bundle, BUNDLE_RESOLVED);
 
 	framework_releaseBundleLock(framework, bundle);
@@ -555,13 +683,21 @@ void fw_serviceChanged(SERVICE_EVENT eve
 }
 
 MANIFEST getManifest(BUNDLE_ARCHIVE archive) {
-	char * root = bundleArchive_getArchiveRoot(archive);
-	char * revision = bundleArchive_getRevision(archive);
-	char manifest[strlen(root) + strlen(revision) + 30];
-	strcpy(manifest, root);
-	strcat(manifest, "/version");
-	strcat(manifest, revision);
-	strcat(manifest, "/MANIFEST/MANIFEST.MF");
+	char manifest[256];
+	sprintf(manifest, "%s/version%ld.%ld/MANIFEST/MANIFEST.MF",
+			bundleArchive_getArchiveRoot(archive),
+			bundleArchive_getRefreshCount(archive),
+			bundleArchive_getCurrentRevisionNumber(archive)
+			);
+
+//	char * root = bundleArchive_getArchiveRoot(archive);
+//	char manifest[256];
+//	strcpy(manifest, root);
+//	strcat(manifest, "/version");
+//	strcat(manifest, bundleArchive_getRefreshCount(archive));
+//	strcat(manifest, ".");
+//	strcat(manifest, bundleArchive_getCurrentRevisionNumber(archive));
+//	strcat(manifest, "/MANIFEST/MANIFEST.MF");
 	return manifest_read(manifest);
 }
 
@@ -573,23 +709,19 @@ long framework_getNextBundleId(FRAMEWORK
 
 celix_status_t framework_markResolvedModules(FRAMEWORK framework, HASH_MAP resolvedModuleWireMap) {
 	if (resolvedModuleWireMap != NULL) {
-		LINKED_LIST wireList = linkedList_create();
 		HASH_MAP_ITERATOR iterator = hashMapIterator_create(resolvedModuleWireMap);
 		while (hashMapIterator_hasNext(iterator)) {
 			HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iterator);
 			MODULE module = (MODULE) hashMapEntry_getKey(entry);
 			LINKED_LIST wires = (LINKED_LIST) hashMapEntry_getValue(entry);
 
-			linkedList_clear(wireList);
-
-			if (linkedList_size(wires) > 0) {
-				module_setWires(module, wires);
-			}
+			module_setWires(module, wires);
 
 			module_setResolved(module);
 			resolver_moduleResolved(module);
 			framework_markBundleResolved(framework, module);
 		}
+		hashMapIterator_destroy(iterator);
 	}
 	return CELIX_SUCCESS;
 }
@@ -617,6 +749,7 @@ ARRAY_LIST framework_getBundles(FRAMEWOR
 		BUNDLE bundle = hashMapIterator_nextValue(iterator);
 		arrayList_add(bundles, bundle);
 	}
+	hashMapIterator_destroy(iterator);
 	return bundles;
 }
 
@@ -627,16 +760,19 @@ BUNDLE framework_getBundle(FRAMEWORK fra
 
 BUNDLE framework_getBundleById(FRAMEWORK framework, long id) {
 	HASH_MAP_ITERATOR iter = hashMapIterator_create(framework->installedBundleMap);
+	BUNDLE bundle = NULL;
 	while (hashMapIterator_hasNext(iter)) {
 		BUNDLE b = hashMapIterator_nextValue(iter);
 		if (bundleArchive_getId(bundle_getArchive(b)) == id) {
-			return b;
+			bundle = b;
+			break;
 		}
 	}
-	return NULL;
+	hashMapIterator_destroy(iter);
+	return bundle;
 }
 
-int framework_acquireInstallLock(FRAMEWORK framework, char * location) {
+celix_status_t framework_acquireInstallLock(FRAMEWORK framework, char * location) {
 	pthread_mutex_lock(&m_installRequestLock);
 
 	while (hashMap_get(m_installRequestMap, location) != NULL) {
@@ -645,28 +781,51 @@ int framework_acquireInstallLock(FRAMEWO
 	hashMap_put(m_installRequestMap, location, location);
 
 	pthread_mutex_unlock(&m_installRequestLock);
+
+	return CELIX_SUCCESS;
 }
 
-int framework_releaseInstallLock(FRAMEWORK framework, char * location) {
+celix_status_t framework_releaseInstallLock(FRAMEWORK framework, char * location) {
 	pthread_mutex_lock(&m_installRequestLock);
 
 	hashMap_remove(m_installRequestMap, location);
 	pthread_cond_broadcast(&framework->condition);
 
 	pthread_mutex_unlock(&m_installRequestLock);
+
+	return CELIX_SUCCESS;
 }
 
-void framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE bundle, int state) {
-	pthread_mutex_lock(&framework->bundleLock);
+celix_status_t framework_setBundleStateAndNotify(FRAMEWORK framework, BUNDLE bundle, int state) {
+	int ret = CELIX_SUCCESS;
+
+	int err = pthread_mutex_lock(&framework->bundleLock);
+	if (err != 0) {
+		celix_log("Failed to lock");
+		return CELIX_BUNDLE_EXCEPTION;
+	}
 
 	bundle_setState(bundle, state);
-	pthread_cond_broadcast(&framework->condition);
+	err = pthread_cond_broadcast(&framework->condition);
+	if (err != 0) {
+		celix_log("Failed to broadcast");
+		ret = CELIX_BUNDLE_EXCEPTION;
+	}
 
-	pthread_mutex_unlock(&framework->bundleLock);
+	err = pthread_mutex_unlock(&framework->bundleLock);
+	if (err != 0) {
+		celix_log("Failed to unlock");
+		return CELIX_BUNDLE_EXCEPTION;
+	}
+	return CELIX_SUCCESS;
 }
 
 celix_status_t framework_acquireBundleLock(FRAMEWORK framework, BUNDLE bundle, int desiredStates) {
-	pthread_mutex_lock(&framework->bundleLock);
+	int err = pthread_mutex_lock(&framework->bundleLock);
+	if (err != 0) {
+		celix_log("Failed to lock");
+		return CELIX_BUNDLE_EXCEPTION;
+	}
 
 	while (!bundle_isLockable(bundle)
 			|| ((framework->globalLockThread != NULL)
@@ -746,29 +905,50 @@ bool framework_acquireGlobalLock(FRAMEWO
 	return !interrupted;
 }
 
-void framework_releaseGlobalLock(FRAMEWORK framework) {
-	pthread_mutex_lock(&framework->bundleLock);
+celix_status_t framework_releaseGlobalLock(FRAMEWORK framework) {
+	int ret = CELIX_SUCCESS;
+	if (pthread_mutex_lock(&framework->bundleLock) != 0) {
+		celix_log("Error locking framework bundle lock");
+		return CELIX_FRAMEWORK_EXCEPTION;
+	}
 
 	if (framework->globalLockThread == pthread_self()) {
 		framework->globalLockCount--;
 		if (framework->globalLockCount == 0) {
 			framework->globalLockThread = NULL;
-			pthread_cond_broadcast(&framework->condition);
+			if (pthread_cond_broadcast(&framework->condition) != 0) {
+				celix_log("Failed to broadcast global lock release.");
+				ret = CELIX_FRAMEWORK_EXCEPTION;
+				// still need to unlock before returning
+			}
 		}
 	} else {
 		printf("The current thread does not own the global lock");
 	}
 
-	pthread_mutex_unlock(&framework->bundleLock);
+	if (pthread_mutex_unlock(&framework->bundleLock) != 0) {
+		celix_log("Error unlocking framework bundle lock");
+		return CELIX_FRAMEWORK_EXCEPTION;
+	}
+	return ret;
 }
 
-void framework_waitForStop(FRAMEWORK framework) {
-	pthread_mutex_lock(&framework->mutex);
-	pthread_cond_wait(&framework->shutdownGate, &framework->mutex);
-	pthread_mutex_unlock(&framework->mutex);
+celix_status_t framework_waitForStop(FRAMEWORK framework) {
+	if (pthread_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) {
+		celix_log("Error waiting for shutdown gate.");
+		return CELIX_FRAMEWORK_EXCEPTION;
+	}
+	if (pthread_mutex_unlock(&framework->mutex) != 0) {
+		celix_log("Error unlocking the framework.");
+		return CELIX_FRAMEWORK_EXCEPTION;
+	}
 }
 
-void * framework_shutdown(void * framework) {
+static void * framework_shutdown(void * framework) {
 	FRAMEWORK fw = (FRAMEWORK) framework;
 
 	HASH_MAP_ITERATOR iterator = hashMapIterator_create(fw->installedBundleMap);
@@ -778,23 +958,50 @@ void * framework_shutdown(void * framewo
 			fw_stopBundle(fw, bundle, 0);
 		}
 	}
+	hashMapIterator_destroy(iterator);
 
-	pthread_mutex_lock(&fw->mutex);
-	pthread_cond_broadcast(&fw->shutdownGate);
-	pthread_mutex_unlock(&fw->mutex);
+	int err = pthread_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);
+	if (err != 0) {
+		celix_log("Error waking the shutdown gate, cannot exit clean.");
+		err = pthread_mutex_unlock(&fw->mutex);
+		if (err != 0) {
+			celix_log("Error unlocking the framework, cannot exit clean.");
+		}
+
+		pthread_exit(NULL);
+		return NULL;
+	}
+	err = pthread_mutex_unlock(&fw->mutex);
+	if (err != 0) {
+		celix_log("Error unlocking the framework, cannot exit clean.");
+	}
 
 	pthread_exit(NULL);
+
+	return NULL;
 }
 
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
 	// nothing to do
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
 	pthread_t shutdownThread;
-	pthread_create(&shutdownThread, NULL, framework_shutdown, bundleContext_getFramework(context));
+	int err = pthread_create(&shutdownThread, NULL, framework_shutdown, bundleContext_getFramework(context));
+	if (err != 0) {
+		celix_log("Could not create shutdown thread, normal exit not possible.");
+		return CELIX_BUNDLE_EXCEPTION;
+	}
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_destroy(void * userData) {
-
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+	return CELIX_SUCCESS;
 }

Modified: incubator/celix/trunk/framework/private/src/manifest.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest.c Tue May 10 08:21:24 2011
@@ -116,6 +116,8 @@ MANIFEST manifest_read(char * filename) 
 			if ((properties_set(mainAttributes, name, value) != NULL) && (!lineContinued)) {
 				printf("Duplicate entry: %s", name);
 			}
+			free(name);
+			free(value);
 		}
 		fclose(file);
 		return mf;
@@ -124,6 +126,15 @@ MANIFEST manifest_read(char * filename) 
 	return NULL;
 }
 
+void manifest_destroy(MANIFEST manifest) {
+	if (manifest != NULL) {
+		properties_destroy(manifest->mainAttributes);
+		manifest->mainAttributes = NULL;
+		free(manifest);
+		manifest = NULL;
+	}
+}
+
 void manifest_write(MANIFEST manifest, char * filename) {
 
 }

Modified: incubator/celix/trunk/framework/private/src/manifest_parser.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/manifest_parser.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/manifest_parser.c (original)
+++ incubator/celix/trunk/framework/private/src/manifest_parser.c Tue May 10 08:21:24 2011
@@ -32,16 +32,19 @@
 #include "requirement.h"
 #include "attribute.h"
 #include "hash_map.h"
+#include "celix_errno.h"
+#include "linked_list_iterator.h"
 
 MANIFEST_PARSER manifestParser_createManifestParser(MODULE owner, MANIFEST manifest) {
 	MANIFEST_PARSER parser = (MANIFEST_PARSER) malloc(sizeof(*parser));
 	parser->manifest = manifest;
 	parser->owner = owner;
 
-	parser->bundleVersion = version_createEmptyVersion();
 	char * bundleVersion = manifest_getValue(manifest, BUNDLE_VERSION);
 	if (bundleVersion != NULL) {
 		parser->bundleVersion = version_createVersionFromString(bundleVersion);
+	} else {
+		parser->bundleVersion = version_createEmptyVersion();
 	}
 	char * bundleSymbolicName = manifest_getValue(manifest, BUNDLE_SYMBOLICNAME);
 	if (bundleSymbolicName != NULL) {
@@ -53,9 +56,21 @@ MANIFEST_PARSER manifestParser_createMan
 	return parser;
 }
 
+celix_status_t manifestParser_destroy(MANIFEST_PARSER parser) {
+//	version_destroy(parser->bundleVersion);
+	parser->bundleSymbolicName = NULL;
+	parser->bundleVersion = NULL;
+	parser->owner = NULL;
+	parser->capabilities = NULL;
+	parser->manifest = NULL;
+	parser->requirements = NULL;
+	free(parser);
+	return CELIX_SUCCESS;
+}
+
 LINKED_LIST manifestParser_parseDelimitedString(char * value, char * delim) {
 	if (value == NULL) {
-		value = "";
+		value = strdup("");
 	}
 
 	LINKED_LIST list = linkedList_create();
@@ -104,6 +119,8 @@ LINKED_LIST manifestParser_parseDelimite
 		}
 	}
 
+	free(value);
+
 	if (strlen(buffer) > 0) {
 		linkedList_addElement(list, strdup(buffer));
 	}
@@ -173,6 +190,8 @@ LINKED_LIST manifestParser_parseStandard
 		}
 	}
 
+	linkedList_destroy(pieces);
+
 	LINKED_LIST clause = linkedList_create();
 	linkedList_addElement(clause, paths);
 	linkedList_addElement(clause, dirsMap);
@@ -188,12 +207,13 @@ LINKED_LIST manifestParser_parseStandard
 			return NULL;
 		}
 
-		LINKED_LIST clauseStrings = manifestParser_parseDelimitedString(header, ",");
+		LINKED_LIST clauseStrings = manifestParser_parseDelimitedString(strdup(header), ",");
 		int i;
 	  	for (i = 0; (clauseStrings != NULL) && (i < linkedList_size(clauseStrings)); i++) {
 	  		char * clauseString = (char *) linkedList_get(clauseStrings, i);
 	  		linkedList_addElement(completeList, manifestParser_parseStandardHeaderClause(clauseString));
 		}
+	  	linkedList_destroy(clauseStrings);
 	  	return completeList;
 	}
 	return completeList;
@@ -226,6 +246,20 @@ LINKED_LIST manifestParser_parseImportHe
 		}
 	}
 
+	LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
+	while(linkedListIterator_hasNext(iter)) {
+		LINKED_LIST clause = linkedListIterator_next(iter);
+
+		LINKED_LIST paths = linkedList_get(clause, 0);
+
+		linkedList_destroy(paths);
+
+		linkedListIterator_remove(iter);
+		linkedList_destroy(clause);
+	}
+	linkedListIterator_destroy(iter);
+	linkedList_destroy(clauses);
+
 	return requirements;
 }
 
@@ -255,6 +289,19 @@ LINKED_LIST manifestParser_parseExportHe
 			linkedList_addElement(capabilities, cap);
 		}
 	}
+	LINKED_LIST_ITERATOR iter = linkedListIterator_create(clauses, 0);
+	while(linkedListIterator_hasNext(iter)) {
+		LINKED_LIST clause = linkedListIterator_next(iter);
+
+		LINKED_LIST paths = linkedList_get(clause, 0);
+
+		linkedList_destroy(paths);
+
+		linkedListIterator_remove(iter);
+		linkedList_destroy(clause);
+	}
+	linkedListIterator_destroy(iter);
+	linkedList_destroy(clauses);
 
 	return capabilities;
 }

Modified: incubator/celix/trunk/framework/private/src/module.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/module.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/module.c (original)
+++ incubator/celix/trunk/framework/private/src/module.c Tue May 10 08:21:24 2011
@@ -52,12 +52,14 @@ MODULE module_create(MANIFEST headerMap,
 	module->headerMap = headerMap;
 	module->id = moduleId;
 	module->bundle = bundle;
+	module->resolved = false;
 
 	MANIFEST_PARSER mp = manifestParser_createManifestParser(module, headerMap);
 	module->symbolicName = mp->bundleSymbolicName;
 	module->version = mp->bundleVersion;
 	module->capabilities = mp->capabilities;
 	module->requirements = mp->requirements;
+	manifestParser_destroy(mp);
 
 	module->wires = NULL;
 
@@ -66,25 +68,60 @@ MODULE module_create(MANIFEST headerMap,
 
 MODULE module_createFrameworkModule() {
 	MODULE module = (MODULE) malloc(sizeof(*module));
-	module->id = "0";
+	module->id = strdup("0");
 	module->symbolicName = strdup("framework");
 	module->version = version_createVersion(1, 0, 0, "");
 	module->capabilities = linkedList_create();
 	module->requirements = linkedList_create();
+	module->wires = NULL;
+	module->headerMap = NULL;
+	module->resolved = false;
+	module->bundle = NULL;
 	return module;
 }
 
+void module_destroy(MODULE module) {
+	LINKED_LIST_ITERATOR capIter = linkedListIterator_create(module->capabilities, 0);
+	while (linkedListIterator_hasNext(capIter)) {
+		CAPABILITY cap = linkedListIterator_next(capIter);
+		capability_destroy(cap);
+	}
+	linkedListIterator_destroy(capIter);
+
+	LINKED_LIST_ITERATOR reqIter = linkedListIterator_create(module->requirements, 0);
+	while (linkedListIterator_hasNext(reqIter)) {
+		REQUIREMENT req = linkedListIterator_next(reqIter);
+		requirement_destroy(req);
+	}
+	linkedListIterator_destroy(reqIter);
+
+	linkedList_destroy(module->capabilities);
+	linkedList_destroy(module->requirements);
+
+	version_destroy(module->version);
+
+	if (module->headerMap != NULL) {
+		manifest_destroy(module->headerMap);
+	}
+	module->headerMap = NULL;
+
+	free(module->id);
+	free(module);
+}
+
 WIRE module_getWire(MODULE module, char * serviceName) {
+	WIRE wire = NULL;
 	if (module->wires != NULL) {
 		LINKED_LIST_ITERATOR iterator = linkedListIterator_create(module->wires, 0);
 		while (linkedListIterator_hasNext(iterator)) {
-			WIRE wire = linkedListIterator_next(iterator);
-			if (strcasecmp(capability_getServiceName(wire_getCapability(wire)), serviceName) == 0) {
-				return wire;
+			WIRE next = linkedListIterator_next(iterator);
+			if (strcasecmp(capability_getServiceName(wire_getCapability(next)), serviceName) == 0) {
+				wire = next;
 			}
 		}
+		linkedListIterator_destroy(iterator);
 	}
-	return NULL;
+	return wire;
 }
 
 VERSION module_getVersion(MODULE module) {

Modified: incubator/celix/trunk/framework/private/src/properties.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/properties.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/properties.c (original)
+++ incubator/celix/trunk/framework/private/src/properties.c Tue May 10 08:21:24 2011
@@ -76,6 +76,17 @@ PROPERTIES properties_create(void) {
 	return hashMap_create(string_hash, string_hash, string_equals, string_equals);
 }
 
+void properties_destroy(PROPERTIES properties) {
+	HASH_MAP_ITERATOR iter = hashMapIterator_create(properties);
+	while (hashMapIterator_hasNext(iter)) {
+		HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+		free(hashMapEntry_getKey(entry));
+		free(hashMapEntry_getValue(entry));
+	}
+	hashMapIterator_destroy(iter);
+	hashMap_destroy(properties, false, false);
+}
+
 PROPERTIES properties_load(char * filename) {
 	PROPERTIES props = properties_create();
 	FILE *file = fopen ( filename, "r" );
@@ -93,15 +104,20 @@ PROPERTIES properties_load(char * filena
 				unsigned int pos = strcspn(line, "=");
 				if (pos != strlen(line)) {
 					key = string_trim(string_ndup((char *)line, pos));
-					value = string_trim(string_ndup(line+pos+1, strlen(line)));
+					char * ival = string_ndup(line+pos+1, strlen(line));
+					value = string_trim(ival);
 					if (value != NULL) {
-						if (strcmp(cont, string_ndup(value+strlen(value)-1, 1)) == 0) {
+						char * cmp = string_ndup(value+strlen(value)-1, 1);
+						if (strcmp(cont, cmp) == 0) {
 							split = 1;
 							value = string_ndup(value, strlen(value)-1);
 						} else {
-							char * old = hashMap_put(props, key, value);
+							char * old = hashMap_put(props, strdup(key), strdup(value));
 						}
+						free(cmp);
+						free(ival);
 					}
+					free(key);
 				}
 			} else {
 				if (strcmp(cont, string_ndup(line+strlen(line)-1, 1)) == 0) {
@@ -110,15 +126,14 @@ PROPERTIES properties_load(char * filena
 				} else {
 					split = 0;
 					strcat(value, string_trim(line));
-					char * old = hashMap_put(props, key, value);
+					char * old = hashMap_put(props, strdup(key), strdup(value));
 				}
 			}
 		}
 		fclose(file);
-		return props;
 	}
 	free(cont);
-	return NULL;
+	return props;
 }
 
 /**
@@ -155,5 +170,5 @@ char * properties_getWithDefault(PROPERT
 }
 
 char * properties_set(PROPERTIES properties, char * key, char * value) {
-	return hashMap_put(properties, key, value);
+	return hashMap_put(properties, strdup(key), strdup(value));
 }

Modified: incubator/celix/trunk/framework/private/src/requirement.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/requirement.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/requirement.c (original)
+++ incubator/celix/trunk/framework/private/src/requirement.c Tue May 10 08:21:24 2011
@@ -52,6 +52,25 @@ REQUIREMENT requirement_create(HASH_MAP 
 	return requirement;
 }
 
+void requirement_destroy(REQUIREMENT requirement) {
+	HASH_MAP_ITERATOR attrIter = hashMapIterator_create(requirement->attributes);
+	while (hashMapIterator_hasNext(attrIter)) {
+		ATTRIBUTE attr = hashMapIterator_nextValue(attrIter);
+		hashMapIterator_remove(attrIter);
+		attribute_destroy(attr);
+	}
+	hashMapIterator_destroy(attrIter);
+	hashMap_destroy(requirement->attributes, false, false);
+	hashMap_destroy(requirement->directives, false, false);
+	versionRange_destroy(requirement->versionRange);
+
+	requirement->attributes = NULL;
+	requirement->directives = NULL;
+	requirement->versionRange = NULL;
+
+	free(requirement);
+}
+
 VERSION_RANGE requirement_getVersionRange(REQUIREMENT requirement) {
 	return requirement->versionRange;
 }
@@ -61,5 +80,5 @@ char * requirement_getTargetName(REQUIRE
 }
 
 bool requirement_isSatisfied(REQUIREMENT requirement, CAPABILITY capability) {
-	versionRange_isInRange(requirement_getVersionRange(requirement), capability_getVersion(capability));
+	return versionRange_isInRange(requirement_getVersionRange(requirement), capability_getVersion(capability));
 }

Modified: incubator/celix/trunk/framework/private/src/resolver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/resolver.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/resolver.c (original)
+++ incubator/celix/trunk/framework/private/src/resolver.c Tue May 10 08:21:24 2011
@@ -64,11 +64,55 @@ HASH_MAP resolver_resolve(MODULE root) {
 	HASH_MAP candidatesMap = hashMap_create(NULL, NULL, NULL, NULL);
 
 	if (resolver_populateCandidatesMap(candidatesMap, root) != 0) {
+		HASH_MAP_ITERATOR iter = hashMapIterator_create(candidatesMap);
+		while (hashMapIterator_hasNext(iter)) {
+			HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+			MODULE key = hashMapEntry_getKey(entry);
+			LINKED_LIST value = hashMapEntry_getValue(entry);
+			hashMapIterator_remove(iter);
+			if (value != NULL) {
+				LINKED_LIST_ITERATOR candSetIter = linkedListIterator_create(value, 0);
+				while (linkedListIterator_hasNext(candSetIter)) {
+					CANDIDATE_SET set = linkedListIterator_next(candSetIter);
+					if (set->candidates != NULL) {
+						linkedList_destroy(set->candidates);
+					}
+					free(set);
+					linkedListIterator_remove(candSetIter);
+				}
+				linkedListIterator_destroy(candSetIter);
+				linkedList_destroy(value);
+			}
+		}
+		hashMapIterator_destroy(iter);
+		hashMap_destroy(candidatesMap, false, false);
 		return NULL;
 	}
 
 	HASH_MAP wireMap = hashMap_create(NULL,NULL,NULL,NULL);
-	return resolver_populateWireMap(candidatesMap, root, wireMap);
+	HASH_MAP resolved = resolver_populateWireMap(candidatesMap, root, wireMap);
+	HASH_MAP_ITERATOR iter = hashMapIterator_create(candidatesMap);
+	while (hashMapIterator_hasNext(iter)) {
+		HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+		MODULE key = hashMapEntry_getKey(entry);
+		LINKED_LIST value = hashMapEntry_getValue(entry);
+		hashMapIterator_remove(iter);
+		if (value != NULL) {
+			LINKED_LIST_ITERATOR candSetIter = linkedListIterator_create(value, 0);
+			while (linkedListIterator_hasNext(candSetIter)) {
+				CANDIDATE_SET set = linkedListIterator_next(candSetIter);
+				if (set->candidates != NULL) {
+					linkedList_destroy(set->candidates);
+				}
+				free(set);
+			}
+			linkedListIterator_destroy(candSetIter);
+			linkedList_destroy(value);
+		}
+	}
+	hashMapIterator_destroy(iter);
+	hashMap_destroy(candidatesMap, false, false);
+	return resolved;
 }
 
 int resolver_populateCandidatesMap(HASH_MAP candidatesMap, MODULE targetModule) {
@@ -103,7 +147,7 @@ int resolver_populateCandidatesMap(HASH_
 		}
 
 		if (linkedList_size(candidates) > 0) {
-			LINKED_LIST_ITERATOR iterator;
+			LINKED_LIST_ITERATOR iterator = NULL;
 			for (iterator = linkedListIterator_create(candidates, 0); linkedListIterator_hasNext(iterator); ) {
 				CAPABILITY candidate = (CAPABILITY) linkedListIterator_next(iterator);
 				if (!module_isResolved(capability_getModule(candidate))) {
@@ -112,11 +156,14 @@ int resolver_populateCandidatesMap(HASH_
 					}
 				}
 			}
+			linkedListIterator_destroy(iterator);
 		}
 
 		if (linkedList_size(candidates) == 0) {
 			LINKED_LIST invalid = linkedList_create();
 			resolver_removeInvalidCandidate(targetModule, candidatesMap, invalid);
+			linkedList_destroy(invalid);
+			linkedList_destroy(candidates);
 			printf("Unable to resolve: %s, %s\n", module_getSymbolicName(targetModule), requirement_getTargetName(req));
 			return -1;
 		} else if (linkedList_size(candidates) > 0) {
@@ -236,18 +283,23 @@ void resolver_moduleResolved(MODULE modu
 				linkedList_addElement(list->capabilities, cap);
 			}
 		}
+
+		linkedList_destroy(capsCopy);
 	}
 }
 
 CAPABILITY_LIST resolver_getCapabilityList(LINKED_LIST list, char * name) {
+	CAPABILITY_LIST capabilityList = NULL;
 	LINKED_LIST_ITERATOR iterator = linkedListIterator_create(list, 0);
 	while (linkedListIterator_hasNext(iterator)) {
 		CAPABILITY_LIST services = (CAPABILITY_LIST) linkedListIterator_next(iterator);
 		if (strcmp(services->serviceName, name) == 0) {
-			return services;
+			capabilityList = services;
+			break;
 		}
 	}
-	return NULL;
+	linkedListIterator_destroy(iterator);
+	return capabilityList;
 }
 
 HASH_MAP resolver_populateWireMap(HASH_MAP candidates, MODULE importer, HASH_MAP wireMap) {
@@ -280,7 +332,8 @@ HASH_MAP resolver_populateWireMap(HASH_M
 	}
 
 	//hashMap_remove(wireMap, importer);
-	hashMap_put(wireMap, importer, serviceWires);
+	LINKED_LIST empty = hashMap_put(wireMap, importer, serviceWires);
+	linkedList_destroy(empty);
 
 	return wireMap;
 }

Modified: incubator/celix/trunk/framework/private/src/service_reference.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_reference.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_reference.c (original)
+++ incubator/celix/trunk/framework/private/src/service_reference.c Tue May 10 08:21:24 2011
@@ -36,15 +36,15 @@ bool serviceReference_isAssignableTo(SER
 		return allow;
 	}
 
-	WIRE providerWire = module_getWire(bundle_getModule(provider), serviceName);
-	WIRE requesterWire = module_getWire(bundle_getModule(requester), serviceName);
+	WIRE providerWire = module_getWire(bundle_getCurrentModule(provider), serviceName);
+	WIRE requesterWire = module_getWire(bundle_getCurrentModule(requester), serviceName);
 
 	if (providerWire == NULL && requesterWire != NULL) {
-		allow = (bundle_getModule(provider) == wire_getExporter(requesterWire));
+		allow = (bundle_getCurrentModule(provider) == wire_getExporter(requesterWire));
 	} else if (providerWire != NULL && requesterWire != NULL) {
 		allow = (wire_getExporter(providerWire) == wire_getExporter(requesterWire));
 	} else if (providerWire != NULL && requesterWire == NULL) {
-		allow = (wire_getExporter(providerWire) == bundle_getModule(requester));
+		allow = (wire_getExporter(providerWire) == bundle_getCurrentModule(requester));
 	} else {
 		allow = false;
 	}

Modified: incubator/celix/trunk/framework/private/src/service_registration.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_registration.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_registration.c (original)
+++ incubator/celix/trunk/framework/private/src/service_registration.c Tue May 10 08:21:24 2011
@@ -41,7 +41,7 @@ SERVICE_REGISTRATION serviceRegistration
 
 	char sId[sizeof(serviceId) + 1];
 	sprintf(sId, "%ld", serviceId);
-	properties_set(dictionary, (char *) SERVICE_ID, strdup(sId));
+	properties_set(dictionary, (char *) SERVICE_ID, sId);
 	properties_set(dictionary, (char *) OBJECTCLASS, serviceName);
 
 	registration->properties = dictionary;
@@ -69,6 +69,8 @@ void serviceRegistration_destroy(SERVICE
 	registration->reference->registration = NULL;
 	free(registration->reference);
 
+	properties_destroy(registration->properties);
+
 	pthread_mutex_destroy(&registration->mutex);
 
 	free(registration);
@@ -78,6 +80,12 @@ bool serviceRegistration_isValid(SERVICE
 	return registration->svcObj != NULL;
 }
 
+void serviceRegistration_invalidate(SERVICE_REGISTRATION registration) {
+	pthread_mutex_lock(&registration->mutex);
+	registration->svcObj = NULL;
+	pthread_mutex_unlock(&registration->mutex);
+}
+
 void serviceRegistration_unregister(SERVICE_REGISTRATION registration) {
 	pthread_mutex_lock(&registration->mutex);
 	if (!serviceRegistration_isValid(registration) || registration->isUnregistering) {
@@ -89,7 +97,8 @@ void serviceRegistration_unregister(SERV
 
 	serviceRegistry_unregisterService(registration->registry, registration->reference->bundle, registration);
 
-	pthread_mutex_lock(&registration->mutex);
-	registration->svcObj = NULL;
-	pthread_mutex_unlock(&registration->mutex);
+	// Unregister service cleans up the registration
+//	pthread_mutex_lock(&registration->mutex);
+//	registration->svcObj = NULL;
+//	pthread_mutex_unlock(&registration->mutex);
 }

Modified: incubator/celix/trunk/framework/private/src/service_registry.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_registry.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_registry.c (original)
+++ incubator/celix/trunk/framework/private/src/service_registry.c Tue May 10 08:21:24 2011
@@ -23,9 +23,12 @@
  *      Author: alexanderb
  */
 #include <stdlib.h>
+#include <stdio.h>
 
 #include "service_registry.h"
 #include "service_registration.h"
+#include "module.h"
+#include "bundle.h"
 
 struct usageCount {
 	unsigned int count;
@@ -56,6 +59,7 @@ USAGE_COUNT serviceRegistry_addUsageCoun
 
 	if (usages == NULL) {
 		usages = arrayList_create();
+		MODULE mod = bundle_getCurrentModule(bundle);
 	}
 	arrayList_add(usages, usage);
 	hashMap_put(registry->inUseMap, bundle, usages);
@@ -69,12 +73,15 @@ void serviceRegistry_flushUsageCount(SER
 		USAGE_COUNT usage = arrayListIterator_next(iter);
 		if (usage->reference == reference) {
 			arrayListIterator_remove(iter);
+			free(usage);
 		}
 	}
+	arrayListIterator_destroy(iter);
 	if (arrayList_size(usages) > 0) {
 		hashMap_put(registry->inUseMap, bundle, usages);
 	} else {
-		hashMap_remove(registry->inUseMap, bundle);
+		ARRAY_LIST removed = hashMap_remove(registry->inUseMap, bundle);
+		arrayList_destroy(removed);
 	}
 }
 
@@ -83,7 +90,11 @@ SERVICE_REGISTRY serviceRegistry_create(
 	registry->serviceChanged = serviceChanged;
 	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
 	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
-	pthread_mutex_init(&registry->mutex, NULL);
+
+	pthread_mutexattr_t mutexattr;
+	pthread_mutexattr_init(&mutexattr);
+	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+	pthread_mutex_init(&registry->mutex, &mutexattr);
 	registry->currentServiceId = 1l;
 	return registry;
 }
@@ -138,8 +149,8 @@ void serviceRegistry_unregisterService(S
 	ARRAY_LIST regs = (ARRAY_LIST) hashMap_get(registry->serviceRegistrations, bundle);
 	if (regs != NULL) {
 		arrayList_removeElement(regs, registration);
+		hashMap_put(registry->serviceRegistrations, bundle, regs);
 	}
-	hashMap_put(registry->serviceRegistrations, bundle, regs);
 
 	pthread_mutex_unlock(&registry->mutex);
 
@@ -148,11 +159,26 @@ void serviceRegistry_unregisterService(S
 		event->type = UNREGISTERING;
 		event->reference = registration->reference;
 		registry->serviceChanged(event, NULL);
+		free(event);
 	}
 
-//	pthread_mutex_lock(&registry->mutex);
+	pthread_mutex_lock(&registry->mutex);
 	// unget service
-//	pthread_mutex_unlock(&registry->mutex);
+
+	ARRAY_LIST clients = serviceRegistry_getUsingBundles(registry, registration->reference);
+	int i;
+	for (i = 0; (clients != NULL) && (i < arrayList_size(clients)); i++) {
+		BUNDLE client = arrayList_get(clients, i);
+		while (serviceRegistry_ungetService(registry, client, registration->reference)) {
+			;
+		}
+	}
+	arrayList_destroy(clients);
+	serviceRegistration_invalidate(registration);
+
+	serviceRegistration_destroy(registration);
+
+	pthread_mutex_unlock(&registry->mutex);
 
 }
 
@@ -170,6 +196,12 @@ void serviceRegistry_unregisterServices(
 		}
 	}
 
+	if (regs != NULL && arrayList_isEmpty(regs)) {
+		ARRAY_LIST removed = hashMap_remove(registry->serviceRegistrations, bundle);
+		arrayList_destroy(removed);
+		removed = NULL;
+	}
+
 	pthread_mutex_lock(&registry->mutex);
 	hashMap_remove(registry->serviceRegistrations, bundle);
 	pthread_mutex_unlock(&registry->mutex);
@@ -201,6 +233,8 @@ ARRAY_LIST serviceRegistry_getServiceRef
 			}
 		}
 	}
+	hashMapIterator_destroy(iterator);
+	hashMapValues_destroy(registrations);
 
 	return references;
 }
@@ -264,6 +298,7 @@ bool serviceRegistry_ungetService(SERVIC
 
 	usage->count--;
 
+
 	if ((registration->svcObj == NULL) || (usage->count <= 0)) {
 		usage->service = NULL;
 		serviceRegistry_flushUsageCount(registry, bundle, reference);
@@ -283,13 +318,36 @@ void serviceRegistry_ungetServices(SERVI
 		return;
 	}
 
+	// usage arrays?
+	ARRAY_LIST fusages = arrayList_clone(usages);
+
 	int i;
-	for (i = 0; i < arrayList_size(usages); i++) {
-		USAGE_COUNT usage = arrayList_get(usages, i);
-		while (serviceRegistry_ungetService(registry, bundle, usage->reference)) {
+	for (i = 0; i < arrayList_size(fusages); i++) {
+		USAGE_COUNT usage = arrayList_get(fusages, i);
+		SERVICE_REFERENCE reference = usage->reference;
+		while (serviceRegistry_ungetService(registry, bundle, reference)) {
 			//
 		}
 	}
-}
 
+	arrayList_destroy(fusages);
+}
 
+ARRAY_LIST serviceRegistry_getUsingBundles(SERVICE_REGISTRY registry, SERVICE_REFERENCE reference) {
+	ARRAY_LIST bundles = arrayList_create();
+	HASH_MAP_ITERATOR iter = hashMapIterator_create(registry->inUseMap);
+	while (hashMapIterator_hasNext(iter)) {
+		HASH_MAP_ENTRY entry = hashMapIterator_nextEntry(iter);
+		BUNDLE bundle = hashMapEntry_getKey(entry);
+		ARRAY_LIST usages = hashMapEntry_getValue(entry);
+		int i;
+		for (i = 0; i < arrayList_size(usages); i++) {
+			USAGE_COUNT usage = arrayList_get(usages, i);
+			if (usage->reference == reference) {
+				arrayList_add(bundles, bundle);
+			}
+		}
+	}
+	hashMapIterator_destroy(iter);
+	return bundles;
+}

Modified: incubator/celix/trunk/framework/private/src/service_tracker.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_tracker.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_tracker.c (original)
+++ incubator/celix/trunk/framework/private/src/service_tracker.c Tue May 10 08:21:24 2011
@@ -59,7 +59,7 @@ void tracker_open(SERVICE_TRACKER tracke
 	SERVICE_LISTENER listener = (SERVICE_LISTENER) malloc(sizeof(*listener));
 	FW_SERVICE_TRACKER fwTracker = findFwServiceTracker(tracker);
 
-	ARRAY_LIST initial = getServiceReferences(tracker->context, tracker->className, NULL);
+	ARRAY_LIST initial = bundleContext_getServiceReferences(tracker->context, tracker->className, NULL);
 	SERVICE_REFERENCE initial_reference;
 	unsigned int i;
 	int len = strlen(tracker->className);
@@ -73,7 +73,7 @@ void tracker_open(SERVICE_TRACKER tracke
 	strcat(filter, ")\0");
 
 	listener->serviceChanged = (void *) tracker_serviceChanged;
-	addServiceListener(tracker->context, listener, filter);
+	bundleContext_addServiceListener(tracker->context, listener, filter);
 	fwTracker->listener = listener;
 
 	for (i = 0; i < arrayList_size(initial); i++) {
@@ -81,14 +81,14 @@ void tracker_open(SERVICE_TRACKER tracke
 		track(fwTracker, initial_reference, NULL);
 	}
 	arrayList_clear(initial);
-	free(initial);
+	arrayList_destroy(initial);
 
 	initial = NULL;
 }
 
 void tracker_close(SERVICE_TRACKER tracker) {
 	FW_SERVICE_TRACKER fwTracker = findFwServiceTracker(tracker);
-	removeServiceListener(tracker->context, fwTracker->listener);
+	bundleContext_removeServiceListener(tracker->context, fwTracker->listener);
 
 	ARRAY_LIST refs = tracker_getServiceReferences(tracker);
 	if (refs != NULL) {
@@ -98,11 +98,12 @@ void tracker_close(SERVICE_TRACKER track
 			untrack(fwTracker, ref, NULL);
 		}
 	}
+	arrayList_destroy(refs);
 }
 
 void tracker_destroy(SERVICE_TRACKER tracker) {
 	FW_SERVICE_TRACKER fwTracker = findFwServiceTracker(tracker);
-	removeServiceListener(tracker->context, fwTracker->listener);
+	bundleContext_removeServiceListener(tracker->context, fwTracker->listener);
 	free(fwTracker->listener);
 	free(fwTracker->customizer);
 	tracker = NULL;
@@ -240,13 +241,14 @@ void untrack(FW_SERVICE_TRACKER fwTracke
 		if (tracked->reference == reference) {
 			if (tracked != NULL) {
 				arrayList_remove(fwTracker->tracked, i);
-				//ungetService(fwTracker->tracker->context, reference);
+				bundleContext_ungetService(fwTracker->tracker->context, reference);
 			}
 			if (fwTracker->customizer != NULL) {
 				fwTracker->customizer->removedService(fwTracker->customizer->handle, reference, tracked->service);
 			} else {
 				bundleContext_ungetService(fwTracker->tracker->context, reference);
 			}
+			free(tracked);
 			break;
 		}
 	}

Modified: incubator/celix/trunk/framework/private/src/utils.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/utils.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/utils.c (original)
+++ incubator/celix/trunk/framework/private/src/utils.c Tue May 10 08:21:24 2011
@@ -61,16 +61,18 @@ char * string_ndup(const char *s, size_t
 }
 
 char * string_trim(char * string) {
+	char * copy = string;
+
 	char *end;
 	// Trim leading space
-	while(isspace(*string)) string++;
+	while(isspace(*copy)) copy++;
 
 	// Trim trailing space
-	end = string + strlen(string) - 1;
-	while(end > string && isspace(*end)) end--;
+	end = copy + strlen(copy) - 1;
+	while(end > copy && isspace(*end)) end--;
 
 	// Write new null terminator
 	*(end+1) = 0;
 
-	return string;
+	return copy;
 }

Modified: incubator/celix/trunk/framework/private/src/version.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/version.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/version.c (original)
+++ incubator/celix/trunk/framework/private/src/version.c Tue May 10 08:21:24 2011
@@ -27,6 +27,7 @@
 #include <string.h>
 
 #include "version.h"
+#include "celix_errno.h"
 
 struct version {
 	int major;
@@ -60,7 +61,9 @@ VERSION version_createVersionFromString(
 
 	token = strtok(version, delims);
 	if (token != NULL) {
-		major = atoi(strdup(token));
+		char * majorS = strdup(token);
+		major = atoi(majorS);
+		free(majorS);
 		token = strtok(NULL, delims);
 		if (token != NULL) {
 			minor = atoi(token);
@@ -86,6 +89,14 @@ VERSION version_createEmptyVersion() {
 	return version_createVersion(0, 0, 0, "");
 }
 
+celix_status_t version_destroy(VERSION version) {
+	version->major = 0;
+	version->minor = 0;
+	version->micro = 0;
+	free(version);
+	return CELIX_SUCCESS;
+}
+
 int version_compareTo(VERSION version, VERSION compare) {
 	if (compare == version) {
 		return 0;

Modified: incubator/celix/trunk/framework/private/src/version_range.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/version_range.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/version_range.c (original)
+++ incubator/celix/trunk/framework/private/src/version_range.c Tue May 10 08:21:24 2011
@@ -48,6 +48,16 @@ VERSION_RANGE versionRange_createVersion
 	return range;
 }
 
+void versionRange_destroy(VERSION_RANGE range) {
+	if (range->high != NULL) {
+		version_destroy(range->high);
+	}
+	if (range->low != NULL) {
+		version_destroy(range->low);
+	}
+	free(range);
+}
+
 VERSION_RANGE versionRange_createInfiniteVersionRange() {
 	VERSION_RANGE range = (VERSION_RANGE) malloc(sizeof(*range));
 

Modified: incubator/celix/trunk/framework/private/src/wire.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/wire.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/wire.c (original)
+++ incubator/celix/trunk/framework/private/src/wire.c Tue May 10 08:21:24 2011
@@ -45,6 +45,14 @@ WIRE wire_create(MODULE importer, REQUIR
 	return wire;
 }
 
+void wire_destroy(WIRE wire) {
+	wire->importer = NULL;
+	wire->requirement = NULL;
+	wire->exporter = NULL;
+	wire->capability = NULL;
+	free(wire);
+}
+
 CAPABILITY wire_getCapability(WIRE wire) {
 	return wire->capability;
 }

Modified: incubator/celix/trunk/hello_world/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/CMakeLists.txt?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/hello_world/CMakeLists.txt (original)
+++ incubator/celix/trunk/hello_world/CMakeLists.txt Tue May 10 08:21:24 2011
@@ -19,4 +19,4 @@ add_library(hello_world SHARED activator
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 target_link_libraries(hello_world framework)
 
-bundle(hello_world)
+bundle(hello_world DIRECTORIES root)

Modified: incubator/celix/trunk/hello_world/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/activator.c?rev=1101360&r1=1101359&r2=1101360&view=diff
==============================================================================
--- incubator/celix/trunk/hello_world/activator.c (original)
+++ incubator/celix/trunk/hello_world/activator.c Tue May 10 08:21:24 2011
@@ -24,30 +24,39 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#include <apr-1/apr_general.h>
 
 #include "bundle_activator.h"
+#include "bundle_context.h"
 
 struct userData {
 	char * word;
 };
 
-void * bundleActivator_create() {
-	struct userData * data = malloc(sizeof(*data));
-	data->word = "World";
-	return data;
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+	*userData = apr_palloc(bundleContext_getMemoryPool(context), sizeof(struct userData));
+	((struct userData *)(*userData))->word = "World";
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
 	struct userData * data = (struct userData *) userData;
 	printf("Hello %s\n", data->word);
 
+	BUNDLE b = bundleContext_getBundle(context);
+	char *entry = NULL;
+	bundle_getEntry(b, "test.txt", &entry);
+	printf("Entry: %s", entry);
+
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
 	struct userData * data = (struct userData *) userData;
 	printf("Goodbye %s\n", data->word);
+	return CELIX_SUCCESS;
 }
 
-void bundleActivator_destroy(void * userData) {
-
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+	return CELIX_SUCCESS;
 }

Added: incubator/celix/trunk/hello_world/root/index.html
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/root/index.html?rev=1101360&view=auto
==============================================================================
--- incubator/celix/trunk/hello_world/root/index.html (added)
+++ incubator/celix/trunk/hello_world/root/index.html Tue May 10 08:21:24 2011
@@ -0,0 +1 @@
+adsf
\ No newline at end of file

Propchange: incubator/celix/trunk/hello_world/root/index.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message