def write_attributes(interface, attribute): assert isinstance(attribute, idlast.Attribute) voidType = idltype.Base(idltype.tk_void) callables = [] param = idlast.Parameter(attribute.file(), attribute.line(), attribute.mainFile(), [], [], 0, attribute.attrType(), "_v") for identifier in attribute.identifiers(): callables.append( Callable(interface, "_set_" + identifier, id.mapID(identifier), voidType, [param], 0, [], [])) return callables
def __init__(self, name, attrType): returnType = idltype.Base(idltype.tk_void) param = idlast.Parameter(None, None, None, [], [], 0, attrType, "value") Method.__init__(self, name, returnType, [param], [])
def aliasType(self): return idltype.Base(self.kind())
def _implied(self, node, handler, poller): """ _implied(node, handler, poller) -> interface Generate implied client-side sendc / sendp operations. Returns a new idlast.Interface containing just those methods, and sets _ami_ops attribute on the original Interface node. """ operations = [] handler_type = idltype.Declared(handler, handler.scopedName(), idltype.tk_objref, 0) poller_type = idltype.Declared(poller, poller.scopedName(), idltype.tk_value, 0) intf_scope = node.scopedName() callables, clashes = self._callables(node) for cb in callables: if cb.oneway(): continue params = [] for param in cb.parameters(): if param.is_in(): params.append(idlast.Parameter(param.file(), param.line(), param.mainFile(), [], [], 0, param.paramType(), param.identifier())) # sendc... op_ident = self._prefixName("sendc_", cb.identifier(), clashes) op_scope = intf_scope + [op_ident] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) handler_param = idlast.Parameter(cb.file(), cb.line(), cb.mainFile(), [], [], 0, handler_type, "ami_handler") op = idlast.Operation(cb.file(), cb.line(), cb.mainFile(), [], [], 0, idltype.Base(idltype.tk_void), op_ident, op_scope, op_repoId, [handler_param] + params, [], cb.contexts()) operations.append(op) if hasattr(cb, "_ami_declarator"): op._ami_from = cb._ami_declarator if cb.identifier().startswith("set"): cb._ami_declarator._ami_set_sendc = op op._ami_setter = 1 else: cb._ami_declarator._ami_get_sendc = op op._ami_setter = 0 else: cb._ami_sendc = op op._ami_from = cb # sendp... op_ident = self._prefixName("sendp_", cb.identifier(), clashes) op_scope = intf_scope + [op_ident] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) poller_param = idlast.Parameter(cb.file(), cb.line(), cb.mainFile(), [], [], 0, poller_type, "ami_poller") op = idlast.Operation(cb.file(), cb.line(), cb.mainFile(), [], [], 0, poller_type, op_ident, op_scope, op_repoId, params[:], [], cb.contexts()) operations.append(op) if hasattr(cb, "_ami_declarator"): op._ami_from = cb._ami_declarator if cb.identifier().startswith("set"): cb._ami_declarator._ami_set_sendp = op op._ami_setter = 1 else: cb._ami_declarator._ami_get_sendp = op op._ami_setter = 0 else: cb._ami_sendp = op op._ami_from = cb node._ami_ops = operations comment = idlast.Comment("// AMI implied operations for interface %s" % node.identifier(), node.file(), node.line()) implied_intf = idlast.Interface(node.file(), node.line(), node.mainFile(), node.pragmas(), [comment], node.identifier(), node.scopedName(), node.repoId(), node.abstract(), node.local(), node.inherits()) implied_intf._setContents(operations) return implied_intf
def _poller(self, node): """ _poller(node) -> (poller_fwd, poller) Build Poller valuetype. """ def amiPoller(n): while isinstance(n, idlast.Declarator): n = n.fullDecl() return n._ami_poller if node.inherits(): base_pollers = [ amiPoller(n) for n in node.inherits() ] else: base_pollers = [ poller_decl ] poller_ident = self._amiName(node.scopedName(), "Poller") poller_scope = node.scopedName()[:-1] + [poller_ident] poller_repoId = "IDL:%s:1.0" % idlutil.slashName(poller_scope) comment = idlast.Comment("// Poller valuetype for interface %s" % node.identifier(), node.file(), node.line()) poller_fwd = idlast.ValueForward(node.file(), node.line(), node.mainFile(), [], [], poller_ident, poller_scope, poller_repoId, 1) poller = idlast.ValueAbs(node.file(), node.line(), node.mainFile(), [], [comment], poller_ident, poller_scope, poller_repoId, base_pollers, []) poller._ami_gen = 1 operations = [] callables, clashes = self._callables(node) for cb in callables: if cb.oneway(): continue op_scope = poller_scope + [cb.identifier()] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) params = [idlast.Parameter(cb.file(), cb.line(), cb.mainFile(), [], [], 0, idltype.Base(idltype.tk_ulong), "ami_timeout")] if cb.returnType().kind() != idltype.tk_void: params.append(idlast.Parameter(cb.file(), cb.line(), cb.mainFile(), [], [], 1, cb.returnType(), "ami_return_val")) for param in cb.parameters(): if param.is_out(): params.append(idlast.Parameter(param.file(), param.line(), param.mainFile(), [], [], 1, param.paramType(), param.identifier())) op = idlast.Operation(cb.file(), cb.line(), cb.mainFile(), [], [], 0, idltype.Base(idltype.tk_void), cb.identifier(), op_scope, op_repoId, params, cb.raises(), []) if hasattr(cb, "_ami_declarator"): if cb.identifier().startswith("set"): cb._ami_declarator._ami_set_poller = op else: cb._ami_declarator._ami_get_poller = op op._ami_from = cb._ami_declarator else: cb._ami_poller = op op._ami_from = cb operations.append(op) poller._setContents(operations) idlast.registerDecl(poller.scopedName(), poller) node._ami_poller = poller poller._ami_from = node return poller_fwd, poller
def _handler(self, node): """ _handler(node) -> (handler_fwd, handler) Build ReplyHandler interface. """ def amiHandler(n): while isinstance(n, idlast.Declarator): n = n.fullDecl() return n._ami_handler if node.inherits(): base_handlers = [ amiHandler(n) for n in node.inherits() ] else: base_handlers = [ reply_handler_decl ] handler_ident = self._amiName(node.scopedName(), "Handler") handler_scope = node.scopedName()[:-1] + [handler_ident] handler_repoId = "IDL:%s:1.0" % idlutil.slashName(handler_scope) comment = idlast.Comment("// ReplyHandler for interface %s" % node.identifier(), node.file(), node.line()) handler_fwd = idlast.Forward(node.file(), node.line(), node.mainFile(), [], [], handler_ident, handler_scope, handler_repoId, 0, 0) handler = idlast.Interface(node.file(), node.line(), node.mainFile(), [], [comment], handler_ident, handler_scope, handler_repoId, 0, 0, base_handlers) handler._ami_gen = 1 operations = [] # Success methods callables, clashes = self._callables(node) for cb in callables: op_scope = handler_scope + [cb.identifier()] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) params = [] if cb.returnType().kind() != idltype.tk_void: params.append(idlast.Parameter(cb.file(), cb.line(), cb.mainFile(), [], [], 0, cb.returnType(), "ami_return_val")) for param in cb.parameters(): if param.is_out(): params.append(idlast.Parameter(param.file(), param.line(), param.mainFile(), [], [], 0, param.paramType(), param.identifier())) op = idlast.Operation(cb.file(), cb.line(), cb.mainFile(), [], [], 0, idltype.Base(idltype.tk_void), cb.identifier(), op_scope, op_repoId, params, [], []) if hasattr(cb, "_ami_declarator"): if cb.identifier().startswith("set"): cb._ami_declarator._ami_set_handler = op else: cb._ami_declarator._ami_get_handler = op else: cb._ami_handler = op operations.append(op) # _excep methods exceps = [] for cb in callables: ident = cb.identifier() excep_ident = self._suffixName("_excep", ident, clashes) params = [idlast.Parameter("<builtin>", 0, 0, [], [], 0, exception_holder_type, "excep_holder")] op_scope = handler_scope + [excep_ident] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) op = idlast.Operation(cb.file(), cb.line(), cb.mainFile(), [], [], 0, idltype.Base(idltype.tk_void), excep_ident, op_scope, op_repoId, params, [], []) if hasattr(cb, "_ami_declarator"): if cb.identifier().startswith("set"): cb._ami_declarator._ami_set_handler_excep = op else: cb._ami_declarator._ami_get_handler_excep = op else: cb._ami_handler_excep = op exceps.append(op) handler._setContents(operations + exceps) idlast.registerDecl(handler.scopedName(), handler) node._ami_handler = handler return handler_fwd, handler
def _callables(self, node): """ _callables(node) -> operations, clashes Return the operations for an interface, converting attributes into get/set operations. Also return a set of defined names used to avoid name clashes. """ operations = [] clashes = set() for cb in node.callables(): if isinstance(cb, idlast.Operation): clashes.add(cb.identifier()) if cb.oneway(): continue operations.append(cb) elif isinstance(cb, idlast.Attribute): for dec in cb.declarators(): clashes.add(dec.identifier()) op_ident = "get_" + dec.identifier() op_scope = node.scopedName() + [op_ident] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) op = idlast.Operation(dec.file(), dec.line(), dec.mainFile(), [], [], 0, cb.attrType(), op_ident, op_scope, op_repoId, [], [], []) op._ami_declarator = dec operations.append(op) if cb.readonly(): continue op_ident = "set_" + dec.identifier() op_scope = node.scopedName() + [op_ident] op_repoId = "IDL:%s:1.0" % idlutil.slashName(op_scope) params = [idlast.Parameter(dec.file(), dec.line(), dec.mainFile(), [], [], 0, cb.attrType(), "attr_" + dec.identifier())] op = idlast.Operation(dec.file(), dec.line(), dec.mainFile(), [], [], 0, idltype.Base(idltype.tk_void), op_ident, op_scope, op_repoId, params, [], []) op._ami_declarator = dec operations.append(op) return operations, clashes
if os.path.isdir(vpylibdir): sys.path.insert(0, vpylibdir) if os.path.isdir(archlibdir): sys.path.insert(0, archlibdir) from omniidl import idlast, idltype from omnijni import cppcode from omnijni import idljni holderKinds = (idltype.tk_boolean, idltype.tk_octet, idltype.tk_char, idltype.tk_short, idltype.tk_ushort, idltype.tk_long, idltype.tk_ulong, idltype.tk_longlong, idltype.tk_ulonglong, idltype.tk_float, idltype.tk_double, idltype.tk_any) holderTypes = [idltype.Base(k) for k in holderKinds] + [idltype.String(0)] if __name__ == '__main__': header = cppcode.Header('holders.h') header.include('<omniORB4/CORBA.h>') header.include('<jni.h>') header.include('<omnijni/loader.h>') body = header.Namespace('CORBA').Namespace('jni') module = cppcode.Module() module.include('<omnijni/omnijni.h>') module.include('"holders.h"') helper = idljni.HolderHelper() for node in holderTypes: # Generate declarations