-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhard_ipc.lua
More file actions
88 lines (81 loc) · 3.23 KB
/
hard_ipc.lua
File metadata and controls
88 lines (81 loc) · 3.23 KB
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
82
83
84
85
86
87
88
require 'utils'
require 'luasharp'
import "System"
ipc_cache_actions = {}
ipc_cache_functions = {}
shared_data_cache = {}
function require_ipc(ipc_signature, result_type, arg_types)
if ipc_cache_actions[ipc_signature] ~= nil or ipc_cache_functions[ipc_signature] ~= nil then
log_(LEVEL_VERBOSE, _text, "IPC already loaded", ipc_signature)
return
end
arg_types = default(arg_types, {})
arg_types[#arg_types + 1] = default(result_type, 'System.Object')
for i, v in pairs(arg_types) do
if type(v) ~= 'string' then
error("Bad argument", CallerName(false), "argument types shound be strings")
end
arg_types[i] = Type.GetType(v)
end
local method = get_generic_method(Svc.PluginInterface:GetType(), 'GetIpcSubscriber', arg_types)
if method.Invoke == nil then
error("GetIpcSubscriber not found", CallerName(false), "No IPC subscriber for", #arg_types, "arguments")
end
local sig = luanet.make_array(Object, { ipc_signature })
local subscriber = method:Invoke(Svc.PluginInterface, sig)
if subscriber == nil then
error("IPC not found", CallerName(false), "signature:", ipc_signature)
end
if result_type == nil then
log_(LEVEL_DEBUG, _text, "loaded action IPC", ipc_signature)
ipc_cache_actions[ipc_signature] = subscriber
else
log_(LEVEL_DEBUG, _text, "loaded function IPC", ipc_signature)
ipc_cache_functions[ipc_signature] = subscriber
end
end
function invoke_ipc(ipc_signature, ...)
local function_subscriber = ipc_cache_functions[ipc_signature]
local action_subscriber = ipc_cache_actions[ipc_signature]
if function_subscriber == nil and action_subscriber == nil then
error("IPC not ready", CallerName(false), "signature:", ipc_signature, "is not loaded")
end
if function_subscriber ~= nil then
local result = function_subscriber:InvokeFunc(...)
if result == function_subscriber then
error("Function IPC failed", CallerName(false), "signature:", ipc_signature)
end
return result
end
-- otherwise its action IPC
local result = action_subscriber:InvokeAction(...)
if result == action_subscriber then
error("IPC failed", CallerName(false), "signature:", ipc_signature)
end
end
function get_shared_data(tag, data_type)
if shared_data_cache[tag] ~= nil then
return shared_data_cache[tag]
end
local method = get_generic_method(Svc.PluginInterface:GetType(), 'GetData', { Type.GetType(data_type) })
local sig = luanet.make_array(Object, { tag })
local so = method:Invoke(Svc.PluginInterface, sig)
if so == sig then
return nil
end
shared_data_cache[tag] = so
return so
end
function release_shared_data(tag)
if tag == nil then
for t, _ in pairs(shared_data_cache) do
log_(LEVEL_VERBOSE, _text, "Releasing shared data", t)
Svc.PluginInterface:RelinquishData(t)
end
shared_data_cache = {}
else
log_(LEVEL_VERBOSE, _text, "Releasing shared data", tag)
Svc.PluginInterface:RelinquishData(tag)
shared_data_cache[tag] = nil
end
end