incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1043903 [1/5] - /incubator/celix/trunk/celix/
Date Thu, 09 Dec 2010 11:49:43 GMT
Author: abroekhuis
Date: Thu Dec  9 11:49:40 2010
New Revision: 1043903

URL: http://svn.apache.org/viewvc?rev=1043903&view=rev
Log:
CELIX-1 initial code import

Added:
    incubator/celix/trunk/celix/
    incubator/celix/trunk/celix/CMakeLists.txt
    incubator/celix/trunk/celix/archive.h
    incubator/celix/trunk/celix/array_list.c
    incubator/celix/trunk/celix/array_list.h
    incubator/celix/trunk/celix/array_list_private.h
    incubator/celix/trunk/celix/attribute.c
    incubator/celix/trunk/celix/attribute.h
    incubator/celix/trunk/celix/bundle.c
    incubator/celix/trunk/celix/bundle.h
    incubator/celix/trunk/celix/bundle_activator.h
    incubator/celix/trunk/celix/bundle_archive.c
    incubator/celix/trunk/celix/bundle_archive.h
    incubator/celix/trunk/celix/bundle_cache.c
    incubator/celix/trunk/celix/bundle_cache.h
    incubator/celix/trunk/celix/bundle_context.c
    incubator/celix/trunk/celix/bundle_context.h
    incubator/celix/trunk/celix/bundle_state.h
    incubator/celix/trunk/celix/capability.c
    incubator/celix/trunk/celix/capability.h
    incubator/celix/trunk/celix/cexcept.h
    incubator/celix/trunk/celix/component.h
    incubator/celix/trunk/celix/constants.h
    incubator/celix/trunk/celix/filter.c
    incubator/celix/trunk/celix/filter.h
    incubator/celix/trunk/celix/framework.c
    incubator/celix/trunk/celix/framework.h
    incubator/celix/trunk/celix/hash_map.c
    incubator/celix/trunk/celix/hash_map.h
    incubator/celix/trunk/celix/hash_map_private.h
    incubator/celix/trunk/celix/hashtable.c
    incubator/celix/trunk/celix/hashtable.h
    incubator/celix/trunk/celix/hashtable_itr.c
    incubator/celix/trunk/celix/hashtable_itr.h
    incubator/celix/trunk/celix/hashtable_private.h
    incubator/celix/trunk/celix/hashtable_utility.c
    incubator/celix/trunk/celix/hashtable_utility.h
    incubator/celix/trunk/celix/headers.h
    incubator/celix/trunk/celix/ioapi.c
    incubator/celix/trunk/celix/ioapi.h
    incubator/celix/trunk/celix/linked_list_iterator.c
    incubator/celix/trunk/celix/linked_list_iterator.h
    incubator/celix/trunk/celix/linked_list_private.h
    incubator/celix/trunk/celix/linkedlist.c
    incubator/celix/trunk/celix/linkedlist.h
    incubator/celix/trunk/celix/manifest.c
    incubator/celix/trunk/celix/manifest.h
    incubator/celix/trunk/celix/manifest_parser.c
    incubator/celix/trunk/celix/manifest_parser.h
    incubator/celix/trunk/celix/miniunz.c
    incubator/celix/trunk/celix/module.c
    incubator/celix/trunk/celix/module.h
    incubator/celix/trunk/celix/properties.c
    incubator/celix/trunk/celix/properties.h
    incubator/celix/trunk/celix/requirement.c
    incubator/celix/trunk/celix/requirement.h
    incubator/celix/trunk/celix/resolver.c
    incubator/celix/trunk/celix/resolver.h
    incubator/celix/trunk/celix/service_reference.c
    incubator/celix/trunk/celix/service_reference.h
    incubator/celix/trunk/celix/service_registration.c
    incubator/celix/trunk/celix/service_registration.h
    incubator/celix/trunk/celix/service_registry.c
    incubator/celix/trunk/celix/service_registry.h
    incubator/celix/trunk/celix/service_tracker.c
    incubator/celix/trunk/celix/service_tracker.h
    incubator/celix/trunk/celix/unzip.c
    incubator/celix/trunk/celix/unzip.h
    incubator/celix/trunk/celix/utils.c
    incubator/celix/trunk/celix/utils.h
    incubator/celix/trunk/celix/version.c
    incubator/celix/trunk/celix/version.h
    incubator/celix/trunk/celix/version_range.c
    incubator/celix/trunk/celix/version_range.h
    incubator/celix/trunk/celix/wire.c
    incubator/celix/trunk/celix/wire.h

Added: incubator/celix/trunk/celix/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/CMakeLists.txt?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/CMakeLists.txt (added)
+++ incubator/celix/trunk/celix/CMakeLists.txt Thu Dec  9 11:49:40 2010
@@ -0,0 +1,11 @@
+aux_source_directory(. SRC)
+add_library(framework SHARED ${SRC})
+target_link_libraries(framework m dl z pthread)
+
+set(dir .)
+file (GLOB headers "${dir}/*.h")
+
+install(FILES ${headers} DESTINATION include COMPONENT framework)
+install(TARGETS framework LIBRARY DESTINATION lib COMPONENT framework)
+
+add_definitions(-DUSE_FILE32API)
\ No newline at end of file

Added: incubator/celix/trunk/celix/archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/archive.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/archive.h (added)
+++ incubator/celix/trunk/celix/archive.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,13 @@
+/*
+ * archive.h
+ *
+ *  Created on: May 31, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef ARCHIVE_H_
+#define ARCHIVE_H_
+
+int extractBundle(char * bundleName, char * revisionRoot);
+
+#endif /* ARCHIVE_H_ */

