celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Offermans <marcel.offerm...@luminis.nl>
Subject Re: Celix services and struct inheritance
Date Thu, 26 Jan 2012 14:06:39 GMT
On Jan 26, 2012, at 13:54 PM, Alexander Broekhuis wrote:

> Hi,
> 2012/1/26 Marcel Offermans <marcel.offermans@luminis.nl>
>>> In my opinion there are 2 alternative to this:
>>> 1)
>>> Register multiple services. But than means I am left with the
>>> challenge how to find the related service.
>> In Java, you already have the option of registering an instance under
>> multiple service names. Would doing the same for C solve your issue?
> This can only work if something like struct inheritance is being used. In
> the case of Java, one component can implement multiple services. In Celix,
> a service is a struct with service pointers. So there is always a one
> (name) to one (struct) relation. To be able to have one component with
> multiple services, and still be able to only retrieve one specific service
> something like struct inheritance is needed.
> Another possibility is to register service - component pairs. This way one
> service has a specific struct with function pointers and no struct
> inheritance is needed. It is up to the user to always use the correct
> service name to retrieve the needed struct.
> So when trying to follow the spec, struct inheritance makes more sense. But
> there are possibly more drawbacks, when using struct inheritance the first
> field has to be the parent struct (not a pointer), this implies that
> abstract data types can't be used, exposing the content of a struct to the
> user.

Fair enough.

> As a note, in the Java case, is it acceptable to register service A and B
> with one component, and when retrieving service A cast it later to B? In
> other words, if a different service is needed, does a user need to do a
> getServiceReference/getService again?

In general I would say no. When you lookup a service in the registry, you have no way of knowing
who provided it (without doing more work) so I would never depend on something like this.
Even if you know there is an implementation that publishes A and B with the same backing instance
(and using one single ServiceRegistration) there might be some interceptor, hook or proxy
that you don't know of.

Greetings, Marcel

View raw message