celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pepijn Noltes <pepijnnol...@gmail.com>
Subject Celix services and struct inheritance
Date Thu, 26 Jan 2012 12:19:53 GMT
Hi All,

I have a problem relating to Celix services and inheritance. The
problem is than under Java it's quite normal to cast retrieved
services to a derived type, but under C this is not as easy and not
safe (no RTTI ->no instanceof). For example the device access
implementation example now uses c inheritance
see snippets below:

Snippet device.h:
struct device_service {
	device_t device;
	celix_status_t (*noDriverFound)(device_t device);

typedef struct device_service * device_service_t;

Snippet base_driver_device.h:
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;

Snippet getService example:
device_service_t service = NULL;
base_driver_device_service_t derivedService = NULL;
status = bundleContext_getService(driver->context, reference, (void **)&service)
derivedService = service;
//You can use service as device_service_t and derivedService as

But I am not really happy with this solution. It leans to much on the
assumption service pointer can be cast to derived type and there is no
way to check if this is correct.
In my opinion there are 2 alternative to this:
Register multiple services. But than means I am left with the
challenge how to find the related service.

Adjust Celix so that a registration is possible for multiple service
names in combination with multiple service structs and provide a
method to retrieve named services for a serviceReference. Something
celix_status_t bundleContext_getService(BUNDLE_CONTEXT context,
SERVICE_REFERENCE reference, char *serviceName, void
The problem with this solution is of course that Celix will deviate
from the OSGi spec.

Any thoughts/ideas/suggestions?


View raw message