You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2012/06/20 10:41:28 UTC
svn commit: r1351992 [2/2] - in /incubator/celix/trunk: ./ device_access/
device_access/device_access/ device_access/device_access/META-INF/
device_access/device_access/private/
device_access/device_access/private/include/ device_access/device_access/p...
Added: incubator/celix/trunk/device_access/driver_locator/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/driver_locator/private/src/activator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/driver_locator/private/src/activator.c (added)
+++ incubator/celix/trunk/device_access/driver_locator/private/src/activator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,92 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+
+#include "bundle_activator.h"
+#include "bundle_context.h"
+#include "driver_locator_private.h"
+
+static const char *DEFAULT_LOCATOR_PATH = "drivers";
+
+struct bundle_instance {
+ driver_locator_service_t service;
+ driver_locator_t locator;
+ SERVICE_REGISTRATION locatorRegistration;
+};
+
+typedef struct bundle_instance *bundle_instance_t;
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *pool;
+ status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ bundle_instance_t bi = apr_palloc(pool, sizeof(struct bundle_instance));
+ if (userData != NULL) {
+ bi->service=NULL;
+ bi->locator=NULL;
+ bi->locatorRegistration=NULL;
+ (*userData)=bi;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *pool;
+ status = bundleContext_getMemoryPool(context, &pool);
+ bundle_instance_t bi = (bundle_instance_t)userData;
+ if (status == CELIX_SUCCESS) {
+ struct activatorData * data = (struct activatorData *) userData;
+ bi->service = apr_palloc(pool, sizeof(*(bi->service)));
+ bi->service->findDrivers = driverLocator_findDrivers;
+ bi->service->loadDriver = driverLocator_loadDriver;
+
+ bi->locator = apr_pcalloc(pool, sizeof(*(bi->locator)));
+ bi->service->locator = bi->locator;
+ bi->locator->pool = pool;
+ bi->locator->drivers = NULL;
+ arrayList_create(pool, &bi->locator->drivers);
+ bundleContext_getProperty(context, "DRIVER_LOCATOR_PATH", &bi->locator->path);
+ if (bi->locator->path == NULL ) {
+ bi->locator->path = (char *)DEFAULT_LOCATOR_PATH;
+ }
+ bundleContext_registerService(context, DRIVER_LOCATOR_SERVICE_NAME, bi->service, NULL, &bi->locatorRegistration);
+ } else {
+ status = CELIX_START_ERROR;
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+ celix_status_t status = CELIX_SUCCESS;
+ bundle_instance_t bi = (bundle_instance_t)userData;
+ serviceRegistration_unregister(bi->locatorRegistration);
+ arrayList_destroy(bi->locator->drivers);
+ return status;
+}
+
+celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) {
+ return CELIX_SUCCESS;
+}
Propchange: incubator/celix/trunk/device_access/driver_locator/private/src/activator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c (added)
+++ incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,99 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <apr_general.h>
+#include <apr_strings.h>
+#include <apr_file_info.h>
+
+#include "driver_locator_private.h"
+#include "device.h"
+
+celix_status_t driverLocator_findDrivers(driver_locator_t locator, apr_pool_t *pool, PROPERTIES props, ARRAY_LIST *drivers) {
+ celix_status_t status = CELIX_SUCCESS;
+
+ char *category = properties_get(props, DEVICE_CATEGORY);
+
+ status = arrayList_create(pool, drivers);
+ if (status == CELIX_SUCCESS) {
+ apr_pool_t *spool;
+ apr_status_t aprStatus = apr_pool_create(&spool, pool);
+ if (aprStatus != APR_SUCCESS) {
+ status = CELIX_ENOMEM;
+ } else {
+ apr_dir_t *dir;
+ aprStatus = apr_dir_open(&dir, locator->path, spool);
+ if (aprStatus != APR_SUCCESS) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ apr_finfo_t dd;
+ while ((apr_dir_read(&dd, APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
+ char str1[256], str2[256], str3[256];
+ if (sscanf(dd.name, "%[^_]_%[^.].%s", str1, str2, str3) == 3 &&
+ strcmp(str1, category) == 0 &&
+ strcmp(str3, "zip") == 0) {
+ char *driver = apr_psprintf(pool, "%s_%s", str1, str2);
+ if (driver != NULL) {
+ arrayList_add(*drivers, driver);
+ }
+ }
+ }
+ apr_dir_close(dir);
+ }
+ apr_pool_destroy(spool);
+ }
+ }
+ return status;
+}
+
+celix_status_t driverLocator_loadDriver(driver_locator_t locator, apr_pool_t *pool, char *id, char **stream) {
+ celix_status_t status = CELIX_SUCCESS;
+ *stream = NULL;
+
+ apr_pool_t *spool;
+ apr_status_t aprStatus = apr_pool_create(&spool, pool);
+ if (aprStatus != APR_SUCCESS) {
+ status = CELIX_ENOMEM;
+ } else {
+ apr_dir_t *dir;
+ aprStatus = apr_dir_open(&dir, locator->path, spool);
+ if (aprStatus != APR_SUCCESS) {
+ status = CELIX_FILE_IO_EXCEPTION;
+ } else {
+ apr_finfo_t dd;
+ while ((apr_dir_read(&dd, APR_FINFO_TYPE, dir)) == APR_SUCCESS) {
+ char str1[256], str2[256];
+ if (sscanf(dd.name, "%[^.].%s", str1, str2) == 2 &&
+ strcmp(str1, id) == 0 &&
+ strcmp(str2, "zip") == 0) {
+ *stream = apr_psprintf(pool, "%s/%s", locator->path, dd.name);
+ break;
+ }
+ }
+ apr_dir_close(dir);
+ }
+ apr_pool_destroy(spool);
+ }
+
+ return status;
+}
+
Propchange: incubator/celix/trunk/device_access/driver_locator/private/src/driver_locator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/example/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,20 @@
+# 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_subdirectory(base_driver)
+add_subdirectory(consuming_driver)
+add_subdirectory(refining_driver)
\ No newline at end of file
Propchange: incubator/celix/trunk/device_access/example/CMakeLists.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include(FindAPR)
+
+bundle(base_driver SOURCES
+ private/src/activator
+ private/src/base_driver
+)
+
+include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
+include_directories(private/include)
+include_directories(public/include)
+include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+target_link_libraries(base_driver utils ${CELIX_LIBRARY} ${APR_LIBRARY})
Propchange: incubator/celix/trunk/device_access/example/base_driver/CMakeLists.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF (added)
+++ incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF Wed Jun 20 08:41:25 2012
@@ -0,0 +1,5 @@
+Bundle-SymbolicName: base_driver
+Bundle-Version: 1.0.0.test
+library: base_driver
+Export-Service: device, base_driver_device_service
+Import-Service: device
Propchange: incubator/celix/trunk/device_access/example/base_driver/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/README.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/README.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/README.txt (added)
+++ incubator/celix/trunk/device_access/example/base_driver/README.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,23 @@
+# 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.
+
+The base driver is "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
Propchange: incubator/celix/trunk/device_access/example/base_driver/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h (added)
+++ incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,32 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef BASE_DRIVER_PRIVATE_H_
+#define BASE_DRIVER_PRIVATE_H_
+
+#include "base_driver_device.h"
+
+celix_status_t baseDriver_create(apr_pool_t *pool, base_driver_device_t *service);
+celix_status_t baseDriver_createService(base_driver_device_t device, base_driver_device_service_t *service);
+
+celix_status_t baseDriver_noDriverFound(device_t device);
+
+celix_status_t baseDriver_getNextChar(base_driver_device_t service, char *c);
+
+#endif /* BASE_DRIVER_PRIVATE_H_ */
Propchange: incubator/celix/trunk/device_access/example/base_driver/private/include/base_driver_private.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c (added)
+++ incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,136 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+#include <apr_pools.h>
+
+#include <celix_errno.h>
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.h>
+#include <device.h>
+
+#include "base_driver_private.h"
+#include "base_driver_device.h"
+
+struct base_driver_bundle_instance {
+ BUNDLE_CONTEXT context;
+ apr_pool_t * pool;
+ ARRAY_LIST serviceRegistrations;
+};
+
+typedef struct base_driver_bundle_instance *base_driver_bundle_instance_t;
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ printf("BASE_DRIVER: creating bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *pool;
+ status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ base_driver_bundle_instance_t instance = apr_palloc(pool, sizeof(*instance));
+ if (instance != NULL) {
+ instance->context = context;
+ instance->pool = pool;
+ status = arrayList_create(pool, &instance->serviceRegistrations);
+ if (status == CELIX_SUCCESS) {
+ (*userData) = instance;
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ }
+ return status;
+}
+
+static celix_status_t bundleActivator_registerBaseDriverDevice(base_driver_bundle_instance_t bi, char *serial) {
+ celix_status_t status = CELIX_SUCCESS;
+ base_driver_device_t device = NULL;
+ status = baseDriver_create(bi->pool, &device);
+ if (status == CELIX_SUCCESS) {
+ base_driver_device_service_t service = NULL;
+ status = baseDriver_createService(device, &service);
+ if (status == CELIX_SUCCESS) {
+ PROPERTIES props = properties_create();
+ properties_set(props, DEVICE_CATEGORY, BASE_DRIVER_DEVICE_CATEGORY);
+ properties_set(props, DEVICE_SERIAL, serial);
+ SERVICE_REGISTRATION service_registration = NULL;
+ status = bundleContext_registerService(bi->context, DEVICE_SERVICE_NAME, service, props, &service_registration);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(bi->serviceRegistrations, service_registration);
+// service_registration = NULL;
+// status = bundleContext_registerService(bi->context, BASE_DRIVER_SERVICE_NAME, service, NULL, &service_registration);
+// if (status == CELIX_SUCCESS) {
+// arrayList_add(bi->serviceRegistrations, service_registration);
+// }
+ }
+ }
+ }
+
+ 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));
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ printf("BASE_DRIVER: starting bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ base_driver_bundle_instance_t 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 context) {
+ printf("BASE_DRIVER: stopping bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ base_driver_bundle_instance_t bundleInstance = userData;
+
+ ARRAY_LIST_ITERATOR iterator = arrayListIterator_create(bundleInstance->serviceRegistrations);
+ while (arrayListIterator_hasNext(iterator)) {
+ SERVICE_REGISTRATION 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 context) {
+ printf("BASE_DRIVER: destroying bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ base_driver_bundle_instance_t bundleInstance = userData;
+
+ arrayList_destroy(bundleInstance->serviceRegistrations);
+ return status;
+}
+
Propchange: incubator/celix/trunk/device_access/example/base_driver/private/src/activator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c (added)
+++ incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,91 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+
+#include <celix_errno.h>
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.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_t device;
+ apr_pool_t *pool;
+ char *input;
+ int inputLength;
+ int currentChar;
+};
+
+celix_status_t baseDriver_noDriverFound(device_t device) {
+ printf("BASE_DRIVER: No driver found\n");
+ return CELIX_SUCCESS;
+}
+
+celix_status_t baseDriver_create(apr_pool_t *pool, base_driver_device_t *baseDriverDevice) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*baseDriverDevice) = apr_palloc(pool, sizeof(struct base_driver_device));
+ if (*baseDriverDevice != NULL) {
+ (*baseDriverDevice)->pool=pool;
+ (*baseDriverDevice)->currentChar = 0;
+ (*baseDriverDevice)->input = (char *)INPUT_STRING;
+ (*baseDriverDevice)->inputLength=strlen(INPUT_STRING);
+ (*baseDriverDevice)->device = apr_palloc(pool, sizeof(*(*baseDriverDevice)->device));
+ if ((*baseDriverDevice)->device == NULL) {
+ status = CELIX_ENOMEM;
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ return status;
+}
+
+celix_status_t baseDriver_createService(base_driver_device_t baseDriverDevice, base_driver_device_service_t *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*service) = apr_palloc(baseDriverDevice->pool, 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_t device, char *c) {
+ (*c) = device->input[device->currentChar];
+ device->currentChar+=1;
+ if (device->currentChar >= device->inputLength) {
+ device->currentChar = 0;
+ }
+ return CELIX_SUCCESS;
+}
+
Propchange: incubator/celix/trunk/device_access/example/base_driver/private/src/base_driver.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h (added)
+++ incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,38 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef 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_t;
+
+struct base_driver_device_service {
+ struct device_service deviceService; /*NOTE: base_driver_device_service is a device_service.*/
+ base_driver_device_t baseDriverDevice;
+ celix_status_t (*getNextChar)(base_driver_device_t baseDriverDevice, char *c);
+};
+
+typedef struct base_driver_device_service * base_driver_device_service_t;
+
+#endif /* BASE_DRIVER_DEVICE_H_ */
Propchange: incubator/celix/trunk/device_access/example/base_driver/public/include/base_driver_device.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include(FindAPR)
+
+bundle(word_consumingdriver SOURCES
+ private/src/activator
+ private/src/consuming_driver
+)
+
+include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
+include_directories(${PROJECT_SOURCE_DIR}/device_access/example/refining_driver/public/include)
+include_directories(private/include)
+include_directories("${PROJECT_SOURCE_DIR}/framework/include")
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+target_link_libraries(word_consumingdriver utils ${CELIX_LIBRARY} ${APR_LIBRARY})
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/CMakeLists.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF Wed Jun 20 08:41:25 2012
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: word_consumingdriver
+Bundle-Version: 1.0.0.test
+library: word_consumingdriver
+Import-Service: device
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/README.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/README.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/README.txt (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/README.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,23 @@
+# 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.
+
+
+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.
+
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,37 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef 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_t;
+
+celix_status_t consumingDriver_create(BUNDLE_CONTEXT context, apr_pool_t *pool, consuming_driver_t *driver);
+celix_status_t consumingDriver_createService(consuming_driver_t driver, driver_service_t *service);
+
+celix_status_t consumingDriver_attach(void *driver, SERVICE_REFERENCE reference, char **result);
+celix_status_t consumingDriver_match(void *driver, SERVICE_REFERENCE reference, int *value);
+
+#endif /* CONSUMING_DRIVER_PRIVATE_H_ */
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/private/include/consuming_driver_private.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,106 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+#include <apr_pools.h>
+
+#include <celix_errno.h>
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.h>
+#include <device.h>
+
+#include "consuming_driver_private.h"
+
+struct consuming_driver_bundle_instance {
+ BUNDLE_CONTEXT context;
+ apr_pool_t * pool;
+ SERVICE_REGISTRATION registration;
+};
+
+typedef struct consuming_driver_bundle_instance *consuming_driver_bundle_instance_t;
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ printf("CONSUMING_DRIVER: creating bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *pool;
+ status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ consuming_driver_bundle_instance_t instance = apr_palloc(pool, sizeof(*instance));
+ if (instance != NULL) {
+ instance->context = context;
+ instance->pool = pool;
+ instance->registration = NULL;
+ (*userData) = instance;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ printf("CONSUMING_DRIVER: starting bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ consuming_driver_bundle_instance_t bi = userData;
+
+ consuming_driver_t driver = NULL;
+ status = consumingDriver_create(context, bi->pool, &driver);
+ if (status == CELIX_SUCCESS) {
+ driver_service_t service = NULL;
+ status = consumingDriver_createService(driver, &service);
+ if (status == CELIX_SUCCESS) {
+ PROPERTIES props = properties_create();
+ properties_set(props, "DRIVER_ID", CONSUMING_DRIVER_ID);
+ status = bundleContext_registerService(context, 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 context) {
+ printf("CONSUMING_DRIVER: stopping bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ consuming_driver_bundle_instance_t 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 context) {
+ printf("CONSUMING_DRIVER: destroying bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ consuming_driver_bundle_instance_t bi = userData;
+ return status;
+}
+
+
+
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/private/src/activator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c (added)
+++ incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,140 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+#include <apr_pools.h>
+#include <apr_thread_proc.h>
+#include <apr_thread_cond.h>
+#include <apr_thread_mutex.h>
+
+#include <device.h>
+#include <service_tracker.h>
+#include <service_reference.h>
+
+#include "celixbool.h"
+#include "consuming_driver_private.h"
+#include "refining_driver_device.h"
+
+
+struct consuming_driver {
+ apr_pool_t *pool;
+ BUNDLE_CONTEXT context;
+ ARRAY_LIST references;
+};
+
+static apr_status_t consumingDriver_cleanup(void *handler) {
+ printf("CONSUMING_DRIVER: cleanup\n");
+ consuming_driver_t driver = handler;
+
+ if (driver->references != NULL) {
+ ARRAY_LIST_ITERATOR iterator = arrayListIterator_create(driver->references);
+ while (arrayListIterator_hasNext(iterator)) {
+ SERVICE_REFERENCE reference = arrayListIterator_next(iterator);
+ bool result;
+ bundleContext_ungetService(driver->context, reference, &result);
+ }
+ arrayListIterator_destroy(iterator);
+
+ arrayList_destroy(driver->references);
+ driver->references=NULL;
+ }
+
+
+ return APR_SUCCESS;
+}
+
+celix_status_t consumingDriver_create(BUNDLE_CONTEXT context, apr_pool_t *pool, consuming_driver_t *driver) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*driver) = apr_palloc(pool, sizeof(**driver));
+ if ((*driver) != NULL) {
+ (*driver)->pool=pool;
+ (*driver)->context=context;
+ (*driver)->references=NULL;
+
+ status = arrayList_create(pool, &(*driver)->references);
+
+ apr_pool_pre_cleanup_register(pool, (*driver), consumingDriver_cleanup);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ return status;
+}
+
+celix_status_t consumingDriver_createService(consuming_driver_t driver, driver_service_t *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*service) = apr_palloc(driver->pool, 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 reference, char **result) {
+ printf("CONSUMING_DRIVER: attached called\n");
+ celix_status_t status = CELIX_SUCCESS;
+ consuming_driver_t driver = driverHandler;
+ (*result) = NULL;
+ refining_driver_device_service_t device_service = NULL;
+
+ status = bundleContext_getService(driver->context, reference, (void **)&device_service);
+ if (status == CELIX_SUCCESS) {
+ arrayList_add(driver->references, reference);
+ //consume the device
+ apr_pool_t *strpool = NULL;
+ apr_status_t aprStatus = apr_pool_create(&strpool, driver->pool);
+ if (aprStatus == APR_SUCCESS) {
+ for (int i=0; i<15; i++) {
+ char *str = NULL;
+ device_service->getNextWord(device_service->refiningDriverDevice, strpool, &str);
+ printf("CONSUMING_DEVICE: Word Device result is %s\n", str);
+ }
+ apr_pool_destroy(strpool);
+ }
+ }
+ return status;
+}
+
+celix_status_t consumingDriver_match(void *driverHandler, SERVICE_REFERENCE reference, int *value) {
+ printf("CONSUMING_DRIVER: match called\n");
+ int match=0;
+ celix_status_t status = CELIX_SUCCESS;
+ consuming_driver_t driver = driverHandler;
+
+ SERVICE_REGISTRATION registration = NULL;
+ PROPERTIES properties = NULL;
+ status = serviceReference_getServiceRegistration(reference, ®istration);
+ if (status == CELIX_SUCCESS) {
+ status = serviceRegistration_getProperties(registration, &properties);
+ if (status == CELIX_SUCCESS) {
+ char *category = properties_get(properties, DEVICE_CATEGORY);
+ if (strcmp(category, REFINING_DRIVER_DEVICE_CATEGORY) == 0) {
+ match = 10;
+ }
+ }
+ }
+
+ (*value) = match;
+ return status;
+}
+
Propchange: incubator/celix/trunk/device_access/example/consuming_driver/private/src/consuming_driver.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include(FindAPR)
+
+bundle(char_refiningdriver SOURCES
+ private/src/activator
+ private/src/refining_driver
+)
+
+include_directories(${PROJECT_SOURCE_DIR}/device_access/device_access/public/include)
+include_directories(${PROJECT_SOURCE_DIR}/device_access/example/base_driver/public/include)
+include_directories(private/include)
+include_directories(public/include)
+include_directories("${PROJECT_SOURCE_DIR}/framework/public/include")
+include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
+target_link_libraries(char_refiningdriver utils ${CELIX_LIBRARY} ${APR_LIBRARY})
Propchange: incubator/celix/trunk/device_access/example/refining_driver/CMakeLists.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF Wed Jun 20 08:41:25 2012
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: char_refiningdriver
+Bundle-Version: 1.0.0.test
+library: char_refiningdriver
+Import-Service: device
Propchange: incubator/celix/trunk/device_access/example/refining_driver/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/README.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/README.txt?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/README.txt (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/README.txt Wed Jun 20 08:41:25 2012
@@ -0,0 +1,22 @@
+# 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.
+
+A refining driver is a driver which is able to attache to certained device services and
+as result publishes differerent - 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.
+
Propchange: incubator/celix/trunk/device_access/example/refining_driver/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,51 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef 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_t;
+
+celix_status_t refiningDriver_create(BUNDLE_CONTEXT context, apr_pool_t *pool, refining_driver_t *driver);
+celix_status_t refiningDriver_destroy(refining_driver_t driver);
+
+celix_status_t refiningDriver_createService(refining_driver_t driver, driver_service_t *service);
+
+celix_status_t refiningDriver_createDevice(refining_driver_t driver, SERVICE_REFERENCE reference, base_driver_device_service_t baseDevice, refining_driver_device_t *device);
+celix_status_t refiningDriver_destroyDevice(refining_driver_device_t device);
+
+
+celix_status_t refiningDriver_attach(void *driver, SERVICE_REFERENCE reference, char **result);
+celix_status_t refiningDriver_match(void *driver, SERVICE_REFERENCE reference, int *value);
+
+
+celix_status_t refiningDriverDevice_noDriverFound(device_t device);
+celix_status_t refiningDriverDevice_createService(refining_driver_device_t, refining_driver_device_service_t *service);
+celix_status_t refiningDriverDevice_getNextWord(refining_driver_device_t refiningDriverDevice, apr_pool_t *pool, char **word);
+
+#endif /* REFINING_DRIVER_PRIVATE_H_ */
Propchange: incubator/celix/trunk/device_access/example/refining_driver/private/include/refining_driver_private.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,106 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+#include <apr_pools.h>
+
+#include <celix_errno.h>
+#include <bundle_activator.h>
+#include <bundle_context.h>
+#include <celixbool.h>
+#include <device.h>
+
+#include "refining_driver_private.h"
+
+struct refining_driver_bundle_instance {
+ BUNDLE_CONTEXT context;
+ apr_pool_t * pool;
+ SERVICE_REGISTRATION registration;
+};
+
+typedef struct refining_driver_bundle_instance *refining_driver_bundle_instance_t;
+
+celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) {
+ printf("REFINING_DRIVER: creating bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *pool;
+ status = bundleContext_getMemoryPool(context, &pool);
+ if (status == CELIX_SUCCESS) {
+ refining_driver_bundle_instance_t instance = apr_palloc(pool, sizeof(*instance));
+ if (instance != NULL) {
+ instance->context = context;
+ instance->pool = pool;
+ instance->registration = NULL;
+ (*userData) = instance;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ }
+ return status;
+}
+
+celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+ printf("REFINING_DRIVER: starting bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_bundle_instance_t bi = userData;
+
+ refining_driver_t driver = NULL;
+ status = refiningDriver_create(context, bi->pool, &driver);
+ if (status == CELIX_SUCCESS) {
+ driver_service_t service = NULL;
+ status = refiningDriver_createService(driver, &service);
+ if (status == CELIX_SUCCESS) {
+ PROPERTIES props = properties_create();
+ properties_set(props, "DRIVER_ID", REFINING_DRIVER_ID);
+ status = bundleContext_registerService(context, 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 context) {
+ printf("REFINING_DRIVER: stopping bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_bundle_instance_t 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 context) {
+ printf("REFINING_DRIVER: destroying bundle\n");
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_bundle_instance_t bi = userData;
+ return status;
+}
+
+
+
Propchange: incubator/celix/trunk/device_access/example/refining_driver/private/src/activator.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c Wed Jun 20 08:41:25 2012
@@ -0,0 +1,293 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#include <stdlib.h>
+#include <apr_strings.h>
+#include <apr_pools.h>
+#include <apr_thread_proc.h>
+#include <apr_thread_cond.h>
+#include <apr_thread_mutex.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_t device;
+ apr_pool_t *pool;
+ BUNDLE_CONTEXT context;
+ int deviceCount;
+ ARRAY_LIST devices;
+};
+
+struct device {
+ /*NOTE: for this example we use a empty device structure*/
+};
+
+struct refining_driver_device {
+ device_t device;
+ apr_pool_t *pool;
+ base_driver_device_service_t baseDriverDeviceService;
+ refining_driver_t driver;
+ SERVICE_REFERENCE baseServiceReference;
+ SERVICE_REGISTRATION deviceRegistration;
+ SERVICE_LISTENER listener;
+};
+
+celix_status_t refiningDriver_destroy(refining_driver_t driver) {
+ apr_pool_destroy(driver->pool);
+ return CELIX_SUCCESS;
+}
+
+static apr_status_t refiningDriver_cleanup(void *handler) {
+ refining_driver_t driver = handler;
+ if (driver != NULL) {
+ if (driver->devices != NULL) {
+ arrayList_destroy(driver->devices);
+ driver->devices=NULL;
+ }
+ }
+ return CELIX_SUCCESS;
+}
+
+celix_status_t refiningDriver_create(BUNDLE_CONTEXT context, apr_pool_t *pool, refining_driver_t *driver) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *driverPool = NULL;
+ apr_status_t aprStatus = apr_pool_create(&driverPool, pool);
+ (*driver) = apr_palloc(driverPool, sizeof(**driver));
+ if ((*driver) != NULL) {
+ apr_pool_pre_cleanup_register(driverPool, (*driver), refiningDriver_cleanup);
+ (*driver)->pool=driverPool;
+ (*driver)->context=context;
+ (*driver)->deviceCount=0;
+ (*driver)->device = apr_palloc(driverPool, sizeof(*(*driver)->device));
+ (*driver)->devices=NULL;
+ status = arrayList_create(driverPool, &(*driver)->devices);
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ return status;
+}
+
+celix_status_t refiningDriver_createService(refining_driver_t driver, driver_service_t *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*service) = apr_palloc(driver->pool, 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_t 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);
+ apr_pool_destroy(device->pool);
+ return status;
+}
+
+
+static celix_status_t refiningDriver_serviceChanged(SERVICE_LISTENER listener, SERVICE_EVENT event) {
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_device_t device = listener->handle;
+ if (event->type == 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_t device) {
+ apr_pool_destroy(device->pool);
+ return CELIX_SUCCESS;
+}
+
+static apr_status_t refining_driver_cleanup_device(void *handler) {
+ apr_status_t status = APR_SUCCESS;
+ refining_driver_device_t 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_t driver, SERVICE_REFERENCE reference, base_driver_device_service_t baseService, refining_driver_device_t *device) {
+ celix_status_t status = CELIX_SUCCESS;
+ apr_pool_t *devicePool = NULL;
+ apr_status_t aprStatus = apr_pool_create(&devicePool, driver->pool);
+
+ if (aprStatus == APR_SUCCESS) {
+ (*device) = apr_palloc(devicePool, sizeof(**device));
+ if ((*device) != NULL) {
+ apr_pool_pre_cleanup_register(devicePool, (*device), refining_driver_cleanup_device);
+ (*device)->driver=driver;
+ (*device)->pool=devicePool;
+ (*device)->baseDriverDeviceService=baseService;
+ (*device)->baseServiceReference=reference;
+ (*device)->deviceRegistration=NULL;
+ (*device)->listener=NULL;
+
+ SERVICE_LISTENER listener = apr_palloc(devicePool, sizeof(*listener));
+ listener->pool=devicePool;
+ listener->handle=(void *)(*device);
+ listener->serviceChanged=(celix_status_t (*)(void * listener, SERVICE_EVENT event))refiningDriver_serviceChanged;
+ bundleContext_addServiceListener(driver->context, listener, NULL);
+ (*device)->listener=listener;
+
+ arrayList_add(driver->devices, (*device));
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ return status;
+}
+
+
+static celix_status_t refiningDriver_registerDevice(refining_driver_t driver, refining_driver_device_t device, char *serial) {
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_device_service_t service = NULL;
+ status = refiningDriverDevice_createService(device, &service);
+ if (status == CELIX_SUCCESS) {
+ PROPERTIES props = properties_create();
+ properties_set(props, DEVICE_CATEGORY, REFINING_DRIVER_DEVICE_CATEGORY);
+ properties_set(props, DEVICE_SERIAL, serial);
+ status = bundleContext_registerService(driver->context, DEVICE_SERVICE_NAME, service, props, &device->deviceRegistration);
+ }
+
+ if (status == CELIX_SUCCESS) {
+ printf("REFINING_DRIVER: registered refining device with serial %s\n", serial);
+ }
+ return status;
+}
+
+celix_status_t refiningDriver_attach(void * driverHandler, SERVICE_REFERENCE reference, char **result) {
+ printf("REFINING_DRIVER: attached called\n");
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_t driver = driverHandler;
+ (*result) = NULL;
+ device_service_t device = NULL;
+ base_driver_device_service_t device_service = NULL;
+ status = bundleContext_getService(driver->context, reference, (void **)&device_service);
+ if (status == CELIX_SUCCESS) {
+ refining_driver_device_t refiningDevice = NULL;
+ status = refiningDriver_createDevice(driver, reference, device_service, &refiningDevice);
+ if (status == CELIX_SUCCESS) {
+ driver->deviceCount+=1;
+ char serial[5];
+ sprintf(serial, "%4i", driver->deviceCount);
+ status = refiningDriver_registerDevice(driver, refiningDevice, serial);
+ }
+ }
+ return status;
+}
+
+celix_status_t refiningDriver_match(void *driverHandler, SERVICE_REFERENCE reference, int *value) {
+ printf("REFINING_DRIVER: match called\n");
+ int match = 0;
+ celix_status_t status = CELIX_SUCCESS;
+ refining_driver_t driver = driverHandler;
+
+ SERVICE_REGISTRATION registration = NULL;
+ PROPERTIES properties = NULL;
+ status = serviceReference_getServiceRegistration(reference, ®istration);
+ if (status == CELIX_SUCCESS) {
+ status = serviceRegistration_getProperties(registration, &properties);
+ if (status == CELIX_SUCCESS) {
+ char *category = properties_get(properties, DEVICE_CATEGORY);
+ if (strcmp(category, BASE_DRIVER_DEVICE_CATEGORY) == 0) {
+ match = 10;
+ }
+ }
+ }
+
+ (*value) = match;
+ return status;
+}
+
+celix_status_t refiningDriverDevice_createService(refining_driver_device_t device, refining_driver_device_service_t *service) {
+ celix_status_t status = CELIX_SUCCESS;
+ (*service) = apr_palloc(device->pool, sizeof(**service));
+ if ((*service) != NULL) {
+ (*service)->deviceService.device=apr_palloc(device->pool, 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_getNextWord(refining_driver_device_t refiningDriverDevice, apr_pool_t *pool, char **word) {
+ celix_status_t status = CELIX_SUCCESS;
+ base_driver_device_t 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 = apr_palloc(pool, (i+1));
+ if (copy != NULL) {
+ strcpy(copy, buff);
+ (*word)=copy;
+ } else {
+ status = CELIX_ENOMEM;
+ }
+ }
+
+ return status;
+}
+
+celix_status_t refiningDriverDevice_noDriverFound(device_t device) {
+ printf("REFINING_DRIVER: no driver found");
+ return CELIX_SUCCESS;
+}
+
Propchange: incubator/celix/trunk/device_access/example/refining_driver/private/src/refining_driver.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h?rev=1351992&view=auto
==============================================================================
--- incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h (added)
+++ incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h Wed Jun 20 08:41:25 2012
@@ -0,0 +1,39 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements. See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership. The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#ifndef 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_t;
+
+struct refining_driver_device_service {
+ struct device_service deviceService; /*NOTE: base_driver_device_service is a device_service.*/
+ refining_driver_device_t refiningDriverDevice;
+ celix_status_t (*getNextWord)(refining_driver_device_t refiningDriverDevice, apr_pool_t *pool, char **c);
+};
+
+typedef struct refining_driver_device_service * refining_driver_device_service_t;
+
+#endif /* REFINING_DRIVER_DEVICE_H_ */
Propchange: incubator/celix/trunk/device_access/example/refining_driver/public/include/refining_driver_device.h
------------------------------------------------------------------------------
svn:mime-type = text/plain