Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
myhhub committed Mar 10, 2021
1 parent 8b07d45 commit a95aa3b
Show file tree
Hide file tree
Showing 170 changed files with 7,040 additions and 0 deletions.
11 changes: 11 additions & 0 deletions EventAdmin/SendEvent/App/App.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
QT += core gui widgets

TEMPLATE = app
CONFIG += console
TARGET = App
DESTDIR = $$OUT_PWD/../bin

include($$PWD/../CTK.pri)

SOURCES += \
main.cpp
43 changes: 43 additions & 0 deletions EventAdmin/SendEvent/App/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <QCoreApplication>
#include <QtDebug>
#include <ctkPluginFrameworkLauncher.h>
#include <ctkPluginContext.h>
#include <ctkPluginException.h>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

// 获取插件所在位置
// 在插件的搜索路径列表中添加一条路径
ctkPluginFrameworkLauncher::addSearchPath("../../../../CTKInstall/lib/ctk-0.1/plugins");
// 设置并启动 CTK 插件框架
ctkPluginFrameworkLauncher::start("org.commontk.eventadmin");
// 获取插件上下文
ctkPluginContext* context = ctkPluginFrameworkLauncher::getPluginContext();

QString path = QCoreApplication::applicationDirPath() + "/plugins";

// 启动插件 BlogEventHandler
try {
QSharedPointer<ctkPlugin> plugin = context->installPlugin(QUrl::fromLocalFile(path + "/BlogEventHandler.dll"));
plugin->start();
qDebug() << "BlogEventHandler start ...";
} catch (const ctkPluginException &e) {
qDebug() << "Failed to start BlogEventHandler" << e.what();
}

//启动插件 BlogManager
try {
QSharedPointer<ctkPlugin> plugin = context->installPlugin(QUrl::fromLocalFile(path + "/BlogManager.dll"));
plugin->start();
qDebug() << "BlogManager start ...";
} catch (const ctkPluginException &e) {
qDebug() << "Failed to start BlogManager" << e.what();
}

// 停止插件
ctkPluginFrameworkLauncher::stop();

return app.exec();
}
16 changes: 16 additions & 0 deletions EventAdmin/SendEvent/CTK.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CTK 安装路径
CTK_INSTALL_PATH = $$PWD/../../../CTKInstall

# CTK 插件相关库所在路径(例如:CTKCore.lib、CTKPluginFramework.lib)
CTK_LIB_PATH = $$CTK_INSTALL_PATH/lib/ctk-0.1

# CTK 插件相关头文件所在路径(例如:ctkPluginFramework.h)
CTK_INCLUDE_PATH = $$CTK_INSTALL_PATH/include/ctk-0.1

# CTK 插件相关头文件所在路径(主要因为用到了 service 相关东西)
CTK_INCLUDE_FRAMEWORK_PATH = $$PWD/../../../CTK-master/Libs/PluginFramework

LIBS += -L$$CTK_LIB_PATH -lCTKCore -lCTKPluginFramework

INCLUDEPATH += $$CTK_INCLUDE_PATH \
$$CTK_INCLUDE_FRAMEWORK_PATH
18 changes: 18 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogEventHandler/BlogEventHandler.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
QT += core
QT -= gui

TEMPLATE = lib
CONFIG += plugin
TARGET = BlogEventHandler
DESTDIR = $$OUT_PWD/../../bin/plugins

include($$PWD/../../CTK.pri)

HEADERS += \
blog_event_handler.h \
blog_event_handler_activator.h

SOURCES += \
blog_event_handler_activator.cpp

RESOURCES += Resource.qrc
8 changes: 8 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogEventHandler/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Plugin-SymbolicName: com.Waleon.EventHandler
Plugin-ActivationPolicy: eager
Plugin-Category: Demos
Plugin-ContactAddress: https://github.com/Waleon
Plugin-Description: A plugin for handle event
Plugin-Name: BlogEventHandler
Plugin-Vendor: Waleon
Plugin-Version: 1.0.0
5 changes: 5 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogEventHandler/Resource.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/BlogEventHandler/META-INF">
<file>MANIFEST.MF</file>
</qresource>
</RCC>
26 changes: 26 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogEventHandler/blog_event_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef BLOG_EVENT_HANDLER_H
#define BLOG_EVENT_HANDLER_H

#include <QObject>
#include <service/event/ctkEventHandler.h>

// 事件处理程序(或订阅者)
class BlogEventHandler : public QObject, public ctkEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)

public:
// 处理事件
void handleEvent(const ctkEvent& event) Q_DECL_OVERRIDE
{
QString title = event.getProperty("title").toString();
QString content = event.getProperty("content").toString();
QString author = event.getProperty("author").toString();

qDebug() << "EventHandler received the message, topic:" << event.getTopic()
<< "properties:" << "title:" << title << "content:" << content << "author:" << author;
}
};

#endif // BLOG_EVENT_HANDLER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "blog_event_handler.h"
#include "blog_event_handler_activator.h"
#include <service/event/ctkEventConstants.h>
#include <QtDebug>

