You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2017/11/20 20:33:33 UTC

[36/46] celix git commit: CELIX-417: Initial refactoring for CMake usage

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/public/include/device.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/public/include/device.h b/device_access/device_access/public/include/device.h
deleted file mode 100644
index 28032ba..0000000
--- a/device_access/device_access/public/include/device.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- *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.
- */
-/*
- * device.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef DEVICE_H_
-#define DEVICE_H_
-
-#include "celix_errno.h"
-
-#define OSGI_DEVICEACCESS_DEVICE_CATEGORY	"DEVICE_CATEGORY"
-#define OSGI_DEVICEACCESS_DEVICE_SERIAL	"DEVICE_SERIAL"
-
-#define OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME "device"
-
-static const int OSGI_DEVICEACCESS_DEVICE_MATCH_NONE	= 0;
-
-typedef struct device * device_pt;
-
-struct device_service {
-	device_pt device;
-	celix_status_t (*noDriverFound)(device_pt device);
-};
-
-typedef struct device_service * device_service_pt;
-
-#endif /* DEVICE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/public/include/driver.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/public/include/driver.h b/device_access/device_access/public/include/driver.h
deleted file mode 100644
index 7e70e06..0000000
--- a/device_access/device_access/public/include/driver.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- *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.
- */
-/*
- * driver.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef DRIVER_H_
-#define DRIVER_H_
-
-#include "celix_errno.h"
-#include "service_reference.h"
-
-#define OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME "driver"
-
-#define OSGI_DEVICEACCESS_DRIVER_ID "DRIVER_ID"
-
-struct driver_service {
-	void *driver;
-	celix_status_t (*attach)(void *driver, service_reference_pt reference, char **result);
-	celix_status_t (*match)(void *driver, service_reference_pt reference, int *value);
-};
-
-typedef struct driver_service *driver_service_pt;
-
-
-#endif /* DRIVER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/public/include/driver_locator.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/public/include/driver_locator.h b/device_access/device_access/public/include/driver_locator.h
deleted file mode 100644
index 405e33a..0000000
--- a/device_access/device_access/public/include/driver_locator.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- *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.
- */
-/*
- * driver_locator.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef DRIVER_LOCATOR_H_
-#define DRIVER_LOCATOR_H_
-
-#include "celix_errno.h"
-#include "properties.h"
-#include "array_list.h"
-
-#define OSGI_DEVICEACCESS_DRIVER_LOCATOR_SERVICE_NAME "driver_locator"
-
-typedef struct driver_locator *driver_locator_pt;
-
-struct driver_locator_service {
-	driver_locator_pt locator;
-	celix_status_t(*findDrivers)(driver_locator_pt loc, properties_pt props, array_list_pt *drivers);
-	celix_status_t(*loadDriver)(driver_locator_pt loc, char *id, char **driver);
-};
-
-typedef struct driver_locator_service *driver_locator_service_pt;
-
-
-#endif /* DRIVER_LOCATOR_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/public/include/driver_selector.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/public/include/driver_selector.h b/device_access/device_access/public/include/driver_selector.h
deleted file mode 100644
index a088d05..0000000
--- a/device_access/device_access/public/include/driver_selector.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- *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.
- */
-/*
- * driver_selector.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef DRIVER_SELECTOR_H_
-#define DRIVER_SELECTOR_H_
-
-#define OSGI_DEVICEACCESS_DRIVER_SELECTOR_SERVICE_NAME "driver_selector"
-
-typedef struct driver_selector *driver_selector_pt;
-
-struct driver_selector_service {
-	driver_selector_pt selector;
-	celix_status_t (*driverSelector_select)(driver_selector_pt selector, service_reference_pt reference, array_list_pt matches, int *select);
-};
-
-typedef struct driver_selector_service *driver_selector_service_pt;
-
-
-#endif /* DRIVER_SELECTOR_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/public/include/match.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/public/include/match.h b/device_access/device_access/public/include/match.h
deleted file mode 100644
index dd8906d..0000000
--- a/device_access/device_access/public/include/match.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- *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.
- */
-/*
- * match.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef MATCH_H_
-#define MATCH_H_
-
-#include <service_reference.h>
-
-struct match {
-	service_reference_pt reference;
-	int matchValue;
-};
-
-typedef struct match *match_pt;
-
-#endif /* MATCH_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/activator.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/activator.c b/device_access/device_access/src/activator.c
new file mode 100755
index 0000000..007e725
--- /dev/null
+++ b/device_access/device_access/src/activator.c
@@ -0,0 +1,194 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.h>
+#include <service_tracker.h>
+
+#include "driver_locator.h"
+#include "device_manager.h"
+#include "log_service.h"
+#include "log_helper.h"
+
+struct device_manager_bundle_instance {
+	log_helper_pt loghelper;
+	bundle_context_pt context;
+	device_manager_pt deviceManager;
+	service_tracker_pt driverLocatorTracker;
+	service_tracker_pt driverTracker;
+	service_tracker_pt deviceTracker;
+};
+
+typedef struct device_manager_bundle_instance *device_manager_bundle_instance_pt;
+
+static celix_status_t deviceManagerBundle_createDriverLocatorTracker(device_manager_bundle_instance_pt bundleData);
+static celix_status_t deviceManagerBundle_createDriverTracker(device_manager_bundle_instance_pt bundleData);
+static celix_status_t deviceManagerBundle_createDeviceTracker(device_manager_bundle_instance_pt bundleData);
+
+celix_status_t addingService_dummy_func(void * handle, service_reference_pt reference, void **service) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_pt dm = handle;
+	bundle_context_pt context = NULL;
+	status = deviceManager_getBundleContext(dm, &context);
+	if (status == CELIX_SUCCESS) {
+		status = bundleContext_getService(context, reference, service);
+	}
+	return status;
+}
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_pt bi = calloc(1, sizeof(struct device_manager_bundle_instance));
+	if (bi == NULL) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*userData) = bi;
+		bi->context = context;
+
+		logHelper_create(context, &bi->loghelper);
+		logHelper_start(bi->loghelper);
+
+		status = deviceManager_create(context, bi->loghelper, &bi->deviceManager);
+	}
+	return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_pt bundleData = userData;
+
+	status = deviceManagerBundle_createDriverLocatorTracker(bundleData);
+	if (status == CELIX_SUCCESS) {
+		status = deviceManagerBundle_createDriverTracker(bundleData);
+		if (status == CELIX_SUCCESS) {
+				status = deviceManagerBundle_createDeviceTracker(bundleData);
+				if (status == CELIX_SUCCESS) {
+					status = serviceTracker_open(bundleData->driverLocatorTracker);
+					if (status == CELIX_SUCCESS) {
+						status = serviceTracker_open(bundleData->driverTracker);
+						if (status == CELIX_SUCCESS) {
+							status = serviceTracker_open(bundleData->deviceTracker);
+						}
+					}
+				}
+		}
+	}
+
+	if (status != CELIX_SUCCESS) {
+		logHelper_log(bundleData->loghelper, OSGI_LOGSERVICE_ERROR, "DEVICE_MANAGER: Error while starting bundle got error num %d", status);
+	}
+
+	logHelper_log(bundleData->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Started");
+
+	return status;
+}
+
+static celix_status_t deviceManagerBundle_createDriverLocatorTracker(device_manager_bundle_instance_pt bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	service_tracker_customizer_pt customizer = NULL;
+
+	status = serviceTrackerCustomizer_create(bundleData->deviceManager, addingService_dummy_func,
+			deviceManager_locatorAdded, deviceManager_locatorModified, deviceManager_locatorRemoved, &customizer);
+
+	if (status == CELIX_SUCCESS) {
+		service_tracker_pt tracker = NULL;
+		status = serviceTracker_create(bundleData->context, "driver_locator", customizer, &tracker);
+		if (status == CELIX_SUCCESS) {
+			bundleData->driverLocatorTracker=tracker;
+		}
+	} else {
+		status = CELIX_ENOMEM;
+	}
+	return status;
+}
+
+static celix_status_t deviceManagerBundle_createDriverTracker(device_manager_bundle_instance_pt bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	service_tracker_customizer_pt customizer = NULL;
+
+	status = serviceTrackerCustomizer_create(bundleData->deviceManager, addingService_dummy_func,
+			deviceManager_driverAdded, deviceManager_driverModified, deviceManager_driverRemoved, &customizer);
+
+	if (status == CELIX_SUCCESS) {
+		service_tracker_pt tracker = NULL;
+		status = serviceTracker_createWithFilter(bundleData->context, "(objectClass=driver)", customizer, &tracker);
+		if (status == CELIX_SUCCESS) {
+			bundleData->driverTracker=tracker;
+		}
+	} else {
+		status = CELIX_ENOMEM;
+	}
+	return status;
+}
+
+static celix_status_t deviceManagerBundle_createDeviceTracker(device_manager_bundle_instance_pt bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	service_tracker_customizer_pt customizer = NULL;
+
+	status = serviceTrackerCustomizer_create(bundleData->deviceManager, addingService_dummy_func,
+			deviceManager_deviceAdded, deviceManager_deviceModified, deviceManager_deviceRemoved, &customizer);
+
+	if (status == CELIX_SUCCESS) {
+		service_tracker_pt tracker = NULL;
+		status = serviceTracker_createWithFilter(bundleData->context, "(|(objectClass=device)(DEVICE_CATEGORY=*))", customizer, &tracker);
+		if (status == CELIX_SUCCESS) {
+			bundleData->deviceTracker=tracker;
+		}
+	} else {
+		status = CELIX_ENOMEM;
+	}
+	return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_pt bundleData = userData;
+//	status = serviceTracker_close(bundleData->driverLocatorTracker);
+	if (status == CELIX_SUCCESS) {
+		status = serviceTracker_close(bundleData->driverTracker);
+		if (status == CELIX_SUCCESS) {
+			status = serviceTracker_close(bundleData->deviceTracker);
+		}
+	}
+
+	return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_pt bundleData = userData;
+	status = deviceManager_destroy(bundleData->deviceManager);
+
+	logHelper_stop(bundleData->loghelper);
+	logHelper_destroy(&bundleData->loghelper);
+
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/device_manager.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/device_manager.c b/device_access/device_access/src/device_manager.c
new file mode 100644
index 0000000..6e7cfd9
--- /dev/null
+++ b/device_access/device_access/src/device_manager.c
@@ -0,0 +1,570 @@
+/**
+ *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.
+ */
+/*
+ * device_manager.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <constants.h>
+#include <string.h>
+
+#include "device_manager.h"
+#include "driver_locator.h"
+#include "driver_matcher.h"
+#include "driver_attributes.h"
+#include "driver_loader.h"
+#include "driver.h"
+#include "device.h"
+#include "log_service.h"
+
+
+#include <bundle.h>
+#include <module.h>
+#include <array_list.h>
+#include <service_registry.h>
+#include <service_reference.h>
+
+struct device_manager {
+	bundle_context_pt context;
+	hash_map_pt devices;
+	hash_map_pt drivers;
+	array_list_pt locators;
+	driver_selector_service_pt selector;
+	log_helper_pt loghelper;
+};
+
+static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service);
+static celix_status_t deviceManager_getIdleDevices(device_manager_pt manager, array_list_pt *idleDevices);
+static celix_status_t deviceManager_isDriverBundle(device_manager_pt manager, bundle_pt bundle, bool *isDriver);
+
+celix_status_t deviceManager_create(bundle_context_pt context, log_helper_pt logHelper, device_manager_pt *manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*manager = calloc(1, sizeof(**manager));
+	if (!*manager) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*manager)->context = context;
+		(*manager)->devices = NULL;
+		(*manager)->drivers = NULL;
+		(*manager)->locators = NULL;
+		(*manager)->selector = NULL;
+
+		(*manager)->devices = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+		(*manager)->drivers = hashMap_create(serviceReference_hashCode, NULL, serviceReference_equals2, NULL);
+
+		(*manager)->loghelper = logHelper;
+
+		status = arrayList_create(&(*manager)->locators);
+
+		logHelper_log((*manager)->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Initialized");
+	}
+
+
+	return status;
+}
+
+celix_status_t deviceManager_destroy(device_manager_pt manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Stop");
+
+	hashMap_destroy(manager->devices, false, false);
+	hashMap_destroy(manager->drivers, false, false);
+	arrayList_destroy(manager->locators);
+
+	return status;
+}
+
+celix_status_t deviceManager_selectorAdded(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Add selector");
+
+	manager->selector = (driver_selector_service_pt) service;
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_selectorModified(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Modify selector");
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_selectorRemoved(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove selector");
+	manager->selector = NULL;
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorAdded(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Add locator");
+	arrayList_add(manager->locators, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorModified(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Modify locator");
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorRemoved(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove locator");
+	arrayList_removeElement(manager->locators, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_deviceAdded(void * handle, service_reference_pt ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Add device");
+	status = deviceManager_attachAlgorithm(manager, ref, service);
+
+	return status;
+}
+
+static celix_status_t deviceManager_attachAlgorithm(device_manager_pt manager, service_reference_pt ref, void *service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	driver_loader_pt loader = NULL;
+	status = driverLoader_create(manager->context, &loader);
+	if (status == CELIX_SUCCESS) {
+		array_list_pt included = NULL;
+		array_list_pt excluded = NULL;
+
+		array_list_pt driverIds = NULL;
+
+		hashMap_put(manager->devices, ref, service);
+
+		status = arrayList_create(&included);
+		if (status == CELIX_SUCCESS) {
+			status = arrayList_create(&excluded);
+			if (status == CELIX_SUCCESS) {
+				properties_pt properties = properties_create();
+
+				unsigned int size = 0;
+				char **keys;
+
+				serviceReference_getPropertyKeys(ref, &keys, &size);
+				for (int i = 0; i < size; i++) {
+					char* key = keys[i];
+					const char* value = NULL;
+					serviceReference_getProperty(ref, key, &value);
+					properties_set(properties, key, value);
+				}
+
+				status = driverLoader_findDrivers(loader, manager->locators, properties, &driverIds);
+				if (status == CELIX_SUCCESS) {
+					hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
+					while (hashMapIterator_hasNext(iter)) {
+						driver_attributes_pt driverAttributes = hashMapIterator_nextValue(iter);
+						arrayList_add(included, driverAttributes);
+
+						// Each driver that already is installed can be removed from the list
+						char *id = NULL;
+						celix_status_t substatus = driverAttributes_getDriverId(driverAttributes, &id);
+						if (substatus == CELIX_SUCCESS) {
+							// arrayList_removeElement(driverIds, id);
+							array_list_iterator_pt idsIter = arrayListIterator_create(driverIds);
+							while (arrayListIterator_hasNext(idsIter)) {
+								char *value = arrayListIterator_next(idsIter);
+								if (strcmp(value, id) == 0) {
+									arrayListIterator_remove(idsIter);
+								}
+							}
+							arrayListIterator_destroy(idsIter);
+						}
+						if(id != NULL){
+							free(id);
+						}
+					}
+					hashMapIterator_destroy(iter);
+
+					status = deviceManager_matchAttachDriver(manager, loader, driverIds, included, excluded, service, ref);
+
+				}
+				arrayList_destroy(driverIds);
+				properties_destroy(properties);
+				arrayList_destroy(excluded);
+			}
+			arrayList_destroy(included);
+		}
+
+	}
+
+	driverLoader_destroy(&loader);
+	return status;
+}
+
+celix_status_t deviceManager_matchAttachDriver(device_manager_pt manager, driver_loader_pt loader,
+		array_list_pt driverIds, array_list_pt included, array_list_pt excluded, void *service, service_reference_pt reference) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	array_list_pt references = NULL;
+
+	int i;
+	for (i = 0; i < arrayList_size(excluded); i++) {
+		void *exclude = arrayList_get(excluded, i);
+		arrayList_removeElement(included, exclude);
+	}
+
+	for (i = 0; i < arrayList_size(driverIds); i++) {
+		char *id = arrayList_get(driverIds, i);
+		logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Driver found: %s", id);
+	}
+
+	status = driverLoader_loadDrivers(loader, manager->locators, driverIds, &references);
+	if (status == CELIX_SUCCESS) {
+		for (i = 0; i < arrayList_size(references); i++) {
+			service_reference_pt reference = arrayList_get(references, i);
+			driver_attributes_pt attributes = hashMap_get(manager->drivers, reference);
+			if (attributes != NULL) {
+				arrayList_add(included, attributes);
+			}
+		}
+
+		driver_matcher_pt matcher = NULL;
+		status = driverMatcher_create(manager->context, &matcher);
+		if (status == CELIX_SUCCESS) {
+			for (i = 0; i < arrayList_size(included); i++) {
+				driver_attributes_pt attributes = arrayList_get(included, i);
+
+				int match = 0;
+				celix_status_t substatus = driverAttributes_match(attributes, reference, &match);
+				if (substatus == CELIX_SUCCESS) {
+					logHelper_log(manager->loghelper, OSGI_LOGSERVICE_INFO, "DEVICE_MANAGER: Found match: %d", match);
+					if (match <= OSGI_DEVICEACCESS_DEVICE_MATCH_NONE) {
+						continue;
+					}
+					driverMatcher_add(matcher, match, attributes);
+				} else {
+					// Ignore
+				}
+			}
+
+			match_pt match = NULL;
+			status = driverMatcher_getBestMatch(matcher, reference, &match);
+			if (status == CELIX_SUCCESS) {
+				if (match == NULL) {
+					status = deviceManager_noDriverFound(manager, service, reference);
+				} else {
+                    driver_attributes_pt finalAttributes = hashMap_get(manager->drivers, match->reference);
+                    if (finalAttributes == NULL) {
+                        status = deviceManager_noDriverFound(manager, service, reference);
+                    } else {
+                        char *newDriverId = NULL;
+                        status = driverAttributes_attach(finalAttributes, reference, &newDriverId);
+                        if (status == CELIX_SUCCESS) {
+                            if (newDriverId != NULL) {
+                                array_list_pt ids = NULL;
+                                arrayList_create(&ids);
+                                arrayList_add(ids, newDriverId);
+                                arrayList_add(excluded, finalAttributes);
+                                status = deviceManager_matchAttachDriver(manager, loader,
+                                        ids, included, excluded, service, reference);
+                            } else {
+                                // Attached, unload unused drivers
+                                status = driverLoader_unloadDrivers(loader, finalAttributes);
+                            }
+                        }
+					}
+				}
+			}
+		}
+
+		driverMatcher_destroy(&matcher);
+
+	}
+
+	if (references != NULL) {
+		arrayList_destroy(references);
+	}
+
+	return status;
+}
+
+celix_status_t deviceManager_noDriverFound(device_manager_pt manager, void *service, service_reference_pt reference) {
+	celix_status_t status = CELIX_SUCCESS;
+    const char* objectClass = NULL;
+    serviceReference_getProperty(reference, (char *) OSGI_FRAMEWORK_OBJECTCLASS, &objectClass);
+    if (strcmp(objectClass, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME) == 0) {
+        device_service_pt device = service;
+        status = device->noDriverFound(device->device);
+    }
+	return status;
+}
+
+celix_status_t deviceManager_deviceModified(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Modify device");
+	// #TODO the device properties could be changed
+	//hashMap_put(manager->devices, ref, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_deviceRemoved(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove device");
+	hashMap_remove(manager->devices, ref);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_driverAdded(void * handle, service_reference_pt ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Add driver");
+	driver_attributes_pt attributes = NULL;
+
+	status = driverAttributes_create(ref, service, &attributes);
+	if (status == CELIX_SUCCESS) {
+		hashMap_put(manager->drivers, ref, attributes);
+	}
+	else{
+		driverAttributes_destroy(attributes);
+	}
+	return status;
+}
+
+celix_status_t deviceManager_driverModified(void * handle, service_reference_pt ref, void * service) {
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Modify driver");
+	// #TODO the driver properties could be changed?
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_driverRemoved(void * handle, service_reference_pt ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	device_manager_pt manager = handle;
+	logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Remove driver");
+
+	hashMap_remove(manager->drivers, ref);
+
+	array_list_pt idleDevices = NULL;
+	status = deviceManager_getIdleDevices(manager, &idleDevices);
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(idleDevices); i++) {
+			celix_status_t forStatus = CELIX_SUCCESS;
+			service_reference_pt ref = arrayList_get(idleDevices, i);
+			const char *bsn = NULL;
+			bundle_pt bundle = NULL;
+			forStatus = serviceReference_getBundle(ref, &bundle);
+			if (forStatus == CELIX_SUCCESS) {
+				module_pt module = NULL;
+				forStatus = bundle_getCurrentModule(bundle, &module);
+				if (forStatus == CELIX_SUCCESS) {
+					forStatus = module_getSymbolicName(module, &bsn);
+					if (forStatus == CELIX_SUCCESS) {
+						logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: IDLE: %s", bsn);
+						// #TODO attachDriver (idle device)
+						// #TODO this can result in a loop?
+						//		Locate and install a driver
+						//		Let the match fail, the device is idle
+						//		The driver is removed, idle check is performed
+						//		Attach is tried again
+						//		.. loop ..
+						void *device = hashMap_get(manager->devices, ref);
+						forStatus = deviceManager_attachAlgorithm(manager, ref, device);
+					}
+				}
+			}
+
+			if (forStatus != CELIX_SUCCESS) {
+				break; //Got error, stop loop and return status
+			}
+		}
+
+
+		hash_map_iterator_pt iter = hashMapIterator_create(manager->drivers);
+		while (hashMapIterator_hasNext(iter)) {
+			hashMapIterator_nextValue(iter);
+//			driver_attributes_pt da = hashMapIterator_nextValue(iter);
+//			driverAttributes_tryUninstall(da);
+		}
+		hashMapIterator_destroy(iter);
+	}
+
+	if (idleDevices != NULL) {
+		arrayList_destroy(idleDevices);
+	}
+
+	return status;
+}
+
+
+celix_status_t deviceManager_getIdleDevices(device_manager_pt manager, array_list_pt *idleDevices) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = arrayList_create(idleDevices);
+	if (status == CELIX_SUCCESS) {
+		hash_map_iterator_pt iter = hashMapIterator_create(manager->devices);
+		while (hashMapIterator_hasNext(iter)) {
+			celix_status_t substatus = CELIX_SUCCESS;
+			service_reference_pt ref = hashMapIterator_nextKey(iter);
+			const char *bsn = NULL;
+			module_pt module = NULL;
+			bundle_pt bundle = NULL;
+			substatus = serviceReference_getBundle(ref, &bundle);
+			if (substatus == CELIX_SUCCESS) {
+				substatus = bundle_getCurrentModule(bundle, &module);
+				if (substatus == CELIX_SUCCESS) {
+					substatus = module_getSymbolicName(module, &bsn);
+					if (substatus == CELIX_SUCCESS) {
+						logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Check idle device: %s", bsn);
+						array_list_pt bundles = NULL;
+						substatus = serviceReference_getUsingBundles(ref, &bundles);
+						if (substatus == CELIX_SUCCESS) {
+							bool inUse = false;
+							int i;
+							for (i = 0; i < arrayList_size(bundles); i++) {
+								bundle_pt bundle = arrayList_get(bundles, i);
+								bool isDriver;
+								celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
+								if (sstatus == CELIX_SUCCESS) {
+									if (isDriver) {
+										const char *bsn = NULL;
+										module_pt module = NULL;
+										bundle_getCurrentModule(bundle, &module);
+										module_getSymbolicName(module, &bsn);
+
+										logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Not idle, used by driver: %s", bsn);
+
+										inUse = true;
+										break;
+									}
+								}
+							}
+
+							if (!inUse) {
+								arrayList_add(*idleDevices, ref);
+							}
+						}
+
+						if(bundles!=NULL){
+							arrayList_destroy(bundles);
+						}
+					}
+				}
+			}
+		}
+		hashMapIterator_destroy(iter);
+	}
+
+	return status;
+}
+
+//TODO examply for discussion only, remove after discussion
+#define DO_IF_SUCCESS(status, call_func) ((status) == CELIX_SUCCESS) ? (call_func) : (status)
+celix_status_t deviceManager_getIdleDevices_exmaple(device_manager_pt manager, array_list_pt *idleDevices) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = arrayList_create(idleDevices);
+	if (status == CELIX_SUCCESS) {
+		hash_map_iterator_pt iter = hashMapIterator_create(manager->devices);
+		while (hashMapIterator_hasNext(iter)) {
+			celix_status_t substatus = CELIX_SUCCESS;
+			service_reference_pt ref = hashMapIterator_nextKey(iter);
+			const char *bsn = NULL;
+			module_pt module = NULL;
+			bundle_pt bundle = NULL;
+			array_list_pt bundles = NULL;
+			substatus = serviceReference_getBundle(ref, &bundle);
+			substatus = DO_IF_SUCCESS(substatus, bundle_getCurrentModule(bundle, &module));
+			substatus = DO_IF_SUCCESS(substatus, module_getSymbolicName(module, &bsn));
+			substatus = DO_IF_SUCCESS(substatus, serviceReference_getUsingBundles(ref, &bundles));
+
+			if (substatus == CELIX_SUCCESS) {
+				logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Check idle device: %s", bsn);
+				bool inUse = false;
+				int i;
+				for (i = 0; i < arrayList_size(bundles); i++) {
+					bundle_pt bundle = arrayList_get(bundles, i);
+					bool isDriver;
+					celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
+					if (sstatus == CELIX_SUCCESS) {
+						if (isDriver) {
+							const char *bsn = NULL;
+							module_pt module = NULL;
+							bundle_getCurrentModule(bundle, &module);
+							module_getSymbolicName(module, &bsn);
+
+							logHelper_log(manager->loghelper, OSGI_LOGSERVICE_DEBUG, "DEVICE_MANAGER: Not idle, used by driver: %s", bsn);
+
+							inUse = true;
+							break;
+						}
+					}
+				}
+
+				if (!inUse) {
+					arrayList_add(*idleDevices, ref);
+				}
+			}
+		}
+		hashMapIterator_destroy(iter);
+	}
+	return status;
+}
+
+celix_status_t deviceManager_isDriverBundle(device_manager_pt manager, bundle_pt bundle, bool *isDriver) {
+	celix_status_t status = CELIX_SUCCESS;
+	(*isDriver) = false;
+
+	array_list_pt refs = NULL;
+		status = bundle_getRegisteredServices(bundle, &refs);
+		if (status == CELIX_SUCCESS) {
+			if (refs != NULL) {
+				int i;
+				for (i = 0; i < arrayList_size(refs); i++) {
+					service_reference_pt ref = arrayList_get(refs, i);
+                    const char* object = NULL;
+                    serviceReference_getProperty(ref, OSGI_FRAMEWORK_OBJECTCLASS, &object);
+                    if (strcmp(object, "driver") == 0) {
+                        *isDriver = true;
+                        break;
+                    }
+				}
+				arrayList_destroy(refs);
+			}
+		}
+
+	return status;
+}
+
+
+celix_status_t deviceManager_getBundleContext(device_manager_pt manager, bundle_context_pt *context) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (manager->context != NULL) {
+		(*context) = manager->context;
+	} else {
+		status = CELIX_INVALID_BUNDLE_CONTEXT;
+	}
+	return status;
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/device_manager.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/device_manager.h b/device_access/device_access/src/device_manager.h
new file mode 100644
index 0000000..00a4f2c
--- /dev/null
+++ b/device_access/device_access/src/device_manager.h
@@ -0,0 +1,56 @@
+/**
+ *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.
+ */
+/*
+ * device_manager.h
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#ifndef DEVICE_MANAGER_H_
+#define DEVICE_MANAGER_H_
+
+#include "log_helper.h"
+
+#include "driver_loader.h"
+
+typedef struct device_manager *device_manager_pt;
+
+celix_status_t deviceManager_create(bundle_context_pt context, log_helper_pt logHelper, device_manager_pt *manager);
+celix_status_t deviceManager_destroy(device_manager_pt manager);
+
+celix_status_t deviceManager_matchAttachDriver(device_manager_pt manager, driver_loader_pt loader,
+			array_list_pt driverIds, array_list_pt included, array_list_pt excluded, void *service, service_reference_pt reference);
+celix_status_t deviceManager_noDriverFound(device_manager_pt manager, void *service, service_reference_pt reference);
+
+celix_status_t deviceManager_locatorAdded(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_locatorModified(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_locatorRemoved(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_deviceAdded(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_deviceModified(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_deviceRemoved(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_driverAdded(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_driverModified(void * handle, service_reference_pt ref, void * service);
+celix_status_t deviceManager_driverRemoved(void * handle, service_reference_pt ref, void * service);
+
+celix_status_t deviceManager_getBundleContext(device_manager_pt manager, bundle_context_pt *context);
+
+// celix_status_t deviceManager_match(device_manager_pt manager, ...);
+
+#endif /* DEVICE_MANAGER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_attributes.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_attributes.c b/device_access/device_access/src/driver_attributes.c
new file mode 100644
index 0000000..5ac7fda
--- /dev/null
+++ b/device_access/device_access/src/driver_attributes.c
@@ -0,0 +1,169 @@
+/**
+ *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.
+ */
+/*
+ * driver_attributes.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "driver_attributes.h"
+#include "bundle.h"
+#include "celixbool.h"
+#include "driver_loader.h"
+#include "device.h"
+#include "constants.h"
+
+struct driver_attributes {
+	bundle_pt bundle;
+	service_reference_pt reference;
+	driver_service_pt driver;
+	bool dynamic;
+};
+
+celix_status_t driverAttributes_create(service_reference_pt reference, driver_service_pt driver, driver_attributes_pt *attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*attributes = calloc(1, sizeof(**attributes));
+	if (!*attributes) {
+		status = CELIX_ENOMEM;
+	} else {
+		bundle_pt bundle = NULL;
+		bundle_archive_pt bundleArchive = NULL;
+		status = serviceReference_getBundle(reference, &bundle);
+
+		if (status == CELIX_SUCCESS) {
+			status = bundle_getArchive(bundle, &bundleArchive);
+
+			if (status == CELIX_SUCCESS) {
+				(*attributes)->reference = reference;
+				(*attributes)->driver = driver;
+				(*attributes)->bundle = bundle;
+
+				const char *location;
+				status = bundleArchive_getLocation(bundleArchive, &location);
+				if (status == CELIX_SUCCESS) {
+					(*attributes)->dynamic = strncmp(location, DRIVER_LOCATION_PREFIX, 4) == 0 ? true : false;
+				}
+
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverAttributes_destroy(driver_attributes_pt attributes){
+	if(attributes != NULL){
+		free(attributes);
+	}
+	return CELIX_SUCCESS;
+}
+
+celix_status_t driverAttributes_getReference(driver_attributes_pt driverAttributes, service_reference_pt *reference) {
+	*reference = driverAttributes->reference;
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t driverAttributes_getDriverId(driver_attributes_pt driverAttributes, char **driverId) {
+	celix_status_t status = CELIX_SUCCESS;
+
+    const char* id_prop = NULL;
+    status = serviceReference_getProperty(driverAttributes->reference, "DRIVER_ID", &id_prop);
+    if (status == CELIX_SUCCESS) {
+        if (!id_prop) {
+            status = CELIX_ENOMEM;
+        } else {
+            *driverId = strdup(id_prop);
+
+            if (*driverId == NULL) {
+                status = CELIX_ENOMEM;
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverAttributes_match(driver_attributes_pt driverAttributes, service_reference_pt reference, int *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = driverAttributes->driver->match(driverAttributes->driver->driver, reference, match);
+
+	return status;
+}
+
+celix_status_t driverAttributes_isInUse(driver_attributes_pt driverAttributes, bool *inUse) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	array_list_pt references = NULL;
+	status = bundle_getServicesInUse(driverAttributes->bundle, &references);
+	if (status == CELIX_SUCCESS) {
+		if (references == NULL || arrayList_size(references) == 0) {
+			*inUse = false;
+		} else {
+			int i;
+			for (i = 0; i < arrayList_size(references); i++) {
+				service_reference_pt ref = arrayList_get(references, i);
+				const char *object = NULL;
+				status = serviceReference_getProperty(ref, OSGI_FRAMEWORK_OBJECTCLASS, &object);
+
+				if (status == CELIX_SUCCESS) {
+					const char* category = NULL;
+					status = serviceReference_getProperty(ref, "DEVICE_CATEGORY", &category);
+
+					if (status == CELIX_SUCCESS) {
+						if ((object != NULL && strcmp(object, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME) == 0) || (category != NULL)) {
+							*inUse = true;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverAttributes_attach(driver_attributes_pt driverAttributes, service_reference_pt reference, char **attach) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = driverAttributes->driver->attach(driverAttributes->driver->driver, reference, attach);
+
+	return status;
+}
+
+celix_status_t driverAttributes_tryUninstall(driver_attributes_pt driverAttributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	bool inUse = false;
+
+	status = driverAttributes_isInUse(driverAttributes, &inUse);
+	if (status == CELIX_SUCCESS) {
+		if (!inUse && driverAttributes->dynamic) {
+			status = bundle_uninstall(driverAttributes->bundle);
+		}
+	}
+
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_attributes.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_attributes.h b/device_access/device_access/src/driver_attributes.h
new file mode 100644
index 0000000..bdb12a2
--- /dev/null
+++ b/device_access/device_access/src/driver_attributes.h
@@ -0,0 +1,46 @@
+/**
+ *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.
+ */
+/*
+ * driver_attributes.h
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#ifndef DRIVER_ATTRIBUTES_H_
+#define DRIVER_ATTRIBUTES_H_
+
+#include "driver.h"
+
+typedef struct driver_attributes *driver_attributes_pt;
+
+celix_status_t driverAttributes_create(service_reference_pt reference, driver_service_pt driver, driver_attributes_pt *attributes);
+celix_status_t driverAttributes_destroy(driver_attributes_pt attributes);
+
+celix_status_t driverAttributes_getReference(driver_attributes_pt driverAttributes, service_reference_pt *reference);
+celix_status_t driverAttributes_getDriverId(driver_attributes_pt driverAttributes, char **driverId);
+
+celix_status_t driverAttributes_match(driver_attributes_pt driverAttributes, service_reference_pt reference, int *match);
+celix_status_t driverAttributes_attach(driver_attributes_pt driverAttributes, service_reference_pt reference, char **attach);
+
+celix_status_t driverAttributes_isInUse(driver_attributes_pt driverAttributes, bool *inUse);
+
+celix_status_t driverAttributes_tryUninstall(driver_attributes_pt driverAttributes);
+
+#endif /* DRIVER_ATTRIBUTES_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_loader.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_loader.c b/device_access/device_access/src/driver_loader.c
new file mode 100644
index 0000000..c4caa65
--- /dev/null
+++ b/device_access/device_access/src/driver_loader.c
@@ -0,0 +1,185 @@
+/**
+ *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.
+ */
+/*
+ * driver_loader.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "driver_loader.h"
+#include "bundle_context.h"
+#include "bundle.h"
+
+struct driver_loader {
+	bundle_context_pt context;
+	array_list_pt loadedDrivers;
+};
+
+celix_status_t driverLoader_create(bundle_context_pt context, driver_loader_pt *loader) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*loader = calloc(1, sizeof(**loader));
+	if (!*loader) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*loader)->context = context;
+		(*loader)->loadedDrivers = NULL;
+		status = arrayList_create(&(*loader)->loadedDrivers);
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_destroy(driver_loader_pt *loader) {
+	if((*loader) != NULL){
+		arrayList_destroy((*loader)->loadedDrivers);
+		free((*loader));
+		(*loader)=NULL;
+	}
+	return CELIX_SUCCESS;
+}
+
+celix_status_t driverLoader_findDrivers(driver_loader_pt loader, array_list_pt locators, properties_pt properties, array_list_pt *driversIds) {
+	celix_status_t status = CELIX_SUCCESS;
+	arrayList_create(driversIds);
+
+	int i;
+	for (i = 0; i < arrayList_size(locators); i++) {
+		array_list_pt drivers;
+		driver_locator_service_pt locator = arrayList_get(locators, i);
+
+		status = driverLoader_findDriversForLocator(loader, locator, properties, &drivers);
+		if (status == CELIX_SUCCESS) {
+			arrayList_addAll(*driversIds, drivers);
+		}
+		arrayList_destroy(drivers);
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_findDriversForLocator(driver_loader_pt loader, driver_locator_service_pt locator, properties_pt properties, array_list_pt *driversIds) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = locator->findDrivers(locator->locator, properties, driversIds);
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDrivers(driver_loader_pt loader, array_list_pt locators, array_list_pt driverIds, array_list_pt *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	status = arrayList_create(references);
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(driverIds); i++) {
+			array_list_pt refs = NULL;
+			char *id = arrayList_get(driverIds, i);
+
+			status = driverLoader_loadDriver(loader, locators, id, &refs);
+			if (status == CELIX_SUCCESS) {
+				arrayList_addAll(*references, refs);
+			}
+			if (refs != NULL) {
+				arrayList_destroy(refs);
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDriver(driver_loader_pt loader, array_list_pt locators, char *driverId, array_list_pt *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	status = arrayList_create(references);
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(locators); i++) {
+			array_list_pt refs = NULL;
+			driver_locator_service_pt locator = arrayList_get(locators, i);
+
+			status = driverLoader_loadDriverForLocator(loader, locator, driverId, &refs);
+			if (status == CELIX_SUCCESS) {
+				arrayList_addAll(*references, refs);
+			}
+
+			if (refs != NULL) {
+				arrayList_destroy(refs);
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDriverForLocator(driver_loader_pt loader, driver_locator_service_pt locator, char *driverId, array_list_pt *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	//The list is created in the bundle_getRegisteredServices chain
+	//arrayList_create(references);
+
+	char *filename = NULL;
+	status = locator->loadDriver(locator->locator, driverId, &filename);
+	if (status == CELIX_SUCCESS) {
+		bundle_pt bundle = NULL;
+		int length = strlen(DRIVER_LOCATION_PREFIX) + strlen(driverId);
+		char location[length+2];
+		snprintf(location, length+2, "%s%s", DRIVER_LOCATION_PREFIX, driverId);
+		status = bundleContext_installBundle2(loader->context, location, filename, &bundle);
+		if (status == CELIX_SUCCESS) {
+			status = bundle_start(bundle);
+			if (status == CELIX_SUCCESS) {
+				status = bundle_getRegisteredServices(bundle, references);
+				if (status == CELIX_SUCCESS) {
+					arrayList_addAll(loader->loadedDrivers, *references);
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_unloadDrivers(driver_loader_pt loader, driver_attributes_pt finalDriver) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	service_reference_pt finalReference = NULL;
+	if (finalDriver != NULL) {
+		status = driverAttributes_getReference(finalDriver, &finalReference);
+	}
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(loader->loadedDrivers); i++) {
+			service_reference_pt reference = arrayList_get(loader->loadedDrivers, i);
+			bool equal = false;
+			status = serviceReference_equals(reference, finalReference, &equal);
+			if (status == CELIX_SUCCESS && !equal) {
+				bundle_pt bundle = NULL;
+				status = serviceReference_getBundle(reference, &bundle);
+				if (status == CELIX_SUCCESS) {
+					bundle_uninstall(bundle); // Ignore status
+				}
+			}
+		}
+	}
+
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_loader.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_loader.h b/device_access/device_access/src/driver_loader.h
new file mode 100644
index 0000000..fde9c88
--- /dev/null
+++ b/device_access/device_access/src/driver_loader.h
@@ -0,0 +1,48 @@
+/**
+ *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.
+ */
+/*
+ * driver_loader.h
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#ifndef DRIVER_LOADER_H_
+#define DRIVER_LOADER_H_
+
+#include "driver_locator.h"
+#include "driver_attributes.h"
+
+#define DRIVER_LOCATION_PREFIX "_DD_"
+
+typedef struct driver_loader *driver_loader_pt;
+
+celix_status_t driverLoader_create(bundle_context_pt context, driver_loader_pt *loader);
+celix_status_t driverLoader_destroy(driver_loader_pt *loader);
+
+celix_status_t driverLoader_findDrivers(driver_loader_pt loader, array_list_pt locators, properties_pt properties, array_list_pt *driversIds);
+celix_status_t driverLoader_findDriversForLocator(driver_loader_pt loader, driver_locator_service_pt locator, properties_pt properties, array_list_pt *driversIds);
+
+celix_status_t driverLoader_loadDrivers(driver_loader_pt loader, array_list_pt locators, array_list_pt driverIds, array_list_pt *references);
+celix_status_t driverLoader_loadDriver(driver_loader_pt loader, array_list_pt locators, char *driverId, array_list_pt *references);
+celix_status_t driverLoader_loadDriverForLocator(driver_loader_pt loader, driver_locator_service_pt locator, char *driverId, array_list_pt *references);
+
+celix_status_t driverLoader_unloadDrivers(driver_loader_pt loader, driver_attributes_pt finalDriver);
+
+#endif /* DRIVER_LOADER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_matcher.c
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_matcher.c b/device_access/device_access/src/driver_matcher.c
new file mode 100644
index 0000000..c7597d3
--- /dev/null
+++ b/device_access/device_access/src/driver_matcher.c
@@ -0,0 +1,274 @@
+/**
+ *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.
+ */
+/*
+ * driver_matcher.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "hash_map.h"
+#include "constants.h"
+
+#include "driver_matcher.h"
+#include "log_helper.h"
+#include "log_service.h"
+
+
+struct driver_matcher {
+	hash_map_pt attributes;
+	array_list_pt matches;
+	log_helper_pt loghelper;
+
+	bundle_context_pt context;
+};
+
+typedef struct match_key {
+	int matchValue;
+}*match_key_t;
+
+static celix_status_t driverMatcher_get(driver_matcher_pt matcher, int key, array_list_pt *attributesV);
+static celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, match_pt *match);
+
+unsigned int driverMatcher_matchKeyHash(const void* match_key) {
+	match_key_t key = (match_key_t) match_key;
+
+	return key->matchValue;
+}
+
+int driverMatcher_matchKeyEquals(const void* key, const void* toCompare) {
+	return ((match_key_t) key)->matchValue == ((match_key_t) toCompare)->matchValue;
+}
+
+celix_status_t driverMatcher_create(bundle_context_pt context, driver_matcher_pt *matcher) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*matcher = calloc(1, sizeof(**matcher));
+	if (!*matcher) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*matcher)->matches = NULL;
+		(*matcher)->context = context;
+		(*matcher)->attributes = hashMap_create(driverMatcher_matchKeyHash, NULL, driverMatcher_matchKeyEquals, NULL);
+
+		arrayList_create(&(*matcher)->matches);
+
+		if(logHelper_create(context, &(*matcher)->loghelper) == CELIX_SUCCESS) {
+			logHelper_start((*matcher)->loghelper);
+		}
+
+	}
+
+	return status;
+}
+
+celix_status_t driverMatcher_destroy(driver_matcher_pt *matcher) {
+
+	if((*matcher) != NULL){
+
+		int i = 0;
+
+		for(;i<arrayList_size((*matcher)->matches);i++){
+			free(arrayList_get((*matcher)->matches,i));
+		}
+		arrayList_destroy((*matcher)->matches);
+
+		hash_map_iterator_pt iter = hashMapIterator_create((*matcher)->attributes);
+		while (hashMapIterator_hasNext(iter)) {
+			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+			match_key_t match = (match_key_t)hashMapEntry_getKey(entry);
+			array_list_pt list = (array_list_pt)hashMapEntry_getValue(entry);
+			free(match);
+			if (list != NULL) {
+				arrayList_destroy(list);
+			}
+		}
+		hashMapIterator_destroy(iter);
+		hashMap_destroy((*matcher)->attributes, false, false);
+
+		logHelper_stop((*matcher)->loghelper);
+		logHelper_destroy(&(*matcher)->loghelper);
+
+		free(*matcher);
+	}
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t driverMatcher_add(driver_matcher_pt matcher, int matchValue, driver_attributes_pt attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	array_list_pt da = NULL;
+	status = driverMatcher_get(matcher, matchValue, &da);
+	if (status == CELIX_SUCCESS) {
+		arrayList_add(da, attributes);
+
+		match_pt match = NULL;
+		match = calloc(1, sizeof(*match));
+		if (!match) {
+			status = CELIX_ENOMEM;
+		} else {
+			match->matchValue = matchValue;
+			match->reference = NULL;
+			driverAttributes_getReference(attributes, &match->reference);
+			arrayList_add(matcher->matches, match);
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverMatcher_get(driver_matcher_pt matcher, int key, array_list_pt *attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	match_key_t matchKeyS = calloc(1, sizeof(*matchKeyS));
+	matchKeyS->matchValue = key;
+
+	*attributes = hashMap_get(matcher->attributes, matchKeyS);
+	if (*attributes == NULL) {
+		arrayList_create(attributes);
+		match_key_t matchKey = calloc(1, sizeof(*matchKey));
+		matchKey->matchValue = key;
+		hashMap_put(matcher->attributes, matchKey, *attributes);
+	}
+
+	free(matchKeyS);
+
+	return status;
+}
+
+celix_status_t driverMatcher_getBestMatch(driver_matcher_pt matcher, service_reference_pt reference, match_pt *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (*match != NULL) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		service_reference_pt selectorRef = NULL;
+		status = bundleContext_getServiceReference(matcher->context, OSGI_DEVICEACCESS_DRIVER_SELECTOR_SERVICE_NAME, &selectorRef);
+		if (status == CELIX_SUCCESS) {
+			int index = -1;
+			if (selectorRef != NULL) {
+				driver_selector_service_pt selector = NULL;
+				status = bundleContext_getService(matcher->context, selectorRef, (void **) &selector);
+				if (status == CELIX_SUCCESS) {
+					if (selector != NULL) {
+						int size = -1;
+						status = selector->driverSelector_select(selector->selector, reference, matcher->matches, &index);
+						if (status == CELIX_SUCCESS) {
+							size = arrayList_size(matcher->matches);
+							if (index != -1 && index >= 0 && index < size) {
+								*match = arrayList_get(matcher->matches, index);
+							}
+						}
+					}
+				}
+			}
+			if (status == CELIX_SUCCESS && *match == NULL) {
+				status = driverMatcher_getBestMatchInternal(matcher, match);
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_pt matcher, match_pt *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!hashMap_isEmpty(matcher->attributes)) {
+		match_key_t matchKey = NULL;
+		hash_map_iterator_pt iter = hashMapIterator_create(matcher->attributes);
+		while (hashMapIterator_hasNext(iter)) {
+			hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
+			match_key_t key = hashMapEntry_getKey(entry);
+			if (matchKey == NULL || matchKey->matchValue < key->matchValue) {
+				matchKey = key;
+			}
+		}
+		hashMapIterator_destroy(iter);
+
+		array_list_pt das = hashMap_get(matcher->attributes, matchKey);
+		service_reference_pt best = NULL;
+		int i;
+		for (i = 0; i < arrayList_size(das); i++) {
+			driver_attributes_pt attributes = arrayList_get(das, i);
+			service_reference_pt reference = NULL;
+
+			celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
+			if (substatus == CELIX_SUCCESS) {
+				if (best != NULL) {
+					const char* rank1Str;
+					const char* rank2Str;
+					int rank1, rank2;
+
+					rank1Str = "0";
+					rank2Str = "0";
+
+					logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare ranking");
+
+					serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_RANKING, &rank1Str);
+					serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_RANKING, &rank2Str);
+
+					rank1 = atoi(rank1Str);
+					rank2 = atoi(rank2Str);
+
+					if (rank1 != rank2) {
+						if (rank1 > rank2) {
+							best = reference;
+						}
+					} else {
+						const char* id1Str;
+						const char* id2Str;
+						long id1, id2;
+
+						id1Str = NULL;
+						id2Str = NULL;
+
+						logHelper_log(matcher->loghelper, OSGI_LOGSERVICE_DEBUG, "DRIVER_MATCHER: Compare id's");
+
+						serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &id1Str);
+						serviceReference_getProperty(reference, OSGI_FRAMEWORK_SERVICE_ID, &id2Str);
+
+						id1 = atol(id1Str);
+						id2 = atol(id2Str);
+
+						if (id1 < id2) {
+							best = reference;
+						}
+					}
+				} else {
+					best = reference;
+				}
+			}
+
+		}
+
+		*match = calloc(1, sizeof(**match));
+		if (!*match) {
+			status = CELIX_ENOMEM;
+		} else {
+			(*match)->matchValue = matchKey->matchValue;
+			(*match)->reference = best;
+		}
+	}
+
+	return status;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/device_access/src/driver_matcher.h
----------------------------------------------------------------------
diff --git a/device_access/device_access/src/driver_matcher.h b/device_access/device_access/src/driver_matcher.h
new file mode 100644
index 0000000..d6cdb22
--- /dev/null
+++ b/device_access/device_access/src/driver_matcher.h
@@ -0,0 +1,42 @@
+/**
+ *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.
+ */
+/*
+ * driver_matcher.h
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#ifndef DRIVER_MATCHER_H_
+#define DRIVER_MATCHER_H_
+
+#include "match.h"
+#include "driver_selector.h"
+#include "driver_attributes.h"
+
+typedef struct driver_matcher *driver_matcher_pt;
+
+celix_status_t driverMatcher_create(bundle_context_pt context, driver_matcher_pt *matcher);
+celix_status_t driverMatcher_destroy(driver_matcher_pt *matcher);
+
+celix_status_t driverMatcher_add(driver_matcher_pt matcher, int match, driver_attributes_pt attributes);
+
+celix_status_t driverMatcher_getBestMatch(driver_matcher_pt matcher, service_reference_pt reference, match_pt *match);
+
+#endif /* DRIVER_MATCHER_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/CMakeLists.txt b/device_access/driver_locator/CMakeLists.txt
index 9138f4a..2e0dde2 100644
--- a/device_access/driver_locator/CMakeLists.txt
+++ b/device_access/driver_locator/CMakeLists.txt
@@ -20,15 +20,13 @@ add_bundle(driver_locator
 	VERSION "0.0.2"
 	NAME "Apache Celix Device Access Driver Locator"
 	SOURCES
-		private/src/activator
-		private/src/driver_locator
+		src/activator
+		src/driver_locator
 )
 
 install_bundle(driver_locator)
+target_include_directories(driver_locator PRIVATE src)
+target_link_libraries(driver_locator PRIVATE Celix::device_access_api)
 
-include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
-include_directories(private/include)
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-
-target_link_libraries(driver_locator celix_utils celix_framework)
+#Setup target aliases to match external usage
+add_library(Celix::driver_locator ALIAS driver_locator)

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/private/include/driver_locator_private.h
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/private/include/driver_locator_private.h b/device_access/driver_locator/private/include/driver_locator_private.h
deleted file mode 100644
index bf6dcbf..0000000
--- a/device_access/driver_locator/private/include/driver_locator_private.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- *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.
- */
-/*
- * driver_locator_private.h
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#ifndef DRIVER_LOCATOR_PRIVATE_H_
-#define DRIVER_LOCATOR_PRIVATE_H_
-
-#include "driver_locator.h"
-
-struct driver_locator {
-    char *path;
-    array_list_pt drivers;
-};
-
-celix_status_t driverLocator_findDrivers(driver_locator_pt locator, properties_pt props, array_list_pt *drivers);
-celix_status_t driverLocator_loadDriver(driver_locator_pt locator, char *id, char **driver);
-
-#endif /* DRIVER_LOCATOR_PRIVATE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/private/src/activator.c
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/private/src/activator.c b/device_access/driver_locator/private/src/activator.c
deleted file mode 100644
index abc60c5..0000000
--- a/device_access/driver_locator/private/src/activator.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- *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.
- */
-/*
- * activator.c
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#include <stdlib.h>
-
-#include "bundle_activator.h"
-#include "bundle_context.h"
-#include "driver_locator_private.h"
-
-static const char *DEFAULT_LOCATOR_PATH = "drivers";
-
-struct bundle_instance {
-	driver_locator_service_pt service;
-	driver_locator_pt locator;
-	service_registration_pt locatorRegistration;
-};
-
-typedef struct bundle_instance *bundle_instance_pt;
-
-celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
-	celix_status_t status = CELIX_SUCCESS;
-	(*userData) = calloc(1, sizeof(struct bundle_instance));
-	if ( (*userData) == NULL ){
-		status = CELIX_ENOMEM;
-	}
-    return status;
-}
-
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-    bundle_instance_pt bi = (bundle_instance_pt)userData;
-
-    bi->service = calloc(1, sizeof(*(bi->service)));
-    bi->locator = calloc(1, sizeof(*(bi->locator)));
-    if(bi->service != NULL && bi->locator != NULL){
-	bi->service->findDrivers = driverLocator_findDrivers;
-	bi->service->loadDriver = driverLocator_loadDriver;
-
-	bi->service->locator = bi->locator;
-	bi->locator->drivers = NULL;
-	arrayList_create(&bi->locator->drivers);
-	bundleContext_getProperty(context, "DRIVER_LOCATOR_PATH", (const char**)&bi->locator->path);
-	if (bi->locator->path == NULL ) {
-		bi->locator->path = (char *)DEFAULT_LOCATOR_PATH;
-	}
-	status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_LOCATOR_SERVICE_NAME, bi->service, NULL, &bi->locatorRegistration);
-    }
-    else{
-	if(bi->service!=NULL) free(bi->service);
-	if(bi->locator!=NULL) free(bi->locator);
-	status = CELIX_ENOMEM;
-    }
-
-    return status;
-}
-
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
-    celix_status_t status = CELIX_SUCCESS;
-    bundle_instance_pt bi = (bundle_instance_pt)userData;
-    serviceRegistration_unregister(bi->locatorRegistration);
-    arrayList_destroy(bi->locator->drivers);
-    return status;
-}
-
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
-    return CELIX_SUCCESS;
-}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/private/src/driver_locator.c
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/private/src/driver_locator.c b/device_access/driver_locator/private/src/driver_locator.c
deleted file mode 100644
index 9c360bf..0000000
--- a/device_access/driver_locator/private/src/driver_locator.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- *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.
- */
-/*
- * driver_locator.c
- *
- *  \date       Jun 20, 2011
- *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- *  \copyright	Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-
-#include "driver_locator_private.h"
-#include "device.h"
-
-celix_status_t driverLocator_findDrivers(driver_locator_pt locator, properties_pt props, array_list_pt *drivers) {
-	celix_status_t status = CELIX_SUCCESS;
-
-	const char* category = properties_get(props, OSGI_DEVICEACCESS_DEVICE_CATEGORY);
-
-	status = arrayList_create(drivers);
-	if (status == CELIX_SUCCESS) {
-		DIR *dir;
-		dir = opendir(locator->path);
-		if (!dir) {
-			status = CELIX_FILE_IO_EXCEPTION;
-		} else {
-			struct dirent *dp;
-			while ((dp = readdir(dir)) != NULL) {
-				char str1[256], str2[256], str3[256];
-				if (sscanf(dp->d_name, "%[^_]_%[^.].%s", str1, str2, str3) == 3 &&
-					strcmp(str1, category) == 0 &&
-					strcmp(str3, "zip") == 0) {
-					int length = strlen(str1) + strlen(str2) + 2;
-					char driver[length];
-					snprintf(driver, length, "%s_%s", str1, str2);
-                    arrayList_add(*drivers, strdup(driver));
-				}
-			}
-			closedir(dir);
-		}
-	}
-	return status;
-}
-
-celix_status_t driverLocator_loadDriver(driver_locator_pt locator, char *id, char **stream) {
-	celix_status_t status = CELIX_SUCCESS;
-	*stream = NULL;
-
-	DIR *dir;
-	dir = opendir(locator->path);
-	if (!dir) {
-		status = CELIX_FILE_IO_EXCEPTION;
-	} else {
-		struct dirent *dp;
-		while ((dp = readdir(dir)) != NULL) {
-			char str1[256], str2[256];
-			if (sscanf(dp->d_name, "%[^.].%s", str1, str2) == 2 &&
-				strcmp(str1, id) == 0 &&
-				strcmp(str2, "zip") == 0) {
-				int length = strlen(locator->path) + strlen(dp->d_name) + 2;
-				char stream_str[length];
-				snprintf(stream_str, length, "%s/%s", locator->path, dp->d_name);
-				*stream = strdup(stream_str);
-				break;
-			}
-		}
-		closedir(dir);
-	}
-
-	return status;
-}
-

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/src/activator.c
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/src/activator.c b/device_access/driver_locator/src/activator.c
new file mode 100644
index 0000000..abc60c5
--- /dev/null
+++ b/device_access/driver_locator/src/activator.c
@@ -0,0 +1,89 @@
+/**
+ *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.
+ */
+/*
+ * activator.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "driver_locator_private.h"
+
+static const char *DEFAULT_LOCATOR_PATH = "drivers";
+
+struct bundle_instance {
+	driver_locator_service_pt service;
+	driver_locator_pt locator;
+	service_registration_pt locatorRegistration;
+};
+
+typedef struct bundle_instance *bundle_instance_pt;
+
+celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
+	celix_status_t status = CELIX_SUCCESS;
+	(*userData) = calloc(1, sizeof(struct bundle_instance));
+	if ( (*userData) == NULL ){
+		status = CELIX_ENOMEM;
+	}
+    return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+    bundle_instance_pt bi = (bundle_instance_pt)userData;
+
+    bi->service = calloc(1, sizeof(*(bi->service)));
+    bi->locator = calloc(1, sizeof(*(bi->locator)));
+    if(bi->service != NULL && bi->locator != NULL){
+	bi->service->findDrivers = driverLocator_findDrivers;
+	bi->service->loadDriver = driverLocator_loadDriver;
+
+	bi->service->locator = bi->locator;
+	bi->locator->drivers = NULL;
+	arrayList_create(&bi->locator->drivers);
+	bundleContext_getProperty(context, "DRIVER_LOCATOR_PATH", (const char**)&bi->locator->path);
+	if (bi->locator->path == NULL ) {
+		bi->locator->path = (char *)DEFAULT_LOCATOR_PATH;
+	}
+	status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_LOCATOR_SERVICE_NAME, bi->service, NULL, &bi->locatorRegistration);
+    }
+    else{
+	if(bi->service!=NULL) free(bi->service);
+	if(bi->locator!=NULL) free(bi->locator);
+	status = CELIX_ENOMEM;
+    }
+
+    return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+    celix_status_t status = CELIX_SUCCESS;
+    bundle_instance_pt bi = (bundle_instance_pt)userData;
+    serviceRegistration_unregister(bi->locatorRegistration);
+    arrayList_destroy(bi->locator->drivers);
+    return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+    return CELIX_SUCCESS;
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/src/driver_locator.c
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/src/driver_locator.c b/device_access/driver_locator/src/driver_locator.c
new file mode 100644
index 0000000..9c360bf
--- /dev/null
+++ b/device_access/driver_locator/src/driver_locator.c
@@ -0,0 +1,91 @@
+/**
+ *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.
+ */
+/*
+ * driver_locator.c
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+
+#include "driver_locator_private.h"
+#include "device.h"
+
+celix_status_t driverLocator_findDrivers(driver_locator_pt locator, properties_pt props, array_list_pt *drivers) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	const char* category = properties_get(props, OSGI_DEVICEACCESS_DEVICE_CATEGORY);
+
+	status = arrayList_create(drivers);
+	if (status == CELIX_SUCCESS) {
+		DIR *dir;
+		dir = opendir(locator->path);
+		if (!dir) {
+			status = CELIX_FILE_IO_EXCEPTION;
+		} else {
+			struct dirent *dp;
+			while ((dp = readdir(dir)) != NULL) {
+				char str1[256], str2[256], str3[256];
+				if (sscanf(dp->d_name, "%[^_]_%[^.].%s", str1, str2, str3) == 3 &&
+					strcmp(str1, category) == 0 &&
+					strcmp(str3, "zip") == 0) {
+					int length = strlen(str1) + strlen(str2) + 2;
+					char driver[length];
+					snprintf(driver, length, "%s_%s", str1, str2);
+                    arrayList_add(*drivers, strdup(driver));
+				}
+			}
+			closedir(dir);
+		}
+	}
+	return status;
+}
+
+celix_status_t driverLocator_loadDriver(driver_locator_pt locator, char *id, char **stream) {
+	celix_status_t status = CELIX_SUCCESS;
+	*stream = NULL;
+
+	DIR *dir;
+	dir = opendir(locator->path);
+	if (!dir) {
+		status = CELIX_FILE_IO_EXCEPTION;
+	} else {
+		struct dirent *dp;
+		while ((dp = readdir(dir)) != NULL) {
+			char str1[256], str2[256];
+			if (sscanf(dp->d_name, "%[^.].%s", str1, str2) == 2 &&
+				strcmp(str1, id) == 0 &&
+				strcmp(str2, "zip") == 0) {
+				int length = strlen(locator->path) + strlen(dp->d_name) + 2;
+				char stream_str[length];
+				snprintf(stream_str, length, "%s/%s", locator->path, dp->d_name);
+				*stream = strdup(stream_str);
+				break;
+			}
+		}
+		closedir(dir);
+	}
+
+	return status;
+}
+

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/driver_locator/src/driver_locator_private.h
----------------------------------------------------------------------
diff --git a/device_access/driver_locator/src/driver_locator_private.h b/device_access/driver_locator/src/driver_locator_private.h
new file mode 100644
index 0000000..bf6dcbf
--- /dev/null
+++ b/device_access/driver_locator/src/driver_locator_private.h
@@ -0,0 +1,39 @@
+/**
+ *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.
+ */
+/*
+ * driver_locator_private.h
+ *
+ *  \date       Jun 20, 2011
+ *  \author    	<a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
+ *  \copyright	Apache License, Version 2.0
+ */
+#ifndef DRIVER_LOCATOR_PRIVATE_H_
+#define DRIVER_LOCATOR_PRIVATE_H_
+
+#include "driver_locator.h"
+
+struct driver_locator {
+    char *path;
+    array_list_pt drivers;
+};
+
+celix_status_t driverLocator_findDrivers(driver_locator_pt locator, properties_pt props, array_list_pt *drivers);
+celix_status_t driverLocator_loadDriver(driver_locator_pt locator, char *id, char **driver);
+
+#endif /* DRIVER_LOCATOR_PRIVATE_H_ */

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/example/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/device_access/example/CMakeLists.txt b/device_access/example/CMakeLists.txt
index 1a5cd77..e21e5e0 100644
--- a/device_access/example/CMakeLists.txt
+++ b/device_access/example/CMakeLists.txt
@@ -22,7 +22,7 @@ if(DEVICE_ACCESS_EXAMPLE)
 	add_subdirectory(refining_driver)
 
     add_deploy(device_access_example
-        BUNDLES device_manager driver_locator shell shell_tui log_service base_driver
+        BUNDLES Celix::device_manager Celix::driver_locator Celix::shell Celix::shell_tui log_service base_driver
     )
 
     deploy_bundles_dir(device_access_example

http://git-wip-us.apache.org/repos/asf/celix/blob/a1c30887/device_access/example/base_driver/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/device_access/example/base_driver/CMakeLists.txt b/device_access/example/base_driver/CMakeLists.txt
index c354d3b..49096a6 100644
--- a/device_access/example/base_driver/CMakeLists.txt
+++ b/device_access/example/base_driver/CMakeLists.txt
@@ -20,14 +20,9 @@ add_bundle(base_driver
  	VERSION "0.0.1"
  	NAME "Apache Celix Device Access Base Driver Example"
 	SOURCES
-		private/src/activator
-		private/src/base_driver
+		src/activator
+		src/base_driver
 )
-
-include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
-include_directories(private/include)
-include_directories(public/include)
-include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
-include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
-
-target_link_libraries(base_driver celix_utils celix_framework)
+target_include_directories(base_driver PRIVATE src)
+target_include_directories(base_driver PUBLIC include)
+target_link_libraries(base_driver PRIVATE Celix::device_access_api)