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