You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by Alexander Broekhuis <a....@gmail.com> on 2012/06/04 15:01:13 UTC
[Native-OSGi] Usage of arrays vs collections
Hi,
I'm working on extracting the OSGi API's from Celix to the Native-OSGi
project. Celix uses a utils library through which Lists and Maps are
provided.
How do we want to solve this in the API? Following the OSGi API, often a
simple array is used (Celix uses an ArrayList in those cases). But the Java
Collection/Dictionary etc are also used.
A simple/portable solution would be to use arrays with an additional return
parameter for places where a collection/list is used. For example:
int bundleContext_getBundles(bundle_context_t context, bundle bundles[],
int *entries);
A similar solution can be used for Dictionaries as well, a simple key/value
struct can be used.
How do we want to solve this? I don't know of any standard C library, and
what about C++?
--
Met vriendelijke groet,
Alexander Broekhuis
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Alexander Broekhuis <a....@gmail.com>.
Hi Rhys,
> You might find SGLIB's "Level 1 API" fits the bill for C and also maps
> reasonably well to C++. The download link off SGLIB's main website
> [1] is broken but the files can be had from the project's Sourceforge
> page [2]. It's licensing should not be a problem [3].
Thx for the links, I will check it out.
But Celix already has a similar utils library now. The simplest for me
would be to use that one for the Native-OSGi project.
--
Met vriendelijke groet,
Alexander Broekhuis
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Rhys Ulerich <rh...@gmail.com>.
> For C there isn't such thing, so we either have to use an existing
> library, or provide something ourselves.
> Since I don't know of any library, I think the later case makes most sense.
>
> Sascha: What makes sense for C++?
You might find SGLIB's "Level 1 API" fits the bill for C and also maps
reasonably well to C++. The download link off SGLIB's main website
[1] is broken but the files can be had from the project's Sourceforge
page [2]. It's licensing should not be a problem [3].
- Rhys
[1] http://sglib.sourceforge.net/
[2] http://sourceforge.net/projects/sglib/files/
[3] http://sglib.sourceforge.net/#license
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Alexander Broekhuis <a....@gmail.com>.
Hi,
> >
> > How do we want to solve this? I don't know of any standard C library, and
> > what about C++?
>
> C++ has C++ Standard Library (STD), which contains arrays, queues,
> maps, etc and is - if i am correct - part of the C++ standard.
> Because C does not have this, I think the purposed solution is a good one.
>
For most parts this will work, basically I will try to follow the OSGi spec
and use an array where it also uses one.
But...
>
> An other option is to make the needed C collections part of the OSGi
> API. Which has the advantages that we can use linked arrays, hash
> maps, etc. The drawback is that we impose a API for something which is
> clearly not part of OSGi.
>
For certain cases something like this is needed, for example for the bundle
headers or service properties. The OSGi spec uses a dictionary for these
cases (which is obsolete and replaced by the Map interface).
Also Enumeration is used quite often. At the moment there is no alternative
for this one in Celix.
Heaving these as part of Native-OSGi isn't a problem as far as I am
concerned. For Java it isn't needed, because it is part of the Java runtime
itself. For C there isn't such thing, so we either have to use an existing
library, or provide something ourselves.
Since I don't know of any library, I think the later case makes most sense.
Sascha: What makes sense for C++?
>
> Greetings,
> Pepijn
>
--
Met vriendelijke groet,
Alexander Broekhuis
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Sascha Zelzer <s....@dkfz-heidelberg.de>.
Hi,
On 06/05/2012 08:48 PM, Alexander Broekhuis wrote:
>> Even for the C++ API, there are some places where I would like to
>> introduce custom data structures to make the life of the API user easier
>> and/or more type-safe.
>>
> Could you check out the "utils" library of Celix and how these can be used
> from C++? Maybe they provide the support that is needed.
>
I had a look at the utils library but pretty much everything in there
(except hash maps) are covered by the C++ standard (in the STL). I was
rather talking about very C++ specific extensions.
Thanks,
Sascha
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Alexander Broekhuis <a....@gmail.com>.
>
> I agree with Pepijn here that imposing a (very small) set of utility
> functions/structs on the API is acceptable. I would personally always
> favour ease of use (concerning the API) over strictly sticking to "pure C".
> If there exists a small C library which we could embed or from which we
> could extract relevant structures for the API, then go for it.
>
Celix already has several collections/lists in a utils library. For now I
will use those. I will also check the library suggested by Rhys, I've
already seen it has no (Hash)Maps, and we definitely need that one.
> Even for the C++ API, there are some places where I would like to
> introduce custom data structures to make the life of the API user easier
> and/or more type-safe.
>
Could you check out the "utils" library of Celix and how these can be used
from C++? Maybe they provide the support that is needed.
--
Met vriendelijke groet,
Alexander Broekhuis
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Sascha Zelzer <s....@dkfz-heidelberg.de>.
Hi,
On 06/04/2012 08:40 PM, Pepijn Noltes wrote:
> Hi All,
>
> On Mon, Jun 4, 2012 at 3:01 PM, Alexander Broekhuis
> <a....@gmail.com> wrote:
>> Hi,
>>
>> I'm working on extracting the OSGi API's from Celix to the Native-OSGi
>> project. Celix uses a utils library through which Lists and Maps are
>> provided.
>>
>> How do we want to solve this in the API? Following the OSGi API, often a
>> simple array is used (Celix uses an ArrayList in those cases). But the Java
>> Collection/Dictionary etc are also used.
>>
>> A simple/portable solution would be to use arrays with an additional return
>> parameter for places where a collection/list is used. For example:
>>
>> int bundleContext_getBundles(bundle_context_t context, bundle bundles[],
>> int *entries);
>>
>> A similar solution can be used for Dictionaries as well, a simple key/value
>> struct can be used.
>>
>> How do we want to solve this? I don't know of any standard C library, and
>> what about C++?
> C++ has C++ Standard Library (STD), which contains arrays, queues,
> maps, etc and is - if i am correct - part of the C++ standard.
> Because C does not have this, I think the purposed solution is a good one.
I agree with Pepijn here that imposing a (very small) set of utility
functions/structs on the API is acceptable. I would personally always
favour ease of use (concerning the API) over strictly sticking to "pure
C". If there exists a small C library which we could embed or from which
we could extract relevant structures for the API, then go for it.
Even for the C++ API, there are some places where I would like to
introduce custom data structures to make the life of the API user easier
and/or more type-safe.
Best,
Sascha
>
> An other option is to make the needed C collections part of the OSGi
> API. Which has the advantages that we can use linked arrays, hash
> maps, etc. The drawback is that we impose a API for something which is
> clearly not part of OSGi.
>
> Greetings,
> Pepijn
Re: [Native-OSGi] Usage of arrays vs collections
Posted by Pepijn Noltes <pe...@gmail.com>.
Hi All,
On Mon, Jun 4, 2012 at 3:01 PM, Alexander Broekhuis
<a....@gmail.com> wrote:
> Hi,
>
> I'm working on extracting the OSGi API's from Celix to the Native-OSGi
> project. Celix uses a utils library through which Lists and Maps are
> provided.
>
> How do we want to solve this in the API? Following the OSGi API, often a
> simple array is used (Celix uses an ArrayList in those cases). But the Java
> Collection/Dictionary etc are also used.
>
> A simple/portable solution would be to use arrays with an additional return
> parameter for places where a collection/list is used. For example:
>
> int bundleContext_getBundles(bundle_context_t context, bundle bundles[],
> int *entries);
>
> A similar solution can be used for Dictionaries as well, a simple key/value
> struct can be used.
>
> How do we want to solve this? I don't know of any standard C library, and
> what about C++?
C++ has C++ Standard Library (STD), which contains arrays, queues,
maps, etc and is - if i am correct - part of the C++ standard.
Because C does not have this, I think the purposed solution is a good one.
An other option is to make the needed C collections part of the OSGi
API. Which has the advantages that we can use linked arrays, hash
maps, etc. The drawback is that we impose a API for something which is
clearly not part of OSGi.
Greetings,
Pepijn