24 from omniidl
import idlast, idlvisitor
25 from omniidl_be.cxx
import ast, util, id, types, output
37 * Example class implementing IDL interface @fq_name@ 40 : public virtual @fq_POA_name@, 41 public virtual PortableServer::RefCountServantBase 44 // Make sure all instances are built on the heap by making the 45 // destructor non-public 46 //virtual ~@impl_name@(); 49 // standard constructor 51 virtual ~@impl_name@(); 53 // attributes and operations 60 * Example implementational code for IDL interface @fqname@ 62 @impl_fqname@::@impl_name@() 64 // Please add extra constructor code here. 68 @impl_fqname@::~@impl_name@() 70 // Please add extra destructor code here. 75 * Methods corresponding to IDL attributes and operations 79 // End of example implementational code 85 * @atmark@file @impl_h@ 86 * @atmark@brief Service implementation header of @file@ 93 #ifndef @include_guard@ 94 #define @include_guard@ 98 #endif // @include_guard@ 105 * @atmark@file @impl_cpp@ 106 * @atmark@brief Service implementation code of @file@ 115 def generate(idl_file, preproc_args, impl_suffix, skel_suffix = "Skel", fd_h=None, fd_cpp=None):
116 basename = idl_file.replace(
".idl",
"")
117 preprocessor_cmd =
"omnicpp" 118 preprocessor_opt =
"-I" + string.join(preproc_args,
" -I")
120 preproc_cmd =
'%s %s %s' % (preprocessor_cmd,\
121 preprocessor_opt, idl_file)
123 file = os.popen(preproc_cmd,
"r") 125 skel_filename = basename + skel_suffix + ".h" 126 idl_filename = idl_file
129 ignore_operations = [
"profile"]
131 tree = _omniidl.compile(file)
150 def __init__(idl_filename, impl_basename, skel_filename, \
151 suffix =
"_impl", ignore_op = [], fd_h =
None, fd_cpp =
None):
152 self.idl_filename = idl_filename
154 self.impl_h_filename = impl_basename + self.suffix +
".h" 155 self.impl_cpp_filename = impl_basename + self.suffix +
".cpp" 156 self.skel_filename = skel_filename
157 self.ignore_op = ignore_op
159 self.include_guard = self.impl_h_filename.upper().replace(
".",
"_")
163 output.Stream(output.createFile(self.impl_h_filename), 2)
165 self.stream_h = output.Stream(fd_h, 2)
169 output.Stream(output.createFile(self.impl_cpp_filename), 2)
171 self.stream_cpp = output.Stream(fd_cpp, 2)
178 bits = name.suffix(self.suffix).fullName()
179 return string.join(bits,
"_")
190 impl_cpp = output.StringStream()
192 impl_h = output.StringStream()
197 stream_h.out(class_h,
199 impl_h = self.impl_h_filename,
200 include_guard = self.include_guard,
201 skel_h = self.skel_filename,
202 file = self.idl_filename,
203 interfaces = str(impl_h))
206 stream_cpp.out(class_cpp,
208 impl_cpp = self.impl_cpp_filename,
209 impl_h = self.impl_h_filename,
210 file = self.idl_filename,
211 interfaces = str(impl_cpp))
214 for n
in bii.allInterfaces():
215 self.ifs.append(string.join(n.scopedName(),
"_") + self.suffix)
226 def __init__(self, stream_h, stream_cpp, ignore_operations):
240 for n
in node.declarations():
241 if ast.shouldGenerateCodeForDecl(n):
246 for n
in node.definitions():
251 self.__allInterfaces.append(node)
253 scopedName = id.Name(node.scopedName())
255 cxx_fqname = scopedName.fullyQualify()
258 fqname = scopedName.fullyQualify(cxx = 0)
267 virtual_operations = []
272 allInterfaces = [node] + ast.allInherits(node)
273 allCallables = util.fold( map(
lambda x:x.callables(), allInterfaces),
274 [],
lambda x, y: x + y )
283 for c
in allCallables:
285 if isinstance(c, idlast.Attribute) :
286 attrType = types.Type(c.attrType())
287 d_attrType = attrType.deref()
289 for i
in c.identifiers():
290 attribname = id.mapID(i)
291 returnType = attrType.op(types.RET)
292 inType = attrType.op(types.IN)
293 attributes.append(returnType +
" " + attribname +
"()")
296 args = attribname +
"(" + inType +
")" 297 declarations.append(
"void " + args)
298 implementations.append(
"void " + impl_flat_name +\
301 declarations.append(returnType +
" " + attribname +
"()")
302 implementations.append(returnType +
" " + impl_flat_name+\
303 "::" + attribname +
"()")
304 elif isinstance(c, idlast.Operation):
306 for p
in c.parameters():
307 paramType = types.Type(p.paramType())
308 cxx_type = paramType.op(types.direction(p), use_out = 0)
310 argname = id.mapID(p.identifier())
311 params.append(cxx_type +
" " + argname)
314 if c.contexts() != []:
315 params.append(
"CORBA::Context_ptr _ctxt")
317 return_type = types.Type(c.returnType()).op(types.RET)
319 opname = id.mapID(c.identifier())
321 arguments = string.join(params,
", ")
322 args = opname +
"(" + arguments +
")" 323 declarations.append(return_type +
" " + args)
324 implementations.append(return_type +
" " + \
328 util.fatalError(
"Internal error generating interface member")
329 raise "No code for interface member: " + repr(c)
332 defs = string.join(map(
lambda x:x +
";\n", declarations),
"")
335 self.stream_h.out(interface_def,
336 impl_fqname = impl_flat_name,
337 impl_name = impl_flat_name,
339 fq_POA_name =
"POA_" + cxx_fqname,
343 impls = string.join(map(
lambda x: x +
"""\ 346 // Please insert your code here and remove the following warning pragma 348 #warning "Code missing in function <""" + x +
""">" 353 implementations),
"")
355 self.stream_cpp.out(interface_code,
357 impl_name = impl_flat_name,
358 impl_fqname = impl_flat_name,
362 if __name__ ==
"__main__":
def visitInterface(self, node)
def impl_simplename(name)
def __init__(self, stream_h, stream_cpp, ignore_operations)
def visitModule(self, node)
def __init__(idl_filename, impl_basename, skel_filename, suffix="_impl", ignore_op=[], fd_h=None, fd_cpp=None)
def generate(idl_file, preproc_args, impl_suffix, skel_suffix="Skel", fd_h=None, fd_cpp=None)