def make_struct_members(cls): result = [] static_funcs = [] funcs = get_funcs(cls) delegate_visibility = "internal" if schema.is_proxy(cls): delegate_visibility = "private" for func in cls.get_static_funcs(): static_funcs.append(get_func_parts(func, 0)) parentClassName = cls.get_parent_capi_name() if (parentClassName != "cef_base_ref_counted_t" and parentClassName != "cef_base_scoped_t"): message = "Error: Generation for base class \"" + cls.get_parent_name( ) + "\" is not supported." raise Exception(message) result.append('internal {0} _base;'.format(parentClassName)) for func in funcs: if not func['basefunc']: result.append('internal IntPtr %(field_name)s;' % func) result.append('') for func in static_funcs: append_dllimport(result, func) for func in funcs: postfixs = schema.get_platform_retval_postfixs(func['csn_retval']) for px in postfixs: func['px'] = px result.append('[UnmanagedFunctionPointer(%s)]' % schema.CEF_CALLBACK) result.append('#if !DEBUG') result.append('[SuppressUnmanagedCodeSecurity]') result.append('#endif') result.append( delegate_visibility + ' delegate %(csn_retval)s%(px)s %(delegate_type)s%(px)s(%(csn_args_proto)s);' % func) result.append('') for func in funcs: if schema.is_proxy(cls): postfixs = schema.get_platform_retval_postfixs(func['csn_retval']) for px in postfixs: func['px'] = px result.append('// %(name)s' % func) result.append('private static IntPtr _p%(slot)s%(px)s;' % func) result.append( 'private static %(delegate_type)s%(px)s _d%(slot)s%(px)s;' % func) result.append('') result.append( 'public static %(csn_retval)s%(px)s %(csn_name)s%(px)s(%(csn_args_proto)s)' % func) result.append('{') result.append(' %(delegate_type)s%(px)s d;' % func) result.append(' var p = self->%(field_name)s;' % func) result.append( ' if (p == _p%(slot)s%(px)s) { d = _d%(slot)s%(px)s; }' % func) result.append(' else') result.append(' {') result.append( ' d = (%(delegate_type)s%(px)s)Marshal.GetDelegateForFunctionPointer(p, typeof(%(delegate_type)s%(px)s));' % func) result.append( ' if (_p%(slot)s%(px)s == IntPtr.Zero) { _d%(slot)s%(px)s = d; _p%(slot)s%(px)s = p; }' % func) result.append(' }') args = ', '.join(map(lambda x: x['name'], func['csn_args'])) if func['csn_retval'] == 'void': result.append(' d(%s);' % args) else: result.append(' return d(%s);' % args) result.append('}') result.append('') if schema.is_handler(cls): iname = schema.get_iname(cls) result.append('private static int _sizeof;') result.append('') result.append('static %s()' % iname) result.append('{') result.append(indent + '_sizeof = Marshal.SizeOf(typeof(%s));' % iname) result.append('}') result.append('') result.append('internal static %s* Alloc()' % iname) result.append('{') result.append(indent + 'var ptr = (%s*)Marshal.AllocHGlobal(_sizeof);' % iname) result.append(indent + '*ptr = new %s();' % iname) result.append(indent + 'ptr->_base._size = (UIntPtr)_sizeof;') result.append(indent + 'return ptr;') result.append('}') result.append('') result.append('internal static void Free(%s* ptr)' % iname) result.append('{') result.append(indent + 'Marshal.FreeHGlobal((IntPtr)ptr);') result.append('}') result.append('') return result
def make_struct_members(cls): result = [] static_funcs = [] funcs = get_funcs(cls) delegate_visibility = "internal" if schema.is_proxy(cls): delegate_visibility = "private" for func in cls.get_static_funcs(): static_funcs.append( get_func_parts(func, 0) ) result.append('internal cef_base_t _base;') for func in funcs: if not func['basefunc']: result.append('internal IntPtr %(field_name)s;' % func) result.append('') for func in static_funcs: append_dllimport(result, func) for func in funcs: postfixs = schema.get_platform_retval_postfixs(func['csn_retval']) for px in postfixs: func['px'] = px result.append('[UnmanagedFunctionPointer(%s)]' % schema.CEF_CALLBACK) result.append('#if !DEBUG') result.append('[SuppressUnmanagedCodeSecurity]') result.append('#endif') result.append(delegate_visibility + ' delegate %(csn_retval)s%(px)s %(delegate_type)s%(px)s(%(csn_args_proto)s);' % func) result.append('') for func in funcs: if schema.is_proxy(cls): postfixs = schema.get_platform_retval_postfixs(func['csn_retval']) for px in postfixs: func['px'] = px result.append('// %(name)s' % func) result.append('private static IntPtr _p%(slot)s%(px)s;' % func) result.append('private static %(delegate_type)s%(px)s _d%(slot)s%(px)s;' % func) result.append('') result.append('public static %(csn_retval)s%(px)s %(csn_name)s%(px)s(%(csn_args_proto)s)' % func) result.append('{') result.append(' %(delegate_type)s%(px)s d;' % func) result.append(' var p = self->%(field_name)s;' % func) result.append(' if (p == _p%(slot)s%(px)s) { d = _d%(slot)s%(px)s; }' % func) result.append(' else') result.append(' {') result.append(' d = (%(delegate_type)s%(px)s)Marshal.GetDelegateForFunctionPointer(p, typeof(%(delegate_type)s%(px)s));' % func) result.append(' if (_p%(slot)s%(px)s == IntPtr.Zero) { _d%(slot)s%(px)s = d; _p%(slot)s%(px)s = p; }' % func) result.append(' }') args = ', '.join(map(lambda x: x['name'], func['csn_args'])) if func['csn_retval'] == 'void': result.append(' d(%s);' % args) else: result.append(' return d(%s);' % args) result.append('}') result.append('') if schema.is_handler(cls): iname = schema.get_iname(cls) result.append('private static int _sizeof;') result.append('') result.append('static %s()' % iname) result.append('{') result.append(indent + '_sizeof = Marshal.SizeOf(typeof(%s));' % iname) result.append('}') result.append('') result.append('internal static %s* Alloc()' % iname) result.append('{') result.append(indent + 'var ptr = (%s*)Marshal.AllocHGlobal(_sizeof);' % iname) result.append(indent + '*ptr = new %s();' % iname) result.append(indent + 'ptr->_base._size = (UIntPtr)_sizeof;') result.append(indent + 'return ptr;') result.append('}') result.append('') result.append('internal static void Free(%s* ptr)' % iname) result.append('{') result.append(indent + 'Marshal.FreeHGlobal((IntPtr)ptr);') result.append('}') result.append('') return result