This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/remove_device_access in repository https://gitbox.apache.org/repos/asf/celix.git
commit 7d91d25d3d7d8167b2124de63e75d7e1056c8055 Author: Pepijn Noltes <[email protected]> AuthorDate: Sat Dec 31 14:05:50 2022 +0100 Remove device access bundles --- bundles/CMakeLists.txt | 1 - bundles/device_access/CMakeLists.txt | 25 - bundles/device_access/README.md | 38 -- bundles/device_access/device_access/CMakeLists.txt | 50 -- .../device_access/device_access/include/device.h | 48 -- .../device_access/device_access/include/driver.h | 46 -- .../device_access/include/driver_locator.h | 47 -- .../device_access/include/driver_selector.h | 42 -- .../device_access/device_access/include/match.h | 39 -- .../device_access/device_access/src/activator.c | 192 ------- .../device_access/src/device_manager.c | 570 --------------------- .../device_access/src/device_manager.h | 57 --- .../device_access/src/driver_attributes.c | 170 ------ .../device_access/src/driver_attributes.h | 47 -- .../device_access/src/driver_loader.c | 186 ------- .../device_access/src/driver_loader.h | 49 -- .../device_access/src/driver_matcher.c | 270 ---------- .../device_access/src/driver_matcher.h | 43 -- .../device_access/driver_locator/CMakeLists.txt | 34 -- .../device_access/driver_locator/src/activator.c | 90 ---- .../driver_locator/src/driver_locator.c | 92 ---- .../driver_locator/src/driver_locator_private.h | 40 -- bundles/device_access/example/CMakeLists.txt | 32 -- .../example/base_driver/CMakeLists.txt | 29 -- .../device_access/example/base_driver/README.md | 29 -- .../base_driver/include/base_driver_device.h | 45 -- .../example/base_driver/src/activator.c | 139 ----- .../example/base_driver/src/base_driver.c | 112 ---- .../example/base_driver/src/base_driver_private.h | 42 -- .../example/consuming_driver/CMakeLists.txt | 30 -- .../example/consuming_driver/README.md | 27 - .../example/consuming_driver/src/activator.c | 104 ---- .../consuming_driver/src/consuming_driver.c | 126 ----- .../src/consuming_driver_private.h | 44 -- .../example/refining_driver/CMakeLists.txt | 32 -- .../example/refining_driver/README.md | 27 - .../include/refining_driver_device.h | 46 -- .../example/refining_driver/src/activator.c | 104 ---- .../example/refining_driver/src/refining_driver.c | 284 ---------- .../refining_driver/src/refining_driver_private.h | 59 --- 40 files changed, 3487 deletions(-) diff --git a/bundles/CMakeLists.txt b/bundles/CMakeLists.txt index fa373e2c..78ecdfd5 100644 --- a/bundles/CMakeLists.txt +++ b/bundles/CMakeLists.txt @@ -19,7 +19,6 @@ add_subdirectory(http_admin) add_subdirectory(logging) add_subdirectory(shell) -add_subdirectory(device_access) add_subdirectory(deployment_admin) add_subdirectory(remote_services) add_subdirectory(pubsub) diff --git a/bundles/device_access/CMakeLists.txt b/bundles/device_access/CMakeLists.txt deleted file mode 100644 index aafa768a..00000000 --- a/bundles/device_access/CMakeLists.txt +++ /dev/null @@ -1,25 +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. - -celix_subproject(DEVICE_ACCESS "Option to enable building the Device Access Service bundles" ON) -if(DEVICE_ACCESS) - message(WARNING "DEVICE_ACCESS is considered unstable, because develop of these bundles has been dormant for a while") - - add_subdirectory(device_access) - add_subdirectory(driver_locator) - add_subdirectory(example) -endif(DEVICE_ACCESS) diff --git a/bundles/device_access/README.md b/bundles/device_access/README.md deleted file mode 100644 index f93e0e80..00000000 --- a/bundles/device_access/README.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -title: Device Access ---- - -<!-- -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 Access - -The Device Access contains a for Celix adapted implementation of the OSGi Compendium Device Access Specification. - -## Properties - DRIVER_LOCATOR_PATH Path to the directory containing the driver bundles, defaults to "drivers". - The Driver Locator uses this path to find drivers. - -## CMake option - BUILD_DEVICE_ACCESS=ON - -## Using info - -If the Celix Device Access is installed, 'find_package(Celix)' will set: - - The `Celix::device_access_api` interface (i.e. headers only) library target - - The `Celix::device_manager` bundle target - - The `Celix::driver_locator` bundle target diff --git a/bundles/device_access/device_access/CMakeLists.txt b/bundles/device_access/device_access/CMakeLists.txt deleted file mode 100644 index 3e3ed888..00000000 --- a/bundles/device_access/device_access/CMakeLists.txt +++ /dev/null @@ -1,50 +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. - - -add_library(device_access_api INTERFACE) -target_include_directories(device_access_api INTERFACE - $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> -) - -add_celix_bundle(device_manager - SYMBOLIC_NAME "apache_celix_device_manager" - VERSION "0.0.2" - NAME "Apache Celix Device Access Device Manager" - GROUP "Celix/DeviceAccess" - SOURCES - src/activator.c - src/driver_attributes.c - src/device_manager.c - src/driver_loader.c - src/driver_matcher.c -) -target_link_libraries(device_manager PRIVATE Celix::log_helper) - -target_include_directories(device_manager PRIVATE src) -target_link_libraries(device_manager PRIVATE device_access_api) -celix_deprecated_utils_headers(device_manager) - -install(TARGETS device_access_api EXPORT celix COMPONENT device_access - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/device_access) -install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/device_access COMPONENT device_access) -install_celix_bundle(device_manager EXPORT celix COMPONENT device_access) - -#Setup target aliases to match external usage -add_library(Celix::device_access_api ALIAS device_access_api) -add_library(Celix::device_manager ALIAS device_manager) - diff --git a/bundles/device_access/device_access/include/device.h b/bundles/device_access/device_access/include/device.h deleted file mode 100644 index 75da6662..00000000 --- a/bundles/device_access/device_access/include/device.h +++ /dev/null @@ -1,48 +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:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/include/driver.h b/bundles/device_access/device_access/include/driver.h deleted file mode 100644 index d85fab3c..00000000 --- a/bundles/device_access/device_access/include/driver.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.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/include/driver_locator.h b/bundles/device_access/device_access/include/driver_locator.h deleted file mode 100644 index 307c2c23..00000000 --- a/bundles/device_access/device_access/include/driver_locator.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. - */ -/** - * driver_locator.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/include/driver_selector.h b/bundles/device_access/device_access/include/driver_selector.h deleted file mode 100644 index b18e1410..00000000 --- a/bundles/device_access/device_access/include/driver_selector.h +++ /dev/null @@ -1,42 +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:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/include/match.h b/bundles/device_access/device_access/include/match.h deleted file mode 100644 index 25b13faf..00000000 --- a/bundles/device_access/device_access/include/match.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. - */ -/** - * match.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/src/activator.c b/bundles/device_access/device_access/src/activator.c deleted file mode 100644 index 2e31085c..00000000 --- a/bundles/device_access/device_access/src/activator.c +++ /dev/null @@ -1,192 +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:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> -#include <stdbool.h> - -#include <bundle_activator.h> -#include <bundle_context.h> -#include <service_tracker.h> - -#include "driver_locator.h" -#include "device_manager.h" -#include "celix_log_helper.h" - -struct device_manager_bundle_instance { - celix_log_helper_t *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; - - bi->loghelper = celix_logHelper_create(context, "celix_device_access"); - - 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) { - celix_logHelper_log(bundleData->loghelper, CELIX_LOG_LEVEL_ERROR, "DEVICE_MANAGER: Error while starting bundle got error num %d", status); - } - - celix_logHelper_log(bundleData->loghelper, CELIX_LOG_LEVEL_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); - - celix_logHelper_destroy(bundleData->loghelper); - - return status; -} diff --git a/bundles/device_access/device_access/src/device_manager.c b/bundles/device_access/device_access/src/device_manager.c deleted file mode 100644 index d6a550a9..00000000 --- a/bundles/device_access/device_access/src/device_manager.c +++ /dev/null @@ -1,570 +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_manager.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> -#include "celix_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 <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; - celix_log_helper_t *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, celix_log_helper_t *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); - - celix_logHelper_log((*manager)->loghelper, CELIX_LOG_LEVEL_DEBUG, "DEVICE_MANAGER: Initialized"); - } - - - return status; -} - -celix_status_t deviceManager_destroy(device_manager_pt manager) { - celix_status_t status = CELIX_SUCCESS; - - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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); - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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) { - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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) { - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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) { - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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); - - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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) { - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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); - - celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_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; -} - - - diff --git a/bundles/device_access/device_access/src/device_manager.h b/bundles/device_access/device_access/src/device_manager.h deleted file mode 100644 index fd290e14..00000000 --- a/bundles/device_access/device_access/src/device_manager.h +++ /dev/null @@ -1,57 +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_manager.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef DEVICE_MANAGER_H_ -#define DEVICE_MANAGER_H_ - -#include "celix_log_helper.h" - -#include "driver_loader.h" - -typedef struct device_manager *device_manager_pt; - -celix_status_t deviceManager_create(bundle_context_pt context, celix_log_helper_t *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_ */ diff --git a/bundles/device_access/device_access/src/driver_attributes.c b/bundles/device_access/device_access/src/driver_attributes.c deleted file mode 100644 index 732086c2..00000000 --- a/bundles/device_access/device_access/src/driver_attributes.c +++ /dev/null @@ -1,170 +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_attributes.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> - -#include "driver_attributes.h" -#include "bundle.h" -#include "driver_loader.h" -#include "device.h" -#include "celix_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; -} diff --git a/bundles/device_access/device_access/src/driver_attributes.h b/bundles/device_access/device_access/src/driver_attributes.h deleted file mode 100644 index 176654ce..00000000 --- a/bundles/device_access/device_access/src/driver_attributes.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. - */ -/** - * driver_attributes.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/src/driver_loader.c b/bundles/device_access/device_access/src/driver_loader.c deleted file mode 100644 index 2df3b78d..00000000 --- a/bundles/device_access/device_access/src/driver_loader.c +++ /dev/null @@ -1,186 +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_loader.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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; -} diff --git a/bundles/device_access/device_access/src/driver_loader.h b/bundles/device_access/device_access/src/driver_loader.h deleted file mode 100644 index 63dab315..00000000 --- a/bundles/device_access/device_access/src/driver_loader.h +++ /dev/null @@ -1,49 +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_loader.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/device_access/src/driver_matcher.c b/bundles/device_access/device_access/src/driver_matcher.c deleted file mode 100644 index c1ae7867..00000000 --- a/bundles/device_access/device_access/src/driver_matcher.c +++ /dev/null @@ -1,270 +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_matcher.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> - -#include "hash_map.h" -#include "celix_constants.h" - -#include "driver_matcher.h" -#include "celix_log_helper.h" - - -struct driver_matcher { - hash_map_pt attributes; - array_list_pt matches; - celix_log_helper_t *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); - - (*matcher)->loghelper = celix_logHelper_create(context, "celix_device_access"); - } - - 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); - - celix_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"; - - celix_logHelper_log(matcher->loghelper, CELIX_LOG_LEVEL_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; - - celix_logHelper_log(matcher->loghelper, CELIX_LOG_LEVEL_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; -} diff --git a/bundles/device_access/device_access/src/driver_matcher.h b/bundles/device_access/device_access/src/driver_matcher.h deleted file mode 100644 index d95fdfd6..00000000 --- a/bundles/device_access/device_access/src/driver_matcher.h +++ /dev/null @@ -1,43 +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_matcher.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">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_ */ diff --git a/bundles/device_access/driver_locator/CMakeLists.txt b/bundles/device_access/driver_locator/CMakeLists.txt deleted file mode 100644 index b5c61949..00000000 --- a/bundles/device_access/driver_locator/CMakeLists.txt +++ /dev/null @@ -1,34 +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. - -add_celix_bundle(driver_locator - SYMBOLIC_NAME "apache_celix_driver_locator" - VERSION "0.0.2" - NAME "Apache Celix Device Access Driver Locator" - GROUP "Celix/DeviceAccess" - SOURCES - src/activator.c - src/driver_locator.c -) - -target_include_directories(driver_locator PRIVATE src) -target_link_libraries(driver_locator PRIVATE Celix::device_access_api) -celix_deprecated_utils_headers(driver_locator) - -#Setup target aliases to match external usage -install_celix_bundle(driver_locator EPXORT celix COMPONENT device_access) -add_library(Celix::driver_locator ALIAS driver_locator) diff --git a/bundles/device_access/driver_locator/src/activator.c b/bundles/device_access/driver_locator/src/activator.c deleted file mode 100644 index 4b4e38eb..00000000 --- a/bundles/device_access/driver_locator/src/activator.c +++ /dev/null @@ -1,90 +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:[email protected]">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; -} diff --git a/bundles/device_access/driver_locator/src/driver_locator.c b/bundles/device_access/driver_locator/src/driver_locator.c deleted file mode 100644 index 308c6ead..00000000 --- a/bundles/device_access/driver_locator/src/driver_locator.c +++ /dev/null @@ -1,92 +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:[email protected]">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; -} - diff --git a/bundles/device_access/driver_locator/src/driver_locator_private.h b/bundles/device_access/driver_locator/src/driver_locator_private.h deleted file mode 100644 index 97c3c848..00000000 --- a/bundles/device_access/driver_locator/src/driver_locator_private.h +++ /dev/null @@ -1,40 +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:[email protected]">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_ */ diff --git a/bundles/device_access/example/CMakeLists.txt b/bundles/device_access/example/CMakeLists.txt deleted file mode 100644 index d1acdbef..00000000 --- a/bundles/device_access/example/CMakeLists.txt +++ /dev/null @@ -1,32 +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. - -celix_subproject(DEVICE_ACCESS_EXAMPLE "Option to enable building the Device Access example bundles" OFF DEPS SHELL SHELL_TUI) -if(DEVICE_ACCESS_EXAMPLE) - add_subdirectory(base_driver) - add_subdirectory(consuming_driver) - add_subdirectory(refining_driver) - - add_celix_container(device_access_example - BUNDLES Celix::device_manager Celix::driver_locator Celix::shell Celix::shell_tui base_driver - ) - - celix_container_bundles_dir(device_access_example - DIR_NAME "drivers" - BUNDLES word_consumingdriver char_refiningdriver - ) -endif(DEVICE_ACCESS_EXAMPLE) diff --git a/bundles/device_access/example/base_driver/CMakeLists.txt b/bundles/device_access/example/base_driver/CMakeLists.txt deleted file mode 100644 index 4265d1f2..00000000 --- a/bundles/device_access/example/base_driver/CMakeLists.txt +++ /dev/null @@ -1,29 +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. - -add_celix_bundle(base_driver - SYMBOLIC_NAME "apache_celix_base_driver_example" - VERSION "0.0.1" - NAME "Apache Celix Device Access Base Driver Example" - SOURCES - src/activator.c - src/base_driver.c -) -celix_deprecated_utils_headers(base_driver) -target_include_directories(base_driver PRIVATE src) -target_include_directories(base_driver PUBLIC include) -target_link_libraries(base_driver PRIVATE Celix::device_access_api) diff --git a/bundles/device_access/example/base_driver/README.md b/bundles/device_access/example/base_driver/README.md deleted file mode 100644 index 9173a0da..00000000 --- a/bundles/device_access/example/base_driver/README.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: Base driver ---- - -<!-- -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. ---> - -# Base driver - -The base driver is a "special" driver that will not be loaded by the device manager. -Normally the device manager will load drivers if it find device which are idle... But before that can happen -at least one device should exists. This is the role of a base driver and it should function like a "normal" OSGi -bundle which registers a device service. - -In this example the base driver will provide two device service with a DEVICE_CATEGORY of "char". \ No newline at end of file diff --git a/bundles/device_access/example/base_driver/include/base_driver_device.h b/bundles/device_access/example/base_driver/include/base_driver_device.h deleted file mode 100644 index 438dad61..00000000 --- a/bundles/device_access/example/base_driver/include/base_driver_device.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. - */ -/** - * base_driver_device.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef BASE_DRIVER_DEVICE_H_ -#define BASE_DRIVER_DEVICE_H_ - -#include "device.h" - -#define BASE_DRIVER_SERVICE_NAME "base_driver_device_service" -#define BASE_DRIVER_DEVICE_CATEGORY "char" - -typedef struct base_driver_device *base_driver_device_pt; - -struct base_driver_device_service { - struct device_service deviceService; /*NOTE: base_driver_device_service is a device_service.*/ - base_driver_device_pt baseDriverDevice; - celix_status_t (*getNextChar)(base_driver_device_pt baseDriverDevice, char *c); -}; - -typedef struct base_driver_device_service * base_driver_device_service_pt; - -#endif /* BASE_DRIVER_DEVICE_H_ */ diff --git a/bundles/device_access/example/base_driver/src/activator.c b/bundles/device_access/example/base_driver/src/activator.c deleted file mode 100644 index c527c404..00000000 --- a/bundles/device_access/example/base_driver/src/activator.c +++ /dev/null @@ -1,139 +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:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> - -#include <celix_errno.h> -#include <bundle_activator.h> -#include <bundle_context.h> -#include <stdbool.h> -#include <device.h> - -#include "base_driver_private.h" -#include "base_driver_device.h" - -struct base_driver_bundle_instance { - bundle_context_pt context; - array_list_pt serviceRegistrations; -}; - -typedef struct base_driver_bundle_instance *base_driver_bundle_instance_pt; - -celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - printf("BASE_DRIVER: creating bundle\n"); - celix_status_t status = CELIX_SUCCESS; - base_driver_bundle_instance_pt instance = calloc(1, sizeof(*instance)); - if (instance != NULL) { - instance->context = context; - status = arrayList_create(&instance->serviceRegistrations); - if (status == CELIX_SUCCESS) { - (*userData) = instance; - } - } else { - status = CELIX_ENOMEM; - } - return status; -} - -static celix_status_t bundleActivator_registerBaseDriverDevice(base_driver_bundle_instance_pt bi, char *serial) { - celix_status_t status = CELIX_SUCCESS; - base_driver_device_pt device = NULL; - base_driver_device_service_pt service = NULL; - status = baseDriver_create(&device); - if (status == CELIX_SUCCESS) { - status = baseDriver_createService(device, &service); - if (status == CELIX_SUCCESS) { - properties_pt props = properties_create(); - properties_set(props, OSGI_DEVICEACCESS_DEVICE_CATEGORY, BASE_DRIVER_DEVICE_CATEGORY); - properties_set(props, OSGI_DEVICEACCESS_DEVICE_SERIAL, serial); - service_registration_pt service_registration = NULL; - status = bundleContext_registerService(bi->context, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME, service, props, &service_registration); - if (status == CELIX_SUCCESS) { - arrayList_add(bi->serviceRegistrations, service_registration); - } - else{ - properties_destroy(props); - } - } - } - - if (status == CELIX_SUCCESS) { - printf("BASE_DRIVER: Successfully registered device service with serial %s.\n", serial); - } else { - printf("BASE_DRIVER: Unsuccessfully registered device service with serial %s. Got error: %s\n", - serial, celix_strerror(status)); - if(service != NULL){ - baseDriver_destroyService(service); - } - if(device != NULL){ - baseDriver_destroy(device); - } - } - return status; -} - -celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { - printf("BASE_DRIVER: starting bundle\n"); - celix_status_t status = CELIX_SUCCESS; - base_driver_bundle_instance_pt bundleInstance = userData; - status = bundleActivator_registerBaseDriverDevice(bundleInstance, "0001"); -// if (status == CELIX_SUCCESS) { -// status = bundleActivator_registerBaseDriverDevice(bundleInstance, "0002"); -// } - return status; -} - -celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { - printf("BASE_DRIVER: stopping bundle\n"); - celix_status_t status = CELIX_SUCCESS; - base_driver_bundle_instance_pt bundleInstance = userData; - - array_list_iterator_pt iterator = arrayListIterator_create(bundleInstance->serviceRegistrations); - while (arrayListIterator_hasNext(iterator)) { - service_registration_pt reg = arrayListIterator_next(iterator); - printf("BASE_DRIVER: unregistering service\n"); - celix_status_t unregStatus = serviceRegistration_unregister(reg); - if (unregStatus != CELIX_SUCCESS) { - status = CELIX_ILLEGAL_STATE; - fprintf(stderr, "Cannot unregister service. Got error %s\n", celix_strerror(unregStatus)); - } else { - printf("BASE_DRIVER: unregistered base device service\n"); - } - } - arrayListIterator_destroy(iterator); - - return status; -} - -celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - printf("BASE_DRIVER: destroying bundle\n"); - celix_status_t status = CELIX_SUCCESS; - base_driver_bundle_instance_pt bundleInstance = userData; - - arrayList_destroy(bundleInstance->serviceRegistrations); - return status; -} - diff --git a/bundles/device_access/example/base_driver/src/base_driver.c b/bundles/device_access/example/base_driver/src/base_driver.c deleted file mode 100644 index 031d0035..00000000 --- a/bundles/device_access/example/base_driver/src/base_driver.c +++ /dev/null @@ -1,112 +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. - */ -/** - * base_driver.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> -#include <string.h> -#include <celix_errno.h> -#include <bundle_activator.h> -#include <bundle_context.h> -#include <stdbool.h> -#include <device.h> - -#include "base_driver_device.h" -#include "base_driver_private.h" - -static const char * INPUT_STRING = "Lorem ipsum dolor sit amet consectetur adipiscing elit "; - -struct device { - /*NOTE: for this example we use a empty device structure*/ -}; - -struct base_driver_device { - device_pt device; - char *input; - int inputLength; - int currentChar; -}; - -celix_status_t baseDriver_noDriverFound(device_pt device) { - printf("BASE_DRIVER: No driver found\n"); - return CELIX_SUCCESS; -} - -celix_status_t baseDriver_create(base_driver_device_pt *baseDriverDevice) { - celix_status_t status = CELIX_SUCCESS; - (*baseDriverDevice) = calloc(1, sizeof(struct base_driver_device)); - if (*baseDriverDevice != NULL) { - (*baseDriverDevice)->currentChar = 0; - (*baseDriverDevice)->input = (char *)INPUT_STRING; - (*baseDriverDevice)->inputLength=strlen(INPUT_STRING); - (*baseDriverDevice)->device = calloc(1, sizeof(*(*baseDriverDevice)->device)); - if ((*baseDriverDevice)->device == NULL) { - status = CELIX_ENOMEM; - } - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t baseDriver_createService(base_driver_device_pt baseDriverDevice, base_driver_device_service_pt *service) { - celix_status_t status = CELIX_SUCCESS; - (*service) = calloc(1, sizeof(struct base_driver_device_service)); - if ((*service) != NULL) { - (*service)->deviceService.noDriverFound = baseDriver_noDriverFound; - (*service)->deviceService.device = baseDriverDevice->device; - (*service)->getNextChar=baseDriver_getNextChar; - (*service)->baseDriverDevice = baseDriverDevice; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t baseDriver_getNextChar(base_driver_device_pt device, char *c) { - (*c) = device->input[device->currentChar]; - device->currentChar+=1; - if (device->currentChar >= device->inputLength) { - device->currentChar = 0; - } - return CELIX_SUCCESS; -} - -celix_status_t baseDriver_destroy(base_driver_device_pt device){ - if(device != NULL){ - if(device->device != NULL){ - free(device->device); - } - free(device); - } - return CELIX_SUCCESS; -} - -celix_status_t baseDriver_destroyService(base_driver_device_service_pt service){ - if(service != NULL){ - free(service); - } - - return CELIX_SUCCESS; -} diff --git a/bundles/device_access/example/base_driver/src/base_driver_private.h b/bundles/device_access/example/base_driver/src/base_driver_private.h deleted file mode 100644 index d4413d17..00000000 --- a/bundles/device_access/example/base_driver/src/base_driver_private.h +++ /dev/null @@ -1,42 +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. - */ -/** - * base_driver_private.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef BASE_DRIVER_PRIVATE_H_ -#define BASE_DRIVER_PRIVATE_H_ - -#include "base_driver_device.h" - -celix_status_t baseDriver_create(base_driver_device_pt *service); -celix_status_t baseDriver_createService(base_driver_device_pt device, base_driver_device_service_pt *service); - -celix_status_t baseDriver_noDriverFound(device_pt device); - -celix_status_t baseDriver_getNextChar(base_driver_device_pt service, char *c); - -celix_status_t baseDriver_destroy(base_driver_device_pt device); -celix_status_t baseDriver_destroyService(base_driver_device_service_pt service); - -#endif /* BASE_DRIVER_PRIVATE_H_ */ diff --git a/bundles/device_access/example/consuming_driver/CMakeLists.txt b/bundles/device_access/example/consuming_driver/CMakeLists.txt deleted file mode 100644 index 3b2f140b..00000000 --- a/bundles/device_access/example/consuming_driver/CMakeLists.txt +++ /dev/null @@ -1,30 +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. - -add_celix_bundle(word_consumingdriver - SYMBOLIC_NAME "apache_celix_word_consuming_driver_example" - VERSION "0.0.1" - NAME "Apache Celix Device Access Word Consuming Driver Example" - SOURCES - src/activator.c - src/consuming_driver.c -) - -celix_deprecated_utils_headers(word_consumingdriver) -target_include_directories(word_consumingdriver PRIVATE src) - -target_link_libraries(word_consumingdriver PRIVATE Celix::device_access_api base_driver char_refiningdriver) diff --git a/bundles/device_access/example/consuming_driver/README.md b/bundles/device_access/example/consuming_driver/README.md deleted file mode 100644 index 7b3c3eb1..00000000 --- a/bundles/device_access/example/consuming_driver/README.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: Consuming driver ---- - -<!-- -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. ---> - -# Consuming driver - -A consuming driver will be able to attach to certain device services, -but will not - in contrast with a refining driver - publish device services. - -In this example the consuming driver will look for "word" services and will print the result a few times. diff --git a/bundles/device_access/example/consuming_driver/src/activator.c b/bundles/device_access/example/consuming_driver/src/activator.c deleted file mode 100644 index 0f585eb8..00000000 --- a/bundles/device_access/example/consuming_driver/src/activator.c +++ /dev/null @@ -1,104 +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:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> - -#include <celix_errno.h> -#include <bundle_activator.h> -#include <bundle_context.h> -#include <stdbool.h> -#include <device.h> - -#include "consuming_driver_private.h" - -struct consuming_driver_bundle_instance { - bundle_context_pt context; - service_registration_pt registration; -}; - -typedef struct consuming_driver_bundle_instance *consuming_driver_bundle_instance_pt; - -celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - printf("CONSUMING_DRIVER: creating bundle\n"); - celix_status_t status = CELIX_SUCCESS; - consuming_driver_bundle_instance_pt instance = calloc(1, sizeof(*instance)); - if (instance != NULL) { - instance->context = context; - instance->registration = NULL; - (*userData) = instance; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { - printf("CONSUMING_DRIVER: starting bundle\n"); - celix_status_t status = CELIX_SUCCESS; - consuming_driver_bundle_instance_pt bi = userData; - - consuming_driver_pt driver = NULL; - status = consumingDriver_create(context, &driver); - if (status == CELIX_SUCCESS) { - driver_service_pt service = NULL; - status = consumingDriver_createService(driver, &service); - if (status == CELIX_SUCCESS) { - properties_pt props = properties_create(); - properties_set(props, "DRIVER_ID", CONSUMING_DRIVER_ID); - status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME, service, props, &bi->registration); - } - } - - if (status == CELIX_SUCCESS) { - printf("CONSUMING_DRIVER: registered driver service.\n"); - } else { - printf("CONSUMING_DRIVER: Could not register driver service. Get error %s\n", celix_strerror(status)); - } - - return status; -} - -celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { - printf("CONSUMING_DRIVER: stopping bundle\n"); - celix_status_t status = CELIX_SUCCESS; - consuming_driver_bundle_instance_pt bi = userData; - - if (bi->registration != NULL) { - serviceRegistration_unregister(bi->registration); - printf("CONSUMING_DRIVER: unregistered driver service\n"); - } - - return status; -} - -celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - printf("CONSUMING_DRIVER: destroying bundle\n"); - celix_status_t status = CELIX_SUCCESS; - return status; -} - - - diff --git a/bundles/device_access/example/consuming_driver/src/consuming_driver.c b/bundles/device_access/example/consuming_driver/src/consuming_driver.c deleted file mode 100644 index 1de85384..00000000 --- a/bundles/device_access/example/consuming_driver/src/consuming_driver.c +++ /dev/null @@ -1,126 +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. - */ -/** - * consuming_driver.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> -#include <string.h> - -#include <device.h> -#include <service_tracker.h> -#include <service_reference.h> - -#include <stdbool.h> -#include "consuming_driver_private.h" -#include "refining_driver_device.h" - - -struct consuming_driver { - bundle_context_pt context; - array_list_pt references; -}; - -celix_status_t consumingDriver_destroy(consuming_driver_pt driver) { - printf("CONSUMING_DRIVER: cleanup\n"); - if (driver->references != NULL) { - array_list_iterator_pt iterator = arrayListIterator_create(driver->references); - while (arrayListIterator_hasNext(iterator)) { - service_reference_pt reference = arrayListIterator_next(iterator); - bool result; - bundleContext_ungetService(driver->context, reference, &result); - } - arrayListIterator_destroy(iterator); - - arrayList_destroy(driver->references); - driver->references=NULL; - } - - - return CELIX_SUCCESS; -} - -celix_status_t consumingDriver_create(bundle_context_pt context, consuming_driver_pt *driver) { - celix_status_t status = CELIX_SUCCESS; - (*driver) = calloc(1, sizeof(**driver)); - if ((*driver) != NULL) { - (*driver)->context=context; - (*driver)->references=NULL; - - status = arrayList_create(&(*driver)->references); - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t consumingDriver_createService(consuming_driver_pt driver, driver_service_pt *service) { - celix_status_t status = CELIX_SUCCESS; - (*service) = calloc(1, sizeof(**service)); - if ((*service) != NULL) { - (*service)->driver = driver; - (*service)->attach = consumingDriver_attach; - (*service)->match = consumingDriver_match; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t consumingDriver_attach(void * driverHandler, service_reference_pt reference, char **result) { - printf("CONSUMING_DRIVER: attached called\n"); - celix_status_t status = CELIX_SUCCESS; - consuming_driver_pt driver = driverHandler; - (*result) = NULL; - refining_driver_device_service_pt device_service = NULL; - - status = bundleContext_getService(driver->context, reference, (void **)&device_service); - if (status == CELIX_SUCCESS) { - arrayList_add(driver->references, reference); - //consume the device - for (int i=0; i<15; i++) { - char *str = NULL; - device_service->getNextWord(device_service->refiningDriverDevice, &str); - printf("CONSUMING_DEVICE: Word Device result is %s\n", str); - } - } - return status; -} - -celix_status_t consumingDriver_match(void *driverHandler, service_reference_pt reference, int *value) { - printf("CONSUMING_DRIVER: match called\n"); - int match=0; - celix_status_t status = CELIX_SUCCESS; - - const char* category = NULL; - status = serviceReference_getProperty(reference, OSGI_DEVICEACCESS_DEVICE_CATEGORY, &category); - if (status == CELIX_SUCCESS) { - if (strcmp(category, REFINING_DRIVER_DEVICE_CATEGORY) == 0) { - match = 10; - } - } - - (*value) = match; - return status; -} - diff --git a/bundles/device_access/example/consuming_driver/src/consuming_driver_private.h b/bundles/device_access/example/consuming_driver/src/consuming_driver_private.h deleted file mode 100644 index 83d7564b..00000000 --- a/bundles/device_access/example/consuming_driver/src/consuming_driver_private.h +++ /dev/null @@ -1,44 +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. - */ -/** - * consuming_driver_private.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef CONSUMING_DRIVER_PRIVATE_H_ -#define CONSUMING_DRIVER_PRIVATE_H_ - -#include <celix_errno.h> -#include <service_reference.h> -#include <driver.h> - -#define CONSUMING_DRIVER_ID "CONSUMING_DRIVER" - -typedef struct consuming_driver *consuming_driver_pt; - -celix_status_t consumingDriver_create(bundle_context_pt context, consuming_driver_pt *driver); -celix_status_t consumingDriver_createService(consuming_driver_pt driver, driver_service_pt *service); - -celix_status_t consumingDriver_attach(void *driver, service_reference_pt reference, char **result); -celix_status_t consumingDriver_match(void *driver, service_reference_pt reference, int *value); - -#endif /* CONSUMING_DRIVER_PRIVATE_H_ */ diff --git a/bundles/device_access/example/refining_driver/CMakeLists.txt b/bundles/device_access/example/refining_driver/CMakeLists.txt deleted file mode 100644 index 12124402..00000000 --- a/bundles/device_access/example/refining_driver/CMakeLists.txt +++ /dev/null @@ -1,32 +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. - -add_celix_bundle(char_refiningdriver - SYMBOLIC_NAME "apache_celix_char_refining_driver_example" - NAME "Apache Celix Device Access Char Refining Driver Example" - VERSION "0.0.1" - SOURCES - src/activator.c - src/refining_driver.c -) - -celix_deprecated_utils_headers(char_refiningdriver) -target_include_directories(char_refiningdriver PRIVATE src) -target_include_directories(char_refiningdriver PUBLIC include) -target_link_libraries(char_refiningdriver PRIVATE Celix::device_access_api base_driver) -target_compile_options(char_refiningdriver PRIVATE -Wno-deprecated-declarations) #char_refiningdriver still uses service listeners, refactor this - diff --git a/bundles/device_access/example/refining_driver/README.md b/bundles/device_access/example/refining_driver/README.md deleted file mode 100644 index d5e44857..00000000 --- a/bundles/device_access/example/refining_driver/README.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: Refining driver ---- - -<!-- -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. ---> - -# Refining driver - -A refining driver is a driver which is able to attach to certain device services and -as result publishes different - refined - device services. -This example will attach to device services with a "char" device category and publish -- for every char device services found - a "word" device services. diff --git a/bundles/device_access/example/refining_driver/include/refining_driver_device.h b/bundles/device_access/example/refining_driver/include/refining_driver_device.h deleted file mode 100644 index cd353718..00000000 --- a/bundles/device_access/example/refining_driver/include/refining_driver_device.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. - */ -/** - * refining_driver_device.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef REFINING_DRIVER_DEVICE_H_ -#define REFINING_DRIVER_DEVICE_H_ - -#include "device.h" - -#define REFINING_DRIVER_SERVICE_NAME "refining_driver_device_service" -#define REFINING_DRIVER_DEVICE_CATEGORY "word" -#define REFINING_DRIVER_DEVICE_SERVIC_NAME "refining_driver_device" - -typedef struct refining_driver_device *refining_driver_device_pt; - -struct refining_driver_device_service { - struct device_service deviceService; /*NOTE: base_driver_device_service is a device_service.*/ - refining_driver_device_pt refiningDriverDevice; - celix_status_t (*getNextWord)(refining_driver_device_pt refiningDriverDevice, char **c); -}; - -typedef struct refining_driver_device_service * refining_driver_device_service_pt; - -#endif /* REFINING_DRIVER_DEVICE_H_ */ diff --git a/bundles/device_access/example/refining_driver/src/activator.c b/bundles/device_access/example/refining_driver/src/activator.c deleted file mode 100644 index bb4d9d61..00000000 --- a/bundles/device_access/example/refining_driver/src/activator.c +++ /dev/null @@ -1,104 +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:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdlib.h> - -#include <celix_errno.h> -#include <bundle_activator.h> -#include <bundle_context.h> -#include <stdbool.h> -#include <device.h> - -#include "refining_driver_private.h" - -struct refining_driver_bundle_instance { - bundle_context_pt context; - service_registration_pt registration; -}; - -typedef struct refining_driver_bundle_instance *refining_driver_bundle_instance_pt; - -celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - printf("REFINING_DRIVER: creating bundle\n"); - celix_status_t status = CELIX_SUCCESS; - refining_driver_bundle_instance_pt instance = calloc(1, sizeof(*instance)); - if (instance != NULL) { - instance->context = context; - instance->registration = NULL; - (*userData) = instance; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { - printf("REFINING_DRIVER: starting bundle\n"); - celix_status_t status = CELIX_SUCCESS; - refining_driver_bundle_instance_pt bi = userData; - - refining_driver_pt driver = NULL; - status = refiningDriver_create(context, &driver); - if (status == CELIX_SUCCESS) { - driver_service_pt service = NULL; - status = refiningDriver_createService(driver, &service); - if (status == CELIX_SUCCESS) { - properties_pt props = properties_create(); - properties_set(props, "DRIVER_ID", REFINING_DRIVER_ID); - status = bundleContext_registerService(context, OSGI_DEVICEACCESS_DRIVER_SERVICE_NAME, service, props, &bi->registration); - } - } - - if (status == CELIX_SUCCESS) { - printf("REFINING_DRIVER: registered driver service.\n"); - } else { - printf("REFINING_DRIVER: Could not register driver service. Get error %s\n", celix_strerror(status)); - } - - return status; -} - -celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) { - printf("REFINING_DRIVER: stopping bundle\n"); - celix_status_t status = CELIX_SUCCESS; - refining_driver_bundle_instance_pt bi = userData; - - if (bi->registration != NULL) { - serviceRegistration_unregister(bi->registration); - printf("REFINING_DRIVER: unregistered driver service\n"); - } - - return status; -} - -celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - printf("REFINING_DRIVER: destroying bundle\n"); - celix_status_t status = CELIX_SUCCESS; - return status; -} - - - diff --git a/bundles/device_access/example/refining_driver/src/refining_driver.c b/bundles/device_access/example/refining_driver/src/refining_driver.c deleted file mode 100644 index a5e06853..00000000 --- a/bundles/device_access/example/refining_driver/src/refining_driver.c +++ /dev/null @@ -1,284 +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. - */ -/** - * refining_driver.c - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <device.h> -#include <bundle_context.h> -#include <service_event.h> - -#include "refining_driver_private.h" -#include "base_driver_device.h" - -static const int MAX_BUFF_SIZE = 1024; - -struct refining_driver { - device_pt device; - bundle_context_pt context; - int deviceCount; - array_list_pt devices; -}; - -struct device { - /*NOTE: for this example we use a empty device structure*/ -}; - -struct refining_driver_device { - device_pt device; - base_driver_device_service_pt baseDriverDeviceService; - refining_driver_pt driver; - service_reference_pt baseServiceReference; - service_registration_pt deviceRegistration; - celix_service_listener_t *listener; -}; - -celix_status_t refiningDriver_destroy(refining_driver_pt driver) { - if (driver != NULL) { - if (driver->devices != NULL) { - arrayList_destroy(driver->devices); - driver->devices=NULL; - } - } - return CELIX_SUCCESS; -} - -celix_status_t refiningDriver_create(bundle_context_pt context, refining_driver_pt *driver) { - celix_status_t status = CELIX_SUCCESS; - (*driver) = calloc(1, sizeof(**driver)); - if ((*driver) != NULL) { - (*driver)->context=context; - (*driver)->deviceCount=0; - (*driver)->device = calloc(1, sizeof(*(*driver)->device)); - (*driver)->devices=NULL; - status = arrayList_create(&(*driver)->devices); - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t refiningDriver_createService(refining_driver_pt driver, driver_service_pt *service) { - celix_status_t status = CELIX_SUCCESS; - (*service) = calloc(1, sizeof(**service)); - if ((*service) != NULL) { - (*service)->driver = driver; - (*service)->attach = refiningDriver_attach; - (*service)->match = refiningDriver_match; - } else { - status = CELIX_ENOMEM; - } - return status; -} - -static celix_status_t refiningDriver_stopDevice(refining_driver_device_pt device) { - printf("REFINING_DRIVER: stopping device, parent device is unregistered\n"); - celix_status_t status = CELIX_SUCCESS; - - if (device->deviceRegistration != NULL) { - status = serviceRegistration_unregister(device->deviceRegistration); - if (status == CELIX_SUCCESS) { - printf("unregistered refining device\n"); - } - } - - arrayList_removeElement(device->driver->devices, device); - return status; -} - - -static celix_status_t refiningDriver_serviceChanged(void *handle, celix_service_event_t *event) { - celix_status_t status = CELIX_SUCCESS; - refining_driver_device_pt device = handle; - if (event->type == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) { - bool equal = false; - status = serviceReference_equals(device->baseServiceReference, event->reference, &equal); - if (status == CELIX_SUCCESS && equal) { - refiningDriver_stopDevice(device); - } - } - return status; -} - -celix_status_t refiningDriver_destroyDevice(refining_driver_device_pt device) { - return CELIX_SUCCESS; -} - -celix_status_t refining_driver_cleanup_device(refining_driver_device_pt handler) { - celix_status_t status = CELIX_SUCCESS;; - refining_driver_device_pt device = handler; - if (device != NULL) { - if (device->listener != NULL) { - bundleContext_removeServiceListener(device->driver->context, device->listener); - } - } - return status; -} - -celix_status_t refiningDriver_createDevice(refining_driver_pt driver, service_reference_pt reference, base_driver_device_service_pt baseService, refining_driver_device_pt *device) { - celix_status_t status = CELIX_SUCCESS; - - (*device) = calloc(1, sizeof(**device)); - if ((*device) != NULL) { - (*device)->driver=driver; - (*device)->baseDriverDeviceService=baseService; - (*device)->baseServiceReference=reference; - (*device)->deviceRegistration=NULL; - (*device)->listener=NULL; - - celix_service_listener_t *listener = calloc(1, sizeof(*listener)); - listener->handle=(void *)(*device); - listener->serviceChanged=(celix_status_t (*)(void * listener, celix_service_event_t *event))refiningDriver_serviceChanged; - bundleContext_addServiceListener(driver->context, listener, NULL); - (*device)->listener=listener; - - arrayList_add(driver->devices, (*device)); - } else { - status = CELIX_ENOMEM; - } - - return status; -} - - -static celix_status_t refiningDriver_registerDevice(refining_driver_pt driver, refining_driver_device_pt device, char *serial) { - celix_status_t status = CELIX_SUCCESS; - refining_driver_device_service_pt service = NULL; - status = refiningDriverDevice_createService(device, &service); - properties_pt props = properties_create(); - - if (status == CELIX_SUCCESS) { - properties_set(props, OSGI_DEVICEACCESS_DEVICE_CATEGORY, REFINING_DRIVER_DEVICE_CATEGORY); - properties_set(props, OSGI_DEVICEACCESS_DEVICE_SERIAL, serial); - status = bundleContext_registerService(driver->context, OSGI_DEVICEACCESS_DEVICE_SERVICE_NAME, service, props, &device->deviceRegistration); - } - - if (status == CELIX_SUCCESS) { - printf("REFINING_DRIVER: registered refining device with serial %s\n", serial); - } - else{ - properties_destroy(props); - refiningDriverDevice_destroyService(service); - } - return status; -} - -celix_status_t refiningDriver_attach(void * driverHandler, service_reference_pt reference, char **result) { - printf("REFINING_DRIVER: attached called\n"); - celix_status_t status = CELIX_SUCCESS; - refining_driver_pt driver = driverHandler; - (*result) = NULL; - base_driver_device_service_pt device_service = NULL; - status = bundleContext_getService(driver->context, reference, (void **)&device_service); - if (status == CELIX_SUCCESS) { - refining_driver_device_pt refiningDevice = NULL; - status = refiningDriver_createDevice(driver, reference, device_service, &refiningDevice); - if (status == CELIX_SUCCESS) { - driver->deviceCount+=1; - char *serial; - asprintf(&serial, "%4i", driver->deviceCount); - status = refiningDriver_registerDevice(driver, refiningDevice, serial); - free(serial); - } - } - return status; -} - -celix_status_t refiningDriver_match(void *driverHandler, service_reference_pt reference, int *value) { - printf("REFINING_DRIVER: match called\n"); - int match = 0; - celix_status_t status = CELIX_SUCCESS; - - const char* category = NULL; - status = serviceReference_getProperty(reference, OSGI_DEVICEACCESS_DEVICE_CATEGORY, &category); - if (status == CELIX_SUCCESS) { - if (strcmp(category, BASE_DRIVER_DEVICE_CATEGORY) == 0) { - match = 10; - } - } - - (*value) = match; - return status; -} - -celix_status_t refiningDriverDevice_createService(refining_driver_device_pt device, refining_driver_device_service_pt *service) { - celix_status_t status = CELIX_SUCCESS; - (*service) = calloc(1, sizeof(**service)); - if ((*service) != NULL) { - (*service)->deviceService.device=calloc(1, sizeof(*(*service)->deviceService.device)); - if ((*service)->deviceService.device != NULL) { - (*service)->deviceService.noDriverFound=refiningDriverDevice_noDriverFound; - (*service)->refiningDriverDevice=device; - (*service)->getNextWord=refiningDriverDevice_getNextWord; - } else { - status = CELIX_ENOMEM; - } - } else { - status = CELIX_ENOMEM; - } - return status; -} - -celix_status_t refiningDriverDevice_destroyService(refining_driver_device_service_pt service){ - if(service != NULL){ - if(service->deviceService.device != NULL){ - free(service->deviceService.device); - } - free(service); - } - return CELIX_SUCCESS; -} - -celix_status_t refiningDriverDevice_getNextWord(refining_driver_device_pt refiningDriverDevice, char **word) { - celix_status_t status = CELIX_SUCCESS; - base_driver_device_pt baseDevice = refiningDriverDevice->baseDriverDeviceService->baseDriverDevice; - char buff[MAX_BUFF_SIZE]; - int i=0; - status = refiningDriverDevice->baseDriverDeviceService->getNextChar(baseDevice, &buff[i]); - while (buff[i] != ' ' && i < (MAX_BUFF_SIZE-1) && status == CELIX_SUCCESS) { - i+=1; - status = refiningDriverDevice->baseDriverDeviceService->getNextChar(baseDevice, &buff[i]); - } - if (status == CELIX_SUCCESS) { - buff[i] = '\0'; - char *copy = calloc(1, (i+1)); - if (copy != NULL) { - strcpy(copy, buff); - (*word)=copy; - } else { - status = CELIX_ENOMEM; - } - } - - return status; -} - -celix_status_t refiningDriverDevice_noDriverFound(device_pt device) { - printf("REFINING_DRIVER: no driver found"); - return CELIX_SUCCESS; -} - diff --git a/bundles/device_access/example/refining_driver/src/refining_driver_private.h b/bundles/device_access/example/refining_driver/src/refining_driver_private.h deleted file mode 100644 index 6eec4ca2..00000000 --- a/bundles/device_access/example/refining_driver/src/refining_driver_private.h +++ /dev/null @@ -1,59 +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. - */ -/** - * refining_driver_private.h - * - * \date Jun 20, 2011 - * \author <a href="mailto:[email protected]">Apache Celix Project Team</a> - * \copyright Apache License, Version 2.0 - */ - -#ifndef REFINING_DRIVER_PRIVATE_H_ -#define REFINING_DRIVER_PRIVATE_H_ - -#include <celix_errno.h> -#include <service_reference.h> -#include <driver.h> - -#include "refining_driver_device.h" -#include "base_driver_device.h" - -#define REFINING_DRIVER_ID "REFINING_DRIVER" - -typedef struct refining_driver *refining_driver_pt; - -celix_status_t refiningDriver_create(bundle_context_pt context, refining_driver_pt *driver); -celix_status_t refiningDriver_destroy(refining_driver_pt driver); - -celix_status_t refiningDriver_createService(refining_driver_pt driver, driver_service_pt *service); - -celix_status_t refiningDriver_createDevice(refining_driver_pt driver, service_reference_pt reference, base_driver_device_service_pt baseDevice, refining_driver_device_pt *device); -celix_status_t refiningDriver_destroyDevice(refining_driver_device_pt device); - - -celix_status_t refiningDriver_attach(void *driver, service_reference_pt reference, char **result); -celix_status_t refiningDriver_match(void *driver, service_reference_pt reference, int *value); - - -celix_status_t refiningDriverDevice_noDriverFound(device_pt device); -celix_status_t refiningDriverDevice_createService(refining_driver_device_pt, refining_driver_device_service_pt *service); -celix_status_t refiningDriverDevice_destroyService(refining_driver_device_service_pt service); -celix_status_t refiningDriverDevice_getNextWord(refining_driver_device_pt refiningDriverDevice, char **word); - -#endif /* REFINING_DRIVER_PRIVATE_H_ */
