Commit 003c0a6c by guanghui.cui

插件更新

parent 219c2b68
...@@ -6,7 +6,8 @@ CONFIG += c++11 ...@@ -6,7 +6,8 @@ CONFIG += c++11
TARGET = FreemudPOS TARGET = FreemudPOS
TEMPLATE = app TEMPLATE = app
INCLUDEPATH += $$PWD/../include/interface \ INCLUDEPATH += $$PWD/../include/ctk \
$$PWD/../include/interface \
CONFIG(debug, debug|release) { CONFIG(debug, debug|release) {
DESTDIR = $$PWD/../debug/bins DESTDIR = $$PWD/../debug/bins
...@@ -23,4 +24,4 @@ HEADERS += \ ...@@ -23,4 +24,4 @@ HEADERS += \
../include/application/fm_singleton.h ../include/application/fm_singleton.h
SOURCES += \ SOURCES += \
fm_pos_app.cpp fmp_app.cpp
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <Windows.h> #include <Windows.h>
#include <vld.h>
//! 命名冲突 //! 命名冲突
#undef StartService #undef StartService
...@@ -36,6 +37,14 @@ public: ...@@ -36,6 +37,14 @@ public:
setServiceDescription(_description); setServiceDescription(_description);
} }
~FMPService()
{
if (_setting) {
delete _setting;
_setting = nullptr;
}
}
bool isRunning() bool isRunning()
{ {
return application()->IsRunning(); return application()->IsRunning();
......
#include <fmp_manager_i.h>
#include <QDebug>
#include <QPluginLoader>
#include <QSettings>
#include <QDir>
#include <QDirIterator>
#include <qtservice.h>
#ifdef Q_OS_WIN
#include <Windows.h>
//! 命名冲突
#undef StartService
#endif
#include "../application/fm_singleton.h"
#include "../fmp_settings/fmp_settings_def.h"
class FMPAppService : public QtService<FMSingleApplication>
{
public:
FMPAppService(int argc, char**argv, const QString &svcname) :
_starttype(0),
_name(svcname),
_setting(0),
QtService<FMSingleApplication>(argc, argv, svcname)
{
createApplication(argc, argv);
_setting = new QSettings(qApp->applicationDirPath() + "/" + qApp->applicationName() + ".ini", QSettings::IniFormat);
_starttype = _setting->value(FMP_INIKEY_SERVICESTARTTYPE, 0).toInt();
_description = _setting->value(FMP_INIKEY_SERVICEDESC, "Freemud POS plugin service").toString();
setStartupType((QtServiceController::StartupType)_starttype);
setServiceDescription(_description);
}
bool isRunning()
{
return application()->IsRunning();
}
void start()
{
FMPManager fmpManager = FMP::GetManager();
fmpManager->StartService();
}
protected:
virtual void createApplication(int &argc, char **argv)
{
if (!application()) {
QtService::createApplication(argc, argv);
}
}
private:
int _starttype;
QSettings *_setting;
QString _name;
QString _description;
};
#define SERVICE 0
int main(int argc, char** argv)
{
QString app_path = QString::fromLocal8Bit(argv[0]);
app_path.replace("\\", "/");
QString app_dir = app_path.section("/", 0, -2);
QString app_name = app_path.section("/", -1);
QSettings setting(app_dir + "/" + app_name.replace(".exe", ".ini"), QSettings::IniFormat);
QString svc_name = setting.value(FMP_INIKEY_SERVICENAME, "FMPService").toString();
FMPAppService svc(argc, argv, svc_name);
if (!svc.isRunning()) {
#if SERVICE
return svc->exec();
#else
svc.start();
return qApp->exec();
#endif
}
else {
return 0;
}
}
...@@ -167,6 +167,10 @@ public: ...@@ -167,6 +167,10 @@ public:
{ } { }
~QtService() ~QtService()
{ {
if (app) {
delete app;
app = 0;
}
} }
protected: protected:
......
[Service] [Service]
Name=FMPService Name=FMPService
Desc=非码 POS 插件服务 Desc=\xe9\x9d\x9e\xe7\xa0\x81 POS \xe6\x8f\x92\xe4\xbb\xb6\xe6\x9c\x8d\xe5\x8a\xa1
;0 自动启动, 1 手动启动
StartType=0 StartType=0
[Plugin] [Plugin]
Path=../plugins Path=../plugins
EntryService=com.fmp.home EntryService=com.fmp.home
;动画开关,0:关闭 1:开启
Animation=1 Animation=1
[Log] [Log]
Path=log Path=log
Size=1 Size=1
;0:关闭 1:错误 2:警告 3:信息 4:调试
Level=4 Level=4
[Home] [Home]
Server=http://115.159.226.87:20001/api/user/login Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371 PartnerId=1521
StoreId=pos_coco_CN9999 StoreId=9999
PosId=fm1802 PosId=01
Position=339, 251 Position=1479, 521
CashierId=001 CashierId=001
[Pay] [Pay]
...@@ -29,11 +26,11 @@ Server=https://115.159.18.100/api ...@@ -29,11 +26,11 @@ Server=https://115.159.18.100/api
Timeout=60 Timeout=60
[Vip] [Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos Server=http://member.freemudorder.com/member_today/service/restful/pos
[Syncer] [Syncer]
Interval=3 Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate TaskUrl=http://192.168.110.150:8080/api/fork/checkupdate
DeployPath=.. DeployPath=..
DownloadPath=download DownloadPath=download
...@@ -43,11 +40,29 @@ Port=34953 ...@@ -43,11 +40,29 @@ Port=34953
Password=posoperator@freemud.cn Password=posoperator@freemud.cn
ShiftId=001 ShiftId=001
ShiftName=001 ShiftName=001
AutoConfirm=0 AutoConfirm=1
cashname=001
mates=database/fmtakeout.mates.info.ini
bill=FileBill/fmptakeout.order.info.ini
billpath=FileBill/billfile
blinkInterval=0.3
slipPort=23772
slipIp=127.0.0.1
Entryurl= Entryurl=
Entryport= Entryport=
[Printer] [Printer]
Name=Microsoft XPS Document Writer Name=Fax
Mode=2 Mode=2
PaperWidth=80 PaperWidth=80
type=4
printType=2
parallel=lpt1
usb=USB-0
IP=127.0.0.1
levlel=All
Printlabel=Gprinter 2120TF
LogDays=10
[Float]
postion=@Point(1617 270)
[Service]
Name=FMPService
Desc=\xe9\x9d\x9e\xe7\xa0\x81 POS \xe6\x8f\x92\xe4\xbb\xb6\xe6\x9c\x8d\xe5\x8a\xa1
StartType=0
[Plugin]
Path=../plugins
EntryService=com.fmp.home
Animation=1
[Log]
Path=log
Size=1
Level=4
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371
StoreId=fm99999
PosId=fm1802
Position=1520, 266
CashierId=001
[Pay]
Server=https://115.159.18.100/api
Timeout=60
[Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos
[Syncer]
Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate
DeployPath=..
DownloadPath=download
[Takeout]
Server=http://wmpos.sandload.cn/api
Port=34953
Password=posoperator@freemud.cn
ShiftId=001
ShiftName=001
AutoConfirm=0
Entryurl=
Entryport=
[Printer]
Name=Microsoft XPS Document Writer
Mode=2
PaperWidth=80
[Home]
Position=1465, 257
No preview for this file type
fmp_epay @ b06641a5
Subproject commit 8835dd277ec825ce8321596fe909dd2706020000 Subproject commit b06641a50a758a814a468faee78c923d8e64683b
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
#include "fmp_logger_p.h" #include "fmp_logger_p.h"
FMPLogger::FMPLogger(ctkPluginContext *context) FMPLogger::FMPLogger(const FMPContext ctx)
: QObject(), : QObject(),
d_ptr(new FMPLoggerPrivate(this, context)), pluginContext(ctx),
d_ptr(new FMPLoggerPrivate(this)),
_max_size(d_ptr->GetMaxLogSize()), _max_size(d_ptr->GetMaxLogSize()),
_path(d_ptr->GetLogPath()), _path(d_ptr->GetLogPath()),
_file(0), _file(0),
_level(d_ptr->GetLogLevel()) _level(d_ptr->GetLogLevel())
{ {
FMPLoggerInterface::InitContext(context);
StartService(); StartService();
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "fmp_logger_i.h" #include "fmp_logger_i.h"
class ctkPluginContext;
class FMPLoggerPrivate; class FMPLoggerPrivate;
class FMPLogger : public QObject, public FMPLoggerInterface class FMPLogger : public QObject, public FMPLoggerInterface
...@@ -18,7 +17,7 @@ class FMPLogger : public QObject, public FMPLoggerInterface ...@@ -18,7 +17,7 @@ class FMPLogger : public QObject, public FMPLoggerInterface
Q_DECLARE_PRIVATE(FMPLogger) Q_DECLARE_PRIVATE(FMPLogger)
public: public:
explicit FMPLogger(ctkPluginContext *context); explicit FMPLogger(const FMPContext ctx);
~FMPLogger(); ~FMPLogger();
protected: protected:
...@@ -28,8 +27,11 @@ protected: ...@@ -28,8 +27,11 @@ protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps()); int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
const FMPContext GetContext() const { return pluginContext; }
public: public:
//! LogInterface //! LogInterface
void SetLoggerName(const QString &modleName) { currentModule = modleName; }
void Log(short level, const QString &msg, const char* file, const char* func, int line); void Log(short level, const QString &msg, const char* file, const char* func, int line);
short GetLogLevel() const; short GetLogLevel() const;
void SetLogLevel(short level); void SetLogLevel(short level);
...@@ -46,6 +48,8 @@ private: ...@@ -46,6 +48,8 @@ private:
uint _max_size; uint _max_size;
QFile *_file; QFile *_file;
QString _path; QString _path;
QString currentModule;
const FMPContext pluginContext;
}; };
#endif // FMP_LOGGER_H #endif // FMP_LOGGER_H
...@@ -2,11 +2,12 @@ ...@@ -2,11 +2,12 @@
#define FMP_LOGGER_I_H #define FMP_LOGGER_I_H
#include <fmp_base_i.h> #include <fmp_base_i.h>
#include <fmp_manager_i.h>
#include <ctkServiceReference.h> #include <ctkServiceReference.h>
#include <ctkPluginContext.h>
#include "fmp_logger_def.h" #include "fmp_logger_def.h"
class FMPLoggerInterface;
/** /**
* 非业务插件接口,必须继承自 BaseInterface * 非业务插件接口,必须继承自 BaseInterface
...@@ -17,6 +18,15 @@ class FMPLoggerInterface : public FMPBaseInterface ...@@ -17,6 +18,15 @@ class FMPLoggerInterface : public FMPBaseInterface
public: public:
enum { LOG_ERROR = 1, LOG_WARNING, LOG_INFO, LOG_DEBUG }; enum { LOG_ERROR = 1, LOG_WARNING, LOG_INFO, LOG_DEBUG };
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
/**
* 设置当前所在模块名(打印时根据模块,使打印)
* @brief SetLoggerName
* @param moduleName
*/
virtual void SetLoggerName(const QString &moduleName) = 0;
/** /**
* @brief Log * @brief Log
* 函数方式记录日志 * 函数方式记录日志
...@@ -75,33 +85,18 @@ public: ...@@ -75,33 +85,18 @@ public:
*/ */
virtual void SetPath(const QString &path) = 0; virtual void SetPath(const QString &path) = 0;
/**
* @brief GetIODevice
* 获取文件输出设备指针(Stream使用)
* @return QIODevice*
*/
virtual QIODevice* GetIODevice() = 0;
static static FMPLoggerInterface* GetLogger(const QString &moduleName = QString())
FMPLoggerInterface* InitContext(ctkPluginContext *ctx = nullptr, bool init = true)
{ {
static FMPLoggerInterface *logger = nullptr; FMPLoggerInterface* svc = FMP::GetService<FMPLoggerInterface>();
if (init && ctx && !logger) { if (svc) {
ctkServiceReference ref = ctx->getServiceReference<FMPLoggerInterface>(); svc->SetLoggerName(moduleName);
if (ref) {
logger = ctx->getService<FMPLoggerInterface>(ref);
}
} }
else if (!init) { return svc;
logger = nullptr;
}
return logger;
} }
}; };
Q_DECLARE_INTERFACE(FMPLoggerInterface, "com.fmp.logger") Q_DECLARE_INTERFACE(FMPLoggerInterface, "fmp.logger")
#include "fmp_logstream.h" #include "fmp_logstream.h"
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QCoreApplication> #include <QCoreApplication>
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include <log4cxx/log4cxx.h> #include <log4cxx/log4cxx.h>
#include <log4cxx/logger.h> #include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h> #include <log4cxx/basicconfigurator.h>
...@@ -14,11 +12,9 @@ ...@@ -14,11 +12,9 @@
using namespace log4cxx; using namespace log4cxx;
using namespace log4cxx::spi; using namespace log4cxx::spi;
FMPLoggerPrivate::FMPLoggerPrivate(FMPLogger *q, ctkPluginContext *ctx) FMPLoggerPrivate::FMPLoggerPrivate(FMPLogger *q)
: q_ptr(q), : q_ptr(q),
_ctx(ctx), _inited(false)
_inited(false),
_file_index(0)
{ {
} }
...@@ -63,7 +59,9 @@ int FMPLoggerPrivate::Uninit() ...@@ -63,7 +59,9 @@ int FMPLoggerPrivate::Uninit()
void FMPLoggerPrivate::Log(short level, const QString &msg, const char* file, const char* func, int line) void FMPLoggerPrivate::Log(short level, const QString &msg, const char* file, const char* func, int line)
{ {
LoggerPtr logger = Logger::getRootLogger(); Q_Q(FMPLogger);
LoggerPtr logger = Logger::getLogger(q->currentModule.toUtf8().data());
switch(level) switch(level)
{ {
case FMPLogStream::ERROR: case FMPLogStream::ERROR:
...@@ -141,14 +139,14 @@ void FMPLoggerPrivate::SetLogPath(const QString &path) ...@@ -141,14 +139,14 @@ void FMPLoggerPrivate::SetLogPath(const QString &path)
bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v) bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v)
{ {
Q_Q(FMPLogger); Q_Q(FMPLogger);
FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx); // FMPSettingsInterface *sets = FMPManagerPlugin::GetManager()->GetService<FMPSettingsInterface>();
if (sets) { // if (sets) {
sets->SetValue(key, v); // sets->SetValue(key, v);
return true; // return true;
} // }
else { // else {
FMP_WARN() << "Settings service not available"; // FMP_WARN() << "Settings service not available";
} // }
return false; return false;
} }
...@@ -156,13 +154,13 @@ bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v) ...@@ -156,13 +154,13 @@ bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v)
QVariant FMPLoggerPrivate::_GetValue(const QString &key, QVariant default_val) QVariant FMPLoggerPrivate::_GetValue(const QString &key, QVariant default_val)
{ {
Q_Q(FMPLogger); Q_Q(FMPLogger);
FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx); // FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx);
if (sets) { // if (sets) {
return sets->GetValue(key); // return sets->GetValue(key);
} // }
else { // else {
FMP_WARN() << "Settings service not available"; // FMP_WARN() << "Settings service not available";
} // }
return default_val; return default_val;
} }
...@@ -7,7 +7,7 @@ class FMPLoggerPrivate ...@@ -7,7 +7,7 @@ class FMPLoggerPrivate
{ {
Q_DECLARE_PUBLIC(FMPLogger) Q_DECLARE_PUBLIC(FMPLogger)
public: public:
explicit FMPLoggerPrivate(FMPLogger *q, ctkPluginContext *ctx); explicit FMPLoggerPrivate(FMPLogger *q);
int Init(); int Init();
int Uninit(); int Uninit();
short GetLogLevel(); short GetLogLevel();
...@@ -26,12 +26,6 @@ protected: ...@@ -26,12 +26,6 @@ protected:
public: public:
bool _inited; bool _inited;
FMPLogger *q_ptr; FMPLogger *q_ptr;
ctkPluginContext *_ctx;
QMap<short, QString> _lvlmap;
int _file_index;
QDateTime _log_date;
}; };
#endif // FMP_LOGGER_P_H #endif // FMP_LOGGER_P_H
#ifndef FMP_LOGGERSTREAM_H #ifndef FMP_LOGGERSTREAM_H
#define FMP_LOGGERSTREAM_H #define FMP_LOGGERSTREAM_H
#include <QObject> #include <QObject>
#include <QDebug> #include <QDebug>
...@@ -11,9 +11,8 @@ public: ...@@ -11,9 +11,8 @@ public:
enum { enum {
ERROR = 1, WARNING, INFO, DEBUG ERROR = 1, WARNING, INFO, DEBUG
}; };
explicit FMPLogStream(FMPLoggerInterface *logger, short level, const char* file, const char* func, int line) explicit FMPLogStream(short level, const char* file, const char* func, int line)
: _logger(logger), : _level(level),
_level(level),
_file(file), _file(file),
_func(func), _func(func),
_line(line) _line(line)
...@@ -23,8 +22,9 @@ public: ...@@ -23,8 +22,9 @@ public:
~FMPLogStream() ~FMPLogStream()
{ {
if (_logger) { FMPLoggerInterface *logger = FMPLoggerInterface::GetLogger();
_logger->Log(_level, _content, _file, _func, _line); if (logger) {
logger->Log(_level, _content, _file, _func, _line);
} }
else { else {
qDebug() << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << _content; qDebug() << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << _content;
...@@ -47,7 +47,6 @@ public: ...@@ -47,7 +47,6 @@ public:
} }
protected: protected:
FMPLoggerInterface* _logger;
int _level; int _level;
const char * _file; const char * _file;
const char * _func; const char * _func;
...@@ -57,13 +56,13 @@ protected: ...@@ -57,13 +56,13 @@ protected:
}; };
//! 快速日志记录宏定义 //! 快速日志记录宏定义
#define FMP_LOG(lvl, log) FMPLogStream(log, lvl, __FILE__, __FUNCTION__, __LINE__) #define FMP_LOG(lvl) FMPLogStream(lvl, __FILE__, __FUNCTION__, __LINE__)
#define FMP_DEBUG() FMP_LOG(FMPLoggerInterface::LOG_DEBUG, FMPLoggerInterface::InitContext()) #define FMP_DEBUG() FMP_LOG(FMPLoggerInterface::LOG_DEBUG)
#define FMP_INFO() FMP_LOG(FMPLoggerInterface::LOG_INFO, FMPLoggerInterface::InitContext()) #define FMP_INFO() FMP_LOG(FMPLoggerInterface::LOG_INFO)
#define FMP_WARN() FMP_LOG(FMPLoggerInterface::LOG_WARNING, FMPLoggerInterface::InitContext()) #define FMP_WARN() FMP_LOG(FMPLoggerInterface::LOG_WARNING)
#define FMP_ERROR() FMP_LOG(FMPLoggerInterface::LOG_ERROR, FMPLoggerInterface::InitContext()) #define FMP_ERROR() FMP_LOG(FMPLoggerInterface::LOG_ERROR)
#endif // FMP_LOGSTREAM_H #endif // FMP_LOGSTREAM_H
...@@ -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 64 #define VER_BUILD 65
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
...@@ -60,6 +60,7 @@ protected: ...@@ -60,6 +60,7 @@ protected:
QFileInfo GetPluginInfo(const QString &plugin_name, const QString &ver = QString()); QFileInfo GetPluginInfo(const QString &plugin_name, const QString &ver = QString());
QStringList GetNewPlugins(); QStringList GetNewPlugins();
QVariantList GetExpiredPlugins(); QVariantList GetExpiredPlugins();
const FMPContext GetContext() const { return fwContext; }
private slots: private slots:
...@@ -68,17 +69,17 @@ private slots: ...@@ -68,17 +69,17 @@ private slots:
void OnServiceEvent(const ctkServiceEvent& event); void OnServiceEvent(const ctkServiceEvent& event);
private: private:
QSharedPointer<ctkPluginFramework> _fw; QSharedPointer<ctkPluginFramework> fw;
ctkPluginFrameworkFactory *_fw_factory; FMPContext fwContext;
ctkProperties _fw_props; QFileSystemWatcher pluginWatcher;
ctkPluginContext *_ctx;
QFileSystemWatcher _watcher;
FMPSettingsInterface *_setting; FMPSettingsInterface* setting;
FMPSyncerInterface *_syncer; FMPSyncerInterface* syncer;
FMPEventHandlerList _event_handlers; FMPEventHandlerList eventHandlers;
QStack<QSharedPointer<ctkPlugin> > _plugins; QStack<QSharedPointer<ctkPlugin> > plugins;
QJsonObject fwProps;
}; };
#endif // FMPLUGINMANAGER_H #endif // FMPLUGINMANAGER_H
...@@ -11,7 +11,7 @@ HEADERS += \ ...@@ -11,7 +11,7 @@ HEADERS += \
fmp_manager.h \ fmp_manager.h \
fmp_manager_i.h \ fmp_manager_i.h \
fmp_me_handlers.h \ fmp_me_handlers.h \
fmp_manager_def.h fmp_manager_d.h
#Target name #Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET) VER = $$system($$PWD/../fmprc.bat $$TARGET)
......
#ifndef FMP_MANAGER_EVENTS_H #ifndef FMP_MANAGER_D_H
#define FMP_MANAGER_EVENTS_H #define FMP_MANAGER_D_H
//! 话题 //! 话题
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
#define FMP_PROPKEY_AGREED "FMPAgreed" #define FMP_PROPKEY_AGREED "FMPAgreed"
#define FMP_PROPKEY_PROCID "FMPProcId" #define FMP_PROPKEY_PROCID "FMPProcId"
#endif // FMP_MANAGER_EVENTS_H #endif // FMP_MANAGER_D_H
#ifndef FMP_MANAGER_I_H #ifndef FMP_MANAGER_I_H
#define FMP_MANAGER_I_H #define FMP_MANAGER_I_H
#include <QSharedPointer>
#include <QPluginLoader>
#include <QDir>
#include <QFileInfo>
#include <QDirIterator>
#include <QJsonDocument>
#include <QCoreApplication>
#include <fmp_base_i.h> #include <fmp_base_i.h>
#include <ctkPluginContext.h>
#include "fmp_manager_d.h"
class FMPManagerInterface;
typedef FMPManagerInterface* FMPManager;
typedef ctkPluginContext* FMPContext;
#include "fmp_manager_def.h"
/** /**
* 非业务插件接口,必须继承自 BaseInterface * 非业务插件接口,必须继承自 BaseInterface
...@@ -12,13 +24,14 @@ ...@@ -12,13 +24,14 @@
class FMPManagerInterface : public FMPBaseInterface class FMPManagerInterface : public FMPBaseInterface
{ {
public: public:
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
/** /**
* 加载插件目录下的所有新插件 * 加载插件目录下的所有新插件
* 首次运行时,所有插件都视为新插件 * 首次运行时,所有插件都视为新插件
* @brief LoadNewPlugins * @brief LoadNewPlugins
* @return * @return
*/ */
virtual void LoadNewPlugins() = 0; virtual void LoadNewPlugins() = 0;
/** /**
* 加载并启动插件 install, start * 加载并启动插件 install, start
...@@ -27,7 +40,7 @@ public: ...@@ -27,7 +40,7 @@ public:
* @param plugin 插件名称 * @param plugin 插件名称
* @return * @return
*/ */
virtual int LoadPlugin(const QString &plugin) = 0; virtual int LoadPlugin(const QString &plugin) = 0;
/** /**
* 请求更新旧版本插件 * 请求更新旧版本插件
...@@ -35,7 +48,7 @@ public: ...@@ -35,7 +48,7 @@ public:
* @param pids * @param pids
* @return * @return
*/ */
virtual void UpgradeOldPlugins(const QVariantList &pids) = 0; virtual void UpgradeOldPlugins(const QVariantList &pids) = 0;
/** /**
* 升级指定的插件 * 升级指定的插件
...@@ -43,17 +56,228 @@ public: ...@@ -43,17 +56,228 @@ public:
* @param pid 插件ID * @param pid 插件ID
* @return * @return
*/ */
virtual int UpgradePlugin(long pid) = 0; virtual int UpgradePlugin(long pid) = 0;
/**
* 获取服务
* @brief GetService
* @return
*/
template <class T>
T* GetService()
{
T* svc = nullptr;
FMPContext ctx = GetContext();
if (ctx) {
try {
ctkServiceReference ref = ctx->getServiceReference<T>();
if (!ref) {
if (LoadPlugin(qobject_interface_iid<T*>()) == FMP_SUCCESS) {
svc = GetService<T>();
}
}
else {
svc = ctx->getService<T>(ref);
}
}
catch(...) {}
}
return svc;
}
/** /**
* 设置插件参数 * 根据服务名称获取服务
* @brief SetProperties * @brief GetService
* @param props Key-Value * @param svcName
* @return * @return
*/ */
virtual int SetProperties(const FMPProps &props) = 0; template <class T>
T* GetService(const QString &svcName)
{
T* svc = nullptr;
FMPContext ctx = GetContext();
if (ctx) {
try {
ctkServiceReference ref = ctx->getServiceReference(svcName.toUtf8().data());
if (!ref) {
ref = ctx->getServiceReference<T>();
}
if (!ref) {
if (LoadPlugin(svcName) == FMP_SUCCESS) {
svc = GetService<T>(svcName);
}
}
else {
svc = ctx->getService<T>(ref);
}
}
catch(...) {}
}
return svc;
}
/**
* 注册服务
* @brief RegisterService
* @param service
* @param props
*/
template <class T>
void RegisterService(QObject *service, const FMPProps &props)
{
FMPContext ctx = GetContext();
if (ctx) {
ctx->registerService<T>(service, props);
}
}
}; };
Q_DECLARE_INTERFACE(FMPManagerInterface, "fmp.manager") Q_DECLARE_INTERFACE(FMPManagerInterface, "fmp.manager")
///////////////////////////////////////////////////////////////////////////////
/**
* 插件管理模块加载类
* @brief The FMP class
*/
class FMP
{
public:
static FMP& Instance()
{
static FMP fmp;
return fmp;
}
static FMPManager GetManager()
{
FMP& fmp = FMP::Instance();
FMPManager svc = fmp.Service();
return svc;
}
template <class T>
static T* GetService()
{
FMPManager manager = FMP::GetManager();
return manager->GetService<T>();
}
template <class T>
static T* GetService(const QString &svcName)
{
FMPManager manager = FMP::GetManager();
return manager->GetService<T>(svcName);
}
template <class T>
static void RegisterService(QObject *svc, const FMPProps &props)
{
FMPManager manager = FMP::GetManager();
manager->RegisterService<T>(svc, props);
}
static void SetProperties(const QJsonObject &p)
{
FMP & fmp = FMP::Instance();
if (p != fmp.props) {
fmp.Unload();
fmp.props = p;
fmp.Load();
}
}
static QJsonObject& GetProperties()
{
FMP& fmp = FMP::Instance();
fmp.props.empty();
return fmp.props;
}
private:
explicit FMP() : svc(nullptr)
{
props[FMP_PROPKEY_LOADER] = "fmp.manager";
props[FMP_PROPKEY_PLUGINPATH] = "../plugins";
props[FMP_PROPKEY_ENTRY] = "fmp.home";
props[FMP_PROPKEY_CFG] = "FreemudPOS.ini";
QFile f(qApp->applicationDirPath() + "/" + props[FMP_PROPKEY_CFG].toString());
if (f.exists() && f.open(QFile::ReadWrite)) {
QJsonDocument d = QJsonDocument::fromJson(f.readAll());
if (!d.isEmpty()) {
props = d.object();
}
}
//!
props[FMP_PROPKEY_PROCID] = qApp->applicationPid();
Load();
}
void Load()
{
QString loaderPath = GetPluginPath( props[FMP_PROPKEY_LOADER].toString());
loader.setFileName(loaderPath);
bool loaded = loader.load();
if (!loaded) {
QString msg = "Failed loading plugin:\n";
msg += loaderPath + "\n";
msg += loader.errorString();
Q_ASSERT_X(loaded, __FILE__, msg.toLocal8Bit().data());
}
FMPManagerInterface *fmpManager = qobject_cast<FMPManagerInterface*>(loader.instance());
Q_ASSERT(fmpManager);
svc = fmpManager;
}
void Unload() { loader.unload(); }
FMPManager Service() const { return svc; }
QString GetPluginPath(const QString &pluginName)
{
QString pluginFileName(pluginName);
pluginFileName.replace(".", "_");
QStringList filters;
#ifdef Q_OS_WIN
filters << pluginFileName + "*" + ".dll";
#else
# ifdef Q_OS_LINUX
filters << pluginFileName + "*" + ".so";
# else
filters << pluginFileName + "*" + ".dylib";
# endif
#endif
QDirIterator dirIter(qApp->applicationDirPath() + "/" + props[FMP_PROPKEY_PLUGINPATH].toString(), filters, QDir::Files);
QString pluginVersion;
QFileInfo pluginFileInfo;
while(dirIter.hasNext()) {
dirIter.next();
QFileInfo fileInfo = dirIter.fileInfo();
QString fileBasename = fileInfo.completeBaseName();
if (fileBasename.startsWith("lib")) fileBasename = fileBasename.mid(3);
QString tmpVer = fileBasename.section(pluginFileName, 1, 1).replace("_", "");
if (pluginVersion.isEmpty() || pluginVersion < tmpVer) {
pluginVersion = tmpVer;
pluginFileInfo = fileInfo;
}
}
return pluginFileInfo.canonicalFilePath();
}
private:
FMPManager svc;
QJsonObject props;
QPluginLoader loader;
};
#endif // FMP_MANAGER_I_H #endif // FMP_MANAGER_I_H
...@@ -6,24 +6,23 @@ ...@@ -6,24 +6,23 @@
/** /**
* @brief 管理器事件默认构造函数 * @brief 管理器事件默认构造函数
*/ */
FMPManagerEventHandler::FMPManagerEventHandler(const QString &topic, FMPluginManager *pm, ctkPluginContext *ctx) FMPManagerEventHandler::FMPManagerEventHandler(const QString &t, FMPluginManager *pm)
: _pm(pm), : pm(pm),
_topic(topic), topic(t)
_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);
} }
/** /**
* @brief 升级事件处理方法 * @brief 升级事件处理方法
*/ */
FMPUpgradeEventHandler::FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm) FMPUpgradeEventHandler::FMPUpgradeEventHandler(FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_UPDATE, pm, ctx) : FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_UPDATE, pm)
{ {
connect(this, SIGNAL(upgrade(QVariantList)), _pm, SLOT(UpgradeOldPlugins(QVariantList))); connect(this, SIGNAL(upgrade(QVariantList)), this->pm, SLOT(UpgradeOldPlugins(QVariantList)));
} }
void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event) void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event)
...@@ -39,10 +38,10 @@ void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event) ...@@ -39,10 +38,10 @@ void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event)
/** /**
* @brief 退出事件处理方法 * @brief 退出事件处理方法
*/ */
FMPQuitEventHandler::FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm) FMPQuitEventHandler::FMPQuitEventHandler(FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_QUIT, pm, ctx) : FMPManagerEventHandler(FMP_TOPICS_QUIT, pm)
{ {
connect(this, SIGNAL(quit()), _pm, SLOT(OnStopService())); connect(this, SIGNAL(quit()), this->pm, SLOT(OnStopService()));
} }
void FMPQuitEventHandler::handleEvent(const ctkEvent &event) void FMPQuitEventHandler::handleEvent(const ctkEvent &event)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <service/event/ctkEventConstants.h> #include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h> #include <service/event/ctkEventHandler.h>
#include "fmp_manager_def.h" #include "fmp_manager_d.h"
class FMPluginManager; class FMPluginManager;
...@@ -19,12 +19,11 @@ class FMPManagerEventHandler : public QObject, public ctkEventHandler ...@@ -19,12 +19,11 @@ class FMPManagerEventHandler : public QObject, public ctkEventHandler
Q_INTERFACES(ctkEventHandler) Q_INTERFACES(ctkEventHandler)
public: public:
explicit FMPManagerEventHandler(const QString &topic, FMPluginManager *pm, ctkPluginContext *ctx); explicit FMPManagerEventHandler(const QString &t, FMPluginManager *pm);
protected: protected:
FMPluginManager* _pm; FMPluginManager* pm;
const QString _topic; const QString topic;
ctkPluginContext* _ctx;
}; };
/** /**
...@@ -35,7 +34,7 @@ class FMPUpgradeEventHandler : public FMPManagerEventHandler ...@@ -35,7 +34,7 @@ class FMPUpgradeEventHandler : public FMPManagerEventHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm); explicit FMPUpgradeEventHandler(FMPluginManager *pm);
void handleEvent(const ctkEvent &event); void handleEvent(const ctkEvent &event);
...@@ -53,7 +52,7 @@ class FMPQuitEventHandler : public FMPManagerEventHandler ...@@ -53,7 +52,7 @@ class FMPQuitEventHandler : public FMPManagerEventHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm); explicit FMPQuitEventHandler(FMPluginManager *pm);
void handleEvent(const ctkEvent &event); void handleEvent(const ctkEvent &event);
......
...@@ -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 64 #define VER_BUILD 65
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
...@@ -6,11 +6,10 @@ ...@@ -6,11 +6,10 @@
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QTimer> #include <QTimer>
FMPNetwork::FMPNetwork(ctkPluginContext *ctx) FMPNetwork::FMPNetwork(const FMPContext ctx) :
: _ctx(ctx), context(ctx),
d_ptr(new FMPNetworkPrivate(this)) d_ptr(new FMPNetworkPrivate(this))
{ {
FMPLoggerInterface::InitContext(ctx);
} }
void FMPNetwork::InitService() void FMPNetwork::InitService()
......
...@@ -15,13 +15,15 @@ class FMPNetwork : public QObject, public FMPNetworkInterface ...@@ -15,13 +15,15 @@ class FMPNetwork : public QObject, public FMPNetworkInterface
Q_DECLARE_PRIVATE(FMPNetwork) Q_DECLARE_PRIVATE(FMPNetwork)
public: public:
explicit FMPNetwork(ctkPluginContext *ctx); explicit FMPNetwork(const FMPContext ctx);
//! 基础插件接口 //! 基础插件接口
//!
protected: protected:
void InitService(); void InitService();
void UninitService(); void UninitService();
int PostEvent(const QString &topic, const FMPProps &pps); int PostEvent(const QString &topic, const FMPProps &pps);
const FMPContext GetContext() const { return context; }
public: public:
//! 网络服务接口 //! 网络服务接口
...@@ -31,8 +33,8 @@ public: ...@@ -31,8 +33,8 @@ public:
FMPSockReplyPointer Send(const FMPSocketRequest &req); FMPSockReplyPointer Send(const FMPSocketRequest &req);
private: private:
ctkPluginContext* _ctx;
FMPNetworkPrivate* d_ptr; FMPNetworkPrivate* d_ptr;
const FMPContext context;
}; };
/** /**
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "fmp_nw_request.h" #include "fmp_nw_request.h"
#include "fmp_nw_reply.h" #include "fmp_nw_reply.h"
#include <QSharedPointer> #include <QSharedPointer>
#include <ctkPluginContext.h>
typedef QSharedPointer<FMPHttpReply> FMPHttpReplyPointer; typedef QSharedPointer<FMPHttpReply> FMPHttpReplyPointer;
typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer; typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer;
...@@ -12,6 +13,8 @@ typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer; ...@@ -12,6 +13,8 @@ typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer;
class FMPNetworkInterface : public FMPBaseInterface class FMPNetworkInterface : public FMPBaseInterface
{ {
public: public:
//! BaseInterface
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
virtual FMPHttpReplyPointer HttpGet(const FMPHttpRequest &req) = 0; virtual FMPHttpReplyPointer HttpGet(const FMPHttpRequest &req) = 0;
virtual FMPHttpReplyPointer HttpPost(const FMPHttpRequest &req, const QByteArray &data) = 0; virtual FMPHttpReplyPointer HttpPost(const FMPHttpRequest &req, const QByteArray &data) = 0;
virtual FMPHttpReplyPointer HttpPut(const FMPHttpRequest &req, const QByteArray &data) = 0; virtual FMPHttpReplyPointer HttpPut(const FMPHttpRequest &req, const QByteArray &data) = 0;
...@@ -40,6 +43,6 @@ public: ...@@ -40,6 +43,6 @@ public:
}; };
Q_DECLARE_INTERFACE(FMPNetworkInterface, "com.fmp.network") Q_DECLARE_INTERFACE(FMPNetworkInterface, "fmp.network")
#endif // FMP_NETWORK_I_H #endif // FMP_NETWORK_I_H
<RCC>
<qresource prefix="/fmp.network/META-INF">
<file>MANIFEST.MF</file>
</qresource>
</RCC>
...@@ -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 56 #define VER_BUILD 65
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
#include "fmp_syncer.h" #include "fmp_syncer.h"
#include "fmp_syncer_p.h" #include "fmp_syncer_p.h"
#include <ctkPluginContext.h>
#include <QDebug> #include <QDebug>
FMPSyncer::FMPSyncer(ctkPluginContext *ctx) FMPSyncer::FMPSyncer(const FMPContext ctx)
: _ctx(ctx), : context(ctx),
d_ptr(new FMPSyncerPrivate(this)), d_ptr(new FMPSyncerPrivate(this)),
_partner_id(d_ptr->GetPartnerId()), _partner_id(d_ptr->GetPartnerId()),
_store_id(d_ptr->GetStoreId()), _store_id(d_ptr->GetStoreId()),
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#define FMP_SYNCER_H #define FMP_SYNCER_H
#include <QObject> #include <QObject>
#include <ctkPluginContext.h>
#include "fmp_syncer_i.h" #include "fmp_syncer_i.h"
class ctkPluginContext;
class FMPSyncerPrivate; class FMPSyncerPrivate;
class FMPSyncer : public QObject, public FMPSyncerInterface class FMPSyncer : public QObject, public FMPSyncerInterface
...@@ -15,14 +15,17 @@ class FMPSyncer : public QObject, public FMPSyncerInterface ...@@ -15,14 +15,17 @@ class FMPSyncer : public QObject, public FMPSyncerInterface
Q_DECLARE_PRIVATE(FMPSyncer) Q_DECLARE_PRIVATE(FMPSyncer)
public: public:
explicit FMPSyncer(ctkPluginContext *ctx); explicit FMPSyncer(const FMPContext ctx);
virtual ~FMPSyncer(); virtual ~FMPSyncer();
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
protected: protected:
//! BaseInterface //! BaseInterface
void InitService(); void InitService();
void UninitService(); void UninitService();
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps()); int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
const FMPContext GetContext() const { return context; }
public: public:
//! SyncInterface //! SyncInterface
QString GetPartnerId() const { return _partner_id; } QString GetPartnerId() const { return _partner_id; }
...@@ -45,8 +48,8 @@ public: ...@@ -45,8 +48,8 @@ public:
void SetDeployPath(const QString &path); void SetDeployPath(const QString &path);
private: private:
ctkPluginContext *_ctx;
FMPSyncerPrivate *d_ptr; FMPSyncerPrivate *d_ptr;
const FMPContext context;
int _req_timeout; int _req_timeout;
int _sync_interval; int _sync_interval;
QString _partner_id; QString _partner_id;
......
...@@ -74,6 +74,6 @@ public: ...@@ -74,6 +74,6 @@ public:
}; };
Q_DECLARE_INTERFACE(FMPSyncerInterface, "com.fmp.syncer") Q_DECLARE_INTERFACE(FMPSyncerInterface, "fmp.syncer")
#endif // FMP_SYNCER_I_H #endif // FMP_SYNCER_I_H
...@@ -22,11 +22,10 @@ ...@@ -22,11 +22,10 @@
FMPSyncerPrivate::FMPSyncerPrivate(FMPSyncer *q) FMPSyncerPrivate::FMPSyncerPrivate(FMPSyncer *q)
: _inited(false), : _inited(false),
_sets(nullptr), sets(0),
_nw(nullptr), nw(0),
q_ptr(q) q_ptr(q)
{ {
FMPLoggerInterface::InitContext(q->_ctx);
} }
int FMPSyncerPrivate::Init() int FMPSyncerPrivate::Init()
...@@ -34,8 +33,8 @@ int FMPSyncerPrivate::Init() ...@@ -34,8 +33,8 @@ int FMPSyncerPrivate::Init()
if (_inited) return FMP_SUCCESS; if (_inited) return FMP_SUCCESS;
Q_Q(FMPSyncer); Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx); sets = FMP::GetService<FMPSettingsInterface>();
_nw = q->GetService<FMPNetworkInterface>(q->_ctx); nw = FMP::GetService<FMPNetworkInterface>();
// if (_sets && _logger && _nw) { // if (_sets && _logger && _nw) {
_inited = true; _inited = true;
...@@ -146,13 +145,13 @@ void FMPSyncerPrivate::SetDeployPath(const QString &path) ...@@ -146,13 +145,13 @@ void FMPSyncerPrivate::SetDeployPath(const QString &path)
QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val) QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val)
{ {
if (!_sets) { if (!sets) {
Q_Q(FMPSyncer); Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx); sets = FMP::GetService<FMPSettingsInterface>();
} }
if (_sets) { if (sets) {
return _sets->GetValue(k, default_val); return sets->GetValue(k, default_val);
} }
else { else {
FMP_WARN() << "Settings service not available"; FMP_WARN() << "Settings service not available";
...@@ -163,13 +162,13 @@ QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val) ...@@ -163,13 +162,13 @@ QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val)
bool FMPSyncerPrivate::_SetValue(const QString &k, QVariant val) bool FMPSyncerPrivate::_SetValue(const QString &k, QVariant val)
{ {
if (!_sets) { if (!sets) {
Q_Q(FMPSyncer); Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx); sets = FMP::GetService<FMPSettingsInterface>();
} }
if (_sets) { if (sets) {
_sets->SetValue(k, val); sets->SetValue(k, val);
return true; return true;
} }
else { else {
...@@ -261,7 +260,7 @@ void FMPSyncerPrivate::run() ...@@ -261,7 +260,7 @@ void FMPSyncerPrivate::run()
QString sync_helper = _GetValue(FMP_INIKEY_SYNCHELPER, "FreemudSyncer").toString(); QString sync_helper = _GetValue(FMP_INIKEY_SYNCHELPER, "FreemudSyncer").toString();
QStringList params; QStringList params;
params << q->_ctx->getProperty(FMP_PROPKEY_PROCID).toString(); params << FMP::GetProperties()[FMP_PROPKEY_PROCID].toString();
QProcess::startDetached(sync_helper, params); QProcess::startDetached(sync_helper, params);
} }
} }
...@@ -315,7 +314,7 @@ void FMPSyncerPrivate::ReportTask(const QString& tid, const QString& msg, const ...@@ -315,7 +314,7 @@ void FMPSyncerPrivate::ReportTask(const QString& tid, const QString& msg, const
QByteArray report_json = QJsonDocument(report_req_jo).toJson(QJsonDocument::Compact); QByteArray report_json = QJsonDocument(report_req_jo).toJson(QJsonDocument::Compact);
FMP_INFO() << QString("report [%1]").arg(QString(report_json)); FMP_INFO() << QString("report [%1]").arg(QString(report_json));
FMPHttpReplyPointer reply = _nw->HttpPost(q->_task_report_url, report_json); FMPHttpReplyPointer reply = nw->HttpPost(q->_task_report_url, report_json);
if(reply->WaitResponse() == FMPHttpReply::NO_ERROR) { if(reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
QString report_rsp = reply->Response(); QString report_rsp = reply->Response();
FMP_INFO() << QString("report successful [%1]").arg(QString(report_rsp)); FMP_INFO() << QString("report successful [%1]").arg(QString(report_rsp));
...@@ -356,7 +355,7 @@ bool FMPSyncerPrivate::GetTask(QJsonObject &task_jo) ...@@ -356,7 +355,7 @@ bool FMPSyncerPrivate::GetTask(QJsonObject &task_jo)
QByteArray task_req = QJsonDocument(task_req_jo).toJson(QJsonDocument::Compact); QByteArray task_req = QJsonDocument(task_req_jo).toJson(QJsonDocument::Compact);
FMP_INFO() << QString("Checking update [%1]").arg(QString(task_req)); FMP_INFO() << QString("Checking update [%1]").arg(QString(task_req));
FMPHttpReplyPointer reply = _nw->HttpPost(q->_task_url, task_req); FMPHttpReplyPointer reply = nw->HttpPost(q->_task_url, task_req);
if( reply->WaitResponse() == FMPHttpReply::NO_ERROR ) { if( reply->WaitResponse() == FMPHttpReply::NO_ERROR ) {
QByteArray task_json = reply->Response(); QByteArray task_json = reply->Response();
FMP_DEBUG() << "Task json:" << task_json; FMP_DEBUG() << "Task json:" << task_json;
...@@ -399,7 +398,7 @@ bool FMPSyncerPrivate::UploadFiles(const QStringList &files) ...@@ -399,7 +398,7 @@ bool FMPSyncerPrivate::UploadFiles(const QStringList &files)
Q_Q(FMPSyncer); Q_Q(FMPSyncer);
QString url = QString("%1/%2_%3_%4").arg(q->_upload_url, q->_store_id, QDate::currentDate().toString("yyyyMMdd"), QFileInfo(file_path + ".zip").fileName()); QString url = QString("%1/%2_%3_%4").arg(q->_upload_url, q->_store_id, QDate::currentDate().toString("yyyyMMdd"), QFileInfo(file_path + ".zip").fileName());
FMPHttpReplyPointer reply = _nw->HttpPut(url, data); FMPHttpReplyPointer reply = nw->HttpPut(url, data);
if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) { if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
//! TODO: //! TODO:
//! 文件上传判断是否成功 //! 文件上传判断是否成功
...@@ -422,7 +421,7 @@ bool FMPSyncerPrivate::GetLatestFiles(const QString &url, QMap<QString, QString> ...@@ -422,7 +421,7 @@ bool FMPSyncerPrivate::GetLatestFiles(const QString &url, QMap<QString, QString>
bool has_latest = false; bool has_latest = false;
FMP_INFO() << QString("Get latest files on server [%1]").arg(url); FMP_INFO() << QString("Get latest files on server [%1]").arg(url);
FMPHttpReplyPointer reply = _nw->HttpGet(url + "/upgradeInfos.txt"); FMPHttpReplyPointer reply = nw->HttpGet(url + "/upgradeInfos.txt");
if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) { if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
QByteArray rsp = reply->Response(); QByteArray rsp = reply->Response();
FMP_DEBUG() << "Get server files response:" << rsp; FMP_DEBUG() << "Get server files response:" << rsp;
...@@ -515,7 +514,7 @@ QStringList FMPSyncerPrivate::DownloadFiles(const QString &url, const QMap<QStri ...@@ -515,7 +514,7 @@ QStringList FMPSyncerPrivate::DownloadFiles(const QString &url, const QMap<QStri
continue; continue;
} }
else { else {
FMPHttpReplyPointer reply = _nw->HttpGet(download_url); FMPHttpReplyPointer reply = nw->HttpGet(download_url);
if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) { if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
file.write(reply->Response()); file.write(reply->Response());
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "fmp_syncer.h" #include "fmp_syncer.h"
#include <QThread> #include <QThread>
#include <QSharedPointer>
class FMPSettingsInterface; class FMPSettingsInterface;
class FMPNetworkInterface; class FMPNetworkInterface;
...@@ -128,8 +129,8 @@ signals: ...@@ -128,8 +129,8 @@ signals:
public: public:
bool _inited; bool _inited;
FMPSyncer *q_ptr; FMPSyncer *q_ptr;
FMPSettingsInterface *_sets; FMPSettingsInterface* sets;
FMPNetworkInterface *_nw; FMPNetworkInterface* nw;
QString _deploy_dir; //! 记录程序所在的目录 QString _deploy_dir; //! 记录程序所在的目录
}; };
......
...@@ -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 55 #define VER_BUILD 65
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
fmp_takeout @ b73febe4
Subproject commit 726d67ae3813864b12031898d5713df1fc30039e Subproject commit b73febe4973c97374b3c3fde6812e005ec44b67c
fmp_vip @ 88afe087
Subproject commit ac9481ea3f610afe143fadfc3168a3395cfffdd3 Subproject commit 88afe08748c23db1325e18b2b69ddf626bdd991a
#ifndef FMP_EVENTS_H #ifndef FMP_EVENTS_H
#define FMP_EVENTS_H #define FMP_EVENTS_H
#include "../fmp_manager/fmp_manager_def.h" #include "../fmp_manager/fmp_manager_d.h"
#endif // FMP_EVENTS_H #endif // FMP_EVENTS_H
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "../common/fmp_events.h" #include "../common/fmp_events.h"
class ctkPluginContext; class ctkPluginContext;
typedef ctkPluginContext* FMPContext;
class FMPBaseInterface class FMPBaseInterface
{ {
...@@ -31,26 +32,16 @@ public: ...@@ -31,26 +32,16 @@ public:
virtual int StopService() { UninitService(); return FMP_SUCCESS; } virtual int StopService() { UninitService(); return FMP_SUCCESS; }
/** /**
* 获取插件服务 * 获取服务对应的插件编号
* @brief GetService * @brief GetName
* @param ctx 插件环境
* @return * @return
*/ */
template <class T> virtual long GetPluginId() const = 0;
T* GetService(ctkPluginContext *ctx)
{
T* svc = 0;
ctkServiceReference ref = ctx->getServiceReference<T>();
if (ref) {
svc = ctx->getService<T>(ref);
}
return svc;
}
protected: protected:
virtual void InitService() = 0; virtual void InitService() = 0;
virtual void UninitService() = 0; virtual void UninitService() = 0;
// virtual void IsAutoStart() = 0;
/** /**
* 异步发送插件事件 * 异步发送插件事件
...@@ -59,7 +50,9 @@ protected: ...@@ -59,7 +50,9 @@ protected:
* @param props 话题参数 * @param props 话题参数
* @return * @return
*/ */
virtual int PostEvent(const QString &topic, const FMPProps &pps) = 0; virtual int PostEvent(const QString &topic, const FMPProps &pps) = 0;
virtual const FMPContext GetContext() const = 0;
}; };
Q_DECLARE_INTERFACE(FMPBaseInterface, "com.fmp.base") Q_DECLARE_INTERFACE(FMPBaseInterface, "com.fmp.base")
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <fmp_base_i.h> #include <fmp_base_i.h>
#include <fmp_logger_i.h> #include <fmp_logger_i.h>
#include <fmp_manager_i.h>
#include <QSemaphore> #include <QSemaphore>
#include <ctkPluginContext.h> #include <ctkPluginContext.h>
#include <service/event/ctkEventAdmin.h> #include <service/event/ctkEventAdmin.h>
...@@ -17,7 +18,6 @@ class ctkPluginContext; ...@@ -17,7 +18,6 @@ class ctkPluginContext;
class FMPluginInterface : public FMPBaseInterface class FMPluginInterface : public FMPBaseInterface
{ {
public: public:
explicit FMPluginInterface(ctkPluginContext *ctx) : _ctx(ctx) {}
virtual ~FMPluginInterface() { _semaphore.release(); } virtual ~FMPluginInterface() { _semaphore.release(); }
/** /**
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
{ {
QString topic = FMP_TOPICS_SERVICES; QString topic = FMP_TOPICS_SERVICES;
topic += FMPE_SERVICE_REQ_START; topic += FMPE_SERVICE_REQ_START;
topic += "/" + QString::number(_ctx->getPlugin()->getPluginId()); topic += "/" + QString::number(GetPluginId());
return PostEvent(topic); return PostEvent(topic);
} }
...@@ -48,7 +48,10 @@ public: ...@@ -48,7 +48,10 @@ public:
return FMP_SUCCESS; return FMP_SUCCESS;
} }
protected: virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
protected:
virtual void TriggerInit() = 0; virtual void TriggerInit() = 0;
virtual void TriggerUninit() = 0; virtual void TriggerUninit() = 0;
...@@ -66,7 +69,7 @@ protected: ...@@ -66,7 +69,7 @@ protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps()) int PostEvent(const QString &topic, const FMPProps &pps = FMPProps())
{ {
ctkEventAdmin *event_admin = GetService<ctkEventAdmin>(_ctx); ctkEventAdmin* event_admin = FMP::GetService<ctkEventAdmin>();
if (event_admin) { if (event_admin) {
ctkEvent ctk_event(topic, pps); ctkEvent ctk_event(topic, pps);
event_admin->postEvent(ctk_event); event_admin->postEvent(ctk_event);
...@@ -81,7 +84,6 @@ protected: ...@@ -81,7 +84,6 @@ protected:
} }
protected: protected:
ctkPluginContext *_ctx;
QSemaphore _semaphore; QSemaphore _semaphore;
}; };
......
[Service] [Service]
Name=FMPService Name=FMPService
Desc=非码 POS 插件服务 Desc=\xe9\x9d\x9e\xe7\xa0\x81 POS \xe6\x8f\x92\xe4\xbb\xb6\xe6\x9c\x8d\xe5\x8a\xa1
;0 自动启动, 1 手动启动
StartType=0 StartType=0
[Plugin] [Plugin]
Path=../plugins Path=../plugins
EntryService=com.fmp.home EntryService=com.fmp.home
;动画开关,0:关闭 1:开启
Animation=1 Animation=1
[Log] [Log]
Path=log Path=log
Size=1 Size=1
;0:关闭 1:错误 2:警告 3:信息 4:调试 Level=0
Level=1
[Home] [Home]
Server=http://115.159.226.87:20001/api/user/login Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371 PartnerId=1521
StoreId=pos_coco_CN9999 StoreId=9999
PosId=fm1802 PosId=01
Position=339, 251 Position=1382, 776
CashierId=001 CashierId=001
[Pay] [Pay]
...@@ -29,11 +26,43 @@ Server=https://115.159.18.100/api ...@@ -29,11 +26,43 @@ Server=https://115.159.18.100/api
Timeout=60 Timeout=60
[Vip] [Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos Server=http://member.freemudorder.com/member_today/service/restful/pos
[Syncer] [Syncer]
Interval=3 Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate TaskUrl=http://192.168.110.150:8080/api/fork/checkupdate
DeployPath=.. DeployPath=..
DownloadPath=download DownloadPath=download
[Takeout]
Server=http://wmpos.sandload.cn/api
Port=34953
Password=posoperator@freemud.cn
ShiftId=001
ShiftName=001
AutoConfirm=1
cashname=001
mates=database/fmtakeout.mates.info.ini
bill=FileBill/fmptakeout.order.info.ini
billpath=FileBill/billfile
blinkInterval=0.3
slipPort=23772
slipIp=127.0.0.1
Entryurl=
Entryport=
[Printer]
Name=Send To OneNote 16
Mode=2
PaperWidth=80
type=4
printType=2
parallel=lpt1
usb=USB-0
IP=127.0.0.1
levlel=All
Printlabel=Gprinter 2120TF
LogDays=10
[Float]
postion=@Point(1617 270)
[Service]
Name=FMPService
Desc=\xe9\x9d\x9e\xe7\xa0\x81 POS \xe6\x8f\x92\xe4\xbb\xb6\xe6\x9c\x8d\xe5\x8a\xa1
StartType=0
[Plugin]
Path=../plugins
EntryService=com.fmp.home
Animation=1
[Log]
Path=log
Size=1
Level=1
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371
StoreId=fm99999
PosId=fm1802
Position=1666, 276
CashierId=001
[Pay]
Server=https://115.159.18.100/api
Timeout=60
[Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos
[Syncer]
Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate
DeployPath=..
DownloadPath=download
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
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