root/ossiedev/branches/jsnyder/trunk/tools/WaveDev/wavedev/importIDL.py @ 11065

Revision 11065, 5.7 KB (checked in by Snyder.Jason, 2 years ago)

python omniidl stuff is now in /usr/lib/omniidl, which isn't on the python path. committing a temporary fix

  • 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
23import omniORB
24sys.path.append('/usr/lib/omniidl')
25
26try:
27    from omniidl import idlast, idlvisitor, idlutil, main, idltype
28    from omniidl_be.cxx import types
29    import _omniidl
30except ImportError:
31    print "ERROR: importIDL.py cannot import the omniidl module"
32    print "  - Is omniORBpy installed?"
33    print "  - Is /usr/local/lib/pythonX.X/site-packages included in ossie.pth?"
34    sys.exit(0)
35
36import ComponentClass as CC
37
38keyList = range(34)
39valList = ['null','void','short','long','ushort','ulong','float','double','boolean', \
40           'char','octet','any','TypeCode','Principal','objref','struct','union','enum', \
41           'string','sequence','array','alias','except','longlong','ulonglong', \
42           'longdouble','wchar','wstring','fixed','value','value_box','native', \
43           'abstract_interface','local_interface']
44baseTypes = dict(zip(keyList,valList))
45
46# Non-standard kinds for forward-declared structs and unions
47baseTypes[100] = 'ot_structforward'
48baseTypes[101] = 'ot_unionforward'
49
50class ExampleVisitor (idlvisitor.AstVisitor):
51    def __init__(self,*args):
52        self.myInterfaces = []   #Used to store the interfaces that are found
53        if hasattr(idlvisitor.AstVisitor,'__init__'):
54            idlvisitor.AstVisitor.__init__(self,args)
55
56    def visitAST(self, node):
57        for n in node.declarations():
58            n.accept(self)
59
60    def visitModule(self, node):
61        for n in node.definitions():
62            n.accept(self)
63
64    def visitInterface(self, node):
65        new_int = CC.Interface(node.identifier(),node.scopedName()[0])
66       
67        ops_list = []
68        self.addOps(node,ops_list)
69        new_int.operations.extend(ops_list)
70        #print node.identifier() + " has " + str(len(new_int.operations)) + " operations"
71        self.myInterfaces.append(new_int)
72
73    def addOps(self,node,ops):
74       
75        for i in node.inherits():
76            self.addOps(i,ops)
77
78        for d in node.contents():
79            if isinstance(d, idlast.Operation):
80                new_op = CC.Operation(d.identifier(),baseTypes[d.returnType().kind()])
81                # Get the c++ mappping of the return type
82                cxxRT = types.Type(d.returnType())
83                new_op.cxxReturnType = cxxRT.base()
84#                if new_op.returnType == 'string':
85#                    print foo2.base()
86                #print new_op.name + "::" + d.identifier() + "()"
87                #tmpstr = node.identifier() + "::" + d.identifier() + "("
88                #tmpstr2 = "  " + node.identifier() + "::" + d.identifier() + "("
89                if hasattr(d,'parameters'):
90                    for p in d.parameters():
91                        new_param = CC.Param(p.identifier())
92                        t =  p.paramType()
93                        # Get the c++ mapping of the type
94                        cxxT = types.Type(t)
95                        new_param.cxxType = cxxT.op(types.direction(p))
96                                               
97                        if hasattr(t,'scopedName'):
98                            #print ' '*8 + str(t.scopedName()),
99                            new_param.dataType = idlutil.ccolonName(t.scopedName())
100                        else:
101                            if isinstance(t,idltype.Type):
102                                #print ' '*8 + baseTypes[t.kind()],
103                                new_param.dataType = baseTypes[t.kind()]
104
105                        if p.is_in() and p.is_out():
106                            new_param.direction = 'inout'
107                        elif p.is_out():
108                            new_param.direction = 'out'
109                        else:
110                            new_param.direction = 'in'
111                        new_op.params.append(new_param)
112                        #tmpstr += new_param.direction + " " + new_param.dataType + ","
113                        #tmpstr2 += new_param.direction + " " + new_param.cxxType + ","
114                ops.append(new_op)
115                #print tmpstr[:-1] + ")"
116                #print tmpstr2[:-1] + ")"
117
118def run(tree, args):
119    visitor = ExampleVisitor()
120    tree.accept(visitor)
121    return visitor.myInterfaces
122
123def getInterfaces(filename):
124  f = os.popen(main.preprocessor_cmd + ' -I "/usr/local/include" -I "/usr/local/include/ossie" -I "/usr/include" "' \
125               + filename + '"','r')
126  try:
127      tree = _omniidl.compile(f, filename)
128  except TypeError:
129      tree = _omniidl.compile(f)
130     
131  ints = run(tree,'')
132  f.close()
133  del tree
134  idlast.clear()
135  idltype.clear()
136  _omniidl.clear()
137  #store file name and location information for each interface
138  for x in ints:
139      x.fullpath = filename
140      i = filename.rfind("/")
141      if i >= 0:
142          x.filename = filename[i+1:]
143         
144      x.filename = x.filename[:-4] #remove the .idl suffix
145   
146     
147  return ints
148 
149
150if __name__ == '__main__':
151    print "Command line not supported in this version"
Note: See TracBrowser for help on using the browser.