Commit 32832ecf by Carwyn

1.同步基础接口InitService/UninitService

parent b1ddd768
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
#include "fmp_he_handlers.h" #include "fmp_he_handlers.h"
#include "fmp_home.h" #include "fmp_home.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home) FMPHomeEventHandler::FMPHomeEventHandler(const QString &topic, FMPHome *home, ctkPluginContext *ctx)
: FMPHomeEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_START "/*" , home), : _home(home),
_topic(topic),
_ctx(ctx) _ctx(ctx)
{ {
FMPProps props; FMPProps props;
...@@ -11,6 +12,11 @@ FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home) ...@@ -11,6 +12,11 @@ FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
_ctx->registerService<ctkEventHandler>(this, props); _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) void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{ {
...@@ -26,3 +32,22 @@ 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(); 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 @@ ...@@ -7,26 +7,33 @@
class FMPHome; class FMPHome;
class FMPHomeEventHandler : public ctkEventHandler class FMPHomeEventHandler : public QObject, public ctkEventHandler
{ {
public: public:
explicit FMPHomeEventHandler(const QString &topic, FMPHome *home) : _home(home), _topic(topic) {} explicit FMPHomeEventHandler(const QString &topic, FMPHome *home, ctkPluginContext *ctx);
protected: protected:
FMPHome* _home; FMPHome* _home;
const QString _topic; const QString _topic;
ctkPluginContext* _ctx;
}; };
class FMPStartEventHandler : public QObject, public FMPHomeEventHandler class FMPStartEventHandler : public FMPHomeEventHandler
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(ctkEventHandler) Q_INTERFACES(ctkEventHandler)
public: public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home); explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event); void handleEvent(const ctkEvent &event);
};
private: class FMPUpgradeAckEventHandler : FMPHomeEventHandler
ctkPluginContext* _ctx; {
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPUpgradeAckEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event);
}; };
#endif // FMP_MANAGER_EVENT_HANDLERS_H #endif // FMP_MANAGER_EVENT_HANDLERS_H
...@@ -7,31 +7,31 @@ FMPHome::FMPHome(ctkPluginContext *context) ...@@ -7,31 +7,31 @@ FMPHome::FMPHome(ctkPluginContext *context)
d_ptr(new FMPHomePrivate(this)), d_ptr(new FMPHomePrivate(this)),
_inited(false) _inited(false)
{ {
} }
FMPHome::~FMPHome() FMPHome::~FMPHome()
{ {
StopService();
delete d_ptr; delete d_ptr;
} }
int FMPHome::StartService() void FMPHome::InitService()
{
if (_inited) return FMP_SUCCESS;
Q_D(FMPHome);
return d->Init();
}
int FMPHome::StopService()
{ {
if (!_inited) return FMP_SUCCESS; if (!_inited) {
Q_D(FMPHome); Q_D(FMPHome);
return d->Uninit(); d->Init();
}
_semaphore.release(1);
} }
void FMPHome::StartPlugins(const QVariantList &pids) void FMPHome::UninitService()
{ {
Q_D(FMPHome); if (_inited) {
d->StartPlugins(pids); Q_D(FMPHome);
d->Uninit();
}
_semaphore.release(1);
} }
int FMPHome::login() int FMPHome::login()
...@@ -70,3 +70,4 @@ void FMPHome::notification(const QString &msg, const QString &title, ...@@ -70,3 +70,4 @@ void FMPHome::notification(const QString &msg, const QString &title,
Q_D(FMPHome); Q_D(FMPHome);
return d->notification(msg, title, icon, mecs); return d->notification(msg, title, icon, mecs);
} }
...@@ -10,20 +10,16 @@ class ctkPluginContext; ...@@ -10,20 +10,16 @@ class ctkPluginContext;
class FMPHomePrivate; class FMPHomePrivate;
class FMPStartEventHandler; class FMPStartEventHandler;
class FMPHome : public QObject, public FMPHomeInterface class FMPHome : public FMPHomeInterface
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(FMPBaseInterface) Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPluginInterface)
Q_INTERFACES(FMPHomeInterface) Q_INTERFACES(FMPHomeInterface)
Q_DECLARE_PRIVATE(FMPHome) Q_DECLARE_PRIVATE(FMPHome)
public: public:
explicit FMPHome(ctkPluginContext *context); explicit FMPHome(ctkPluginContext *context);
~FMPHome(); virtual ~FMPHome();
int StartService();
int StopService();
void StartPlugins(const QVariantList &pids);
int login(); int login();
bool isLogined(); bool isLogined();
...@@ -34,11 +30,14 @@ public: ...@@ -34,11 +30,14 @@ public:
void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME), void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME),
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000); QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000);
protected slots:
virtual void InitService();
virtual void UninitService();
private: private:
friend class FMPStartEventHandler;
FMPHomePrivate *d_ptr; FMPHomePrivate *d_ptr;
bool _inited; bool _inited;
friend class FMPStartEventHandler;
}; };
#endif // FMP_HOME_H #endif // FMP_HOME_H
...@@ -49,6 +49,7 @@ unix { ...@@ -49,6 +49,7 @@ unix {
#Target name #Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET) VER = $$system($$PWD/../fmprc.bat $$TARGET)
#VER = 0.1.1
ORIGIN_TARGET = $$TARGET ORIGIN_TARGET = $$TARGET
TARGET = $${TARGET}_$${VER} TARGET = $${TARGET}_$${VER}
......
...@@ -4,13 +4,32 @@ ...@@ -4,13 +4,32 @@
#include <fmp_plugin_i.h> #include <fmp_plugin_i.h>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
class FMPHomeInterface : public FMPluginInterface class FMPHomeInterface : public QObject, public FMPluginInterface
{ {
Q_OBJECT
Q_INTERFACES(FMPluginInterface)
public: public:
explicit FMPHomeInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx) {} explicit FMPHomeInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx)
virtual int login() = 0; {
virtual bool isLogined() = 0; connect(this, &FMPHomeInterface::TriggerInit, this, &FMPHomeInterface::InitService);
virtual QString userName() = 0; 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 * @brief blink
...@@ -38,6 +57,13 @@ public: ...@@ -38,6 +57,13 @@ public:
*/ */
virtual void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME), virtual void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME),
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000) = 0; 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) : ...@@ -53,6 +53,7 @@ NavWindow::NavWindow(QWidget *parent) :
NavWindow::~NavWindow() NavWindow::~NavWindow()
{ {
FMP_DEBUG() << __FUNCTION__ << "****";
delete _btn_group; delete _btn_group;
for(int i=0; i<actions.size(); ++i) { for(int i=0; i<actions.size(); ++i) {
delete actions.at(i); delete actions.at(i);
...@@ -60,10 +61,11 @@ NavWindow::~NavWindow() ...@@ -60,10 +61,11 @@ NavWindow::~NavWindow()
actions.clear(); actions.clear();
delete _animationShow; delete _animationShow;
delete _systemTrayIcon; delete _systemTrayIcon;
delete stateGroup;
delete stateDefault; delete stateDefault;
delete stateSpread; delete stateSpread;
delete stateGroup;
delete stateBlink; delete stateBlink;
delete _stateMachine;
delete ui; delete ui;
} }
......
...@@ -24,7 +24,7 @@ FMPHomePrivate::FMPHomePrivate(FMPHome *q) ...@@ -24,7 +24,7 @@ FMPHomePrivate::FMPHomePrivate(FMPHome *q)
FMPHomePrivate::~FMPHomePrivate() FMPHomePrivate::~FMPHomePrivate()
{ {
Uninit();
} }
int FMPHomePrivate::Init() int FMPHomePrivate::Init()
...@@ -60,11 +60,6 @@ int FMPHomePrivate::Uninit() ...@@ -60,11 +60,6 @@ int FMPHomePrivate::Uninit()
return FMP_SUCCESS; return FMP_SUCCESS;
} }
void FMPHomePrivate::StartPlugins(const QVariantList &pids)
{
FMP_DEBUG() << pids;
}
int FMPHomePrivate::login() int FMPHomePrivate::login()
{ {
if(_isLogining) { if(_isLogining) {
...@@ -122,7 +117,6 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName) ...@@ -122,7 +117,6 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
FMP_DEBUG() << "Menu clicked: " << btnName; FMP_DEBUG() << "Menu clicked: " << btnName;
if(btnName == "quit") { if(btnName == "quit") {
FMP_DEBUG() << "Will Quit!";
q->PostEvent(FMP_TOPICS_QUIT); q->PostEvent(FMP_TOPICS_QUIT);
return; return;
} }
...@@ -135,10 +129,21 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName) ...@@ -135,10 +129,21 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
if(btnName == "payment") { if(btnName == "payment") {
FMPePayInterface *e = q->GetService<FMPePayInterface>(q->_ctx); FMPePayInterface *e = q->GetService<FMPePayInterface>(q->_ctx);
e->StartService(); if (e) {
e->StartService();
}
else {
FMP_WARN() << "Pay service not available";
}
} else if(btnName == "vip") { } else if(btnName == "vip") {
FMPVipInterface *e = q->GetService<FMPVipInterface>(q->_ctx); 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") { } else if(btnName == "takeout") {
// FMPTakeoutInterface *e = q->GetService<FMPTakeoutInterface>(q->_ctx); // FMPTakeoutInterface *e = q->GetService<FMPTakeoutInterface>(q->_ctx);
// e->StartService(); // e->StartService();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#define VER_MINOR 1 #define VER_MINOR 1
#define VER_REVISION 0 #define VER_REVISION 0
#define VER_BUILD 4 #define VER_BUILD 7
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #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