Skip to content

Commit 69019be

Browse files
committed
fix: backport device mode and system-wide conf
ca6a44e feat: add device passthru mode c7f3a69 feat: support system-wide runtime configuration Signed-off-by: reddevillg <reddevillg@gmail.com>
1 parent eb48f94 commit 69019be

16 files changed

Lines changed: 258 additions & 72 deletions

File tree

api/schema/v1.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@
14391439
"type": "string"
14401440
}
14411441
},
1442+
"device_mode": {
1443+
"type": "array",
1444+
"items": {
1445+
"$ref": "#/$defs/DeviceOption"
1446+
}
1447+
},
14421448
"ext_defs": {
14431449
"description": "external extension definitions to extend the component",
14441450
"type": "object",
@@ -1450,6 +1456,12 @@
14501456
}
14511457
}
14521458
}
1459+
},
1460+
"DeviceOption": {
1461+
"description": "device option",
1462+
"enum": [
1463+
"passthru"
1464+
]
14531465
}
14541466
},
14551467
"type": "object",
@@ -1594,6 +1606,9 @@
15941606
},
15951607
"RuntimeConfigure": {
15961608
"$ref": "#/$defs/RuntimeConfigure"
1609+
},
1610+
"DeviceOption": {
1611+
"$ref": "#/$defs/DeviceOption"
15971612
}
15981613
}
15991614
}

api/schema/v1.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
1+
# SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
22
# SPDX-License-Identifier: LGPL-3.0-or-later
33
#
44
# NOTE:
@@ -1090,13 +1090,20 @@ $defs:
10901090
type: object
10911091
additionalProperties:
10921092
type: string
1093+
device_mode:
1094+
type: array
1095+
items:
1096+
$ref: '#/$defs/DeviceOption'
10931097
ext_defs:
10941098
description: external extension definitions to extend the component
10951099
type: object
10961100
additionalProperties:
10971101
type: array
10981102
items:
10991103
$ref: '#/$defs/ExtensionDefine'
1104+
DeviceOption:
1105+
description: device option
1106+
enum: ["passthru"]
11001107
type: object
11011108
properties:
11021109
# NOTE: "properties" is auto generated by referring all types is $defs

apps/ll-cli/src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <algorithm>
3434
#include <functional>
35+
#include <map>
3536
#include <memory>
3637
#include <string_view>
3738
#include <thread>
@@ -200,6 +201,13 @@ ll-cli run org.deepin.demo -- bash -x /path/to/bash/script)"));
200201
->delimiter(',')
201202
->allow_extra_args(false)
202203
->group("");
204+
const std::map<std::string, linglong::api::types::v1::DeviceOption> deviceOptionMap = {
205+
{ "passthru", linglong::api::types::v1::DeviceOption::Passthru },
206+
};
207+
cliRun->add_option("--device-mode", runOptions.deviceOptions, _("Add device options"))
208+
->delimiter(',')
209+
->transform(CLI::CheckedTransformer(deviceOptionMap, CLI::ignore_case))
210+
->allow_extra_args(false);
203211
cliRun->add_option("COMMAND", runOptions.commands, _("Run commands in a running sandbox"));
204212
}
205213

configure.h.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2+
* SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
33
*
44
* SPDX-License-Identifier: LGPL-3.0-or-later
55
*/
@@ -22,8 +22,9 @@
2222
#define LINGLONG_CLIENT_NAME "@LINGLONG_CLI_BIN@"
2323
#define LINGLONG_CLIENT_PATH "@CMAKE_INSTALL_FULL_BINDIR@/@LINGLONG_CLI_BIN@"
2424
#define LINGLONG_EXPORT_PATH "@LINGLONG_EXPORT_PATH@"
25+
#define LINGLONG_SYSCONFDIR SYSCONFDIR "/linglong"
2526
// The directory where the package install hooks reside.
26-
#define LINGLONG_INSTALL_HOOKS_DIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@/linglong/config.d"
27+
#define LINGLONG_INSTALL_HOOKS_DIR LINGLONG_SYSCONFDIR "/config.d"
2728

