diff --git a/gb.dbus/src/c_dbusconnection.c b/gb.dbus/src/c_dbusconnection.c index d0163f623..9a20d7f18 100644 --- a/gb.dbus/src/c_dbusconnection.c +++ b/gb.dbus/src/c_dbusconnection.c @@ -270,7 +270,7 @@ END_METHOD GB_DESC CDBusConnectionDesc[] = { - GB_DECLARE("DBusConnection", sizeof(CDBUSCONNECTION)), GB_NOT_CREATABLE(), + GB_DECLARE("_DBusConnection", sizeof(CDBUSCONNECTION)), GB_NOT_CREATABLE(), GB_STATIC_METHOD("_exit", NULL, DBusConnection_exit, NULL), GB_METHOD("_free", NULL, DBusConnection_free, NULL), diff --git a/gb.dbus/src/gb.dbus/.project b/gb.dbus/src/gb.dbus/.project index 2ab5d65b4..9031947f6 100644 --- a/gb.dbus/src/gb.dbus/.project +++ b/gb.dbus/src/gb.dbus/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 Title=gb.dbus Startup=MMain -Version=3.15.90 +Version=3.16.90 VersionFile=1 Component=gb.dbus TabSize=2 diff --git a/gb.dbus/src/gb.dbus/.src/DBus.class b/gb.dbus/src/gb.dbus/.src/DBus.class index 7ef01e225..158a6c9eb 100644 --- a/gb.dbus/src/gb.dbus/.src/DBus.class +++ b/gb.dbus/src/gb.dbus/.src/DBus.class @@ -10,7 +10,6 @@ Static Property Read Null As Object Static Property Unique As Boolean Static Private $sAppName As String -Static Private $iRegisterCount As Integer Static Private $bUnique As Boolean Static Public Sub _get((Application) As String) As DBusApplication @@ -67,36 +66,36 @@ Static Public Sub _Normalize(sName As String, Optional bKeepCase As Boolean, Opt End -Static Public Sub _RegisterApplication(hConnection As DBusConnection) As String - - Dim sName As String - - If IsNull(hConnection.Tag) Then - sName = Name_Read() - If hConnection._RequestName(sName, True) Then - If $bUnique Then - Error.Raise("Unique application is already registered") - Else - Error.Raise("Application is already registered") - Endif - Endif - hConnection.Tag = sName - Endif - Inc $iRegisterCount - Return hConnection.Tag - -End - -Static Public Sub _UnregisterApplication(hConnection As DBusConnection) - - Dec $iRegisterCount - If $iRegisterCount > 0 Then Return - If Not hConnection.Tag Then Return - hConnection._ReleaseName(hConnection.Tag) - hConnection.Tag = "" - -End - +' Static Public Sub _RegisterApplication(hConnection As DBusConnection) As String +' +' Dim sName As String +' +' If IsNull(hConnection.Tag) Then +' sName = Name_Read() +' If hConnection._RequestName(sName, True) Then +' If $bUnique Then +' Error.Raise("Unique application is already registered") +' Else +' Error.Raise("Application is already registered") +' Endif +' Endif +' hConnection.Tag = sName +' Endif +' Inc $iRegisterCount +' Return hConnection.Tag +' +' End +' +' Static Public Sub _UnregisterApplication(hConnection As DBusConnection) +' +' Dec $iRegisterCount +' If $iRegisterCount > 0 Then Return +' If Not hConnection.Tag Then Return +' hConnection._ReleaseName(hConnection.Tag) +' hConnection.Tag = "" +' +' End +' Static Private Function Name_Read() As String Dim sName As String diff --git a/gb.dbus/src/gb.dbus/.src/DBusConnection.class b/gb.dbus/src/gb.dbus/.src/DBusConnection.class new file mode 100644 index 000000000..0cc678ade --- /dev/null +++ b/gb.dbus/src/gb.dbus/.src/DBusConnection.class @@ -0,0 +1,39 @@ +' Gambas class file + +Export + +Inherits _DBusConnection + +Private $sName As String +Private $nConnect As Integer + +Public Sub Open() As String + + Dim sName As String + + If Not $sName Then + sName = DBus.Name + If Me._RequestName(sName, True) Then + If DBus.Unique Then + Error.Raise("Unique application is already registered") + Else + Error.Raise("Application is already registered") + Endif + Endif + $sName = sName + Endif + Inc $nConnect + Return $sName + +End + +Public Sub Close() + + Dec $nConnect + If $nConnect > 0 Then Return + If Not $sName Then Return + Me._ReleaseName($sName) + $sName = "" + +End + diff --git a/gb.dbus/src/gb.dbus/.src/DBusObject.class b/gb.dbus/src/gb.dbus/.src/DBusObject.class index 18c3dcaf2..9bab29fa7 100644 --- a/gb.dbus/src/gb.dbus/.src/DBusObject.class +++ b/gb.dbus/src/gb.dbus/.src/DBusObject.class @@ -126,7 +126,7 @@ Public Sub _Register(hConnection As DBusConnection, sFullPath As String, Optiona Inc $iRegister If Not $sName Then - $sName = DBus._RegisterApplication(hConnection) + $sName = hConnection.Open() If Not DBus.Unique Then $sName = Left($sName, -Len(CStr(Application.Id)) - 1) Endif @@ -210,7 +210,7 @@ Public Sub _Unregister(hConnection As DBusConnection) $sPath = "" If _ObjectCache.Count = 0 Then - DBus._UnregisterApplication(hConnection) + hConnection.Close() $sName = "" Endif diff --git a/gb.dbus/src/gb.dbus/.src/MMain.module b/gb.dbus/src/gb.dbus/.src/MMain.module index bd0d13766..df063edc7 100644 --- a/gb.dbus/src/gb.dbus/.src/MMain.module +++ b/gb.dbus/src/gb.dbus/.src/MMain.module @@ -155,6 +155,8 @@ End Public Sub Main() - Print DBus["org.freedesktop.DBus"]._Introspect("/a") + 'Print DBus["org.freedesktop.DBus"]._Introspect("/a") + + 'DBus["system://org.freedesktop.login1"]["/org/freedesktop/login1", "org.freedesktop.login1.Manager"].PowerOff(True) End