1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/glib"
11 "github.com/bnema/puregotk/v4/gobject"
12)
13
14// Invoked when a connection to a message bus has been obtained.
15type BusAcquiredCallback func(uintptr, string, uintptr)
16
17// Invoked when the name is acquired.
18type BusNameAcquiredCallback func(uintptr, string, uintptr)
19
20// Invoked when the name is lost or @connection has been closed.
21type BusNameLostCallback func(uintptr, string, uintptr)
22
23var xBusOwnName func(BusType, string, BusNameOwnerFlags, uintptr, uintptr, uintptr, uintptr, uintptr) uint
24
25// Requests ownership of @name on the bus specified by @bus_type.
26//
27// It asynchronously calls @name_acquired_handler and @name_lost_handler when
28// the name is acquired and lost, respectively.
29//
30// Callbacks will be invoked in the thread-default
31// main context (see [method@GLib.MainContext.push_thread_default])
32// of the thread you are calling this function from.
33//
34// You are guaranteed that one of the @name_acquired_handler and @name_lost_handler
35// callbacks will be invoked after calling this function — there are three
36// possible cases:
37//
38// - @name_lost_handler with a `NULL` connection (if a connection to the bus
39// can’t be made).
40// - @bus_acquired_handler then @name_lost_handler (if the name can’t be
41// obtained).
42// - @bus_acquired_handler then @name_acquired_handler (if the name was
43// obtained).
44//
45// When you are done owning the name, call [func@Gio.bus_unown_name] with the
46// owner ID this function returns.
47//
48// If the name is acquired or lost (for example another application
49// could acquire the name if you allow replacement or the application
50// currently owning the name exits), the handlers are also invoked.
51// If the [class@Gio.DBusConnection] that is used for attempting to own the name
52// closes, then @name_lost_handler is invoked since it is no longer
53// possible for other processes to access the process.
54//
55// You cannot use [func@Gio.bus_own_name] several times for the same name (unless
56// interleaved with calls to [func@Gio.bus_unown_name]) — only the first call
57// will work.
58//
59// Another guarantee is that invocations of @name_acquired_handler
60// and @name_lost_handler are guaranteed to alternate; that
61// is, if @name_acquired_handler is invoked then you are
62// guaranteed that the next time one of the handlers is invoked, it
63// will be @name_lost_handler. The reverse is also true.
64//
65// If you plan on exporting objects (using, for example,
66// [method@Gio.DBusConnection.register_object]), note that it is generally too late
67// to export the objects in @name_acquired_handler. Instead, you can do this
68// in @bus_acquired_handler since you are guaranteed that this will run
69// before @name is requested from the bus.
70//
71// This behavior makes it very simple to write applications that want
72// to [own names](dbus-name-owning.html#d-bus-name-owning) and export objects.
73// Simply register objects to be exported in @bus_acquired_handler and
74// unregister the objects (if any) in @name_lost_handler.
75func BusOwnName(BusTypeVar BusType, NameVar string, FlagsVar BusNameOwnerFlags, BusAcquiredHandlerVar *BusAcquiredCallback, NameAcquiredHandlerVar *BusNameAcquiredCallback, NameLostHandlerVar *BusNameLostCallback, UserDataVar uintptr, UserDataFreeFuncVar *glib.DestroyNotify) uint {
76
77 var BusAcquiredHandlerVarRef uintptr
78 if BusAcquiredHandlerVar != nil {
79 BusAcquiredHandlerVarPtr := uintptr(unsafe.Pointer(BusAcquiredHandlerVar))
80 if cbRefPtr, ok := glib.GetCallback(BusAcquiredHandlerVarPtr); ok {
81 BusAcquiredHandlerVarRef = cbRefPtr
82 } else {
83 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
84 cbFn := *BusAcquiredHandlerVar
85 cbFn(arg0, core.GoString(arg1), arg2)
86 }
87 BusAcquiredHandlerVarRef = purego.NewCallback(fcb)
88 glib.SaveCallbackWithClosure(BusAcquiredHandlerVarPtr, BusAcquiredHandlerVarRef, BusAcquiredHandlerVar)
89 }
90 }
91
92 var NameAcquiredHandlerVarRef uintptr
93 if NameAcquiredHandlerVar != nil {
94 NameAcquiredHandlerVarPtr := uintptr(unsafe.Pointer(NameAcquiredHandlerVar))
95 if cbRefPtr, ok := glib.GetCallback(NameAcquiredHandlerVarPtr); ok {
96 NameAcquiredHandlerVarRef = cbRefPtr
97 } else {
98 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
99 cbFn := *NameAcquiredHandlerVar
100 cbFn(arg0, core.GoString(arg1), arg2)
101 }
102 NameAcquiredHandlerVarRef = purego.NewCallback(fcb)
103 glib.SaveCallbackWithClosure(NameAcquiredHandlerVarPtr, NameAcquiredHandlerVarRef, NameAcquiredHandlerVar)
104 }
105 }
106
107 var NameLostHandlerVarRef uintptr
108 if NameLostHandlerVar != nil {
109 NameLostHandlerVarPtr := uintptr(unsafe.Pointer(NameLostHandlerVar))
110 if cbRefPtr, ok := glib.GetCallback(NameLostHandlerVarPtr); ok {
111 NameLostHandlerVarRef = cbRefPtr
112 } else {
113 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
114 cbFn := *NameLostHandlerVar
115 cbFn(arg0, core.GoString(arg1), arg2)
116 }
117 NameLostHandlerVarRef = purego.NewCallback(fcb)
118 glib.SaveCallbackWithClosure(NameLostHandlerVarPtr, NameLostHandlerVarRef, NameLostHandlerVar)
119 }
120 }
121
122 var UserDataFreeFuncVarRef uintptr
123 if UserDataFreeFuncVar != nil {
124 UserDataFreeFuncVarPtr := uintptr(unsafe.Pointer(UserDataFreeFuncVar))
125 if cbRefPtr, ok := glib.GetCallback(UserDataFreeFuncVarPtr); ok {
126 UserDataFreeFuncVarRef = cbRefPtr
127 } else {
128 fcb := func(arg0 uintptr) {
129 cbFn := *UserDataFreeFuncVar
130 cbFn(arg0)
131 }
132 UserDataFreeFuncVarRef = purego.NewCallback(fcb)
133 glib.SaveCallbackWithClosure(UserDataFreeFuncVarPtr, UserDataFreeFuncVarRef, UserDataFreeFuncVar)
134 }
135 }
136
137 cret := xBusOwnName(BusTypeVar, NameVar, FlagsVar, BusAcquiredHandlerVarRef, NameAcquiredHandlerVarRef, NameLostHandlerVarRef, UserDataVar, UserDataFreeFuncVarRef)
138 return cret
139}
140
141var xBusOwnNameOnConnection func(uintptr, string, BusNameOwnerFlags, uintptr, uintptr, uintptr, uintptr) uint
142
143// Like [func@Gio.bus_own_name] but takes a [class@Gio.DBusConnection] instead
144// of a [enum@Gio.BusType].
145func BusOwnNameOnConnection(ConnectionVar *DBusConnection, NameVar string, FlagsVar BusNameOwnerFlags, NameAcquiredHandlerVar *BusNameAcquiredCallback, NameLostHandlerVar *BusNameLostCallback, UserDataVar uintptr, UserDataFreeFuncVar *glib.DestroyNotify) uint {
146
147 var NameAcquiredHandlerVarRef uintptr
148 if NameAcquiredHandlerVar != nil {
149 NameAcquiredHandlerVarPtr := uintptr(unsafe.Pointer(NameAcquiredHandlerVar))
150 if cbRefPtr, ok := glib.GetCallback(NameAcquiredHandlerVarPtr); ok {
151 NameAcquiredHandlerVarRef = cbRefPtr
152 } else {
153 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
154 cbFn := *NameAcquiredHandlerVar
155 cbFn(arg0, core.GoString(arg1), arg2)
156 }
157 NameAcquiredHandlerVarRef = purego.NewCallback(fcb)
158 glib.SaveCallbackWithClosure(NameAcquiredHandlerVarPtr, NameAcquiredHandlerVarRef, NameAcquiredHandlerVar)
159 }
160 }
161
162 var NameLostHandlerVarRef uintptr
163 if NameLostHandlerVar != nil {
164 NameLostHandlerVarPtr := uintptr(unsafe.Pointer(NameLostHandlerVar))
165 if cbRefPtr, ok := glib.GetCallback(NameLostHandlerVarPtr); ok {
166 NameLostHandlerVarRef = cbRefPtr
167 } else {
168 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
169 cbFn := *NameLostHandlerVar
170 cbFn(arg0, core.GoString(arg1), arg2)
171 }
172 NameLostHandlerVarRef = purego.NewCallback(fcb)
173 glib.SaveCallbackWithClosure(NameLostHandlerVarPtr, NameLostHandlerVarRef, NameLostHandlerVar)
174 }
175 }
176
177 var UserDataFreeFuncVarRef uintptr
178 if UserDataFreeFuncVar != nil {
179 UserDataFreeFuncVarPtr := uintptr(unsafe.Pointer(UserDataFreeFuncVar))
180 if cbRefPtr, ok := glib.GetCallback(UserDataFreeFuncVarPtr); ok {
181 UserDataFreeFuncVarRef = cbRefPtr
182 } else {
183 fcb := func(arg0 uintptr) {
184 cbFn := *UserDataFreeFuncVar
185 cbFn(arg0)
186 }
187 UserDataFreeFuncVarRef = purego.NewCallback(fcb)
188 glib.SaveCallbackWithClosure(UserDataFreeFuncVarPtr, UserDataFreeFuncVarRef, UserDataFreeFuncVar)
189 }
190 }
191
192 cret := xBusOwnNameOnConnection(ConnectionVar.GoPointer(), NameVar, FlagsVar, NameAcquiredHandlerVarRef, NameLostHandlerVarRef, UserDataVar, UserDataFreeFuncVarRef)
193 return cret
194}
195
196var xBusOwnNameOnConnectionWithClosures func(uintptr, string, BusNameOwnerFlags, *gobject.Closure, *gobject.Closure) uint
197
198// Version of [func@Gio.bus_own_name_on_connection] using closures instead of
199// callbacks for easier binding in other languages.
200func BusOwnNameOnConnectionWithClosures(ConnectionVar *DBusConnection, NameVar string, FlagsVar BusNameOwnerFlags, NameAcquiredClosureVar *gobject.Closure, NameLostClosureVar *gobject.Closure) uint {
201
202 cret := xBusOwnNameOnConnectionWithClosures(ConnectionVar.GoPointer(), NameVar, FlagsVar, NameAcquiredClosureVar, NameLostClosureVar)
203 return cret
204}
205
206var xBusOwnNameWithClosures func(BusType, string, BusNameOwnerFlags, *gobject.Closure, *gobject.Closure, *gobject.Closure) uint
207
208// Version of [func@Gio.bus_own_name using closures instead of callbacks for
209// easier binding in other languages.
210func BusOwnNameWithClosures(BusTypeVar BusType, NameVar string, FlagsVar BusNameOwnerFlags, BusAcquiredClosureVar *gobject.Closure, NameAcquiredClosureVar *gobject.Closure, NameLostClosureVar *gobject.Closure) uint {
211
212 cret := xBusOwnNameWithClosures(BusTypeVar, NameVar, FlagsVar, BusAcquiredClosureVar, NameAcquiredClosureVar, NameLostClosureVar)
213 return cret
214}
215
216var xBusUnownName func(uint)
217
218// Stops owning a name.
219//
220// Note that there may still be D-Bus traffic to process (relating to owning
221// and unowning the name) in the current thread-default
222// [struct@GLib.MainContext] after this function has returned. You should
223// continue to iterate the [struct@GLib.MainContext] until the
224// [callback@GLib.DestroyNotify] function passed to [func@Gio.bus_own_name] is
225// called, in order to avoid memory leaks through callbacks queued on the
226// [struct@GLib.MainContext] after it’s stopped being iterated.
227func BusUnownName(OwnerIdVar uint) {
228
229 xBusUnownName(OwnerIdVar)
230
231}
232
233func init() {
234 core.SetPackageName("GIO", "gio-2.0")
235 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
236 var libs []uintptr
237 for _, libPath := range core.GetPaths("GIO") {
238 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
239 if err != nil {
240 panic(err)
241 }
242 libs = append(libs, lib)
243 }
244
245 core.PuregoSafeRegister(&xBusOwnName, libs, "g_bus_own_name")
246 core.PuregoSafeRegister(&xBusOwnNameOnConnection, libs, "g_bus_own_name_on_connection")
247 core.PuregoSafeRegister(&xBusOwnNameOnConnectionWithClosures, libs, "g_bus_own_name_on_connection_with_closures")
248 core.PuregoSafeRegister(&xBusOwnNameWithClosures, libs, "g_bus_own_name_with_closures")
249 core.PuregoSafeRegister(&xBusUnownName, libs, "g_bus_unown_name")
250
251}