def dispatcher_func(data, target, opcode, message, c_args): # `data` is the handle to proxy/resource python object # `target` is the wl_proxy/wl_resource for self, this should be the same as self._ptr # `message` is the wl_message for self._interface.events/requests[opcode] # TODO: handle any user_data attached to the wl_proxy/wl_resource # get the proxy/resource object from the user data handle self = ffi.from_handle(data) # get the callback func = self.dispatcher[opcode] if func is None: return 0 # rebuild the args into python objects args = self.dispatcher.messages[opcode].c_to_arguments(c_args) try: ret = func(self, *args) except Exception: traceback.print_exc() return 0 if ret is None: return 0 else: return ret
def _timer_callback(data_ptr): if data_ptr == ffi.NULL: data = None else: data = ffi.from_handle(data_ptr) return f(data)
def _signal_callback(signal_number, data_ptr): if data_ptr == ffi.NULL: data = None else: data = ffi.from_handle(data_ptr) return f(signal_number, data)
def _signal_callback(fd, mask, data_ptr): if data_ptr == ffi.NULL: data = None else: data = ffi.from_handle(data_ptr) return f(fd, mask, data)
def event_loop_timer_func(data_ptr): callback_info = ffi.from_handle(data_ptr) ret = callback_info.callback(callback_info.data) if isinstance(ret, int): return ret return 0
def event_loop_signal_func(signal_number, data_ptr): callback_info = ffi.from_handle(data_ptr) ret = callback_info.callback(signal_number, callback_info.data) if isinstance(ret, int): return ret return 0
def event_loop_fd_func(fd, mask, data_ptr): callback_info = ffi.from_handle(data_ptr) ret = callback_info.callback(fd, mask, callback_info.data) if isinstance(ret, int): return ret return 0
def resource_destroy_func(res_ptr): # the user data to the resource is the handle to the resource resource_handle = lib.wl_resource_get_user_data(res_ptr) resource = ffi.from_handle(resource_handle) # if the destructor has been set, run it func = resource.dispatcher.destructor if func is not None: func(resource)
def _global_bind_func(client_ptr, data, version, id): # `data` is the handle to Global _global = ffi.from_handle(data) version = min(_global._interface.version, version) resource = _global._interface.resource_class(client_ptr, version, id) # Call a user defined handler if _global.bind_handler: _global.bind_handler(resource)
def global_bind_func(client_ptr, data, version, id): # `data` is the handle to Global callback_info = ffi.from_handle(data) version = min(callback_info["interface"].version, version) resource = callback_info["interface"].resource_class(client_ptr, version, id) # Call a user defined handler if callback_info["bind_func"]: # TODO: add some error catching so we don't segfault callback_info["bind_func"](resource)
def notify_func(listener_ptr, data): # basically a `container_of` macro, but using cffi, get the # wl_listener_container for the given listener container = ffi.cast( "struct wl_listener_container *", ffi.cast("char*", listener_ptr) - ffi.offsetof("struct wl_listener_container", "destroy_listener")) listener = ffi.from_handle(container.handle) if listener._signal is not None and listener._signal._data_wrapper is not None: data = listener._signal._data_wrapper(data) callback = listener._notify callback(listener, data)
def get_object(self, id): """Look up an object in the client name space This looks up an object in the client object name space by its object ID. :param id: The object id :type id: `int` :returns: The object, or ``None`` if there is not object for the given ID """ res_ptr = lib.wl_client_get_object(self._ptr, id) # If the object doesn't exist, this returns NULL, and asking for # forgiveness doesn't work, becuase it will seg fault if res_ptr == ffi.NULL: return res_py_ptr = lib.wl_resource_get_user_data(res_ptr) return ffi.from_handle(res_py_ptr)
def get_object(self, object_id): """Look up an object in the client name space This looks up an object in the client object name space by its object ID. :param object_id: The object id :type object_id: `int` :returns: The object, or ``None`` if there is not object for the given ID """ res_ptr = lib.wl_client_get_object(self._ptr, object_id) # If the object doesn't exist, this returns NULL, and asking for # forgiveness doesn't work, becuase it will seg fault if res_ptr == ffi.NULL: return None resource_handle = lib.wl_resource_get_user_data(res_ptr) return ffi.from_handle(resource_handle)
def event_loop_idle_func(data_ptr): callback_info = ffi.from_handle(data_ptr) callback_info.callback(callback_info.data)