// GENERATED — DO NOT EDIT

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

///|
pub(open) trait IDBusConnection {
  fn as_dbus_connection(Self) -> DBusConnection
  fn call_finish(Self, &IAsyncResult) -> @glib.Variant raise @glib.Error_ = _
  fn close_sync(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn emit_signal(Self, String?, String, String, String, &@glib.IVariant?) -> Bool raise @glib.Error_ = _
  fn export_action_group(Self, String, &IActionGroup) -> UInt raise @glib.Error_ = _
  fn export_menu_model(Self, String, &IMenuModel) -> UInt raise @glib.Error_ = _
  fn flush_sync(Self, &ICancellable?) -> Bool raise @glib.Error_ = _
  fn get_capabilities(Self) -> DBusCapabilityFlags = _
  fn get_exit_on_close(Self) -> Bool = _
  fn get_flags(Self) -> DBusConnectionFlags = _
  fn get_guid(Self) -> String = _
  fn get_last_serial(Self) -> UInt = _
  fn get_peer_credentials(Self) -> Credentials? = _
  fn get_stream(Self) -> IOStream = _
  fn get_unique_name(Self) -> String? = _
  fn is_closed(Self) -> Bool = _
  fn remove_filter(Self, UInt) -> Unit = _
  fn send_message(Self, &IDBusMessage, DBusSendMessageFlags) -> (Bool, UInt) raise @glib.Error_ = _
  fn send_message_with_reply_finish(Self, &IAsyncResult) -> DBusMessage raise @glib.Error_ = _
  fn send_message_with_reply_sync(
    Self,
    &IDBusMessage,
    DBusSendMessageFlags,
    Int,
    &ICancellable?,
  ) -> (DBusMessage, UInt) raise @glib.Error_ = _
  fn set_exit_on_close(Self, Bool) -> Unit = _
  fn signal_unsubscribe(Self, UInt) -> Unit = _
  fn start_message_processing(Self) -> Unit = _
  fn unexport_action_group(Self, UInt) -> Unit = _
  fn unexport_menu_model(Self, UInt) -> Unit = _
  fn unregister_object(Self, UInt) -> Bool = _
  fn unregister_subtree(Self, UInt) -> Bool = _
  fn close(Self, &ICancellable?, (Result[Bool, @glib.Error_]) -> Unit) -> Unit = _
  fn flush(Self, &ICancellable?, (Result[Bool, @glib.Error_]) -> Unit) -> Unit = _
  fn signal_subscribe(
    Self,
    String?,
    String?,
    String?,
    String?,
    String?,
    DBusSignalFlags,
    (DBusConnection, String?, String, String, String, @glib.Variant) -> Unit,
  ) -> Unit = _
}

///|
pub impl IDBusConnection for DBusConnection with fn as_dbus_connection(self) {
  self
}

///|
#borrow(res, error)
extern "c" fn moonbit_g_dbus_connection_new_finish(
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusConnection = "moonbit_g_dbus_connection_new_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusConnection.new_finish.html).
pub fn DBusConnection::new_finish(
  res : &IAsyncResult,
) -> DBusConnection raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_new_finish(
    res.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => result
  }
}

///|
#borrow(res, error)
extern "c" fn moonbit_g_dbus_connection_new_for_address_finish(
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusConnection = "moonbit_g_dbus_connection_new_for_address_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusConnection.new_for_address_finish.html).
pub fn DBusConnection::new_for_address_finish(
  res : &IAsyncResult,
) -> DBusConnection raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_new_for_address_finish(
    res.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => result
  }
}

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusConnection.new_for_address_sync.html).
pub fn DBusConnection::new_for_address_sync(
  address : String,
  flags : DBusConnectionFlags,
  observer : &IDBusAuthObserver?,
  cancellable : &ICancellable?,
) -> DBusConnection raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_new_for_address_sync(
    @encoding/utf8.encode(address),
    flags.to_int(),
    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(stream, guid, observer, cancellable, error)
extern "c" fn moonbit_g_dbus_connection_new_sync(
  stream : IOStream,
  guid : @glib.Nullable[Bytes],
  flags : Int,
  observer : @glib.Nullable[DBusAuthObserver],
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusConnection = "moonbit_g_dbus_connection_new_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/ctor.DBusConnection.new_sync.html).
pub fn DBusConnection::new_sync(
  stream : &IIOStream,
  guid : String?,
  flags : DBusConnectionFlags,
  observer : &IDBusAuthObserver?,
  cancellable : &ICancellable?,
) -> DBusConnection raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_new_sync(
    stream.as_io_stream(),
    match guid {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    flags.to_int(),
    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_, res, error)
extern "c" fn moonbit_g_dbus_connection_call_finish(
  self_ : DBusConnection,
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Variant = "moonbit_g_dbus_connection_call_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.call_finish.html).
pub fn DBusConnection::call_finish(
  self : DBusConnection,
  res : &IAsyncResult,
) -> @glib.Variant raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_call_finish(
    self,
    res.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_dbus_connection_close_sync(
  self_ : DBusConnection,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_dbus_connection_close_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.close_sync.html).
pub fn DBusConnection::close_sync(
  self : DBusConnection,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_close_sync(
    self,
    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_, destination_bus_name, object_path, interface_name, signal_name, parameters, error)
extern "c" fn moonbit_g_dbus_connection_emit_signal(
  self_ : DBusConnection,
  destination_bus_name : @glib.Nullable[Bytes],
  object_path : Bytes,
  interface_name : Bytes,
  signal_name : Bytes,
  parameters : @glib.Nullable[@glib.Variant],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_dbus_connection_emit_signal"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.emit_signal.html).
pub fn DBusConnection::emit_signal(
  self : DBusConnection,
  destination_bus_name : String?,
  object_path : String,
  interface_name : String,
  signal_name : String,
  parameters : &@glib.IVariant?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_emit_signal(
    self,
    match destination_bus_name {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    @encoding/utf8.encode(object_path),
    @encoding/utf8.encode(interface_name),
    @encoding/utf8.encode(signal_name),
    match parameters {
      Some(v) => @glib.Nullable::some(v.as_variant())
      None => @glib.Nullable::null()
    },
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, object_path, action_group, error)
extern "c" fn moonbit_g_dbus_connection_export_action_group(
  self_ : DBusConnection,
  object_path : Bytes,
  action_group : ActionGroup,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt = "moonbit_g_dbus_connection_export_action_group"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.export_action_group.html).
pub fn DBusConnection::export_action_group(
  self : DBusConnection,
  object_path : String,
  action_group : &IActionGroup,
) -> UInt raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_export_action_group(
    self,
    @encoding/utf8.encode(object_path),
    action_group.as_action_group(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, object_path, menu, error)
extern "c" fn moonbit_g_dbus_connection_export_menu_model(
  self_ : DBusConnection,
  object_path : Bytes,
  menu : MenuModel,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> UInt = "moonbit_g_dbus_connection_export_menu_model"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.export_menu_model.html).
pub fn DBusConnection::export_menu_model(
  self : DBusConnection,
  object_path : String,
  menu : &IMenuModel,
) -> UInt raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_export_menu_model(
    self,
    @encoding/utf8.encode(object_path),
    menu.as_menu_model(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, cancellable, error)
extern "c" fn moonbit_g_dbus_connection_flush_sync(
  self_ : DBusConnection,
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_dbus_connection_flush_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.flush_sync.html).
pub fn DBusConnection::flush_sync(
  self : DBusConnection,
  cancellable : &ICancellable?,
) -> Bool raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_flush_sync(
    self,
    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_connection_get_capabilities(
  self_ : DBusConnection,
) -> Int = "moonbit_g_dbus_connection_get_capabilities"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.get_capabilities.html).
pub fn DBusConnection::get_capabilities(
  self : DBusConnection,
) -> DBusCapabilityFlags {
  DBusCapabilityFlags::from_int(
    moonbit_g_dbus_connection_get_capabilities(self),
  )
}

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

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_connection_get_flags(
  self_ : DBusConnection,
) -> Int = "moonbit_g_dbus_connection_get_flags"

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

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

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.get_last_serial.html).
#borrow(self)
pub extern "c" fn DBusConnection::get_last_serial(
  self : DBusConnection,
) -> UInt = "moonbit_g_dbus_connection_get_last_serial"

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_connection_get_peer_credentials(
  self_ : DBusConnection,
) -> @glib.Nullable[Credentials] = "moonbit_g_dbus_connection_get_peer_credentials"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.get_peer_credentials.html).
pub fn DBusConnection::get_peer_credentials(
  self : DBusConnection,
) -> Credentials? {
  let raw_result = moonbit_g_dbus_connection_get_peer_credentials(self)
  raw_result.to_option()
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.get_stream.html).
#borrow(self)
pub extern "c" fn DBusConnection::get_stream(self : DBusConnection) -> IOStream = "moonbit_g_dbus_connection_get_stream"

///|
#borrow(self_)
extern "c" fn moonbit_g_dbus_connection_get_unique_name(
  self_ : DBusConnection,
) -> @glib.Nullable[Bytes] = "moonbit_g_dbus_connection_get_unique_name"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.get_unique_name.html).
pub fn DBusConnection::get_unique_name(self : DBusConnection) -> String? {
  let result = moonbit_g_dbus_connection_get_unique_name(self)
  match result.to_option() {
    Some(bytes) => Some(@encoding/utf8.decode_lossy(bytes))
    None => None
  }
}

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

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.remove_filter.html).
#borrow(self)
pub extern "c" fn DBusConnection::remove_filter(
  self : DBusConnection,
  filter_id : UInt,
) = "moonbit_g_dbus_connection_remove_filter"

///|
#borrow(self_, message, out_serial, error)
extern "c" fn moonbit_g_dbus_connection_send_message(
  self_ : DBusConnection,
  message : DBusMessage,
  flags : Int,
  out_serial : Ref[UInt],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> Bool = "moonbit_g_dbus_connection_send_message"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.send_message.html).
pub fn DBusConnection::send_message(
  self : DBusConnection,
  message : &IDBusMessage,
  flags : DBusSendMessageFlags,
) -> (Bool, UInt) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let out_serial = Ref(0U)
  let result = moonbit_g_dbus_connection_send_message(
    self,
    message.as_dbus_message(),
    flags.to_int(),
    out_serial,
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  (result, out_serial.val)
}

///|
#borrow(self_, res, error)
extern "c" fn moonbit_g_dbus_connection_send_message_with_reply_finish(
  self_ : DBusConnection,
  res : AsyncResult,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusMessage = "moonbit_g_dbus_connection_send_message_with_reply_finish"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.send_message_with_reply_finish.html).
pub fn DBusConnection::send_message_with_reply_finish(
  self : DBusConnection,
  res : &IAsyncResult,
) -> DBusMessage raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_dbus_connection_send_message_with_reply_finish(
    self,
    res.as_async_result(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  result
}

///|
#borrow(self_, message, out_serial, cancellable, error)
extern "c" fn moonbit_g_dbus_connection_send_message_with_reply_sync(
  self_ : DBusConnection,
  message : DBusMessage,
  flags : Int,
  timeout_msec : Int,
  out_serial : Ref[UInt],
  cancellable : @glib.Nullable[Cancellable],
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> DBusMessage = "moonbit_g_dbus_connection_send_message_with_reply_sync"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.send_message_with_reply_sync.html).
pub fn DBusConnection::send_message_with_reply_sync(
  self : DBusConnection,
  message : &IDBusMessage,
  flags : DBusSendMessageFlags,
  timeout_msec : Int,
  cancellable : &ICancellable?,
) -> (DBusMessage, UInt) raise @glib.Error_ {
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let out_serial = Ref(0U)
  let result = moonbit_g_dbus_connection_send_message_with_reply_sync(
    self,
    message.as_dbus_message(),
    flags.to_int(),
    timeout_msec,
    out_serial,
    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, out_serial.val)
}

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.set_exit_on_close.html).
#borrow(self)
pub extern "c" fn DBusConnection::set_exit_on_close(
  self : DBusConnection,
  exit_on_close : Bool,
) = "moonbit_g_dbus_connection_set_exit_on_close"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.signal_unsubscribe.html).
#borrow(self)
pub extern "c" fn DBusConnection::signal_unsubscribe(
  self : DBusConnection,
  subscription_id : UInt,
) = "moonbit_g_dbus_connection_signal_unsubscribe"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.start_message_processing.html).
#borrow(self)
pub extern "c" fn DBusConnection::start_message_processing(
  self : DBusConnection,
) = "moonbit_g_dbus_connection_start_message_processing"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.unexport_action_group.html).
#borrow(self)
pub extern "c" fn DBusConnection::unexport_action_group(
  self : DBusConnection,
  export_id : UInt,
) = "moonbit_g_dbus_connection_unexport_action_group"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.unexport_menu_model.html).
#borrow(self)
pub extern "c" fn DBusConnection::unexport_menu_model(
  self : DBusConnection,
  export_id : UInt,
) = "moonbit_g_dbus_connection_unexport_menu_model"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.unregister_object.html).
#borrow(self)
pub extern "c" fn DBusConnection::unregister_object(
  self : DBusConnection,
  registration_id : UInt,
) -> Bool = "moonbit_g_dbus_connection_unregister_object"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.unregister_subtree.html).
#borrow(self)
pub extern "c" fn DBusConnection::unregister_subtree(
  self : DBusConnection,
  registration_id : UInt,
) -> Bool = "moonbit_g_dbus_connection_unregister_subtree"

///|
#borrow(self_, cancellable)
extern "c" fn g_dbus_connection_close(
  self_ : DBusConnection,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Bool,
      @glib.Nullable[@glib.Error_],
      (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_dbus_connection_close"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.close.html).
pub fn DBusConnection::close(
  self : DBusConnection,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_dbus_connection_close(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
#borrow(self_, cancellable)
extern "c" fn g_dbus_connection_flush(
  self_ : DBusConnection,
  cancellable : @glib.Nullable[Cancellable],
  function : FuncRef[
    (
      Bool,
      @glib.Nullable[@glib.Error_],
      (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
    ) -> Unit,
  ],
  closure : (Bool, @glib.Nullable[@glib.Error_]) -> Unit,
) = "moonbit_g_dbus_connection_flush"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.flush.html).
pub fn DBusConnection::flush(
  self : DBusConnection,
  cancellable : &ICancellable?,
  callback : (Result[Bool, @glib.Error_]) -> Unit,
) -> Unit {
  g_dbus_connection_flush(
    self,
    match cancellable {
      Some(v) => @glib.Nullable::some(v.as_cancellable())
      None => @glib.Nullable::null()
    },
    fn(result, error, f) { f(result, error) },
    fn(result, error) {
      match error.to_option() {
        Some(e) => callback(Err(e))
        None => callback(Ok(result))
      }
    },
  )
}

///|
#borrow(instance, sender, interface_name, member_, object_path, arg0)
extern "c" fn gd_bus_connection_signal_subscribe(
  instance : DBusConnection,
  sender : @glib.Nullable[Bytes],
  interface_name : @glib.Nullable[Bytes],
  member_ : @glib.Nullable[Bytes],
  object_path : @glib.Nullable[Bytes],
  arg0 : @glib.Nullable[Bytes],
  flags : Int,
  function : FuncRef[
    (
      DBusConnection,
      Bytes,
      Int,
      Bytes,
      Bytes,
      Bytes,
      @glib.Variant,
      (DBusConnection, String?, String, String, String, @glib.Variant) -> Unit,
    ) -> Unit,
  ],
  closure : (DBusConnection, String?, String, String, String, @glib.Variant) -> Unit,
) -> Unit = "moonbit_g_dbus_connection_signal_subscribe"

///|
/// [Upstream documentation](https://docs.gtk.org/gio/method.DBusConnection.signal_subscribe.html).
pub fn DBusConnection::signal_subscribe(
  self : DBusConnection,
  sender : String?,
  interface_name : String?,
  member_ : String?,
  object_path : String?,
  arg0 : String?,
  flags : DBusSignalFlags,
  callback : (DBusConnection, String?, String, String, String, @glib.Variant) -> Unit,
) -> Unit {
  gd_bus_connection_signal_subscribe(
    self,
    match sender {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    match interface_name {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    match member_ {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    match object_path {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    match arg0 {
      Some(s) => @glib.Nullable::some(@encoding/utf8.encode(s))
      None => @glib.Nullable::null()
    },
    flags.to_int(),
    fn(
      connection,
      sender_name,
      sender_name_has,
      object_path,
      interface_name,
      signal_name,
      parameters,
      f,
    ) {
      f(
        connection,
        if sender_name_has > 0 {
          Some(@encoding/utf8.decode_lossy(sender_name))
        } else {
          None
        },
        @encoding/utf8.decode_lossy(object_path),
        @encoding/utf8.decode_lossy(interface_name),
        @encoding/utf8.decode_lossy(signal_name),
        parameters,
      )
    },
    callback,
  )
}

///|
impl IDBusConnection with fn call_finish(self, res) -> @glib.Variant raise @glib.Error_ {
  self.as_dbus_connection().call_finish(res)
}

///|
impl IDBusConnection with fn close_sync(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_dbus_connection().close_sync(cancellable)
}

///|
impl IDBusConnection with fn emit_signal(
  self,
  destination_bus_name,
  object_path,
  interface_name,
  signal_name,
  parameters,
) -> Bool raise @glib.Error_ {
  self
  .as_dbus_connection()
  .emit_signal(
    destination_bus_name, object_path, interface_name, signal_name, parameters,
  )
}

///|
impl IDBusConnection with fn export_action_group(
  self,
  object_path,
  action_group,
) -> UInt raise @glib.Error_ {
  self.as_dbus_connection().export_action_group(object_path, action_group)
}

///|
impl IDBusConnection with fn export_menu_model(self, object_path, menu) -> UInt raise @glib.Error_ {
  self.as_dbus_connection().export_menu_model(object_path, menu)
}

///|
impl IDBusConnection with fn flush_sync(self, cancellable) -> Bool raise @glib.Error_ {
  self.as_dbus_connection().flush_sync(cancellable)
}

///|
impl IDBusConnection with fn get_capabilities(self) -> DBusCapabilityFlags {
  self.as_dbus_connection().get_capabilities()
}

///|
impl IDBusConnection with fn get_exit_on_close(self) -> Bool {
  self.as_dbus_connection().get_exit_on_close()
}

///|
impl IDBusConnection with fn get_flags(self) -> DBusConnectionFlags {
  self.as_dbus_connection().get_flags()
}

///|
impl IDBusConnection with fn get_guid(self) -> String {
  self.as_dbus_connection().get_guid()
}

///|
impl IDBusConnection with fn get_last_serial(self) -> UInt {
  self.as_dbus_connection().get_last_serial()
}

///|
impl IDBusConnection with fn get_peer_credentials(self) -> Credentials? {
  self.as_dbus_connection().get_peer_credentials()
}

///|
impl IDBusConnection with fn get_stream(self) -> IOStream {
  self.as_dbus_connection().get_stream()
}

///|
impl IDBusConnection with fn get_unique_name(self) -> String? {
  self.as_dbus_connection().get_unique_name()
}

///|
impl IDBusConnection with fn is_closed(self) -> Bool {
  self.as_dbus_connection().is_closed()
}

///|
impl IDBusConnection with fn remove_filter(self, filter_id) -> Unit {
  self.as_dbus_connection().remove_filter(filter_id)
}

///|
impl IDBusConnection with fn send_message(self, message, flags) -> (Bool, UInt) raise @glib.Error_ {
  self.as_dbus_connection().send_message(message, flags)
}

///|
impl IDBusConnection with fn send_message_with_reply_finish(self, res) -> DBusMessage raise @glib.Error_ {
  self.as_dbus_connection().send_message_with_reply_finish(res)
}

///|
impl IDBusConnection with fn send_message_with_reply_sync(
  self,
  message,
  flags,
  timeout_msec,
  cancellable,
) -> (DBusMessage, UInt) raise @glib.Error_ {
  self
  .as_dbus_connection()
  .send_message_with_reply_sync(message, flags, timeout_msec, cancellable)
}

///|
impl IDBusConnection with fn set_exit_on_close(self, exit_on_close) -> Unit {
  self.as_dbus_connection().set_exit_on_close(exit_on_close)
}

///|
impl IDBusConnection with fn signal_unsubscribe(self, subscription_id) -> Unit {
  self.as_dbus_connection().signal_unsubscribe(subscription_id)
}

///|
impl IDBusConnection with fn start_message_processing(self) -> Unit {
  self.as_dbus_connection().start_message_processing()
}

///|
impl IDBusConnection with fn unexport_action_group(self, export_id) -> Unit {
  self.as_dbus_connection().unexport_action_group(export_id)
}

///|
impl IDBusConnection with fn unexport_menu_model(self, export_id) -> Unit {
  self.as_dbus_connection().unexport_menu_model(export_id)
}

///|
impl IDBusConnection with fn unregister_object(self, registration_id) -> Bool {
  self.as_dbus_connection().unregister_object(registration_id)
}

///|
impl IDBusConnection with fn unregister_subtree(self, registration_id) -> Bool {
  self.as_dbus_connection().unregister_subtree(registration_id)
}

///|
impl IDBusConnection with fn close(self, cancellable, callback) -> Unit {
  self.as_dbus_connection().close(cancellable, callback)
}

///|
impl IDBusConnection with fn flush(self, cancellable, callback) -> Unit {
  self.as_dbus_connection().flush(cancellable, callback)
}

///|
impl IDBusConnection with fn signal_subscribe(
  self,
  sender,
  interface_name,
  member_,
  object_path,
  arg0,
  flags,
  callback,
) -> Unit {
  self
  .as_dbus_connection()
  .signal_subscribe(
    sender, interface_name, member_, object_path, arg0, flags, callback,
  )
}

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

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

///|
pub fn DBusConnection::as_async_initable(
  self : DBusConnection,
) -> AsyncInitable = "%identity"

///|
pub impl IAsyncInitable for DBusConnection with fn as_async_initable(self) {
  self.as_async_initable()
}

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

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