From c922ee7cd34ef880aaae1af31e8bae7e7766df56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Wed, 21 Dec 2011 01:37:09 +0000 Subject: [PATCH] [GB.DBUS] * BUG: Fix object registering and unregistering, so that the program quits normally when the last object is unregistered. git-svn-id: svn://localhost/gambas/trunk@4302 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.dbus/src/gb.dbus/.settings | 17 ++++++++++++---- gb.dbus/src/gb.dbus/.src/DBus.class | 1 - gb.dbus/src/gb.dbus/.src/DBusObject.class | 24 +++++++++++++++++++++++ gb.dbus/src/gb.dbus/.src/MMain.module | 8 ++++---- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/gb.dbus/src/gb.dbus/.settings b/gb.dbus/src/gb.dbus/.settings index 5bed0d615..6110b7910 100644 --- a/gb.dbus/src/gb.dbus/.settings +++ b/gb.dbus/src/gb.dbus/.settings @@ -4,6 +4,9 @@ Count=0 [DebugWindow] Count=0 +[DebugWindow/_ObjectCache] +Geometry=[0,0,210,210] + [DebugWindow/aArg] Geometry=[0,0,348,210] @@ -25,9 +28,15 @@ Geometry=[525,290,455,446] [DebugWindow/cCol["globalStrut"]] Geometry=[494,219,455,446] +[DebugWindow/hConnection] +Geometry=[0,0,210,210] + [DebugWindow/hObserver.Message] Geometry=[0,0,274,251] +[DebugWindow/hParent] +Geometry=[0,0,210,210] + [FFind] SearchIn="Module" CaseSensitive=False @@ -36,12 +45,12 @@ SearchComment=False SearchString=True [OpenFile] -File[1]=".src/MMain.module:40.4" +File[1]=".src/MMain.module:52.0" File[2]=".src/DBusApplication.class:74.2" -Active=3 -File[3]=".src/DBus.class:92.0" +File[3]=".src/DBus.class:76.2" File[4]=".src/DBusProxy.class:21.50" -File[5]=".src/DBusObject.class:326.54" +Active=5 +File[5]=".src/DBusObject.class:113.12" File[6]=".src/CTest.class:11.2" File[7]=".src/DBusSignal.class:6.0" Count=7 diff --git a/gb.dbus/src/gb.dbus/.src/DBus.class b/gb.dbus/src/gb.dbus/.src/DBus.class index 332b6e233..3eb848a8e 100644 --- a/gb.dbus/src/gb.dbus/.src/DBus.class +++ b/gb.dbus/src/gb.dbus/.src/DBus.class @@ -88,7 +88,6 @@ Static Public Sub _UnregisterApplication(hConnection As DBusConnection) End - Static Private Function Name_Read() As String If $sAppName Then Return $sAppName diff --git a/gb.dbus/src/gb.dbus/.src/DBusObject.class b/gb.dbus/src/gb.dbus/.src/DBusObject.class index 287c144fb..613146625 100644 --- a/gb.dbus/src/gb.dbus/.src/DBusObject.class +++ b/gb.dbus/src/gb.dbus/.src/DBusObject.class @@ -36,6 +36,8 @@ Static Private $sInterface As String Private $sPath As String Private $aChildren As String[] Private $hObserver As DBusObserver +Private $iRegister As Integer +Private $bRegisterParent As Boolean Static Private Sub ConvType(sType As String) As String @@ -62,6 +64,9 @@ Public Sub _Register(hConnection As DBusConnection, sPath As String) Dim hParent As DBusObject Dim sParent As String + Inc $iRegister + If $iRegister > 1 Then Return + If Not $sName Then $sName = DBus._RegisterApplication(hConnection) If Left(sPath) <> "/" Then sPath = "/" & sPath @@ -69,12 +74,14 @@ Public Sub _Register(hConnection As DBusConnection, sPath As String) If _ObjectCache.Exist(sPath) Then Return $sPath = sPath + _ObjectCache[sPath] = Me If sPath <> "/" Then sParent = File.Dir(sPath) hParent = _ObjectCache[sParent] If Not hParent Then + $bRegisterParent = True hParent = New DBusObject hParent._Register(hConnection, sParent) Endif @@ -91,6 +98,23 @@ Public Sub _Unregister(hConnection As DBusConnection) Dim sChild As String Dim hChild As DBusObject + Dim sParent As String + Dim hParent As DBusObject + + Dec $iRegister + If $iRegister > 0 Then Return + + If $bRegisterParent Then + + $bRegisterParent = False + sParent = File.Dir($sPath) + hParent = _ObjectCache[sParent] + If hParent Then + hParent._Unregister(hConnection) + Return + Endif + + Endif If $aChildren Then For Each sChild In $aChildren diff --git a/gb.dbus/src/gb.dbus/.src/MMain.module b/gb.dbus/src/gb.dbus/.src/MMain.module index 5c35ba4f3..4abc6aabc 100644 --- a/gb.dbus/src/gb.dbus/.src/MMain.module +++ b/gb.dbus/src/gb.dbus/.src/MMain.module @@ -32,9 +32,9 @@ Public Sub Main() ' Debug DBus.Session.Applications.Join("\n") ' DBus.Debug = True - 'DBus.Session.Register(CTest, "/Test") + DBus.Session.Register(CTest, "/Test") - Debug DBus["system://org.freedesktop.UPower"]["/org/freedesktop/UPower"].SuspendAllowed() + 'Debug DBus["system://org.freedesktop.UPower"]["/org/freedesktop/UPower"].SuspendAllowed() 'Wait 10 ' @@ -46,11 +46,11 @@ Public Sub Main() 'hSignal = New DBusSignal(DBus.Session, "org.freedesktop.DBus") As "MySignal" ' hSignal = New DBusSignal(DBus.Session, "", True) As "MySignal" ' - ' Wait 3 + Wait 3 ' ' hSignal.Enabled = False - 'DBus.Session.Unregister(CTest) + DBus.Session.Unregister(CTest) End