45 from omniidl
import idlast, idlvisitor
46 from omniidl_be.cxx
import ast, util, id, types, output
58 * Example class implementing IDL interface @fq_name@ 61 : public virtual @fq_POA_name@, 62 public virtual PortableServer::RefCountServantBase 65 // Make sure all instances are built on the heap by making the 66 // destructor non-public 67 //virtual ~@impl_name@(); 70 // standard constructor 72 virtual ~@impl_name@(); 74 // attributes and operations 81 * Example implementational code for IDL interface @fqname@ 83 @impl_fqname@::@impl_name@() 85 // Please add extra constructor code here. 89 @impl_fqname@::~@impl_name@() 91 // Please add extra destructor code here. 96 * Methods corresponding to IDL attributes and operations 100 // End of example implementational code 106 * @atmark@file @impl_h@ 107 * @atmark@brief Service implementation header of @file@ 114 #ifndef @include_guard@ 115 #define @include_guard@ 119 #endif // @include_guard@ 126 * @atmark@file @impl_cpp@ 127 * @atmark@brief Service implementation code of @file@ 136 def generate(idl_file, preproc_args, impl_suffix, skel_suffix = "Skel", fd_h=None, fd_cpp=None):
137 basename = idl_file.replace(
".idl",
"")
138 preprocessor_cmd =
"omnicpp" 139 preprocessor_opt =
"-I" + string.join(preproc_args,
" -I")
141 preproc_cmd =
'%s %s %s' % (preprocessor_cmd,\
142 preprocessor_opt, idl_file)
144 file = os.popen(preproc_cmd,
"r") 146 skel_filename = basename + skel_suffix + ".h" 147 idl_filename = idl_file
150 ignore_operations = [
"profile"]
152 tree = _omniidl.compile(file)
155 cxx_svc_impl.__init__(idl_filename, \
162 ifs = cxx_svc_impl.run(tree)
171 def __init__(idl_filename, impl_basename, skel_filename, \
172 suffix = "_impl", ignore_op = [], fd_h = None, fd_cpp = None):
173 self.idl_filename = idl_filename
175 self.impl_h_filename = impl_basename + self.suffix +
".h" 176 self.impl_cpp_filename = impl_basename + self.suffix +
".cpp" 177 self.skel_filename = skel_filename
178 self.ignore_op = ignore_op
180 self.include_guard = self.impl_h_filename.upper().replace(
".",
"_")
184 output.Stream(output.createFile(self.impl_h_filename), 2)
186 self.stream_h = output.Stream(fd_h, 2)
190 output.Stream(output.createFile(self.impl_cpp_filename), 2)
192 self.stream_cpp = output.Stream(fd_cpp, 2)
199 bits = name.suffix(self.suffix).fullName()
200 return string.join(bits,
"_")
211 impl_cpp = output.StringStream()
213 impl_h = output.StringStream()
218 stream_h.out(class_h,
220 impl_h = self.impl_h_filename,
221 include_guard = self.include_guard,
222 skel_h = self.skel_filename,
223 file = self.idl_filename,
224 interfaces = str(impl_h))
227 stream_cpp.out(class_cpp,
229 impl_cpp = self.impl_cpp_filename,
230 impl_h = self.impl_h_filename,
231 file = self.idl_filename,
232 interfaces = str(impl_cpp))
235 for n
in bii.allInterfaces():
236 self.ifs.
append(string.join(n.scopedName(),
"_") + self.suffix)
247 def __init__(self, stream_h, stream_cpp, ignore_operations):
261 for n
in node.declarations():
262 if ast.shouldGenerateCodeForDecl(n):
267 for n
in node.definitions():
274 scopedName = id.Name(node.scopedName())
276 cxx_fqname = scopedName.fullyQualify()
279 fqname = scopedName.fullyQualify(cxx = 0)
288 virtual_operations = []
293 allInterfaces = [node] + ast.allInherits(node)
294 allCallables = util.fold( map(
lambda x:x.callables(), allInterfaces),
295 [],
lambda x, y: x + y )
304 for c
in allCallables:
306 if isinstance(c, idlast.Attribute) :
307 attrType = types.Type(c.attrType())
308 d_attrType = attrType.deref()
310 for i
in c.identifiers():
311 attribname = id.mapID(i)
312 returnType = attrType.op(types.RET)
313 inType = attrType.op(types.IN)
314 attributes.append(returnType +
" " + attribname +
"()")
317 args = attribname +
"(" + inType +
")" 318 declarations.append(
"void " + args)
319 implementations.append(
"void " + impl_flat_name +\
322 declarations.append(returnType +
" " + attribname +
"()")
323 implementations.append(returnType +
" " + impl_flat_name+\
324 "::" + attribname +
"()")
325 elif isinstance(c, idlast.Operation):
327 for p
in c.parameters():
328 paramType = types.Type(p.paramType())
329 cxx_type = paramType.op(types.direction(p), use_out = 0)
331 argname = id.mapID(p.identifier())
332 params.append(cxx_type +
" " + argname)
335 if c.contexts() != []:
336 params.append(
"CORBA::Context_ptr _ctxt")
338 return_type = types.Type(c.returnType()).op(types.RET)
340 opname = id.mapID(c.identifier())
342 arguments = string.join(params,
", ")
343 args = opname +
"(" + arguments +
")" 344 declarations.append(return_type +
" " + args)
345 implementations.append(return_type +
" " + \
349 util.fatalError(
"Internal error generating interface member")
350 raise "No code for interface member: " + repr(c)
353 defs = string.join(map(
lambda x:x +
";\n", declarations),
"")
357 impl_fqname = impl_flat_name,
358 impl_name = impl_flat_name,
360 fq_POA_name =
"POA_" + cxx_fqname,
364 impls = string.join(map(
lambda x: x +
"""\ 367 // Please insert your code here and remove the following warning pragma 368 #warning "Code missing in function <""" + x +
""">" 372 implementations),
"")
376 impl_name = impl_flat_name,
377 impl_fqname = impl_flat_name,
381 if __name__ ==
"__main__":
385 print cxx_svc_impl.generate(sys.argv[1],
"SVC_impl")
def visitInterface(self, node)
def impl_simplename(name)
def __init__(self, stream_h, stream_cpp, ignore_operations)
def visitModule(self, node)
def generate(idl_file, preproc_args, impl_suffix, skel_suffix="Skel", fd_h=None, fd_cpp=None)
def __init__(idl_filename, impl_basename, skel_filename, suffix="_impl", ignore_op=[], fd_h=None, fd_cpp=None)