2829
#define LINGLONG_EXPORT_VERSION "1.0.0.2"
2930
// The package's locale domain.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is generated by tools/codegen.sh
2+
// DO NOT EDIT IT.
3+
4+
// clang-format off
5+
6+
// To parse this JSON data, first install
7+
//
8+
// json.hpp https://github.com/nlohmann/json
9+
//
10+
// Then include this file, and then do
11+
//
12+
// DeviceOption.hpp data = nlohmann::json::parse(jsonString);
13+
14+
#pragma once
15+
16+
#include <optional>
17+
#include <nlohmann/json.hpp>
18+
#include "linglong/api/types/v1/helper.hpp"
19+
20+
namespace linglong {
21+
namespace api {
22+
namespace types {
23+
namespace v1 {
24+
/**
25+
* device option
26+
*/
27+
28+
using nlohmann::json;
29+
30+
/**
31+
* device option
32+
*/
33+
enum class DeviceOption : int { Passthru };
34+
}
35+
}
36+
}
37+
}
38+
39+
// clang-format on

libs/api/src/linglong/api/types/v1/Generators.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "linglong/api/types/v1/ExportDirs.hpp"
6060
#include "linglong/api/types/v1/DialogMessage.hpp"
6161
#include "linglong/api/types/v1/DialogHandShakePayload.hpp"
62+
#include "linglong/api/types/v1/DeviceOption.hpp"
6263
#include "linglong/api/types/v1/ContainerProcessStateInfo.hpp"
6364
#include "linglong/api/types/v1/CommonResult.hpp"
6465
#include "linglong/api/types/v1/CommonOptions.hpp"
@@ -253,6 +254,9 @@ void to_json(json & j, const UpgradeListResult & x);
253254
void from_json(const json & j, LinglongAPIV1 & x);
254255
void to_json(json & j, const LinglongAPIV1 & x);
255256

257+
void from_json(const json & j, DeviceOption & x);
258+
void to_json(json & j, const DeviceOption & x);
259+
256260
void from_json(const json & j, InteractionMessageType & x);
257261
void to_json(json & j, const InteractionMessageType & x);
258262

@@ -1200,12 +1204,16 @@ j["version"] = x.version;
12001204
}
12011205

12021206
inline void from_json(const json & j, RuntimeConfigure& x) {
1207+
x.deviceMode = get_stack_optional<std::vector<DeviceOption>>(j, "device_mode");
12031208
x.env = get_stack_optional<std::map<std::string, std::string>>(j, "env");
12041209
x.extDefs = get_stack_optional<std::map<std::string, std::vector<ExtensionDefine>>>(j, "ext_defs");
12051210
}
12061211

12071212
inline void to_json(json & j, const RuntimeConfigure & x) {
12081213
j = json::object();
1214+
if (x.deviceMode) {
1215+
j["device_mode"] = x.deviceMode;
1216+
}
12091217
if (x.env) {
12101218
j["env"] = x.env;
12111219
}
@@ -1283,6 +1291,7 @@ x.commonOptions = get_stack_optional<CommonOptions>(j, "CommonOptions");
12831291
x.commonResult = get_stack_optional<CommonResult>(j, "CommonResult");
12841292
x.containerProcessStateInfo = get_stack_optional<ContainerProcessStateInfo>(j, "ContainerProcessStateInfo");
12851293
x.deviceNode = get_stack_optional<DeviceNode>(j, "DeviceNode");
1294+
x.deviceOption = get_stack_optional<DeviceOption>(j, "DeviceOption");
12861295
x.dialogHandShakePayload = get_stack_optional<DialogHandShakePayload>(j, "DialogHandShakePayload");
12871296
x.dialogMessage = get_stack_optional<DialogMessage>(j, "DialogMessage");
12881297
x.exportDirs = get_stack_optional<ExportDirs>(j, "ExportDirs");
@@ -1354,6 +1363,9 @@ j["ContainerProcessStateInfo"] = x.containerProcessStateInfo;
13541363
if (x.deviceNode) {
13551364
j["DeviceNode"] = x.deviceNode;
13561365
}
1366+
if (x.deviceOption) {
1367+
j["DeviceOption"] = x.deviceOption;
1368+
}
13571369
if (x.dialogHandShakePayload) {
13581370
j["DialogHandShakePayload"] = x.dialogHandShakePayload;
13591371
}
@@ -1467,6 +1479,18 @@ j["XDGDirectoryPermissions"] = x.xdgDirectoryPermissions;
14671479
}
14681480
}
14691481

