Commit 6be36ff2 by guanghui.cui

插件更新

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