CTK 插件框架介绍

CTK 插件框架介绍CTKPluginFramework:IntroductionTheCTKPluginFrameworkcanshortlybedescribedasadynamiccomponentsystemforC++.CTK插件框架可以简要的描

大家好,又见面了,我是你们的朋友全栈君。

CTK Plugin Framework: Introduction

The CTK Plugin Framework can shortly be described as a dynamic component system for C++.

CTK 插件框架可以简要的描述为一个c++动态组件系统。

Contents

[hide]

Design

The design of the CTK Plugin Framework (see also the Design Document) is heavily inspired by OSGi (a dynamic component system for Java) and enablesa development model where applications are (dynamically) composed of many different (reusable) components. This modelallows to communicate throughservices, which are objects that are specifically shared between components.

The framework’s layered model is illustrated in Figure 1, containing:

CTK 插件框架介绍

Figure 1: Layered Model of the CTK Plugin Framework

  • Plugins – Plugins are the CTK components created by the developers.
  • Services Layer – Connects plugins in a dynamic way by offering a publish-find-bind model for C++ objects.
  • Life Cycle Layer – The API to install, start, stop, update, and uninstall plugins.
  • Security – Handles security aspects (not available yet)

A more detailed explanation of these concepts can be found below.

Plugins

A CTK Plugin is, at it’s core, a shared library based on the Qt Plugin system.Additionally, symbols in CTK libraries are by default hidden across all platforms. This is the first step towardsmodularity,which is about keeping things local and not shared. The less things you share, the less wrong assumptions can be made. However, withoutsharing there can be no collaboration. CTK Plugins usually only share symbols (classes and functions) to support the CTK services model.

Services

A collaborative model in C++ is usually realized with the use of factory patterns. Different toolkits use different patterns and APIto access such a factory. Very often, influencing the decision about which implementation is used by the factory is non-trivial. Further, theimplementation code can usually not advertise its availability, nor can the user list the possible implementations and pick the most suitableone. Factories are also in general not dynamic, once an instance of an implementation is registered, it can not be withdrawn. Finally, ifmany different factories are in use, there is no centralized overview of the implementations to which your code is bound.

One solution to these issues is the CTK service registry. A plugin can create an object and register it with the CTK service registry underone or moreinterfaces (an interface is a C++ class with usually only pure virtual methods). Other plugins can ask the registry to list all services (objects)that are registered under a specific interface. A plugin may even wait for a specific service to appear and then get a call back.

A plugin can therefore register a service, it can get a service, and it canlisten for a service to appear or disappear.An arbitrary number of plugins can register services under the same interface, and any number of plugins can get the same service, see Figure 2.

CTK 插件框架介绍

Figure 2: Registering and getting a service

If multiple plugins register objects under the same interface, they can be distinguished by theirproperties. Each service registration has a set ofstandard and custom properties. You can use an expressive filter language to select only the services in which you are interested. Properties canalso be used for other roles at the application level.

Since services are dynamic, a plugin can decide to withdraw its service from the registry while other plugins are still using it. Plugins using sucha service must then ensure that they no longer use the service object and drop any pointers to it. This may sound like a significantadditional complexity at first, but using helper classes likectkServiceTracker and aframework like Declarative Services (to be developed) can make this process straight-forward and the gained advantages are quite large.The dynamic nature of services allows to install and uninstall plugins on the fly while other plugins stay functional. It also models real worldproblems closer because most often, such problems are not static. For example in a distributed environment a service could model a connection end-pointand if the connection to the remote machine is gone, the service can be withdrawn. Further, the dynamics solve the initialization problem. Applicationsusing CTK Plugins do not require a specific start ordering in their plugins.

Though the service registry accepts any QObject-based object as a service, the best way to achieve reuse is to register these objects under (standard)interfaces to decouple the implementation from the client code. Hence the CTK Plugin Framework provides a number of standard interfaces which aredesigned closely to the service specifications published in theOSGi Service Platform Release 4 Compendium Specification.These standard services are described in detail in the specification and on this Wiki.

Deployment

The CTK Plugin Framework can be used as the main container for all your application logic, but it can also be embedded in your existing framework.The management of the framework is standardized by providing a simple API allowing plugins to install, start, stop, and update other plugins,as well as enumerating the plugins and their service usage. This APIcan be used by so-calledmanagement agents to control the Plugin Framework. Management agents can be as diverse as command shells, richgraphical desktop applications, or an AJAX-application.

Benefits

The CTK Plugin Framework is based on OSGi principles and APIs. As such, it inherits a very mature and thoroughly designed component system thatis used in the Java world to build highly complex applications. It brings those benefits to native (Qt based) C++ applications. The following listis taken from Benefits of Using OSGi and adapted to the CTK context.

Reduced Complexity

Developing with the CTK Plugin Framework means developing plugins. They hide their internals from other plugins and communicate through well defined
services. Hiding internals means more freedom to change later. This not only reduces the number of bugs, it also makes plugins simpler to develop because correctly sized plugins implement a piece of functionality through well defined interfaces.

Reuse

The standardized component model makes it very easy to use third party components in an application.

Real World

The CTK Plugin Framework is dynamic. It can update plugins on the fly and services can come and go. There are a surprising number of real world scenarios that match this dynamic service model. Applications can therefore reuse the powerful primitives of the service registry (register, get, list with an expressive filter language, and waiting for services to appear and disappear) in their own domain. This not only saves writing code, it also provides global visibility, debugging tools, and more functionality than would have implemented for a dedicated solution. Writing code in such a dynamic environment sounds like a nightmare, but fortunately, there are support classes and frameworks that take most, if not all, of the pain out of it.

Easy Deployment

The CTK Plugin Framework is not just a standard for components. It also specifies how components are installed and managed. This API can be used by plugins to provide a management agent. This management agent can be as simple as a command shell, a graphical desktop application, a cloud computing interface for Amazon’s EC2, or an IBM Tivoli management system. The standardized management API makes it very easy to integrate the CTK Plugin Framework in existing and future systems.

Dynamic Updates

The used OSGi component model is a dynamic model. Plugins can be installed, started, stopped, updated, and uninstalled without bringing down the whole system.

Adaptive

The used OSGi component model is designed from the ground up to allow the mixing and matching of components. This requires that the dependencies of components need to be specified and it requires components to live in an environment where their optional dependencies are not always available. The service registry is a dynamic registry where plugins can register, get, and listen to services. This dynamic service model allows plugins to find out what capabilities are available on the system and adapt the functionality they can provide. This makes code more flexible and resilient to changes.

Transparency

Plugins and services are first class citizens in the CTK Plugin environment. The management API provides access to the internal state of a plugin as well as how it is connected to other plugins. Parts of the applications can be stopped to debug a certain problem, or diagnostic plugins can be brought in.

Versioning

In the CTK Plugin Framework, all plugins are carefully versioned and only plugins that can collaborate are wired together.

Simple

The CTK Plugin API is surprisingly simple. The core API is less than 25 classes. This core API is sufficient to write plugins, install them, start, stop, update, and uninstall them and includes all listener classes.

Lazy

Lazy in software is good and the used OSGi technology has many mechanisms in place to do things only when they are really needed. For example, plugins can be started eagerly, but they can also be configured to only start when another plugin is using them. Services can be registered but only created when they are used. These kind of lazy scenarios can save tremendous runtime costs.

Humble

The CTK Plugin Framework does not take over your whole application. You can choose to expose the provided functionality to just parts of your application, or even run multiple instances of the framework inside the same process.

Non Intrusive

Applications (plugins) in a CTK Plugin environment are left to their own. They can use any facilities without the framework restricting them. There is no special interface required for CTK services, every QObject can act as a service and every class (also non-QObject based) can act as an interface.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/137564.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 系统日志管理[通俗易懂]

    系统日志管理[通俗易懂]1、日志的查看日志可以记录下系统所产生的所有行为,并按照某种规范表达出来。我们可以使用日志系统所记录的信息为系统进行排错,优化系统的性能,或者根据这些信息调整系统的行为。收集你想要的数据,分析出有价值的信息,可以提高系统、产品的安全性,可以帮助开发完善代码,优化产品。日志会成为在事故发生后查明“发生了什么”的一个很好的“取证”信息来源。日志可以为审计进行审计跟踪。系统用久了偶尔也会出现一

    2022年4月29日
    27
  • Pycharm中的代码调试基本步骤

    Pycharm中的代码调试基本步骤文章目录步骤一、在所选行点击鼠标左键,此时会出现红点标记,若想取消再点击一次即可步骤二、在空白处单击鼠标右键,并点击DEBUG选项步骤三、点击控制台相关的功能按键就行调试步骤一、在所选行点击鼠标左键,此时会出现红点标记,若想取消再点击一次即可步骤二、在空白处单击鼠标右键,并点击DEBUG选项步骤三、点击控制台相关的功能按键就行调试…

    2022年8月28日
    2
  • 五个步骤教你数据清洗_数据仓库ods层

    五个步骤教你数据清洗_数据仓库ods层关于ODS层是否做数据清洗一直是存在争议的,但有一点是可以确定的,对于比较重的清洗工作是要留到后面数仓的ETL过程中进行处理。但是,有这么一种情况:我们在长期的生产实际过程中,发现部分已知的数据问题的处理可以通过自动化的方式来处理,这种方式通常在数据入库之前,做额外的加工处理后再做入库操作。数据清洗的主要工作是处理那些不符合要求的数据,从而提升数据质量,比如一些常见的问题:错误的数据、重复的数据错误的数据这种错误通常是业务系统处理不够健全造成的,比如字符串数据后面有回车空格、日期格式不正确、日期

    2022年10月5日
    0
  • android 点餐系统「建议收藏」

    android 点餐系统「建议收藏」      最近进入一家新公司,这家公司是做手机软件开发的。现在自己是试习期,主要任务是看书。看了有一个月了实在是无聊,就想做个手机软件来玩玩。想到之前看到一篇报道,台湾有家餐饮公司用IPAD给客户自助点餐。我就想再android系统上做一下。想了也有一个多星期了,准备开始开工了。     系统主要是四个模块。顾客端,系统管理端,厨师端,数据库端。它们的主要流程如下:     其他的系统分析

    2022年6月19日
    45
  • 图的存储及遍历 深度遍历和广度遍历 C++代码实现

    写这个程序给我的感觉就是乱,思路不是很清晰,遍历的逻辑关系还掌握的不是很熟,只是大概知道是这么回事,但是让自己去写的话,可能就写不出来了!还是要加大对遍历的熟悉程度才行啊!PS:另外推荐一个让大家真

    2021年12月25日
    37
  • 逻辑斯蒂回归(Logistic Regression)

    logistic回归logistic回归经常被人译为“逻辑回归“,虽然我个人认为貌似并没有什么关联,但下面就姑且这么叫吧。逻辑回归虽然是名字里带着回归,但其实是一种解决分类问题的算法,说到分类就有分几类的区别,本篇我们只讨论用于二分类问题的逻辑回归。基本的线性回归的形式为:y=ωTx+by=ωTx+by=\omega^{T}x+b线性回归模型产生的预测值是一系列实值。为了使得输…

    2022年4月4日
    42

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号