ocarina.py 11 KB
Newer Older
yoogx's avatar
yoogx committed
1
#! /usr/bin/python
2
3
4
5
'''
:mod:`ocarina` -- Python binding to the Ocarina AADL processor
==============================================================

6
.. moduleauthor:: Jerome Hugues, Arnaud Schach
7
8
9
10
11

This module provides direct access to top-level functions of Ocarina
to load, parse, instantiate AADL models, and to invoke backends.

'''
yoogx's avatar
yoogx committed
12
13

################################################################################
14
15

try:
arnaud's avatar
arnaud committed
16
17
18
    import libocarina_python # Ocarina bindings
    import ocarina_me_aadl_aadl_instances_nodes as AIN
    import ocarina_me_aadl_aadl_tree_nodes as ATN
19
    from ocarina_common_tools import *
arnaud's avatar
arnaud committed
20
    import io
21
22
except ImportError:
    pass
yoogx's avatar
yoogx committed
23

yoogx's avatar
yoogx committed
24
25
class Enum(tuple): __getattr__ = tuple.index

yoogx's avatar
yoogx committed
26
27
28
################################################################################
def version ():
    '''Print Ocarina version'''
arnaud's avatar
arnaud committed
29
    libocarina_python.version()
yoogx's avatar
yoogx committed
30
31
32
33

################################################################################
def status ():
    '''Print Ocarina status'''
arnaud's avatar
arnaud committed
34
    libocarina_python.status()
yoogx's avatar
yoogx committed
35

36
37
################################################################################
def reset ():
yoogx's avatar
yoogx committed
38
39
    '''Reset Ocarina internal state

40
41
    **Note:** this function must be called before processing a new set of
    models.'''
yoogx's avatar
yoogx committed
42

arnaud's avatar
arnaud committed
43
    libocarina_python.reset()
44

yoogx's avatar
yoogx committed
45
46
################################################################################
def load (filename):
yoogx's avatar
yoogx committed
47
48
    '''Load a file

49
    :param filename: name of the file to be loaded, using Ocarina search path
yoogx's avatar
yoogx committed
50
51
52
53
    :type filename: string

    E.g. to load "foo.aadl":

arnaud's avatar
arnaud committed
54
    >>> load("foo.aadl")
yoogx's avatar
yoogx committed
55
56

    '''
57
    return runOcarinaFunction (libocarina_python.load, filename)
yoogx's avatar
yoogx committed
58
59
60
61

################################################################################
def analyze ():
    '''Analyze models'''
62
63

    return runOcarinaFunction (libocarina_python.analyze)
yoogx's avatar
yoogx committed
64
65
66

################################################################################
def instantiate (root_system):
67
68
69
70
71
72
    '''Instantiate model, starting from root_system

    :param root_system: name of the root system to instantiate
    :type root_system: string

    '''
73

74
    return runOcarinaFunction (libocarina_python.instantiate, root_system)
yoogx's avatar
yoogx committed
75
76

################################################################################
arnaud's avatar
arnaud committed
77
Backends = Enum ([ "polyorb_hi_ada", "polyorb_hi_c"])
yoogx's avatar
yoogx committed
78
79
'''List of supported backends, used by :data:`generate`'''
# Note, this list should match backend names as specified by Ocarina CLI
yoogx's avatar
yoogx committed
80

yoogx's avatar
yoogx committed
81
def generate (generator):
yoogx's avatar
yoogx committed
82
    '''Generate code
yoogx's avatar
yoogx committed
83

yoogx's avatar
yoogx committed
84
85
86
    :param generator: one supported backends, from :data:`Backends`

    For instance, to use the PolyORB-HI/Ada backend, you may use the following
yoogx's avatar
yoogx committed
87

arnaud's avatar
arnaud committed
88
    >>> generate (Backends.polyorb_hi_ada)
yoogx's avatar
yoogx committed
89
    '''
90
91

    return runOcarinaFunction (libocarina_python.generate, Backends[generator])
yoogx's avatar
yoogx committed
92
93
94

################################################################################

95
96
97
def getPackages ():
    '''Return the list of all the packages defined in the current AADL project
    '''
98
99

    return runOcarinaFunction (libocarina_python.getPackages)
100
101
102
103

################################################################################

def getImportDeclarations ():
104
    '''Return the list of all the import declarations used in the
arnaud's avatar
arnaud committed
105
    current AADL project
106
    '''
107
108

    return runOcarinaFunction (libocarina_python.getImportDeclarations)
109
110
111
112

################################################################################

def getAliasDeclarations ():
113
    '''Return the list of all the alias declaration defined in the
arnaud's avatar
arnaud committed
114
    current AADL project
115
    '''
116
117

    return runOcarinaFunction (libocarina_python.getAliasDeclarations)
118
119
120
121
122
123
124
125
126
127
128

################################################################################

def getComponentTypes (category):
    '''Return a list of component types defined in the current AADL project

    :param category: one of the AADL category defined in the standard

    For instance, to retrieve all the system types from the current project,
    you may use the following

arnaud's avatar
arnaud committed
129
    >>> getComponentTypes (System)
130
    '''
131
132

    return runOcarinaFunction (libocarina_python.getComponentTypes, category)
133
134
135
136

################################################################################

def getComponentImplementations (category):
137
    '''Return a list of component implementations defined in the
arnaud's avatar
arnaud committed
138
    current AADL project
139
140
141

    :param category: one of the AADL category defined in the standard

142
    For instance, to retrieve all the system implementations from the
arnaud's avatar
arnaud committed
143
    current project, you may use the following
144

arnaud's avatar
arnaud committed
145
    >>> getComponentImplementations (System)
146
    '''
147
    return runOcarinaFunction (libocarina_python.getComponentImplementations, category)
148
149
150
151
152
153

################################################################################

def getAnnexes ():
    '''Return the list of all the annexes defined in the current AADL project
    '''
154
155

    return runOcarinaFunction (libocarina_python.getAnnexes)
156
157
158
159
160
161

################################################################################

def getPrototypes ():
    '''Return the list of all the prototypes defined in the current AADL project
    '''
162
163

    return runOcarinaFunction (libocarina_python.getPrototypes)
164
165
166
167

################################################################################

def getPrototypeBindings ():
168
    '''Return the list of all the prototype bindings defined in the
arnaud's avatar
arnaud committed
169
    current AADL project
170
    '''
171
172

    return runOcarinaFunction (libocarina_python.getPrototypeBindings)
173
174
175
176

################################################################################

def getFlowSpecifications ():
177
    '''Return the list of all the flow specification defined in the
arnaud's avatar
arnaud committed
178
    current AADL project
179
    '''
180
181

    return runOcarinaFunction (libocarina_python.getFlowSpecifications)
182
183
184
185

################################################################################

def getFlowImplementations ():
186
    '''Return the list of all the flow implementation defined in the
arnaud's avatar
arnaud committed
187
    current AADL project
188
    '''
189
190

    return runOcarinaFunction (libocarina_python.getFlowImplementations)
191
192
193
194
195
196

################################################################################

def getModes ():
    '''Return the list of all the modes defined in the current AADL project
    '''
197
198

    return runOcarinaFunction (libocarina_python.getModes)
199
200
201
202

################################################################################

def getModeTransitions ():
203
    '''Return the list of all the mode transition defined in the
arnaud's avatar
arnaud committed
204
    current AADL project
205
    '''
206
207

    return runOcarinaFunction (libocarina_python.getModeTransitions)
208
209
210
211
212
213

################################################################################

def getInModes ():
    '''Return the list of all the in mode used in the current AADL project
    '''
214

215
216
217
218

################################################################################

def getPropertySets ():
219
    '''Return the list of all the property set defined in the
arnaud's avatar
arnaud committed
220
    current AADL project
221
    '''
222
223

    return runOcarinaFunction (libocarina_python.getPropertySets)
224
225
226
227

################################################################################