1482+
inline void from_json(const json & j, DeviceOption & x) {
1483+
if (j == "passthru") x = DeviceOption::Passthru;
1484+
else { throw std::runtime_error("Input JSON does not conform to schema!"); }
1485+
}
1486+
1487+
inline void to_json(json & j, const DeviceOption & x) {
1488+
switch (x) {
1489+
case DeviceOption::Passthru: j = "passthru"; break;
1490+
default: throw std::runtime_error("Unexpected value in enumeration \"DeviceOption\": " + std::to_string(static_cast<int>(x)));
1491+
}
1492+
}
1493+
14701494
inline void from_json(const json & j, InteractionMessageType & x) {
14711495
if (j == "Downgrade") x = InteractionMessageType::Downgrade;
14721496
else if (j == "Install") x = InteractionMessageType::Install;

libs/api/src/linglong/api/types/v1/LinglongAPIV1.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace linglong {
6565
namespace api {
6666
namespace types {
6767
namespace v1 {
68+
enum class DeviceOption : int;
6869
enum class InteractionMessageType : int;
6970
enum class State : int;
7071
}
@@ -98,6 +99,7 @@ std::optional<CommonOptions> commonOptions;
9899
std::optional<CommonResult> commonResult;
99100
std::optional<ContainerProcessStateInfo> containerProcessStateInfo;
100101
std::optional<DeviceNode> deviceNode;
102+
std::optional<DeviceOption> deviceOption;
101103
std::optional<DialogHandShakePayload> dialogHandShakePayload;
102104
std::optional<DialogMessage> dialogMessage;
103105
std::optional<ExportDirs> exportDirs;

libs/api/src/linglong/api/types/v1/RuntimeConfigure.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@
1919

2020
#include "linglong/api/types/v1/ExtensionDefine.hpp"
2121

22+
namespace linglong {
23+
namespace api {
24+
namespace types {
25+
namespace v1 {
26+
enum class DeviceOption : int;
27+
}
28+
}
29+
}
30+
}
31+
2232
namespace linglong {
2333
namespace api {
2434
namespace types {
2535
namespace v1 {
2636
using nlohmann::json;
2737

2838
struct RuntimeConfigure {
39+
std::optional<std::vector<DeviceOption>> deviceMode;
2940
std::optional<std::map<std::string, std::string>> env;
3041
/**
3142
* external extension definitions to extend the component

libs/common/src/linglong/common/dir.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -47,4 +47,9 @@ std::filesystem::path getUserRuntimeConfigDir() noexcept
4747
return configDir / "linglong";
4848
}
4949

50+
std::filesystem::path getSystemRuntimeConfigDir() noexcept
51+
{
52+
return LINGLONG_SYSCONFDIR;
53+
}
54+
5055
} // namespace linglong::common::dir

libs/common/src/linglong/common/dir.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -25,4 +25,6 @@ std::filesystem::path getUserCacheDir() noexcept;
2525

2626
std::filesystem::path getUserRuntimeConfigDir() noexcept;
2727

28+
std::filesystem::path getSystemRuntimeConfigDir() noexcept;
29+
2830
} // namespace linglong::common::dir

0 commit comments

Comments
 (0)