ocarina.py 22 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
65
66
67
68
69
70
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            libocarina_python.load (filename)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
83
84
85
86
87
88
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.analyze ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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

    '''
arnaud's avatar
arnaud committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            libocarina_python.instantiate (root_system)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
136
137
138
139
140
141
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            libocarina_python.generate (Backends[generator])
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
156
157
158
159
160
161
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPackages()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
162
163
164
165

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

def getImportDeclarations ():
arnaud's avatar
arnaud committed
166
167
    '''Return the list of all the import declaration used in the 
    current AADL project
168
    '''
arnaud's avatar
arnaud committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    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])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
183
184
185
186

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

def getAliasDeclarations ():
arnaud's avatar
arnaud committed
187
188
    '''Return the list of all the alias declaration defined in the 
    current AADL project
189
    '''
arnaud's avatar
arnaud committed
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getAliasDeclarations ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
225
226
227
228
229
230
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentTypes (category)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
231
232
233
234

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

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

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

arnaud's avatar
arnaud committed
240
241
    For instance, to retrieve all the system implementations from the 
    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
253
254
255
256
257
258
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentImplementations (category)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
273
274
275
276
277
278
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getAnnexes ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
293
294
295
296
297
298
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPrototypes ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
299
300
301
302

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

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

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

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

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

def getFlowImplementations ():
arnaud's avatar
arnaud committed
345
346
    '''Return the list of all the flow implementation defined in the 
    current AADL project
347
    '''
arnaud's avatar
arnaud committed
348
349
350
351
352
353
354
355
356
357
358
359
360
361
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getFlowImplementations ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
376
377
378
379
380
381
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getModes ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
382
383
384
385

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

def getModeTransitions ():
arnaud's avatar
arnaud committed
386
387
    '''Return the list of all the mode transition defined in the 
    current AADL project
388
    '''
arnaud's avatar
arnaud committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getModeTransitions ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
417
418
419
420
421
422
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInModes ()
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
423
424
425
426

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

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

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

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

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

arnaud's avatar
arnaud committed
454
455
    For instance, to retrieve all the property types from property 
    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
467
468
469
470
471
472
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyTypes (propertySetId)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
473
474
475
476

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

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

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

arnaud's avatar
arnaud committed
483
484
485
    For instance, to retrieve all the property declaration from 
    property set propertySet, retrieve its id (propertySetId) 
    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
497
498
499
500
501
502
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyDefinitions (propertySetId)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]
503
504
505
506

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

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

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

arnaud's avatar
arnaud committed
513
514
    For instance, to retrieve all the constant property from property 
    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
526
527
528
529
530
531
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getPropertyConstants (propertySetId)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
553
554
555
556
557
558
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInstances (category)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
580
581
582
583
584
585
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getComponentName (nodeId)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
612
613
    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])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
635
636
637
638
639
640
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getInstanceName (nodeId)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
    >>> getNodeId (MyHome)
    '''
    info = io.BytesIO()
    error = io.BytesIO()
    raisedError = []
    res = ''
    with std_redirector(info,error):
        try:
            res = libocarina_python.getNodeId (name)
        except:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        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:
            raisedError.append(getErrorMessage()) 
    stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
    if stderrMsg[1]!=[]:
        raisedError.append(stderrMsg[1])
    return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] , 
        raisedError ]