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 "github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// `GDBusServer` is a helper for listening to and accepting D-Bus
16// connections. This can be used to create a new D-Bus server, allowing two
17// peers to use the D-Bus protocol for their own specialized communication.
18// A server instance provided in this way will not perform message routing or
19// implement the
20// [`org.freedesktop.DBus` interface](https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-messages).
21//
22// To just export an object on a well-known name on a message bus, such as the
23// session or system bus, you should instead use [func@Gio.bus_own_name].
24//
25// An example of peer-to-peer communication with GDBus can be found
26// in [gdbus-example-peer.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-peer.c).
27//
28// Note that a minimal `GDBusServer` will accept connections from any
29// peer. In many use-cases it will be necessary to add a
30// [class@Gio.DBusAuthObserver] that only accepts connections that have
31// successfully authenticated as the same user that is running the
32// `GDBusServer`. Since GLib 2.68 this can be achieved more simply by passing
33// the `G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` flag to the
34// server.
35type DBusServer struct {
36 gobject.Object
37}
38
39var xDBusServerGLibType func() types.GType
40
41func DBusServerGLibType() types.GType {
42 return xDBusServerGLibType()
43}
44
45func DBusServerNewFromInternalPtr(ptr uintptr) *DBusServer {
46 cls := &DBusServer{}
47 cls.Ptr = ptr
48 return cls
49}
50
51var xNewDBusServerSync func(string, DBusServerFlags, string, uintptr, uintptr, **glib.Error) uintptr
52
53// Creates a new D-Bus server that listens on the first address in
54// @address that works.
55//
56// Once constructed, you can use g_dbus_server_get_client_address() to
57// get a D-Bus address string that clients can use to connect.
58//
59// To have control over the available authentication mechanisms and
60// the users that are authorized to connect, it is strongly recommended
61// to provide a non-%NULL #GDBusAuthObserver.
62//
63// Connect to the #GDBusServer::new-connection signal to handle
64// incoming connections.
65//
66// The returned #GDBusServer isn't active - you have to start it with
67// g_dbus_server_start().
68//
69// #GDBusServer is used in this [example](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gdbus-example-peer.c).
70//
71// This is a synchronous failable constructor. There is currently no
72// asynchronous version.
73func NewDBusServerSync(AddressVar string, FlagsVar DBusServerFlags, GuidVar string, ObserverVar *DBusAuthObserver, CancellableVar *Cancellable) (*DBusServer, error) {
74 var cls *DBusServer
75 var cerr *glib.Error
76
77 cret := xNewDBusServerSync(AddressVar, FlagsVar, GuidVar, ObserverVar.GoPointer(), CancellableVar.GoPointer(), &cerr)
78
79 if cret == 0 {
80 return nil, cerr
81 }
82 cls = &DBusServer{}
83 cls.Ptr = cret
84 if cerr == nil {
85 return cls, nil
86 }
87 return cls, cerr
88
89}
90
91var xDBusServerGetClientAddress func(uintptr) string
92
93// Gets a
94// [D-Bus address](https://dbus.freedesktop.org/doc/dbus-specification.html#addresses)
95// string that can be used by clients to connect to @server.
96//
97// This is valid and non-empty if initializing the #GDBusServer succeeded.
98func (x *DBusServer) GetClientAddress() string {
99
100 cret := xDBusServerGetClientAddress(x.GoPointer())
101 return cret
102}
103
104var xDBusServerGetFlags func(uintptr) DBusServerFlags
105
106// Gets the flags for @server.
107func (x *DBusServer) GetFlags() DBusServerFlags {
108
109 cret := xDBusServerGetFlags(x.GoPointer())
110 return cret
111}
112
113var xDBusServerGetGuid func(uintptr) string
114
115// Gets the GUID for @server, as provided to g_dbus_server_new_sync().
116func (x *DBusServer) GetGuid() string {
117
118 cret := xDBusServerGetGuid(x.GoPointer())
119 return cret
120}
121
122var xDBusServerIsActive func(uintptr) bool
123
124// Gets whether @server is active.
125func (x *DBusServer) IsActive() bool {
126
127 cret := xDBusServerIsActive(x.GoPointer())
128 return cret
129}
130
131var xDBusServerStart func(uintptr)
132
133// Starts @server.
134func (x *DBusServer) Start() {
135
136 xDBusServerStart(x.GoPointer())
137
138}
139
140var xDBusServerStop func(uintptr)
141
142// Stops @server.
143func (x *DBusServer) Stop() {
144
145 xDBusServerStop(x.GoPointer())
146
147}
148
149func (c *DBusServer) GoPointer() uintptr {
150 if c == nil {
151 return 0
152 }
153 return c.Ptr
154}
155
156func (c *DBusServer) SetGoPointer(ptr uintptr) {
157 c.Ptr = ptr
158}
159
160// GetPropertyActive gets the "active" property.
161// Whether the server is currently active.
162func (x *DBusServer) GetPropertyActive() bool {
163 var v gobject.Value
164 x.GetProperty("active", &v)
165 return v.GetBoolean()
166}
167
168// SetPropertyAddress sets the "address" property.
169// The D-Bus address to listen on.
170func (x *DBusServer) SetPropertyAddress(value string) {
171 var v gobject.Value
172 v.Init(gobject.TypeStringVal)
173 v.SetString(&value)
174 x.SetProperty("address", &v)
175}
176
177// GetPropertyAddress gets the "address" property.
178// The D-Bus address to listen on.
179func (x *DBusServer) GetPropertyAddress() string {
180 var v gobject.Value
181 x.GetProperty("address", &v)
182 return v.GetString()
183}
184
185// GetPropertyClientAddress gets the "client-address" property.
186// The D-Bus address that clients can use.
187func (x *DBusServer) GetPropertyClientAddress() string {
188 var v gobject.Value
189 x.GetProperty("client-address", &v)
190 return v.GetString()
191}
192
193// SetPropertyGuid sets the "guid" property.
194// The GUID of the server.
195//
196// See #GDBusConnection:guid for more details.
197func (x *DBusServer) SetPropertyGuid(value string) {
198 var v gobject.Value
199 v.Init(gobject.TypeStringVal)
200 v.SetString(&value)
201 x.SetProperty("guid", &v)
202}
203
204// GetPropertyGuid gets the "guid" property.
205// The GUID of the server.
206//
207// See #GDBusConnection:guid for more details.
208func (x *DBusServer) GetPropertyGuid() string {
209 var v gobject.Value
210 x.GetProperty("guid", &v)
211 return v.GetString()
212}
213
214// Emitted when a new authenticated connection has been made. Use
215// g_dbus_connection_get_peer_credentials() to figure out what
216// identity (if any), was authenticated.
217//
218// If you want to accept the connection, take a reference to the
219// @connection object and return %TRUE. When you are done with the
220// connection call g_dbus_connection_close() and give up your
221// reference. Note that the other peer may disconnect at any time -
222// a typical thing to do when accepting a connection is to listen to
223// the #GDBusConnection::closed signal.
224//
225// If #GDBusServer:flags contains %G_DBUS_SERVER_FLAGS_RUN_IN_THREAD
226// then the signal is emitted in a new thread dedicated to the
227// connection. Otherwise the signal is emitted in the thread-default
228// main context (see [method@GLib.MainContext.push_thread_default])
229// of the thread that @server was constructed in.
230//
231// You are guaranteed that signal handlers for this signal runs
232// before incoming messages on @connection are processed. This means
233// that it's suitable to call g_dbus_connection_register_object() or
234// similar from the signal handler.
235func (x *DBusServer) ConnectNewConnection(cb *func(DBusServer, uintptr) bool) uint {
236 cbPtr := uintptr(unsafe.Pointer(cb))
237 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
238 handlerID := gobject.SignalConnect(x.GoPointer(), "new-connection", cbRefPtr)
239 glib.SaveHandlerMapping(handlerID, cbPtr)
240 return handlerID
241 }
242
243 fcb := func(clsPtr uintptr, ConnectionVarp uintptr) bool {
244 fa := DBusServer{}
245 fa.Ptr = clsPtr
246 cbFn := *cb
247
248 return cbFn(fa, ConnectionVarp)
249
250 }
251 cbRefPtr := purego.NewCallback(fcb)
252 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
253 handlerID := gobject.SignalConnect(x.GoPointer(), "new-connection", cbRefPtr)
254 glib.SaveHandlerMapping(handlerID, cbPtr)
255 return handlerID
256}
257
258// Initializes the object implementing the interface.
259//
260// This method is intended for language bindings. If writing in C,
261// g_initable_new() should typically be used instead.
262//
263// The object must be initialized before any real use after initial
264// construction, either with this function or g_async_initable_init_async().
265//
266// Implementations may also support cancellation. If @cancellable is not %NULL,
267// then initialization can be cancelled by triggering the cancellable object
268// from another thread. If the operation was cancelled, the error
269// %G_IO_ERROR_CANCELLED will be returned. If @cancellable is not %NULL and
270// the object doesn't support cancellable initialization the error
271// %G_IO_ERROR_NOT_SUPPORTED will be returned.
272//
273// If the object is not initialized, or initialization returns with an
274// error, then all operations on the object except g_object_ref() and
275// g_object_unref() are considered to be invalid, and have undefined
276// behaviour. See the [description][iface@Gio.Initable#description] for more details.
277//
278// Callers should not assume that a class which implements #GInitable can be
279// initialized multiple times, unless the class explicitly documents itself as
280// supporting this. Generally, a class’ implementation of init() can assume
281// (and assert) that it will only be called once. Previously, this documentation
282// recommended all #GInitable implementations should be idempotent; that
283// recommendation was relaxed in GLib 2.54.
284//
285// If a class explicitly supports being initialized multiple times, it is
286// recommended that the method is idempotent: multiple calls with the same
287// arguments should return the same results. Only the first call initializes
288// the object; further calls return the result of the first call.
289//
290// One reason why a class might need to support idempotent initialization is if
291// it is designed to be used via the singleton pattern, with a
292// #GObjectClass.constructor that sometimes returns an existing instance.
293// In this pattern, a caller would expect to be able to call g_initable_init()
294// on the result of g_object_new(), regardless of whether it is in fact a new
295// instance.
296func (x *DBusServer) Init(CancellableVar *Cancellable) (bool, error) {
297 var cerr *glib.Error
298
299 cret := XGInitableInit(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
300 if cerr == nil {
301 return cret, nil
302 }
303 return cret, cerr
304
305}
306
307func init() {
308 core.SetPackageName("GIO", "gio-2.0")
309 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
310 var libs []uintptr
311 for _, libPath := range core.GetPaths("GIO") {
312 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
313 if err != nil {
314 panic(err)
315 }
316 libs = append(libs, lib)
317 }
318
319 core.PuregoSafeRegister(&xDBusServerGLibType, libs, "g_dbus_server_get_type")
320
321 core.PuregoSafeRegister(&xNewDBusServerSync, libs, "g_dbus_server_new_sync")
322
323 core.PuregoSafeRegister(&xDBusServerGetClientAddress, libs, "g_dbus_server_get_client_address")
324 core.PuregoSafeRegister(&xDBusServerGetFlags, libs, "g_dbus_server_get_flags")
325 core.PuregoSafeRegister(&xDBusServerGetGuid, libs, "g_dbus_server_get_guid")
326 core.PuregoSafeRegister(&xDBusServerIsActive, libs, "g_dbus_server_is_active")
327 core.PuregoSafeRegister(&xDBusServerStart, libs, "g_dbus_server_start")
328 core.PuregoSafeRegister(&xDBusServerStop, libs, "g_dbus_server_stop")
329
330}