Commit 6be36ff2 by guanghui.cui

插件更新

parent 88afe087
......@@ -54,6 +54,7 @@ int FMNetwork::send(const QString &url, const QByteArray &reqData, QByteArray &r
rspData = reply->readAll();
} else {
int err = reply->error();
rspData = reply->readAll();
error = FM_API_NETWORERROR;
errorMsg = netErrInfo(err);
}
......
......@@ -2,14 +2,13 @@
#include "fmp_ve_handlers.h"
#include "fmp_vip.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPVip *vip)
FMPStartEventHandler::FMPStartEventHandler(FMPVip *vip)
: FMPVipEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"
+ QString::number(ctx->getPlugin()->getPluginId()), vip),
_ctx(ctx)
+ QString::number(vip->GetPluginId()), vip)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
FMP::RegisterService<ctkEventHandler>(this, props);
}
......
......@@ -27,11 +27,8 @@ class FMPStartEventHandler : public QObject, public FMPVipEventHandler
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPVip *vip);
explicit FMPStartEventHandler(FMPVip *vip);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
#include "fmp_vip_p.h"
#include "fmp_ve_handlers.h"
class ctkPluginContext;
FMPVip::FMPVip(ctkPluginContext *context)
: FMPVipInterface(context),
FMPVip::FMPVip(const FMPContext ctx)
: FMPVipInterface(),
context(ctx),
_inited(false),
d_ptr(new FMPVipPrivate(this))
{
FMPStartEventHandler *handler = new FMPStartEventHandler(_ctx, this);
FMPLoggerInterface::InitContext(context);
FMPStartEventHandler *handler = new FMPStartEventHandler(this);
}
FMPVip::~FMPVip()
......
......@@ -14,15 +14,18 @@ class FMPVip : public FMPVipInterface
Q_DECLARE_PRIVATE(FMPVip)
public:
explicit FMPVip(ctkPluginContext *context);
explicit FMPVip(const FMPContext ctx);
virtual ~FMPVip();
protected:
const FMPContext GetContext() const { return context; }
protected:
void InitService();
void UninitService();
private:
bool _inited;
FMPVipPrivate* d_ptr;
FMPVipPrivate* d_ptr;
const FMPContext context;
};
#endif // FMP_VIP_H
......@@ -13,7 +13,7 @@ class FMPVipInterface : public QObject, public FMPluginInterface
Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPluginInterface)
public:
explicit FMPVipInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx)
explicit FMPVipInterface() : FMPluginInterface()
{
connect(this, &FMPVipInterface::TriggerInit, this, &FMPVipInterface::OnTriggerInit);
connect(this, &FMPVipInterface::TriggerUninit, this, &FMPVipInterface::OnTriggerUninit);
......@@ -28,7 +28,7 @@ protected slots:
void OnTriggerUninit() { FMPluginInterface::OnTriggerUninit(); }
};
Q_DECLARE_INTERFACE(FMPVipInterface, "com.fmp.vip")
Q_DECLARE_INTERFACE(FMPVipInterface, "fmp.vip")
#endif // FMP_LOGGER_I_H
......@@ -3,7 +3,6 @@
#include <fmp_home_i.h>
#include <QCoreApplication>
#include <QDateTime>
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include "fmp_vip_server.h"
#include "fmp_vip_settings.h"
......@@ -19,16 +18,16 @@ FMPVipPrivate::FMPVipPrivate(FMPVip *vip):
int FMPVipPrivate::Init()
{
Q_Q(FMPVip);
FMPHomeInterface *home = q->GetService<FMPHomeInterface>(q->_ctx);
FMPHomeInterface* home = FMP::GetService<FMPHomeInterface>();
if(q->_inited) {
home->notification(QString::fromLocal8Bit("[非码POS插件]已在运行!"));
} else {
_settings = q->GetService<FMPSettingsInterface>(q->_ctx);
FMPVipSettings::instance()->init(_settings);
settings = FMP::GetService<FMPSettingsInterface>();
FMPVipSettings::instance()->init(settings);
auto resend = new ReSend();
resend->start();
FMPVipServer::instance()->SetPluginContext(q->_ctx);
FMPVipServer::instance();
q->_inited = true;
......
......@@ -17,9 +17,9 @@ public:
int Uninit();
public:
FMPVip *q_ptr;
FMPVip *q_ptr;
private:
FMPSettingsInterface *_settings;
FMPSettingsInterface* settings;
};
#endif // FMP_VIP_P_H
......@@ -33,11 +33,6 @@ void FMPVipServer::Write(const QByteArray &data)
}
}
void FMPVipServer::SetPluginContext(ctkPluginContext *ctx)
{
dispatcher->setPluginContext(ctx);
}
void FMPVipServer::onNewConnection()
{
socket = nextPendingConnection();
......@@ -78,6 +73,7 @@ void FMPVipServer::SendToMonitor(const QByteArray &data)
{
QTcpSocket client;
FMP_INFO() << "SendToMonitor to pos: " << data;
int jsonLength=data.length();
char* m_pFmPackage = new char[jsonLength + sizeof(FMSOCKEHEADER)];
FMSOCKEHEADER header = { 0, 0, 0 };
......@@ -109,4 +105,5 @@ void FMPVipServer::SendToMonitor(const QByteArray &data)
FMP_DEBUG() << "socket 连接失败!";
}
client.close();
delete[] m_pFmPackage;
}
......@@ -6,7 +6,6 @@
#define FMSOCKFLAG 0x4d46
class FMVipDispatcher;
class ctkPluginContext;
typedef struct {
int flag;
......@@ -22,7 +21,6 @@ public:
void Listen(quint16 port);
void Write(const QByteArray &data);
void SetPluginContext(ctkPluginContext *ctx);
//signals:
private slots:
void onNewConnection();
......
......@@ -12,9 +12,9 @@ FMPVipSettings *FMPVipSettings::instance()
return &vipSettings;
}
void FMPVipSettings::init(FMPSettingsInterface *settings)
void FMPVipSettings::init(FMPSettingsInterface* svc)
{
this->_settings = settings;
this->settings = svc;
}
QString FMPVipSettings::getServerUrl()
......@@ -24,8 +24,8 @@ QString FMPVipSettings::getServerUrl()
QVariant FMPVipSettings::_GetValue(const QString &key, QVariant defaultValue)
{
if (_settings) {
return _settings->GetValue(key);
if (settings) {
return settings->GetValue(key);
}
else {
FMP_WARN() << "Settings service not available";
......@@ -36,8 +36,8 @@ QVariant FMPVipSettings::_GetValue(const QString &key, QVariant defaultValue)
bool FMPVipSettings::_SetValue(const QString &key, QVariant value)
{
if (_settings) {
_settings->SetValue(key, value);
if (settings) {
settings->SetValue(key, value);
return true;
}
else {
......
......@@ -12,7 +12,7 @@ class FMPVipSettings : public QObject
Q_OBJECT
public:
static FMPVipSettings *instance();
void init(FMPSettingsInterface *settings);
void init(FMPSettingsInterface *svc);
QString getServerUrl();
......@@ -23,7 +23,7 @@ private:
bool _SetValue(const QString &key, QVariant value);
private:
FMPSettingsInterface *_settings;
FMPSettingsInterface* settings;
};
#endif // FMP_VIP_SETTINGS_H
......@@ -10,16 +10,15 @@
#include "fmp_vip_server.h"
#include "tasklogin.h"
#include "taskpay.h"
#include "taskothers.h"
#include "taskfinal.h"
#include <ctkPluginContext.h>
#undef StartService
#include <fmp_epay_i.h>
FMVipDispatcher::FMVipDispatcher(QObject *parent) :
QObject(parent),
fmTask(nullptr),
_ctx(nullptr)
fmTask(nullptr)
{
}
......@@ -49,32 +48,29 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
rspData = taskPay.doTask();
break;
}
case FM_QR_Pay: {
if (_ctx) {
ctkServiceReference ref =_ctx->getServiceReference<FMPePayInterface>();
FMPePayInterface *epay = _ctx->getService<FMPePayInterface>(ref);
epay->DockPayRequest(reqData);
epay->StartService();
rspData = epay->DockPayRespond();
epay->StopService();
}
else {
rspData = QString::fromLocal8Bit("{\"msg:\":\"支付服务不可用\"}").toUtf8();
}
FMPePayInterface *epay = FMP::GetService<FMPePayInterface>();
epay->DockPayRequest(reqData);
epay->StartService();
rspData = epay->DockPayRespond();
break;
}
case FM_Order_Refund: {
// TaskRefundOrder taskRefundOrder(jsonObj);
// rspData = taskRefundOrder.doTask();
break;
}
case FM_Order_Revoke: {
// TaskRefundPay taskRefundPay(jsonObj);
// rspData = taskRefundPay.doTask();
break;
}
case FM_QR_Refund: {
if (_ctx) {
ctkServiceReference ref =_ctx->getServiceReference<FMPePayInterface>();
FMPePayInterface *epay = _ctx->getService<FMPePayInterface>(ref);
epay->DockRefundRequest(reqData);
epay->StartService();
rspData = epay->DockRefundRespond();
epay->StopService();
}
else {
rspData = QString::fromLocal8Bit("{\"msg:\":\"退款服务不可用\"}").toUtf8();
}
FMPePayInterface *epay = FMP::GetService<FMPePayInterface>();
epay->DockRefundRequest(reqData);
epay->StartService();
rspData = epay->DockRefundRespond();
break;
}
case FM_Final: {
......@@ -90,16 +86,3 @@ void FMVipDispatcher::doTask(const QByteArray &reqData, QByteArray &rspData)
FMP_INFO() << "Send to pos: " << rspData;
}
void FMVipDispatcher::setPluginContext(ctkPluginContext *ctx)
{
if (ctx && _ctx != ctx) {
try {
//! Verify pointer
ctx->getPlugin();
_ctx = ctx;
}
catch(const ctkException&) {
FMP_ERROR() << "Invalid context:" << ctx;
}
}
}
......@@ -8,7 +8,6 @@
class FMTask;
class FMPVipServer;
class ctkPluginContext;
class FMVipDispatcher : public QObject/*, public FMApiRelay*/
{
......@@ -19,11 +18,9 @@ public:
void doTask(const QByteArray &reqData, QByteArray &rspData);
void setPluginContext(ctkPluginContext *ctx);
private:
FMTask * fmTask;
ctkPluginContext* _ctx;
};
#endif // FMVIPDISPATCHER_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