root/ossiedev/trunk/tools/WaveDev/wavedev/importIDL.py @ 6760

Revision 5933, 5.5 KB (checked in by jgaeddert, 5 years ago)

specifying exception handle for import error

  • Property svn:eol-style set to native
Line 
1#! /usr/bin/env python
2
3## Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
4##
5## This file is part of the OSSIE Waveform Developer.
6##
7## OSSIE Waveform Developer is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## OSSIE Waveform Developer is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with OSSIE Waveform Developer; if not, write to the Free Software
19## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21import os, sys
22import string
23
24try:
25    from omniidl import idlast, idlvisitor, idlutil, main, idltype
26    from omniidl_be.cxx import types
27    import _omniidl
28except ImportError:
29    print "ERROR: importIDL.py cannot import the omniidl module"
30    print "  - Is omniORBpy installed?"
31    print "  - Is /usr/local/lib/pythonX.X/site-packages included in ossie.pth?"
32    sys.exit(0)
33
34import ComponentClass as CC
35
36keyList = range(34)
37valList = ['null','void','short','long','ushort','ulong','float','double','boolean', \
38           'char','octet','any','TypeCode','Principal','objref','struct','union','enum', \
39           'string','sequence','array','alias','except','longlong','ulonglong', \
40           'longdouble','wchar','wstring','fixed','value','value_box','native', \
41           'abstract_interface','local_interface']
42baseTypes = dict(zip(keyList,valList))
43
44# Non-standard kinds for forward-declared structs and unions
45baseTypes[100] = 'ot_structforward'
46baseTypes[101] = 'ot_unionforward'
47
48class ExampleVisitor (idlvisitor.AstVisitor):
49    def __init__(self,*args):
50        self.myInterfaces = []   #Used to store the interfaces that are found
51        if hasattr(idlvisitor.AstVisitor,'__init__'):
52            idlvisitor.AstVisitor.__init__(self,args)
53
54    def visitAST(self, node):
55        for n in node.declarations():
56            n.accept(self)
57
58    def visitModule(self, node):
59        for n in node.definitions():
60            n.accept(self)
61
62    def visitInterface(self, node):
63        new_int = CC.Interface(node.identifier(),node.scopedName()[0])
64       
65        ops_list = []
66        self.addOps(node,ops_list)
67        new_int.operations.extend(ops_list)
68        #print node.identifier() + " has " + str(len(new_int.operations)) + " operations"
69        self.myInterfaces.append(new_int)
70
71    def addOps(self,node,ops):
72       
73        for i in node.inherits():
74            self.addOps(i,ops)
75
76        for d in node.contents():
77            if isinstance(d, idlast.Operation):
78                new_op = CC.Operation(d.identifier(),baseTypes[d.returnType().kind()])
79                # Get the c++ mappping of the return type
80                cxxRT = types.Type(d.returnType())
81                new_op.cxxReturnType = cxxRT.base()
82#                if new_op.returnType == 'string':
83#                    print foo2.base()
84                #print new_op.name + "::" + d.identifier() + "()"
85                #tmpstr = node.identifier() + "::" + d.identifier() + "("
86                #tmpstr2 = "  " + node.identifier() + "::" + d.identifier() + "("
87                if hasattr(d,'parameters'):
88                    for p in d.parameters():
89                        new_param = CC.Param(p.identifier())
90                        t =  p.paramType()
91                        # Get the c++ mapping of the type
92                        cxxT = types.Type(t)
93                        new_param.cxxType = cxxT.op(types.direction(p))
94                                               
95                        if hasattr(t,'scopedName'):
96                            #print ' '*8 + str(t.scopedName()),
97                            new_param.dataType = idlutil.ccolonName(t.scopedName())
98                        else:
99                            if isinstance(t,idltype.Type):
100                                #print ' '*8 + baseTypes[t.kind()],
101                                new_param.dataType = baseTypes[t.kind()]
102
103                        if p.is_in() and p.is_out():
104                            new_param.direction = 'inout'
105                        elif p.is_out():
106                            new_param.direction = 'out'
107                        else:
108                            new_param.direction = 'in'
109                        new_op.params.append(new_param)
110                        #tmpstr += new_param.direction + " " + new_param.dataType + ","
111                        #tmpstr2 += new_param.direction + " " + new_param.cxxType + ","
112                ops.append(new_op)
113                #print tmpstr[:-1] + ")"
114                #print tmpstr2[:-1] + ")"
115
116def run(tree, args):
117    visitor = ExampleVisitor()
118    tree.accept(visitor)
119    return visitor.myInterfaces
120
121def getInterfaces(filename):
122  f = os.popen(main.preprocessor_cmd + ' -I "/usr/local/include" -I "/usr/include" "' \
123               + filename + '"','r')
124  tree = _omniidl.compile(f)
125  ints = run(tree,'')
126  f.close()
127  del tree
128  idlast.clear()
129  idltype.clear()
130  _omniidl.clear()
131  #store file name and location information for each interface
132  for x in ints:
133      x.fullpath = filename
134      i = filename.rfind("/")
135      if i >= 0:
136          x.filename = filename[i+1:]
137         
138      x.filename = x.filename[:-4] #remove the .idl suffix
139   
140     
141  return ints
142 
143
144if __name__ == '__main__':
145    print "Command line not supported in this version"
Note: See TracBrowser for help on using the browser.