Commit 8d1d8bdf authored by Benoît Minisini's avatar Benoît Minisini
Browse files

DBusConnection: Open() and Close() now allow to explicitly register to a bus.

[GB.DBUS]
* NEW: DBusConnection: Open() is a new method that allows to explicitly register to a bus.
* NEW: DBusConnection: Close() is a new method that allows to explicitly unregister from a bus.
parent 469c0476
Pipeline #361444394 passed with stage
in 26 minutes and 2 seconds
......@@ -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),
......
# 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
......
......@@ -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
......
' 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
......@@ -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
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment