首页 > 编程语言 >C++插件管理系统

C++插件管理系统

时间:2024-09-12 21:23:02浏览次数:3  
标签:std 插件 plugify 管理系统 module C++ cpp include untrustedmodders

插件加载目录结构

execute
    plug.exe
    plugify.dll
    plugify.pconfig
    res
        cpp-lang-module.pmodule
        example_plugin.pplugin
        bin
            cpp-lang-module.dll
            example_plugin.dll

 plugify.pconfig

{
    "baseDir": "res",
    "logSeverity": "debug",
    "repositories": [
    ],
    "preferOwnSymbols": false
}

example_plugin.pplugin

{
    "fileVersion": 1,
    "version": 1,
    "versionName": "1.0",
    "friendlyName": "PluginCPP",
    "description": "An example of a plugin. This can be used as a starting point when creating your own plugin.",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/orgs/untrustedmodders/README.md",
    "downloadURL": "https://github.com/orgs/untrustedmodders/example-repo.zip",
    "updateURL": "https://github.com/untrustedmodders/plugify/issues",
    "entryPoint": "bin/example_plugin",
    "supportedPlatforms": [],
    "languageModule": {
        "name": "cpp"
    },
    "dependencies": [],
    "exportedMethods": [
        {
            "name": "MakePrint",
            "funcName": "MakePrint",
            "paramTypes": [
                {
                    "type": "int32",
                    "name": "count"
                },
                {
                    "type": "string",
                    "name": "message"
                }
            ],
            "retType": {
                "type": "void"
            }
        }
    ]
}

 cpp-lang-module.pmodule

{
    "fileVersion": 1,
    "version": 0,
    "versionName": "v0",
    "friendlyName": "Cpp language module",
    "language": "cpp",
    "description": "Adds support for C++ plugins",
    "createdBy": "untrustedmodders",
    "createdByURL": "https://github.com/untrustedmodders/",
    "docsURL": "https://github.com/untrustedmodders/cpp-lang-module/blob/main/README.md",
    "downloadURL": "https://github.com/untrustedmodders/cpp-lang-module/releases/download/v0/cpp-lang-module.zip",
    "updateURL": "https://untrustedmodders.github.io/cpp-lang-module/cpp-lang-module.json",
    "supportedPlatforms": [],
    "forceLoad": false
}

 插件定义
#include <plugify/cpp_plugin.h>
#include <plugin_export.h>
#include <iostream>

class ExamplePlugin : public plugify::IPluginEntry {
public:
	void OnPluginStart() override {
		std::cout << "Example Start!" << std::endl;
	}

	void OnPluginEnd() override {
		std::cout << "Example End!" << std::endl;
	}

	void MakePrint(int count, const std::string& message) {
		for (int i = 0; i < count; ++i) {
			std::cout << message << std::endl;
		}
	}
} g_examplePlugin;

EXPOSE_PLUGIN(PLUGIN_API, &g_examplePlugin)

extern "C"
PLUGIN_API void MakePrint(int count, const std::string& message) {
	g_examplePlugin.MakePrint(count, message);
}
 模块定义

#include <plugify/assembly.h>
#include <plugify/module.h>
#include <plugify/plugin.h>
#include <plugify/plugify_provider.h>
#include <plugify/language_module.h>
#include <plugify/cpp_plugin.h>

#include <module_export.h>
#include <unordered_map>
#include <map>
#include <array>

class CppLanguageModule final : public plugify::ILanguageModule {
public:
	CppLanguageModule() = default;

	// ILanguageModule
	plugify::InitResult Initialize(std::weak_ptr<plugify::IPlugifyProvider> provider, plugify::ModuleRef module) override;
	void Shutdown() override;
	void OnMethodExport(plugify::PluginRef plugin) override;
	plugify::LoadResult OnPluginLoad(plugify::PluginRef plugin) override;
	void OnPluginStart(plugify::PluginRef plugin) override;
	void OnPluginEnd(plugify::PluginRef plugin) override;
	bool IsDebugBuild() override;

	const std::shared_ptr<plugify::IPlugifyProvider>& GetProvider() { return _provider; }
	plugify::MemAddr GetNativeMethod(std::string_view methodName) const;
	void GetNativeMethod(std::string_view methodName, plugify::MemAddr* addressDest);

private:
	std::shared_ptr<plugify::IPlugifyProvider> _provider;
	
	std::map<plugify::UniqueId, AssemblyHolder> _assemblyMap;
	std::unordered_map<std::string, plugify::MemAddr, string_hash, std::equal_to<>> _nativesMap;
	
