简体   繁体   English

基于插件架构的c / c ++应用程序

[英]plug-in architecture based c/c++ application

I need to know how to start writing an application based on plug-in architecture. 我需要知道如何开始编写基于插件架构的应用程序。 I mean how to write a base code and let others develop the application by adding the plug-ins they write. 我的意思是如何编写基本代码,让其他人通过添加他们编写的插件来开发应用程序。 I know that there is some problems in doing so in c++. 我知道在c ++中这样做有一些问题。 most people use another language such as python to add plug-ins to their c++ application. 大多数人使用python之类的其他语言将插件添加到他们的c ++应用程序中。

I think, this is not the answer you expect, but you could try to examine the Rainmeter sources. 我想,这不是你期望的答案,但你可以尝试检查Rainmeter的来源。 It's written in C++ (some places could be done better, to my mind, but overall it's ok) and the whole application is done the way so it just handles plugins. 它是用C ++编写的(有些地方可以做得更好,在我看来,但总的来说还可以)并且整个应用程序都是按照它处理插件的方式完成的。

Even the simple API is done via plugins, there is also a bunch of examples of contributed plugins, I mean, written by someone else (I did that too, one day). 即使是简单的API也是通过插件完成的,还有一堆贡献插件的例子,我的意思是,由别人写的(我也是这样做的,有一天)。

I think you could actually study a lot of new tricks in the plugin-based development by looking at other applications. 我认为你可以通过查看其他应用程序来研究基于插件的开发中的许多新技巧。

Also to mention, another good sample is Miranda IM . 另外,另一个好样本是Miranda IM

Edit: Also, if I han the same task, I would actually add some python (or something like that) backend to my application and use it as the language for SDK (for example, using boost::python ). 编辑:另外,如果我有相同的任务,我实际上会添加一些python (或类似的东西)后端到我的应用程序并使用它作为SDK的语言(例如,使用boost::python )。

You should : 你应该 :

  • define an interface 定义一个接口
  • load your plugin and give it this interface 加载你的插件并给它这个界面

Your plugin will be able communicate with the host application through this interface. 您的插件将能够通过此界面与主机应用程序进行通信。 That means, you must think carefully at what you want your plugins to do. 这意味着,您必须仔细考虑您希望插件的功能。

You will probably need to support various versions of the interface if your host application changes and you add functionnalities. 如果主机应用程序发生更改并添加了功能,则可能需要支持各种版本的接口。

could you define access points in your application where an external application could communicate with? 你可以在应用程序中定义外部应用程序可以与之通信的接入点吗?

let's say you define some named pipe mechanism or a TCP/IP socket, where the external application would call this API to manipulate your application? 假设您定义了一些命名管道机制或TCP / IP套接字,外部应用程序将调用此API来操作您的应用程序?

given that you need to register these plugins in the core application before allowing them to use your application. 鉴于您需要在允许它们使用您的应用程序之前在核心应用程序中注册这些插件。 you might even add public private certificates to authenticate the origin of this plugin, (ie to sign the plugin with a private key where instances of your application would validate against a public key) 您甚至可以添加公共私有证书来验证此插件的来源,(即使用私钥对插件进行签名,其中应用程序的实例将根据公钥进行验证)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM