Skip to content

Commit 6ee4e1f

Browse files
reddevillgComixHe
authored andcommitted
feat: add extension interface
Signed-off-by: reddevillg <reddevillg@gmail.com>
1 parent 49c6660 commit 6ee4e1f

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

libs/linglong/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pfl_add_library(
3535
src/linglong/cli/printer.h
3636
src/linglong/cli/terminal_notifier.cpp
3737
src/linglong/cli/terminal_notifier.h
38+
src/linglong/extension/extension.cpp
3839
src/linglong/package/architecture.cpp
3940
src/linglong/package/architecture.h
4041
src/linglong/package/fallback_version.cpp
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: LGPL-3.0-or-later
5+
*/
6+
7+
#include "extension.h"
8+
9+
#include <algorithm>
10+
#include <fstream>
11+
12+
namespace linglong::extension {
13+
14+
ExtensionIf::~ExtensionIf() { }
15+
16+
ExtensionIf *ExtensionFactory::makeExtension(const std::string &name)
17+
{
18+
if (name == ExtensionImplNVIDIADisplayDriver::name) {
19+
return new ExtensionImplNVIDIADisplayDriver();
20+
}
21+
22+
return NULL;
23+
}
24+
25+
std::string ExtensionImplNVIDIADisplayDriver::name = "org.deepin.driver.display.nvidia";
26+
27+
ExtensionImplNVIDIADisplayDriver::ExtensionImplNVIDIADisplayDriver()
28+
{
29+
driverName = hostDriverEnable();
30+
}
31+
32+
bool ExtensionImplNVIDIADisplayDriver::shouldEnable(std::string &extensionName)
33+
{
34+
if (extensionName != name) {
35+
return false;
36+
}
37+
38+
if (!driverName.empty()) {
39+
extensionName = name + "." + driverName;
40+
return true;
41+
}
42+
43+
return false;
44+
}
45+
46+
std::string ExtensionImplNVIDIADisplayDriver::hostDriverEnable()
47+
{
48+
std::string version;
49+
50+
std::ifstream versionFile("/sys/module/nvidia/version");
51+
if (versionFile) {
52+
versionFile >> version;
53+
54+
std::replace(version.begin(), version.end(), '.', '-');
55+
}
56+
57+
return version;
58+
}
59+
60+
} // namespace linglong::extension
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: LGPL-3.0-or-later
5+
*/
6+
7+
#pragma once
8+
9+
#include <string>
10+
11+
namespace linglong::extension {
12+
13+
class ExtensionIf
14+
{
15+
public:
16+
ExtensionIf() { };
17+
virtual ~ExtensionIf() = 0;
18+
19+
virtual bool shouldDownload(std::string &) { return false; }
20+
21+
virtual bool shouldEnable(std::string &) { return false; }
22+
23+
virtual bool shouldPrune(std::string &) { return false; }
24+
};
25+
26+
class ExtensionFactory
27+
{
28+
public:
29+
static ExtensionIf *makeExtension(const std::string &name);
30+
};
31+
32+
class ExtensionImplNVIDIADisplayDriver : public ExtensionIf
33+
{
34+
public:
35+
ExtensionImplNVIDIADisplayDriver();
36+
37+
~ExtensionImplNVIDIADisplayDriver() override { }
38+
39+
bool shouldEnable(std::string &extensionName) override;
40+
41+
static std::string name;
42+
43+
private:
44+
std::string hostDriverEnable();
45+
46+
std::string driverName;
47+
};
48+
49+
} // namespace linglong::extension

0 commit comments

Comments
 (0)