// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://docs.gtk.org/gio/class.DBusServer.html).
pub type DBusServer

///|
pub(open) trait IDBusServer {
  fn as_dbus_server(Self) -> DBusServer
  fn get_client_address(Self) -> String = _
  fn get_flags(Self) -> DBusServerFlags = _
  fn get_guid(Self) -> String = _
  fn is_active(Self) -> Bool = _
  fn start(Self) -> Unit = _
  fn stop(Self) -> Unit = _
  fn connect_new_connection(Self, (DBusServer, DBusConnection) -> Bool) -> UInt64 = _
}

///|
pub impl IDBusServer for DBusServer with fn as_dbus_server(self) {
  self
}

///|
#borrow(address, guid, observer, cancellable, error)
extern "c" fn moonbit_g_dbus_server_new_sync(
  address : Bytes,
  flags : Int,
  guid : Bytes,
  observer : @glib.Nullable[DBusAuthObserver],
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusServer = "moonbit_g_dbus_server_new_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusServer.new_sync.html).
pub fn DBusServer::new_sync(
  address : String,
  flags : DBusServerFlags,
  guid : String,
  observer : &IDBusAuthObserver?,
  cancellable : &ICancellable?,
) -> DBusServer raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_server_new_sync(
    @encoding/utf8.encode(address),
    flags.to_int(),
    @encoding/utf8.encode(guid),
    match observer {
      Some(v) => @glib.Nullable::some(v.as_dbus_auth_observer())
      None => @glib.Nullable::null()
    },
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => result
  }
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_server_get_client_address(
  self_ : DBusServer,
) -> Bytes = "moonbit_g_dbus_server_get_client_address"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.get_client_address.html).
pub fn DBusServer::get_client_address(self : DBusServer) -> String {
  @encoding/utf8.decode_lossy(moonbit_g_dbus_server_get_client_address(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_server_get_flags(self_ : DBusServer) -> Int = "moonbit_g_dbus_server_get_flags"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.get_flags.html).
pub fn DBusServer::get_flags(self : DBusServer) -> DBusServerFlags {
  DBusServerFlags::from_int(moonbit_g_dbus_server_get_flags(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_server_get_guid(self_ : DBusServer) -> Bytes = "moonbit_g_dbus_server_get_guid"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.get_guid.html).
pub fn DBusServer::get_guid(self : DBusServer) -> String {
  @encoding/utf8.decode_lossy(moonbit_g_dbus_server_get_guid(self))
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.is_active.html).
#borrow(self)
pub extern "c" fn DBusServer::is_active(self : DBusServer) -> Bool = "moonbit_g_dbus_server_is_active"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.start.html).
#borrow(self)
pub extern "c" fn DBusServer::start(self : DBusServer) = "moonbit_g_dbus_server_start"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusServer.stop.html).
#borrow(self)
pub extern "c" fn DBusServer::stop(self : DBusServer) = "moonbit_g_dbus_server_stop"

///|
#borrow(instance)
extern "c" fn gd_bus_server_connect_new_connection(
  instance : DBusServer,
  function : FuncRef[
    (DBusServer, DBusConnection, (DBusServer, DBusConnection) -> Bool) -> Bool,
  ],
  closure : (DBusServer, DBusConnection) -> Bool,
) -> UInt64 = "moonbit_gd_bus_server_connect_new_connection"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/signal.DBusServer.new-connection.html).
pub fn DBusServer::connect_new_connection(
  self : DBusServer,
  f : (DBusServer, DBusConnection) -> Bool,
) -> UInt64 {
  gd_bus_server_connect_new_connection(
    self,
    fn(instance_, connection, f) { f(instance_, connection) },
    f,
  )
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_server_get_address(self_ : DBusServer) -> Bytes = "moonbit_gd_bus_server_get_address"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusServer.address.html).
pub fn DBusServer::get_address(self : DBusServer) -> String {
  @encoding/utf8.decode_lossy(moonbit_gd_bus_server_get_address(self))
}

///|
#borrow(self_)
extern "c" fn moonbit_gd_bus_server_get_authentication_observer(
  self_ : DBusServer,
) -> @glib.Nullable[DBusAuthObserver] = "moonbit_gd_bus_server_get_authentication_observer"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/property.DBusServer.authentication-observer.html).
pub fn DBusServer::get_authentication_observer(
  self : DBusServer,
) -> DBusAuthObserver? {
  moonbit_gd_bus_server_get_authentication_observer(self).to_option()
}

///|
impl IDBusServer with fn get_client_address(self) -> String {
  self.as_dbus_server().get_client_address()
}

///|
impl IDBusServer with fn get_flags(self) -> DBusServerFlags {
  self.as_dbus_server().get_flags()
}

///|
impl IDBusServer with fn get_guid(self) -> String {
  self.as_dbus_server().get_guid()
}

///|
impl IDBusServer with fn is_active(self) -> Bool {
  self.as_dbus_server().is_active()
}

///|
impl IDBusServer with fn start(self) -> Unit {
  self.as_dbus_server().start()
}

///|
impl IDBusServer with fn stop(self) -> Unit {
  self.as_dbus_server().stop()
}

///|
impl IDBusServer with fn connect_new_connection(self, f) -> UInt64 {
  self.as_dbus_server().connect_new_connection(f)
}

///|
pub fn DBusServer::as_gobject_object(self : DBusServer) -> @gobject.Object = "%identity"

///|
pub impl @gobject.IObject for DBusServer with fn as_object(self) {
  self.as_gobject_object()
}

///|
pub fn DBusServer::as_initable(self : DBusServer) -> Initable = "%identity"

///|
pub impl IInitable for DBusServer with fn as_initable(self) {
  self.as_initable()
}