1// Package gobject was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gobject
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// The type of the @complete_interface_info function of #GTypePluginClass.
15type TypePluginCompleteInterfaceInfo func(uintptr, types.GType, types.GType, *InterfaceInfo)
16
17// The type of the @complete_type_info function of #GTypePluginClass.
18type TypePluginCompleteTypeInfo func(uintptr, types.GType, *TypeInfo, *TypeValueTable)
19
20// The type of the @unuse_plugin function of #GTypePluginClass.
21type TypePluginUnuse func(uintptr)
22
23// The type of the @use_plugin function of #GTypePluginClass, which gets called
24// to increase the use count of @plugin.
25type TypePluginUse func(uintptr)
26
27// The #GTypePlugin interface is used by the type system in order to handle
28// the lifecycle of dynamically loaded types.
29type TypePluginClass struct {
30 _ structs.HostLayout
31
32 BaseIface uintptr
33
34 UsePlugin TypePluginUse
35
36 UnusePlugin TypePluginUnuse
37
38 CompleteTypeInfo TypePluginCompleteTypeInfo
39
40 CompleteInterfaceInfo TypePluginCompleteInterfaceInfo
41}
42
43func (x *TypePluginClass) GoPointer() uintptr {
44 return uintptr(unsafe.Pointer(x))
45}
46
47// An interface that handles the lifecycle of dynamically loaded types.
48//
49// The GObject type system supports dynamic loading of types.
50// It goes as follows:
51//
52// 1. The type is initially introduced (usually upon loading the module
53// the first time, or by your main application that knows what modules
54// introduces what types), like this:
55// ```c
56// new_type_id = g_type_register_dynamic (parent_type_id,
57// "TypeName",
58// new_type_plugin,
59// type_flags);
60// ```
61// where `new_type_plugin` is an implementation of the
62// `GTypePlugin` interface.
63//
64// 2. The type's implementation is referenced, e.g. through
65// [func@GObject.TypeClass.ref] or through [func@GObject.type_create_instance]
66// (this is being called by [ctor@GObject.Object.new]) or through one of the above
67// done on a type derived from `new_type_id`.
68//
69// 3. This causes the type system to load the type's implementation by calling
70// [method@GObject.TypePlugin.use] and [method@GObject.TypePlugin.complete_type_info]
71// on `new_type_plugin`.
72//
73// 4. At some point the type's implementation isn't required anymore, e.g. after
74// [method@GObject.TypeClass.unref] or [func@GObject.type_free_instance]
75// (called when the reference count of an instance drops to zero).
76//
77// 5. This causes the type system to throw away the information retrieved
78// from [method@GObject.TypePlugin.complete_type_info] and then it calls
79// [method@GObject.TypePlugin.unuse] on `new_type_plugin`.
80//
81// 6. Things may repeat from the second step.
82//
83// So basically, you need to implement a `GTypePlugin` type that
84// carries a use_count, once use_count goes from zero to one, you need
85// to load the implementation to successfully handle the upcoming
86// [method@GObject.TypePlugin.complete_type_info] call. Later, maybe after
87// succeeding use/unuse calls, once use_count drops to zero, you can
88// unload the implementation again. The type system makes sure to call
89// [method@GObject.TypePlugin.use] and [method@GObject.TypePlugin.complete_type_info]
90// again when the type is needed again.
91//
92// [class@GObject.TypeModule] is an implementation of `GTypePlugin` that
93// already implements most of this except for the actual module loading and
94// unloading. It even handles multiple registered types per module.
95type TypePlugin interface {
96 GoPointer() uintptr
97 SetGoPointer(uintptr)
98 CompleteInterfaceInfo(InstanceTypeVar types.GType, InterfaceTypeVar types.GType, InfoVar *InterfaceInfo)
99 CompleteTypeInfo(GTypeVar types.GType, InfoVar *TypeInfo, ValueTableVar *TypeValueTable)
100 Unuse()
101 Use()
102}
103
104var xTypePluginGLibType func() types.GType
105
106func TypePluginGLibType() types.GType {
107 return xTypePluginGLibType()
108}
109
110type TypePluginBase struct {
111 Ptr uintptr
112}
113
114func (x *TypePluginBase) GoPointer() uintptr {
115 if x == nil {
116 return 0
117 }
118 return x.Ptr
119}
120
121func (x *TypePluginBase) SetGoPointer(ptr uintptr) {
122 x.Ptr = ptr
123}
124
125// Calls the @complete_interface_info function from the
126// #GTypePluginClass of @plugin. There should be no need to use this
127// function outside of the GObject type system itself.
128func (x *TypePluginBase) CompleteInterfaceInfo(InstanceTypeVar types.GType, InterfaceTypeVar types.GType, InfoVar *InterfaceInfo) {
129
130 XGTypePluginCompleteInterfaceInfo(x.GoPointer(), InstanceTypeVar, InterfaceTypeVar, InfoVar)
131
132}
133
134// Calls the @complete_type_info function from the #GTypePluginClass of @plugin.
135// There should be no need to use this function outside of the GObject
136// type system itself.
137func (x *TypePluginBase) CompleteTypeInfo(GTypeVar types.GType, InfoVar *TypeInfo, ValueTableVar *TypeValueTable) {
138
139 XGTypePluginCompleteTypeInfo(x.GoPointer(), GTypeVar, InfoVar, ValueTableVar)
140
141}
142
143// Calls the @unuse_plugin function from the #GTypePluginClass of
144// @plugin. There should be no need to use this function outside of
145// the GObject type system itself.
146func (x *TypePluginBase) Unuse() {
147
148 XGTypePluginUnuse(x.GoPointer())
149
150}
151
152// Calls the @use_plugin function from the #GTypePluginClass of
153// @plugin. There should be no need to use this function outside of
154// the GObject type system itself.
155func (x *TypePluginBase) Use() {
156
157 XGTypePluginUse(x.GoPointer())
158
159}
160
161var XGTypePluginCompleteInterfaceInfo func(uintptr, types.GType, types.GType, *InterfaceInfo)
162var XGTypePluginCompleteTypeInfo func(uintptr, types.GType, *TypeInfo, *TypeValueTable)
163var XGTypePluginUnuse func(uintptr)
164var XGTypePluginUse func(uintptr)
165
166func init() {
167 core.SetPackageName("GOBJECT", "gobject-2.0")
168 core.SetSharedLibraries("GOBJECT", []string{"libgobject-2.0.so.0"})
169 var libs []uintptr
170 for _, libPath := range core.GetPaths("GOBJECT") {
171 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
172 if err != nil {
173 panic(err)
174 }
175 libs = append(libs, lib)
176 }
177
178 core.PuregoSafeRegister(&xTypePluginGLibType, libs, "g_type_plugin_get_type")
179
180 core.PuregoSafeRegister(&XGTypePluginCompleteInterfaceInfo, libs, "g_type_plugin_complete_interface_info")
181 core.PuregoSafeRegister(&XGTypePluginCompleteTypeInfo, libs, "g_type_plugin_complete_type_info")
182 core.PuregoSafeRegister(&XGTypePluginUnuse, libs, "g_type_plugin_unuse")
183 core.PuregoSafeRegister(&XGTypePluginUse, libs, "g_type_plugin_use")
184
185}