ocarina.py 3.85 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
################################################################################
def set_real_theorem (theorem_name):
    '''Set main REAL theorem

    :param theorem_name: name of the theorem
    :type theorem_name: string

    '''

    return runOcarinaFunction (libocarina_python.set_real_theorem, theorem_name)

################################################################################
def add_real_library (libraryname):
    '''

91
    :param libraryname: name of the REAL library file to include
92
93
94
95
96
97
    :type libraryname: string

    '''

    return runOcarinaFunction (libocarina_python.add_real_library, libraryname)

yoogx's avatar
yoogx committed
98
################################################################################
99
Backends = Enum ([ "polyorb_hi_ada", "polyorb_hi_c", "real_theorem"])
yoogx's avatar
yoogx committed
100
101
'''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
102

yoogx's avatar
yoogx committed
103
def generate (generator):
yoogx's avatar
yoogx committed
104
    '''Generate code
yoogx's avatar
yoogx committed
105

yoogx's avatar
yoogx committed
106
107
108
    :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
109

arnaud's avatar
arnaud committed
110
    >>> generate (Backends.polyorb_hi_ada)
yoogx's avatar
yoogx committed
111
    '''
112
113

    return runOcarinaFunction (libocarina_python.generate, Backends[generator])
yoogx's avatar
yoogx committed
114
115
116

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

117
def getPropertyValue (nodeId,propertyId):
118
119
    '''Get the value of the property
    '''
120
121
122
123
124
125
126
127
    return runOcarinaFunction (libocarina_python.getPropertyValue, nodeId,propertyId)

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

def getPropertyValueByName (nodeId,propertyString):
    '''Get the value of the property
    '''
    return runOcarinaFunction (libocarina_python.getPropertyValueByName, nodeId, propertyString)