Skip to content

feat: dplugin#262

Closed
black-desk wants to merge 2 commits into
linuxdeepin:masterfrom
black-desk:black-desk/dev/dplugin
Closed

feat: dplugin#262
black-desk wants to merge 2 commits into
linuxdeepin:masterfrom
black-desk:black-desk/dev/dplugin

Conversation

@black-desk

Copy link
Copy Markdown
  • build: clean cmakelist
  • feat: start impl dplugin

@deepin-bot

deepin-bot Bot commented Feb 9, 2023

Copy link
Copy Markdown
Contributor

Doc Check bot
🟡 some documents missing!

File Line Symbol
include/util/dplugin.h 25 const QScopedPointer Dtk::Core::DPlugin::library
include/util/dplugin.h 23 static QList< std::shared_ptr< DPlugin > > Dtk::Core::DPlugin::listPlugins
include/util/dplugin.h 26 QString Dtk::Core::DPlugin::name
include/util/dplugin.h 18 Dtk::Core::DPlugin

@black-desk
black-desk force-pushed the black-desk/dev/dplugin branch 5 times, most recently from f18bad2 to 1a02895 Compare February 16, 2023 13:25
@black-desk

Copy link
Copy Markdown
Author

@kegechen @zccrs @Groveer @justforlxz

这边希望给 DTK 添加一个通用的插件寻找机制, 方便需要使用插件来加载可选功能的应用编写.

这个机制目前设计如下:

应用会从 QT 给的 AppDataLocation 目录下的 plugins 文件夹中寻找配置文件. 配置文件中记录该插件的名称 版本和库名(也可以是绝对路径). 这些信息被用来初始化一个 QLibrary 对象. 需要加载插件的应用使用这个对象来工作.

这种设计参考了 chrome 以及 fcitx 的设计, 这两个项目都没有采取固定位置直接放置 so 库的做法, 而是采取了如此通过配置文件来寻找真正要使用的插件的做法.

由于 AppDataLocation 尊重 XDG_DATA_DIR 环境变量1, 如此设计对于需要更改插件实际存放位置的情况来说比较友好.

Footnotes

  1. https://github.com/qt/qtbase/blob/d7e8d5bb1b5a9c4b21a3d824780c672eaf4e56b1/src/corelib/io/qstandardpaths_unix.cpp#L374

@github-actions

github-actions Bot commented Feb 16, 2023

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@black-desk
black-desk force-pushed the black-desk/dev/dplugin branch from 53937c9 to 1c26bc7 Compare February 16, 2023 15:33
@zccrs

zccrs commented Feb 20, 2023

Copy link
Copy Markdown
Member

@kegechen @zccrs @Groveer @justforlxz

这边希望给 DTK 添加一个通用的插件寻找机制, 方便需要使用插件来加载可选功能的应用编写.

这个机制目前设计如下:

应用会从 QT 给的 AppDataLocation 目录下的 plugins 文件夹中寻找配置文件. 配置文件中记录该插件的名称 版本和库名(也可以是绝对路径). 这些信息被用来初始化一个 QLibrary 对象. 需要加载插件的应用使用这个对象来工作.

这种设计参考了 chrome 以及 fcitx 的设计, 这两个项目都没有采取固定位置直接放置 so 库的做法, 而是采取了如此通过配置文件来寻找真正要使用的插件的做法.

由于 AppDataLocation 尊重 XDG_DATA_DIR 环境变量1, 如此设计对于需要更改插件实际存放位置的情况来说比较友好.

Footnotes

  1. https://github.com/qt/qtbase/blob/d7e8d5bb1b5a9c4b21a3d824780c672eaf4e56b1/src/corelib/io/qstandardpaths_unix.cpp#L374 leftwards_arrow_with_hook

为什么不直接使用 QPluginLoader 呢

@black-desk

black-desk commented Feb 20, 2023

Copy link
Copy Markdown
Author

为什么不直接使用 QPluginLoader 呢

重点并不在于加载库的具体过程,而在于插件加载的过程需要:

  1. 尊重XDG_DATA_DIRS环境变量
  2. 方便具体的库位置移动

这对nix/flatpak以及玲珑类的打包方式都很有意义。

Comment thread src/util/util.cmake
${CMAKE_CURRENT_LIST_DIR}/dvtablehook.cpp
${CMAKE_CURRENT_LIST_DIR}/dthreadutils.cpp
${CMAKE_CURRENT_LIST_DIR}/dtimedloop.cpp
set(UTILS_SOURCE ${UTILS_SOURCE}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using list(APPEND).

Comment thread include/util/dplugin.h

class DPluginPrivate;

class DPlugin : public QObject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should DPlugin derive from DObject? If yes, it's better to use D_DECLARE_PRIVATE. And remember to make DPluginPrivate derive from DObjectPrivate.

No logical change.
This commit implement DPlugin class. Documentation will be added later.
@black-desk
black-desk force-pushed the black-desk/dev/dplugin branch from 1c26bc7 to d2cc763 Compare March 6, 2023 08:27
@black-desk

Copy link
Copy Markdown
Author

想了想好像解决不了插件里面又加载了其他的so的问题, 我再考虑考虑怎么解决 这个先挂着

Comment thread src/util/dplugin.cpp
QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath)
{
auto const pluginDir = QDir(pluginDirPath);
auto const entryList = pluginDir.entryList();

@kegechen kegechen Jul 17, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以通过 QDir::Filter::Files 过滤一下,下面就不用判断是不是文件了

Comment thread src/util/dplugin.cpp
}

auto config = jsonDoc.object();
if (!DPluginPrivate::configCompatible(config["pluginConfigVersion"])) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • json 的示例文件可以在注释或者什么地方提供一下。
  • 既然已知是 plugin 的配置文件,是不是 json 中的 key 可以去掉 plugin 的前缀

Comment thread src/util/dplugin.cpp
return plugins;
}

QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath)
QList<std::shared_ptr<DPlugin>> DPluginPrivate::load(const QString &pluginDirPath)

@deepin-bot

deepin-bot Bot commented Jan 9, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.21
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #399

@deepin-bot

deepin-bot Bot commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.22
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #400

@deepin-bot

deepin-bot Bot commented Mar 11, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.25
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #406

@deepin-bot

deepin-bot Bot commented Mar 27, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.26
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #407

@deepin-bot

deepin-bot Bot commented Apr 23, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.27
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #410

@deepin-bot

deepin-bot Bot commented Apr 30, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.28
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #411

@deepin-bot

deepin-bot Bot commented May 16, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.29
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #415

@deepin-bot

deepin-bot Bot commented May 31, 2024

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 5.6.30
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #424

@black-desk black-desk closed this Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants