~jpsamaroo/DBus.jl

ref: 9e5239501e185e95ce1b6d1a321da3de82b169ba DBus.jl/src/DBus.jl -rw-r--r-- 753 bytes
9e523950Julian P Samaroo Initial commit 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module DBus

using Dbus_jll

include("api.jl")

const ERROR = Ref{DBusError}()

struct DBusException
    title::String
    name::Cstring
    msg::Cstring
end
function Base.show(io::IO, ex::DBusException)
    name = Base.unsafe_string(ex.name)
    msg = Base.unsafe_string(ex.msg)
    print(io, ex.title, " (", name, "): ", msg)
end

function check(title, error=ERROR)
    if dbus_error_is_set(error)
        name = error[].name
        msg = error[].message
        dbus_error_free(error)
        throw(DBusException(title, name, msg))
    end
end

function connect()
    conn = dbus_bus_get(DBUS_BUS_SESSION, ERROR)
    check("Connection Error")
    @assert conn != C_NULL
    conn
end

function __init__()
    dbus_error_init(ERROR)
end

end # module