Commit 683465e7 authored by gambas's avatar gambas
Browse files

Connections to the D-Bus buses are correctly freed when the program ends.

[GB.DBUS]
* BUG: Connections to the D-Bus buses are correctly freed when the program ends.
parent fc49ac61
Pipeline #448892927 passed with stage
in 21 minutes and 34 seconds
......@@ -27,18 +27,6 @@
#include "c_dbusconnection.h"
#include "c_dbus.h"
BEGIN_PROPERTY(DBus_System)
GB.ReturnObject(CDBUSCONNECTION_get(DBUS_BUS_SYSTEM));
END_PROPERTY
BEGIN_PROPERTY(DBus_Session)
GB.ReturnObject(CDBUSCONNECTION_get(DBUS_BUS_SESSION));
END_PROPERTY
BEGIN_PROPERTY(DBus_Debug)
if (READ_PROPERTY)
......@@ -58,8 +46,6 @@ GB_DESC CDBusDesc[] =
{
GB_DECLARE_STATIC("_DBus"),
GB_STATIC_PROPERTY_READ("System", "DBusConnection", DBus_System),
GB_STATIC_PROPERTY_READ("Session", "DBusConnection", DBus_Session),
GB_STATIC_PROPERTY("Debug", "b", DBus_Debug),
GB_CONSTANT("Method", "i", DBUS_MESSAGE_TYPE_METHOD_CALL),
......
......@@ -26,9 +26,6 @@
#include "helper.h"
#include "c_dbusconnection.h"
static CDBUSCONNECTION *_system = NULL;
static CDBUSCONNECTION *_session = NULL;
static DBusConnection *get_bus(DBusBusType type)
{
DBusConnection *conn;
......@@ -42,48 +39,27 @@ static DBusConnection *get_bus(DBusBusType type)
return conn;
}
CDBUSCONNECTION *CDBUSCONNECTION_get(DBusBusType type)
static CDBUSCONNECTION *connect_bus(DBusBusType type)
{
CDBUSCONNECTION *ob;
DBusConnection *conn;
if (type == DBUS_BUS_SYSTEM)
{
if (!_system)
{
conn = get_bus(type);
if (conn)
{
_system = GB.New(GB.FindClass("DBusConnection"), NULL, NULL);
GB.Ref(_system);
_system->connection = conn;
}
}
return _system;
}
else if (type == DBUS_BUS_SESSION)
{
if (!_session)
{
conn = get_bus(type);
if (conn)
{
_session = GB.New(GB.FindClass("DBusConnection"), NULL, NULL);
GB.Ref(_session);
_session->connection = conn;
}
}
return _session;
}
else
conn = get_bus(type);
if (!conn)
return NULL;
ob = GB.New(GB.FindClass("DBusConnection"), NULL, NULL);
ob->connection = conn;
return ob;
}
BEGIN_METHOD_VOID(DBusConnection_exit)
GB.Unref(POINTER(&_session));
GB.Unref(POINTER(&_system));
BEGIN_METHOD(DBusConnection_Connect, GB_BOOLEAN system)
GB.ReturnObject(connect_bus(VARG(system) ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION));
END_PROPERTY
END_METHOD
BEGIN_METHOD_VOID(DBusConnection_free)
......@@ -272,7 +248,7 @@ GB_DESC CDBusConnectionDesc[] =
{
GB_DECLARE("_DBusConnection", sizeof(CDBUSCONNECTION)), GB_NOT_CREATABLE(),
GB_STATIC_METHOD("_exit", NULL, DBusConnection_exit, NULL),
GB_STATIC_METHOD("_Connect", "DBusConnection", DBusConnection_Connect, "(System)b"),
GB_METHOD("_free", NULL, DBusConnection_free, NULL),
GB_METHOD("_Introspect", "s", DBusConnection_Introspect, "(Application)s[(Object)s]"),
GB_METHOD("_CallMethod", "v", DBusConnection_CallMethod, "(Application)s(Object)s(Interface)s(Method)s(InputSignature)s(OutputSignature)s(Arguments)Array;"),
......
......@@ -44,6 +44,4 @@ typedef
}
CDBUSCONNECTION;
CDBUSCONNECTION *CDBUSCONNECTION_get(DBusBusType type);
#endif /* __CDBUS_H */
......@@ -4,6 +4,9 @@ Export
Inherits _DBus
Static Property Read System As DBusConnection
Static Property Read Session As DBusConnection
Static Property Name As String
Static Public _ApplicationCache As New Collection
Static Property Read Null As Object
......@@ -12,6 +15,9 @@ Static Property Unique As Boolean
Static Private $sAppName As String
Static Private $bUnique As Boolean
Static Private $hSystem As DBusConnection
Static Private $hSession As DBusConnection
Static Public Sub _get((Application) As String) As DBusApplication
Dim hConn As DBusConnection
......@@ -21,14 +27,14 @@ Static Public Sub _get((Application) As String) As DBusApplication
If Application Like "system://*" Then
sKey = Application
Application = Mid$(Application, 10)
hConn = _DBus.System
hConn = DBus.System
Else If Application Like "session://*" Then
sKey = Application
Application = Mid$(Application, 11)
hConn = _DBus.Session
hConn = DBus.Session
Else
sKey = "session://" & Application
hConn = _DBus.Session
hConn = DBus.Session
Endif
hApp = _ApplicationCache[sKey]
......@@ -162,3 +168,17 @@ Static Private Sub Unique_Write(Value As Boolean)
$bUnique = Value
End
Static Private Function System_Read() As DBusConnection
If Not $hSystem Then $hSystem = DBusConnection._Connect(True)
Return $hSystem
End
Static Private Function Session_Read() As DBusConnection
If Not $hSession Then $hSession = DBusConnection._Connect(False)
Return $hSession
End
......@@ -18,7 +18,7 @@ Public Sub _new(Connection As DBusConnection, ApplicationName As String)
$hConn = Connection
$sName = ApplicationName
If $hConn = _DBus.System Then
If $hConn = DBus.System Then
$sKey = "system://" & $sName
Else
$sKey = "session://" & $sName
......
......@@ -139,7 +139,7 @@ Public Sub Main1()
End
Public Sub Main4()
Public Sub Main()
Dim hDBusApplication As DBusApplication
Dim hDBusProxy As DBusProxy
......@@ -153,7 +153,7 @@ Public Sub Main4()
End
Public Sub Main()
Public Sub Main5()
'Print DBus["org.freedesktop.DBus"]._Introspect("/a")
......
Supports Markdown
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