File: lua_swupdate.lua

package info (click to toggle)
swupdate 2025.12%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,004 kB
  • sloc: ansic: 66,621; python: 6,291; makefile: 791; sh: 538; javascript: 229
file content (138 lines) | stat: -rw-r--r-- 4,731 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
--[[

    SWUpdate IPC Lua Module Interface.

    Interface specification for the Lua IPC module.
    See: bindings/lua_swupdate.c

    Copyright (C) 2022, Siemens AG
    Author: Christian Storm <christian.storm@siemens.com>

    SPDX-License-Identifier: GPL-2.0-or-later

--]]

---@diagnostic disable: missing-return
---@diagnostic disable: unused-local
-- luacheck: no unused args


--- SWUpdate IPC Lua Module.
--- @class lua_swupdate
local lua_swupdate = {}


--- Get local IPv4 network interface(s) information.
--
-- The returned Table contains the network interface names
-- as keys and a space-separated IP address and subnet mask
-- as values, e.g., {['eth0']="192.168.1.1 255.255.255.0"}.
--
--- @return table<string, string>
lua_swupdate.ipv4 = function() end


--- @enum lua_swupdate.RECOVERY_STATUS
--- Lua equivalent of `RECOVERY_STATUS` as in `include/swupdate_status.h`.
lua_swupdate.RECOVERY_STATUS = {
    IDLE       = 0,
    START      = 1,
    RUN        = 2,
    SUCCESS    = 3,
    FAILURE    = 4,
    DOWNLOAD   = 5,
    DONE       = 6,
    SUBPROCESS = 7,
    PROGRESS   = 8
}


--- @enum lua_swupdate.sourcetype
--- Lua equivalent of `sourcetype` as in `include/swupdate_status.h`.
lua_swupdate.sourcetype = {
    SOURCE_UNKNOWN           = 0,
    SOURCE_WEBSERVER         = 1,
    SOURCE_SURICATTA         = 2,
    SOURCE_DOWNLOADER        = 3,
    SOURCE_LOCAL             = 4,
    SOURCE_CHUNKS_DOWNLOADER = 5
}


--- Lua equivalent of `struct progress_msg` as in `include/progress_ipc.h`.
--- @class lua_swupdate.progress_msg
--- @field apiversion number  API Version for compatibility check
--- @field status     lua_swupdate.RECOVERY_STATUS  Update status, one of `lua_swupdate.RECOVERY_STATUS`'s values
--- @field download   number  Downloaded data percentage
--- @field source     lua_swupdate.sourcetype  Interface that triggered the update, one of `lua_swupdate.sourcetype`'s values
--- @field nsteps     number  Total number of steps
--- @field step       number  Current step
--- @field percent    number  Percentage done in current step
--- @field artifact   string  Name of image to be installed
--- @field handler    string  Name of running Handler
--- @field info       string  Additional information about installation


--- SWUpdate progress socket binding.
--
-- The returned Class Table contains methods to
-- interact with SWUpdate's progress socket.
--
lua_swupdate.progress = function()
    return {
        --- Connect to SWUpdate's progress socket.
        --
        --- @param  self  table   This `lua_swupdate.progress` instance
        --- @return number | nil  # The connection handle or nil in case of error
        --- @return nil | string  # nil or an error message in case of error
        connect = function(self) end,

        --- Receive data from SWUpdate's progress socket.
        --
        --- @param  self  table                        This `lua_swupdate.progress` instance
        --- @return table | lua_swupdate.progress_msg  # This `lua_swupdate.progress` instance on error or the received progress message
        --- @return nil                                # nil in case of error
        receive = function(self) end,

        --- Close connection to SWUpdate's progress socket.
        --
        --- @param  self  table  This `lua_swupdate.progress` instance
        --- @return table        # This `lua_swupdate.progress` instance
        close = function(self) end,
    }
end


--- SWUpdate control socket binding.
--
-- The returned Class Table contains methods to
-- interact with SWUpdate's control socket.
--
lua_swupdate.control = function()
    return {
        --- Connect to SWUpdate's control socket.
        --
        --- @param  self  table   This `lua_swupdate.control` instance
        --- @return number | nil  # Connection handle or nil in case of error
        --- @return nil | string  # nil or an error message in case of error
        connect = function(self) end,

        --- Write to connected SWUpdate control socket.
        --
        --- @param  self  table    This `lua_swupdate.control` instance
        --- @param  data  string   Chunk data to write to SWUpdate's control socket
        --- @return boolean | nil  # true or nil in case of error
        --- @return nil | string   # nil or an error message in case of error
        write = function(self, data) end,

        --- Close connection to SWUpdate's control socket.
        --
        --- @param  self  table    This `lua_swupdate.control` instance
        --- @return boolean | nil  # true or nil in case of error
        --- @return nil | string   # nil or an error message in case of error
        close = function(self) end,
    }
end


return lua_swupdate