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 2012/06/20 10:41:28 UTC

svn commit: r1351992 [1/2] - in /incubator/celix/trunk: ./ device_access/ device_access/device_access/ device_access/device_access/META-INF/ device_access/device_access/private/ device_access/device_access/private/include/ device_access/device_access/p...

Author: pnoltes
Date: Wed Jun 20 08:41:25 2012
New Revision: 1351992

URL: http://svn.apache.org/viewvc?rev=1351992&view=rev
Log:
CELIX-29: Added Device Access.

Added:
    incubator/celix/trunk/device_access/
    incubator/celix/trunk/device_access/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/device_access/
    incubator/celix/trunk/device_access/device_access/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/device_access/META-INF/
    incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF   (with props)
    incubator/celix/trunk/device_access/device_access/private/
    incubator/celix/trunk/device_access/device_access/private/include/
    incubator/celix/trunk/device_access/device_access/private/include/device_manager.h   (with props)
    incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h   (with props)
    incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h   (with props)
    incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h   (with props)
    incubator/celix/trunk/device_access/device_access/private/src/
    incubator/celix/trunk/device_access/device_access/private/src/activator.c   (with props)
    incubator/celix/trunk/device_access/device_access/private/src/device_manager.c   (with props)
    incubator/celix/trunk/device_access/device_access/private/src/driver_attributes.c   (with props)
    incubator/celix/trunk/device_access/device_access/private/src/driver_loader.c   (with props)
    incubator/celix/trunk/device_access/device_access/private/src/driver_matcher.c   (with props)
    incubator/celix/trunk/device_access/device_access/public/
    incubator/celix/trunk/device_access/device_access/public/include/
    incubator/celix/trunk/device_access/device_access/public/include/device.h   (with props)
    incubator/celix/trunk/device_access/device_access/public/include/driver.h   (with props)
    incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h   (with props)
    incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h   (with props)
    incubator/celix/trunk/device_access/device_access/public/include/match.h   (with props)
    incubator/celix/trunk/device_access/driver_locator/
    incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/driver_locator/META-INF/
    incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF   (with props)
    incubator/celix/trunk/device_access/driver_locator/private/
    incubator/celix/trunk/device_access/driver_locator/private/include/
    incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h   (with props)
    incubator/celix/trunk/device_access/driver_locator/private/src/
    incubator/celix/trunk/device_access/driver_locator/private/src/activator.c   (with props)
    incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c   (with props)
    incubator/celix/trunk/device_access/example/
    incubator/celix/trunk/device_access/example/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/example/base_driver/
    incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/example/base_driver/META-INF/
    incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF   (with props)
    incubator/celix/trunk/device_access/example/base_driver/README.txt   (with props)
    incubator/celix/trunk/device_access/example/base_driver/private/
    incubator/celix/trunk/device_access/example/base_driver/private/include/
    incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h   (with props)
    incubator/celix/trunk/device_access/example/base_driver/private/src/
    incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c   (with props)
    incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c   (with props)
    incubator/celix/trunk/device_access/example/base_driver/public/
    incubator/celix/trunk/device_access/example/base_driver/public/include/
    incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/
    incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/META-INF/
    incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/README.txt   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/private/
    incubator/celix/trunk/device_access/example/consuming_driver/private/include/
    incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/private/src/
    incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c   (with props)
    incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/
    incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/META-INF/
    incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/README.txt   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/private/
    incubator/celix/trunk/device_access/example/refining_driver/private/include/
    incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/private/src/
    incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c   (with props)
    incubator/celix/trunk/device_access/example/refining_driver/public/
    incubator/celix/trunk/device_access/example/refining_driver/public/include/
    incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h   (with props)
Modified:
    incubator/celix/trunk/CMakeLists.txt

Modified: incubator/celix/trunk/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/CMakeLists.txt?rev=1351992&r1=1351991&r2=1351992&view=diff
==============================================================================
--- incubator/celix/trunk/CMakeLists.txt (original)
+++ incubator/celix/trunk/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -61,5 +61,7 @@ add_subdirectory(remote_services)
 
 add_subdirectory(deployment_admin)
 
+add_subdirectory(device_access)
+
 include(target.cmake)
 #enable_testing()

Added: incubator/celix/trunk/device_access/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,27 @@
+# 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.
+
+link_directories("${PROJECT_SOURCE_DIR}/framework/lib")
+
+
+add_subdirectory(device_access)
+add_subdirectory(driver_locator)
+
+add_subdirectory(example)
+
+deploy("device_access_example" BUNDLES device_manager driver_locator shell shell_tui log_service base_driver)
+

Propchange: incubator/celix/trunk/device_access/CMakeLists.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/device_access/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,32 @@
+# 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(FindAPR)
+
+bundle(device_manager SOURCES 
+	private/src/activator
+	private/src/driver_attributes 
+	private/src/device_manager
+	private/src/driver_loader
+	private/src/driver_matcher)
+
+include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+
+include_directories("public/include")
+include_directories("private/include")
+
+target_link_libraries(device_manager ${CELIX_LIBRARY} ${UTILS_LIBRARY} ${APR_LIBRARY})

Propchange: incubator/celix/trunk/device_access/device_access/CMakeLists.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF (added)
+++ incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF Wed Jun 20 08:41:25 2012
@@ -0,0 +1,5 @@
+Bundle-SymbolicName: device_manager
+Bundle-Version: 1.0.0.test
+library: device_manager
+Export-Service: device,driver
+Import-Service: device,driver