def getPropertyTypes (propertySetId):
228
    '''Return the list of all the property types defined in the
arnaud's avatar
arnaud committed
229
    provided property set
230

231
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
232
    current AADL project to serach in
233

234
    For instance, to retrieve all the property types from property
arnaud's avatar
arnaud committed
235
    set propertySet, retrieve its id (propertySetId) and use the following
236

arnaud's avatar
arnaud committed
237
    >>> getPropertyTypes (propertySetId)
238
    '''
239
240

    return runOcarinaFunction (libocarina_python.getPropertyTypes, propertySetId)
241
242
243
244

################################################################################

def getPropertyDefinitions (propertySetId):
245
    '''Return the list of all the property declaration defined in the
arnaud's avatar
arnaud committed
246
    provided property set
247

248
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
249
    current AADL project to serach in
250

251
252
    For instance, to retrieve all the property declaration from
    property set propertySet, retrieve its id (propertySetId)
arnaud's avatar
arnaud committed
253
    and use the following
254

arnaud's avatar
arnaud committed
255
    >>> getPropertyDefinitions (propertySetId)
256
    '''
257
258

    return runOcarinaFunction (libocarina_python.getPropertyDefinitions, propertySetId)
259
260
261
262

################################################################################

def getPropertyConstants (propertySetId):
263
    '''Return the list of all the constant property defined in the
arnaud's avatar
arnaud committed
264
    provided property set
265

266
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
267
    current AADL project to serach in
268

269
    For instance, to retrieve all the constant property from property
arnaud's avatar
arnaud committed
270
    set propertySet, retrieve its id (propertySetId) and use the following
271

arnaud's avatar
arnaud committed
272
    >>> getPropertyConstants (propertySetId)
273
    '''
274
275

    return runOcarinaFunction (libocarina_python.getPropertyConstants,propertySetId)
276
277
278
279
280
281
282
283
284
285
286

################################################################################

def getInstances (category):
    '''Return a list of instances defined in the current AADL project

    :param category: one of the AADL category defined in the standard

    For instance, to retrieve all the system instances from the current project,
    you may use the following

arnaud's avatar
arnaud committed
287
    >>> getInstances (System)
288
    '''
289
290

    return runOcarinaFunction (libocarina_python.getInstances, category)
291
292
293
294
295
296
297
298

################################################################################

def getComponentName (nodeId):
    '''Get the name of an AADL component

    :param nodeId: the id of the component whose name is searched

299
    For instance, to retrieve the name of MyComponent,
300
301
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
302
    >>> getComponentName (nodeId)
303
    '''
304
305

    return runOcarinaFunction (libocarina_python.getComponentName, nodeId)
306
307
308
309
310
311

################################################################################

def getComponentFullname (nodeId):
    '''Get the full qualified name of an AADL component

312
    :param nodeId: the id of the component whose
313
314
    full qualified name is searched

315
    For instance, to retrieve the full qualified name of MyComponent,
316
317
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
318
    >>> getComponentFullname (nodeId)
319
    '''
320
321

    return runOcarinaFunction (libocarina_python.getComponentFullname, nodeId)
322
323
324
325
326
327
328
329

################################################################################

def getInstanceName (nodeId):
    '''Get the name of an AADL instance

    :param nodeId: the id of the instance whose name is searched

330
    For instance, to retrieve the name of MyInstance,
331
332
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
333
    >>> getInstanceName (nodeId)
334
    '''
335
336

    return runOcarinaFunction (libocarina_python.getInstanceName, nodeId)
337
338
339
340
341
342
343
344
345
346

################################################################################

def getNodeId (name):
    '''Get the Id of a component from its name

    :param name: the AADL name of the node whose id is queried

    For instance, to retrieve the id of MyHome, you may use the following

arnaud's avatar
arnaud committed
347
348
    >>> getNodeId (MyHome)
    '''
349
350

    return runOcarinaFunction (libocarina_python.getNodeId, name)
arnaud's avatar
arnaud committed
351
352
353
354
355
356

################################################################################

def getRoot ():
    '''Get the Id of the current root instantiated model
    '''
357
358

    return runOcarinaFunction (libocarina_python.getRoot)