	std::vector<plugify::MemAddr*> _addresses;

	static std::array<void*, 15> _pluginApi;
};

// ILanguageModule
InitResult CppLanguageModule::Initialize(std::weak_ptr<IPlugifyProvider> provider, ModuleRef /*module*/) {
	if (!(_provider = provider.lock())) {
		return ErrorData{ "Provider not exposed" };
	}

	_provider->Log("[CPPLM]  Inited!", Severity::Debug);

	return InitResultData{};
}
 测试
plug.exe
plugify init
[+] Info: Plugify Init!
[+] Info: Version: 1.0.0.0
[+] Info: Git: [v35-1-g08987de]:(v35) - Fix cmake typo in test on main at 'Sun Sep 1 09:21:31 2024'
[+] Info: Compiled on: Windows-10.0.19045 from: Ninja with: 'MSVC'
[~] Debug: Loading local packages
[~] Debug: Loading remote packages
[#] Error: Packages manifest from 'https://github.com/untrustedmodders/plugify/issues' has JSON parsing error: 8:1: expected_brace
   <!DOCTYPE html>
   ^
[~] Debug: PackageManager loaded in 788.826ms
[~] Debug: [CPPLM] Inited!
Example Start!
[~] Debug: PluginManager loaded in 10.951ms
 参考

GitHub - untrustedmodders/cpp-lang-module: C++ Language Module


 

创作不易,小小的支持一下吧!

标签:std,插件,plugify,管理系统,module,C++,cpp,include,untrustedmodders
From: https://blog.csdn.net/qq_30220519/article/details/142058580

相关文章

  • C++---string类常见接口
    介绍 string类详情===>>>https://cplusplus.com/reference/string/string/?kw=string1.string是表示字符串的字符串类(感觉就像一个动态的字符数组)2.该类的接口与常规容器的接口基本相同,再添加了一些专门用来操作string的常规操作。3.string在底层实际是:basic_string模......
  • C++入门基础知识64——【关于 C+++数据抽象】
    成长路上不孤单......
  • C++音视频毕设项目计划书
    最近我经常收到私信,询问如何准备秋季招聘,以及学生阶段如何参与实习或进行小项目来提升自己的技能。我个人建议,找到相关行业的公司进行实习是个不错的选择。不过,自己也可以尝试做一些小项目,不断改进和优化,以提升动手能力。以下是一个音视频项目计划书,分享给大家:项目开发计划书:流媒......
  • C++读取命令行参数的学习(BOOST库)
    在c++工程中,经常需要通过命令行参数来获取程序运行所需要的信息。作者在实际工作中学习了Boost库,这里根据作者的理解,写了一个依托boost库完成命令行参数提取的程序模版,请大佬批评!!#defineOK0#defineExit-99//主程序#include<iostream>#include"XApp.h"intmain(int......
  • Springboot大学生志愿者服务智慧管理系统094zx程序+源码+数据库+调试部署+开发环境
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、项目背景与意义随着社会的快速发展,大学生志愿者服务已成为连接校园与社会的重要桥梁,对促进青年成长、服务社会发挥着不可估量的作用。然而,传统......
  • Springboot大学生心理健康管理系统的设计与实现zw779
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、研究背景与意义随着社会竞争的加剧和生活节奏的加快,大学生群体面临着巨大的学业、就业和人际关系等多重压力,心理健康问题日益凸显。传统心理健......
  • Springboot第二课堂素质学分管理系统fma2s--(程序+源码+数据库+调试部署+开发环境)
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、项目背景随着教育改革的深入,高校越来越重视学生的全面发展,第二课堂作为培养学生综合素质的重要平台,其重要性日益凸显。然而,传统的管理方式存在......
  • 基于python+flask框架的社区健康数据管理系统APP(开题+程序+论文) 计算机毕设
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容研究背景在当今社会,随着人们生活水平的提高和健康意识的增强,对健康管理的需求日益迫切。然而,传统的健康管理方式往往依赖于个人自觉或医疗机构的有......
  • 基于SpringBoot+Vue+uniapp的敏捷工贸公司销售管理系统(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 题解 力扣 LeetCode 105 从前序与中序遍历序列构造二叉树 C/C++
    题目传送门:105.从前序与中序遍历序列构造二叉树-力扣(LeetCode)https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/description/每次在中序遍历序列片段中找到前序遍历序列队首,这是该层的根节点该位置左侧是左子树,右侧是右子树再......