Added: incubator/celix/trunk/celix/array_list.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/array_list.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/array_list.c (added)
+++ incubator/celix/trunk/celix/array_list.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,258 @@
+/*
+ * array_list.c
+ *
+ *  Created on: Aug 4, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "array_list.h"
+#include "array_list_private.h"
+
+ARRAY_LIST arrayList_create(void) {
+	ARRAY_LIST list = (ARRAY_LIST) malloc(sizeof(*list));
+
+	list->size = 0;
+	list->capacity = 10;
+	list->elementData = (void **) malloc(sizeof(void*) * list->capacity);
+
+	return list;
+}
+
+void arrayList_trimToSize(ARRAY_LIST list) {
+	list->modCount++;
+	int oldCapacity = list->capacity;
+	if (list->size < oldCapacity) {
+		void ** newList = (void **) realloc(list->elementData, sizeof(void *) * list->size);
+		list->capacity = list->size;
+		list->elementData = newList;
+	}
+}
+
+void arrayList_ensureCapacity(ARRAY_LIST list, int capacity) {
+	list->modCount++;
+	int oldCapacity = list->capacity;
+	if (capacity > oldCapacity) {
+		int newCapacity = (oldCapacity * 3) / 2 + 1;
+		if (newCapacity < capacity) {
+			newCapacity = capacity;
+		}
+		void ** newList = (void **) realloc(list->elementData, sizeof(void *) * newCapacity);
+		list->capacity = newCapacity;
+		list->elementData = newList;
+	}
+}
+
+unsigned int arrayList_size(ARRAY_LIST list) {
+	return list->size;
+}
+
+bool arrayList_isEmpty(ARRAY_LIST list) {
+	return list->size == 0;
+}
+
+bool arrayList_contains(ARRAY_LIST list, void * element) {
+	int index = arrayList_indexOf(list, element);
+	return index >= 0;
+}
+
+int arrayList_indexOf(ARRAY_LIST list, void * element) {
+	if (element == NULL) {
+		int i = 0;
+		for (i = 0; i < list->size; i++) {
+			if (list->elementData[i] == NULL) {
+				return i;
+			}
+		}
+	} else {
+		int i = 0;
+		for (i = 0; i < list->size; i++) {
+			if (list->elementData[i] == element) { //equalsFunction?
+				return i;
+			}
+		}
+	}
+	return -1;
+}
+
+int arrayList_lastIndexOf(ARRAY_LIST list, void * element) {
+	if (element == NULL) {
+		int i = 0;
+		for (i = list->size - 1; i >= 0; i--) {
+			if (list->elementData[i] == NULL) {
+				return i;
+			}
+		}
+	} else {
+		int i = 0;
+		for (i = list->size - 1; i >= 0; i--) {
+			if (list->elementData[i] == element) { //equalsFunction?
+				return i;
+			}
+		}
+	}
+	return -1;
+}
+
+void * arrayList_get(ARRAY_LIST list, unsigned int index) {
+	if (index >= list->size) {
+		return NULL;
+	}
+
+	return list->elementData[index];
+}
+
+void * arrayList_set(ARRAY_LIST list, unsigned int index, void * element) {
+	if (index >= list->size) {
+		return NULL;
+	}
+
+	void * oldElement = list->elementData[index];
+	list->elementData[index] = element;
+	return oldElement;
+}
+
+bool arrayList_add(ARRAY_LIST list, void * element) {
+	arrayList_ensureCapacity(list, list->size + 1);
+	list->elementData[list->size++] = element;
+	return true;
+}
+
+int arrayList_addIndex(ARRAY_LIST list, unsigned int index, void * element) {
+	if (index > list->size || index < 0) {
+		return -1;
+	}
+	arrayList_ensureCapacity(list, list->size+1);
+	unsigned int numMoved = list->size - index;
+	memmove(list->elementData+(index+1), list->elementData+index, sizeof(void *) * numMoved);
+
+	list->elementData[index] = element;
+	list->size++;
+}
+
+void * arrayList_remove(ARRAY_LIST list, unsigned int index) {
+	if (index >= list->size) {
+		return NULL;
+	}
+
+	list->modCount++;
+	void * oldElement = list->elementData[index];
+	unsigned int numMoved = list->size - index - 1;
+	memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+	list->elementData[--list->size] = NULL;
+
+	return oldElement;
+}
+
+void arrayList_fastRemove(ARRAY_LIST list, unsigned int index) {
+	list->modCount++;
+
+	unsigned int numMoved = list->size - index - 1;
+	memmove(list->elementData+index, list->elementData+index+1, sizeof(void *) * numMoved);
+	list->elementData[--list->size] = NULL;
+}
+
+bool arrayList_removeElement(ARRAY_LIST list, void * element) {
+	if (element == NULL) {
+		int i = 0;
+		for (i = 0; i < list->size; i++) {
+			if (list->elementData[i] == NULL) {
+				arrayList_fastRemove(list, i);
+				return true;
+			}
+		}
+	} else {
+		int i = 0;
+		for (i = 0; i < list->size; i++) {
+			if (list->elementData[i] == element) { //equalsFunction?
+				arrayList_fastRemove(list, i);
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
+void arrayList_clear(ARRAY_LIST list) {
+	list->modCount++;
+
+	int i;
+	for (i = 0; i < list->size; i++) {
+		// free(list->elementData[i]);
+		list->elementData[i] = NULL;
+	}
+	list->size = 0;
+}
+
+ARRAY_LIST arrayList_clone(ARRAY_LIST list) {
+	ARRAY_LIST new = arrayList_create();
+//	arrayList_ensureCapacity(new, list->size);
+//	memcpy(new->elementData, list->elementData, list->size);
+//	new->size = list->size;
+	int i;
+	for (i = 0; i < arrayList_size(list); i++) {
+		arrayList_add(new, arrayList_get(list, i));
+	}
+	new->modCount = 0;
+	return new;
+}
+
+ARRAY_LIST_ITERATOR arrayListIterator_create(ARRAY_LIST list) {
+	ARRAY_LIST_ITERATOR iterator = (ARRAY_LIST_ITERATOR) malloc(sizeof(*iterator));
+
+	iterator->lastReturned = -1;
+	iterator->cursor = 0;
+	iterator->list = list;
+	iterator->expectedModificationCount = list->modCount;
+
+	return iterator;
+}
+
+bool arrayListIterator_hasNext(ARRAY_LIST_ITERATOR iterator) {
+	return iterator->cursor != iterator->list->size;
+}
+
+void * arrayListIterator_next(ARRAY_LIST_ITERATOR iterator) {
+	if (iterator->expectedModificationCount != iterator->list->modCount) {
+		return NULL;
+	}
+	void * next = arrayList_get(iterator->list, iterator->cursor);
+	iterator->lastReturned = iterator->cursor++;
+	return next;
+}
+
+bool arrayListIterator_hasPrevious(ARRAY_LIST_ITERATOR iterator) {
+	return iterator->cursor != 0;
+}
+
+void * arrayListIterator_previous(ARRAY_LIST_ITERATOR iterator) {
+	if (iterator->expectedModificationCount != iterator->list->modCount) {
+		return NULL;
+	}
+	int i = iterator->cursor - 1;
+	void * previous = arrayList_get(iterator->list, i);
+	iterator->lastReturned = iterator->cursor = i;
+	return previous;
+}
+
+void arrayListIterator_remove(ARRAY_LIST_ITERATOR iterator) {
+	if (iterator->lastReturned == -1) {
+		return;
+	}
+	if (iterator->expectedModificationCount != iterator->list->modCount) {
+		return;
+	}
+	if (arrayList_remove(iterator->list, iterator->lastReturned) != NULL) {
+		if (iterator->lastReturned < iterator->cursor) {
+			iterator->cursor--;
+		}
+		iterator->lastReturned = -1;
+		iterator->expectedModificationCount = iterator->list->modCount;
+	}
+}
+
+
+
+

Added: incubator/celix/trunk/celix/array_list.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/array_list.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/array_list.h (added)
+++ incubator/celix/trunk/celix/array_list.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,41 @@
+/*
+ * array_list.h
+ *
+ *  Created on: Aug 4, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef ARRAY_LIST_H_
+#define ARRAY_LIST_H_
+
+#include <stdbool.h>
+
+typedef struct arrayList * ARRAY_LIST;
+
+typedef struct arrayListIterator * ARRAY_LIST_ITERATOR;
+
+ARRAY_LIST arrayList_create(void);
+void arrayList_trimToSize(ARRAY_LIST list);
+void arrayList_ensureCapacity(ARRAY_LIST list, int capacity);
+unsigned int arrayList_size(ARRAY_LIST list);
+bool arrayList_isEmpty(ARRAY_LIST list);
+bool arrayList_contains(ARRAY_LIST list, void * element);
+int arrayList_indexOf(ARRAY_LIST list, void * element);
+int arrayList_lastIndexOf(ARRAY_LIST list, void * element);
+void * arrayList_get(ARRAY_LIST list, unsigned int index);
+void * arrayList_set(ARRAY_LIST list, unsigned int index, void * element);
+bool arrayList_add(ARRAY_LIST list, void * element);
+int arrayList_addIndex(ARRAY_LIST list, unsigned int index, void * element);
+void * arrayList_remove(ARRAY_LIST list, unsigned int index);
+bool arrayList_removeElement(ARRAY_LIST list, void * element);
+void arrayList_clear(ARRAY_LIST list);
+ARRAY_LIST arrayList_clone(ARRAY_LIST list);
+
+ARRAY_LIST_ITERATOR arrayListIterator_create(ARRAY_LIST list);
+bool arrayListIterator_hasNext(ARRAY_LIST_ITERATOR iterator);
+void * arrayListIterator_next(ARRAY_LIST_ITERATOR iterator);
+bool arrayListIterator_hasPrevious(ARRAY_LIST_ITERATOR iterator);
+void * arrayListIterator_previous(ARRAY_LIST_ITERATOR iterator);
+void arrayListIterator_remove(ARRAY_LIST_ITERATOR iterator);
+
+#endif /* ARRAY_LIST_H_ */

Added: incubator/celix/trunk/celix/array_list_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/array_list_private.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/array_list_private.h (added)
+++ incubator/celix/trunk/celix/array_list_private.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,31 @@
+/*
+ * array_list_private.h
+ *
+ *  Created on: Aug 4, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef ARRAY_LIST_PRIVATE_H_
+#define ARRAY_LIST_PRIVATE_H_
+
+#include "array_list.h"
+
+struct arrayList {
+	void ** elementData;
+	unsigned int size;
+	unsigned int capacity;
+
+	unsigned int modCount;
+};
+
+struct arrayListIterator {
+	ARRAY_LIST list;
+	unsigned int cursor;
+	int lastReturned;
+	unsigned int expectedModificationCount;
+};
+
+void * arrayList_remove(ARRAY_LIST list, unsigned int index);
+
+
+#endif /* ARRAY_LIST_PRIVATE_H_ */

Added: incubator/celix/trunk/celix/attribute.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/attribute.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/attribute.c (added)
+++ incubator/celix/trunk/celix/attribute.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,16 @@
+/*
+ * attribute.c
+ *
+ *  Created on: Jul 27, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "attribute.h"
+
+ATTRIBUTE attribute_create(char * key, char * value) {
+	ATTRIBUTE attribute = malloc(sizeof(*attribute));
+	attribute->key = key;
+	attribute->value = value;
+	return attribute;
+}

Added: incubator/celix/trunk/celix/attribute.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/attribute.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/attribute.h (added)
+++ incubator/celix/trunk/celix/attribute.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,21 @@
+/*
+ * attribute.h
+ *
+ *  Created on: Jul 27, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef ATTRIBUTE_H_
+#define ATTRIBUTE_H_
+
+struct attribute {
+	char * key;
+	char * value;
+};
+
+typedef struct attribute * ATTRIBUTE;
+
+ATTRIBUTE attribute_create(char * key, char * value);
+
+
+#endif /* ATTRIBUTE_H_ */

Added: incubator/celix/trunk/celix/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle.c (added)
+++ incubator/celix/trunk/celix/bundle.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,213 @@
+/*
+ * bundle.c
+ *
+ *  Created on: Mar 23, 2010
+ *      Author: alexanderb
+ */
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "bundle.h"
+#include "framework.h"
+#include "manifest.h"
+#include "module.h"
+#include "version.h"
+#include "array_list.h"
+#include "bundle_archive.h"
+
+struct bundle {
+	BUNDLE_CONTEXT context;
+	ACTIVATOR activator;
+	long lastModified;
+	BUNDLE_STATE state;
+	void * handle;
+	BUNDLE_ARCHIVE archive;
+	MODULE module;
+
+	pthread_mutex_t lock;
+	int lockCount;
+	pthread_t lockThread;
+
+	struct framework * framework;
+};
+
+MODULE bundle_createModule(BUNDLE bundle);
+
+BUNDLE bundle_create() {
+	BUNDLE bundle = (BUNDLE) malloc(sizeof(*bundle));
+	BUNDLE_ARCHIVE archive = bundleArchive_createSystemBundleArchive();
+	bundle->archive = archive;
+	bundle->activator = NULL;
+	bundle->context = NULL;
+	bundle->framework = NULL;
+	bundle->state = BUNDLE_INSTALLED;
+
+
+	MODULE module = module_createFrameworkModule();
+
+	bundle->module = module;
+
+	pthread_mutex_init(&bundle->lock, NULL);
+	bundle->lockCount = 0;
+	bundle->lockThread = NULL;
+
+	resolver_addModule(module);
+
+	return bundle;
+}
+
+BUNDLE bundle_createFromArchive(FRAMEWORK framework, BUNDLE_ARCHIVE archive) {
+	BUNDLE bundle = malloc(sizeof(*bundle));
+	bundle->archive = archive;
+	bundle->activator = NULL;
+	bundle->context = NULL;
+	bundle->framework = framework;
+	bundle->state = BUNDLE_INSTALLED;
+
+	MODULE module = bundle_createModule(bundle);
+	bundle->module = module;
+
+	pthread_mutex_init(&bundle->lock, NULL);
+	bundle->lockCount = 0;
+	bundle->lockThread = NULL;
+
+	resolver_addModule(module);
+
+	return bundle;
+}
+
+BUNDLE_ARCHIVE bundle_getArchive(BUNDLE bundle) {
+	return bundle->archive;
+}
+
+MODULE bundle_getModule(BUNDLE bundle) {
+	return bundle->module;
+}
+
+void * bundle_getHandle(BUNDLE bundle) {
+	return bundle->handle;
+}
+
+void bundle_setHandle(BUNDLE bundle, void * handle) {
+	bundle->handle = handle;
+}
+
+ACTIVATOR bundle_getActivator(BUNDLE bundle) {
+	return bundle->activator;
+}
+
+void bundle_setActivator(BUNDLE bundle, ACTIVATOR activator) {
+	bundle->activator = activator;
+}
+
+BUNDLE_CONTEXT bundle_getContext(BUNDLE bundle) {
+	return bundle->context;
+}
+
+void bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context) {
+	bundle->context = context;
+}
+
+BUNDLE_STATE bundle_getState(BUNDLE bundle) {
+	return bundle->state;
+}
+
+void bundle_setState(BUNDLE bundle, BUNDLE_STATE state) {
+	bundle->state = state;
+}
+
+MODULE bundle_createModule(BUNDLE bundle) {
+	MANIFEST headerMap = getManifest(bundle->archive);
+	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, strdup(moduleId), bundle);
+
+
+	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(check->module);
+			VERSION version = module_getVersion(check->module);
+			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;
+			}
+		}
+	}
+
+	return module;
+}
+
+void startBundle(BUNDLE bundle, int options) {
+	fw_startBundle(bundle->framework, bundle, options);
+
+}
+
+void stopBundle(BUNDLE bundle, int options) {
+	fw_stopBundle(bundle->framework, bundle, options);
+}
+
+
+
+bool bundle_isLockable(BUNDLE bundle) {
+	bool lockable = false;
+	pthread_mutex_lock(&bundle->lock);
+
+	lockable = (bundle->lockCount == 0) || (bundle->lockThread == pthread_self());
+
+	pthread_mutex_unlock(&bundle->lock);
+
+	return lockable;
+}
+
+pthread_t bundle_getLockingThread(BUNDLE bundle) {
+	pthread_t lockingThread = NULL;
+	pthread_mutex_lock(&bundle->lock);
+
+	lockingThread = bundle->lockThread;
+
+	pthread_mutex_unlock(&bundle->lock);
+}
+
+bool bundle_lock(BUNDLE bundle) {
+	pthread_mutex_lock(&bundle->lock);
+
+	if ((bundle->lockCount > 0) && bundle->lockThread != pthread_self()) {
+		return false;
+	}
+	bundle->lockCount++;
+	bundle->lockThread = pthread_self();
+
+	pthread_mutex_unlock(&bundle->lock);
+	return true;
+}
+
+bool bundle_unlock(BUNDLE bundle) {
+	pthread_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;
+	}
+
+	pthread_mutex_unlock(&bundle->lock);
+	return true;
+}

Added: incubator/celix/trunk/celix/bundle.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle.h (added)
+++ incubator/celix/trunk/celix/bundle.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,47 @@
+/*
+ * bundle.h
+ *
+ *  Created on: Mar 23, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_H_
+#define BUNDLE_H_
+
+#include "headers.h"
+
+BUNDLE bundle_create();
+
+BUNDLE bundle_createFromArchive(FRAMEWORK framework, BUNDLE_ARCHIVE archive);
+
+BUNDLE_ARCHIVE bundle_getArchive(BUNDLE bundle);
+MODULE bundle_getModule(BUNDLE bundle);
+void * bundle_getHandle(BUNDLE bundle);
+void bundle_setHandle(BUNDLE bundle, void * handle);
+ACTIVATOR bundle_getActivator(BUNDLE bundle);
+void bundle_setActivator(BUNDLE bundle, ACTIVATOR activator);
+BUNDLE_CONTEXT bundle_getContext(BUNDLE bundle);
+void bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context);
+
+void startBundle(BUNDLE bundle, int options);
+
+void stopBundle(BUNDLE bundle, int options);
+
+//void updateBundle(BUNDLE bundle, InputStream input);
+
+void uninstallBundle(BUNDLE bundle);
+
+// Service Reference Functions
+ARRAY_LIST getUsingBundles(SERVICE_REFERENCE reference);
+
+int compareTo(SERVICE_REFERENCE a, SERVICE_REFERENCE b);
+
+
+BUNDLE_STATE bundle_getState(BUNDLE bundle);
+bool bundle_isLockable(BUNDLE bundle);
+pthread_t bundle_getLockingThread(BUNDLE bundle);
+bool bundle_lock(BUNDLE bundle);
+bool bundle_unlock(BUNDLE bundle);
+
+
+#endif /* BUNDLE_H_ */

Added: incubator/celix/trunk/celix/bundle_activator.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_activator.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_activator.h (added)
+++ incubator/celix/trunk/celix/bundle_activator.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,18 @@
+/*
+ * activator.h
+ *
+ *  Created on: Mar 18, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_ACTIVATOR_H_
+#define BUNDLE_ACTIVATOR_H_
+
+#include "headers.h"
+
+void * bundleActivator_create();
+void bundleActivator_start(void * userData, BUNDLE_CONTEXT context);
+void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context);
+void bundleActivator_destroy(void * userData);
+
+#endif /* BUNDLE_ACTIVATOR_H_ */

Added: incubator/celix/trunk/celix/bundle_archive.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_archive.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_archive.c (added)
+++ incubator/celix/trunk/celix/bundle_archive.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,253 @@
+/*
+ * bundle_archive.c
+ *
+ *  Created on: Aug 8, 2010
+ *      Author: alexanderb
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "bundle_archive.h"
+#include "headers.h"
+
+struct bundleArchive {
+	long id;
+	char * location;
+	DIR * archiveRootDir;
+	char * archiveRoot;
+	char * revision;
+
+	BUNDLE_STATE persistentState;
+};
+
+BUNDLE_ARCHIVE bundleArchive_createSystemBundleArchive() {
+	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
+	archive->id = 0l;
+	archive->location = "System Bundle";
+	return archive;
+}
+
+char * bundleArchive_getRevisionLocation(BUNDLE_ARCHIVE archive /*, int revision */);
+void bundleArchive_setRevisionLocation(BUNDLE_ARCHIVE archive, char * location/*, int revision */);
+
+void bundleArchive_initialize(BUNDLE_ARCHIVE archive);
+
+void bundleArchive_deleteTree(char * directory);
+
+BUNDLE_ARCHIVE bundleArchive_create(char * archiveRoot, long id, char * location) {
+	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
+
+	archive->id = id;
+	archive->location = location;
+	archive->archiveRootDir = NULL;
+	archive->archiveRoot = archiveRoot;
+
+	bundleArchive_initialize(archive);
+
+	bundleArchive_revise(archive, location);
+
+	return archive;
+}
+
+BUNDLE_ARCHIVE bundleArchive_recreate(char * archiveRoot) {
+	BUNDLE_ARCHIVE archive = (BUNDLE_ARCHIVE) malloc(sizeof(*archive));
+	archive->archiveRoot = archiveRoot;
+	archive->archiveRootDir = opendir(archiveRoot);
+	archive->id = -1;
+	archive->persistentState = -1;
+	archive->location = NULL;
+
+	char * location = bundleArchive_getRevisionLocation(archive);
+	bundleArchive_revise(archive, location);
+
+	return archive;
+}
+
+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");
+	FILE * bundleIdFile = fopen(bundleId, "r");
+	char id[256];
+	fgets (id , sizeof(id) , bundleIdFile);
+	fclose(bundleIdFile);
+
+	return atol(id);
+}
+
+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");
+	FILE * bundleLocationFile = fopen(bundleLocation, "r");
+
+	char location[256];
+	fgets (location , sizeof(location) , bundleLocationFile);
+	fclose(bundleLocationFile);
+
+	return strdup(location);
+}
+
+char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive) {
+	return archive->archiveRoot;
+}
+
+char * bundleArchive_getRevision(BUNDLE_ARCHIVE archive) {
+	return archive->revision;
+}
+
+BUNDLE_STATE bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive) {
+	if (archive->persistentState >= 0) {
+		return archive->persistentState;
+	}
+
+	char persistentStateLocation[strlen(archive->archiveRoot) + 14];
+	strcpy(persistentStateLocation, archive->archiveRoot);
+	strcat(persistentStateLocation, "/bundle.state");
+	FILE * persistentStateLocationFile = fopen(persistentStateLocation, "r");
+	char state[256];
+	fgets (state , sizeof(state) , persistentStateLocationFile);
+	fclose(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;
+	} else {
+		archive->persistentState = BUNDLE_INSTALLED;
+	}
+
+	return archive->persistentState;
+}
+
+void bundleArchive_setPersistentState(BUNDLE_ARCHIVE archive, BUNDLE_STATE state) {
+	char persistentStateLocation[strlen(archive->archiveRoot) + 14];
+	strcpy(persistentStateLocation, archive->archiveRoot);
+	strcat(persistentStateLocation, "/bundle.state");
+	FILE * persistentStateLocationFile = fopen(persistentStateLocation, "w");
+	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;
+	}
+	fprintf(persistentStateLocationFile, "%s", s);
+	fclose(persistentStateLocationFile);
+
+	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");
+
+	FILE * revisionLocationFile = fopen(revisionLocation, "r");
+	char location[256];
+	fgets (location , sizeof(location) , revisionLocationFile);
+	fclose(revisionLocationFile);
+
+	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");
+
+	FILE * revisionLocationFile = fopen(revisionLocation, "w");
+	fprintf(revisionLocationFile, "%s", location);
+	fclose(revisionLocationFile);
+}
+
+void bundleArchive_close(BUNDLE_ARCHIVE archive) {
+	// close revision
+	// not yet needed/possible
+}
+
+void bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive) {
+	bundleArchive_close(archive);
+	bundleArchive_deleteTree(archive->archiveRoot);
+}
+
+void bundleArchive_initialize(BUNDLE_ARCHIVE archive) {
+	if (archive->archiveRootDir != NULL) {
+		return;
+	}
+
+	mkdir(archive->archiveRoot, 0755);
+	archive->archiveRootDir = opendir(archive->archiveRoot);
+
+	char bundleId[strlen(archive->archiveRoot) + 10];
+	strcpy(bundleId, archive->archiveRoot);
+	strcat(bundleId, "/bundle.id");
+	FILE * bundleIdFile = fopen(bundleId, "w");
+	fprintf(bundleIdFile, "%ld", archive->id);
+	fclose(bundleIdFile);
+
+	char bundleLocation[strlen(archive->archiveRoot) + 16];
+	strcpy(bundleLocation,archive->archiveRoot);
+	strcat(bundleLocation, "/bundle.location");
+	FILE * bundleLocationFile = fopen(bundleLocation, "w");
+	fprintf(bundleLocationFile, "%s", archive->location);
+	fclose(bundleLocationFile);
+}
+
+void bundleArchive_deleteTree(char * directory) {
+	DIR * dir = opendir(directory);
+	struct dirent * dp;
+	while ((dp = readdir(dir))) {
+		if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) {
+			char subdir[strlen(directory) + strlen(dp->d_name) + 2];
+			strcpy(subdir, directory);
+			strcat(subdir, "/");
+			strcat(subdir, dp->d_name);
+
+			struct stat s;
+			stat(dp->d_name, &s);
+			if (S_ISDIR(s.st_mode)) {
+//			if (dp->d_type == DT_DIR) {
+				bundleCache_deleteTree(subdir);
+			} else {
+				remove(subdir);
+			}
+		}
+	}
+	remove(directory);
+}

Added: incubator/celix/trunk/celix/bundle_archive.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_archive.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_archive.h (added)
+++ incubator/celix/trunk/celix/bundle_archive.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,27 @@
+/*
+ * bundle_archive.h
+ *
+ *  Created on: Aug 8, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_ARCHIVE_H_
+#define BUNDLE_ARCHIVE_H_
+
+#include "bundle_state.h"
+
+typedef struct bundleArchive * BUNDLE_ARCHIVE;
+
+BUNDLE_ARCHIVE bundleArchive_create(char * archiveRoot, long id, char * location);
+BUNDLE_ARCHIVE bundleArchive_createSystemBundleArchive();
+BUNDLE_ARCHIVE bundleArchive_recreate(char * archiveRoot);
+long bundleArchive_getId(BUNDLE_ARCHIVE archive);
+char * bundleArchive_getLocation(BUNDLE_ARCHIVE archive);
+char * bundleArchive_getArchiveRoot(BUNDLE_ARCHIVE archive);
+char * bundleArchive_getRevision(BUNDLE_ARCHIVE archive);
+BUNDLE_STATE bundleArchive_getPersistentState(BUNDLE_ARCHIVE archive);
+void bundleArchive_revise(BUNDLE_ARCHIVE archive, char * location);
+void bundleArchive_close(BUNDLE_ARCHIVE archive);
+void bundleArchive_closeAndDelete(BUNDLE_ARCHIVE archive);
+
+#endif /* BUNDLE_ARCHIVE_H_ */

Added: incubator/celix/trunk/celix/bundle_cache.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_cache.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_cache.c (added)
+++ incubator/celix/trunk/celix/bundle_cache.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,106 @@
+/*
+ * bundle_cache.c
+ *
+ *  Created on: Aug 6, 2010
+ *      Author: alexanderb
+ */
+#include <dirent.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "bundle_cache.h"
+#include "bundle_archive.h"
+#include "headers.h"
+#include "constants.h"
+
+struct bundleCache {
+	PROPERTIES configurationMap;
+	char * cacheDir;
+};
+
+void bundleCache_deleteTree(char * directory);
+
+BUNDLE_CACHE bundleCache_create(PROPERTIES configurationMap) {
+	BUNDLE_CACHE cache = (BUNDLE_CACHE) malloc(sizeof(*cache));
+
+	cache->configurationMap = configurationMap;
+	char * cacheDir = getProperty(configurationMap, (char *) FRAMEWORK_STORAGE);
+	if (cacheDir == NULL) {
+		cacheDir = ".cache";
+	}
+	cache->cacheDir = cacheDir;
+
+	return cache;
+}
+
+void bundleCache_delete(BUNDLE_CACHE cache) {
+	bundleCache_deleteTree(cache->cacheDir);
+}
+
+void bundleCache_deleteTree(char * directory) {
+	DIR * dir = opendir(directory);
+	struct dirent * dp;
+	while ((dp = readdir(dir))) {
+		if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) {
+			char subdir[strlen(directory) + strlen(dp->d_name) + 2];
+			strcpy(subdir, directory);
+			strcat(subdir, "/");
+			strcat(subdir, dp->d_name);
+
+			struct stat s;
+			stat(dp->d_name, &s);
+			if (S_ISDIR(s.st_mode)) {
+//			if (dp->d_type == DT_DIR) {
+				bundleCache_deleteTree(subdir);
+			} else {
+				remove(subdir);
+			}
+		}
+	}
+	remove(directory);
+}
+
+ARRAY_LIST bundleCache_getArchives(BUNDLE_CACHE cache) {
+	DIR * dir = opendir(cache->cacheDir);
+	if (dir == NULL) {
+		mkdir(cache->cacheDir, 0755);
+		dir = opendir(cache->cacheDir);
+		if (dir == NULL) {
+			printf("Problem opening/creating cache.\n");
+			return NULL;
+		}
+	}
+
+	ARRAY_LIST list = arrayList_create();
+	struct dirent * dp;
+	while ((dp = readdir(dir))) {
+		char archiveRoot[strlen(cache->cacheDir) + strlen(dp->d_name) + 2];
+		strcpy(archiveRoot, cache->cacheDir);
+		strcat(archiveRoot, "/");
+		strcat(archiveRoot, dp->d_name);
+
+		struct stat s;
+		stat(archiveRoot, &s);
+		if (S_ISDIR(s.st_mode)
+//		if (dp->d_type == DT_DIR
+				&& (strcmp((dp->d_name), ".") != 0)
+				&& (strcmp((dp->d_name), "..") != 0)
+				&& (strncmp(dp->d_name, "bundle", 6) == 0)
+				&& (strcmp(dp->d_name, "bundle0") != 0)) {
+
+			BUNDLE_ARCHIVE archive = bundleArchive_recreate(strdup(archiveRoot));
+			arrayList_add(list, archive);
+		}
+	}
+
+	return list;
+}
+
+BUNDLE_ARCHIVE bundleCache_createArchive(BUNDLE_CACHE cache, long id, char * location) {
+	char archiveRoot[256];
+	sprintf(archiveRoot, "%s/bundle%ld",  cache->cacheDir, id);
+
+	return bundleArchive_create(strdup(archiveRoot), id, location);
+}

Added: incubator/celix/trunk/celix/bundle_cache.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_cache.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_cache.h (added)
+++ incubator/celix/trunk/celix/bundle_cache.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,23 @@
+/*
+ * bundle_cache.h
+ *
+ *  Created on: Aug 8, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_CACHE_H_
+#define BUNDLE_CACHE_H_
+
+#include "properties.h"
+#include "array_list.h"
+#include "bundle_archive.h"
+
+typedef struct bundleCache * BUNDLE_CACHE;
+
+BUNDLE_CACHE bundleCache_create(PROPERTIES configurationMap);
+ARRAY_LIST bundleCache_getArchives(BUNDLE_CACHE cache);
+BUNDLE_ARCHIVE bundleCache_createArchive(BUNDLE_CACHE cache, long id, char * location);
+void bundleCache_delete(BUNDLE_CACHE cache);
+
+
+#endif /* BUNDLE_CACHE_H_ */

Added: incubator/celix/trunk/celix/bundle_context.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_context.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_context.c (added)
+++ incubator/celix/trunk/celix/bundle_context.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,72 @@
+/*
+ * bundle_context.c
+ *
+ *Some change to test hudson
+ *
+ *  Created on: Mar 26, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "bundle_context.h"
+#include "framework.h"
+
+struct bundleContext {
+	struct framework * framework;
+	struct bundle * bundle;
+};
+
+BUNDLE_CONTEXT bundleContext_create(FRAMEWORK framework, BUNDLE bundle) {
+	BUNDLE_CONTEXT context = malloc(sizeof(*context));
+	context->framework = framework;
+	context->bundle = bundle;
+	return context;
+}
+
+FRAMEWORK bundleContext_getFramework(BUNDLE_CONTEXT context) {
+	return context->framework;
+}
+
+BUNDLE bundleContext_installBundle(BUNDLE_CONTEXT context, char * location) {
+	return fw_installBundle(context->framework, location);
+}
+
+SERVICE_REGISTRATION bundleContext_registerService(BUNDLE_CONTEXT context, char * serviceName, void * svcObj, HASHTABLE properties) {
+	return fw_registerService(context->framework, context->bundle, serviceName, svcObj, properties);
+}
+
+ARRAY_LIST getServiceReferences(BUNDLE_CONTEXT context, char * serviceName, char * filter) {
+	return fw_getServiceReferences(context->framework, context->bundle, serviceName, filter);
+}
+
+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;
+}
+
+void * bundleContext_getService(BUNDLE_CONTEXT context, SERVICE_REFERENCE reference) {
+	return fw_getService(context->framework, context->bundle, reference);
+}
+
+bool bundleContext_ungetService(BUNDLE_CONTEXT context, SERVICE_REFERENCE reference) {
+	return framework_ungetService(context->framework, context->bundle, reference);
+}
+
+ARRAY_LIST bundleContext_getBundles(BUNDLE_CONTEXT context) {
+	return framework_getBundles(context->framework);
+}
+
+BUNDLE bundleContext_getBundleById(BUNDLE_CONTEXT context, long id) {
+	return framework_getBundleById(context->framework, id);
+}
+
+void addServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener, char * filter) {
+	fw_addServiceListener(context->bundle, listener, filter);
+}
+
+void removeServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener) {
+	fw_removeServiceListener(context->bundle, listener);
+}

Added: incubator/celix/trunk/celix/bundle_context.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_context.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_context.h (added)
+++ incubator/celix/trunk/celix/bundle_context.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,34 @@
+/*
+ * bundle_context.h
+ *
+ *  Created on: Mar 26, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_CONTEXT_H_
+#define BUNDLE_CONTEXT_H_
+
+#include "headers.h"
+
+BUNDLE_CONTEXT bundleContext_create(FRAMEWORK framework, BUNDLE bundle);
+
+FRAMEWORK bundleContext_getFramework(BUNDLE_CONTEXT context);
+
+BUNDLE bundleContext_installBundle(BUNDLE_CONTEXT context, char * location);
+
+SERVICE_REGISTRATION bundleContext_registerService(BUNDLE_CONTEXT context, char * serviceName, void * svcObj, HASHTABLE properties);
+
+ARRAY_LIST getServiceReferences(BUNDLE_CONTEXT context, char * serviceName, char * filter);
+SERVICE_REFERENCE bundleContext_getServiceReference(BUNDLE_CONTEXT context, char * serviceName);
+
+void * bundleContext_getService(BUNDLE_CONTEXT context, SERVICE_REFERENCE reference);
+bool bundleContext_ungetService(BUNDLE_CONTEXT context, SERVICE_REFERENCE reference);
+
+ARRAY_LIST bundleContext_getBundles(BUNDLE_CONTEXT context);
+BUNDLE bundleContext_getBundleById(BUNDLE_CONTEXT context, long id);
+
+void addServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener, char * filter);
+void removeServiceListener(BUNDLE_CONTEXT context, SERVICE_LISTENER listener);
+
+
+#endif /* BUNDLE_CONTEXT_H_ */

Added: incubator/celix/trunk/celix/bundle_state.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/bundle_state.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/bundle_state.h (added)
+++ incubator/celix/trunk/celix/bundle_state.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,23 @@
+/*
+ * bundle_state.h
+ *
+ *  Created on: Sep 27, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef BUNDLE_STATE_H_
+#define BUNDLE_STATE_H_
+
+enum bundleState
+{
+	BUNDLE_UNINSTALLED = 0x00000001,
+	BUNDLE_INSTALLED = 0x00000002,
+	BUNDLE_RESOLVED = 0x00000004,
+	BUNDLE_STARTING = 0x00000008,
+	BUNDLE_STOPPING = 0x00000010,
+	BUNDLE_ACTIVE = 0x00000020,
+};
+
+typedef enum bundleState BUNDLE_STATE;
+
+#endif /* BUNDLE_STATE_H_ */

Added: incubator/celix/trunk/celix/capability.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/capability.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/capability.c (added)
+++ incubator/celix/trunk/celix/capability.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,48 @@
+/*
+ * capability.c
+ *
+ *  Created on: Jul 12, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "capability.h"
+#include "attribute.h"
+
+struct capability {
+	char * serviceName;
+	MODULE module;
+	VERSION version;
+	HASH_MAP attributes;
+	HASH_MAP directives;
+};
+
+CAPABILITY capability_create(MODULE module, HASH_MAP directives, HASH_MAP attributes) {
+	CAPABILITY capability = (CAPABILITY) malloc(sizeof(*capability));
+
+	capability->module = module;
+	capability->attributes = attributes;
+	capability->directives = directives;
+
+	capability->version = version_createEmptyVersion();
+	ATTRIBUTE versionAttribute = (ATTRIBUTE) hashMap_get(attributes, "version");
+	if (versionAttribute != NULL) {
+		capability->version = version_createVersionFromString(versionAttribute->value);
+	}
+	ATTRIBUTE serviceAttribute = (ATTRIBUTE) hashMap_get(attributes, "service");
+	capability->serviceName = serviceAttribute->value;
+
+	return capability;
+}
+
+char * capability_getServiceName(CAPABILITY capability) {
+	return capability->serviceName;
+}
+
+VERSION capability_getVersion(CAPABILITY capability) {
+	return capability->version;
+}
+
+MODULE capability_getModule(CAPABILITY capability) {
+	return capability->module;
+}

Added: incubator/celix/trunk/celix/capability.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/capability.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/capability.h (added)
+++ incubator/celix/trunk/celix/capability.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,20 @@
+/*
+ * capability.h
+ *
+ *  Created on: Jul 12, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef CAPABILITY_H_
+#define CAPABILITY_H_
+
+#include "hash_map.h"
+#include "module.h"
+
+
+CAPABILITY capability_create(MODULE module, HASH_MAP directives, HASH_MAP attributes);
+char * capability_getServiceName(CAPABILITY capability);
+VERSION capability_getVersion(CAPABILITY capability);
+MODULE capability_getModule(CAPABILITY capability);
+
+#endif /* CAPABILITY_H_ */

Added: incubator/celix/trunk/celix/cexcept.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/cexcept.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/cexcept.h (added)
+++ incubator/celix/trunk/celix/cexcept.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,248 @@
+/*===
+cexcept.h 2.0.1 (2008-Jul-19-Sat)
+http://www.nicemice.net/cexcept/
+Adam M. Costello
+http://www.nicemice.net/amc/
+
+An interface for exception-handling in ANSI C (C89 and subsequent ISO
+standards), developed jointly with Cosmin Truta.
+
+    Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
+    This software may be modified only if its author and version
+    information is updated accurately, and may be redistributed
+    only if accompanied by this unaltered notice.  Subject to those
+    restrictions, permission is granted to anyone to do anything
+    with this software.  The copyright holders make no guarantees
+    regarding this software, and are not responsible for any damage
+    resulting from its use.
+
+The cexcept interface is not compatible with and cannot interact
+with system exceptions (like division by zero or memory segmentation
+violation), compiler-generated exceptions (like C++ exceptions), or
+other exception-handling interfaces.
+
+When using this interface across multiple .c files, do not include
+this header file directly.  Instead, create a wrapper header file that
+includes this header file and then invokes the define_exception_type
+macro (see below).  The .c files should then include that header file.
+
+The interface consists of one type, one well-known name, and six macros.
+
+
+define_exception_type(type_name);
+
+    This macro is used like an external declaration.  It specifies
+    the type of object that gets copied from the exception thrower to
+    the exception catcher.  The type_name can be any type that can be
+    assigned to, that is, a non-constant arithmetic type, struct, union,
+    or pointer.  Examples:
+
+        define_exception_type(int);
+
+        enum exception { out_of_memory, bad_arguments, disk_full };
+        define_exception_type(enum exception);
+
+        struct exception { int code; const char *msg; };
+        define_exception_type(struct exception);
+
+    Because throwing an exception causes the object to be copied (not
+    just once, but twice), programmers may wish to consider size when
+    choosing the exception type.
+
+
+struct exception_context;
+
+    This type may be used after the define_exception_type() macro has
+    been invoked.  A struct exception_context must be known to both
+    the thrower and the catcher.  It is expected that there be one
+    context for each thread that uses exceptions.  It would certainly
+    be dangerous for multiple threads to access the same context.
+    One thread can use multiple contexts, but that is likely to be
+    confusing and not typically useful.  The application can allocate
+    this structure in any way it pleases--automatic, static, or dynamic.
+    The application programmer should pretend not to know the structure
+    members, which are subject to change.
+
+
+struct exception_context *the_exception_context;
+
+    The Try/Catch and Throw statements (described below) implicitly
+    refer to a context, using the name the_exception_context.  It is
+    the application's responsibility to make sure that this name yields
+    the address of a mutable (non-constant) struct exception_context
+    wherever those statements are used.  Subject to that constraint, the
+    application may declare a variable of this name anywhere it likes
+    (inside a function, in a parameter list, or externally), and may
+    use whatever storage class specifiers (static, extern, etc) or type
+    qualifiers (const, volatile, etc) it likes.  Examples:
+
+        static struct exception_context
+          * const the_exception_context = &foo;
+
+        { struct exception_context *the_exception_context = bar; ... }
+
+        int blah(struct exception_context *the_exception_context, ...);
+
+        extern struct exception_context the_exception_context[1];
+
+    The last example illustrates a trick that avoids creating a pointer
+    object separate from the structure object.
+
+    The name could even be a macro, for example:
+
+        struct exception_context ec_array[numthreads];
+        #define the_exception_context (ec_array + thread_id)
+
+    Be aware that the_exception_context is used several times by the
+    Try/Catch/Throw macros, so it shouldn't be expensive or have side
+    effects.  The expansion must be a drop-in replacement for an
+    identifier, so it's safest to put parentheses around it.
+
+
+void init_exception_context(struct exception_context *ec);
+
+    For context structures allocated statically (by an external
+    definition or using the "static" keyword), the implicit
+    initialization to all zeros is sufficient, but contexts allocated
+    by other means must be initialized using this macro before they
+    are used by a Try/Catch statement.  It does no harm to initialize
+    a context more than once (by using this macro on a statically
+    allocated context, or using this macro twice on the same context),
+    but a context must not be re-initialized after it has been used by a
+    Try/Catch statement.
+
+
+Try statement
+Catch (expression) statement
+
+    The Try/Catch/Throw macros are capitalized in order to avoid
+    confusion with the C++ keywords, which have subtly different
+    semantics.
+
+    A Try/Catch statement has a syntax similar to an if/else statement,
+    except that the parenthesized expression goes after the second
+    keyword rather than the first.  As with if/else, there are two
+    clauses, each of which may be a simple statement ending with a
+    semicolon or a brace-enclosed compound statement.  But whereas
+    the else clause is optional, the Catch clause is required.  The
+    expression must be a modifiable lvalue (something capable of being
+    assigned to) of the same type (disregarding type qualifiers) that
+    was passed to define_exception_type().
+
+    If a Throw that uses the same exception context as the Try/Catch is
+    executed within the Try clause (typically within a function called
+    by the Try clause), and the exception is not caught by a nested
+    Try/Catch statement, then a copy of the exception will be assigned
+    to the expression, and control will jump to the Catch clause.  If no
+    such Throw is executed, then the assignment is not performed, and
+    the Catch clause is not executed.
+
+    The expression is not evaluated unless and until the exception is
+    caught, which is significant if it has side effects, for example:
+
+        Try foo();
+        Catch (p[++i].e) { ... }
+
+    IMPORTANT: Jumping into or out of a Try clause (for example via
+    return, break, continue, goto, longjmp) is forbidden--the compiler
+    will not complain, but bad things will happen at run-time.  Jumping
+    into or out of a Catch clause is okay, and so is jumping around
+    inside a Try clause.  In many cases where one is tempted to return
+    from a Try clause, it will suffice to use Throw, and then return
+    from the Catch clause.  Another option is to set a flag variable and
+    use goto to jump to the end of the Try clause, then check the flag
+    after the Try/Catch statement.
+
+    IMPORTANT: The values of any non-volatile automatic variables
+    changed within the Try clause are undefined after an exception is
+    caught.  Therefore, variables modified inside the Try block whose
+    values are needed later outside the Try block must either use static
+    storage or be declared with the "volatile" type qualifier.
+
+
+Throw expression;
+
+    A Throw statement is very much like a return statement, except that
+    the expression is required.  Whereas return jumps back to the place
+    where the current function was called, Throw jumps back to the Catch
+    clause of the innermost enclosing Try clause.  The expression must
+    be compatible with the type passed to define_exception_type().  The
+    exception must be caught, otherwise the program may crash.
+
+    Slight limitation:  If the expression is a comma-expression, it must
+    be enclosed in parentheses.
+
+
+Try statement
+Catch_anonymous statement
+
+    When the value of the exception is not needed, a Try/Catch statement
+    can use Catch_anonymous instead of Catch (expression).
+
+
+Everything below this point is for the benefit of the compiler.  The
+application programmer should pretend not to know any of it, because it
+is subject to change.
+
+===*/
+
+
+#ifndef CEXCEPT_H
+#define CEXCEPT_H
+
+
+#include <setjmp.h>
+
+#define define_exception_type(etype) \
+struct exception_context { \
+  jmp_buf *penv; \
+  int caught; \
+  volatile struct { etype etmp; } v; \
+}
+
+/* etmp must be volatile because the application might use automatic */
+/* storage for the_exception_context, and etmp is modified between   */
+/* the calls to setjmp() and longjmp().  A wrapper struct is used to */
+/* avoid warnings about a duplicate volatile qualifier in case etype */
+/* already includes it.                                              */
+
+#define init_exception_context(ec) ((void)((ec)->penv = 0))
+
+#define Try \
+  { \
+    jmp_buf *exception__prev, exception__env; \
+    exception__prev = the_exception_context->penv; \
+    the_exception_context->penv = &exception__env; \
+    if (setjmp(exception__env) == 0) { \
+      do
+
+#define exception__catch(action) \
+      while (the_exception_context->caught = 0, \
+             the_exception_context->caught); \
+    } \
+    else { \
+      the_exception_context->caught = 1; \
+    } \
+    the_exception_context->penv = exception__prev; \
+  } \
+  if (!the_exception_context->caught || action) { } \
+  else
+
+#define Catch(e) exception__catch(((e) = the_exception_context->v.etmp, 0))
+#define Catch_anonymous exception__catch(0)
+
+/* Try ends with do, and Catch begins with while(0) and ends with     */
+/* else, to ensure that Try/Catch syntax is similar to if/else        */
+/* syntax.                                                            */
+/*                                                                    */
+/* The 0 in while(0) is expressed as x=0,x in order to appease        */
+/* compilers that warn about constant expressions inside while().     */
+/* Most compilers should still recognize that the condition is always */
+/* false and avoid generating code for it.                            */
+
+#define Throw \
+  for (;; longjmp(*the_exception_context->penv, 1)) \
+    the_exception_context->v.etmp =
+
+
+#endif /* CEXCEPT_H */

Added: incubator/celix/trunk/celix/component.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/component.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/component.h (added)
+++ incubator/celix/trunk/celix/component.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,16 @@
+/*
+ * component.h
+ *
+ *  Created on: Mar 17, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef COMPONENT_H_
+#define COMPONENT_H_
+
+void start();
+
+void stop();
+
+
+#endif /* COMPONENT_H_ */

Added: incubator/celix/trunk/celix/constants.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/constants.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/constants.h (added)
+++ incubator/celix/trunk/celix/constants.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,29 @@
+/*
+ * constants.h
+ *
+ *  Created on: Apr 29, 2010
+ *      Author: dk489
+ */
+
+#ifndef CONSTANTS_H_
+#define CONSTANTS_H_
+
+static const char * const OBJECTCLASS = "objectClass";
+static const char * const SERVICE_ID = "service.id";
+
+static const char * const BUNDLE_ACTIVATOR_CREATE = "bundleActivator_create";
+static const char * const BUNDLE_ACTIVATOR_START = "bundleActivator_start";
+static const char * const BUNDLE_ACTIVATOR_STOP = "bundleActivator_stop";
+static const char * const BUNDLE_ACTIVATOR_DESTROY = "bundleActivator_destroy";
+
+static const char * const HEADER_LIBRARY = "library";
+
+static const char * const BUNDLE_SYMBOLICNAME = "Bundle-SymbolicName";
+static const char * const BUNDLE_VERSION = "Bundle-Version";
+static const char * const EXPORT_PACKAGE = "Export-Service";
+static const char * const IMPORT_PACKAGE = "Import-Service";
+
+static const char * const FRAMEWORK_STORAGE = "org.osgi.framework.storage";
+
+
+#endif /* CONSTANTS_H_ */

