Commit 003c0a6c by guanghui.cui

插件更新

parent 219c2b68
......@@ -6,7 +6,8 @@ CONFIG += c++11
TARGET = FreemudPOS
TEMPLATE = app
INCLUDEPATH += $$PWD/../include/interface \
INCLUDEPATH += $$PWD/../include/ctk \
$$PWD/../include/interface \
CONFIG(debug, debug|release) {
DESTDIR = $$PWD/../debug/bins
......@@ -23,4 +24,4 @@ HEADERS += \
../include/application/fm_singleton.h
SOURCES += \
fm_pos_app.cpp
fmp_app.cpp
......@@ -8,6 +8,7 @@
#ifdef Q_OS_WIN
#include <Windows.h>
#include <vld.h>
//! 命名冲突
#undef StartService
......@@ -36,6 +37,14 @@ public:
setServiceDescription(_description);
}
~FMPService()
{
if (_setting) {
delete _setting;
_setting = nullptr;
}
}
bool 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:
{ }
~QtService()
{
if (app) {
delete app;
app = 0;
}
}
protected:
......
[Service]
Name=FMPService
Desc=非码 POS 插件服务
;0 自动启动, 1 手动启动
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
;动画开关,0:关闭 1:开启
Animation=1
[Log]
Path=log
Size=1
;0:关闭 1:错误 2:警告 3:信息 4:调试
Level=4
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371
StoreId=pos_coco_CN9999
PosId=fm1802
Position=339, 251
PartnerId=1521
StoreId=9999
PosId=01
Position=1479, 521
CashierId=001
[Pay]
......@@ -29,11 +26,11 @@ Server=https://115.159.18.100/api
Timeout=60
[Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos
Server=http://member.freemudorder.com/member_today/service/restful/pos
[Syncer]
Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate
TaskUrl=http://192.168.110.150:8080/api/fork/checkupdate
DeployPath=..
DownloadPath=download
......@@ -43,11 +40,29 @@ Port=34953
Password=posoperator@freemud.cn
ShiftId=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=
Entryport=
[Printer]
Name=Microsoft XPS Document Writer
Name=Fax
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=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 @@
#include "fmp_logger_p.h"
FMPLogger::FMPLogger(ctkPluginContext *context)
FMPLogger::FMPLogger(const FMPContext ctx)
: QObject(),
d_ptr(new FMPLoggerPrivate(this, context)),
pluginContext(ctx),
d_ptr(new FMPLoggerPrivate(this)),
_max_size(d_ptr->GetMaxLogSize()),
_path(d_ptr->GetLogPath()),
_file(0),
_level(d_ptr->GetLogLevel())
{
FMPLoggerInterface::InitContext(context);
StartService();
}
......
......@@ -7,7 +7,6 @@
#include "fmp_logger_i.h"
class ctkPluginContext;
class FMPLoggerPrivate;
class FMPLogger : public QObject, public FMPLoggerInterface
......@@ -18,7 +17,7 @@ class FMPLogger : public QObject, public FMPLoggerInterface
Q_DECLARE_PRIVATE(FMPLogger)
public:
explicit FMPLogger(ctkPluginContext *context);
explicit FMPLogger(const FMPContext ctx);
~FMPLogger();
protected:
......@@ -28,8 +27,11 @@ protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
const FMPContext GetContext() const { return pluginContext; }
public:
//! LogInterface
void SetLoggerName(const QString &modleName) { currentModule = modleName; }
void Log(short level, const QString &msg, const char* file, const char* func, int line);
short GetLogLevel() const;
void SetLogLevel(short level);
......@@ -46,6 +48,8 @@ private:
uint _max_size;
QFile *_file;
QString _path;
QString currentModule;
const FMPContext pluginContext;
};
#endif // FMP_LOGGER_H
......@@ -2,11 +2,12 @@
#define FMP_LOGGER_I_H
#include <fmp_base_i.h>
#include <fmp_manager_i.h>
#include <ctkServiceReference.h>
#include <ctkPluginContext.h>
#include "fmp_logger_def.h"
class FMPLoggerInterface;
/**
* 非业务插件接口,必须继承自 BaseInterface
......@@ -17,6 +18,15 @@ class FMPLoggerInterface : public FMPBaseInterface
public:
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
* 函数方式记录日志
......@@ -75,33 +85,18 @@ public:
*/
virtual void SetPath(const QString &path) = 0;
/**
* @brief GetIODevice
* 获取文件输出设备指针(Stream使用)
* @return QIODevice*
*/
virtual QIODevice* GetIODevice() = 0;
static
FMPLoggerInterface* InitContext(ctkPluginContext *ctx = nullptr, bool init = true)
static FMPLoggerInterface* GetLogger(const QString &moduleName = QString())
{
static FMPLoggerInterface *logger = nullptr;
if (init && ctx && !logger) {
ctkServiceReference ref = ctx->getServiceReference<FMPLoggerInterface>();
if (ref) {
logger = ctx->getService<FMPLoggerInterface>(ref);
}
FMPLoggerInterface* svc = FMP::GetService<FMPLoggerInterface>();
if (svc) {
svc->SetLoggerName(moduleName);
}
else if (!init) {
logger = nullptr;
}
return logger;
return svc;
}
};
Q_DECLARE_INTERFACE(FMPLoggerInterface, "com.fmp.logger")
Q_DECLARE_INTERFACE(FMPLoggerInterface, "fmp.logger")
#include "fmp_logstream.h"
......
......@@ -4,8 +4,6 @@
#include <QDir>
#include <QFileInfo>
#include <QCoreApplication>
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include <log4cxx/log4cxx.h>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
......@@ -14,11 +12,9 @@
using namespace log4cxx;
using namespace log4cxx::spi;
FMPLoggerPrivate::FMPLoggerPrivate(FMPLogger *q, ctkPluginContext *ctx)
FMPLoggerPrivate::FMPLoggerPrivate(FMPLogger *q)
: q_ptr(q),
_ctx(ctx),
_inited(false),
_file_index(0)
_inited(false)
{
}
......@@ -63,7 +59,9 @@ int FMPLoggerPrivate::Uninit()
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)
{
case FMPLogStream::ERROR:
......@@ -141,14 +139,14 @@ void FMPLoggerPrivate::SetLogPath(const QString &path)
bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v)
{
Q_Q(FMPLogger);
FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx);
if (sets) {
sets->SetValue(key, v);
return true;
}
else {
FMP_WARN() << "Settings service not available";
}
// FMPSettingsInterface *sets = FMPManagerPlugin::GetManager()->GetService<FMPSettingsInterface>();
// if (sets) {
// sets->SetValue(key, v);
// return true;
// }
// else {
// FMP_WARN() << "Settings service not available";
// }
return false;
}
......@@ -156,13 +154,13 @@ bool FMPLoggerPrivate::_SetValue(const QString &key, QVariant v)
QVariant FMPLoggerPrivate::_GetValue(const QString &key, QVariant default_val)
{
Q_Q(FMPLogger);
FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx);
if (sets) {
return sets->GetValue(key);
}
else {
FMP_WARN() << "Settings service not available";
}
// FMPSettingsInterface *sets = q->GetService<FMPSettingsInterface>(_ctx);
// if (sets) {
// return sets->GetValue(key);
// }
// else {
// FMP_WARN() << "Settings service not available";
// }
return default_val;
}
......@@ -7,7 +7,7 @@ class FMPLoggerPrivate
{
Q_DECLARE_PUBLIC(FMPLogger)
public:
explicit FMPLoggerPrivate(FMPLogger *q, ctkPluginContext *ctx);
explicit FMPLoggerPrivate(FMPLogger *q);
int Init();
int Uninit();
short GetLogLevel();
......@@ -26,12 +26,6 @@ protected:
public:
bool _inited;
FMPLogger *q_ptr;
ctkPluginContext *_ctx;
QMap<short, QString> _lvlmap;
int _file_index;
QDateTime _log_date;
};
#endif // FMP_LOGGER_P_H
#ifndef FMP_LOGGERSTREAM_H
#ifndef FMP_LOGGERSTREAM_H
#define FMP_LOGGERSTREAM_H
#include <QObject>
#include <QDebug>
......@@ -11,9 +11,8 @@ public:
enum {
ERROR = 1, WARNING, INFO, DEBUG
};
explicit FMPLogStream(FMPLoggerInterface *logger, short level, const char* file, const char* func, int line)
: _logger(logger),
_level(level),
explicit FMPLogStream(short level, const char* file, const char* func, int line)
: _level(level),
_file(file),
_func(func),
_line(line)
......@@ -23,8 +22,9 @@ public:
~FMPLogStream()
{
if (_logger) {
_logger->Log(_level, _content, _file, _func, _line);
FMPLoggerInterface *logger = FMPLoggerInterface::GetLogger();
if (logger) {
logger->Log(_level, _content, _file, _func, _line);
}
else {
qDebug() << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") << _content;
......@@ -47,7 +47,6 @@ public:
}
protected:
FMPLoggerInterface* _logger;
int _level;
const char * _file;
const char * _func;
......@@ -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_INFO() FMP_LOG(FMPLoggerInterface::LOG_INFO, FMPLoggerInterface::InitContext())
#define FMP_WARN() FMP_LOG(FMPLoggerInterface::LOG_WARNING, FMPLoggerInterface::InitContext())
#define FMP_ERROR() FMP_LOG(FMPLoggerInterface::LOG_ERROR, FMPLoggerInterface::InitContext())
#define FMP_DEBUG() FMP_LOG(FMPLoggerInterface::LOG_DEBUG)
#define FMP_INFO() FMP_LOG(FMPLoggerInterface::LOG_INFO)
#define FMP_WARN() FMP_LOG(FMPLoggerInterface::LOG_WARNING)
#define FMP_ERROR() FMP_LOG(FMPLoggerInterface::LOG_ERROR)
#endif // FMP_LOGSTREAM_H
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 64
#define VER_BUILD 65
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -60,6 +60,7 @@ protected:
QFileInfo GetPluginInfo(const QString &plugin_name, const QString &ver = QString());
QStringList GetNewPlugins();
QVariantList GetExpiredPlugins();
const FMPContext GetContext() const { return fwContext; }
private slots:
......@@ -68,17 +69,17 @@ private slots:
void OnServiceEvent(const ctkServiceEvent& event);
private:
QSharedPointer<ctkPluginFramework> _fw;
ctkPluginFrameworkFactory *_fw_factory;
ctkProperties _fw_props;
ctkPluginContext *_ctx;
QFileSystemWatcher _watcher;
QSharedPointer<ctkPluginFramework> fw;
FMPContext fwContext;
QFileSystemWatcher pluginWatcher;
FMPSettingsInterface *_setting;
FMPSyncerInterface *_syncer;
FMPSettingsInterface* setting;
FMPSyncerInterface* syncer;
FMPEventHandlerList _event_handlers;
QStack<QSharedPointer<ctkPlugin> > _plugins;
FMPEventHandlerList eventHandlers;
QStack<QSharedPointer<ctkPlugin> > plugins;
QJsonObject fwProps;
};
#endif // FMPLUGINMANAGER_H
......@@ -11,7 +11,7 @@ HEADERS += \
fmp_manager.h \
fmp_manager_i.h \
fmp_me_handlers.h \
fmp_manager_def.h
fmp_manager_d.h
#Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET)
......
#ifndef FMP_MANAGER_EVENTS_H
#define FMP_MANAGER_EVENTS_H
#ifndef FMP_MANAGER_D_H
#define FMP_MANAGER_D_H
//! 话题
......@@ -17,4 +17,4 @@
#define FMP_PROPKEY_AGREED "FMPAgreed"
#define FMP_PROPKEY_PROCID "FMPProcId"
#endif // FMP_MANAGER_EVENTS_H
#endif // FMP_MANAGER_D_H
#ifndef 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 <ctkPluginContext.h>
#include "fmp_manager_d.h"
class FMPManagerInterface;
typedef FMPManagerInterface* FMPManager;
typedef ctkPluginContext* FMPContext;
#include "fmp_manager_def.h"
/**
* 非业务插件接口,必须继承自 BaseInterface
......@@ -12,13 +24,14 @@
class FMPManagerInterface : public FMPBaseInterface
{
public:
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
/**
* 加载插件目录下的所有新插件
* 首次运行时,所有插件都视为新插件
* @brief LoadNewPlugins
* @return
*/
virtual void LoadNewPlugins() = 0;
virtual void LoadNewPlugins() = 0;
/**
* 加载并启动插件 install, start
......@@ -27,7 +40,7 @@ public:
* @param plugin 插件名称
* @return
*/
virtual int LoadPlugin(const QString &plugin) = 0;
virtual int LoadPlugin(const QString &plugin) = 0;
/**
* 请求更新旧版本插件
......@@ -35,7 +48,7 @@ public:
* @param pids
* @return
*/
virtual void UpgradeOldPlugins(const QVariantList &pids) = 0;
virtual void UpgradeOldPlugins(const QVariantList &pids) = 0;
/**
* 升级指定的插件
......@@ -43,17 +56,228 @@ public:
* @param pid 插件ID
* @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
* @param props Key-Value
* 根据服务名称获取服务
* @brief GetService
* @param svcName
* @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")
///////////////////////////////////////////////////////////////////////////////
/**
* 插件管理模块加载类
* @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
......@@ -6,24 +6,23 @@
/**
* @brief 管理器事件默认构造函数
*/
FMPManagerEventHandler::FMPManagerEventHandler(const QString &topic, FMPluginManager *pm, ctkPluginContext *ctx)
: _pm(pm),
_topic(topic),
_ctx(ctx)
FMPManagerEventHandler::FMPManagerEventHandler(const QString &t, FMPluginManager *pm)
: pm(pm),
topic(t)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
props[ctkEventConstants::EVENT_TOPIC] = topic;
FMP::RegisterService<ctkEventHandler>(this, props);
}
/**
* @brief 升级事件处理方法
*/
FMPUpgradeEventHandler::FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_UPDATE, pm, ctx)
FMPUpgradeEventHandler::FMPUpgradeEventHandler(FMPluginManager *pm)
: 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)
......@@ -39,10 +38,10 @@ void FMPUpgradeEventHandler::handleEvent(const ctkEvent &event)
/**
* @brief 退出事件处理方法
*/
FMPQuitEventHandler::FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm)
: FMPManagerEventHandler(FMP_TOPICS_QUIT, pm, ctx)
FMPQuitEventHandler::FMPQuitEventHandler(FMPluginManager *pm)
: 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)
......
......@@ -5,7 +5,7 @@
#include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h>
#include "fmp_manager_def.h"
#include "fmp_manager_d.h"
class FMPluginManager;
......@@ -19,12 +19,11 @@ class FMPManagerEventHandler : public QObject, public ctkEventHandler
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPManagerEventHandler(const QString &topic, FMPluginManager *pm, ctkPluginContext *ctx);
explicit FMPManagerEventHandler(const QString &t, FMPluginManager *pm);
protected:
FMPluginManager* _pm;
const QString _topic;
ctkPluginContext* _ctx;
FMPluginManager* pm;
const QString topic;
};
/**
......@@ -35,7 +34,7 @@ class FMPUpgradeEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public:
explicit FMPUpgradeEventHandler(ctkPluginContext *ctx, FMPluginManager *pm);
explicit FMPUpgradeEventHandler(FMPluginManager *pm);
void handleEvent(const ctkEvent &event);
......@@ -53,7 +52,7 @@ class FMPQuitEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public:
explicit FMPQuitEventHandler(ctkPluginContext *ctx, FMPluginManager *pm);
explicit FMPQuitEventHandler(FMPluginManager *pm);
void handleEvent(const ctkEvent &event);
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 64
#define VER_BUILD 65
//! Convert version numbers to string
#define _STR(S) #S
......
......@@ -6,11 +6,10 @@
#include <QtNetwork/QNetworkReply>
#include <QTimer>
FMPNetwork::FMPNetwork(ctkPluginContext *ctx)
: _ctx(ctx),
d_ptr(new FMPNetworkPrivate(this))
FMPNetwork::FMPNetwork(const FMPContext ctx) :
context(ctx),
d_ptr(new FMPNetworkPrivate(this))
{
FMPLoggerInterface::InitContext(ctx);
}
void FMPNetwork::InitService()
......
......@@ -15,13 +15,15 @@ class FMPNetwork : public QObject, public FMPNetworkInterface
Q_DECLARE_PRIVATE(FMPNetwork)
public:
explicit FMPNetwork(ctkPluginContext *ctx);
explicit FMPNetwork(const FMPContext ctx);
//! 基础插件接口
//!
protected:
void InitService();
void UninitService();
int PostEvent(const QString &topic, const FMPProps &pps);
const FMPContext GetContext() const { return context; }
public:
//! 网络服务接口
......@@ -31,8 +33,8 @@ public:
FMPSockReplyPointer Send(const FMPSocketRequest &req);
private:
ctkPluginContext* _ctx;
FMPNetworkPrivate* d_ptr;
const FMPContext context;
};
/**
......
......@@ -5,6 +5,7 @@
#include "fmp_nw_request.h"
#include "fmp_nw_reply.h"
#include <QSharedPointer>
#include <ctkPluginContext.h>
typedef QSharedPointer<FMPHttpReply> FMPHttpReplyPointer;
typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer;
......@@ -12,6 +13,8 @@ typedef QSharedPointer<FMPSocketReply> FMPSockReplyPointer;
class FMPNetworkInterface : public FMPBaseInterface
{
public:
//! BaseInterface
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
virtual FMPHttpReplyPointer HttpGet(const FMPHttpRequest &req) = 0;
virtual FMPHttpReplyPointer HttpPost(const FMPHttpRequest &req, const QByteArray &data) = 0;
virtual FMPHttpReplyPointer HttpPut(const FMPHttpRequest &req, const QByteArray &data) = 0;
......@@ -40,6 +43,6 @@ public:
};
Q_DECLARE_INTERFACE(FMPNetworkInterface, "com.fmp.network")
Q_DECLARE_INTERFACE(FMPNetworkInterface, "fmp.network")
#endif // FMP_NETWORK_I_H
<RCC>
<qresource prefix="/fmp.network/META-INF">
<file>MANIFEST.MF</file>
</qresource>
</RCC>
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 56
#define VER_BUILD 65
//! Convert version numbers to string
#define _STR(S) #S
......
#include "fmp_syncer.h"
#include "fmp_syncer_p.h"
#include <ctkPluginContext.h>
#include <QDebug>
FMPSyncer::FMPSyncer(ctkPluginContext *ctx)
: _ctx(ctx),
FMPSyncer::FMPSyncer(const FMPContext ctx)
: context(ctx),
d_ptr(new FMPSyncerPrivate(this)),
_partner_id(d_ptr->GetPartnerId()),
_store_id(d_ptr->GetStoreId()),
......
......@@ -2,9 +2,9 @@
#define FMP_SYNCER_H
#include <QObject>
#include <ctkPluginContext.h>
#include "fmp_syncer_i.h"
class ctkPluginContext;
class FMPSyncerPrivate;
class FMPSyncer : public QObject, public FMPSyncerInterface
......@@ -15,14 +15,17 @@ class FMPSyncer : public QObject, public FMPSyncerInterface
Q_DECLARE_PRIVATE(FMPSyncer)
public:
explicit FMPSyncer(ctkPluginContext *ctx);
explicit FMPSyncer(const FMPContext ctx);
virtual ~FMPSyncer();
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
protected:
//! BaseInterface
void InitService();
void UninitService();
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps());
const FMPContext GetContext() const { return context; }
public:
//! SyncInterface
QString GetPartnerId() const { return _partner_id; }
......@@ -45,8 +48,8 @@ public:
void SetDeployPath(const QString &path);
private:
ctkPluginContext *_ctx;
FMPSyncerPrivate *d_ptr;
const FMPContext context;
int _req_timeout;
int _sync_interval;
QString _partner_id;
......
......@@ -74,6 +74,6 @@ public:
};
Q_DECLARE_INTERFACE(FMPSyncerInterface, "com.fmp.syncer")
Q_DECLARE_INTERFACE(FMPSyncerInterface, "fmp.syncer")
#endif // FMP_SYNCER_I_H
......@@ -22,11 +22,10 @@
FMPSyncerPrivate::FMPSyncerPrivate(FMPSyncer *q)
: _inited(false),
_sets(nullptr),
_nw(nullptr),
sets(0),
nw(0),
q_ptr(q)
{
FMPLoggerInterface::InitContext(q->_ctx);
}
int FMPSyncerPrivate::Init()
......@@ -34,8 +33,8 @@ int FMPSyncerPrivate::Init()
if (_inited) return FMP_SUCCESS;
Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx);
_nw = q->GetService<FMPNetworkInterface>(q->_ctx);
sets = FMP::GetService<FMPSettingsInterface>();
nw = FMP::GetService<FMPNetworkInterface>();
// if (_sets && _logger && _nw) {
_inited = true;
......@@ -146,13 +145,13 @@ void FMPSyncerPrivate::SetDeployPath(const QString &path)
QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val)
{
if (!_sets) {
if (!sets) {
Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx);
sets = FMP::GetService<FMPSettingsInterface>();
}
if (_sets) {
return _sets->GetValue(k, default_val);
if (sets) {
return sets->GetValue(k, default_val);
}
else {
FMP_WARN() << "Settings service not available";
......@@ -163,13 +162,13 @@ QVariant FMPSyncerPrivate::_GetValue(const QString &k, QVariant default_val)
bool FMPSyncerPrivate::_SetValue(const QString &k, QVariant val)
{
if (!_sets) {
if (!sets) {
Q_Q(FMPSyncer);
_sets = q->GetService<FMPSettingsInterface>(q->_ctx);
sets = FMP::GetService<FMPSettingsInterface>();
}
if (_sets) {
_sets->SetValue(k, val);
if (sets) {
sets->SetValue(k, val);
return true;
}
else {
......@@ -261,7 +260,7 @@ void FMPSyncerPrivate::run()
QString sync_helper = _GetValue(FMP_INIKEY_SYNCHELPER, "FreemudSyncer").toString();
QStringList params;
params << q->_ctx->getProperty(FMP_PROPKEY_PROCID).toString();
params << FMP::GetProperties()[FMP_PROPKEY_PROCID].toString();
QProcess::startDetached(sync_helper, params);
}
}
......@@ -315,7 +314,7 @@ void FMPSyncerPrivate::ReportTask(const QString& tid, const QString& msg, const
QByteArray report_json = QJsonDocument(report_req_jo).toJson(QJsonDocument::Compact);
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) {
QString report_rsp = reply->Response();
FMP_INFO() << QString("report successful [%1]").arg(QString(report_rsp));
......@@ -356,7 +355,7 @@ bool FMPSyncerPrivate::GetTask(QJsonObject &task_jo)
QByteArray task_req = QJsonDocument(task_req_jo).toJson(QJsonDocument::Compact);
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 ) {
QByteArray task_json = reply->Response();
FMP_DEBUG() << "Task json:" << task_json;
......@@ -399,7 +398,7 @@ bool FMPSyncerPrivate::UploadFiles(const QStringList &files)
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());
FMPHttpReplyPointer reply = _nw->HttpPut(url, data);
FMPHttpReplyPointer reply = nw->HttpPut(url, data);
if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
//! TODO:
//! 文件上传判断是否成功
......@@ -422,7 +421,7 @@ bool FMPSyncerPrivate::GetLatestFiles(const QString &url, QMap<QString, QString>
bool has_latest = false;
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) {
QByteArray rsp = reply->Response();
FMP_DEBUG() << "Get server files response:" << rsp;
......@@ -515,7 +514,7 @@ QStringList FMPSyncerPrivate::DownloadFiles(const QString &url, const QMap<QStri
continue;
}
else {
FMPHttpReplyPointer reply = _nw->HttpGet(download_url);
FMPHttpReplyPointer reply = nw->HttpGet(download_url);
if (reply->WaitResponse() == FMPHttpReply::NO_ERROR) {
file.write(reply->Response());
}
......
......@@ -3,6 +3,7 @@
#include "fmp_syncer.h"
#include <QThread>
#include <QSharedPointer>
class FMPSettingsInterface;
class FMPNetworkInterface;
......@@ -128,8 +129,8 @@ signals:
public:
bool _inited;
FMPSyncer *q_ptr;
FMPSettingsInterface *_sets;
FMPNetworkInterface *_nw;
FMPSettingsInterface* sets;
FMPNetworkInterface* nw;
QString _deploy_dir; //! 记录程序所在的目录
};
......
......@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 55
#define VER_BUILD 65
//! Convert version numbers to string
#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
#define FMP_EVENTS_H
#include "../fmp_manager/fmp_manager_def.h"
#include "../fmp_manager/fmp_manager_d.h"
#endif // FMP_EVENTS_H
......@@ -11,6 +11,7 @@
#include "../common/fmp_events.h"
class ctkPluginContext;
typedef ctkPluginContext* FMPContext;
class FMPBaseInterface
{
......@@ -31,26 +32,16 @@ public:
virtual int StopService() { UninitService(); return FMP_SUCCESS; }
/**
* 获取插件服务
* @brief GetService
* @param ctx 插件环境
* 获取服务对应的插件编号
* @brief GetName
* @return
*/
template <class T>
T* GetService(ctkPluginContext *ctx)
{
T* svc = 0;
ctkServiceReference ref = ctx->getServiceReference<T>();
if (ref) {
svc = ctx->getService<T>(ref);
}
return svc;
}
virtual long GetPluginId() const = 0;
protected:
virtual void InitService() = 0;
virtual void UninitService() = 0;
// virtual void IsAutoStart() = 0;
/**
* 异步发送插件事件
......@@ -59,7 +50,9 @@ protected:
* @param props 话题参数
* @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")
......
......@@ -8,6 +8,7 @@
#include <fmp_base_i.h>
#include <fmp_logger_i.h>
#include <fmp_manager_i.h>
#include <QSemaphore>
#include <ctkPluginContext.h>
#include <service/event/ctkEventAdmin.h>
......@@ -17,7 +18,6 @@ class ctkPluginContext;
class FMPluginInterface : public FMPBaseInterface
{
public:
explicit FMPluginInterface(ctkPluginContext *ctx) : _ctx(ctx) {}
virtual ~FMPluginInterface() { _semaphore.release(); }
/**
......@@ -31,7 +31,7 @@ public:
{
QString topic = FMP_TOPICS_SERVICES;
topic += FMPE_SERVICE_REQ_START;
topic += "/" + QString::number(_ctx->getPlugin()->getPluginId());
topic += "/" + QString::number(GetPluginId());
return PostEvent(topic);
}
......@@ -48,7 +48,10 @@ public:
return FMP_SUCCESS;
}
protected:
virtual long GetPluginId() const { return GetContext()->getPlugin()->getPluginId(); }
protected:
virtual void TriggerInit() = 0;
virtual void TriggerUninit() = 0;
......@@ -66,7 +69,7 @@ protected:
int PostEvent(const QString &topic, const FMPProps &pps = FMPProps())
{
ctkEventAdmin *event_admin = GetService<ctkEventAdmin>(_ctx);
ctkEventAdmin* event_admin = FMP::GetService<ctkEventAdmin>();
if (event_admin) {
ctkEvent ctk_event(topic, pps);
event_admin->postEvent(ctk_event);
......@@ -81,7 +84,6 @@ protected:
}
protected:
ctkPluginContext *_ctx;
QSemaphore _semaphore;
};
......
[Service]
Name=FMPService
Desc=非码 POS 插件服务
;0 自动启动, 1 手动启动
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
;动画开关,0:关闭 1:开启
Animation=1
[Log]
Path=log
Size=1
;0:关闭 1:错误 2:警告 3:信息 4:调试
Level=1
Level=0
[Home]
Server=http://115.159.226.87:20001/api/user/login
PartnerId=1371
StoreId=pos_coco_CN9999
PosId=fm1802
Position=339, 251
PartnerId=1521
StoreId=9999
PosId=01
Position=1382, 776
CashierId=001
[Pay]
......@@ -29,11 +26,43 @@ Server=https://115.159.18.100/api
Timeout=60
[Vip]
Server=http://jtest.sandload.cn/member_tianfu/service/restful/pos
Server=http://member.freemudorder.com/member_today/service/restful/pos
[Syncer]
Interval=3
TaskUrl=http://115.159.33.143/api/fork/checkupdate
TaskUrl=http://192.168.110.150:8080/api/fork/checkupdate
DeployPath=..
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