On Thu, Jan 26, 2012 at 3:06 PM, Marcel Offermans
<[email protected]> wrote:
> On Jan 26, 2012, at 13:54 PM, Alexander Broekhuis wrote:
>
>> Hi,
>>
>> 2012/1/26 Marcel Offermans <[email protected]>
>>
>>>
>>>> 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.

Ok, so in Java you would solve this by looking up a B service the same
service.id property as A or another agreed on/specified property ?


>
> Greetings, Marcel
>

Reply via email to