Commit 62ee3e06 by Carwyn

Revert "1. 基础接口调整,使用 InitService 初始化服务,UninitService 释放服务"

This reverts commit 9bb5223e.
parent 9bb5223e
......@@ -39,14 +39,14 @@ FMPLogger::~FMPLogger()
delete d_ptr;
}
void FMPLogger::InitService()
int FMPLogger::StartService()
{
d_func()->Init();
return d_func()->Init();
}
void FMPLogger::UninitService()
int FMPLogger::StopService()
{
d_func()->Uninit();
return d_func()->Uninit();
}
void FMPLogger::Log(short level, const QString &msg, const char* file, const char* func, int line)
......
......@@ -22,11 +22,10 @@ public:
explicit FMPLogger(ctkPluginContext *context);
~FMPLogger();
protected:
//! BaseInterface
void InitService();
void UninitService();
int StartService();
int StopService();
protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
public:
......
......@@ -28,7 +28,6 @@ unix {
#Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET)
#VER = 0.1.1
ORIGIN_TARGET = $$TARGET
TARGET = $${TARGET}_$${VER}
......
......@@ -82,18 +82,15 @@ public:
static
FMPLoggerInterface* InitContext(bool init = true, ctkPluginContext *ctx = nullptr)
FMPLoggerInterface* InitContext(ctkPluginContext *ctx = nullptr)
{
static FMPLoggerInterface *logger = nullptr;
if (init && ctx && !logger) {
if (ctx && !logger) {
ctkServiceReference ref = ctx->getServiceReference<FMPLoggerInterface>();
if (ref) {
logger = ctx->getService<FMPLoggerInterface>(ref);
}
}
else if (!init) {
logger = nullptr;
}
return logger;
}
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 45
#define VER_BUILD 43
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -25,9 +25,9 @@ FMPluginManager::~FMPluginManager()
StopService();
}
void FMPluginManager::InitService()
int FMPluginManager::StartService()
{
if (_fw_factory) return;
if (_fw_factory) return FMP_SUCCESS;
_fw_factory = new ctkPluginFrameworkFactory(_fw_props);
......@@ -94,45 +94,34 @@ void FMPluginManager::InitService()
FMP_ERROR() << e.cause()->what();
exit(FMP_FAILURE);
}
return FMP_SUCCESS;
}
void FMPluginManager::UninitService()
int FMPluginManager::StopService()
{
if (_fw_factory) {
FMP_INFO() << "======================== Quit ========================";
_watcher.removePath(_fw_props[FMP_PROPKEY_PLUGINPATH].toString());
_event_handlers.clear();
//! 优雅关闭
try {
// QList<ctkServiceReference> svcs = _ctx->getServiceReferences();
// foreach(ctkServiceReference s, svcs) {
// QSharedPointer<ctkPlugin> p = s.getPlugin();
// qDebug() << p->getSymbolicName() << p->getPluginId() << "---";
// if (p->getPluginId() > 0) {
// p->stop();
// }
// }
_fw->stop();
while(_fw->waitForStop(200).getType() == ctkPluginFrameworkEvent::FRAMEWORK_WAIT_TIMEDOUT) {
QCoreApplication::processEvents();
}
}
catch (const ctkPluginException& e) {
FMP_ERROR() << e.cause()->what();
}
delete _fw_factory;
_fw_factory = nullptr;
_ctx = nullptr;
_fw.clear();
_event_handlers.clear();
//! TODO: 优雅关闭
// if (_fw_factory) {
// delete _fw_factory;
// _fw_factory = nullptr;
// _ctx = nullptr;
// _fw.clear();
// }
qApp->quit();
}
else {
FMP_WARN() << "Stopping in progress...";
}
return FMP_SUCCESS;
}
int FMPluginManager::SetProperties(const FMPProps &props)
......@@ -198,9 +187,6 @@ int FMPluginManager::UpgradePlugin(long pid)
if (p) {
QString plugin_name = p->getSymbolicName();
p->stop();
//! TODO: 检查停止之前,服务是否处理启动状态,
//! 如果是,则需要启动服务
return LoadPlugin(plugin_name);
}
......@@ -232,7 +218,6 @@ void FMPluginManager::OnPluginsChanged(const QString &path)
if (!expired_plugins.isEmpty()) {
FMPProps props;
props[FMP_PROPKEY_PID_LIST] = expired_plugins;
//! Request plugin update
PostEvent(QString(FMP_TOPICS_SERVICES) + FMPE_SERVICE_REQ_UPDATE, props);
}
}
......
......@@ -32,25 +32,20 @@ public:
explicit FMPluginManager();
~FMPluginManager();
protected:
//! 基础接口
void InitService();
void UninitService();
int StartService();
int StopService();
int SetProperties(const FMPProps &props);
protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
public:
//! 管理器接口
void LoadNewPlugins();
int LoadPlugin(const QString &plugin);
void UpgradeOldPlugins(const QVariantList &);
int UpgradePlugin(long pid);
int SetProperties(const FMPProps &props);
public slots:
void OnStartService() { StartService(); }
void OnStopService() { StopService(); }
void UpgradeOldPlugins(const QVariantList &);
public slots:
void OnPluginsChanged(const QString &path);
......
#include <fmp_logger_i.h>
#include "fmp_me_handlers.h"
#include "fmp_manager.h"
#include <QCoreApplication>
/**
* @brief 管理器事件默认构造函数
......@@ -20,33 +19,28 @@ FMPManagerEventHandler::FMPManagerEventHandler(const QString &topic, FMPluginMan
/**
* @brief 升级事件处理方法
*/
FMPUpgradeEventHandler::FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_UPDATE, pm, ctx)
{
connect(this, SIGNAL(upgrade(QVariantList)), _pm, SLOT(UpgradeOldPlugins(QVariantList)));
}
void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event)
{
if (!event.getProperty(FMP_PROPKEY_PID_LIST).toList().isEmpty()) {
emit upgrade(event.getProperty(FMP_PROPKEY_PID_LIST).toList());
if (_pm) {
if (event.getProperty(FMP_PROPKEY_AGREED).toBool()) {
_pm->UpgradeOldPlugins(event.getProperty(FMP_PROPKEY_PID_LIST).toList());
}
}
else {
FMP_DEBUG() << "No plugin ids." << event.getTopic();
FMP_DEBUG() << "No handler instance for event" << event.getTopic();
}
}
/**
* @brief 退出事件处理方法
*/
FMPQuitEventHandler::FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_QUIT, pm, ctx)
{
connect(this, SIGNAL(quit()), _pm, SLOT(OnStopService()));
}
void FMPQuitEventHandler::handleEvent(const ctkEvent &event)
{
emit quit();
if (_pm) {
_pm->deleteLater();
}
else {
FMP_DEBUG() << "No handler instance for event" << event.getTopic();
}
}
......@@ -35,13 +35,12 @@ class FMPUpgradeEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public:
explicit FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm);
explicit FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_UPDATE, pm, ctx)
{}
void handleEvent(const ctkEvent &event);
signals:
void upgrade(const QVariantList &pid_list);
private:
};
......@@ -53,12 +52,11 @@ class FMPQuitEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public:
explicit FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm);
explicit FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_QUIT, pm, ctx)
{}
void handleEvent(const ctkEvent &event);
signals:
void quit();
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 45
#define VER_BUILD 43
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -13,14 +13,14 @@ FMPNetwork::FMPNetwork(ctkPluginContext *ctx)
FMPLoggerInterface::InitContext(ctx);
}
void FMPNetwork::InitService()
int FMPNetwork::StartService()
{
//! FMP_NOIMPL;
return FMP_NOIMPL;
}
void FMPNetwork::UninitService()
int FMPNetwork::StopService()
{
//! FMP_NOIMPL;
return FMP_NOIMPL;
}
int FMPNetwork::PostEvent(const QString &topic, const FMPProps &pps)
......
......@@ -17,13 +17,10 @@ class FMPNetwork : public QObject, public FMPNetworkInterface
public:
explicit FMPNetwork(ctkPluginContext *ctx);
//! 基础插件接口
//!
protected:
void InitService();
void UninitService();
int StartService();
int StopService();
int PostEvent(const QString &topic, const FMPProps &pps);
public:
//! 网络服务接口
FMPHttpReplyPointer HttpGet(const FMPHttpRequest &req);
FMPHttpReplyPointer HttpPost(const FMPHttpRequest &req, const QByteArray &data);
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 45
#define VER_BUILD 43
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -20,23 +20,19 @@ FMPSyncer::FMPSyncer(ctkPluginContext *ctx)
StartService();
}
FMPSyncer::~FMPSyncer()
int FMPSyncer::StartService()
{
StopService();
return d_func()->Init();
}
void FMPSyncer::InitService()
{
d_func()->Init();
}
void FMPSyncer::UninitService()
int FMPSyncer::StopService()
{
if (d_ptr) {
d_ptr->terminate();
delete d_ptr;
d_ptr = nullptr;
}
return FMP_SUCCESS;
}
int FMPSyncer::PostEvent(const QString &topic, const FMPProps &pps)
......
......@@ -16,12 +16,11 @@ class FMPSyncer : public QObject, public FMPSyncerInterface
public:
explicit FMPSyncer(ctkPluginContext *ctx);
virtual ~FMPSyncer();
protected:
//! BaseInterface
void InitService();
void UninitService();
int StartService();
int StopService();
protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
public:
//! SyncInterface
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 45
#define VER_BUILD 43
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -5,9 +5,6 @@
//! 插件错误代码
#define FMP_SUCCESS 0
#define FMP_START_PENDING 1
#define FMP_STOP_PENDING 2
#define FMP_FAILURE -1
#define FMP_REFUSED -2
#define FMP_NOIMPL -3
......
......@@ -21,14 +21,14 @@ public:
* 失败返回 \link FMP_FAILURE \endlink。
* FMP_REFUSED
*/
virtual int StartService() { InitService(); return FMP_SUCCESS; }
virtual int StartService() = 0;
/**
* 停止插件服务
* @brief StopService
* @return
*/
virtual int StopService() { UninitService(); return FMP_SUCCESS; }
virtual int StopService() = 0;
/**
* 获取插件服务
......@@ -49,9 +49,6 @@ public:
}
protected:
virtual void InitService() = 0;
virtual void UninitService() = 0;
/**
* 异步发送插件事件
* @brief PostEvent
......
......@@ -8,7 +8,6 @@
#include <fmp_base_i.h>
#include <fmp_logger_i.h>
#include <QSemaphore>
#include <ctkPluginContext.h>
#include <service/event/ctkEventAdmin.h>
......@@ -17,16 +16,9 @@ class ctkPluginContext;
class FMPluginInterface : public FMPBaseInterface
{
public:
explicit FMPluginInterface(ctkPluginContext *ctx) : _ctx(ctx) {}
explicit FMPluginInterface(ctkPluginContext *ctx) : _ctx(ctx){}
/**
* 业务插件启动只能请求启动,由事件订阅者决定是否允许启动
* -允许:订阅者通知业务插件,业务插件事件处理器触发 TriggerInit
* -拒绝:订阅者通知业务插件
* @brief StartService
* @return
*/
virtual int StartService()
int StartService()
{
QString topic = FMP_TOPICS_SERVICES;
topic += FMPE_SERVICE_REQ_START;
......@@ -34,22 +26,7 @@ public:
return PostEvent(topic);
}
/**
* 默认异步启动插件,以确保业务资源释放都在主线程中
* @brief StopService
* @return
*/
virtual int StopService()
{
TriggerUninit();
_semaphore.acquire(1);
return FMP_SUCCESS;
}
protected:
virtual void TriggerInit() = 0;
virtual void TriggerUninit() = 0;
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps())
{
ctkEventAdmin *event_admin = GetService<ctkEventAdmin>(_ctx);
......@@ -68,7 +45,6 @@ protected:
protected:
ctkPluginContext *_ctx;
QSemaphore _semaphore;
};
Q_DECLARE_INTERFACE(FMPluginInterface, "com.fmp.plugin")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment