celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [56/60] [abbrv] celix git commit: Merge branch 'develop' into feature/CELIX-426-cxx-api
Date Sun, 27 May 2018 18:53:04 GMT
http://git-wip-us.apache.org/repos/asf/celix/blob/2e04253d/libs/framework/private/mock/framework_mock.c
----------------------------------------------------------------------
diff --cc libs/framework/private/mock/framework_mock.c
index 0000000,7bbd752..9933dc0
mode 000000,100644..100644
--- a/libs/framework/private/mock/framework_mock.c
+++ b/libs/framework/private/mock/framework_mock.c
@@@ -1,0 -1,346 +1,341 @@@
+ /**
+  *Licensed to the Apache Software Foundation (ASF) under one
+  *or more contributor license agreements.  See the NOTICE file
+  *distributed with this work for additional information
+  *regarding copyright ownership.  The ASF licenses this file
+  *to you under the Apache License, Version 2.0 (the
+  *"License"); you may not use this file except in compliance
+  *with the License.  You may obtain a copy of the License at
+  *
+  *  http://www.apache.org/licenses/LICENSE-2.0
+  *
+  *Unless required by applicable law or agreed to in writing,
+  *software distributed under the License is distributed on an
+  *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  * KIND, either express or implied.  See the License for the
+  *specific language governing permissions and limitations
+  *under the License.
+  */
 -/*
 - * framework_mock.c
 - *
 - *  \date       Feb 7, 2013
 - *  \author     <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
 - *  \copyright  Apache License, Version 2.0
 - */
++
+ #include <CppUTestExt/MockSupport_c.h>
+ #include "CppUTestExt/MockSupport_c.h"
+ 
+ #include "framework_private.h"
+ 
+ celix_status_t framework_create(framework_pt *framework, properties_pt config) {
+ 	mock_c()->actualCall("framework_create");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_destroy(framework_pt framework) {
+ 	mock_c()->actualCall("framework_destroy");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_init(framework_pt framework) {
+ 	mock_c()->actualCall("fw_init");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_start(framework_pt framework) {
+ 	mock_c()->actualCall("framework_start");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_stop(framework_pt framework) {
+ 	mock_c()->actualCall("framework_stop");
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_getProperty(framework_pt framework, const char* name, const char* defaultValue, const char** value) {
+ 	mock_c()->actualCall("fw_getProperty")
+ 			->withPointerParameters("framework", framework)
+ 			->withStringParameters("name", name)
+ 			->withStringParameters("defaultValue", defaultValue)
+ 			->withOutputParameter("value", (const char **) value);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_installBundle(framework_pt framework, bundle_pt * bundle, const char * location, const char *inputFile) {
+ 	mock_c()->actualCall("fw_installBundle")
+ 			->withPointerParameters("framework", framework)
+ 			->withStringParameters("location", location)
+ 			->withStringParameters("inputFile", inputFile)
+ 			->withOutputParameter("bundle", (void **) bundle);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_uninstallBundle(framework_pt framework, bundle_pt bundle) {
+ 	mock_c()->actualCall("fw_uninstallBundle")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_getBundleEntry(framework_pt framework, bundle_pt bundle, const char *name, char **entry) {
+ 	mock_c()->actualCall("framework_getBundleEntry")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle)
+ 			->withStringParameters("name", name)
+ 			->withOutputParameter("entry", (const char **) entry);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ celix_status_t fw_startBundle(framework_pt framework, bundle_pt bundle, int options) {
+ 	mock_c()->actualCall("fw_startBundle")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withIntParameters("options", options);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_updateBundle(framework_pt framework, bundle_pt bundle, const char *inputFile) {
+ 	mock_c()->actualCall("framework_updateBundle")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withStringParameters("inputFile", inputFile);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_stopBundle(framework_pt framework, bundle_pt bundle, bool record) {
+ 	mock_c()->actualCall("fw_stopBundle")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withIntParameters("record", record);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ celix_status_t fw_registerService(framework_pt framework, service_registration_pt * registration, bundle_pt bundle, const char* serviceName, const void* svcObj, properties_pt properties) {
+ 	mock_c()->actualCall("fw_registerService")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withStringParameters("serviceName", serviceName)
+ 		->withPointerParameters("service", (void*) svcObj)
+ 		->withPointerParameters("properties", properties)
+ 		->withOutputParameter("registration", (void **) registration);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_registerServiceFactory(framework_pt framework, service_registration_pt * registration, bundle_pt bundle, const char* serviceName, service_factory_pt factory, properties_pt properties) {
+ 	mock_c()->actualCall("fw_registerServiceFactory")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withStringParameters("serviceName", serviceName)
+ 		->withPointerParameters("serviceFactory", factory)
+ 		->withPointerParameters("properties", properties)
+ 		->withOutputParameter("registration", (void **) registration);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ void fw_unregisterService(service_registration_pt registration) {
+ 	mock_c()->actualCall("fw_unregisterService");
+ }
+ 
+ 
+ celix_status_t fw_getServiceReferences(framework_pt framework, array_list_pt *references, bundle_pt bundle, const char * serviceName, const char * filter) {
+ 	mock_c()->actualCall("fw_getServiceReferences")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withStringParameters("serviceName", serviceName)
+ 		->withStringParameters("filter", filter)
+ 		->withOutputParameter("references", (void **) references);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_ungetServiceReference(framework_pt framework, bundle_pt bundle, service_reference_pt reference) {
+     mock_c()->actualCall("framework_ungetServiceReference")
+         ->withPointerParameters("framework", framework)
+         ->withPointerParameters("bundle", bundle)
+         ->withPointerParameters("reference", reference);
+     return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_getService(framework_pt framework, bundle_pt bundle, service_reference_pt reference, const void **service) {
+ 	mock_c()->actualCall("fw_getService")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withPointerParameters("reference", reference)
+ 		->withOutputParameter("service", service);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t framework_ungetService(framework_pt framework, bundle_pt bundle, service_reference_pt reference, bool *result) {
+ 	mock_c()->actualCall("framework_ungetService")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withPointerParameters("reference", reference)
+ 		->withOutputParameter("result", (int *) result);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_getBundleRegisteredServices(framework_pt framework, bundle_pt bundle, array_list_pt *services) {
+ 	mock_c()->actualCall("fw_getBundleRegisteredServices")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle)
+ 			->withOutputParameter("services", (void **) services);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_getBundleServicesInUse(framework_pt framework, bundle_pt bundle, array_list_pt *services) {
+ 	mock_c()->actualCall("fw_getBundleServicesInUse")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle)
+ 			->withOutputParameter("services", (void **) services);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ void fw_addServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt listener, const char* filter) {
+ 	mock_c()->actualCall("fw_addServiceListener")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withPointerParameters("listener", listener)
+ 		->withStringParameters("filter", filter);
+ }
+ 
+ void fw_removeServiceListener(framework_pt framework, bundle_pt bundle, service_listener_pt listener) {
+ 	mock_c()->actualCall("fw_removeServiceListener")
+ 		->withPointerParameters("framework", framework)
+ 		->withPointerParameters("bundle", bundle)
+ 		->withPointerParameters("listener", listener);
+ }
+ 
+ 
+ celix_status_t fw_addBundleListener(framework_pt framework, bundle_pt bundle, bundle_listener_pt listener) {
+ 	mock_c()->actualCall("fw_addBundleListener")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle)
+ 			->withPointerParameters("listener", listener);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_removeBundleListener(framework_pt framework, bundle_pt bundle, bundle_listener_pt listener) {
+ 	mock_c()->actualCall("fw_removeBundleListener")
+ 			->withPointerParameters("framework", framework)
+ 			->withPointerParameters("bundle", bundle)
+ 			->withPointerParameters("listener", listener);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_addFrameworkListener(framework_pt framework, bundle_pt bundle, framework_listener_pt listener) {
+     mock_c()->actualCall("fw_addframeworkListener")
+             ->withPointerParameters("framework", framework)
+             ->withPointerParameters("bundle", bundle)
+             ->withPointerParameters("listener", listener);
+     return mock_c()->returnValue().value.intValue;
+ }
+ 
+ celix_status_t fw_removeFrameworkListener(framework_pt framework, bundle_pt bundle, framework_listener_pt listener) {
+     mock_c()->actualCall("fw_removeframeworkListener")
+             ->withPointerParameters("framework", framework)
+             ->withPointerParameters("bundle", bundle)
+             ->withPointerParameters("listener", listener);
+         return mock_c()->returnValue().value.intValue;
+ }
+ 
+ void fw_serviceChanged(framework_pt framework, service_event_type_e eventType, service_registration_pt registration, properties_pt oldprops) {
+ 	mock_c()->actualCall("fw_serviceChanged");
+ }
+ 
+ 
+ celix_status_t fw_isServiceAssignable(framework_pt fw, bundle_pt requester, service_reference_pt reference, bool *assignable) {
+ 	mock_c()->actualCall("fw_isServiceAssignable");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ //bundle_archive_t fw_createArchive(long id, char * location) {
+ 
+ //void revise(bundle_archive_t archive, char * location) {
+ 
+ celix_status_t getManifest(bundle_archive_pt archive, manifest_pt *manifest) {
+ 	mock_c()->actualCall("getManifest")
+ 			->withPointerParameters("archive", archive)
+ 			->withOutputParameter("manifest", (void **) manifest);
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ bundle_pt findBundle(bundle_context_pt context) {
+ 	mock_c()->actualCall("findBundle");
+ 		return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ service_registration_pt findRegistration(service_reference_pt reference) {
+ 	mock_c()->actualCall("findRegistration");
+ 		return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ 
+ service_reference_pt listToArray(array_list_pt list) {
+ 	mock_c()->actualCall("listToArray")
+ 			->withPointerParameters("list", list);
+ 		return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ celix_status_t framework_markResolvedModules(framework_pt framework, linked_list_pt wires) {
+ 	mock_c()->actualCall("framework_markResolvedModules");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ celix_status_t framework_waitForStop(framework_pt framework) {
+ 	mock_c()->actualCall("framework_waitForStop");
+ 		return mock_c()->returnValue().value.intValue;
+ }
+ 
+ 
+ array_list_pt framework_getBundles(framework_pt framework) {
+ 	mock_c()->actualCall("framework_getBundles")
+ 			->withPointerParameters("framework", framework);
+ 		return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ bundle_pt framework_getBundle(framework_pt framework, const char* location) {
+ 	mock_c()->actualCall("framework_getBundle")
+ 			->withPointerParameters("framework", framework)
+ 			->withStringParameters("location", location);
+ 		return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ bundle_pt framework_getBundleById(framework_pt framework, long id) {
+ 	mock_c()->actualCall("framework_getBundleById")
+ 		->withPointerParameters("framework", framework)
+ 		->withIntParameters("id", id);
+ 	return mock_c()->returnValue().value.pointerValue;
+ }
+ 
+ celix_status_t framework_getFrameworkBundle(framework_pt framework, bundle_pt *bundle) {
+ 	mock_c()->actualCall("framework_getFrameworkBundle")
+ 			->withPointerParameters("framework", framework)
+ 			->withOutputParameter("bundle", bundle);
+ 	return mock_c()->returnValue().value.intValue;
+ }
+ 
+ void celix_framework_useBundles(framework_t *fw, void *callbackHandle, void(*use)(void *handle, const bundle_t *bnd)) {
+ 	mock_c()->actualCall("celix_framework_useBundles")
+ 			->withPointerParameters("fw", fw)
+ 			->withPointerParameters("callbackHandle", callbackHandle)
+ 			->withPointerParameters("use", use);
+ }
+ 
 -void celix_framework_useBundle(framework_t *fw, long bundleId, void *callbackHandle, void(*use)(void *handle, const bundle_t *bnd)) {
++bool celix_framework_useBundle(framework_t *fw, long bundleId, void *callbackHandle, void(*use)(void *handle, const bundle_t *bnd)) {
+ 	mock_c()->actualCall("celix_framework_useBundle")
+ 			->withPointerParameters("fw", fw)
+ 			->withLongIntParameters("bundleId", bundleId)
+ 			->withPointerParameters("callbackHandle", callbackHandle)
+ 			->withPointerParameters("use", use);
++    return mock_c()->returnValue().value.boolValue;
+ }
+ 
+ service_registration_t* celix_framework_registerServiceFactory(framework_t *fw , const celix_bundle_t *bnd, const char* serviceName, celix_service_factory_t *factory, celix_properties_t *properties) {
+ 	mock_c()->actualCall("celix_framework_registerServiceFactory")
+ 			->withPointerParameters("fw", fw)
+ 			->withConstPointerParameters("bnd", bnd)
+ 			->withStringParameters("serviceName", serviceName)
+ 			->withPointerParameters("factory", factory)
+ 			->withPointerParameters("properties", properties);
+ 	return mock_c()->returnValue().value.pointerValue;
+ }

http://git-wip-us.apache.org/repos/asf/celix/blob/2e04253d/libs/framework/src/bundle.c
----------------------------------------------------------------------
diff --cc libs/framework/src/bundle.c
index 0000000,6493c9f..5d61c19
mode 000000,100644..100644
--- a/libs/framework/src/bundle.c
+++ b/libs/framework/src/bundle.c
@@@ -1,0 -1,725 +1,765 @@@
+ /**
+  *Licensed to the Apache Software Foundation (ASF) under one
+  *or more contributor license agreements.  See the NOTICE file
+  *distributed with this work for additional information
+  *regarding copyright ownership.  The ASF licenses this file
+  *to you under the Apache License, Version 2.0 (the
+  *"License"); you may not use this file except in compliance
+  *with the License.  You may obtain a copy of the License at
+  *
+  *  http://www.apache.org/licenses/LICENSE-2.0
+  *
+  *Unless required by applicable law or agreed to in writing,
+  *software distributed under the License is distributed on an
+  *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  * KIND, either express or implied.  See the License for the
+  *specific language governing permissions and limitations
+  *under the License.
+  */
+ 
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "framework_private.h"
+ #include "bundle_private.h"
+ #include "resolver.h"
+ #include "utils.h"
++#include "celix_bundle.h"
+ 
+ celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module);
+ celix_status_t bundle_closeRevisions(bundle_pt bundle);
+ 
+ celix_status_t bundle_create(bundle_pt * bundle) {
+     celix_status_t status;
+     bundle_archive_pt archive = NULL;
+ 
+ 	*bundle = (bundle_pt) malloc(sizeof(**bundle));
+ 	if (*bundle == NULL) {
+ 		return CELIX_ENOMEM;
+ 	}
+ 	status = bundleArchive_createSystemBundleArchive(&archive);
+ 	if (status == CELIX_SUCCESS) {
+         module_pt module;
+ 
+         (*bundle)->archive = archive;
+         (*bundle)->activator = NULL;
+         (*bundle)->context = NULL;
+         (*bundle)->framework = NULL;
+         (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+         (*bundle)->modules = NULL;
+         arrayList_create(&(*bundle)->modules);
+         (*bundle)->handle = NULL;
+         (*bundle)->manifest = NULL;
+ 
+         module = module_createFrameworkModule((*bundle));
+         bundle_addModule(*bundle, module);
+ 
+         status = celixThreadMutex_create(&(*bundle)->lock, NULL);
+         if (status != CELIX_SUCCESS) {
+         	status = CELIX_ILLEGAL_STATE;
+         } else {
+ 			(*bundle)->lockCount = 0;
+ 			(*bundle)->lockThread = celix_thread_default;
+         }
+ 	}
+ 	framework_logIfError(logger, status, NULL, "Failed to create bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive) {
+     module_pt module;
+ 	
+ 	celix_status_t status;
+ 
+ 	*bundle = (bundle_pt) malloc(sizeof(**bundle));
+ 	if (*bundle == NULL) {
+ 		return CELIX_ENOMEM;
+ 	}
+ 	(*bundle)->archive = archive;
+ 	(*bundle)->activator = NULL;
+ 	(*bundle)->context = NULL;
+ 	(*bundle)->handle = NULL;
+ 	(*bundle)->manifest = NULL;
+ 	(*bundle)->framework = framework;
+ 	(*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+ 	(*bundle)->modules = NULL;
+ 	arrayList_create(&(*bundle)->modules);
+ 	
+ 	status = bundle_createModule(*bundle, &module);
+ 	if (status == CELIX_SUCCESS) {
+ 		bundle_addModule(*bundle, module);
+         status = celixThreadMutex_create(&(*bundle)->lock, NULL);
+         if (status != CELIX_SUCCESS) {
+ 			status = CELIX_ILLEGAL_STATE;
+ 		} else {
+ 			(*bundle)->lockCount = 0;
+ 			(*bundle)->lockThread = celix_thread_default;
+ 		}
+ 	} else {
+ 	    status = CELIX_FILE_IO_EXCEPTION;
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to create bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_destroy(bundle_pt bundle) {
+ 	array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
+ 	while (arrayListIterator_hasNext(iter)) {
+ 		module_pt module = arrayListIterator_next(iter);
+ 		module_destroy(module);
+ 	}
+ 	arrayListIterator_destroy(iter);
+ 	arrayList_destroy(bundle->modules);
+ 	celixThreadMutex_destroy(&bundle->lock);
+ 
+ 	free(bundle);
+ 
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 
+ 	if (bundle != NULL && *archive == NULL) {
+ 		*archive = bundle->archive;
+ 	} else {
+ 		status = CELIX_ILLEGAL_ARGUMENT;
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to get bundle archive");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 
+ 	if (bundle == NULL || arrayList_size(bundle->modules)==0 ) {
+ 		status = CELIX_ILLEGAL_ARGUMENT;
+ 	} else {
+ 		*module = arrayList_get(bundle->modules, arrayList_size(bundle->modules) - 1);
+ 	}
+ 
+ 	return status;
+ }
+ 
+ array_list_pt bundle_getModules(bundle_pt bundle) {
+     return bundle->modules;
+ }
+ 
+ void * bundle_getHandle(bundle_pt bundle) {
+ 	return bundle->handle;
+ }
+ 
+ void bundle_setHandle(bundle_pt bundle, void * handle) {
+ 	bundle->handle = handle;
+ }
+ 
+ activator_pt bundle_getActivator(bundle_pt bundle) {
+ 	return bundle->activator;
+ }
+ 
+ celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) {
+ 	bundle->activator = activator;
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) {
+ 	*context = bundle->context;
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) {
+ 	bundle->context = context;
+ 	return CELIX_SUCCESS;
+ }
+ 
 -celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** entry) {
 -	return framework_getBundleEntry(bundle->framework, bundle, name, entry);
++celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** out) {
++	char *entry = celix_bundle_getEntry(bundle, name);
++	if (out != NULL ) {
++		*out = entry;
++	}
++	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) {
+ 	if(bundle==NULL){
+ 		*state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
+ 		return CELIX_BUNDLE_EXCEPTION;
+ 	}
+ 	*state = bundle->state;
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) {
+ 	bundle->state = state;
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 	bundle_archive_pt archive = NULL;
+ 	bundle_revision_pt revision = NULL;
+ 	manifest_pt headerMap = NULL;
+ 
+ 	status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
+ 	status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
+ 	status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap));
+ 	if (status == CELIX_SUCCESS) {
+ 		long bundleId = 0;
+         status = bundleArchive_getId(bundle->archive, &bundleId);
+         if (status == CELIX_SUCCESS) {
+ 			int revision = 0;
+ 			char moduleId[512];
+ 
+ 			snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision);
+ 			*module = module_create(headerMap, moduleId, bundle);
+ 
+ 			if (*module != NULL) {
+ 				version_pt bundleVersion = module_getVersion(*module);
+ 				const char * symName = NULL;
+ 				status = module_getSymbolicName(*module, &symName);
+ 				if (status == CELIX_SUCCESS) {
+ 					array_list_pt bundles = framework_getBundles(bundle->framework);
+ 					unsigned int i;
+ 					for (i = 0; i < arrayList_size(bundles); i++) {
+ 						bundle_pt check = (bundle_pt) arrayList_get(bundles, i);
+ 
+ 						long id;
+ 						if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
+ 							if (id != bundleId) {
+ 								module_pt mod = NULL;
+ 								const char * sym = NULL;
+ 								version_pt version;
+ 								int cmp;
+ 								status = bundle_getCurrentModule(check, &mod);
+ 								status = module_getSymbolicName(mod, &sym);
+ 
+ 								version = module_getVersion(mod);
+ 								version_compareTo(bundleVersion, version, &cmp);
+ 								if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
+ 										!cmp) {
+ 									char *versionString = NULL;
+ 									version_toString(version, &versionString);
+ 									printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, versionString);
+ 									free(versionString);
+ 									status = CELIX_BUNDLE_EXCEPTION;
+ 									break;
+ 								}
+ 							}
+ 						}
+ 					}
+ 					arrayList_destroy(bundles);
+ 				}
+ 			}
+         }
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to create module");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_start(bundle_pt bundle) {
+ 	return bundle_startWithOptions(bundle, 0);
+ }
+ 
+ celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) {
+ 	celix_status_t status = CELIX_SUCCESS;
+     if (bundle != NULL) {
+     	bool systemBundle = false;
+     	status = bundle_isSystemBundle(bundle, &systemBundle);
+     	if (status == CELIX_SUCCESS) {
+     		if (systemBundle) {
+     			framework_start(bundle->framework);
+     		} else {
+     			status = fw_startBundle(bundle->framework, bundle, options);
+     		}
+     	}
+     }
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to start bundle");
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_update(bundle_pt bundle, const char *inputFile) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 	if (bundle != NULL) {
+ 		bool systemBundle = false;
+ 		status = bundle_isSystemBundle(bundle, &systemBundle);
+ 		if (status == CELIX_SUCCESS) {
+ 			if (systemBundle) {
+ 				// #TODO: Support framework update
+ 				status = CELIX_BUNDLE_EXCEPTION;
+ 			} else {
+ 				status = framework_updateBundle(bundle->framework, bundle, inputFile);
+ 			}
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to update bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_stop(bundle_pt bundle) {
+ 	return bundle_stopWithOptions(bundle, 0);
+ }
+ 
+ celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 	if (bundle != NULL) {
+ 		bool systemBundle = false;
+ 		status = bundle_isSystemBundle(bundle, &systemBundle);
+ 		if (status == CELIX_SUCCESS) {
+ 			if (systemBundle) {
+ 				framework_stop(bundle->framework);
+ 			} else {
+ 				status = fw_stopBundle(bundle->framework, bundle, options);
+ 			}
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to stop bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_uninstall(bundle_pt bundle) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 	if (bundle != NULL) {
+ 		bool systemBundle = false;
+ 		status = bundle_isSystemBundle(bundle, &systemBundle);
+ 		if (status == CELIX_SUCCESS) {
+ 			if (systemBundle) {
+ 				status = CELIX_BUNDLE_EXCEPTION;
+ 			} else {
+ 				status = fw_uninstallBundle(bundle->framework, bundle);
+ 			}
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to uninstall bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) {
+ 	celix_status_t status;
+ 	bool systemBundle;
+ 
+ 	status = bundle_isSystemBundle(bundle, &systemBundle);
+ 	if (status == CELIX_SUCCESS) {
+ 		if (!systemBundle) {
+ 			status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_INSTALLED);
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to set persistent state to inactive");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) {
+ 	celix_status_t status;
+ 	bool systemBundle;
+ 
+ 	status = bundle_isSystemBundle(bundle, &systemBundle);
+ 	if (status == CELIX_SUCCESS) {
+ 		if (!systemBundle) {
+ 			status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_UNINSTALLED);
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to set persistent state to uninstalled");
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char *inputFile) {
+ 	celix_status_t status;
+ 
+ 	bundle_archive_pt archive = NULL;
+ 	status = bundle_getArchive(bundle, &archive);
+ 	if (status == CELIX_SUCCESS) {
+ 		status = bundleArchive_revise(archive, location, inputFile);
+ 		if (status == CELIX_SUCCESS) {
+ 			module_pt module;
+ 			status = bundle_createModule(bundle, &module);
+ 			if (status == CELIX_SUCCESS) {
+ 				status = bundle_addModule(bundle, module);
+ 			} else {
+ 				bool rolledback;
+ 				status = bundleArchive_rollbackRevise(archive, &rolledback);
+ 				if (status == CELIX_SUCCESS) {
+ 					status = CELIX_BUNDLE_EXCEPTION;
+ 				}
+ 			}
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to revise bundle");
+ 
+ 	return status;
+ }
+ 
+ //bool bundle_rollbackRevise(bundle_pt bundle) {
+ //	module_pt module = arrayList_remove(bundle->modules, arrayList_set(bundle->modules) - 1);
+ //	return resolver_removeModule(module);
+ //}
+ 
+ celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) {
+ 	arrayList_add(bundle->modules, module);
+ 	resolver_addModule(module);
+ 	return CELIX_SUCCESS;
+ }
+ 
+ celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) {
+ 	celix_status_t status;
+ 	long bundleId;
+ 	bundle_archive_pt archive = NULL;
+ 
+ 	status = bundle_getArchive(bundle, &archive);
+ 	if (status == CELIX_SUCCESS) {
+ 		status = bundleArchive_getId(archive, &bundleId);
+ 		if (status == CELIX_SUCCESS) {
+ 			*systemBundle = (bundleId == 0);
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to check if bundle is the systembundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) {
+ 	celix_status_t status;
+ 
+ 	status = celixThreadMutex_lock(&bundle->lock);
+ 	if (status != CELIX_SUCCESS) {
+ 		status = CELIX_BUNDLE_EXCEPTION;
+ 	} else {
+ 		bool equals;
+ 		status = thread_equalsSelf(bundle->lockThread, &equals);
+ 		if (status == CELIX_SUCCESS) {
+ 			*lockable = (bundle->lockCount == 0) || (equals);
+ 		}
+ 
+ 		status = celixThreadMutex_unlock(&bundle->lock);
+ 		if (status != CELIX_SUCCESS) {
+ 			status = CELIX_BUNDLE_EXCEPTION;
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to check if bundle is lockable");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t *thread) {
+ 	celix_status_t status;
+ 
+ 	status = celixThreadMutex_lock(&bundle->lock);
+ 	if (status != CELIX_SUCCESS) {
+ 		status = CELIX_BUNDLE_EXCEPTION;
+ 	} else {
+ 		*thread = bundle->lockThread;
+ 
+ 		status = celixThreadMutex_unlock(&bundle->lock);
+ 		if (status != CELIX_SUCCESS) {
+ 			status = CELIX_BUNDLE_EXCEPTION;
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to get locking thread");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_lock(bundle_pt bundle, bool *locked) {
+ 	celix_status_t status;
+ 	bool equals;
+ 
+ 	celixThreadMutex_lock(&bundle->lock);
+ 
+ 	status = thread_equalsSelf(bundle->lockThread, &equals);
+ 	if (status == CELIX_SUCCESS) {
+ 		if ((bundle->lockCount > 0) && !equals) {
+ 			*locked = false;
+ 		} else {
+ 			bundle->lockCount++;
+ 			bundle->lockThread = celixThread_self();
+ 			*locked = true;
+ 		}
+ 	}
+ 
+ 	celixThreadMutex_unlock(&bundle->lock);
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to lock bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 
+ 	bool equals;
+ 
+ 	celixThreadMutex_lock(&bundle->lock);
+ 
+ 	if (bundle->lockCount == 0) {
+ 		*unlocked = false;
+ 	} else {
+ 		status = thread_equalsSelf(bundle->lockThread, &equals);
+ 		if (status == CELIX_SUCCESS) {
+ 			if ((bundle->lockCount > 0) && !equals) {
+ 				*unlocked = false;
+ 			}
+ 			else{
+ 			   bundle->lockCount--;
+ 			   if (bundle->lockCount == 0) {
+ 			   	bundle->lockThread = celix_thread_default;
+ 			   }
+ 			   *unlocked = true;
+ 		   }
+ 	   }
+ 	}
+ 
+ 	celixThreadMutex_unlock(&bundle->lock);
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to unlock bundle");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_close(bundle_pt bundle) {
+ 	bundle_archive_pt archive = NULL;
+ 	
+ 	celix_status_t status;
+ 
+     bundle_closeModules(bundle);
+     bundle_closeRevisions(bundle);
+     status = bundle_getArchive(bundle, &archive);
+     if (status == CELIX_SUCCESS) {
+ 		bundleArchive_close(archive);
+     }
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to close bundle");
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_closeAndDelete(bundle_pt bundle) {
+ 	celix_status_t status;
+ 
+ 	bundle_archive_pt archive = NULL;
+ 
+     bundle_closeModules(bundle);
+     bundle_closeRevisions(bundle);
+     status = bundle_getArchive(bundle, &archive);
+     if (status == CELIX_SUCCESS) {
+     	bundleArchive_closeAndDelete(archive);
+     }
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to close and delete bundle");
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_closeRevisions(bundle_pt bundle) {
+     celix_status_t status = CELIX_SUCCESS;
+ 
+     // TODO implement this
+     return status;
+ }
+ 
+ celix_status_t bundle_closeModules(bundle_pt bundle) {
+     celix_status_t status = CELIX_SUCCESS;
+ 
+     unsigned int i = 0;
+     for (i = 0; i < arrayList_size(bundle->modules); i++) {
+         module_pt module = (module_pt) arrayList_get(bundle->modules, i);
+         resolver_removeModule(module);
+         module_setWires(module, NULL);
+     }
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_refresh(bundle_pt bundle) {
+ 	celix_status_t status;
+ 	module_pt module;
+ 
+ 	status = bundle_closeModules(bundle);
+ 	if (status == CELIX_SUCCESS) {
+ 		arrayList_clear(bundle->modules);
+ 		status = bundle_createModule(bundle, &module);
+ 		if (status == CELIX_SUCCESS) {
+ 			status = bundle_addModule(bundle, module);
+ 			if (status == CELIX_SUCCESS) {
+ 				bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
+ 			}
+ 		}
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to refresh bundle");
+ 
+     return status;
+ }
+ 
+ celix_status_t bundle_getBundleId(bundle_t *bundle, long *bndId) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 	long id = celix_bundle_getId(bundle);
+ 	if (id >= 0) {
+ 		*bndId = id;
+ 	} else {
+ 		status = CELIX_BUNDLE_EXCEPTION;
+ 		*bndId = -1;
+ 	}
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt *list) {
+ 	celix_status_t status;
+ 
+ 	status = fw_getBundleRegisteredServices(bundle->framework, bundle, list);
+ 
+ 	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get registered services");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) {
+ 	celix_status_t status;
+ 
+ 	status = fw_getBundleServicesInUse(bundle->framework, bundle, list);
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to get in use services");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 
+ 	if (bundle != NULL && framework != NULL) {
+ 		bundle->framework = framework;
+ 	} else {
+ 		status = CELIX_ILLEGAL_ARGUMENT;
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to set framework");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) {
+ 	celix_status_t status = CELIX_SUCCESS;
+ 
+ 	if (bundle != NULL && *framework == NULL) {
+ 		*framework = bundle->framework;
+ 	} else {
+ 		status = CELIX_ILLEGAL_ARGUMENT;
+ 	}
+ 
+ 	framework_logIfError(logger, status, NULL, "Failed to get framework");
+ 
+ 	return status;
+ }
+ 
+ celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location){
 -
+ 	celix_status_t status;
+ 
+ 	bundle_archive_pt archive = NULL;
+ 
+ 	status = bundle_getArchive(bundle, &archive);
+ 	if (status != CELIX_SUCCESS){
+ 		printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n");
+ 		return status;
+ 	}
+ 
+ 	status =  bundleArchive_getLocation(archive, location);
+ 	if (status != CELIX_SUCCESS){
+ 		printf("[ ERROR ]:  Bundle - getBundleLocation (BundleArchiveLocation) \n");
+ 		return status;
+ 	}
+ 
+ 	return CELIX_SUCCESS;
+ }
+ 
+ 
++celix_status_t bundle_getBundleCache(bundle_pt bundle, const char **out) {
++    celix_status_t status;
++    
++    const char *cache = NULL;
++    bundle_archive_pt archive = NULL;
++    bundle_revision_pt rev = NULL;
++    
++    status = bundle_getArchive(bundle, &archive);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]: Bundle - bundle_getBundleCache (BundleArchive) \n");
++        return status;
++    }
++    
++    status = bundleArchive_getCurrentRevision(archive, &rev);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]:  Bundle - bundle_getBundleCache (BundleArchiveRevision) \n");
++        return status;
++    }
++    
++    status = bundleRevision_getRoot(rev, &cache);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]:  Bundle - bundle_getBundleCache (BundleArchiveRevision) \n");
++        return status;
++    }
++    
++    if (out != NULL) {
++        *out = cache;
++    }
++    
++    return CELIX_SUCCESS;
++}
+ 
+ 
+ 
+ 
+ /**********************************************************************************************************************
+  **********************************************************************************************************************
+  * Updated API
+  **********************************************************************************************************************
+  **********************************************************************************************************************/
+ 
+ long celix_bundle_getId(const bundle_t* bnd) {
+ 	long bndId = -1;
+ 	bundle_archive_pt archive = NULL;
 -	bundle_getArchive((bundle_t*)bnd, &archive);
++	if (bnd != NULL) {
++		bundle_getArchive((bundle_t *) bnd, &archive);
++	}
+ 	if (archive != NULL) {
+ 		bundleArchive_getId(archive, &bndId);
+ 	}
 -
+ 	if (bndId < 0) {
+ 		framework_logIfError(logger, CELIX_BUNDLE_EXCEPTION, NULL, "Failed to get bundle id");
+ 	}
+ 	return bndId;
+ }
+ 
+ celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd) {
 -	return bnd->state;
++    celix_bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
++    if (bnd != NULL) {
++        state = bnd->state;
++    }
++    return state;
+ }
+ 
+ char* celix_bundle_getEntry(const bundle_t* bnd, const char *path) {
+ 	char *entry = NULL;
+ 	if (bnd != NULL && bnd->framework != NULL) {
+ 		framework_getBundleEntry(bnd->framework, (celix_bundle_t*)bnd, path, &entry);
+ 	}
+ 	return entry;
+ }

http://git-wip-us.apache.org/repos/asf/celix/blob/2e04253d/libs/framework/src/bundle.c.orig
----------------------------------------------------------------------
diff --cc libs/framework/src/bundle.c.orig
index 0000000,0000000..550d511
new file mode 100644
--- /dev/null
+++ b/libs/framework/src/bundle.c.orig
@@@ -1,0 -1,0 +1,779 @@@
++/**
++ *Licensed to the Apache Software Foundation (ASF) under one
++ *or more contributor license agreements.  See the NOTICE file
++ *distributed with this work for additional information
++ *regarding copyright ownership.  The ASF licenses this file
++ *to you under the Apache License, Version 2.0 (the
++ *"License"); you may not use this file except in compliance
++ *with the License.  You may obtain a copy of the License at
++ *
++ *  http://www.apache.org/licenses/LICENSE-2.0
++ *
++ *Unless required by applicable law or agreed to in writing,
++ *software distributed under the License is distributed on an
++ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++ * KIND, either express or implied.  See the License for the
++ *specific language governing permissions and limitations
++ *under the License.
++ */
++
++#include <stdlib.h>
++#include <string.h>
++
++#include "framework_private.h"
++#include "bundle_private.h"
++#include "resolver.h"
++#include "utils.h"
++#include "celix_bundle.h"
++
++celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module);
++celix_status_t bundle_closeRevisions(bundle_pt bundle);
++
++celix_status_t bundle_create(bundle_pt * bundle) {
++    celix_status_t status;
++    bundle_archive_pt archive = NULL;
++
++	*bundle = (bundle_pt) malloc(sizeof(**bundle));
++	if (*bundle == NULL) {
++		return CELIX_ENOMEM;
++	}
++	status = bundleArchive_createSystemBundleArchive(&archive);
++	if (status == CELIX_SUCCESS) {
++        module_pt module;
++
++        (*bundle)->archive = archive;
++        (*bundle)->activator = NULL;
++        (*bundle)->context = NULL;
++        (*bundle)->framework = NULL;
++        (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
++        (*bundle)->modules = NULL;
++        arrayList_create(&(*bundle)->modules);
++        (*bundle)->handle = NULL;
++        (*bundle)->manifest = NULL;
++
++        module = module_createFrameworkModule((*bundle));
++        bundle_addModule(*bundle, module);
++
++        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
++        if (status != CELIX_SUCCESS) {
++        	status = CELIX_ILLEGAL_STATE;
++        } else {
++			(*bundle)->lockCount = 0;
++			(*bundle)->lockThread = celix_thread_default;
++        }
++	}
++	framework_logIfError(logger, status, NULL, "Failed to create bundle");
++
++	return status;
++}
++
++celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive) {
++    module_pt module;
++	
++	celix_status_t status;
++
++	*bundle = (bundle_pt) malloc(sizeof(**bundle));
++	if (*bundle == NULL) {
++		return CELIX_ENOMEM;
++	}
++	(*bundle)->archive = archive;
++	(*bundle)->activator = NULL;
++	(*bundle)->context = NULL;
++	(*bundle)->handle = NULL;
++	(*bundle)->manifest = NULL;
++	(*bundle)->framework = framework;
++	(*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
++	(*bundle)->modules = NULL;
++	arrayList_create(&(*bundle)->modules);
++	
++	status = bundle_createModule(*bundle, &module);
++	if (status == CELIX_SUCCESS) {
++		bundle_addModule(*bundle, module);
++        status = celixThreadMutex_create(&(*bundle)->lock, NULL);
++        if (status != CELIX_SUCCESS) {
++			status = CELIX_ILLEGAL_STATE;
++		} else {
++			(*bundle)->lockCount = 0;
++			(*bundle)->lockThread = celix_thread_default;
++		}
++	} else {
++	    status = CELIX_FILE_IO_EXCEPTION;
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to create bundle");
++
++	return status;
++}
++
++celix_status_t bundle_destroy(bundle_pt bundle) {
++	array_list_iterator_pt iter = arrayListIterator_create(bundle->modules);
++	while (arrayListIterator_hasNext(iter)) {
++		module_pt module = arrayListIterator_next(iter);
++		module_destroy(module);
++	}
++	arrayListIterator_destroy(iter);
++	arrayList_destroy(bundle->modules);
++	celixThreadMutex_destroy(&bundle->lock);
++
++	free(bundle);
++
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) {
++	celix_status_t status = CELIX_SUCCESS;
++
++	if (bundle != NULL && *archive == NULL) {
++		*archive = bundle->archive;
++	} else {
++		status = CELIX_ILLEGAL_ARGUMENT;
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to get bundle archive");
++
++	return status;
++}
++
++celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) {
++	celix_status_t status = CELIX_SUCCESS;
++
++	if (bundle == NULL || arrayList_size(bundle->modules)==0 ) {
++		status = CELIX_ILLEGAL_ARGUMENT;
++	} else {
++		*module = arrayList_get(bundle->modules, arrayList_size(bundle->modules) - 1);
++	}
++
++	return status;
++}
++
++array_list_pt bundle_getModules(bundle_pt bundle) {
++    return bundle->modules;
++}
++
++void * bundle_getHandle(bundle_pt bundle) {
++	return bundle->handle;
++}
++
++void bundle_setHandle(bundle_pt bundle, void * handle) {
++	bundle->handle = handle;
++}
++
++activator_pt bundle_getActivator(bundle_pt bundle) {
++	return bundle->activator;
++}
++
++celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) {
++	bundle->activator = activator;
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) {
++	*context = bundle->context;
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) {
++	bundle->context = context;
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_getEntry(bundle_pt bundle, const char* name, char** out) {
++	char *entry = celix_bundle_getEntry(bundle, name);
++	if (out != NULL ) {
++		*out = entry;
++	}
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) {
++	if(bundle==NULL){
++		*state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
++		return CELIX_BUNDLE_EXCEPTION;
++	}
++	*state = bundle->state;
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) {
++	bundle->state = state;
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) {
++	celix_status_t status = CELIX_SUCCESS;
++	bundle_archive_pt archive = NULL;
++	bundle_revision_pt revision = NULL;
++	manifest_pt headerMap = NULL;
++
++	status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
++	status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision));
++	status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap));
++	if (status == CELIX_SUCCESS) {
++		long bundleId = 0;
++        status = bundleArchive_getId(bundle->archive, &bundleId);
++        if (status == CELIX_SUCCESS) {
++			int revision = 0;
++			char moduleId[512];
++
++			snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision);
++			*module = module_create(headerMap, moduleId, bundle);
++
++			if (*module != NULL) {
++				version_pt bundleVersion = module_getVersion(*module);
++				const char * symName = NULL;
++				status = module_getSymbolicName(*module, &symName);
++				if (status == CELIX_SUCCESS) {
++					array_list_pt bundles = framework_getBundles(bundle->framework);
++					unsigned int i;
++					for (i = 0; i < arrayList_size(bundles); i++) {
++						bundle_pt check = (bundle_pt) arrayList_get(bundles, i);
++
++						long id;
++						if (bundleArchive_getId(check->archive, &id) == CELIX_SUCCESS) {
++							if (id != bundleId) {
++								module_pt mod = NULL;
++								const char * sym = NULL;
++								version_pt version;
++								int cmp;
++								status = bundle_getCurrentModule(check, &mod);
++								status = module_getSymbolicName(mod, &sym);
++
++								version = module_getVersion(mod);
++								version_compareTo(bundleVersion, version, &cmp);
++								if ((symName != NULL) && (sym != NULL) && !strcmp(symName, sym) &&
++										!cmp) {
++									char *versionString = NULL;
++									version_toString(version, &versionString);
++									printf("Bundle symbolic name and version are not unique: %s:%s\n", sym, versionString);
++									free(versionString);
++									status = CELIX_BUNDLE_EXCEPTION;
++									break;
++								}
++							}
++						}
++					}
++					arrayList_destroy(bundles);
++				}
++			}
++        }
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to create module");
++
++	return status;
++}
++
++celix_status_t bundle_start(bundle_pt bundle) {
++	return bundle_startWithOptions(bundle, 0);
++}
++
++celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) {
++	celix_status_t status = CELIX_SUCCESS;
++    if (bundle != NULL) {
++    	bool systemBundle = false;
++    	status = bundle_isSystemBundle(bundle, &systemBundle);
++    	if (status == CELIX_SUCCESS) {
++    		if (systemBundle) {
++    			framework_start(bundle->framework);
++    		} else {
++    			status = fw_startBundle(bundle->framework, bundle, options);
++    		}
++    	}
++    }
++
++	framework_logIfError(logger, status, NULL, "Failed to start bundle");
++
++    return status;
++}
++
++celix_status_t bundle_update(bundle_pt bundle, const char *inputFile) {
++	celix_status_t status = CELIX_SUCCESS;
++	if (bundle != NULL) {
++		bool systemBundle = false;
++		status = bundle_isSystemBundle(bundle, &systemBundle);
++		if (status == CELIX_SUCCESS) {
++			if (systemBundle) {
++				// #TODO: Support framework update
++				status = CELIX_BUNDLE_EXCEPTION;
++			} else {
++				status = framework_updateBundle(bundle->framework, bundle, inputFile);
++			}
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to update bundle");
++
++	return status;
++}
++
++celix_status_t bundle_stop(bundle_pt bundle) {
++	return bundle_stopWithOptions(bundle, 0);
++}
++
++celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) {
++	celix_status_t status = CELIX_SUCCESS;
++	if (bundle != NULL) {
++		bool systemBundle = false;
++		status = bundle_isSystemBundle(bundle, &systemBundle);
++		if (status == CELIX_SUCCESS) {
++			if (systemBundle) {
++				framework_stop(bundle->framework);
++			} else {
++				status = fw_stopBundle(bundle->framework, bundle, options);
++			}
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to stop bundle");
++
++	return status;
++}
++
++celix_status_t bundle_uninstall(bundle_pt bundle) {
++	celix_status_t status = CELIX_SUCCESS;
++	if (bundle != NULL) {
++		bool systemBundle = false;
++		status = bundle_isSystemBundle(bundle, &systemBundle);
++		if (status == CELIX_SUCCESS) {
++			if (systemBundle) {
++				status = CELIX_BUNDLE_EXCEPTION;
++			} else {
++				status = fw_uninstallBundle(bundle->framework, bundle);
++			}
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to uninstall bundle");
++
++	return status;
++}
++
++celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) {
++	celix_status_t status;
++	bool systemBundle;
++
++	status = bundle_isSystemBundle(bundle, &systemBundle);
++	if (status == CELIX_SUCCESS) {
++		if (!systemBundle) {
++			status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_INSTALLED);
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to set persistent state to inactive");
++
++	return status;
++}
++
++celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) {
++	celix_status_t status;
++	bool systemBundle;
++
++	status = bundle_isSystemBundle(bundle, &systemBundle);
++	if (status == CELIX_SUCCESS) {
++		if (!systemBundle) {
++			status = bundleArchive_setPersistentState(bundle->archive, OSGI_FRAMEWORK_BUNDLE_UNINSTALLED);
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to set persistent state to uninstalled");
++
++    return status;
++}
++
++celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char *inputFile) {
++	celix_status_t status;
++
++	bundle_archive_pt archive = NULL;
++	status = bundle_getArchive(bundle, &archive);
++	if (status == CELIX_SUCCESS) {
++		status = bundleArchive_revise(archive, location, inputFile);
++		if (status == CELIX_SUCCESS) {
++			module_pt module;
++			status = bundle_createModule(bundle, &module);
++			if (status == CELIX_SUCCESS) {
++				status = bundle_addModule(bundle, module);
++			} else {
++				bool rolledback;
++				status = bundleArchive_rollbackRevise(archive, &rolledback);
++				if (status == CELIX_SUCCESS) {
++					status = CELIX_BUNDLE_EXCEPTION;
++				}
++			}
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to revise bundle");
++
++	return status;
++}
++
++//bool bundle_rollbackRevise(bundle_pt bundle) {
++//	module_pt module = arrayList_remove(bundle->modules, arrayList_set(bundle->modules) - 1);
++//	return resolver_removeModule(module);
++//}
++
++celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) {
++	arrayList_add(bundle->modules, module);
++	resolver_addModule(module);
++	return CELIX_SUCCESS;
++}
++
++celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) {
++	celix_status_t status;
++	long bundleId;
++	bundle_archive_pt archive = NULL;
++
++	status = bundle_getArchive(bundle, &archive);
++	if (status == CELIX_SUCCESS) {
++		status = bundleArchive_getId(archive, &bundleId);
++		if (status == CELIX_SUCCESS) {
++			*systemBundle = (bundleId == 0);
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to check if bundle is the systembundle");
++
++	return status;
++}
++
++celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) {
++	celix_status_t status;
++
++	status = celixThreadMutex_lock(&bundle->lock);
++	if (status != CELIX_SUCCESS) {
++		status = CELIX_BUNDLE_EXCEPTION;
++	} else {
++		bool equals;
++		status = thread_equalsSelf(bundle->lockThread, &equals);
++		if (status == CELIX_SUCCESS) {
++			*lockable = (bundle->lockCount == 0) || (equals);
++		}
++
++		status = celixThreadMutex_unlock(&bundle->lock);
++		if (status != CELIX_SUCCESS) {
++			status = CELIX_BUNDLE_EXCEPTION;
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to check if bundle is lockable");
++
++	return status;
++}
++
++celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t *thread) {
++	celix_status_t status;
++
++	status = celixThreadMutex_lock(&bundle->lock);
++	if (status != CELIX_SUCCESS) {
++		status = CELIX_BUNDLE_EXCEPTION;
++	} else {
++		*thread = bundle->lockThread;
++
++		status = celixThreadMutex_unlock(&bundle->lock);
++		if (status != CELIX_SUCCESS) {
++			status = CELIX_BUNDLE_EXCEPTION;
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to get locking thread");
++
++	return status;
++}
++
++celix_status_t bundle_lock(bundle_pt bundle, bool *locked) {
++	celix_status_t status;
++	bool equals;
++
++	celixThreadMutex_lock(&bundle->lock);
++
++	status = thread_equalsSelf(bundle->lockThread, &equals);
++	if (status == CELIX_SUCCESS) {
++		if ((bundle->lockCount > 0) && !equals) {
++			*locked = false;
++		} else {
++			bundle->lockCount++;
++			bundle->lockThread = celixThread_self();
++			*locked = true;
++		}
++	}
++
++	celixThreadMutex_unlock(&bundle->lock);
++
++	framework_logIfError(logger, status, NULL, "Failed to lock bundle");
++
++	return status;
++}
++
++celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) {
++	celix_status_t status = CELIX_SUCCESS;
++
++	bool equals;
++
++	celixThreadMutex_lock(&bundle->lock);
++
++	if (bundle->lockCount == 0) {
++		*unlocked = false;
++	} else {
++		status = thread_equalsSelf(bundle->lockThread, &equals);
++		if (status == CELIX_SUCCESS) {
++			if ((bundle->lockCount > 0) && !equals) {
++				*unlocked = false;
++			}
++			else{
++			   bundle->lockCount--;
++			   if (bundle->lockCount == 0) {
++			   	bundle->lockThread = celix_thread_default;
++			   }
++			   *unlocked = true;
++		   }
++	   }
++	}
++
++	celixThreadMutex_unlock(&bundle->lock);
++
++	framework_logIfError(logger, status, NULL, "Failed to unlock bundle");
++
++	return status;
++}
++
++celix_status_t bundle_close(bundle_pt bundle) {
++	bundle_archive_pt archive = NULL;
++	
++	celix_status_t status;
++
++    bundle_closeModules(bundle);
++    bundle_closeRevisions(bundle);
++    status = bundle_getArchive(bundle, &archive);
++    if (status == CELIX_SUCCESS) {
++		bundleArchive_close(archive);
++    }
++
++	framework_logIfError(logger, status, NULL, "Failed to close bundle");
++
++    return status;
++}
++
++celix_status_t bundle_closeAndDelete(bundle_pt bundle) {
++	celix_status_t status;
++
++	bundle_archive_pt archive = NULL;
++
++    bundle_closeModules(bundle);
++    bundle_closeRevisions(bundle);
++    status = bundle_getArchive(bundle, &archive);
++    if (status == CELIX_SUCCESS) {
++    	bundleArchive_closeAndDelete(archive);
++    }
++
++	framework_logIfError(logger, status, NULL, "Failed to close and delete bundle");
++
++    return status;
++}
++
++celix_status_t bundle_closeRevisions(bundle_pt bundle) {
++    celix_status_t status = CELIX_SUCCESS;
++
++    // TODO implement this
++    return status;
++}
++
++celix_status_t bundle_closeModules(bundle_pt bundle) {
++    celix_status_t status = CELIX_SUCCESS;
++
++    unsigned int i = 0;
++    for (i = 0; i < arrayList_size(bundle->modules); i++) {
++        module_pt module = (module_pt) arrayList_get(bundle->modules, i);
++        resolver_removeModule(module);
++        module_setWires(module, NULL);
++    }
++
++    return status;
++}
++
++celix_status_t bundle_refresh(bundle_pt bundle) {
++	celix_status_t status;
++	module_pt module;
++
++	status = bundle_closeModules(bundle);
++	if (status == CELIX_SUCCESS) {
++		arrayList_clear(bundle->modules);
++		status = bundle_createModule(bundle, &module);
++		if (status == CELIX_SUCCESS) {
++			status = bundle_addModule(bundle, module);
++			if (status == CELIX_SUCCESS) {
++				bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
++			}
++		}
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to refresh bundle");
++
++    return status;
++}
++
++celix_status_t bundle_getBundleId(bundle_t *bundle, long *bndId) {
++	celix_status_t status = CELIX_SUCCESS;
++	long id = celix_bundle_getId(bundle);
++	if (id >= 0) {
++		*bndId = id;
++	} else {
++		status = CELIX_BUNDLE_EXCEPTION;
++		*bndId = -1;
++	}
++	return status;
++}
++
++celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt *list) {
++	celix_status_t status;
++
++	status = fw_getBundleRegisteredServices(bundle->framework, bundle, list);
++
++	framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get registered services");
++
++	return status;
++}
++
++celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) {
++	celix_status_t status;
++
++	status = fw_getBundleServicesInUse(bundle->framework, bundle, list);
++
++	framework_logIfError(logger, status, NULL, "Failed to get in use services");
++
++	return status;
++}
++
++celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) {
++	celix_status_t status = CELIX_SUCCESS;
++
++	if (bundle != NULL && framework != NULL) {
++		bundle->framework = framework;
++	} else {
++		status = CELIX_ILLEGAL_ARGUMENT;
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to set framework");
++
++	return status;
++}
++
++celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) {
++	celix_status_t status = CELIX_SUCCESS;
++
++	if (bundle != NULL && *framework == NULL) {
++		*framework = bundle->framework;
++	} else {
++		status = CELIX_ILLEGAL_ARGUMENT;
++	}
++
++	framework_logIfError(logger, status, NULL, "Failed to get framework");
++
++	return status;
++}
++
++celix_status_t bundle_getBundleLocation(bundle_pt bundle, const char **location){
++	celix_status_t status;
++
++	bundle_archive_pt archive = NULL;
++
++	status = bundle_getArchive(bundle, &archive);
++	if (status != CELIX_SUCCESS){
++		printf("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n");
++		return status;
++	}
++
++	status =  bundleArchive_getLocation(archive, location);
++	if (status != CELIX_SUCCESS){
++		printf("[ ERROR ]:  Bundle - getBundleLocation (BundleArchiveLocation) \n");
++		return status;
++	}
++
++	return CELIX_SUCCESS;
++}
++
++
++celix_status_t bundle_getBundleCache(bundle_pt bundle, const char **out) {
++    celix_status_t status;
++    
++    const char *cache = NULL;
++    bundle_archive_pt archive = NULL;
++    bundle_revision_pt rev = NULL;
++    
++    status = bundle_getArchive(bundle, &archive);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]: Bundle - bundle_getBundleCache (BundleArchive) \n");
++        return status;
++    }
++    
++    status = bundleArchive_getCurrentRevision(archive, &rev);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]:  Bundle - bundle_getBundleCache (BundleArchiveRevision) \n");
++        return status;
++    }
++    
++    status = bundleRevision_getRoot(rev, &cache);
++    if (status != CELIX_SUCCESS){
++        printf("[ ERROR ]:  Bundle - bundle_getBundleCache (BundleArchiveRevision) \n");
++        return status;
++    }
++    
++    if (out != NULL) {
++        *out = cache;
++    }
++    
++    return CELIX_SUCCESS;
++}
++
++
++
++
++/**********************************************************************************************************************
++ **********************************************************************************************************************
++ * Updated API
++ **********************************************************************************************************************
++ **********************************************************************************************************************/
++
++long celix_bundle_getId(const bundle_t* bnd) {
++	long bndId = -1;
++	bundle_archive_pt archive = NULL;
++	if (bnd != NULL) {
++		bundle_getArchive((bundle_t *) bnd, &archive);
++	}
++	if (archive != NULL) {
++		bundleArchive_getId(archive, &bndId);
++	}
++	if (bndId < 0) {
++		framework_logIfError(logger, CELIX_BUNDLE_EXCEPTION, NULL, "Failed to get bundle id");
++	}
++	return bndId;
++}
++
++celix_bundle_state_e celix_bundle_getState(const bundle_t *bnd) {
++<<<<<<< HEAD:framework/src/bundle.c
++	celix_bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
++	if (bnd != NULL) {
++		state = bnd->state;
++	}
++	return state;
++}
++
++char* celix_bundle_getEntry(const bundle_t *bnd, const char *relPath) {
++	char *entry = NULL;
++	if (bnd != NULL) {
++		framework_getBundleEntry(bnd->framework, (bundle_t*)bnd, relPath, &entry);
++	}
++	return entry;
++}
++
++=======
++	return bnd->state;
++}
++
++char* celix_bundle_getEntry(const bundle_t* bnd, const char *path) {
++	char *entry = NULL;
++	if (bnd != NULL && bnd->framework != NULL) {
++		framework_getBundleEntry(bnd->framework, (celix_bundle_t*)bnd, path, &entry);
++	}
++	return entry;
++}
++>>>>>>> develop:libs/framework/src/bundle.c


Mime
View raw message