
Also rename the intermediate lua api table WpDebug -> WpLog Keeps things more consistent with the function names (wp_log*), with the lua api (Log.*) and with pipewire using log.{h,c} as well. After all, these functions are for logging...
160 lines
3.7 KiB
Lua
160 lines
3.7 KiB
Lua
-- WirePlumber
|
|
--
|
|
-- This file contains the API that is made available to the Lua scripts
|
|
--
|
|
-- Copyright © 2020 Collabora Ltd.
|
|
-- @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
--
|
|
-- SPDX-License-Identifier: MIT
|
|
|
|
local function Constraint (spec)
|
|
assert (type(spec[1]) == "string", "Constraint: expected subject as string");
|
|
assert (type(spec[2]) == "string", "Constraint: expected verb as string");
|
|
|
|
local subject = spec[1]
|
|
local verb = spec[2]
|
|
local verbs = {
|
|
["="] = "equals",
|
|
["c"] = "in-list",
|
|
["~"] = "in-range",
|
|
["#"] = "matches",
|
|
["+"] = "is-present",
|
|
["-"] = "is-absent"
|
|
}
|
|
|
|
-- check and convert verb to its short version
|
|
local verb_is_valid = false
|
|
for k, v in pairs(verbs) do
|
|
if verb == k or verb == v then
|
|
verb = k
|
|
spec[2] = k
|
|
verb_is_valid = true
|
|
break
|
|
end
|
|
end
|
|
assert (verb_is_valid, "Constraint: invalid verb '" .. verb .. "'")
|
|
|
|
-- check and convert type to its integer value
|
|
local type = spec["type"]
|
|
if type then
|
|
local valid_types = { "pw-global", "pw", "gobject" }
|
|
local type_is_valid = false
|
|
|
|
for i, v in ipairs(valid_types) do
|
|
if type == v then
|
|
spec["type"] = i
|
|
type_is_valid = true
|
|
break
|
|
end
|
|
end
|
|
|
|
assert(type_is_valid, "Constraint: invalid subject type '" .. type .. "'")
|
|
end
|
|
|
|
-- check if we got the right amount of values
|
|
if verb == "=" or verb == "#" then
|
|
assert (spec[3] ~= nil,
|
|
"Constraint: " .. verbs[verb] .. ": expected constraint value")
|
|
elseif verb == "c" then
|
|
assert (spec[3] ~= nil,
|
|
"Constraint: " .. verbs[verb] .. ": expected at least one constraint value")
|
|
elseif verb == "~" then
|
|
assert (spec[3] ~= nil and spec[4] ~= nil,
|
|
"Constraint: " .. verbs[verb] .. ": expected two values")
|
|
else
|
|
assert (spec[3] == nil,
|
|
"Constraint: " .. verbs[verb] .. ": expected no value, but there is one")
|
|
end
|
|
|
|
return debug.setmetatable(spec, { __name = "Constraint" })
|
|
end
|
|
|
|
local function dump_table(t, indent)
|
|
local indent_str = ""
|
|
indent = indent or 1
|
|
for i = 1, indent, 1 do
|
|
indent_str = indent_str .. "\t"
|
|
end
|
|
|
|
for k, v in pairs(t) do
|
|
if (type(v) == "table") then
|
|
print (indent_str .. tostring(k) .. ": ")
|
|
dump_table(v, indent + 1)
|
|
else
|
|
print (indent_str .. tostring(k) .. ": " .. tostring(v))
|
|
end
|
|
end
|
|
end
|
|
|
|
local Debug = {
|
|
dump_table = dump_table,
|
|
}
|
|
|
|
local Id = {
|
|
INVALID = 0xffffffff,
|
|
ANY = 0xffffffff,
|
|
}
|
|
|
|
local Features = {
|
|
PipewireObject = {
|
|
MINIMAL = 0x11,
|
|
},
|
|
ALL = 0xffffffff,
|
|
}
|
|
|
|
local Feature = {
|
|
Proxy = {
|
|
BOUND = 1,
|
|
},
|
|
PipewireObject = {
|
|
INFO = (1 << 4),
|
|
PARAM_PROPS = (1 << 5),
|
|
PARAM_FORMAT = (1 << 6),
|
|
PARAM_PROFILE = (1 << 7),
|
|
PARAM_PORT_CONFIG = (1 << 8),
|
|
PARAM_ROUTE = (1 << 9),
|
|
},
|
|
SpaDevice = {
|
|
ENABLED = (1 << 16),
|
|
},
|
|
Node = {
|
|
PORTS = (1 << 16),
|
|
},
|
|
Session = {
|
|
ENDPOINTS = (1 << 16),
|
|
LINKS = (1 << 17),
|
|
},
|
|
Endpoint = {
|
|
STREAMS = (1 << 16),
|
|
},
|
|
Metadata = {
|
|
DATA = (1 << 16),
|
|
},
|
|
SessionItem = {
|
|
ACTIVE = (1 << 0),
|
|
EXPORTED = (1 << 1),
|
|
},
|
|
}
|
|
|
|
SANDBOX_EXPORT = {
|
|
Debug = Debug,
|
|
Id = Id,
|
|
Features = Features,
|
|
Feature = Feature,
|
|
GLib = GLib,
|
|
Log = WpLog,
|
|
Core = WpCore,
|
|
Plugin = WpPlugin_find,
|
|
ObjectManager = WpObjectManager_new,
|
|
Interest = WpObjectInterest_new,
|
|
SessionItem = WpSessionItem_new,
|
|
Constraint = Constraint,
|
|
Device = WpDevice_new,
|
|
SpaDevice = WpSpaDevice_new,
|
|
Node = WpNode_new,
|
|
LocalNode = WpImplNode_new,
|
|
Link = WpLink_new,
|
|
ImplSession = WpImplSession_new,
|
|
Pod = WpSpaPod,
|
|
}
|