Commit 1f98a6ab by Amnes1a

修改外卖插件的接口形式

parent 726d67ae
#include "fmp_takeout_p.h" #include "fmp_takeout_p.h"
#include "fmp_te_handlers.h" #include "fmp_te_handlers.h"
FMPTakeout::FMPTakeout(ctkPluginContext *context) FMPTakeout::FMPTakeout(const FMPContext context)
: FMPTakeoutInterface(context), : FMPTakeoutInterface(),
pluginContext(context),
_inited(false), _inited(false),
_ste_handler(new FMPStartEventHandler(this)),
d_ptr(new FMPTakeoutPrivate(this)) d_ptr(new FMPTakeoutPrivate(this))
{ {
FMPStartEventHandler *se = new FMPStartEventHandler(_ctx, this);
} }
FMPTakeout::~FMPTakeout() FMPTakeout::~FMPTakeout()
...@@ -19,13 +20,17 @@ FMPTakeout::~FMPTakeout() ...@@ -19,13 +20,17 @@ FMPTakeout::~FMPTakeout()
void FMPTakeout::InitService() void FMPTakeout::InitService()
{ {
d_func()->Init(); if(_inited)
return;
Q_D(FMPTakeout);
d->Init();
} }
void FMPTakeout::UninitService() void FMPTakeout::UninitService()
{ {
if (_inited) { if (_inited) {
d_func()->Uninit(); Q_D(FMPTakeout);
d->Uninit();
} }
} }
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <QObject> #include <QObject>
#include "fmp_takeout_i.h" #include "fmp_takeout_i.h"
class FMPStartEventHandler;
class FMPTakeoutPrivate; class FMPTakeoutPrivate;
class FMPTakeout : public FMPTakeoutInterface class FMPTakeout : public FMPTakeoutInterface
...@@ -14,22 +16,19 @@ class FMPTakeout : public FMPTakeoutInterface ...@@ -14,22 +16,19 @@ class FMPTakeout : public FMPTakeoutInterface
Q_DECLARE_PRIVATE(FMPTakeout) Q_DECLARE_PRIVATE(FMPTakeout)
public: public:
explicit FMPTakeout(ctkPluginContext *context); explicit FMPTakeout(const FMPContext context);
virtual ~FMPTakeout(); virtual ~FMPTakeout();
protected: protected:
void UninitService(); void UninitService();
void InitService(); void InitService();
const FMPContext GetContext()const{ return pluginContext;}
private: private:
bool _inited; bool _inited;
FMPTakeoutPrivate* d_ptr; FMPTakeoutPrivate* d_ptr;
const FMPContext pluginContext;
QPointer<FMPStartEventHandler> _ste_handler;
signals:
public slots:
}; };
#endif // FMPTakeout_H #endif // FMPTakeout_H
#ifndef FMPTAKEOUTINTERFACE_H #ifndef FMPTAKEOUTINTERFACE_H
#define FMPTAKEOUTINTERFACE_H #define FMPTAKEOUTINTERFACE_H
#include <fmp_plugin_i.h> #include <fmp_plugin_i.h>
#include "fmp_takeout_def.h" #include "fmp_takeout_def.h"
/** /**
...@@ -15,7 +14,7 @@ class FMPTakeoutInterface : public QObject, public FMPluginInterface ...@@ -15,7 +14,7 @@ class FMPTakeoutInterface : public QObject, public FMPluginInterface
Q_INTERFACES(FMPBaseInterface) Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPluginInterface) Q_INTERFACES(FMPluginInterface)
public: public:
explicit FMPTakeoutInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx) explicit FMPTakeoutInterface() : FMPluginInterface()
{ {
connect(this, &FMPTakeoutInterface::TriggerInit, this, &FMPTakeoutInterface::OnTriggerInit, Qt::UniqueConnection); connect(this, &FMPTakeoutInterface::TriggerInit, this, &FMPTakeoutInterface::OnTriggerInit, Qt::UniqueConnection);
connect(this, &FMPTakeoutInterface::TriggerUninit, this, &FMPTakeoutInterface::OnTriggerUninit, Qt::UniqueConnection); connect(this, &FMPTakeoutInterface::TriggerUninit, this, &FMPTakeoutInterface::OnTriggerUninit, Qt::UniqueConnection);
...@@ -32,5 +31,4 @@ protected slots: ...@@ -32,5 +31,4 @@ protected slots:
Q_DECLARE_INTERFACE(FMPTakeoutInterface, "com.fmp.takeout") Q_DECLARE_INTERFACE(FMPTakeoutInterface, "com.fmp.takeout")
#endif // FMPTAKEOUTINTERFACE_H #endif // FMPTAKEOUTINTERFACE_H
...@@ -17,36 +17,27 @@ FMPTakeoutPrivate::FMPTakeoutPrivate(FMPTakeout *parent) ...@@ -17,36 +17,27 @@ FMPTakeoutPrivate::FMPTakeoutPrivate(FMPTakeout *parent)
} }
int FMPTakeoutPrivate::Init() void FMPTakeoutPrivate::Init()
{ {
Q_Q(FMPTakeout); Q_Q(FMPTakeout);
if(!q) if(q->_inited)
{ {
return 0; emit sgnGetFromHome();
} }
else else
{ {
if(0 == q->_inited) _Home = FMP::GetService<FMPHomeInterface>();
{ _Printer = FMP::GetService<FMPPrinterInterface>();
_Home = q->GetService<FMPHomeInterface>(q->_ctx); InitApp();
_Printer= q->GetService<FMPPrinterInterface>(q->_ctx); q->_inited = true;
InitApp();
q->_inited = true;
return FMP_SUCCESS;
}
else{
emit sgnGetFromHome();
return 1;
}
} }
} }
FMPTakeoutPrivate::~FMPTakeoutPrivate() FMPTakeoutPrivate::~FMPTakeoutPrivate()
{ {
Uninit(); Uninit();
} }
int FMPTakeoutPrivate::Uninit() void FMPTakeoutPrivate::Uninit()
{ {
Q_Q(FMPTakeout); Q_Q(FMPTakeout);
emit sgnStopTime(); emit sgnStopTime();
...@@ -64,7 +55,6 @@ int FMPTakeoutPrivate::Uninit() ...@@ -64,7 +55,6 @@ int FMPTakeoutPrivate::Uninit()
_settings = 0; _settings = 0;
} }
q->_inited = false; q->_inited = false;
return FMP_SUCCESS;
} }
// home 提供接口 // home 提供接口
......
#ifndef FMP_TAKEOUT_P_H #ifndef FMP_TAKEOUT_P_H
#define FMP_TAKEOUT_P_H #define FMP_TAKEOUT_P_H
#include "fmp_takeout.h" #include "fmp_takeout.h"
...@@ -11,13 +11,11 @@ class FMPTakeoutPrivate:public QObject ...@@ -11,13 +11,11 @@ class FMPTakeoutPrivate:public QObject
Q_DECLARE_PUBLIC(FMPTakeout) Q_DECLARE_PUBLIC(FMPTakeout)
public: public:
explicit FMPTakeoutPrivate(FMPTakeout *q); explicit FMPTakeoutPrivate(FMPTakeout *q);
int Init();
int Uninit();
~FMPTakeoutPrivate(); ~FMPTakeoutPrivate();
void Init();
void Uninit();
void InitApp(); void InitApp();
private:
public: public:
FMPTakeout *q_ptr; FMPTakeout *q_ptr;
FMPHomeInterface *_Home; FMPHomeInterface *_Home;
......
/*============================================================================= /*=============================================================================
Library: CTK Library: CTK
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
#include "fmp_takeout_plugin_p.h" #include "fmp_takeout_plugin_p.h"
#include "fmp_takeout.h" #include "fmp_takeout.h"
#include <QtPlugin> #include <QtPlugin>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
...@@ -47,8 +45,6 @@ void FMPTakeoutPlugin::stop(ctkPluginContext* context) ...@@ -47,8 +45,6 @@ void FMPTakeoutPlugin::stop(ctkPluginContext* context)
delete _takeout_service; delete _takeout_service;
_takeout_service = 0; _takeout_service = 0;
} }
int a = 0;
} }
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
......
#include "fmp_logger_i.h"
#include "fmp_te_handlers.h" #include "fmp_te_handlers.h"
#include "fmp_takeout.h" #include "fmp_takeout.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPTakeout *Takeout) FMPStartEventHandler::FMPStartEventHandler(FMPTakeout *Takeout)
: FMPTakeoutEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"+ QString::number(ctx->getPlugin()->getPluginId()), : FMPTakeoutEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"+ QString::number(Takeout->GetPluginId()),Takeout)
Takeout),
_ctx(ctx)
{ {
FMPProps props; FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic; props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props); FMP::RegisterService<ctkEventHandler>(this, props);
} }
void FMPStartEventHandler::handleEvent(const ctkEvent &event) void FMPStartEventHandler::handleEvent(const ctkEvent &event)
...@@ -19,11 +18,38 @@ void FMPStartEventHandler::handleEvent(const ctkEvent &event) ...@@ -19,11 +18,38 @@ void FMPStartEventHandler::handleEvent(const ctkEvent &event)
_Takeout->TriggerInit(); _Takeout->TriggerInit();
} }
else { else {
// FMP_WARN_CTX(_ctx) << "Refused start request" << event.getTopic(); FMP_WARN() << "Refused start request " << event.getTopic();
} }
} }
else { else {
// FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic(); FMP_DEBUG() << "No handler instance for event " << event.getTopic();
}
}
FMPNetWorkEventHandler::FMPNetWorkEventHandler(FMPTakeout *Takeout)
:FMPTakeoutEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/" + QString::number(Takeout->GetPluginId()), Takeout)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
FMP::RegisterService<ctkEventHandler>(this, props);
}
void FMPNetWorkEventHandler::handleEvent(const ctkEvent &event)
{
if(_Takeout)
{
if(event.getProperty(FMP_PROPKEY_AGREED).toBool())
{
_Takeout->TriggerInit();
}
else
{
FMP_WARN() << "Refused start request " << event.getTopic();
}
}
else
{
FMP_DEBUG() << "No handler instance for event " << event.getTopic();
} }
} }
#ifndef FMPTAKEOUTEVENTHANDLER_H #ifndef FMPTAKEOUTEVENTHANDLER_H
#define FMPTAKEOUTEVENTHANDLER_H #define FMPTAKEOUTEVENTHANDLER_H
#include <QObject> #include <QObject>
#include <service/event/ctkEventConstants.h> #include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h> #include <service/event/ctkEventHandler.h>
class FMPTakeout; class FMPTakeout;
class FMPTakeoutEventHandler : public ctkEventHandler class FMPTakeoutEventHandler : public ctkEventHandler
{ {
public: public:
...@@ -17,19 +15,22 @@ protected: ...@@ -17,19 +15,22 @@ protected:
const QString _topic; const QString _topic;
}; };
class FMPStartEventHandler : public QObject, public FMPTakeoutEventHandler class FMPStartEventHandler : public QObject, public FMPTakeoutEventHandler
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(ctkEventHandler) Q_INTERFACES(ctkEventHandler)
public: public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPTakeout *Takeout); explicit FMPStartEventHandler(FMPTakeout *Takeout);
void handleEvent(const ctkEvent &event); void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
}; };
class FMPNetWorkEventHandler : public QObject, public FMPTakeoutEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPNetWorkEventHandler(FMPTakeout* Takeout);
void handleEvent(const ctkEvent& event);
};
#endif // FMPTAKEOUTEVENTHANDLER_H #endif // FMPTAKEOUTEVENTHANDLER_H
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