Commit 32832ecf by Carwyn

1.同步基础接口InitService/UninitService

parent b1ddd768
......@@ -2,8 +2,9 @@
#include "fmp_he_handlers.h"
#include "fmp_home.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
: FMPHomeEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_START "/*" , home),
FMPHomeEventHandler::FMPHomeEventHandler(const QString &topic, FMPHome *home, ctkPluginContext *ctx)
: _home(home),
_topic(topic),
_ctx(ctx)
{
FMPProps props;
......@@ -11,6 +12,11 @@ FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
_ctx->registerService<ctkEventHandler>(this, props);
}
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
: FMPHomeEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_START "/*", home, ctx)
{
// connect();
}
void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{
......@@ -26,3 +32,22 @@ void FMPStartEventHandler::handleEvent(const ctkEvent &event)
FMP_DEBUG() << "No handler instance for event" << event.getTopic();
}
}
FMPUpgradeAckEventHandler::FMPUpgradeAckEventHandler(ctkPluginContext *ctx, FMPHome *home)
: FMPHomeEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_UPDATE "/*" , home, ctx)
{
}
void FMPUpgradeAckEventHandler::handleEvent(const ctkEvent &event)
{
if (_home) {
QString ack_topic = event.getTopic();
//! com/fmp/services/REQ_START/id
ack_topic.replace(FMPE_SERVICE_REQ_UPDATE, FMPE_SERVICE_ACK_UPDATE);
FMPProps props;
//! TODO:
// props[FMP_PROPKEY_AGREED] = _home->isLogined();
// _home->PostEvent(ack_topic, props);
}
}
......@@ -7,26 +7,33 @@
class FMPHome;
class FMPHomeEventHandler : public ctkEventHandler
class FMPHomeEventHandler : public QObject, public ctkEventHandler
{
public:
explicit FMPHomeEventHandler(const QString &topic, FMPHome *home) : _home(home), _topic(topic) {}
explicit FMPHomeEventHandler(const QString &topic, FMPHome *home, ctkPluginContext *ctx);
protected:
FMPHome* _home;
const QString _topic;
ctkPluginContext* _ctx;
};
class FMPStartEventHandler : public QObject, public FMPHomeEventHandler
class FMPStartEventHandler : public FMPHomeEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event);
};
private:
ctkPluginContext* _ctx;
class FMPUpgradeAckEventHandler : FMPHomeEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPUpgradeAckEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event);
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
......@@ -7,31 +7,31 @@ FMPHome::FMPHome(ctkPluginContext *context)
d_ptr(new FMPHomePrivate(this)),
_inited(false)
{
}
FMPHome::~FMPHome()
{
StopService();
delete d_ptr;
}
int FMPHome::StartService()
{
if (_inited) return FMP_SUCCESS;
Q_D(FMPHome);
return d->Init();
}
int FMPHome::StopService()
void FMPHome::InitService()
{
if (!_inited) return FMP_SUCCESS;
if (!_inited) {
Q_D(FMPHome);
return d->Uninit();
d->Init();
}
_semaphore.release(1);
}
void FMPHome::StartPlugins(const QVariantList &pids)
void FMPHome::UninitService()
{
if (_inited) {
Q_D(FMPHome);
d->StartPlugins(pids);
d->Uninit();
}
_semaphore.release(1);
}
int FMPHome::login()
......@@ -70,3 +70,4 @@ void FMPHome::notification(const QString &msg, const QString &title,
Q_D(FMPHome);
return d->notification(msg, title, icon, mecs);
}
......@@ -10,20 +10,16 @@ class ctkPluginContext;
class FMPHomePrivate;
class FMPStartEventHandler;
class FMPHome : public QObject, public FMPHomeInterface
class FMPHome : public FMPHomeInterface
{
Q_OBJECT
Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPluginInterface)
Q_INTERFACES(FMPHomeInterface)
Q_DECLARE_PRIVATE(FMPHome)
public:
explicit FMPHome(ctkPluginContext *context);
~FMPHome();
int StartService();
int StopService();
void StartPlugins(const QVariantList &pids);
virtual ~FMPHome();
int login();
bool isLogined();
......@@ -34,11 +30,14 @@ public:
void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME),
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000);
protected slots:
virtual void InitService();
virtual void UninitService();
private:
friend class FMPStartEventHandler;
FMPHomePrivate *d_ptr;
bool _inited;
friend class FMPStartEventHandler;
};
#endif // FMP_HOME_H
......@@ -49,6 +49,7 @@ unix {
#Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET)
#VER = 0.1.1
ORIGIN_TARGET = $$TARGET
TARGET = $${TARGET}_$${VER}
......
......@@ -4,15 +4,34 @@
#include <fmp_plugin_i.h>
#include <QSystemTrayIcon>
class FMPHomeInterface : public FMPluginInterface
class FMPHomeInterface : public QObject, public FMPluginInterface
{
Q_OBJECT
Q_INTERFACES(FMPluginInterface)
public:
explicit FMPHomeInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx) {}
explicit FMPHomeInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx)
{
connect(this, &FMPHomeInterface::TriggerInit, this, &FMPHomeInterface::InitService);
connect(this, &FMPHomeInterface::TriggerUninit, this, &FMPHomeInterface::UninitService);
}
virtual int login() = 0;
virtual bool isLogined() = 0;
virtual QString userName() = 0;
/**
* Entry 插件不需要请求启动,直接执行 StartService 启动
* 默认异步启动插件,以确保业务资源分配都在主线程中
* @brief StartService
* @return
*/
virtual int StartService()
{
TriggerInit();
_semaphore.acquire(1);
return FMP_SUCCESS;
}
/**
* @brief blink
* 在导航窗口中闪烁某张图片,并在下次点击导航窗口时唤起传入的插件
* @param plugin 要换起的插件对象
......@@ -38,6 +57,13 @@ public:
*/
virtual void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME),
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000) = 0;
protected slots:
void InitService() = 0;
void UninitService() = 0;
signals:
void TriggerInit();
void TriggerUninit();
};
......
......@@ -53,6 +53,7 @@ NavWindow::NavWindow(QWidget *parent) :
NavWindow::~NavWindow()
{
FMP_DEBUG() << __FUNCTION__ << "****";
delete _btn_group;
for(int i=0; i<actions.size(); ++i) {
delete actions.at(i);
......@@ -60,10 +61,11 @@ NavWindow::~NavWindow()
actions.clear();
delete _animationShow;
delete _systemTrayIcon;
delete stateGroup;
delete stateDefault;
delete stateSpread;
delete stateGroup;
delete stateBlink;
delete _stateMachine;
delete ui;
}
......
......@@ -24,7 +24,7 @@ FMPHomePrivate::FMPHomePrivate(FMPHome *q)
FMPHomePrivate::~FMPHomePrivate()
{
Uninit();
}
int FMPHomePrivate::Init()
......@@ -60,11 +60,6 @@ int FMPHomePrivate::Uninit()
return FMP_SUCCESS;
}
void FMPHomePrivate::StartPlugins(const QVariantList &pids)
{
FMP_DEBUG() << pids;
}
int FMPHomePrivate::login()
{
if(_isLogining) {
......@@ -122,7 +117,6 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
FMP_DEBUG() << "Menu clicked: " << btnName;
if(btnName == "quit") {
FMP_DEBUG() << "Will Quit!";
q->PostEvent(FMP_TOPICS_QUIT);
return;
}
......@@ -135,10 +129,21 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
if(btnName == "payment") {
FMPePayInterface *e = q->GetService<FMPePayInterface>(q->_ctx);
if (e) {
e->StartService();
}
else {
FMP_WARN() << "Pay service not available";
}
} else if(btnName == "vip") {
FMPVipInterface *e = q->GetService<FMPVipInterface>(q->_ctx);
e->StartService();
if (e) {
// e->StartService();
e->TriggerInit();
}
else {
FMP_WARN() << "Vip service not available";
}
} else if(btnName == "takeout") {
// FMPTakeoutInterface *e = q->GetService<FMPTakeoutInterface>(q->_ctx);
// e->StartService();
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 4
#define VER_BUILD 7
//! Convert version numbers to string
#define _STR(S) #S
......
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