[Gambas-user] Error during registration on the D-Bus

T Lee Davidson t.lee.davidson at gmail.com
Sun Mar 11 09:24:11 CET 2018


On 03/10/2018 12:32 PM, Hans Lehmann wrote:
> Hello,
> 
> I try in vain to call my service program for the D-Bus only once.
> At the first start I see the window and can use the service with a D-Bus client program.
> After a further start I expect the inserted error message - instead there is an error message:
> 
> This application has raised an unexpected error and must abort.
> Unique application is already registered.
> DBus._RegisterApplication.78
> 
> With kind regards
> 
> Hans
> 
> FMain.class:
> 
> Public Sub Form_Open()
> 
>   DBus.Unique = True
> 
>   If DBus.IsRegistered(Service) Then
>      Message.Error("An instance of " & Application.Name & " already exists.")
>      FMain.Close()
>   Else
>      DBus.Session.Register(Service, "/Service")
>   Endif
> 
> End
> 
> Public Sub Form_Close()
> 
>   If DBus.IsRegistered(Service) Then DBus.Session.Unregister(Service)
>   FMain.Close()
> 
> End
> 
> --------------------------------------------------------------------------------------------------
> 
> Service.class:
> 
> Inherits DBusObject
> Create Static
> 
> Public Function ComputeAdd(Value1 As Float, Value2 As Float) As Float
>   Return Value1 + Value2
> End
> 

Hans, it appears that you provided the complete code of a project modeled after the example in the Wiki.

You are testing by launching two separate instances of the application, correct?

If so, then I'm sure the problem is that the Service object of the first instance 'belongs' to that particular instance, and the
second instance of the app knows nothing about it because it has its own, distinct Service object. So, it sees its own Service
object as not registered and tries to register another "org.gambas.server" on the bus which is a collision.

(For some reason, the behavior of DBus.Unique seems to be reversed. When set to True a non-unique ID is registered.)

I think you would need to try calling a dbus method of the app and then only register on the bus if there is an exception.
Something like:

[code]
  Try DBus["org.gambas.server"]["/Service"].ComputeAdd(0, 0)
  If Error Then
    DBus.Session.Register(Service, "/Service")
  Else
    Message.Error("An instance of " & Application.Name & " already exists.")
    FMain.Close()
  Endif
[/code]


-- 
Lee


More information about the User mailing list