system-info-generated: Introudce system-info-generated
The new system-info API has been introduced. We call it
'system-info-generated' as it is automatically generated out of
model-config.xml.
There are 3 main features:
1. As aformentioned, and its name is saying, the new API comprises
fully auto-generated code and header.
2. The new API provides full set of exclusive getter functions for
each single feature, which has specified getter attribute, in
model-config.xml.
3. The new API can understand <enum> scheme in model-config.xml.
And the generated API contains enum declaration derived out of it.
Details:
1. Fully auto-generated API
To this end, SystemInfoGenerator has been introduced. Try running it
at the top directory.
$) python3 -m SystemInfoGenerator --help
The python package provides several options specifying behavior or
output file path it will generate.
2. Generate getter functions for each feature
With help of SystemInfoGenerator, the new API code and header are
generated out of the model-config.xml at build time. It is processed
before building library, generating code, making them be a part of
the library.
For example, if a model-config.xml might have defined features like below,
| <key name="tizen.org/feature/AAA"
| getter="foo" type="string">new.string.feature</key>
| <key name="tizen.org/feature/BBB"
| getter="bar" type="int">3</key>
| <key name="tizen.org/feature/CCC"
| getter="baz" type="bool">True</key>
then, getter functions, one by one for each feature, are generated from
the attribute @getter with prefix 'system_info_get_' before building
capi-system-info library. Here are prototypes of generated getter.
| int system_info_get_foo(char **value);
| int system_info_get_bar(int *value);
| int system_info_get_baz(bool *value);
Calling those getters fetch the feature value.
| #include <system_info_generated.h>
|
| char *s;
| int i;
| bool b;
|
| system_info_get_foo(&s); // s = "new.feature.value"
| system_info_get_bar(&i); // i = 3
| system_info_get_baz(&b); // b = True
Their behavior is totally identical to the previous API.
| #include <system_info.h>
|
| ...
| system_info_get_platform_string("tizen.org/feature/AAA", &s);
| system_info_get_platform_int("tizen.org/feature/BBB", &i);
| system_info_get_platform_bool("tizen.org/feature/CCC", &b);
3. Generate enum declaration
model-config.xml can now declare enum that is a enumeration of
integer, which is in form of C-style enum. For example,
a model-config.xml can declare two types of enum, "some_enum_e"
and "another_enum_e".
| <enum typename="some_enum_e">
| <enumerator>SOME_ENUM_0</enumerator>
| <enumerator>SOME_ENUM_1</enumerator>
| <enumerator>SOME_ENUM_2</enumerator>
| <enumerator>SOME_ENUM_3</enumerator>
| <enumerator>SOME_ENUM_4</enumerator>
| </enum>
| <enum typename="another_enum_e">
| <enumerator value=100>ANOTHER_ENUM_0</enumerator>
| <enumerator>ANOTHER_ENUM_1</enumerator>
| <enumerator>ANOTHER_ENUM_2</enumerator>
| <enumerator>ANOTHER_ENUM_3</enumerator>
| <enumerator>ANOTHER_ENUM_4</enumerator>
| </enum>
The @typename can be used as a @type of feature, and enumerator
value can be used as a feature value. For example, below declaration
is possible.
| <key name="tizen.org/feature/DDD"
| getter="qux" type="some_enum_e">SOME_ENUM_0</key>
| <key name="tizen.org/feature/EEE"
| getter="quux" type="another_enum_e">ANOTHER_ENUM_3</key>
From the above declarations, SystemInfoGenerator generates enum declarations
in header file. (Header file can be specified with option --ouptut-header)
| typedef enum {
| SOME_ENUM_0 = 0,
| SOME_ENUM_1 = 1,
| SOME_ENUM_2 = 2,
| SOME_ENUM_3 = 3,
| SOME_ENUM_4 = 4,
| } some_enum_e;
|
| typedef enum {
| ANOTHER_ENUM_0 = 100,
| ANOTHER_ENUM_1 = 101,
| ANOTHER_ENUM_2 = 102,
| ANOTHER_ENUM_3 = 103,
| ANOTHER_ENUM_4 = 104,
| } another_enum_e;
And getter will be generated in the same way how those normal types
have been.
| int system_info_get_qux(some_enum_e *value);
| int system_info_get_quux(another_enum_e *value);
Calling those getters fetch the feature value.
| #include <system_info_generated.h>
|
| some_enum_e some;
| another_enum_e another;
|
| system_info_get_qux(&some); // some = SOME_ENUM_0, 0
| system_info_get_quux(&another); // another = ANOTHER_ENUM_3, 103
SystemInfoGenerator component:
├── __init__.py
├── __main__.py
│ : See 'python -m SystemInfoGenerator --help'.
├── ModelConfigParser.py
│ : Parser for deserializing model-config.xml. It takes list of
│ model-config.xml, deserializes and returns list of TizenFeature
│ and TizenFeatureEnum.
├── SystemInfoBoilerplate.py
│ : Boilerplate generator.
├── SystemInfoCommon.py
│ : Common code for SystemInfoGenerator package.
├── SystemInfoGenerator.py
│ : Generator for source and header of system-info-generated API.
├── SystemInfoUtilityGenerator.py
│ : Generator for utility source and header of system-info-generated API.
│ Currently, it only contains convertor that converts enumerator
│ name into corresponding integer.
└── TizenFeature.py
: There are two classes, TizenFeature and TizenFeatureEnum. The
TizenFeature represents <key> element of model-config.xml, and
TizenFeatureEnum represents <enum> element.
Change-Id: I4027ac73c6258976bbad413acf359d3727c882f8
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>