Added: incubator/celix/trunk/celix/filter.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/filter.c?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/filter.c (added)
+++ incubator/celix/trunk/celix/filter.c Thu Dec  9 11:49:40 2010
@@ -0,0 +1,508 @@
+/*
+ * filter.c
+ *
+ *  Created on: Apr 28, 2010
+ *      Author: dk489
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "headers.h"
+#include "filter.h"
+
+typedef enum operand
+{
+	EQUAL,
+	APPROX,
+	GREATER,
+	LESS,
+	PRESENT,
+	SUBSTRING,
+	AND,
+	OR,
+	NOT,
+} OPERAND;
+
+struct filter {
+	OPERAND operand;
+	char * attribute;
+	int operands;
+	void * value;
+};
+
+void filter_skipWhiteSpace(char * filterString, int * pos);
+FILTER filter_parseFilter(char * filterString, int * pos);
+FILTER filter_parseFilterComp(char * filterString, int * pos);
+FILTER filter_parseAnd(char * filterString, int * pos);
+FILTER filter_parseOr(char * filterString, int * pos);
+FILTER filter_parseNot(char * filterString, int * pos);
+FILTER filter_parseItem(char * filterString, int * pos);
+char * filter_parseAttr(char * filterString, int * pos);
+char * filter_parseValue(char * filterString, int * pos);
+ARRAY_LIST filter_parseSubstring(char * filterString, int * pos);
+
+int filter_compare(OPERAND operand, char * string, void * value2);
+int filter_compareString(OPERAND operand, char * string, void * value2);
+
+void filter_skipWhiteSpace(char * filterString, int * pos) {
+	int length;
+	for (length = strlen(filterString); (*pos < length) && isspace(filterString[*pos]);) {
+		(*pos)++;
+	}
+}
+
+FILTER filter_create(char * filterString) {
+	FILTER filter = NULL;
+	int pos = 0;
+	filter = filter_parseFilter(filterString, &pos);
+	if (pos != strlen(filterString)) {
+		printf("Error: Extraneous trailing characters\n");
+		return NULL;
+	}
+	return filter;
+}
+
+void filter_destroy(FILTER filter) {
+	if (filter != NULL) {
+		if (filter->operand == SUBSTRING) {
+			arrayList_clear(filter->value);
+			free(filter->value);
+		} else {
+			free(filter->value);
+		}
+		free(filter->attribute);
+		free(filter);
+	}
+}
+
+FILTER filter_parseFilter(char * filterString, int * pos) {
+	FILTER filter;
+	filter_skipWhiteSpace(filterString, pos);
+	if (filterString[*pos] != '(') {
+		printf("Error: Missing '('\n");
+		return NULL;
+	}
+	(*pos)++;
+
+	filter = filter_parseFilterComp(filterString, pos);
+
+	filter_skipWhiteSpace(filterString, pos);
+
+	if (filterString[*pos] != ')') {
+		printf("Error: Missing ')'\n");
+		return NULL;
+	}
+	(*pos)++;
+	filter_skipWhiteSpace(filterString, pos);
+
+	return filter;
+}
+
+FILTER filter_parseFilterComp(char * filterString, int * pos) {
+	filter_skipWhiteSpace(filterString, pos);
+
+	char c = filterString[*pos];
+
+	switch (c) {
+		case '&': {
+			(*pos)++;
+			return filter_parseAnd(filterString, pos);
+		}
+		case '|': {
+			(*pos)++;
+			return filter_parseOr(filterString, pos);
+		}
+		case '!': {
+			(*pos)++;
+			return filter_parseNot(filterString, pos);
+		}
+	}
+	return filter_parseItem(filterString, pos);
+}
+
+FILTER filter_parseAnd(char * filterString, int * pos) {
+	FILTER filter = (FILTER) malloc(sizeof(*filter));
+	ARRAY_LIST operands = arrayList_create();
+	filter_skipWhiteSpace(filterString, pos);
+
+	if (filterString[*pos] != '(') {
+		printf("Error: Missing '('\n");
+		return NULL;
+	}
+
+	while(filterString[*pos] == '(') {
+		FILTER child = filter_parseFilter(filterString, pos);
+		arrayList_add(operands, child);
+	}
+
+	filter->operand = AND;
+	filter->attribute = NULL;
+	filter->value = operands;
+
+	return filter;
+}
+
+FILTER filter_parseOr(char * filterString, int * pos) {
+	FILTER filter = (FILTER) malloc(sizeof(*filter));
+	ARRAY_LIST operands = arrayList_create();
+	filter_skipWhiteSpace(filterString, pos);
+
+	if (filterString[*pos] != '(') {
+		printf("Error: Missing '('\n");
+		return NULL;
+	}
+
+	while(filterString[*pos] == '(') {
+		FILTER child = filter_parseFilter(filterString, pos);
+		arrayList_add(operands, child);
+	}
+
+	filter->operand = OR;
+	filter->attribute = NULL;
+	filter->value = operands;
+
+	return filter;
+}
+
+FILTER filter_parseNot(char * filterString, int * pos) {
+	FILTER filter = (FILTER) malloc(sizeof(*filter));
+	filter_skipWhiteSpace(filterString, pos);
+
+	if (filterString[*pos] != '(') {
+		printf("Error: Missing '('\n");
+		return NULL;
+	}
+
+	FILTER child = filter_parseFilter(filterString, pos);
+
+	filter->operand = NOT;
+	filter->attribute = NULL;
+	filter->value = child;
+
+	return filter;
+}
+
+FILTER filter_parseItem(char * filterString, int * pos) {
+	char * attr = filter_parseAttr(filterString, pos);
+	filter_skipWhiteSpace(filterString, pos);
+	switch(filterString[*pos]) {
+		case '~': {
+			if (filterString[*pos + 1] == '=') {
+				FILTER filter = (FILTER) malloc(sizeof(*filter));
+				*pos += 2;
+				filter->operand = APPROX;
+				filter->attribute = attr;
+				filter->value = filter_parseValue(filterString, pos);
+				return filter;
+			}
+			break;
+		}
+		case '>': {
+			if (filterString[*pos + 1] == '=') {
+				FILTER filter = (FILTER) malloc(sizeof(*filter));
+				*pos += 2;
+				filter->operand = GREATER;
+				filter->attribute = attr;
+				filter->value = filter_parseValue(filterString, pos);
+				return filter;
+			}
+			break;
+		}
+		case '<': {
+			if (filterString[*pos + 1] == '=') {
+				FILTER filter = (FILTER) malloc(sizeof(*filter));
+				*pos += 2;
+				filter->operand = LESS;
+				filter->attribute = attr;
+				filter->value = filter_parseValue(filterString, pos);
+				return filter;
+			}
+			break;
+		}
+		case '=': {
+
+			if (filterString[*pos + 1] == '*') {
+				int oldPos = *pos;
+				*pos += 2;
+				filter_skipWhiteSpace(filterString, pos);
+				if (filterString[*pos] == ')') {
+					FILTER filter = (FILTER) malloc(sizeof(*filter));
+					filter->operand = PRESENT;
+					filter->attribute = attr;
+					filter->value = NULL;
+					return filter;
+				}
+				*pos = oldPos;
+			}
+			FILTER filter = (FILTER) malloc(sizeof(*filter));
+			ARRAY_LIST subs;
+			(*pos)++;
+			subs = filter_parseSubstring(filterString, pos);
+			if (arrayList_size(subs) == 1) {
+				char * string = (char *) arrayList_get(subs, 0);
+				if (string != NULL) {
+					filter->operand = EQUAL;
+					filter->attribute = attr;
+					filter->value = string;
+
+					arrayList_clear(subs);
+					free(subs);
+//					arrayList_destroy(subs);
+
+					return filter;
+				}
+			}
+			filter->operand = SUBSTRING;
+			filter->attribute = attr;
+			filter->value = subs;
+			return filter;
+		}
+	}
+	printf("Invalid operator\n");
+	return NULL;
+}
+
+char * filter_parseAttr(char * filterString, int * pos) {
+	filter_skipWhiteSpace(filterString, pos);
+	int begin = *pos;
+	int end = *pos;
+	int length = 0;
+
+	char c = filterString[*pos];
+
+	while (c != '~' && c != '<' && c != '>' && c != '=' && c != '(' && c != ')') {
+		(*pos)++;
+
+		if (!isspace(c)) {
+			end = *pos;
+		}
+
+		c = filterString[*pos];
+	}
+
+	length = end - begin;
+
+	if (length == 0) {
+		printf("Missing attr");
+		return NULL;
+	} else {
+		char * attr = (char *) malloc(length+1);
+		strncpy(attr, filterString+begin, length);
+		attr[length] = '\0';
+		return attr;
+	}
+}
+
+char * filter_parseValue(char * filterString, int * pos) {
+	char * value = strdup("");
+	int keepRunning = 1;
+
+	while (keepRunning) {
+		char c = filterString[*pos];
+
+		switch (c) {
+			case ')': {
+				keepRunning = 0;
+				break;
+			}
+			case '(': {
+				printf("Invalid value");
+				return NULL;
+			}
+			case '\\': {
+				(*pos)++;
+				c = filterString[*pos];
+			}
+			default: {
+				char ch[2];
+				ch[0] = c;
+				ch[1] = '\0';
+				strcat(value, ch);
+				(*pos)++;
+				break;
+			}
+		}
+	}
+
+	if (strlen(value) == 0) {
+		printf("Missing value");
+		return NULL;
+	}
+	return value;
+}
+
+ARRAY_LIST filter_parseSubstring(char * filterString, int * pos) {
+	char * sub = (char *) malloc(strlen(filterString));
+	ARRAY_LIST operands = arrayList_create();
+	int keepRunning = 1;
+	sub[0] = '\0';
+	while (keepRunning) {
+		char c = filterString[*pos];
+
+		switch (c) {
+			case ')': {
+				if (strlen(sub) > 0) {
+					arrayList_add(operands, sub);
+				}
+				keepRunning = 0;
+				break;
+			}
+			case '(': {
+				printf("Invalid value");
+				return NULL;
+			}
+			case '*': {
+				if (strlen(sub) > 0) {
+					arrayList_add(operands, sub);
+				}
+				sub[0] = '\0';
+				arrayList_add(operands, NULL);
+				(*pos)++;
+				break;
+			}
+			case '\\': {
+				(*pos)++;
+				c = filterString[*pos];
+			}
+			default: {
+				char ch[2];
+				ch[0] = c;
+				ch[1] = '\0';
+				strcat(sub, ch);
+				(*pos)++;
+				break;
+			}
+		}
+	}
+	int size = arrayList_size(operands);
+
+	if (size == 0) {
+		printf("Missing value");
+		return NULL;
+	}
+
+	return operands;
+}
+
+int filter_match(FILTER filter, HASHTABLE properties) {
+	switch (filter->operand) {
+		case AND: {
+			ARRAY_LIST filters = (ARRAY_LIST) filter->value;
+			unsigned int i;
+			for (i = 0; i < arrayList_size(filters); i++) {
+				FILTER sfilter = (FILTER) arrayList_get(filters, i);
+				if (!filter_match(sfilter, properties)) {
+					return 0;
+				}
+			}
+			return 1;
+		}
+		case OR: {
+			ARRAY_LIST filters = (ARRAY_LIST) filter->value;
+			unsigned int i;
+			for (i = 0; i < arrayList_size(filters); i++) {
+				FILTER sfilter = (FILTER) arrayList_get(filters, i);
+				if (filter_match(sfilter, properties)) {
+					return 1;
+				}
+			}
+			return 0;
+		}
+		case NOT: {
+			FILTER sfilter = (FILTER) filter->value;
+			return !filter_match(sfilter, properties);
+		}
+		case SUBSTRING :
+		case EQUAL :
+		case GREATER :
+		case LESS :
+		case APPROX : {
+			char * value = (properties == NULL) ? NULL: getProperty(properties, filter->attribute);
+
+			return filter_compare(filter->operand, (char *) value, filter->value);
+		}
+		case PRESENT: {
+			char * value = (properties == NULL) ? NULL: getProperty(properties, filter->attribute);
+			return value != NULL;
+		}
+	}
+	return 0;
+}
+
+int filter_compare(OPERAND operand, char * string, void * value2) {
+	if (string == NULL) {
+		return 0;
+	}
+	return filter_compareString(operand, string, value2);
+
+}
+
+int filter_compareString(OPERAND operand, char * string, void * value2) {
+	switch (operand) {
+		case SUBSTRING: {
+			ARRAY_LIST subs = (ARRAY_LIST) value2;
+			int pos = 0;
+			int i;
+			int size = arrayList_size(subs);
+			for (i = 0; i < size; i++) {
+				char * substr = (char *) arrayList_get(subs, i);
+
+				if (i + 1 < size) {
+					if (substr == NULL) {
+						char * substr2 = (char *) arrayList_get(subs, i + 1);
+						if (substr2 == NULL) {
+							continue;
+						}
+						unsigned int index = strcspn(string+pos, substr2);
+						if (index == strlen(string+pos)) {
+							return 0;
+						}
+
+						pos = index + strlen(substr2);
+						if (i + 2 < size) {
+							i++;
+						}
+					} else {
+						unsigned int len = strlen(substr);
+						char region[len+1];
+						strncpy(region, string+pos, len);
+						region[len] = '\0';
+						if (strcmp(region, substr) == 0) {
+							pos += len;
+						} else {
+							return 0;
+						}
+					}
+				} else {
+					if (substr == NULL) {
+						return 1;
+					}
+					unsigned int len = strlen(substr);
+					int begin = strlen(string)-len;
+					return (strcmp(string+begin, substr) == 0);
+				}
+			}
+			return 0;
+		}
+		case APPROX:
+		case EQUAL: {
+			return (strcmp(string, (char *) value2) == 0);
+		}
+		case GREATER: {
+			return (strcmp(string, (char *) value2) >= 0);
+		}
+		case LESS: {
+			return (strcmp(string, (char *) value2) <= 0);
+		}
+		case AND:
+		case NOT:
+		case OR:
+		case PRESENT: {
+
+		}
+	}
+	return 0;
+}
+

Added: incubator/celix/trunk/celix/filter.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/celix/filter.h?rev=1043903&view=auto
==============================================================================
--- incubator/celix/trunk/celix/filter.h (added)
+++ incubator/celix/trunk/celix/filter.h Thu Dec  9 11:49:40 2010
@@ -0,0 +1,18 @@
+/*
+ * filter.h
+ *
+ *  Created on: Apr 28, 2010
+ *      Author: dk489
+ */
+
+#ifndef FILTER_H_
+#define FILTER_H_
+
+typedef struct filter * FILTER;
+
+FILTER filter_create(char * filterString);
+void filter_destroy(FILTER filter);
+
+int filter_match(FILTER filter, HASHTABLE properties);
+
+#endif /* FILTER_H_ */



Mime
View raw message