Skip to content

Commit

Permalink
GI-generated signal connector functions
Browse files Browse the repository at this point in the history
Make @cfunction based signal connection methods a little less painful by using GI
to set return, argument types
  • Loading branch information
jwahlstrand committed Oct 28, 2023
1 parent ca4819a commit 8eca099
Show file tree
Hide file tree
Showing 15 changed files with 4,590 additions and 3 deletions.
18 changes: 18 additions & 0 deletions GI/src/giexport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,24 @@ function all_object_methods!(exprs,ns;skiplist=Symbol[],object_skiplist=Symbol[]
end
end

function all_object_signals!(exprs,ns;skiplist=Symbol[],object_skiplist=Symbol[], liboverride=nothing, exclude_deprecated=true)
not_implemented=0
skipped=0
created=0
objects=get_all(ns,GIObjectInfo,exclude_deprecated)
for o in objects
name=get_name(o)
if in(name,object_skiplist)
continue
end
signals = get_signals(o)
for s in signals
(exclude_deprecated && is_deprecated(s)) && continue
push!(exprs, decl(s))
end
end
end

function all_interfaces!(exprs,exports,ns;print_summary=true,skiplist=Symbol[],exclude_deprecated=true)
interfaces=get_all(ns,GIInterfaceInfo,exclude_deprecated)

Expand Down
36 changes: 35 additions & 1 deletion GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,46 @@ function decl(callbackinfo::GICallbackInfo)
unblock(d)
end

## Signal output
function decl(signalinfo::GISignalInfo)
name = get_name(signalinfo)
fname=Symbol(replace(String(name),"-"=>"_"))
oname = Symbol("on_$fname")
rettypefunc = Symbol("$(fname)_signal_return_type")
typeargsfunc = Symbol("$(fname)_signal_arg_types")
@assert is_method(signalinfo)
object = get_container(signalinfo)
@assert object !== nothing
objtypeinfo = extract_type(InstanceType,object)
rettypeinfo=get_return_type(signalinfo)
rettype = extract_type(rettypeinfo).ctype
args=get_args(signalinfo)
argctypes_arr=[]
for arg in args
argtype = extract_type(arg)
push!(argctypes_arr, argtype.ctype)
end
argctypes = Expr(:tuple, argctypes_arr...)
d = quote
function $oname(f, object::$(objtypeinfo.jtype), user_data=object, after=false)
GLib.signal_connect_generic(f, object, $(String(name)), $rettype, $argctypes, after, user_data)
end
function $rettypefunc(object::$(objtypeinfo.jtype))
$rettype
end
function $typeargsfunc(object::$(objtypeinfo.jtype))
$argctypes
end
end
unblock(d)
end

## Handling argument types, creating methods

struct NotImplementedError <: Exception
message::String
end
NotImplementedError() = NotImplementedError("") # could overload `Base.showerror`
NotImplementedError() = NotImplementedError("")

abstract type InstanceType end
is_pointer(::Type{InstanceType}) = true
Expand Down
2 changes: 1 addition & 1 deletion GI/src/girepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ may_be_null(ai::GICallableInfo) = may_return_null(ai)

for (owner,flag) in [
(:type, :is_pointer), (:callable, :may_return_null), (:callable, :skip_return),
(:arg, :is_caller_allocates), (:arg, :may_be_null),
(:callable, :is_method), (:arg, :is_caller_allocates), (:arg, :may_be_null),
(:arg, :is_skip), (:arg, :is_return_value), (:arg, :is_optional),
(:type, :is_zero_terminated), (:base, :is_deprecated), (:struct, :is_gtype_struct),
(:object, :get_abstract)]
Expand Down
1 change: 1 addition & 0 deletions gen/gen_gdk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ c = GI.all_objects!(exprs,exports,ns,skiplist=object_skiplist;print_summary=true
GI.append_object_docs!(exprs, "gdk4", d, c, ns)
GI.all_interfaces!(exprs,exports,ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs,ns;skiplist=skiplist,object_skiplist=object_skiplist)

push!(exprs,exports)

Expand Down
1 change: 1 addition & 0 deletions gen/gen_gdkpixbuf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GI.append_struc_docs!(exprs, "gdk-pixbuf", d, c, ns)
c = GI.all_objects!(exprs,exports,ns;constructor_skiplist=[:new_from_resource,:new_with_mime_type,:new_from_resource_at_scale])
GI.append_object_docs!(exprs, "gdk-pixbuf", d, c, ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs,ns;skiplist=skiplist)
push!(exprs,exports)

GI.write_to_file(path,"gdkpixbuf_structs",toplevel)
Expand Down
1 change: 1 addition & 0 deletions gen/gen_gio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GI.all_interfaces!(exprs,exports,ns;skiplist=[:XdpProxyResolverIface])
c = GI.all_objects!(exprs,exports,ns;skiplist=obj_skiplist,constructor_skiplist=[:new_for_bus_sync,:new_sync,:new_with_fd_list,:new_for_address_finish,:new_for_bus_finish,:new_for_bus_finish,:new_from_filename,:new_loopback,:new_section,:new_with_default_fallbacks,:new_from_file_with_password],output_cache_define=false,output_cache_init=false)
GI.append_object_docs!(exprs, "gio", d, c, ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs,ns;object_skiplist=vcat(obj_skiplist,[:AppInfoMonitor,:DBusConnection,:DBusMenuModel,:DBusProxy,:DBusMethodInvocation,:IOModule,:SimpleProxyResolver,:UnixMountMonitor,:Task]))

push!(exprs,exports)

Expand Down
3 changes: 2 additions & 1 deletion gen/gen_gobject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ GI.append_object_docs!(exprs, "gobject", d, c, ns)
push!(exprs,:(gtype_wrapper_cache[:GObject] = GObjectLeaf))
GI.all_interfaces!(exprs,exports,ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs, ns;skiplist=skiplist,object_skiplist=[:BindingGroup,:SignalGroup,:Object])

push!(exprs,exports)

Expand Down Expand Up @@ -74,7 +75,7 @@ skiplist=vcat(handled_list,[:enum_complete_type_info,:enum_register_static,:flag
:flags_register_static,:param_type_register_static,:signal_accumulator_first_wins,
:signal_accumulator_true_handled,:signal_connect_closure,:signal_connect_closure_by_id,
:signal_handler_find,:signal_handlers_block_matched,:signal_handlers_disconnect_matched,
:signal_handlers_unblock_matched,:signal_override_class_closure,:signal_query,
:signal_handlers_unblock_matched,:signal_override_class_closure,
:source_set_closure,:source_set_dummy_callback,:type_add_interface_static,
:type_check_instance,:type_check_instance_is_a,:type_check_instance_is_fundamentally_a,
:type_default_interface_unref,:type_free_instance,
Expand Down
1 change: 1 addition & 0 deletions gen/gen_gsk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GI.append_struc_docs!(exprs, "gsk4", d, c, ns)
c = GI.all_objects!(exprs,exports,ns,output_cache_define=false,output_cache_init=false)
GI.append_object_docs!(exprs, "gsk4", d, c, ns)
GI.all_interfaces!(exprs,exports,ns)
GI.all_object_signals!(exprs,ns)

push!(exprs,exports)

Expand Down
1 change: 1 addition & 0 deletions gen/gen_gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ GI.all_interfaces!(exprs,exports,ns;exclude_deprecated=false)
c = GI.all_objects!(exprs,exports,ns,exclude_deprecated=false,skiplist=object_skiplist,constructor_skiplist=[:new_from_resource,:new_with_mnemonic,:new_with_text,:new_with_entry,:new_with_model_and_entry,:new_for_resource,:new_from_icon_name],output_cache_define=false,output_cache_init=false)
GI.append_object_docs!(exprs, "gtk4", d, c, ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs,ns;skiplist=skiplist,object_skiplist=object_skiplist,exclude_deprecated=false)

push!(exprs,exports)

Expand Down
1 change: 1 addition & 0 deletions gen/gen_pango.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct_skiplist,c = GI.all_struct_exprs!(exprs,exports,ns;excludelist=struct_ski
GI.all_objects!(exprs,exports,ns)
GI.all_interfaces!(exprs,exports,ns)
GI.all_callbacks!(exprs, exports, ns)
GI.all_object_signals!(exprs,ns)

push!(exprs,exports)

Expand Down
Loading

0 comments on commit 8eca099

Please sign in to comment.