Commit 1f98a6ab by Amnes1a

修改外卖插件的接口形式

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