void BlogEventHandlerActivator::start(ctkPluginContext* context)
{
m_pEventHandler = new BlogEventHandler();

ctkDictionary props;
props[ctkEventConstants::EVENT_TOPIC] = "org/commontk/bloggenerator/published";
props[ctkEventConstants::EVENT_FILTER] = "(author=Waleon)";
context->registerService<ctkEventHandler>(m_pEventHandler, props);
}

void BlogEventHandlerActivator::stop(ctkPluginContext* context)
{
Q_UNUSED(context)

delete m_pEventHandler;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BLOG_EVENT_HANDLER_ACTIVATOR_H
#define BLOG_EVENT_HANDLER_ACTIVATOR_H

#include <ctkPluginActivator.h>

class BlogEventHandler;

class BlogEventHandlerActivator : public QObject, public ctkPluginActivator
{
Q_OBJECT
Q_INTERFACES(ctkPluginActivator)
Q_PLUGIN_METADATA(IID "BLOG_EVENT_HANDLER")

public:
void start(ctkPluginContext* context);
void stop(ctkPluginContext* context);

private:
BlogEventHandler *m_pEventHandler;
};

#endif // BLOG_EVENT_HANDLER_ACTIVATOR_H
20 changes: 20 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/BlogManager.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
QT += core
QT -= gui

TEMPLATE = lib
CONFIG += plugin
TARGET = BlogManager
DESTDIR = $$OUT_PWD/../../bin/plugins

include($$PWD/../../CTK.pri)

HEADERS += \
blog_manager.h \
blog_manager_activator.h


SOURCES += \
blog_manager.cpp \
blog_manager_activator.cpp

RESOURCES += Resource.qrc
8 changes: 8 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Plugin-SymbolicName: com.Waleon.BlogManager
Plugin-ActivationPolicy: eager
Plugin-Category: Demos
Plugin-ContactAddress: https://github.com/Waleon
Plugin-Description: A plugin for publish blog
Plugin-Name: BlogManager
Plugin-Vendor: Waleon
Plugin-Version: 1.0.0
5 changes: 5 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/Resource.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/BlogManager/META-INF">
<file>MANIFEST.MF</file>
</qresource>
</RCC>
28 changes: 28 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/blog_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "blog_manager.h"
#include <service/event/ctkEventAdmin.h>
#include <QtDebug>

BlogManager::BlogManager(ctkPluginContext* context)
: m_pContext(context)
{

}

// 发布事件
void BlogManager::publishBlog(const Blog& blog)
{
ctkServiceReference ref = m_pContext->getServiceReference<ctkEventAdmin>();
if (ref) {
ctkEventAdmin* eventAdmin = m_pContext->getService<ctkEventAdmin>(ref);

ctkDictionary props;
props["title"] = blog.title;
props["content"] = blog.content;
props["author"] = blog.author;
ctkEvent event("org/commontk/bloggenerator/published", props);

qDebug() << "Publisher sends a message, properties:" << props;

eventAdmin->sendEvent(event);
}
}
24 changes: 24 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/blog_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef BLOG_MANAGER_H
#define BLOG_MANAGER_H

#include <ctkPluginContext.h>

typedef struct Blog_Info {
QString title;
QString author;
QString content;
} Blog;

// 事件发布者
class BlogManager
{
public:
BlogManager(ctkPluginContext* context);
// 发布事件
void publishBlog(const Blog& blog);

private:
ctkPluginContext* m_pContext;
};

#endif // BLOG_MANAGER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "blog_manager.h"
#include "blog_manager_activator.h"
#include <QtDebug>
void BlogManagerActivator::start(ctkPluginContext* context)
{
m_pBlogManager = new BlogManager(context);

Blog blog;
blog.title = "CTK Event Admin";
blog.content = "This is a simple blog";
blog.author = "Waleon";
m_pBlogManager->publishBlog(blog);
}

void BlogManagerActivator::stop(ctkPluginContext* context)
{
Q_UNUSED(context)

delete m_pBlogManager;
}
22 changes: 22 additions & 0 deletions EventAdmin/SendEvent/Plugins/BlogManager/blog_manager_activator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BLOG_MANAGER_ACTIVATOR_H
#define BLOG_MANAGER_ACTIVATOR_H

#include <ctkPluginActivator.h>

class BlogManager;

class BlogManagerActivator : public QObject, public ctkPluginActivator
{
Q_OBJECT
Q_INTERFACES(ctkPluginActivator)
Q_PLUGIN_METADATA(IID "BLOG_MANAGER")

public:
void start(ctkPluginContext* context);
void stop(ctkPluginContext* context);

private:
BlogManager *m_pBlogManager;
};

#endif // BLOG_MANAGER_ACTIVATOR_H
7 changes: 7 additions & 0 deletions EventAdmin/SendEvent/Plugins/Plugins.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TEMPLATE = subdirs

SUBDIRS += \
BlogManager \
BlogEventHandler

CONFIG += ordered
7 changes: 7 additions & 0 deletions EventAdmin/SendEvent/SendEvent.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TEMPLATE = subdirs

SUBDIRS += \
App \
Plugins

CONFIG += ordered
Loading

0 comments on commit a95aa3b

Please sign in to comment.