ocarina.py 21.9 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

    '''
arnaud's avatar
arnaud committed
57
58
59
60
61
62
63
64
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            libocarina_python.load (filename)
        except:
65
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
66
67
68
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
69
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
70
        raisedError ]
yoogx's avatar
yoogx committed
71
72
73
74

################################################################################
def analyze ():
    '''Analyze models'''
arnaud's avatar
arnaud committed
75
76
77
78
79
80
81
82
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.analyze ()
        except:
83
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
84
85
86
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
87
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
88
        raisedError ]
yoogx's avatar
yoogx committed
89
90
91

################################################################################
def instantiate (root_system):
92
93
94
95
96
97
    '''Instantiate model, starting from root_system

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

    '''
98

arnaud's avatar
arnaud committed
99
100
101
102
103
104
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
105
            res = libocarina_python.instantiate (root_system)
arnaud's avatar
arnaud committed
106
        except:
107
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
108
109
110
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
111
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
112
        raisedError ]
yoogx's avatar
yoogx committed
113
114

################################################################################
arnaud's avatar
arnaud committed
115
Backends = Enum ([ "polyorb_hi_ada", "polyorb_hi_c"])
yoogx's avatar
yoogx committed
116
117
'''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
118

yoogx's avatar
yoogx committed
119
def generate (generator):
yoogx's avatar
yoogx committed
120
    '''Generate code
yoogx's avatar
yoogx committed
121

yoogx's avatar
yoogx committed
122
123
124
    :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
125

arnaud's avatar
arnaud committed
126
    >>> generate (Backends.polyorb_hi_ada)
yoogx's avatar
yoogx committed
127
    '''
arnaud's avatar
arnaud committed
128
129
130
131
132
133
134
135
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            libocarina_python.generate (Backends[generator])
        except:
136
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
137
138
139
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
140
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
141
        raisedError ]
yoogx's avatar
yoogx committed
142
143
144

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

145
146
147
def getPackages ():
    '''Return the list of all the packages defined in the current AADL project
    '''
arnaud's avatar
arnaud committed
148
149
150
151
152
153
154
155
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPackages()
        except:
156
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
157
158
159
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
160
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
161
        raisedError ]
162
163
164
165

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

def getImportDeclarations ():
166
    '''Return the list of all the import declaration used in the
arnaud's avatar
arnaud committed
167
    current AADL project
168
    '''
arnaud's avatar
arnaud committed
169
170
171
172
173
174
175
176
177
178
179
180
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getImportDeclarations()
        except:
            raisedError.append(getErrorMessage())
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
181
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
182
        raisedError ]
183
184
185
186

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

def getAliasDeclarations ():
187
    '''Return the list of all the alias declaration defined in the
arnaud's avatar
arnaud committed
188
    current AADL project
189
    '''
arnaud's avatar
arnaud committed
190
191
192
193
194
195
196
197
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getAliasDeclarations ()
        except:
198
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
199
200
201
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
202
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
203
        raisedError ]
204
205
206
207
208
209
210
211
212
213
214

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

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
215
    >>> getComponentTypes (System)
216
    '''
arnaud's avatar
arnaud committed
217
218
219
220
221
222
223
224
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentTypes (category)
        except:
225
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
226
227
228
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
229
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
230
        raisedError ]
231
232
233
234

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

def getComponentImplementations (category):
235
    '''Return a list of component implementations defined in the
arnaud's avatar
arnaud committed
236
    current AADL project
237
238
239

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

240
    For instance, to retrieve all the system implementations from the
arnaud's avatar
arnaud committed
241
    current project, you may use the following
242

arnaud's avatar
arnaud committed
243
    >>> getComponentImplementations (System)
244
    '''
arnaud's avatar
arnaud committed
245
246
247
248
249
250
251
252
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentImplementations (category)
        except:
253
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
254
255
256
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
257
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
258
        raisedError ]
259
260
261
262
263
264

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

def getAnnexes ():
    '''Return the list of all the annexes defined in the current AADL project
    '''
arnaud's avatar
arnaud committed
265
266
267
268
269
270
271
272
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getAnnexes ()
        except:
273
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
274
275
276
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
277
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
278
        raisedError ]
279
280
281
282
283
284

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

def getPrototypes ():
    '''Return the list of all the prototypes defined in the current AADL project
    '''
arnaud's avatar
arnaud committed
285
286
287
288
289
290
291
292
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPrototypes ()
        except:
293
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
294
295
296
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
297
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
298
        raisedError ]
299
300
301
302

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

def getPrototypeBindings ():
303
    '''Return the list of all the prototype bindings defined in the
arnaud's avatar
arnaud committed
304
    current AADL project
305
    '''
arnaud's avatar
arnaud committed
306
307
308
309
310
311
312
313
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPrototypeBindings ()
        except:
314
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
315
316
317
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
318
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
319
        raisedError ]
320
321
322
323

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

def getFlowSpecifications ():
324
    '''Return the list of all the flow specification defined in the
arnaud's avatar
arnaud committed
325
    current AADL project
326
    '''
arnaud's avatar
arnaud committed
327
328
329
330
331
332
333
334
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getFlowSpecifications ()
        except:
335
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
336
337
338
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
339
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
340
        raisedError ]
341
342
343
344

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

def getFlowImplementations ():
345
    '''Return the list of all the flow implementation defined in the
arnaud's avatar
arnaud committed
346
    current AADL project
347
    '''
arnaud's avatar
arnaud committed
348
349
350
351
352
353
354
355
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getFlowImplementations ()
        except:
356
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
357
358
359
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
360
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
361
        raisedError ]
362
363
364
365
366
367

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

def getModes ():
    '''Return the list of all the modes defined in the current AADL project
    '''
arnaud's avatar
arnaud committed
368
369
370
371
372
373
374
375
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getModes ()
        except:
376
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
377
378
379
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
380
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
381
        raisedError ]
382
383
384
385

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

def getModeTransitions ():
386
    '''Return the list of all the mode transition defined in the
arnaud's avatar
arnaud committed
387
    current AADL project
388
    '''
arnaud's avatar
arnaud committed
389
390
391
392
393
394
395
396
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getModeTransitions ()
        except:
397
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
398
399
400
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
401
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
402
        raisedError ]
403
404
405
406
407
408

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

def getInModes ():
    '''Return the list of all the in mode used in the current AADL project
    '''
arnaud's avatar
arnaud committed
409
410
411
412
413
414
415
416
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInModes ()
        except:
417
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
418
419
420
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
421
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
422
        raisedError ]
423
424
425
426

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

def getPropertySets ():
427
    '''Return the list of all the property set defined in the
arnaud's avatar
arnaud committed
428
    current AADL project
429
    '''
arnaud's avatar
arnaud committed
430
431
432
433
434
435
436
437
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertySets ()
        except:
438
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
439
440
441
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
442
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
443
        raisedError ]
444
445
446
447

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

def getPropertyTypes (propertySetId):
448
    '''Return the list of all the property types defined in the
arnaud's avatar
arnaud committed
449
    provided property set
450

451
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
452
    current AADL project to serach in
453

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

arnaud's avatar
arnaud committed
457
    >>> getPropertyTypes (propertySetId)
458
    '''
arnaud's avatar
arnaud committed
459
460
461
462
463
464
465
466
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyTypes (propertySetId)
        except:
467
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
468
469
470
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
471
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
472
        raisedError ]
473
474
475
476

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

def getPropertyDefinitions (propertySetId):
477
    '''Return the list of all the property declaration defined in the
arnaud's avatar
arnaud committed
478
    provided property set
479

480
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
481
    current AADL project to serach in
482

483
484
    For instance, to retrieve all the property declaration from
    property set propertySet, retrieve its id (propertySetId)
arnaud's avatar
arnaud committed
485
    and use the following
486

arnaud's avatar
arnaud committed
487
    >>> getPropertyDefinitions (propertySetId)
488
    '''
arnaud's avatar
arnaud committed
489
490
491
492
493
494
495
496
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyDefinitions (propertySetId)
        except:
497
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
498
499
500
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
501
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
502
        raisedError ]
503
504
505
506

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

def getPropertyConstants (propertySetId):
507
    '''Return the list of all the constant property defined in the
arnaud's avatar
arnaud committed
508
    provided property set
509

510
    :param propertySetId: the nodeId of the property set in the
arnaud's avatar
arnaud committed
511
    current AADL project to serach in
512

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

arnaud's avatar
arnaud committed
516
    >>> getPropertyConstants (propertySetId)
517
    '''
arnaud's avatar
arnaud committed
518
519
520
521
522
523
524
525
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyConstants (propertySetId)
        except:
526
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
527
528
529
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
530
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
531
        raisedError ]
532
533
534
535
536
537
538
539
540
541
542

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

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
543
    >>> getInstances (System)
544
    '''
arnaud's avatar
arnaud committed
545
546
547
548
549
550
551
552
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInstances (category)
        except:
553
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
554
555
556
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
557
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
558
        raisedError ]
559
560
561
562
563
564
565
566

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

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

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

567
    For instance, to retrieve the name of MyComponent,
568
569
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
570
    >>> getComponentName (nodeId)
571
    '''
arnaud's avatar
arnaud committed
572
573
574
575
576
577
578
579
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentName (nodeId)
        except:
580
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
581
582
583
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
584
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
585
        raisedError ]
586
587
588
589
590
591

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

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

592
    :param nodeId: the id of the component whose
593
594
    full qualified name is searched

595
    For instance, to retrieve the full qualified name of MyComponent,
596
597
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
598
    >>> getComponentFullname (nodeId)
599
    '''
arnaud's avatar
arnaud committed
600
601
602
603
604
605
606
607
608
609
610
611
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentFullname (nodeId)
        except:
            raisedError.append(getErrorMessage())
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
612
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
613
        raisedError ]
614
615
616
617
618
619
620
621

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

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

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

622
    For instance, to retrieve the name of MyInstance,
623
624
    retrieve its id (nodeId) and use the following

arnaud's avatar
arnaud committed
625
    >>> getInstanceName (nodeId)
626
    '''
arnaud's avatar
arnaud committed
627
628
629
630
631
632
633
634
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInstanceName (nodeId)
        except:
635
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
636
637
638
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
639
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
640
        raisedError ]
641
642
643
644
645
646
647
648
649
650

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

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
651
652
653
654
655
656
657
658
659
660
    >>> getNodeId (MyHome)
    '''
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getNodeId (name)
        except:
661
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
662
663
664
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
665
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
        raisedError ]

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

def getRoot ():
    '''Get the Id of the current root instantiated model
    '''
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getRoot ()
        except:
681
            raisedError.append(getErrorMessage())
arnaud's avatar
arnaud committed
682
683
684
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
685
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
arnaud's avatar
arnaud committed
686
        raisedError ]