-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add celix_properties_t and celix_array_list_t pointer type to dfi #782
Open
xuzhenbao
wants to merge
3
commits into
apache:master
Choose a base branch
from
xuzhenbao:add_dyn_type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,9 @@ The data types supported by the interface description include: | |
|
||
*Type schema*: | ||
|
||
|**Identifier**|B |D |F |I |J |S |V |Z |b | i | j | s |P | t |N | | ||
|---------|---|------|-----|-------|-------|-------|----|--------------|-----|--------|--------|--------|------|------------------|---| | ||
|**Types**|char|double|float|int32_t|int64_t|int16_t|void|boolean(uint8)|uchar|uint32_t|uint64_t|uint16_t|void *| char *(C string) |int| | ||
|**Identifier**|B |D |F |I |J |S |V |Z |b | i | j | s |P | t |N | p | a | | ||
|---------|---|------|-----|-------|-------|-------|----|--------------|-----|--------|--------|--------|------|------------------|---|---------------------|---------------------| | ||
|**Types**|char|double|float|int32_t|int64_t|int16_t|void|boolean(uint8)|uchar|uint32_t|uint64_t|uint16_t|void *| char *(C string) |int| celix_properties_t* | celix_array_list_t* | | ||
|
||
|
||
- **Complex Types(Struct)** | ||
|
@@ -236,12 +236,12 @@ The data types supported by the interface description include: | |
~~~ | ||
In order to represent the properties of function parameters (eg: in, out...), function parameters support the following metadata annotations: | ||
|
||
|Meta-info| Description| | ||
|---------|------------| | ||
|am=handle| void pointer for the handle.| | ||
|am=pre | output pointer with memory pre-allocated, it should be pointer to [trivially copyable type](#notion-definitions).| | ||
|am=out | output pointer, the caller should use `free` to release the memory, and it should be pointer to text(t) or double pointer to [serializable types](#notion-definitions).| | ||
|const=true| text argument(t) can use it, Normally a text argument will be handled as char*, meaning that the callee is expected to take of ownership.If a const=true annotation is used the text argument will be handled as a const char*, meaning that the caller keeps ownership of the string.| | ||
|Meta-info| Description | | ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
|am=handle| void pointer for the handle. | | ||
|am=pre | output pointer with memory pre-allocated, it should be pointer to [trivially copyable type](#notion-definitions). | | ||
|am=out | output pointer, the caller should use `free` to release the memory, and it should be pointer to text(t) or double pointer to [serializable types](#notion-definitions). | | ||
|const=true| text argument(t) and `celix_properties_t*`(p) and `celix_array_list_t*`(a) can use it, Normally a text argument will be handled as char*, meaning that the callee is expected to take of ownership.If a const=true annotation is used the text argument will be handled as a const char*, meaning that the caller keeps ownership of the string. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: The properties and array_list types have been added as potential targets for
|
||
|
||
If there is no metadata annotation, the default is standard argument(input parameter). And it can be any serializable type. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
:header | ||
type=interface | ||
name=example8 | ||
version=1.0.0 | ||
:annotations | ||
:types | ||
:methods | ||
getProps=getProps(#am=handle;P#am=out;*p)N | ||
setProps=setProps(#am=handle;Pp)N | ||
setConstProps=setConstProps(#am=handle;P#const=true;p)N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
:header | ||
type=interface | ||
name=example8 | ||
version=1.0.0 | ||
:annotations | ||
:types | ||
:methods | ||
getArrayList=getArrayList(#am=handle;P#am=out;*a)N | ||
setArrayList=setArrayList(#am=handle;Pa)N | ||
setConstArrayList=setConstArrayList(#am=handle;P#const=true;a)N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a descriptor
a
enough for array list?With the current implementation of array list, the array element type is fixed at creation. Using the array list wrong (e.g. getLong, when it is a string) will lead to an assert failure.
With dfi you can serializer / deserialize array list of any element type, but the underlying code will assume a element type (or needs to use defense programming by checking the element type before continuing).
Maybe it is better to use different dfi descriptor for the different array lists (string, long, double, boolean and version).
@xuzhenbao and @PengZheng WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or
a
together with type annotation using meta-info.And then the dfi could do the type-checking.
Will it make the local service different from the remote ones?
For a local service, we must do the type-checking anyway.
Or shall we make array element type assertions instead so that local/remote services could be unified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
a
with annotations sound good.IMO there is a different between local calls and remote calls. Generally speaking local calls can be trusted (although here is also room for improvement (static bundles / signed bundles, because you can dynamically install new bundles). A remote call is less trustworthy, so IMO crashing (assert fail) is then not an option.
To be honest, I am still unsure if the current array list implementation is the correct approach. Another option could be to really split up the public array list API in a long, double, string, pointer, boolean, version array. So something like:
celix_long_array_list_t
with functions likecelix_longArrayList_get
, etc.The underlying code can still be the current array_list, but the public api only provided wrapper around the generic impl.
If we want to do that, this can and should be done separate from this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree.
Imagine that we are dealing with json rather than array list or properties, there are at least two options:
json_is_array
etc.Both should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using JSON Schema is indeed a good option. It helps avoid overly defensive programming and ensures validation occurs before messages are deserialized.
However, isn’t the DFI descriptor already a form of serialization schema? But less focused on the serialized format itself and more on the memory representation (excluding padding and alignment details, which are handled by libffi).
Given that libjansson does not support JSON Schema, I believe it would be better to extend the DFI type system to be more explicit. This could also open the door to future enhancements, such as adding support for annotations like
min
/max
.One potential downside of this approach is that it would no longer be possible to generate a descriptor string directly from a header file. Currently, - I think - this is possible (e.g., parsing a
celix_array_list_t*
field by adding ana
descriptor type). This is why I think it might be better to replacecelix_array_list_t
with type-specific versions.For now, my proposal is to keep the
a
descriptor for this pull request. If we decide to replacecelix_array_list_t
with type-specific versions in the future, both the DFI and serialization logic would need to be updated accordingly.