Propchange: incubator/celix/trunk/device_access/device_access/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/private/include/device_manager.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/include/device_manager.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/include/device_manager.h (added)
+++ incubator/celix/trunk/device_access/device_access/private/include/device_manager.h Wed Jun 20 08:41:25 2012
@@ -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.
+ */
+
+#ifndef DEVICE_MANAGER_H_
+#define DEVICE_MANAGER_H_
+
+#include "driver_loader.h"
+
+typedef struct device_manager *device_manager_t;
+
+celix_status_t deviceManager_create(apr_pool_t *pool, BUNDLE_CONTEXT context, device_manager_t *manager);
+celix_status_t deviceManager_destroy(device_manager_t manager);
+
+celix_status_t deviceManager_matchAttachDriver(device_manager_t manager, apr_pool_t *attachPool, driver_loader_t loader,
+			ARRAY_LIST driverIds, ARRAY_LIST included, ARRAY_LIST excluded, void *service, SERVICE_REFERENCE reference);
+celix_status_t deviceManager_noDriverFound(device_manager_t manager, void *service, SERVICE_REFERENCE reference);
+
+celix_status_t deviceManager_locatorAdded(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_locatorModified(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_locatorRemoved(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_deviceAdded(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_deviceModified(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_deviceRemoved(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_driverAdded(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_driverModified(void * handle, SERVICE_REFERENCE ref, void * service);
+celix_status_t deviceManager_driverRemoved(void * handle, SERVICE_REFERENCE ref, void * service);
+
+celix_status_t deviceManager_getBundleContext(device_manager_t manager, BUNDLE_CONTEXT *context);
+
+// celix_status_t deviceManager_match(device_manager_t manager, ...);
+
+#endif /* DEVICE_MANAGER_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/private/include/device_manager.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h (added)
+++ incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h Wed Jun 20 08:41:25 2012
@@ -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.
+ */
+
+#ifndef DRIVER_ATTRIBUTES_H_
+#define DRIVER_ATTRIBUTES_H_
+
+#include "driver.h"
+
+typedef struct driver_attributes *driver_attributes_t;
+
+celix_status_t driverAttributes_create(apr_pool_t *pool, SERVICE_REFERENCE reference, driver_service_t driver, driver_attributes_t *attributes);
+
+celix_status_t driverAttributes_getReference(driver_attributes_t driverAttributes, SERVICE_REFERENCE *reference);
+celix_status_t driverAttributes_getDriverId(driver_attributes_t driverAttributes, char **driverId);
+
+celix_status_t driverAttributes_match(driver_attributes_t driverAttributes, SERVICE_REFERENCE reference, int *match);
+celix_status_t driverAttributes_attach(driver_attributes_t driverAttributes, SERVICE_REFERENCE reference, char **attach);
+
+celix_status_t driverAttributes_isInUse(driver_attributes_t driverAttributes, bool *inUse);
+
+celix_status_t driverAttributes_tryUninstall(driver_attributes_t driverAttributes);
+
+#endif /* DRIVER_ATTRIBUTES_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/private/include/driver_attributes.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h (added)
+++ incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,41 @@
+/**
+ *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.
+ */
+
+#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_t;
+
+celix_status_t driverLoader_create(apr_pool_t *pool, BUNDLE_CONTEXT context, driver_loader_t *loader);
+
+celix_status_t driverLoader_findDrivers(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, PROPERTIES properties, ARRAY_LIST *driversIds);
+celix_status_t driverLoader_findDriversForLocator(driver_loader_t loader, apr_pool_t *pool, driver_locator_service_t locator, PROPERTIES properties, ARRAY_LIST *driversIds);
+
+celix_status_t driverLoader_loadDrivers(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, ARRAY_LIST driverIds, ARRAY_LIST *references);
+celix_status_t driverLoader_loadDriver(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, char *driverId, ARRAY_LIST *references);
+celix_status_t driverLoader_loadDriverForLocator(driver_loader_t loader, apr_pool_t *pool, driver_locator_service_t locator, char *driverId, ARRAY_LIST *references);
+
+celix_status_t driverLoader_unloadDrivers(driver_loader_t loader, driver_attributes_t finalDriver);
+
+#endif /* DRIVER_LOADER_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/private/include/driver_loader.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h (added)
+++ incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,35 @@
+/**
+ *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.
+ */
+
+#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_t;
+
+celix_status_t driverMatcher_create(apr_pool_t *pool, BUNDLE_CONTEXT context, driver_matcher_t *matcher);
+
+celix_status_t driverMatcher_add(driver_matcher_t matcher, int match, driver_attributes_t attributes);
+
+celix_status_t driverMatcher_getBestMatch(driver_matcher_t matcher, apr_pool_t *pool, SERVICE_REFERENCE reference, match_t *match);
+
+#endif /* DRIVER_MATCHER_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/private/include/driver_matcher.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/src/activator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/src/activator.c (added)
+++ incubator/celix/trunk/device_access/device_access/private/src/activator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,188 @@
+/**
+ *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 <apr_strings.h>
+
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.h>
+#include <service_tracker.h>
+
+#include "driver_locator.h"
+#include "device_manager.h"
+
+struct device_manager_bundle_instance {
+	BUNDLE_CONTEXT context;
+	apr_pool_t *pool;
+	device_manager_t deviceManager;
+	SERVICE_TRACKER driverLocatorTracker;
+	SERVICE_TRACKER driverTracker;
+	SERVICE_TRACKER deviceTracker;
+};
+
+typedef struct device_manager_bundle_instance *device_manager_bundle_instance_t;
+
+static celix_status_t deviceManagerBundle_createDriverLocatorTracker(device_manager_bundle_instance_t bundleData);
+static celix_status_t deviceManagerBundle_createDriverTracker(device_manager_bundle_instance_t bundleData);
+static celix_status_t deviceManagerBundle_createDeviceTracker(device_manager_bundle_instance_t bundleData);
+
+celix_status_t addingService_dummy_func(void * handle, SERVICE_REFERENCE reference, void **service) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_t dm = handle;
+	BUNDLE_CONTEXT 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 context, void **userData) {
+	celix_status_t status = CELIX_SUCCESS;
+	apr_pool_t *pool;
+	status = bundleContext_getMemoryPool(context, &pool);
+	if (status == CELIX_SUCCESS) {
+		device_manager_bundle_instance_t bi = apr_palloc(pool, sizeof(struct device_manager_bundle_instance));
+		if (bi == NULL) {
+			status = CELIX_ENOMEM;
+		} else {
+			(*userData) = bi;
+			bi->context = context;
+			bi->pool = pool;
+			status = deviceManager_create(pool, context, &bi->deviceManager);
+		}
+	}
+	return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_t bundleData = userData;
+	apr_pool_t *pool;
+	status = bundleContext_getMemoryPool(context, &pool);
+	if (status == CELIX_SUCCESS) {
+		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) {
+		printf("DEVICE_MANAGER: Error while starting bundle got error num %i\n", status);
+	}
+
+	printf("DEVICE_MANAGER: Started\n");
+	return status;
+}
+
+static celix_status_t deviceManagerBundle_createDriverLocatorTracker(device_manager_bundle_instance_t bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_TRACKER_CUSTOMIZER customizer = apr_palloc(bundleData->pool, sizeof(struct serviceTrackerCustomizer));
+	if (customizer != NULL) {
+		customizer->handle=bundleData->deviceManager;
+		customizer->addingService=addingService_dummy_func;
+		customizer->addedService=deviceManager_locatorAdded;
+		customizer->modifiedService=deviceManager_locatorModified;
+		customizer->removedService=deviceManager_locatorRemoved;
+
+		SERVICE_TRACKER tracker = NULL;
+		status = serviceTracker_create(bundleData->pool, 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_t bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_TRACKER_CUSTOMIZER customizer = apr_palloc(bundleData->pool, sizeof(struct serviceTrackerCustomizer));
+	if (customizer != NULL) {
+		customizer->handle=bundleData->deviceManager;
+		customizer->addingService=addingService_dummy_func;
+		customizer->addedService=deviceManager_driverAdded;
+		customizer->modifiedService=deviceManager_driverModified;
+		customizer->removedService=deviceManager_driverRemoved;
+
+		SERVICE_TRACKER tracker = NULL;
+		status = serviceTracker_createWithFilter(bundleData->pool, 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_t bundleData) {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_TRACKER_CUSTOMIZER customizer = apr_palloc(bundleData->pool, sizeof(struct serviceTrackerCustomizer));
+	if (customizer != NULL) {
+		customizer->handle=bundleData->deviceManager;
+		customizer->addingService=addingService_dummy_func;
+		customizer->addedService= deviceManager_deviceAdded;
+		customizer->modifiedService=deviceManager_deviceModified;
+		customizer->removedService=deviceManager_deviceRemoved;
+
+		SERVICE_TRACKER tracker = NULL;
+		status = serviceTracker_createWithFilter(bundleData->pool, 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 context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_t 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 context) {
+	celix_status_t status = CELIX_SUCCESS;
+	device_manager_bundle_instance_t bundleData = userData;
+	deviceManager_destroy(bundleData->deviceManager);
+	return CELIX_SUCCESS;
+}

Propchange: incubator/celix/trunk/device_access/device_access/private/src/activator.c
------------------------------------------------------------------------------
    svn:executable = *

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

Added: incubator/celix/trunk/device_access/device_access/private/src/device_manager.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/src/device_manager.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/src/device_manager.c (added)
+++ incubator/celix/trunk/device_access/device_access/private/src/device_manager.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,586 @@
+/**
+ *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 <constants.h>
+#include <apr_general.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 <bundle.h>
+#include <module.h>
+#include <array_list.h>
+#include <service_registry.h>
+#include <service_reference.h>
+
+struct device_manager {
+	apr_pool_t *pool;
+	BUNDLE_CONTEXT context;
+	HASH_MAP devices;
+	HASH_MAP drivers;
+	ARRAY_LIST locators;
+	driver_selector_service_t selector;
+};
+
+static celix_status_t deviceManager_attachAlgorithm(device_manager_t manager, SERVICE_REFERENCE ref, void *service);
+static celix_status_t deviceManager_getIdleDevices(device_manager_t manager, apr_pool_t *pool, ARRAY_LIST *idleDevices);
+static celix_status_t deviceManager_isDriverBundle(device_manager_t manager, BUNDLE bundle, bool *isDriver);
+
+celix_status_t deviceManager_create(apr_pool_t *pool, BUNDLE_CONTEXT context, device_manager_t *manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*manager = apr_palloc(pool, sizeof(**manager));
+	if (!*manager) {
+		status = CELIX_ENOMEM;
+	} else {
+		(*manager)->pool = pool;
+		(*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);
+		status = arrayList_create((*manager)->pool, &(*manager)->locators);
+	}
+
+	printf("DEVICE_MANAGER: Initialized\n");
+	return status;
+}
+
+celix_status_t deviceManager_destroy(device_manager_t manager) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	printf("DEVICE_MANAGER: Stop\n");
+	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 ref, void * service) {
+	printf("DEVICE_MANAGER: Add selector\n");
+	device_manager_t manager = handle;
+	manager->selector = (driver_selector_service_t) service;
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_selectorModified(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Modify selector\n");
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_selectorRemoved(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Remove selector\n");
+	device_manager_t manager = handle;
+	manager->selector = NULL;
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorAdded(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Add locator\n");
+	device_manager_t manager = handle;
+	arrayList_add(manager->locators, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorModified(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Modify locator\n");
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_locatorRemoved(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Remove locator\n");
+	device_manager_t manager = handle;
+	arrayList_removeElement(manager->locators, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_deviceAdded(void * handle, SERVICE_REFERENCE ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+	printf("DEVICE_MANAGER: Add device\n");
+	device_manager_t manager = handle;
+
+	status = deviceManager_attachAlgorithm(manager, ref, service);
+
+	return status;
+}
+
+static celix_status_t deviceManager_attachAlgorithm(device_manager_t manager, SERVICE_REFERENCE ref, void *service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	apr_pool_t *attachPool = NULL;
+	apr_status_t aprStatus = apr_pool_create(&attachPool, manager->pool);
+	if (aprStatus != APR_SUCCESS) {
+		status = CELIX_ILLEGAL_STATE;
+	} else {
+		driver_loader_t loader = NULL;
+		status = driverLoader_create(attachPool, manager->context, &loader);
+		if (status == CELIX_SUCCESS) {
+			ARRAY_LIST included = NULL;
+			ARRAY_LIST excluded = NULL;
+
+			ARRAY_LIST driverIds = NULL;
+
+			hashMap_put(manager->devices, ref, service);
+
+			status = arrayList_create(attachPool, &included);
+			if (status == CELIX_SUCCESS) {
+				status = arrayList_create(attachPool, &excluded);
+				if (status == CELIX_SUCCESS) {
+					SERVICE_REGISTRATION registration = NULL;
+					status = serviceReference_getServiceRegistration(ref, &registration);
+					if (status == CELIX_SUCCESS) {
+						PROPERTIES properties = NULL;
+						status = serviceRegistration_getProperties(registration, &properties);
+						if (status == CELIX_SUCCESS) {
+							status = driverLoader_findDrivers(loader, attachPool, manager->locators, properties, &driverIds);
+							if (status == CELIX_SUCCESS) {
+								HASH_MAP_ITERATOR iter = hashMapIterator_create(manager->drivers);
+								while (hashMapIterator_hasNext(iter)) {
+									driver_attributes_t 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 idsIter = arrayListIterator_create(driverIds);
+										while (arrayListIterator_hasNext(idsIter)) {
+											char *value = arrayListIterator_next(idsIter);
+											if (strcmp(value, id) == 0) {
+												arrayListIterator_remove(idsIter);
+											}
+										}
+										arrayListIterator_destroy(idsIter);
+									} else {
+										// Ignore
+									}
+								}
+								hashMapIterator_destroy(iter);
+
+								status = deviceManager_matchAttachDriver(manager, attachPool, loader, driverIds, included, excluded, service, ref);
+								arrayList_destroy(driverIds);
+							}
+						}
+					}
+					arrayList_destroy(excluded);
+				}
+				arrayList_destroy(included);
+			}
+
+		}
+		apr_pool_destroy(attachPool);
+	}
+	return status;
+}
+
+celix_status_t deviceManager_matchAttachDriver(device_manager_t manager, apr_pool_t *attachPool, driver_loader_t loader,
+		ARRAY_LIST driverIds, ARRAY_LIST included, ARRAY_LIST excluded, void *service, SERVICE_REFERENCE reference) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	ARRAY_LIST 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);
+		printf("DEVICE_MANAGER: Driver found: %s\n", id);
+	}
+
+	status = driverLoader_loadDrivers(loader, attachPool, manager->locators, driverIds, &references);
+	if (status == CELIX_SUCCESS) {
+		for (i = 0; i < arrayList_size(references); i++) {
+			SERVICE_REFERENCE reference = arrayList_get(references, i);
+			driver_attributes_t attributes = hashMap_get(manager->drivers, reference);
+			if (attributes != NULL) {
+				arrayList_add(included, attributes);
+			}
+		}
+
+		driver_matcher_t matcher = NULL;
+		status = driverMatcher_create(attachPool, manager->context, &matcher);
+		if (status == CELIX_SUCCESS) {
+			for (i = 0; i < arrayList_size(included); i++) {
+				driver_attributes_t attributes = arrayList_get(included, i);
+
+				int match = 0;
+				celix_status_t substatus = driverAttributes_match(attributes, reference, &match);
+				if (substatus == CELIX_SUCCESS) {
+					printf("DEVICE_MANAGER: Found match: %d\n", match);
+					if (match <= DEVICE_MATCH_NONE) {
+						continue;
+					}
+					driverMatcher_add(matcher, match, attributes);
+				} else {
+					// Ignore
+				}
+			}
+
+			match_t match = NULL;
+			status = driverMatcher_getBestMatch(matcher, attachPool, reference, &match);
+			if (status == CELIX_SUCCESS) {
+				if (match == NULL) {
+					status = deviceManager_noDriverFound(manager, service, reference);
+				} else {
+					SERVICE_REGISTRATION registration = NULL;
+					status = serviceReference_getServiceRegistration(match->reference, &registration);
+					if (status == CELIX_SUCCESS) {
+						PROPERTIES properties = NULL;
+						status = serviceRegistration_getProperties(registration, &properties);
+						if (status == CELIX_SUCCESS) {
+							char *driverId = properties_get(properties, (char *) DRIVER_ID);
+							driver_attributes_t 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 ids = NULL;
+										arrayList_create(attachPool, &ids);
+										arrayList_add(ids, newDriverId);
+										arrayList_add(excluded, finalAttributes);
+										status = deviceManager_matchAttachDriver(manager, attachPool, loader,
+												ids, included, excluded, service, reference);
+									} else {
+										// Attached, unload unused drivers
+										status = driverLoader_unloadDrivers(loader, finalAttributes);
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	if (references != NULL) {
+		arrayList_destroy(references);
+	}
+
+	return status;
+}
+
+celix_status_t deviceManager_noDriverFound(device_manager_t manager, void *service, SERVICE_REFERENCE reference) {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_REGISTRATION registration = NULL;
+	status = serviceReference_getServiceRegistration(reference, &registration);
+	if (status == CELIX_SUCCESS) {
+		PROPERTIES properties = NULL;
+		status = serviceRegistration_getProperties(registration, &properties);
+		if (status == CELIX_SUCCESS) {
+			char *objectClass = properties_get(properties, (char *) OBJECTCLASS);
+			if (strcmp(objectClass, DRIVER_SERVICE_NAME) == 0) {
+				device_service_t device = service;
+				status = device->noDriverFound(device->device);
+			}
+		}
+	}
+	return status;
+}
+
+celix_status_t deviceManager_deviceModified(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Modify device\n");
+	// #TODO the device properties could be changed
+	//device_manager_t manager = handle;
+	//hashMap_put(manager->devices, ref, service);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_deviceRemoved(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Remove device\n");
+	device_manager_t manager = handle;
+	hashMap_remove(manager->devices, ref);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_driverAdded(void * handle, SERVICE_REFERENCE ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	printf("DEVICE_MANAGER: Add driver\n");
+	device_manager_t manager = handle;
+	apr_pool_t *pool = NULL;
+	driver_attributes_t attributes = NULL;
+
+	status = apr_pool_create(&pool, manager->pool);
+	if (status == CELIX_SUCCESS) {
+		status = driverAttributes_create(pool, ref, service, &attributes);
+		if (status == CELIX_SUCCESS) {
+			hashMap_put(manager->drivers, ref, attributes);
+		}
+	}
+	return status;
+}
+
+celix_status_t deviceManager_driverModified(void * handle, SERVICE_REFERENCE ref, void * service) {
+	printf("DEVICE_MANAGER: Modify driver\n");
+	// #TODO the driver properties could be changed?
+	return CELIX_SUCCESS;
+}
+
+celix_status_t deviceManager_driverRemoved(void * handle, SERVICE_REFERENCE ref, void * service) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	printf("DEVICE_MANAGER: Remove driver\n");
+	device_manager_t manager = handle;
+	hashMap_remove(manager->drivers, ref);
+
+	apr_pool_t *idleCheckPool;
+	apr_status_t aprStatus = apr_pool_create(&idleCheckPool, manager->pool);
+	if (aprStatus != APR_SUCCESS) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		ARRAY_LIST idleDevices = NULL;
+		status = deviceManager_getIdleDevices(manager, idleCheckPool, &idleDevices);
+		if (status == CELIX_SUCCESS) {
+			int i;
+			for (i = 0; i < arrayList_size(idleDevices); i++) {
+				celix_status_t forStatus = CELIX_SUCCESS;
+				SERVICE_REFERENCE ref = arrayList_get(idleDevices, i);
+				char *bsn = NULL;
+				BUNDLE bundle = NULL;
+				forStatus = serviceReference_getBundle(ref, &bundle);
+				if (forStatus == CELIX_SUCCESS) {
+					MODULE module = NULL;
+					forStatus = bundle_getCurrentModule(bundle, &module);
+					if (forStatus == CELIX_SUCCESS) {
+						forStatus = module_getSymbolicName(module, &bsn);
+						if (forStatus == CELIX_SUCCESS) {
+							printf("DEVICE_MANAGER: IDLE: %s\n", 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 iter = hashMapIterator_create(manager->drivers);
+			while (hashMapIterator_hasNext(iter)) {
+				driver_attributes_t 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_t manager, apr_pool_t *pool, ARRAY_LIST *idleDevices) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = arrayList_create(pool, idleDevices);
+	if (status == CELIX_SUCCESS) {
+		HASH_MAP_ITERATOR iter = hashMapIterator_create(manager->devices);
+		while (hashMapIterator_hasNext(iter)) {
+			celix_status_t substatus = CELIX_SUCCESS;
+			SERVICE_REFERENCE ref = hashMapIterator_nextKey(iter);
+			char *bsn = NULL;
+			MODULE module = NULL;
+			BUNDLE 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) {
+						SERVICE_REGISTRATION registration = NULL;
+						substatus = serviceReference_getServiceRegistration(ref, &registration);
+						if (substatus == CELIX_SUCCESS) {
+							SERVICE_REGISTRY registry = NULL;
+							substatus = serviceRegistration_getRegistry(registration, &registry);
+							if (substatus == CELIX_SUCCESS) {
+								printf("DEVICE_MANAGER: Check idle device: %s\n", bsn);
+								ARRAY_LIST bundles = serviceRegistry_getUsingBundles(registry, pool, ref);
+								bool inUse = false;
+								int i;
+								for (i = 0; i < arrayList_size(bundles); i++) {
+									BUNDLE bundle = arrayList_get(bundles, i);
+									bool isDriver;
+									celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
+									if (sstatus == CELIX_SUCCESS) {
+										if (isDriver) {
+											char *bsn = NULL;
+											MODULE module = NULL;
+											bundle_getCurrentModule(bundle, &module);
+											module_getSymbolicName(module, &bsn);
+
+											printf("DEVICE_MANAGER: Not idle, used by driver: %s\n", bsn);
+
+											inUse = true;
+											break;
+										}
+									}
+								}
+
+								if (!inUse) {
+									arrayList_add(*idleDevices, ref);
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+		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_t manager, apr_pool_t *pool, ARRAY_LIST *idleDevices) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = arrayList_create(pool, idleDevices);
+	if (status == CELIX_SUCCESS) {
+		HASH_MAP_ITERATOR iter = hashMapIterator_create(manager->devices);
+		while (hashMapIterator_hasNext(iter)) {
+			celix_status_t substatus = CELIX_SUCCESS;
+			SERVICE_REFERENCE ref = hashMapIterator_nextKey(iter);
+			char *bsn = NULL;
+			MODULE module = NULL;
+			BUNDLE bundle = NULL;
+			SERVICE_REGISTRATION registration = NULL;
+			SERVICE_REGISTRY registry = 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_getServiceRegistration(ref, &registration));
+			substatus = DO_IF_SUCCESS(substatus, serviceRegistration_getRegistry(registration, &registry));
+
+			if (substatus == CELIX_SUCCESS) {
+				ARRAY_LIST bundles = serviceRegistry_getUsingBundles(registry, pool, ref);
+				printf("DEVICE_MANAGER: Check idle device: %s\n", bsn);
+				bool inUse = false;
+				int i;
+				for (i = 0; i < arrayList_size(bundles); i++) {
+					BUNDLE bundle = arrayList_get(bundles, i);
+					bool isDriver;
+					celix_status_t sstatus = deviceManager_isDriverBundle(manager, bundle, &isDriver);
+					if (sstatus == CELIX_SUCCESS) {
+						if (isDriver) {
+							char *bsn = NULL;
+							MODULE module = NULL;
+							bundle_getCurrentModule(bundle, &module);
+							module_getSymbolicName(module, &bsn);
+
+							printf("DEVICE_MANAGER: Not idle, used by driver: %s\n", bsn);
+
+							inUse = true;
+							break;
+						}
+					}
+				}
+
+				if (!inUse) {
+					arrayList_add(*idleDevices, ref);
+				}
+			}
+		}
+	}
+	return status;
+}
+
+celix_status_t deviceManager_isDriverBundle(device_manager_t manager, BUNDLE bundle, bool *isDriver) {
+	celix_status_t status = CELIX_SUCCESS;
+	(*isDriver) = false;
+
+	ARRAY_LIST refs = NULL;
+	apr_pool_t *pool = NULL;
+	status = bundle_getMemoryPool(bundle, &pool);
+	if (status == CELIX_SUCCESS) {
+		status = bundle_getRegisteredServices(bundle, pool, &refs);
+		if (status == CELIX_SUCCESS) {
+			if (refs != NULL) {
+				int i;
+				for (i = 0; i < arrayList_size(refs); i++) {
+					celix_status_t substatus = CELIX_SUCCESS;
+					SERVICE_REFERENCE ref = arrayList_get(refs, i);
+					SERVICE_REGISTRATION registration = NULL;
+					substatus = serviceReference_getServiceRegistration(ref, &registration);
+					if (substatus == CELIX_SUCCESS) {
+						PROPERTIES properties = NULL;
+						substatus = serviceRegistration_getProperties(registration, &properties);
+						if (substatus == CELIX_SUCCESS) {
+							char *object = properties_get(properties, (char *) OBJECTCLASS);
+																if (strcmp(object, "driver") == 0) {
+																	*isDriver = true;
+																	break;
+																}
+						}
+
+					}
+				}
+				arrayList_destroy(refs);
+			}
+		}
+
+	}
+
+	return status;
+}
+
+
+celix_status_t deviceManager_getBundleContext(device_manager_t manager, BUNDLE_CONTEXT *context) {
+	celix_status_t status = CELIX_SUCCESS;
+	if (manager->context != NULL) {
+		(*context) = manager->context;
+	} else {
+		status = CELIX_INVALID_BUNDLE_CONTEXT;
+	}
+	return status;
+}
+
+
+

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

Added: incubator/celix/trunk/device_access/device_access/private/src/driver_attributes.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/src/driver_attributes.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/src/driver_attributes.c (added)
+++ incubator/celix/trunk/device_access/device_access/private/src/driver_attributes.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,188 @@
+/**
+ *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 <apr_strings.h>
+
+#include "driver_attributes.h"
+#include "bundle.h"
+#include "celixbool.h"
+#include "driver_loader.h"
+#include "device.h"
+#include "constants.h"
+
+struct driver_attributes {
+	apr_pool_t *pool;
+
+	BUNDLE bundle;
+	SERVICE_REFERENCE reference;
+	driver_service_t driver;
+	bool dynamic;
+};
+
+celix_status_t driverAttributes_create(apr_pool_t *pool, SERVICE_REFERENCE reference, driver_service_t driver, driver_attributes_t *attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*attributes = apr_palloc(pool, sizeof(**attributes));
+	if (!*attributes) {
+		status = CELIX_ENOMEM;
+	} else {
+		BUNDLE bundle = NULL;
+		BUNDLE_ARCHIVE bundleArchive = NULL;
+		status = serviceReference_getBundle(reference, &bundle);
+
+		if (status == CELIX_SUCCESS) {
+			status = bundle_getArchive(bundle, &bundleArchive);
+
+			if (status == CELIX_SUCCESS) {
+				(*attributes)->pool = pool;
+				(*attributes)->reference = reference;
+				(*attributes)->driver = driver;
+				(*attributes)->bundle = bundle;
+
+				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_getReference(driver_attributes_t driverAttributes, SERVICE_REFERENCE *reference) {
+	*reference = driverAttributes->reference;
+
+	return CELIX_SUCCESS;
+}
+
+celix_status_t driverAttributes_getDriverId(driver_attributes_t driverAttributes, char **driverId) {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_REGISTRATION registration = NULL;
+	status = serviceReference_getServiceRegistration(driverAttributes->reference, &registration);
+
+	if (status == CELIX_SUCCESS) {
+		PROPERTIES properties = NULL;
+		status = serviceRegistration_getProperties(registration, &properties);
+
+		if (status == CELIX_SUCCESS) {
+			char *id_prop = properties_get(properties, "DRIVER_ID");
+
+			if (id_prop) {
+				status = CELIX_ENOMEM;
+			} else {
+				*driverId = apr_pstrdup(driverAttributes->pool,id_prop);
+
+				if (*driverId == NULL) {
+					status = CELIX_ENOMEM;
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverAttributes_match(driver_attributes_t driverAttributes, SERVICE_REFERENCE reference, int *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = driverAttributes->driver->match(driverAttributes->driver->driver, reference, match);
+
+	return status;
+}
+
+celix_status_t static get_property_from_registration(SERVICE_REFERENCE ref, char *key, char **prop_value)  {
+	celix_status_t status = CELIX_SUCCESS;
+	SERVICE_REGISTRATION registration = NULL;
+	status = serviceReference_getServiceRegistration(ref, &registration);
+
+	if (status == CELIX_SUCCESS) {
+		PROPERTIES properties = NULL;
+		status = serviceRegistration_getProperties(registration, &properties);
+
+		if (status == CELIX_SUCCESS) {
+			(*prop_value) = properties_get(properties, key);
+
+			if ((*prop_value == NULL)) {
+				status = CELIX_ENOMEM;
+			}
+		}
+	}
+
+	return status;
+}
+
+
+celix_status_t driverAttributes_isInUse(driver_attributes_t driverAttributes, bool *inUse) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	ARRAY_LIST 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 ref = arrayList_get(references, i);
+				char *object = NULL;
+				status = get_property_from_registration(ref, (char *) OBJECTCLASS, &object);
+
+				if (status == CELIX_SUCCESS) {
+					char *category = NULL;
+					status = get_property_from_registration(ref, "DEVICE_CATEGORY", &category);
+
+					if (status == CELIX_SUCCESS) {
+						if ((object != NULL && strcmp(object, DEVICE_SERVICE_NAME) == 0) || (category != NULL)) {
+							*inUse = true;
+						}
+					}
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverAttributes_attach(driver_attributes_t driverAttributes, SERVICE_REFERENCE 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_t 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;
+}

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

Added: incubator/celix/trunk/device_access/device_access/private/src/driver_loader.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/src/driver_loader.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/src/driver_loader.c (added)
+++ incubator/celix/trunk/device_access/device_access/private/src/driver_loader.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,214 @@
+/**
+ *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 <apr_general.h>
+#include <apr_strings.h>
+
+#include "driver_loader.h"
+#include "bundle_context.h"
+#include "bundle.h"
+
+struct driver_loader {
+	apr_pool_t *pool;
+
+	BUNDLE_CONTEXT context;
+	ARRAY_LIST loadedDrivers;
+};
+
+static apr_status_t driverLoader_destroy(void *loaderP);
+
+celix_status_t driverLoader_create(apr_pool_t *pool, BUNDLE_CONTEXT context, driver_loader_t *loader) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*loader = apr_palloc(pool, sizeof(**loader));
+	if (!*loader) {
+		status = CELIX_ENOMEM;
+	} else {
+		apr_pool_pre_cleanup_register(pool, *loader, driverLoader_destroy);
+
+		(*loader)->context = context;
+		(*loader)->loadedDrivers = NULL;
+		(*loader)->pool = pool;
+		status = arrayList_create(pool, &(*loader)->loadedDrivers);
+	}
+
+	return status;
+}
+
+apr_status_t driverLoader_destroy(void *loaderP) {
+	driver_loader_t matcher = loaderP;
+	arrayList_destroy(matcher->loadedDrivers);
+	return APR_SUCCESS;
+}
+
+celix_status_t driverLoader_findDrivers(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, PROPERTIES properties, ARRAY_LIST *driversIds) {
+	celix_status_t status = CELIX_SUCCESS;
+	arrayList_create(pool, driversIds);
+
+	int i;
+	for (i = 0; i < arrayList_size(locators); i++) {
+		ARRAY_LIST drivers;
+		driver_locator_service_t locator = arrayList_get(locators, i);
+
+		apr_pool_t *spool;
+		apr_status_t aprStatus = apr_pool_create(&spool, pool);
+		if (aprStatus != APR_SUCCESS) {
+			status = CELIX_ENOMEM;
+		} else {
+			status = driverLoader_findDriversForLocator(loader, spool, locator, properties, &drivers);
+			if (status == CELIX_SUCCESS) {
+				arrayList_addAll(*driversIds, drivers);
+			}
+			arrayList_destroy(drivers);
+			apr_pool_destroy(spool);
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_findDriversForLocator(driver_loader_t loader, apr_pool_t *pool, driver_locator_service_t locator, PROPERTIES properties, ARRAY_LIST *driversIds) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	status = locator->findDrivers(locator->locator, pool, properties, driversIds);
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDrivers(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, ARRAY_LIST driverIds, ARRAY_LIST *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	status = arrayList_create(pool, references);
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(driverIds); i++) {
+			ARRAY_LIST refs = NULL;
+			char *id = arrayList_get(driverIds, i);
+
+			apr_pool_t *spool;
+			apr_status_t aprStatus = apr_pool_create(&spool, pool);
+			if (aprStatus != APR_SUCCESS) {
+				status = CELIX_ENOMEM;
+			} else {
+				status = driverLoader_loadDriver(loader, pool, locators, id, &refs);
+				if (status == CELIX_SUCCESS) {
+					arrayList_addAll(*references, refs);
+				}
+				if (refs != NULL) {
+					arrayList_destroy(refs);
+				}
+				apr_pool_destroy(spool);
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDriver(driver_loader_t loader, apr_pool_t *pool, ARRAY_LIST locators, char *driverId, ARRAY_LIST *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	status = arrayList_create(pool, references);
+	if (status == CELIX_SUCCESS) {
+		int i;
+		for (i = 0; i < arrayList_size(locators); i++) {
+			ARRAY_LIST refs = NULL;
+			driver_locator_service_t locator = arrayList_get(locators, i);
+
+			apr_pool_t *spool;
+			apr_status_t aprStatus = apr_pool_create(&spool, pool);
+			if (aprStatus != APR_SUCCESS) {
+				status = CELIX_ENOMEM;
+			} else {
+				status = driverLoader_loadDriverForLocator(loader, pool, locator, driverId, &refs);
+				if (status == CELIX_SUCCESS) {
+					arrayList_addAll(*references, refs);
+				}
+				if (refs != NULL) {
+					arrayList_destroy(refs);
+				}
+			}
+			apr_pool_destroy(spool);
+
+
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_loadDriverForLocator(driver_loader_t loader, apr_pool_t *pool, driver_locator_service_t locator, char *driverId, ARRAY_LIST *references) {
+	celix_status_t status = CELIX_SUCCESS;
+	arrayList_create(loader->pool, references);
+
+	apr_pool_t *loadPool;
+	apr_status_t aprStatus = apr_pool_create(&loadPool, pool);
+	if (aprStatus != APR_SUCCESS) {
+		status = CELIX_ENOMEM;
+	} else {
+		char *filename = NULL;
+		status = locator->loadDriver(locator->locator, loadPool, driverId, &filename);
+		if (status == CELIX_SUCCESS) {
+			BUNDLE bundle = NULL;
+			apr_pool_t *bundlePool;
+			status = bundleContext_getMemoryPool(loader->context, &bundlePool);
+			if (status == CELIX_SUCCESS) {
+				char *location = apr_pstrcat(bundlePool, DRIVER_LOCATION_PREFIX, driverId, NULL);
+				status = bundleContext_installBundle2(loader->context, location, filename, &bundle);
+				if (status == CELIX_SUCCESS) {
+					status = bundle_start(bundle, 0);
+					if (status == CELIX_SUCCESS) {
+						status = bundle_getRegisteredServices(bundle, pool, references);
+						if (status == CELIX_SUCCESS) {
+							arrayList_addAll(loader->loadedDrivers, *references);
+						}
+					}
+				}
+			}
+		}
+		apr_pool_destroy(loadPool);
+	}
+
+	return status;
+}
+
+celix_status_t driverLoader_unloadDrivers(driver_loader_t loader, driver_attributes_t finalDriver) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	SERVICE_REFERENCE 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 reference = arrayList_get(loader->loadedDrivers, i);
+			bool equal = false;
+			status = serviceReference_equals(reference, finalReference, &equal);
+			if (status == CELIX_SUCCESS && !equal) {
+				BUNDLE bundle = NULL;
+				status = serviceReference_getBundle(reference, &bundle);
+				if (status == CELIX_SUCCESS) {
+					bundle_uninstall(bundle); // Ignore status
+				}
+			}
+		}
+	}
+
+	return status;
+}

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

Added: incubator/celix/trunk/device_access/device_access/private/src/driver_matcher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/private/src/driver_matcher.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/private/src/driver_matcher.c (added)
+++ incubator/celix/trunk/device_access/device_access/private/src/driver_matcher.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,247 @@
+/**
+ *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 "hash_map.h"
+#include "constants.h"
+
+#include "driver_matcher.h"
+
+struct driver_matcher {
+	apr_pool_t *pool;
+	HASH_MAP attributes;
+	 ARRAY_LIST matches;
+
+	 BUNDLE_CONTEXT context;
+};
+
+typedef struct match_key {
+	int matchValue;
+} *match_key_t;
+
+static apr_status_t driverMatcher_destroy(void *matcherP);
+static celix_status_t driverMatcher_get(driver_matcher_t matcher, int key, ARRAY_LIST *attributesV);
+static celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_t matcher, apr_pool_t *pool, match_t *match);
+
+unsigned int driverMatcher_matchKeyHash(void * match_key) {
+	match_key_t key = match_key;
+
+	return key->matchValue;
+}
+
+int driverMatcher_matchKeyEquals(void * key, void * toCompare) {
+	return ((match_key_t) key)->matchValue == ((match_key_t) toCompare)->matchValue;
+}
+
+celix_status_t driverMatcher_create(apr_pool_t *pool, BUNDLE_CONTEXT context, driver_matcher_t *matcher) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	*matcher = apr_palloc(pool, sizeof(**matcher));
+	if (!*matcher) {
+		status = CELIX_ENOMEM;
+	} else {
+		apr_pool_pre_cleanup_register(pool, *matcher, driverMatcher_destroy);
+
+		(*matcher)->pool = pool;
+		(*matcher)->matches = NULL;
+		(*matcher)->context = context;
+		(*matcher)->attributes = hashMap_create(driverMatcher_matchKeyHash, NULL, driverMatcher_matchKeyEquals, NULL);
+
+		arrayList_create(pool, &(*matcher)->matches);
+	}
+
+	return status;
+}
+
+apr_status_t driverMatcher_destroy(void *matcherP) {
+	driver_matcher_t matcher = matcherP;
+	arrayList_destroy(matcher->matches);
+	HASH_MAP_ITERATOR iter = hashMapIterator_create(matcher->attributes);
+	while (hashMapIterator_hasNext(iter)) {
+		ARRAY_LIST list = hashMapIterator_nextValue(iter);
+		if (list != NULL) {
+			arrayList_destroy(list);
+		}
+	}
+	hashMapIterator_destroy(iter);
+	hashMap_destroy(matcher->attributes, false, false);
+	return APR_SUCCESS;
+}
+
+celix_status_t driverMatcher_add(driver_matcher_t matcher, int matchValue, driver_attributes_t attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	ARRAY_LIST da = NULL;
+	status = driverMatcher_get(matcher, matchValue, &da);
+	if (status == CELIX_SUCCESS) {
+		arrayList_add(da, attributes);
+
+		match_t match = NULL;
+		match = apr_palloc(matcher->pool, 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_t matcher, int key, ARRAY_LIST *attributes) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	apr_pool_t *spool = NULL;
+	apr_pool_create(&spool, matcher->pool);
+
+	match_key_t matchKeyS = apr_palloc(spool, sizeof(*matchKeyS));
+	matchKeyS->matchValue = key;
+
+	*attributes = hashMap_get(matcher->attributes, matchKeyS);
+	if (*attributes == NULL) {
+		arrayList_create(matcher->pool, attributes);
+		match_key_t matchKey = apr_palloc(matcher->pool, sizeof(*matchKey));
+		matchKey->matchValue = key;
+		hashMap_put(matcher->attributes, matchKey, *attributes);
+	}
+
+	apr_pool_destroy(spool);
+
+	return status;
+}
+
+celix_status_t driverMatcher_getBestMatch(driver_matcher_t matcher, apr_pool_t *pool, SERVICE_REFERENCE reference, match_t *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (*match != NULL) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	} else {
+		SERVICE_REFERENCE selectorRef = NULL;
+		status = bundleContext_getServiceReference(matcher->context, DRIVER_SELECTOR_SERVICE_NAME, &selectorRef);
+		if (status == CELIX_SUCCESS) {
+			int index = -1;
+			if (selectorRef != NULL) {
+				driver_selector_service_t 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, pool, match);
+			}
+		}
+	}
+
+	return status;
+}
+
+celix_status_t driverMatcher_getBestMatchInternal(driver_matcher_t matcher, apr_pool_t *pool, match_t *match) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!hashMap_isEmpty(matcher->attributes)) {
+		match_key_t matchKey = NULL;
+		HASH_MAP_ITERATOR iter = hashMapIterator_create(matcher->attributes);
+		while (hashMapIterator_hasNext(iter)) {
+			HASH_MAP_ENTRY 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 das = hashMap_get(matcher->attributes, matchKey);
+		SERVICE_REFERENCE best = NULL;
+		int i;
+		for (i = 0; i < arrayList_size(das); i++) {
+			driver_attributes_t attributes = arrayList_get(das, i);
+			SERVICE_REFERENCE reference = NULL;
+
+			celix_status_t substatus = driverAttributes_getReference(attributes, &reference);
+			if (substatus == CELIX_SUCCESS) {
+				if (best != NULL) {
+					printf("DRIVER_MATCHER: Compare ranking\n");
+					char *rank1Str, *rank2Str;
+					int rank1, rank2;
+					SERVICE_REGISTRATION registration = NULL;
+					substatus = serviceReference_getServiceRegistration(reference, &registration);
+					if (substatus == CELIX_SUCCESS) {
+						PROPERTIES properties = NULL;
+						status = serviceRegistration_getProperties(registration, &properties);
+						if (status == CELIX_SUCCESS) {
+
+							rank1Str = properties_getWithDefault(properties, (char *) SERVICE_RANKING, "0");
+							rank2Str = properties_getWithDefault(properties, (char *) SERVICE_RANKING, "0");
+
+							rank1 = atoi(rank1Str);
+							rank2 = atoi(rank2Str);
+
+							if (rank1 != rank2) {
+								if (rank1 > rank2) {
+									best = reference;
+								}
+							} else {
+								printf("DRIVER_MATCHER: Compare id's\n");
+								char *id1Str, *id2Str;
+								long id1, id2;
+
+								id1Str = properties_get(properties, (char *) SERVICE_ID);
+								id2Str = properties_get(properties, (char *) SERVICE_ID);
+
+								id1 = atol(id1Str);
+								id2 = atol(id2Str);
+
+								if (id1 < id2) {
+									best = reference;
+								}
+							}
+						}
+					}
+				} else {
+					best = reference;
+				}
+			}
+
+		}
+
+		*match = apr_palloc(pool, sizeof(**match));
+		if (!*match) {
+			status = CELIX_ENOMEM;
+		} else {
+			(*match)->matchValue = matchKey->matchValue;
+			(*match)->reference = best;
+		}
+	}
+
+	return status;
+}

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

Added: incubator/celix/trunk/device_access/device_access/public/include/device.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/public/include/device.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/public/include/device.h (added)
+++ incubator/celix/trunk/device_access/device_access/public/include/device.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,41 @@
+/**
+ *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.
+ */
+
+#ifndef DEVICE_H_
+#define DEVICE_H_
+
+#include "celix_errno.h"
+
+#define DEVICE_CATEGORY	"DEVICE_CATEGORY"
+#define DEVICE_SERIAL	"DEVICE_SERIAL"
+
+#define DEVICE_SERVICE_NAME "device"
+
+static const int DEVICE_MATCH_NONE	= 0;
+
+typedef struct device * device_t;
+
+struct device_service {
+	device_t device;
+	celix_status_t (*noDriverFound)(device_t device);
+};
+
+typedef struct device_service * device_service_t;
+
+#endif /* DEVICE_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/public/include/device.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/public/include/driver.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/public/include/driver.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/public/include/driver.h (added)
+++ incubator/celix/trunk/device_access/device_access/public/include/driver.h Wed Jun 20 08:41:25 2012
@@ -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.
+ */
+
+#ifndef DRIVER_H_
+#define DRIVER_H_
+
+#include "celix_errno.h"
+#include "service_reference.h"
+
+#define DRIVER_SERVICE_NAME "driver"
+
+#define DRIVER_ID "DRIVER_ID"
+
+struct driver_service {
+	void *driver;
+	celix_status_t (*attach)(void *driver, SERVICE_REFERENCE reference, char **result);
+	celix_status_t (*match)(void *driver, SERVICE_REFERENCE reference, int *value);
+};
+
+typedef struct driver_service *driver_service_t;
+
+
+#endif /* DRIVER_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/public/include/driver.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h (added)
+++ incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,40 @@
+/**
+ *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.
+ */
+
+#ifndef DRIVER_LOCATOR_H_
+#define DRIVER_LOCATOR_H_
+
+#include "celix_errno.h"
+#include "properties.h"
+#include "array_list.h"
+
+#define DRIVER_LOCATOR_SERVICE_NAME "driver_locator"
+
+typedef struct driver_locator *driver_locator_t;
+
+struct driver_locator_service {
+	driver_locator_t locator;
+	celix_status_t(*findDrivers)(driver_locator_t loc, apr_pool_t *pool, PROPERTIES props, ARRAY_LIST *drivers);
+	celix_status_t(*loadDriver)(driver_locator_t loc, apr_pool_t *pool, char *id, char **driver);
+};
+
+typedef struct driver_locator_service *driver_locator_service_t;
+
+
+#endif /* DRIVER_LOCATOR_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/public/include/driver_locator.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h (added)
+++ incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,35 @@
+/**
+ *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.
+ */
+
+#ifndef DRIVER_SELECTOR_H_
+#define DRIVER_SELECTOR_H_
+
+#define DRIVER_SELECTOR_SERVICE_NAME "driver_selector"
+
+typedef struct driver_selector *driver_selector_t;
+
+struct driver_selector_service {
+	driver_selector_t selector;
+	celix_status_t (*driverSelector_select)(driver_selector_t selector, SERVICE_REFERENCE reference, ARRAY_LIST matches, int *select);
+};
+
+typedef struct driver_selector_service *driver_selector_service_t;
+
+
+#endif /* DRIVER_SELECTOR_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/public/include/driver_selector.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/device_access/public/include/match.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/device_access/public/include/match.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/device_access/public/include/match.h (added)
+++ incubator/celix/trunk/device_access/device_access/public/include/match.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,32 @@
+/**
+ *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.
+ */
+
+#ifndef MATCH_H_
+#define MATCH_H_
+
+#include <service_reference.h>
+
+struct match {
+	SERVICE_REFERENCE reference;
+	int matchValue;
+};
+
+typedef struct match *match_t;
+
+#endif /* MATCH_H_ */

Propchange: incubator/celix/trunk/device_access/device_access/public/include/match.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,27 @@
+# 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(FindAPR)
+
+bundle(driver_locator SOURCES 
+	private/src/activator 
+	private/src/driver_locator
+)
+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 utils ${CELIX_LIBRARY} ${APR_LIBRARY})

Propchange: incubator/celix/trunk/device_access/driver_locator/CMakeLists.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF (added)
+++ incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF Wed Jun 20 08:41:25 2012
@@ -0,0 +1,5 @@
+Bundle-SymbolicName: driver_locator
+Bundle-Version: 1.0.0.test
+library: driver_locator
+Export-Service: driver_locator
+Import-Service: driver_locator

Propchange: incubator/celix/trunk/device_access/driver_locator/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h (added)
+++ incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,34 @@
+/**
+ *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.
+ */
+
+#ifndef DRIVER_LOCATOR_PRIVATE_H_
+#define DRIVER_LOCATOR_PRIVATE_H_
+
+#include "driver_locator.h"
+
+struct driver_locator {
+    apr_pool_t *pool;
+    char *path;
+    ARRAY_LIST drivers;
+};
+
+celix_status_t driverLocator_findDrivers(driver_locator_t locator, apr_pool_t *pool, PROPERTIES props, ARRAY_LIST *drivers);
+celix_status_t driverLocator_loadDriver(driver_locator_t locator, apr_pool_t *pool, char *id, char **driver);
+
+#endif /* DRIVER_LOCATOR_PRIVATE_H_ */

Propchange: incubator/celix/trunk/device_access/driver_locator/private/include/driver_locator_private.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain