-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbusproxy.lua
81 lines (66 loc) · 1.91 KB
/
dbusproxy.lua
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local setmetatable = setmetatable
local lgi = require 'lgi'
local GLib, Gio = lgi.GLib, lgi.Gio
local DBusProxy = Gio.DBusProxy
local DBusProxyFlags = Gio.DBusProxyFlags
local DBusInterfaceInfo = Gio.DBusInterfaceInfo
local DBusCallFlags = Gio.DBusCallFlags
local Variant = GLib.Variant
local proxy = { mt = {} }
function proxy:connect()
local p, err = DBusProxy.new_sync(
self._private.bus,
DBusProxyFlags.NONE,
DBusInterfaceInfo({name = self._private.interface}),
self._private.name,
self._private.path,
self._private.interface)
self._private.proxy = p
end
function proxy:get_path()
return self._private.path
end
function proxy:get(name)
return self._private.proxy:get_cached_property(name).value
end
function proxy:get_property(interface, name)
return self:call(
"org.freedesktop.DBus.Properties",
"Get",
Variant('(ss)',{interface, name})
).value
end
function proxy:set_property(interface, name, params)
self:call(
"org.freedesktop.DBus.Properties",
"Set",
Variant('(ssv)',{interface, name, params})
)
end
function proxy:call(interface, method, params)
return self._private.proxy:call_sync(
(interface or self._private.interface) .. "." .. method,
params,
DBusCallFlags.NONE,
-1
)
end
function proxy:on_signal(callback)
self._private.proxy.on_g_signal = callback
end
function proxy:on_properties_changed(callback)
self._private.proxy.on_g_properties_changed = callback
end
local function new(args)
local p = { _private = {} }
p._private.bus = args.bus
p._private.interface = args.interface
p._private.name = args.name
p._private.path = args.path
setmetatable(p, {__index = proxy})
return p
end
function proxy.mt:__call(...)
return new(...)
end
return setmetatable(proxy, proxy.mt)