Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmPOS
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaojing.zhang
fmPOS
Commits
62ee3e06
Commit
62ee3e06
authored
Apr 17, 2017
by
Carwyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "1. 基础接口调整,使用 InitService 初始化服务,UninitService 释放服务"
This reverts commit
9bb5223e
.
parent
9bb5223e
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
69 additions
and
140 deletions
+69
-140
fmp_logger/fmp_logger.cpp
+4
-4
fmp_logger/fmp_logger.h
+3
-4
fmp_logger/fmp_logger.pro
+0
-1
fmp_logger/fmp_logger_i.h
+2
-5
fmp_logger/version.h
+1
-1
fmp_manager/fmp_manager.cpp
+16
-31
fmp_manager/fmp_manager.h
+5
-10
fmp_manager/fmp_me_handlers.cpp
+11
-17
fmp_manager/fmp_me_handlers.h
+6
-8
fmp_manager/version.h
+1
-1
fmp_network/fmp_network.cpp
+4
-4
fmp_network/fmp_network.h
+2
-5
fmp_network/version.h
+1
-1
fmp_syncer/fmp_syncer.cpp
+5
-9
fmp_syncer/fmp_syncer.h
+3
-4
fmp_syncer/version.h
+1
-1
include/common/fmp_constants.h
+0
-3
include/interface/fmp_base_i.h
+2
-5
include/interface/fmp_plugin_i.h
+2
-26
No files found.
fmp_logger/fmp_logger.cpp
View file @
62ee3e06
...
...
@@ -39,14 +39,14 @@ FMPLogger::~FMPLogger()
delete
d_ptr
;
}
void
FMPLogger
::
Ini
tService
()
int
FMPLogger
::
Star
tService
()
{
d_func
()
->
Init
();
return
d_func
()
->
Init
();
}
void
FMPLogger
::
Uninit
Service
()
int
FMPLogger
::
Stop
Service
()
{
d_func
()
->
Uninit
();
return
d_func
()
->
Uninit
();
}
void
FMPLogger
::
Log
(
short
level
,
const
QString
&
msg
,
const
char
*
file
,
const
char
*
func
,
int
line
)
...
...
fmp_logger/fmp_logger.h
View file @
62ee3e06
...
...
@@ -22,11 +22,10 @@ public:
explicit
FMPLogger
(
ctkPluginContext
*
context
);
~
FMPLogger
();
protected
:
//! BaseInterface
void
Ini
tService
();
void
Uninit
Service
();
int
Star
tService
();
int
Stop
Service
();
protected
:
int
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
=
FMPProps
());
public
:
...
...
fmp_logger/fmp_logger.pro
View file @
62ee3e06
...
...
@@ -28,7 +28,6 @@ unix {
#Target name
VER
=
$$
system
(
$$
PWD
/../
fmprc
.
bat
$$
TARGET
)
#VER = 0.1.1
ORIGIN_TARGET
=
$$
TARGET
TARGET
=
$$
{
TARGET
}
_
$$
{
VER
}
...
...
fmp_logger/fmp_logger_i.h
View file @
62ee3e06
...
...
@@ -82,18 +82,15 @@ public:
static
FMPLoggerInterface
*
InitContext
(
bool
init
=
true
,
ctkPluginContext
*
ctx
=
nullptr
)
FMPLoggerInterface
*
InitContext
(
ctkPluginContext
*
ctx
=
nullptr
)
{
static
FMPLoggerInterface
*
logger
=
nullptr
;
if
(
init
&&
ctx
&&
!
logger
)
{
if
(
ctx
&&
!
logger
)
{
ctkServiceReference
ref
=
ctx
->
getServiceReference
<
FMPLoggerInterface
>
();
if
(
ref
)
{
logger
=
ctx
->
getService
<
FMPLoggerInterface
>
(
ref
);
}
}
else
if
(
!
init
)
{
logger
=
nullptr
;
}
return
logger
;
}
...
...
fmp_logger/version.h
View file @
62ee3e06
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 4
5
#define VER_BUILD 4
3
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_manager/fmp_manager.cpp
View file @
62ee3e06
...
...
@@ -25,9 +25,9 @@ FMPluginManager::~FMPluginManager()
StopService
();
}
void
FMPluginManager
::
Ini
tService
()
int
FMPluginManager
::
Star
tService
()
{
if
(
_fw_factory
)
return
;
if
(
_fw_factory
)
return
FMP_SUCCESS
;
_fw_factory
=
new
ctkPluginFrameworkFactory
(
_fw_props
);
...
...
@@ -94,45 +94,34 @@ void FMPluginManager::InitService()
FMP_ERROR
()
<<
e
.
cause
()
->
what
();
exit
(
FMP_FAILURE
);
}
return
FMP_SUCCESS
;
}
void
FMPluginManager
::
Uninit
Service
()
int
FMPluginManager
::
Stop
Service
()
{
if
(
_fw_factory
)
{
FMP_INFO
()
<<
"======================== Quit ========================"
;
_watcher
.
removePath
(
_fw_props
[
FMP_PROPKEY_PLUGINPATH
].
toString
());
_event_handlers
.
clear
();
//! 优雅关闭
try
{
// QList<ctkServiceReference> svcs = _ctx->getServiceReferences();
// foreach(ctkServiceReference s, svcs) {
// QSharedPointer<ctkPlugin> p = s.getPlugin();
// qDebug() << p->getSymbolicName() << p->getPluginId() << "---";
// if (p->getPluginId() > 0) {
// p->stop();
// }
// }
_fw
->
stop
();
while
(
_fw
->
waitForStop
(
200
).
getType
()
==
ctkPluginFrameworkEvent
::
FRAMEWORK_WAIT_TIMEDOUT
)
{
QCoreApplication
::
processEvents
();
}
}
catch
(
const
ctkPluginException
&
e
)
{
FMP_ERROR
()
<<
e
.
cause
()
->
what
();
}
delete
_fw_factory
;
_fw_factory
=
nullptr
;
_ctx
=
nullptr
;
_fw
.
clear
();
_event_handlers
.
clear
();
//! TODO: 优雅关闭
// if (_fw_factory) {
// delete _fw_factory;
// _fw_factory = nullptr;
// _ctx = nullptr;
// _fw.clear();
// }
qApp
->
quit
();
}
else
{
FMP_WARN
()
<<
"Stopping in progress..."
;
}
return
FMP_SUCCESS
;
}
int
FMPluginManager
::
SetProperties
(
const
FMPProps
&
props
)
...
...
@@ -198,9 +187,6 @@ int FMPluginManager::UpgradePlugin(long pid)
if
(
p
)
{
QString
plugin_name
=
p
->
getSymbolicName
();
p
->
stop
();
//! TODO: 检查停止之前,服务是否处理启动状态,
//! 如果是,则需要启动服务
return
LoadPlugin
(
plugin_name
);
}
...
...
@@ -232,7 +218,6 @@ void FMPluginManager::OnPluginsChanged(const QString &path)
if
(
!
expired_plugins
.
isEmpty
())
{
FMPProps
props
;
props
[
FMP_PROPKEY_PID_LIST
]
=
expired_plugins
;
//! Request plugin update
PostEvent
(
QString
(
FMP_TOPICS_SERVICES
)
+
FMPE_SERVICE_REQ_UPDATE
,
props
);
}
}
...
...
fmp_manager/fmp_manager.h
View file @
62ee3e06
...
...
@@ -32,25 +32,20 @@ public:
explicit
FMPluginManager
();
~
FMPluginManager
();
protected
:
//! 基础接口
void
InitService
();
void
UninitService
();
int
StartService
();
int
StopService
();
int
SetProperties
(
const
FMPProps
&
props
);
protected
:
int
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
=
FMPProps
());
public
:
//! 管理器接口
void
LoadNewPlugins
();
int
LoadPlugin
(
const
QString
&
plugin
);
void
UpgradeOldPlugins
(
const
QVariantList
&
);
int
UpgradePlugin
(
long
pid
);
int
SetProperties
(
const
FMPProps
&
props
);
public
slots
:
void
OnStartService
()
{
StartService
();
}
void
OnStopService
()
{
StopService
();
}
void
UpgradeOldPlugins
(
const
QVariantList
&
);
public
slots
:
void
OnPluginsChanged
(
const
QString
&
path
);
...
...
fmp_manager/fmp_me_handlers.cpp
View file @
62ee3e06
#
include
<
fmp_logger_i
.
h
>
#include "fmp_me_handlers.h"
#include "fmp_manager.h"
#include <QCoreApplication>
/**
* @brief 管理器事件默认构造函数
...
...
@@ -20,33 +19,28 @@ FMPManagerEventHandler::FMPManagerEventHandler(const QString &topic, FMPluginMan
/**
* @brief 升级事件处理方法
*/
FMPUpgradeEventHandler
::
FMPUpgradeEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
)
:
FMPManagerEventHandler
(
FMP_TOPICS_SERVICES
FMPE_SERVICE_ACK_UPDATE
,
pm
,
ctx
)
{
connect
(
this
,
SIGNAL
(
upgrade
(
QVariantList
)),
_pm
,
SLOT
(
UpgradeOldPlugins
(
QVariantList
)));
}
void
FMPUpgradeEventHandler
::
handleEvent
(
const
ctkEvent
&
event
)
{
if
(
!
event
.
getProperty
(
FMP_PROPKEY_PID_LIST
).
toList
().
isEmpty
())
{
emit
upgrade
(
event
.
getProperty
(
FMP_PROPKEY_PID_LIST
).
toList
());
if
(
_pm
)
{
if
(
event
.
getProperty
(
FMP_PROPKEY_AGREED
).
toBool
())
{
_pm
->
UpgradeOldPlugins
(
event
.
getProperty
(
FMP_PROPKEY_PID_LIST
).
toList
());
}
}
else
{
FMP_DEBUG
()
<<
"No
plugin ids.
"
<<
event
.
getTopic
();
FMP_DEBUG
()
<<
"No
handler instance for event
"
<<
event
.
getTopic
();
}
}
/**
* @brief 退出事件处理方法
*/
FMPQuitEventHandler
::
FMPQuitEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
)
:
FMPManagerEventHandler
(
FMP_TOPICS_QUIT
,
pm
,
ctx
)
{
connect
(
this
,
SIGNAL
(
quit
()),
_pm
,
SLOT
(
OnStopService
()));
}
void
FMPQuitEventHandler
::
handleEvent
(
const
ctkEvent
&
event
)
{
emit
quit
();
if
(
_pm
)
{
_pm
->
deleteLater
();
}
else
{
FMP_DEBUG
()
<<
"No handler instance for event"
<<
event
.
getTopic
();
}
}
fmp_manager/fmp_me_handlers.h
View file @
62ee3e06
...
...
@@ -35,13 +35,12 @@ class FMPUpgradeEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public
:
explicit
FMPUpgradeEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
);
explicit
FMPUpgradeEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
)
:
FMPManagerEventHandler
(
FMP_TOPICS_SERVICES
FMPE_SERVICE_REQ_UPDATE
,
pm
,
ctx
)
{}
void
handleEvent
(
const
ctkEvent
&
event
);
signals
:
void
upgrade
(
const
QVariantList
&
pid_list
);
private
:
};
...
...
@@ -53,12 +52,11 @@ class FMPQuitEventHandler : public FMPManagerEventHandler
{
Q_OBJECT
public
:
explicit
FMPQuitEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
);
explicit
FMPQuitEventHandler
(
ctkPluginContext
*
ctx
,
FMPluginManager
*
pm
)
:
FMPManagerEventHandler
(
FMP_TOPICS_QUIT
,
pm
,
ctx
)
{}
void
handleEvent
(
const
ctkEvent
&
event
);
signals
:
void
quit
();
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
fmp_manager/version.h
View file @
62ee3e06
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 4
5
#define VER_BUILD 4
3
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_network/fmp_network.cpp
View file @
62ee3e06
...
...
@@ -13,14 +13,14 @@ FMPNetwork::FMPNetwork(ctkPluginContext *ctx)
FMPLoggerInterface
::
InitContext
(
ctx
);
}
void
FMPNetwork
::
Ini
tService
()
int
FMPNetwork
::
Star
tService
()
{
//!
FMP_NOIMPL;
return
FMP_NOIMPL
;
}
void
FMPNetwork
::
Uninit
Service
()
int
FMPNetwork
::
Stop
Service
()
{
//!
FMP_NOIMPL;
return
FMP_NOIMPL
;
}
int
FMPNetwork
::
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
)
...
...
fmp_network/fmp_network.h
View file @
62ee3e06
...
...
@@ -17,13 +17,10 @@ class FMPNetwork : public QObject, public FMPNetworkInterface
public
:
explicit
FMPNetwork
(
ctkPluginContext
*
ctx
);
//! 基础插件接口
//!
protected:
void
InitService
();
void
UninitService
();
int
StartService
();
int
StopService
();
int
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
);
public
:
//! 网络服务接口
FMPHttpReplyPointer
HttpGet
(
const
FMPHttpRequest
&
req
);
FMPHttpReplyPointer
HttpPost
(
const
FMPHttpRequest
&
req
,
const
QByteArray
&
data
);
...
...
fmp_network/version.h
View file @
62ee3e06
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 4
5
#define VER_BUILD 4
3
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_syncer/fmp_syncer.cpp
View file @
62ee3e06
...
...
@@ -20,23 +20,19 @@ FMPSyncer::FMPSyncer(ctkPluginContext *ctx)
StartService
();
}
FMPSyncer
::~
FMPSyncer
()
int
FMPSyncer
::
StartService
()
{
StopService
();
return
d_func
()
->
Init
();
}
void
FMPSyncer
::
InitService
()
{
d_func
()
->
Init
();
}
void
FMPSyncer
::
UninitService
()
int
FMPSyncer
::
StopService
()
{
if
(
d_ptr
)
{
d_ptr
->
terminate
();
delete
d_ptr
;
d_ptr
=
nullptr
;
}
return
FMP_SUCCESS
;
}
int
FMPSyncer
::
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
)
...
...
fmp_syncer/fmp_syncer.h
View file @
62ee3e06
...
...
@@ -16,12 +16,11 @@ class FMPSyncer : public QObject, public FMPSyncerInterface
public
:
explicit
FMPSyncer
(
ctkPluginContext
*
ctx
);
virtual
~
FMPSyncer
();
protected
:
//! BaseInterface
void
InitService
();
void
UninitService
();
int
StartService
();
int
StopService
();
protected
:
int
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
=
FMPProps
());
public
:
//! SyncInterface
...
...
fmp_syncer/version.h
View file @
62ee3e06
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 4
5
#define VER_BUILD 4
3
//! Convert version numbers to string
#define _STR(S) #S
...
...
include/common/fmp_constants.h
View file @
62ee3e06
...
...
@@ -5,9 +5,6 @@
//! 插件错误代码
#define FMP_SUCCESS 0
#define FMP_START_PENDING 1
#define FMP_STOP_PENDING 2
#define FMP_FAILURE -1
#define FMP_REFUSED -2
#define FMP_NOIMPL -3
...
...
include/interface/fmp_base_i.h
View file @
62ee3e06
...
...
@@ -21,14 +21,14 @@ public:
* 失败返回 \link FMP_FAILURE \endlink。
* FMP_REFUSED
*/
virtual
int
StartService
()
{
InitService
();
return
FMP_SUCCESS
;
}
virtual
int
StartService
()
=
0
;
/**
* 停止插件服务
* @brief StopService
* @return
*/
virtual
int
StopService
()
{
UninitService
();
return
FMP_SUCCESS
;
}
virtual
int
StopService
()
=
0
;
/**
* 获取插件服务
...
...
@@ -49,9 +49,6 @@ public:
}
protected
:
virtual
void
InitService
()
=
0
;
virtual
void
UninitService
()
=
0
;
/**
* 异步发送插件事件
* @brief PostEvent
...
...
include/interface/fmp_plugin_i.h
View file @
62ee3e06
...
...
@@ -8,7 +8,6 @@
#include <fmp_base_i.h>
#include <fmp_logger_i.h>
#include <QSemaphore>
#include <ctkPluginContext.h>
#include <service/event/ctkEventAdmin.h>
...
...
@@ -17,16 +16,9 @@ class ctkPluginContext;
class
FMPluginInterface
:
public
FMPBaseInterface
{
public
:
explicit
FMPluginInterface
(
ctkPluginContext
*
ctx
)
:
_ctx
(
ctx
)
{}
explicit
FMPluginInterface
(
ctkPluginContext
*
ctx
)
:
_ctx
(
ctx
){}
/**
* 业务插件启动只能请求启动,由事件订阅者决定是否允许启动
* -允许:订阅者通知业务插件,业务插件事件处理器触发 TriggerInit
* -拒绝:订阅者通知业务插件
* @brief StartService
* @return
*/
virtual
int
StartService
()
int
StartService
()
{
QString
topic
=
FMP_TOPICS_SERVICES
;
topic
+=
FMPE_SERVICE_REQ_START
;
...
...
@@ -34,22 +26,7 @@ public:
return
PostEvent
(
topic
);
}
/**
* 默认异步启动插件,以确保业务资源释放都在主线程中
* @brief StopService
* @return
*/
virtual
int
StopService
()
{
TriggerUninit
();
_semaphore
.
acquire
(
1
);
return
FMP_SUCCESS
;
}
protected
:
virtual
void
TriggerInit
()
=
0
;
virtual
void
TriggerUninit
()
=
0
;
int
PostEvent
(
const
QString
&
topic
,
const
FMPProps
&
pps
=
FMPProps
())
{
ctkEventAdmin
*
event_admin
=
GetService
<
ctkEventAdmin
>
(
_ctx
);
...
...
@@ -68,7 +45,6 @@ protected:
protected
:
ctkPluginContext
*
_ctx
;
QSemaphore
_semaphore
;
};
Q_DECLARE_INTERFACE
(
FMPluginInterface
,
"com.fmp.plugin"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment