aboutsummaryrefslogtreecommitdiffstats
path: root/src/doc/qtivi/src/idl-syntax.qdoc
blob: c05fbec5522498cced769ff6797ef781eb3aa095 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/****************************************************************************
**
** Copyright (C) 2017 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the QtIvi module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL-QTAS$
** Commercial License Usage
** Licensees holding valid commercial Qt Automotive Suite licenses may use
** this file in accordance with the commercial license agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and The Qt Company.  For
** licensing terms and conditions see https://www.qt.io/terms-conditions.
** For further information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*
  NOTE: Some content in this file was copied from the QFace Documentation
*/
/*!
\page idl-syntax.html
\title QFace IDL syntax
\nextpage Jinja template syntax
\keyword IDL

This page explains the basic usage of the QFace IDL. A more detailed description of the library
can be found on its \l {https://pelagicore.github.io/qface/}{page}

QFace (Qt interface language) is an Interface Description Languge (IDL). While it is primarily
designed to define an interface between Qt, QML and C++, it is intended to be flexible enough also
to be used in other contexts.


\section1 The IDL

The IDL uses common API concepts such as modules, interfaces, properties, structs and enums/flags.
Additionally it knows about lists and \l {Model/View Programming}{models}.
A list is an array of primitive or complex types. A model is an indicator for large data sets
which are typical used via a defined API (e.g. pagination).

\code
module org.example 1.0

interface Echo {
    string message;
    void echo(string message);
    signal broadcast(string message);
    Status status;
}

enum Status {
    Null, Loading, Ready, Error
}
\endcode

The data types provided by QFace can be divided into primitive and complex types:

\b {Primitive Types}
\list
    \li bool
    \li int
    \li real
    \li string
    \li var
\endlist

\b {Complex Types}
\list
    \li Interface
    \li Struct
    \li Enum
    \li Flag
    \li Array
    \li Model
\endlist

The language as such does not provide any support for maps or dictionaries. The reason for not
providing a map container type is that keys in dictionaries requires a hash which can not always
be guaranteed to be available in complex types.

\section1 Grammar
The grammar of QFace is well defined and is based on the concepts of modules as a larger
collection of information.

A module can have several interfaces, structs and/or enums/flags.

\code
module <module> <version>
import <module> <version>

interface <Identifier> {
    [readonly] <type> <identifier>
    <type> <operation>(<parameter>*)
    signal <signal>(<parameter>*)
}

struct <Identifier> {
    <type> <identifier>;
}

enum <Identifier> {
    <name> = <value>,
}

flag <Identifier> {
    <name> = <value>,
}
\endcode

A QFace document always describes one module. Each document can contain one or more interfaces,
structs, flags or enums. Each document can import other modules using the import statement.

\section1 Module

A module is identified by its name. The name should normally be a URI where all parts are
lowercase (e.g. \e {entertainment.tuner}). A module may import other modules with the primary
purpose being to ensure that dependencies are declared inside the QFace file.

\code
// org.example.qface
module org.example 1.0

import org.common 1.0
\endcode

\section1 Interface

An interface is a collection of properties, operation and signals. Properties carry data, whereas
the operations normally modify the data. Signals are used to notify the user of changes.

\code
interface WeatherStation {
    real temperature;
    void reset();
    signal error(string message);
}
\endcode

\section1 Struct

The struct is supposed to serve as a container to transport structured data. It supports neither
properties nor operations.

\section1 Property

Interfaces and structures data are carried by properties: syntax elements allowing to describe
some attributes of the entity. A property can be of any type, known to IDL. It can be marked as \e
{readonly}, in which case this attribute of the interface is not supposed to be written to from
the outside code. It's up to the generator to enforce this constraint.

\section1 Enum/Flag
Enums and flags are the concepts known from many popular programming languages (C++,Java,etc).
They differ only in what values they can take: enums are allowed to take only a single value,
whereas flags can be an OR-ed combination of multiple values.

\section1 Types

Types are either local and can be referenced simply by their name, or they are from an external
module in which case they need to be referenced with the fully qualified name (module + '.' +
name). A type can be an interface, struct, enum or flag.

A module consists of either one or more interfaces, structs and enums/flags. They can come in any
number or combination. The interface is the only type which can contain operations and signals.
A struct is merely a container to transport structured data. Enum and flags allows the user to
encode information used inside the struct or interface as datatype.

The QFace library does not allow to extend interfaces. It is by design kept simple.

Below is an example of a QFace file.

\code
module entertainment.tuner 1.0;

import common 1.0

interface Tuner {
    // property currentStation
    readonly Station currentStation;
    // operation nextStation
    void nextStation();
    // operation previousStation
    void previousStation();
    // operation updateCurrentStation
    void updateCurrentStation(int stationId);

    list<int> primitiveList;
    list<Station> complexList;
    model<int> primitiveModel;
    model<Station> complexModel;
}

\endcode


\section1 Annotations
\target annotations_reference

Annotations is a way to add meta information to your interface definition. It is available to each
symbol in the interface.

Annotations allows an interface author to extend the existing interface with additional meta
information, called tags, aka annotations. One or several annotations can precede a module,
interface, struct or enum. They are also allowed before an operation, property or signal.
Everywhere where a documentation comment is allowed you can also add annotations.

An annotation looks like this:

\code
@service: {port: 12345}
interface Tuner {
}
\endcode

An in code annotation precedes a symbol and it starts with an @ sign. A symbol can have more than
one one annotation line. Each line should be one individual annotation. The content is YAML
content. All @ signs preceding a symbol are collected and then evaluated using a YAML parser.

For larger annotations one can use the external annotation document feature.

\code
@singleton: yes
@data: [1,2,3]
@config: { values: [LEFT, RIGHT, TOP] }
\endcode

This will be result into a YAML content of

\code
singleton: yes
data: [1,2,3]
config: { values: [LEFT, RIGHT, TOP] }
\endcode

And the result as Python object would be

\code
{
  "data": [ 1, 2, 3 ],
  "singleton": true,
  "config": {
    "values": [ "LEFT", "RIGHT", "TOP" ]
  }
}
\endcode

\section1 Annotation Documents

QFace allows also to specify these annotations in external documents using the YAML syntax. For
this you need to create a document with the same name as the QFace document but with the extension
.yaml. It should have roughly the following format

\code
com.pelagicore.ivi.Tuner:
    service:
      port: 12345
\endcode

On the root level should be a fully qualified name of a symbol. The symbol will be looked up and
the following annotation information merged with the existing annotations from the QFace document.

\section1 Merging Annotations

The external annotations will be merged on top of the embedded annotations on per symbol base.
Dictionaries will be merged. If a merge can not be done then the external document based
annotations will override the embedded annotations.

The annotation are available later when navigating the domain model.

\code
{% if "service" in interface.tags %}
interface {{interface}} is served on port: {{interface.tags.service.port}}
{% else %}
interface {{interface}} is not served
{% endif %}
\endcode

\note
QFace does not specify specific annotations, but defines just the annotation format. The set of
annotations supported must be defined and documented by the generator.

\section1 Domain Model

As a result of parsing the IDL document, a domain model object must be created. The domain model
resembles the structure of our system as objects. It is build by the parser and serves as the
input into the generator.

The IDL is converted into an in memory domain model (see qface/idl/domain.py)

\code
- System
    - Module
        - Import
        - Interface
              - Property
              - Operation
              - Event
        - Enum
        - Flag
        - Struct
              - Property
\endcode

The domain model is the base for the code generation. You traverse the domain tree and trigger
your own code generation.

Detailed description of QFace library API is found on the library \l
{http://qface.readthedocs.io/en/latest/api.html} {page}
*/