The EDB Json API consists of two query functions, that are defined in the C header file edbjson.h (use #include "edbquery.h" to include the header file into your C application).
enum EdbPrintJsonFlags { EdbPrintJsonFUTF8 = 0x01, EdbPrintJsonFFlat = 0x02 }; EdbBool EdbPrintJsonObj( FILE*, Edb*, unsigned flags, EdbObject*); EdbBool EdbPrintJsonList( FILE*, Edb*, unsigned flags, unsigned otypes); EdbBool EdbPrintJsonOList(FILE*, Edb*, unsigned flags, EdbObjectList*, unsigned otypes); EdbBool EdbPrintJsonListByName(FILE*,Edb*,unsigned flags,const char*,unsigned otypes); EdbBool EdbPrintJson150(FILE*, Edb*, unsigned flags, int argc, const char* argv[]);
All functions accept an FILE pointer to an open writable file (e.g. from fopen) and a pointer to the Edb data-base and "flags", that can be 0 or an or-combination of EdbPrintJsonFUTF8 and EdbPrintJsonFFlat. The EdbPrintJsonObj gets a pointer to the EdbObject to be printed. The EdbPrintJsonList gets an "otypes" bit-vector defining the object types to be printed. The EdbPrintJsonOList gets a list of pointers to EdbObjects to be printed (plus an optional "otypes" bit-vector for additional filtering). All three functions support these flags:
Print the given EdbObject as a Json object with key-value pairs. Here is an output example for an EdbConnector (with the EdbPrintJsonFFlat flag):
{ "otype": "connector", "id": 8, "name": "P10", "partner": 11, "parent": 7, "cavities": [9,10] }
Here is an output example for the same EdbConnector (but without the EdbPrintJsonFFlat flag, so you can see the contained Cavities are also printed in-place):
{ "otype": "connector", "id": 8, "name": "P10", "partner": 11, "parent": 7, "cavities": [{ "otype": "cavity", "id": 9, "name": "4", "partner": 12, "parent": 8, "joined": [17] }, { "otype": "cavity", "id": 10, "name": "5", "parent": 8 }] }
A Json object (that turns into a JavaScript object when it is parsed) is basically a set of key-value pairs. Each Edb Object is printed as a Json object. There is a set of fields common to all Edb Objects:
Key | Type | optional? | Description |
---|---|---|---|
otype | string | no | defines the object type, one of "component", "connector", "cavity", "wire", "multicore" or "module". |
id | number | no | identifies this object; this number is unique within the data-base (given by Edb*). This id can be used to refer to other objects (e.g. to print them too). |
name | string | yes | defines the object name, it may not be unique within the object's parent. |
attrs | object | yes | defines a nested Json object that stores
another set of key-value pairs describing the
attributes at the object.
Ordinary attributes appear as string-key and string-value,
but attributes with multiple values appear as
string-key and list-of-strings-value. The example shows the ordinary
attributes power and descr and the
multi-value attribute notes with three values:
"attrs": { "power": "5V", "notes": ["A", "B", "C"], "descr": "Master Power", } |
A Component object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | string | yes | defines the Component type, one of "ecu", "inliner", "splice", "eyelet", "hier", "hbox", or "svg". |
connectors | list | yes | defines the Connectors contained in this Component; either as a list of id numbers (if the EdbPrintJsonFFlat flag is set) or as a list of nested Connector objects. |
A Connector object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | array of strings | yes | defines the Connector type, one of "male", "female" or "invisible". Additionally, at inliner components, "anti"; can appear. |
partner | number | yes | defines the id of the inliner-partner Connector; if this Connector has no partner, then this field is missing. |
parent | number | no | defines the id of the parent Component. |
cavities | list | yes | defines the Cavities contained in this Connector; either as a list of id numbers (if the EdbPrintJsonFFlat flag is set) or as a list of nested Cavity objects. |
A Cavity object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | array of strings | yes | defines the Cavity type, at most one of "halfdot" or "spliced" plus either "in" or "out" or both. |
partner | number | yes | defines the id of the inliner-partner Cavity; if this Cavity has no partner, then this field is missing. |
parent | number | no | defines the id of the parent Connector. |
joined | list | yes | defines the connected Wires as a list of id numbers. |
A Wire object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | string | yes | defines the Wire type, one of "ground", "power", "logical" or "bus". |
group | number | yes | defines the id of the surrounding Multicore; if this Wire is not a member in any Multicore, then this field is missing. |
joined | list | yes | defines the connected Cavities as a list of id numbers. |
A Multicore object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | string | yes | defines the Cavity type, one of "twisted", "shielded" or "twshielded". |
shield | number | yes | defines the id of the shield wire; if this Multicore has no shield wire, then this field is missing. |
parent | number | yes | defines the id of the parent Multicore; if this Multicore is a root Multicore and not a sub-node in a Multicore-tree, then this field is missing. |
members | list | yes | defines the member Wires as a list of id numbers. |
children | list | yes | defines the sub-nodes (nested Multicores) that form a Multicore-tree; either as a list of id numbers (if the EdbPrintJsonFFlat flag is set) or as a list of nested Multicore objects. |
A Module object provides these additional fields:
Key | Type | optional? | Description |
---|---|---|---|
type | string | yes | defines the Module type, one of "function", "signal", "config", "harness" or "always". |
options | array of strings | yes | denotes the list of module options, currently only "autocomplete" |
members | list | yes | defines the member Objects as a list of id numbers; any Edb object can be a member of a Module. |
Print a Json list with all Edb Objects that matches the object type(s) as given by the "otypes" bit-vector argument. If "otypes" is 0, then print all Edb Objects, that means print the full Edb data-base. If e.g. the bit (1<<OTWire) is set in otypes, then print all Edb Wire objects. If e.g. the bits (1<<OTWire) and (1<<OTComponent) are set in otypes, then print all Edb Components and all Edb Wires.
The flag EdbPrintJsonFFlat defines if the containment is printed in-place or not, as described above. If EdbPrintJsonFFlat is not set, then the containment is printed as Components contain Connectors and Connectors contain Cavities with these consequences: if Components are not marked in otypes, then neither Connectors nor Cavities can be printed (regardless if they are marked in otypes or not); if Connectors are not marked in otypes, then Cavities can not be printed (regardless if they are marked in otypes or not).
The list of Json objects are printed according to the description above.
Print a Json list with all Edb Objects that are given in the list argument (if the "otypes" bit-vector argument is non-zero, then non-matching objects are skipped). The flag EdbPrintJsonFFlat defines if the containment is printed in-place or not, as described above. The list of Json objects are printed according to the description above.
Similar to EdbPrintJsonList above, print a Json list with all Edb Objects that matches the object type(s) as given by the "otypes" bit-vector argument. and matches the given name.
Print a Json list with the strings, as given by argv - followed by those config-module that don't have an expr attribute. There is only one caller for this PrintJson150() that will pass the expr attribute's Boolean variables through the argv argument.
set edb [edb new]
We assume $edb “points” to a loaded database.
$edb json flags -obj $obj fname $edb json flags -id $id fname $edb json flags fname $edb json flags otypes fname $edb json flags -name $name fname $edb json flags -name $name otypes fname
These Tcl commands will print Json format into the file given as file-name fname by calling EdbPrintJsonObj(), EdbPrintJsonList() or EdbPrintJsonListByName().
The first and second commands will call EdbPrintJsonObj(). The third command will call EdbPrintJsonList() with otypes = 0 (print all). The forth command will call EdbPrintJsonList() with otypes set from an or-combinations of bits corresponding to the otypes options. The fifth and sixth commands will call EdbPrintJsonListByName().
Here is a list of the supported flags and otypes:
flags | map to flags argument in C function |
---|---|
-utf8 | EdbPrintJsonFUTF8 |
-flat | EdbPrintJsonFFlat |
otypes | map to otypes argument in C function |
-component | (1<<OTComponent) |
-connector | (1<<OTConnector) |
-cavity | (1<<OTCavity) |
-wire | (1<<OTWire) |
-multicore | (1<<OTMulticore) |
-module | (1<<OTModule) |
$edb json flags -olist $list fname $edb json flags -olist $list otypes fname
These Tcl commands will print Json format into the file given as file-name fname by calling EdbPrintJsonOList() with $list expected to be a Tcl list of data-base objects. In this mode, the otypes is usually empty (but can be set to filter certain objects by types).
$edb json flags -j150 $arg1 $arg2 ... fname
This Tcl command will call EdbPrintJson150().