- 重构部分代码 修复在resetUkey和析构函数中重复调用disConnectDev释放相同的设备句柄从而导致崩溃的问题 虹膜人脸一体设备在拔出时无法释放内存并且会阻塞进程,当释放人脸虹膜设备对象时,如果当前设备已经被拔出了,就重启服务,释放资源。 (#25243) 启用驱动时,扫描当前设备,创建对应的设备对象;禁用驱动时,释放当前对应的设备对象 (#25387) 修复文件安装路径错误
1753 lines
62 KiB
Diff
1753 lines
62 KiB
Diff
From fe1104186ef3fe8978b75b01960cd147c99665bf Mon Sep 17 00:00:00 2001
|
||
From: luoqing <luoqing@kylinsec.com.cn>
|
||
Date: Thu, 6 Jul 2023 14:41:24 +0800
|
||
Subject: [PATCH 3/6] refactor(*):Modify the code according to the
|
||
https://gitee.com/openeuler/kiran-authentication-devices/pulls/17 review
|
||
opinions
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
- 根据 https://gitee.com/openeuler/kiran-authentication-devices/pulls/17 评审意见修改代码
|
||
---
|
||
CMakeLists.txt | 7 +-
|
||
data/CMakeLists.txt | 14 +-
|
||
data/config.h.in | 5 +-
|
||
data/device.conf | 26 ++--
|
||
data/driver.conf | 5 +-
|
||
include/auth-enum.h | 5 -
|
||
src/auth-device-manager.cpp | 130 +++++++++---------
|
||
src/auth-device-manager.h | 10 +-
|
||
src/config-helper.cpp | 67 ++++++---
|
||
src/config-helper.h | 15 +-
|
||
src/device/auth-device.cpp | 86 ++++++++++--
|
||
src/device/auth-device.h | 30 ++--
|
||
src/device/bio-device.cpp | 47 +++----
|
||
src/device/bio-device.h | 18 +--
|
||
src/device/device-creator.cpp | 19 +--
|
||
src/device/device-creator.h | 2 +-
|
||
src/device/finger-vein/fv-sd-device.cpp | 32 +----
|
||
src/device/finger-vein/fv-sd-device.h | 4 +-
|
||
src/device/fingerprint/fp-zk-device.cpp | 30 +---
|
||
src/device/fingerprint/fp-zk-device.h | 4 +-
|
||
.../multi-function/mf-iristar-device.cpp | 32 ++---
|
||
src/device/multi-function/mf-iristar-device.h | 7 +-
|
||
src/device/ukey/ukey-skf-device.cpp | 77 +++--------
|
||
src/device/ukey/ukey-skf-device.h | 6 +-
|
||
.../multi-function/mf-iristar-driver.cpp | 71 +++-------
|
||
src/driver/multi-function/mf-iristar-driver.h | 8 +-
|
||
src/feature-db.cpp | 2 +-
|
||
src/utils.cpp | 29 +---
|
||
src/utils.h | 3 -
|
||
ukey-manager/ukey-manager.cpp | 1 +
|
||
30 files changed, 359 insertions(+), 433 deletions(-)
|
||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||
index 122d4be..d1189aa 100644
|
||
--- a/CMakeLists.txt
|
||
+++ b/CMakeLists.txt
|
||
@@ -19,9 +19,14 @@ set(CMAKE_CXX_STANDARD 11)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
||
set(TRANSLATION_INSTALL_DIR ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/translations)
|
||
-configure_file(${CMAKE_SOURCE_DIR}/data/config.h.in ${CMAKE_BINARY_DIR}/config.h)
|
||
+set(CONF_INSTALL_DIR /${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME})
|
||
|
||
add_subdirectory(src)
|
||
add_subdirectory(data)
|
||
add_subdirectory(ukey-manager)
|
||
|
||
+
|
||
+set(KAD_INSTALL_INCLUDE ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
||
+
|
||
+install(FILES ${PROJECT_SOURCE_DIR}/include/kiran-auth-device-i.h
|
||
+ DESTINATION ${KAD_INSTALL_INCLUDE}/)
|
||
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
|
||
index 44846ff..617cd14 100644
|
||
--- a/data/CMakeLists.txt
|
||
+++ b/data/CMakeLists.txt
|
||
@@ -1,6 +1,5 @@
|
||
cmake_minimum_required(VERSION 3.2)
|
||
|
||
-set(SYSCONFDIR "/etc")
|
||
# init variables
|
||
if(SYSTEMD_FOUND)
|
||
pkg_get_variable(SYSTEM_UNIT_DIR systemd systemdsystemunitdir)
|
||
@@ -29,15 +28,16 @@ install(FILES ${PROJECT_BINARY_DIR}/data/com.kylinsec.Kiran.AuthDevice.service
|
||
DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/dbus-1/system-services)
|
||
|
||
install(FILES ${PROJECT_SOURCE_DIR}/data/driver.conf
|
||
- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME})
|
||
+ DESTINATION ${CONF_INSTALL_DIR})
|
||
|
||
install(FILES ${PROJECT_SOURCE_DIR}/data/device.conf
|
||
- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME})
|
||
+ DESTINATION ${CONF_INSTALL_DIR})
|
||
|
||
install(FILES ${PROJECT_SOURCE_DIR}/data/ukey-manager.conf
|
||
- DESTINATION ${SYSCONFDIR}/${PROJECT_NAME})
|
||
+ DESTINATION ${CONF_INSTALL_DIR})
|
||
|
||
-set(KAD_INSTALL_INCLUDE ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
||
+set(DRIVER_CONF_PATH ${CONF_INSTALL_DIR}/driver.conf)
|
||
+set(DEVICE_CONF_PATH ${CONF_INSTALL_DIR}/device.conf)
|
||
+set(UKEY_MANAGER_CONF_PATH ${CONF_INSTALL_DIR}/ukey-manager.conf)
|
||
|
||
-install(FILES ${PROJECT_SOURCE_DIR}/include/kiran-auth-device-i.h
|
||
- DESTINATION ${KAD_INSTALL_INCLUDE}/)
|
||
\ No newline at end of file
|
||
+configure_file(${CMAKE_SOURCE_DIR}/data/config.h.in ${CMAKE_BINARY_DIR}/config.h)
|
||
\ No newline at end of file
|
||
diff --git a/data/config.h.in b/data/config.h.in
|
||
index d0b327a..fb1f582 100644
|
||
--- a/data/config.h.in
|
||
+++ b/data/config.h.in
|
||
@@ -1,3 +1,6 @@
|
||
#pragma once
|
||
|
||
-#define TRANSLATE_PREFIX "@TRANSLATION_INSTALL_DIR@"
|
||
+#define TRANSLATE_PREFIX "@TRANSLATION_INSTALL_DIR@"
|
||
+#define DEVICE_CONF "@DEVICE_CONF_PATH@"
|
||
+#define DRIVER_CONF "@DRIVER_CONF_PATH@"
|
||
+#define UKEY_MANAGER_CONF "@UKEY_MANAGER_CONF_PATH@"
|
||
\ No newline at end of file
|
||
diff --git a/data/device.conf b/data/device.conf
|
||
index 9a367bf..6d7d83b 100644
|
||
--- a/data/device.conf
|
||
+++ b/data/device.conf
|
||
@@ -3,50 +3,40 @@
|
||
#Name=
|
||
#设备类型
|
||
#Type=
|
||
-#设备的标识VID,PID.通过标识可找到该设备属于哪种类型的设备
|
||
-#Vid=
|
||
+#设备Id,由设备vid和pid组成,以,分隔组成列表。通过标识可找到该设备属于哪种类型的设备
|
||
+#Id=vid1:pid1,vid2:pid2
|
||
#Pid=
|
||
#驱动名,与driver.conf中的相对应
|
||
#Driver=
|
||
-#对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so;
|
||
-#LibPath=
|
||
|
||
[ZKFingerpint]
|
||
Name= ZKFingerpint
|
||
# 设备类型
|
||
Type=0
|
||
# 设备的标识VID,PID.通过标识可找到该设备属于哪种类型的设备
|
||
-Vid=1b55
|
||
-Pid=0120
|
||
+Id=1b55:0120
|
||
Driver= zkfp
|
||
|
||
[sd]
|
||
Name=saintdeem
|
||
Type=2
|
||
-Vid=05e3
|
||
-Pid=0608
|
||
+Id=05e3:0608
|
||
Driver=sdfv
|
||
|
||
[iristar]
|
||
Name=iristar
|
||
Type=1,3
|
||
-Vid=04b4
|
||
-Pid=00f3
|
||
+Id=04b4:00f3
|
||
Driver=irs_sdk2
|
||
|
||
[ft-skf]
|
||
Name=Feitian UKey
|
||
Type=5
|
||
-Vid=096e
|
||
-Pid=0309
|
||
+Id=096e:0309
|
||
Driver=ukey-skf-ft
|
||
-LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libes_3000gm.so
|
||
|
||
[fish-skf]
|
||
Name=YuWeng UKey
|
||
Type=5
|
||
-Vid=4612
|
||
-Pid=04b4
|
||
-Driver=ukey-skf-fish
|
||
-#对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so;
|
||
-LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libGDBapi.so
|
||
\ No newline at end of file
|
||
+Id=4612:04b4
|
||
+Driver=ukey-skf-fish
|
||
\ No newline at end of file
|
||
diff --git a/data/driver.conf b/data/driver.conf
|
||
index 917c9ab..135d592 100644
|
||
--- a/data/driver.conf
|
||
+++ b/data/driver.conf
|
||
@@ -2,6 +2,7 @@
|
||
#[DriverName] #驱动名,必填,与实际so对应
|
||
#Enable #是否开启,必填,不填写则默认禁用
|
||
#Type #设备类型,必填; 指纹-0;Refer to enum DeviceType in file /usr/include/kiran-authentication-device/kiran-auth-device-i.h
|
||
+#LibPath #对于UKey设备必填,其他类型设备选填:指定加载so的绝对路径;一般不用填,不填则加载默认so;
|
||
[zkfp]
|
||
Enable=true
|
||
Type=0
|
||
@@ -20,7 +21,9 @@ Type=1,3
|
||
[ukey-skf-ft]
|
||
Enable=true
|
||
Type=5
|
||
+LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libes_3000gm.so
|
||
|
||
[ukey-skf-fish]
|
||
Enable=true
|
||
-Type=5
|
||
\ No newline at end of file
|
||
+Type=5
|
||
+LibPath=/usr/lib64/kiran-authentication-devices-sdk/ukey/skf/libGDBapi.so
|
||
\ No newline at end of file
|
||
diff --git a/include/auth-enum.h b/include/auth-enum.h
|
||
index 28d8853..b9e9e49 100644
|
||
--- a/include/auth-enum.h
|
||
+++ b/include/auth-enum.h
|
||
@@ -19,11 +19,6 @@ namespace Kiran
|
||
{
|
||
#define DATABASE_DIR "/usr/share/kiran-authentication-devices"
|
||
|
||
-#define DRIVER_BLACK_LIST_CONF "/etc/kiran-authentication-device/driver-blacklist.conf"
|
||
-#define DEVICE_CONF "/etc/kiran-authentication-devices/device.conf"
|
||
-#define DRIVER_CONF "/etc/kiran-authentication-devices/driver.conf"
|
||
-#define UKEY_MANAGER_CONF "/etc/kiran-authentication-devices/ukey-manager.conf"
|
||
-
|
||
#define AUTH_USER_ADMIN "com.kylinsec.kiran.authentication.user-administration"
|
||
|
||
#define FT_UKEY_DRIVER_LIB "libes_3000gm.so"
|
||
diff --git a/src/auth-device-manager.cpp b/src/auth-device-manager.cpp
|
||
index 7cff6a6..a9f5fb0 100644
|
||
--- a/src/auth-device-manager.cpp
|
||
+++ b/src/auth-device-manager.cpp
|
||
@@ -20,6 +20,7 @@
|
||
#include <QDBusMessage>
|
||
#include "auth_device_manager_adaptor.h"
|
||
#include "config-helper.h"
|
||
+#include "config.h"
|
||
#include "device/auth-device.h"
|
||
#include "device/device-creator.h"
|
||
#include "device/ukey/ukey-skf-device.h"
|
||
@@ -31,6 +32,9 @@
|
||
|
||
namespace Kiran
|
||
{
|
||
+
|
||
+#define MAX_RETREY_CREATE_COUNT 2
|
||
+
|
||
AuthDeviceManager::AuthDeviceManager(QObject* parent) : QObject(parent)
|
||
{
|
||
}
|
||
@@ -180,15 +184,24 @@ void AuthDeviceManager::onRemove(const QDBusMessage& message, const QString& fea
|
||
void AuthDeviceManager::onSetEnableDriver(const QDBusMessage& message, const QString& driver_name, bool enable)
|
||
{
|
||
QStringList driverList = ConfigHelper::getDriverList();
|
||
- if (!driverList.contains(driver_name))
|
||
- {
|
||
- goto end;
|
||
- }
|
||
- ConfigHelper::setDriverEnabled(driver_name, enable);
|
||
+ QDBusMessage replyMessage;
|
||
|
||
- // 驱动被禁用,将当前正在使用的设备释放掉
|
||
- if (!enable)
|
||
+ do
|
||
{
|
||
+ if (!driverList.contains(driver_name))
|
||
+ {
|
||
+ replyMessage = message.createErrorReply(QDBusError::Failed, "No driver with the corresponding name was found.");
|
||
+ break;
|
||
+ }
|
||
+ ConfigHelper::setDriverEnabled(driver_name, enable);
|
||
+ replyMessage = message.createReply();
|
||
+
|
||
+ if (enable)
|
||
+ {
|
||
+ break;
|
||
+ }
|
||
+
|
||
+ // 驱动被禁用,将当前正在使用的设备释放掉
|
||
auto devices = m_deviceMap.values();
|
||
Q_FOREACH (AuthDevicePtr device, devices)
|
||
{
|
||
@@ -204,19 +217,55 @@ void AuthDeviceManager::onSetEnableDriver(const QDBusMessage& message, const QSt
|
||
Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID);
|
||
KLOG_INFO() << QString("destroyed deviceType: %1, deviceID:%2").arg(deviceType).arg(deviceID);
|
||
}
|
||
- }
|
||
-end:
|
||
- auto replyMessage = message.createReply();
|
||
+ } while (false);
|
||
+
|
||
QDBusConnection::systemBus().send(replyMessage);
|
||
}
|
||
|
||
+AuthDeviceList AuthDeviceManager::createDevices(const DeviceInfo& deviceInfo)
|
||
+{
|
||
+ // TODO:先从内置默认支持的设备开始搜索,最后才搜索第三方设备
|
||
+ QString vid = deviceInfo.idVendor;
|
||
+ QString pid = deviceInfo.idProduct;
|
||
+ if (!ConfigHelper::isDeviceSupported(vid, pid))
|
||
+ {
|
||
+ KLOG_DEBUG() << "no auth device!"
|
||
+ << "idVendor:" << vid
|
||
+ << "idProduct:" << pid;
|
||
+ return AuthDeviceList();
|
||
+ }
|
||
+
|
||
+ DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid);
|
||
+ if (!ConfigHelper::driverEnabled(vid, pid))
|
||
+ {
|
||
+ KLOG_INFO() << QString("driver:%1 is disabled, auth device: %2 can't be used")
|
||
+ .arg(deviceConf.driver)
|
||
+ .arg(deviceConf.deviceName)
|
||
+ << " vid:" << vid << " pid:" << pid;
|
||
+ return AuthDeviceList();
|
||
+ }
|
||
+
|
||
+ QString libPath = ConfigHelper::getLibPath(vid, pid);
|
||
+ DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver, libPath);
|
||
+
|
||
+ if (driverPtr.isNull())
|
||
+ {
|
||
+ KLOG_ERROR() << QString("get driver: %1 failed!").arg(deviceConf.driver);
|
||
+ return AuthDeviceList();
|
||
+ }
|
||
+
|
||
+ AuthDeviceList deviceList = DeviceCereator::getInstance()->createDevices(vid, pid, driverPtr);
|
||
+ return deviceList;
|
||
+}
|
||
+
|
||
CHECK_AUTH_WITH_1ARGS(AuthDeviceManager, Remove, onRemove, AUTH_USER_ADMIN, const QString&)
|
||
CHECK_AUTH_WITH_2ARGS(AuthDeviceManager, SetEnableDriver, onSetEnableDriver, AUTH_USER_ADMIN, const QString&, bool)
|
||
|
||
void AuthDeviceManager::init()
|
||
{
|
||
m_dbusAdaptor = QSharedPointer<AuthDeviceManagerAdaptor>(new AuthDeviceManagerAdaptor(this));
|
||
- connect(&m_timer, &QTimer::timeout, this, &AuthDeviceManager::handleDeviceReCreate);
|
||
+ m_ReCreateTimer.setInterval(1000);
|
||
+ connect(&m_ReCreateTimer, &QTimer::timeout, this, &AuthDeviceManager::handleDeviceReCreate);
|
||
|
||
QDBusConnection dbusConnection = QDBusConnection::systemBus();
|
||
if (!dbusConnection.registerService(AUTH_DEVICE_DBUS_NAME))
|
||
@@ -249,37 +298,7 @@ void AuthDeviceManager::init()
|
||
|
||
void AuthDeviceManager::handleDeviceAdded(const DeviceInfo& deviceInfo)
|
||
{
|
||
- // TODO:先从内置默认支持的设备开始搜索,最后才搜索第三方设备
|
||
- QString vid = deviceInfo.idVendor;
|
||
- QString pid = deviceInfo.idProduct;
|
||
- if (!ConfigHelper::isDeviceSupported(vid, pid))
|
||
- {
|
||
- KLOG_DEBUG() << "no auth device!"
|
||
- << "idVendor:" << vid
|
||
- << "idProduct:" << pid;
|
||
- return;
|
||
- }
|
||
-
|
||
- DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid);
|
||
- if (!ConfigHelper::driverEnabled(vid, pid))
|
||
- {
|
||
- KLOG_INFO() << QString("driver:%1 is disabled, auth device: %2 can't be used")
|
||
- .arg(deviceConf.driver)
|
||
- .arg(deviceConf.deviceName)
|
||
- << " vid:" << vid << " pid:" << pid;
|
||
- return;
|
||
- }
|
||
-
|
||
- QString libPath = ConfigHelper::getLibPath(vid, pid);
|
||
- DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver, libPath);
|
||
-
|
||
- if (driverPtr.isNull())
|
||
- {
|
||
- KLOG_ERROR() << QString("get driver: %1 failed!").arg(deviceConf.driver);
|
||
- return;
|
||
- }
|
||
-
|
||
- AuthDeviceList deviceList = DeviceCereator::getInstance()->getDevices(vid, pid, driverPtr);
|
||
+ AuthDeviceList deviceList = createDevices(deviceInfo);
|
||
if (deviceList.count() == 0)
|
||
{
|
||
handleDeviceCreateFail(deviceInfo);
|
||
@@ -289,7 +308,6 @@ void AuthDeviceManager::handleDeviceAdded(const DeviceInfo& deviceInfo)
|
||
Q_FOREACH (auto device, deviceList)
|
||
{
|
||
m_deviceMap.insert(deviceInfo.busPath, device);
|
||
- Q_EMIT this->DeviceAdded(device->deviceType(), device->deviceID());
|
||
Q_EMIT m_dbusAdaptor->DeviceAdded(device->deviceType(), device->deviceID());
|
||
|
||
KLOG_DEBUG() << "auth device added"
|
||
@@ -304,9 +322,9 @@ void AuthDeviceManager::handleDeviceCreateFail(DeviceInfo deviceInfo)
|
||
m_retreyCreateDeviceMap.insert(deviceInfo, 0);
|
||
if (m_retreyCreateDeviceMap.count() != 0)
|
||
{
|
||
- if (!m_timer.isActive())
|
||
+ if (!m_ReCreateTimer.isActive())
|
||
{
|
||
- m_timer.start(1000);
|
||
+ m_ReCreateTimer.start();
|
||
}
|
||
}
|
||
}
|
||
@@ -334,7 +352,7 @@ void AuthDeviceManager::handleDeviceDeleted()
|
||
deviceID = oldAuthDevice->deviceID();
|
||
deviceType = oldAuthDevice->deviceType();
|
||
int removeCount = m_deviceMap.remove(busPath);
|
||
- oldAuthDevice.clear();
|
||
+
|
||
Q_EMIT m_dbusAdaptor->DeviceDeleted(deviceType, deviceID);
|
||
|
||
QMapIterator<DeviceInfo, int> i(m_retreyCreateDeviceMap);
|
||
@@ -355,7 +373,7 @@ void AuthDeviceManager::handleDeviceReCreate()
|
||
{
|
||
if (m_retreyCreateDeviceMap.count() == 0)
|
||
{
|
||
- m_timer.stop();
|
||
+ m_ReCreateTimer.stop();
|
||
return;
|
||
}
|
||
|
||
@@ -363,28 +381,15 @@ void AuthDeviceManager::handleDeviceReCreate()
|
||
while (i.hasNext())
|
||
{
|
||
i.next();
|
||
- if (i.value() >= 2)
|
||
+ if (i.value() >= MAX_RETREY_CREATE_COUNT)
|
||
{
|
||
m_retreyCreateDeviceMap.remove(i.key());
|
||
continue;
|
||
}
|
||
|
||
auto deviceInfo = i.key();
|
||
- QString vid = deviceInfo.idVendor;
|
||
- QString pid = deviceInfo.idProduct;
|
||
-
|
||
- DeviceConf deviceConf = ConfigHelper::getDeviceConf(vid, pid);
|
||
- DriverPtr driverPtr = DriverFactory::getInstance()->getDriver(deviceConf.driver);
|
||
- if (!driverPtr.isNull())
|
||
- {
|
||
- if (!driverPtr->initDriver())
|
||
- {
|
||
- KLOG_ERROR() << QString("init driver %1 failed").arg(deviceConf.driver);
|
||
- continue;
|
||
- }
|
||
- }
|
||
|
||
- AuthDeviceList deviceList = DeviceCereator::getInstance()->getDevices(vid, pid, driverPtr);
|
||
+ AuthDeviceList deviceList = createDevices(deviceInfo);
|
||
if (deviceList.count() == 0)
|
||
{
|
||
m_retreyCreateDeviceMap.insert(i.key(), i.value() + 1);
|
||
@@ -394,7 +399,6 @@ void AuthDeviceManager::handleDeviceReCreate()
|
||
Q_FOREACH (auto device, deviceList)
|
||
{
|
||
m_deviceMap.insert(deviceInfo.busPath, device);
|
||
- Q_EMIT this->DeviceAdded(device->deviceType(), device->deviceID());
|
||
Q_EMIT m_dbusAdaptor->DeviceAdded(device->deviceType(), device->deviceID());
|
||
|
||
KLOG_DEBUG() << "device added"
|
||
diff --git a/src/auth-device-manager.h b/src/auth-device-manager.h
|
||
index 2253d50..95e68e9 100644
|
||
--- a/src/auth-device-manager.h
|
||
+++ b/src/auth-device-manager.h
|
||
@@ -29,7 +29,6 @@ class AuthDeviceManagerAdaptor;
|
||
namespace Kiran
|
||
{
|
||
class AuthDevice;
|
||
-class ContextFactory;
|
||
|
||
class AuthDeviceManager : public QObject, protected QDBusContext
|
||
{
|
||
@@ -53,7 +52,7 @@ public Q_SLOTS:
|
||
void Remove(const QString &feature_id);
|
||
|
||
private Q_SLOTS:
|
||
- void handleDeviceAdded(const DeviceInfo &usbInfo);
|
||
+ void handleDeviceAdded(const DeviceInfo &deviceInfo);
|
||
void handleDeviceDeleted();
|
||
void handleDeviceReCreate();
|
||
void handleDeviceCreateFail(DeviceInfo deviceInfo);
|
||
@@ -62,10 +61,7 @@ private:
|
||
void init();
|
||
void onRemove(const QDBusMessage &message, const QString &feature_id);
|
||
void onSetEnableDriver(const QDBusMessage &message, const QString &driver_name, bool enable);
|
||
-
|
||
-Q_SIGNALS:
|
||
- void DeviceAdded(int device_type, const QString &device_id);
|
||
- void DeviceDeleted(int device_type, const QString &device_id);
|
||
+ QList<QSharedPointer<AuthDevice>> createDevices(const DeviceInfo &deviceInfo);
|
||
|
||
private:
|
||
static AuthDeviceManager *m_instance;
|
||
@@ -73,7 +69,7 @@ private:
|
||
QSharedPointer<AuthDeviceManagerAdaptor> m_dbusAdaptor;
|
||
// 总线 -- AuthDevice对象对应
|
||
QMultiMap<QString, QSharedPointer<AuthDevice>> m_deviceMap;
|
||
- QTimer m_timer;
|
||
+ QTimer m_ReCreateTimer;
|
||
|
||
// 设备信息-重试次数
|
||
QMap<DeviceInfo, int> m_retreyCreateDeviceMap;
|
||
diff --git a/src/config-helper.cpp b/src/config-helper.cpp
|
||
index 31287e4..8fc5a47 100644
|
||
--- a/src/config-helper.cpp
|
||
+++ b/src/config-helper.cpp
|
||
@@ -16,6 +16,7 @@
|
||
#include <qt5-log-i.h>
|
||
#include <QSettings>
|
||
#include "auth-enum.h"
|
||
+#include "config.h"
|
||
|
||
namespace Kiran
|
||
{
|
||
@@ -27,25 +28,46 @@ DeviceConf ConfigHelper::getDeviceConf(const QString &vid, const QString &pid)
|
||
Q_FOREACH (auto deviceConf, deviceConfList)
|
||
{
|
||
confSettings.beginGroup(deviceConf);
|
||
- if ((confSettings.value("Vid").toString() == vid) &&
|
||
- (confSettings.value("Pid").toString() == pid))
|
||
+
|
||
+ QStringList idList = confSettings.value("Id").toStringList();
|
||
+ for (const QString &id : idList)
|
||
{
|
||
- DeviceConf conf;
|
||
- conf.deviceName = confSettings.value("Name").toString();
|
||
- conf.type = confSettings.value("Type").toInt();
|
||
- conf.vid = confSettings.value("Vid").toString();
|
||
- conf.pid = confSettings.value("Pid").toString();
|
||
- conf.driver = confSettings.value("Driver").toString();
|
||
- conf.libPath = confSettings.value("LibPath").toString();
|
||
-
|
||
- return conf;
|
||
+ if (id == QString("%1:%2").arg(vid).arg(pid))
|
||
+ {
|
||
+ DeviceConf conf;
|
||
+ conf.deviceName = confSettings.value("Name").toString();
|
||
+ conf.type = confSettings.value("Type").toInt();
|
||
+ conf.vid = vid;
|
||
+ conf.pid = pid;
|
||
+ conf.driver = confSettings.value("Driver").toString();
|
||
+ return conf;
|
||
+ }
|
||
}
|
||
+
|
||
confSettings.endGroup();
|
||
}
|
||
|
||
return DeviceConf();
|
||
}
|
||
|
||
+DriverConf ConfigHelper::getDriverConf(const QString &vid, const QString &pid)
|
||
+{
|
||
+ QString driverName = getDeviceConf(vid, pid).driver;
|
||
+
|
||
+ DriverConf driverConf;
|
||
+ QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat);
|
||
+ confSettings.beginGroup(driverName);
|
||
+
|
||
+ driverConf.driverName = driverName;
|
||
+ driverConf.enable = confSettings.value("Enable").toBool();
|
||
+ driverConf.type = confSettings.value("Type").toInt();
|
||
+ driverConf.libPath = confSettings.value("LibPath").toString();
|
||
+
|
||
+ confSettings.endGroup();
|
||
+
|
||
+ return driverConf;
|
||
+}
|
||
+
|
||
QString ConfigHelper::getDriverName(const QString &vid, const QString &pid)
|
||
{
|
||
DeviceConf conf = getDeviceConf(vid, pid);
|
||
@@ -60,8 +82,8 @@ QString ConfigHelper::getDeviceName(const QString &vid, const QString &pid)
|
||
|
||
QString ConfigHelper::getLibPath(const QString &vid, const QString &pid)
|
||
{
|
||
- DeviceConf conf = getDeviceConf(vid, pid);
|
||
- return conf.libPath;
|
||
+ DriverConf driverConf = getDriverConf(vid, pid);
|
||
+ return driverConf.libPath;
|
||
}
|
||
|
||
int ConfigHelper::getDeviceType(const QString &vid, const QString &pid)
|
||
@@ -91,16 +113,14 @@ bool ConfigHelper::driverEnabled(const QString &vid, const QString &pid)
|
||
return enable;
|
||
}
|
||
|
||
-void ConfigHelper::setDriverEnabled(const QString& driverName, bool enable)
|
||
+void ConfigHelper::setDriverEnabled(const QString &driverName, bool enable)
|
||
{
|
||
QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat);
|
||
QStringList driverList = confSettings.childGroups();
|
||
- QString enableStr;
|
||
if (driverList.contains(driverName))
|
||
{
|
||
- enableStr = enable ? QString("true") : QString("false");
|
||
- confSettings.setValue(QString("%1/Enable").arg(driverName), QVariant(enableStr));
|
||
- KLOG_INFO() << QString("driver: %1 %2").arg(driverName).arg((enable == true) ? "enable":"disable");
|
||
+ confSettings.setValue(QString("%1/Enable").arg(driverName), QVariant(enable));
|
||
+ KLOG_INFO() << QString("driver: %1 %2").arg(driverName).arg(enable ? "enable" : "disable");
|
||
}
|
||
}
|
||
|
||
@@ -112,11 +132,16 @@ bool ConfigHelper::isDeviceSupported(const QString &vid, const QString &pid)
|
||
Q_FOREACH (auto deviceConf, deviceConfList)
|
||
{
|
||
confSettings.beginGroup(deviceConf);
|
||
- if ((confSettings.value("Vid").toString() == vid) &&
|
||
- (confSettings.value("Pid").toString() == pid))
|
||
+
|
||
+ QStringList idList = confSettings.value("Id").toStringList();
|
||
+ for (const QString &id : idList)
|
||
{
|
||
- return true;
|
||
+ if (id == QString("%1:%2").arg(vid).arg(pid))
|
||
+ {
|
||
+ return true;
|
||
+ }
|
||
}
|
||
+
|
||
confSettings.endGroup();
|
||
}
|
||
return false;
|
||
diff --git a/src/config-helper.h b/src/config-helper.h
|
||
index 1d0d677..91cf895 100644
|
||
--- a/src/config-helper.h
|
||
+++ b/src/config-helper.h
|
||
@@ -12,7 +12,7 @@
|
||
* Author: luoqing <luoqing@kylinsec.com.cn>
|
||
*/
|
||
#pragma once
|
||
-#include <QObject>
|
||
+#include <QString>
|
||
|
||
namespace Kiran
|
||
{
|
||
@@ -24,16 +24,25 @@ struct DeviceConf
|
||
QString vid;
|
||
QString pid;
|
||
QString driver;
|
||
+};
|
||
+
|
||
+struct DriverConf
|
||
+{
|
||
+ QString driverName;
|
||
+ bool enable;
|
||
+ int type;
|
||
QString libPath;
|
||
};
|
||
|
||
-class ConfigHelper : public QObject
|
||
+class ConfigHelper
|
||
{
|
||
public:
|
||
- ConfigHelper(QObject *parent = nullptr) : QObject(parent){};
|
||
+ ConfigHelper() {};
|
||
~ConfigHelper(){};
|
||
|
||
static DeviceConf getDeviceConf(const QString &vid, const QString &pid);
|
||
+ static DriverConf getDriverConf(const QString &vid, const QString &pid);
|
||
+
|
||
static QString getDriverName(const QString &vid, const QString &pid);
|
||
static QString getDeviceName(const QString &vid, const QString &pid);
|
||
static QString getLibPath(const QString &vid, const QString &pid);
|
||
diff --git a/src/device/auth-device.cpp b/src/device/auth-device.cpp
|
||
index 7111ff6..aef4b85 100644
|
||
--- a/src/device/auth-device.cpp
|
||
+++ b/src/device/auth-device.cpp
|
||
@@ -18,11 +18,11 @@
|
||
#include <QUuid>
|
||
#include <QtConcurrent>
|
||
#include "auth_device_adaptor.h"
|
||
+#include "config-helper.h"
|
||
#include "feature-db.h"
|
||
#include "kiran-auth-device-i.h"
|
||
#include "polkit-proxy.h"
|
||
#include "utils.h"
|
||
-#include "config-helper.h"
|
||
|
||
namespace Kiran
|
||
{
|
||
@@ -38,7 +38,7 @@ AuthDevice::~AuthDevice(){};
|
||
|
||
bool AuthDevice::init()
|
||
{
|
||
- if(!initDevice())
|
||
+ if (!initDevice())
|
||
{
|
||
return false;
|
||
}
|
||
@@ -96,15 +96,6 @@ void AuthDevice::onNameLost(const QString& serviceName)
|
||
}
|
||
}
|
||
|
||
-void AuthDevice::clearWatchedServices()
|
||
-{
|
||
- QStringList watchedServices = m_serviceWatcher->watchedServices();
|
||
- Q_FOREACH (auto service, watchedServices)
|
||
- {
|
||
- m_serviceWatcher->removeWatchedService(service);
|
||
- }
|
||
-}
|
||
-
|
||
DeviceInfo AuthDevice::deviceInfo()
|
||
{
|
||
DeviceInfo deviceInfo;
|
||
@@ -120,6 +111,55 @@ void AuthDevice::setDeviceInfo(const QString& idVendor, const QString& idProduct
|
||
m_idProduct = idProduct;
|
||
}
|
||
|
||
+void AuthDevice::clearWatchedServices()
|
||
+{
|
||
+ QStringList watchedServices = m_serviceWatcher->watchedServices();
|
||
+ Q_FOREACH (auto service, watchedServices)
|
||
+ {
|
||
+ m_serviceWatcher->removeWatchedService(service);
|
||
+ }
|
||
+}
|
||
+
|
||
+void AuthDevice::internalStopEnroll()
|
||
+{
|
||
+ if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL)
|
||
+ {
|
||
+ deviceStopEnroll();
|
||
+ setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
+ clearWatchedServices();
|
||
+ KLOG_DEBUG() << QString("enroll stop, device type:%1,name:%2 ,id:%3")
|
||
+ .arg(deviceType())
|
||
+ .arg(deviceName())
|
||
+ .arg(deviceID());
|
||
+ }
|
||
+}
|
||
+
|
||
+void AuthDevice::internalStopIdentify()
|
||
+{
|
||
+ if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY)
|
||
+ {
|
||
+ deviceStopIdentify();
|
||
+ m_featuresThatNeedToIdentify.clear();
|
||
+ setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
+ clearWatchedServices();
|
||
+ KLOG_DEBUG() << QString("identify stop, device type:%1,name:%2 ,id:%3")
|
||
+ .arg(deviceType())
|
||
+ .arg(deviceName())
|
||
+ .arg(deviceID());
|
||
+ }
|
||
+}
|
||
+
|
||
+QList<QByteArray> AuthDevice::findFeaturesByFeatureIDs(const QStringList& featureIDs)
|
||
+{
|
||
+ QList<QByteArray> saveList;
|
||
+ Q_FOREACH (auto id, featureIDs)
|
||
+ {
|
||
+ QByteArray feature = FeatureDB::getInstance()->getFeature(id);
|
||
+ saveList << feature;
|
||
+ }
|
||
+ return saveList;
|
||
+}
|
||
+
|
||
void AuthDevice::onEnrollStart(const QDBusMessage& dbusMessage, const QString& extraInfo)
|
||
{
|
||
QString message;
|
||
@@ -147,25 +187,41 @@ void AuthDevice::onEnrollStop(const QDBusMessage& dbusMessage)
|
||
|
||
void AuthDevice::onIdentifyStart(const QDBusMessage& dbusMessage, const QString& value)
|
||
{
|
||
- QString message;
|
||
if (deviceStatus() != DEVICE_STATUS_IDLE)
|
||
{
|
||
- message = tr("Device Busy");
|
||
+ QString message = tr("Device Busy");
|
||
Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, message);
|
||
- KLOG_DEBUG() << QString("%1, deviceID:%2").arg(message).arg(deviceID());
|
||
+ KLOG_DEBUG() << QString("%1, deviceID:%2").arg("Device Busy").arg(deviceID());
|
||
return;
|
||
}
|
||
|
||
+ QStringList featureIDs;
|
||
QJsonArray jsonArray = Utils::getValueFromJsonString(value, AUTH_DEVICE_JSON_KEY_FEATURE_IDS).toArray();
|
||
if (!jsonArray.isEmpty())
|
||
{
|
||
QVariantList varList = jsonArray.toVariantList();
|
||
Q_FOREACH (auto var, varList)
|
||
{
|
||
- m_identifyIDs << var.toString();
|
||
+ featureIDs << var.toString();
|
||
}
|
||
}
|
||
|
||
+ if (featureIDs.isEmpty())
|
||
+ {
|
||
+ m_featuresThatNeedToIdentify = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber());
|
||
+ }
|
||
+ else
|
||
+ {
|
||
+ m_featuresThatNeedToIdentify = findFeaturesByFeatureIDs(featureIDs);
|
||
+ }
|
||
+
|
||
+ if (m_featuresThatNeedToIdentify.count() == 0)
|
||
+ {
|
||
+ KLOG_DEBUG() << "no found feature id";
|
||
+ Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, tr("identify fail!"));
|
||
+ return;
|
||
+ }
|
||
+
|
||
setDeviceStatus(DEVICE_STATUS_DOING_IDENTIFY);
|
||
m_serviceWatcher->addWatchedService(dbusMessage.service());
|
||
auto replyMessage = dbusMessage.createReply();
|
||
diff --git a/src/device/auth-device.h b/src/device/auth-device.h
|
||
index 581998e..7209781 100644
|
||
--- a/src/device/auth-device.h
|
||
+++ b/src/device/auth-device.h
|
||
@@ -23,13 +23,13 @@
|
||
#include "auth-enum.h"
|
||
#include "driver/driver.h"
|
||
#include "kiran-auth-device-i.h"
|
||
+#include "device-creator.h"
|
||
|
||
class AuthDeviceAdaptor;
|
||
|
||
namespace Kiran
|
||
{
|
||
typedef void *Handle;
|
||
-class BDriver;
|
||
|
||
class AuthDevice : public QObject, protected QDBusContext
|
||
{
|
||
@@ -43,10 +43,8 @@ public:
|
||
explicit AuthDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr);
|
||
virtual ~AuthDevice();
|
||
bool init();
|
||
- virtual bool initDevice() = 0;
|
||
|
||
QDBusObjectPath getObjectPath() { return m_objectPath; };
|
||
- void setDeviceType(DeviceType deviceType) { m_deviceType = deviceType; };
|
||
|
||
DeviceType deviceType() { return m_deviceType; };
|
||
DeviceStatus deviceStatus() { return m_deviceStatus; };
|
||
@@ -57,6 +55,10 @@ public:
|
||
|
||
QString driverName() { return m_driverName; };
|
||
|
||
+private:
|
||
+ virtual bool initDevice() = 0;
|
||
+ friend AuthDeviceList DeviceCereator::createDevices(const QString &vid, const QString &pid, DriverPtr driver);
|
||
+
|
||
public Q_SLOTS:
|
||
virtual void EnrollStart(const QString &extraInfo);
|
||
virtual void EnrollStop();
|
||
@@ -65,6 +67,7 @@ public Q_SLOTS:
|
||
virtual QStringList GetFeatureIDList();
|
||
|
||
protected:
|
||
+ void setDeviceType(DeviceType deviceType) { m_deviceType = deviceType; };
|
||
void setDeviceStatus(DeviceStatus deviceStatus) { m_deviceStatus = deviceStatus; };
|
||
void setDeviceName(const QString &deviceName) { m_deviceName = deviceName; };
|
||
void setDeviceInfo(const QString &idVendor, const QString &idProduct);
|
||
@@ -73,8 +76,13 @@ protected:
|
||
void setDriverName(const QString &driverName) { m_driverName = driverName; };
|
||
|
||
void clearWatchedServices();
|
||
- virtual void internalStopEnroll() = 0;
|
||
- virtual void internalStopIdentify() = 0;
|
||
+ void internalStopEnroll();
|
||
+ void internalStopIdentify();
|
||
+
|
||
+ virtual void deviceStopEnroll() = 0;
|
||
+ virtual void deviceStopIdentify() = 0;
|
||
+
|
||
+ QList<QByteArray> getFeaturesThatNeedToIdentify() {return m_featuresThatNeedToIdentify;};
|
||
|
||
private:
|
||
void onEnrollStart(const QDBusMessage &message, const QString &extraInfo);
|
||
@@ -85,21 +93,23 @@ private:
|
||
virtual void doingEnrollStart(const QString &extraInfo) = 0;
|
||
virtual void doingIdentifyStart(const QString &value) = 0;
|
||
|
||
-private Q_SLOTS:
|
||
- void onNameLost(const QString &serviceName);
|
||
-
|
||
-private:
|
||
void registerDBusObject();
|
||
void initServiceWatcher();
|
||
|
||
+ QList<QByteArray> findFeaturesByFeatureIDs(const QStringList &featureIDs);
|
||
+
|
||
+private Q_SLOTS:
|
||
+ void onNameLost(const QString &serviceName);
|
||
+
|
||
Q_SIGNALS:
|
||
void retry();
|
||
|
||
protected:
|
||
QSharedPointer<AuthDeviceAdaptor> m_dbusAdaptor;
|
||
- QStringList m_identifyIDs;
|
||
|
||
private:
|
||
+ QList<QByteArray> m_featuresThatNeedToIdentify;
|
||
+
|
||
QString m_driverName;
|
||
QString m_deviceID;
|
||
|
||
diff --git a/src/device/bio-device.cpp b/src/device/bio-device.cpp
|
||
index 8d73cd5..841d48c 100644
|
||
--- a/src/device/bio-device.cpp
|
||
+++ b/src/device/bio-device.cpp
|
||
@@ -22,8 +22,8 @@ namespace Kiran
|
||
{
|
||
#define TEMPLATE_MAX_NUMBER 1000
|
||
|
||
-BioDevice::BioDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent) : AuthDevice{vid,pid,driver,parent},
|
||
- m_futureWatcher(nullptr)
|
||
+BioDevice::BioDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) : AuthDevice{vid, pid, driver, parent},
|
||
+ m_futureWatcher(nullptr)
|
||
{
|
||
initFutureWatcher();
|
||
}
|
||
@@ -36,7 +36,7 @@ void BioDevice::doingEnrollStart(const QString &extraInfo)
|
||
{
|
||
KLOG_DEBUG() << "biological information enroll start";
|
||
// 获取当前保存的特征模板,判断是否达到最大数目
|
||
- QByteArrayList saveList = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(),deviceSerialNumber());
|
||
+ QByteArrayList saveList = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber());
|
||
if (saveList.count() == TEMPLATE_MAX_NUMBER)
|
||
{
|
||
QString message = tr("feature has reached the upper limit of %1").arg(TEMPLATE_MAX_NUMBER);
|
||
@@ -87,30 +87,6 @@ void BioDevice::doingIdentifyStart(const QString &value)
|
||
m_dbusAdaptor->IdentifyStatus("", ENROLL_STATUS_NORMAL, message);
|
||
}
|
||
|
||
-void BioDevice::internalStopEnroll()
|
||
-{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL)
|
||
- {
|
||
- acquireFeatureStop();
|
||
- m_enrollTemplates.clear();
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- KLOG_DEBUG() << QString("device type:%1,internal enroll stop").arg(deviceType());
|
||
- }
|
||
-}
|
||
-
|
||
-void BioDevice::internalStopIdentify()
|
||
-{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY)
|
||
- {
|
||
- acquireFeatureStop();
|
||
- m_identifyIDs.clear();
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- KLOG_DEBUG() << QString("device type:%1,internal identify stop").arg(deviceType());
|
||
- }
|
||
-}
|
||
-
|
||
void BioDevice::doingEnrollProcess(QByteArray feature)
|
||
{
|
||
int templatesCount = enrollTemplatesFromCache().count();
|
||
@@ -146,12 +122,13 @@ void BioDevice::doingEnrollProcess(QByteArray feature)
|
||
else if (enrollTemplatesFromCache().count() == mergeTemplateCount())
|
||
{
|
||
enrollTemplateMerge();
|
||
+ internalStopEnroll();
|
||
}
|
||
}
|
||
|
||
void BioDevice::doingIdentifyProcess(QByteArray feature)
|
||
{
|
||
- QString featureID = identifyFeature(feature, m_identifyIDs);
|
||
+ QString featureID = identifyFeature(feature, getFeaturesThatNeedToIdentify());
|
||
if (!featureID.isEmpty())
|
||
{
|
||
notifyIdentifyProcess(IDENTIFY_PROCESS_MACTCH, featureID);
|
||
@@ -208,6 +185,17 @@ void BioDevice::saveEnrollTemplateToCache(QByteArray enrollTemplate)
|
||
}
|
||
}
|
||
|
||
+void BioDevice::deviceStopEnroll()
|
||
+{
|
||
+ acquireFeatureStop();
|
||
+ m_enrollTemplates.clear();
|
||
+}
|
||
+
|
||
+void BioDevice::deviceStopIdentify()
|
||
+{
|
||
+ acquireFeatureStop();
|
||
+}
|
||
+
|
||
void BioDevice::enrollProcessRetry()
|
||
{
|
||
Q_EMIT this->retry();
|
||
@@ -215,7 +203,8 @@ void BioDevice::enrollProcessRetry()
|
||
|
||
QString BioDevice::isFeatureEnrolled(QByteArray fpTemplate)
|
||
{
|
||
- return identifyFeature(fpTemplate, QStringList());
|
||
+ QList<QByteArray> features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber());
|
||
+ return identifyFeature(fpTemplate, features);
|
||
}
|
||
|
||
void BioDevice::initFutureWatcher()
|
||
diff --git a/src/device/bio-device.h b/src/device/bio-device.h
|
||
index 643acf1..4c05923 100644
|
||
--- a/src/device/bio-device.h
|
||
+++ b/src/device/bio-device.h
|
||
@@ -20,7 +20,7 @@ class BioDevice : public AuthDevice
|
||
{
|
||
Q_OBJECT
|
||
public:
|
||
- explicit BioDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent = nullptr);
|
||
+ explicit BioDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr);
|
||
~BioDevice();
|
||
int mergeTemplateCount() { return m_mergeTemplateCount; };
|
||
void setMergeTemplateCount(int count) { m_mergeTemplateCount = count; };
|
||
@@ -29,16 +29,16 @@ protected:
|
||
virtual QByteArray acquireFeature() = 0;
|
||
virtual void acquireFeatureStop() = 0;
|
||
virtual void acquireFeatureFail() = 0;
|
||
- virtual QString identifyFeature(QByteArray feature, QStringList featureIDs) = 0;
|
||
-
|
||
- virtual void enrollTemplateMerge() {};
|
||
- virtual int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) {return GENERAL_RESULT_OK;};
|
||
-
|
||
- void internalStopEnroll() override;
|
||
- void internalStopIdentify() override;
|
||
+ virtual QString identifyFeature(QByteArray feature, QList<QByteArray> existedfeatures) = 0;
|
||
+
|
||
+ virtual void enrollTemplateMerge(){};
|
||
+ virtual int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) { return GENERAL_RESULT_OK; };
|
||
+
|
||
+ virtual void deviceStopEnroll() override;
|
||
+ virtual void deviceStopIdentify() override;
|
||
|
||
virtual void enrollProcessRetry();
|
||
- //TODO:优化通知
|
||
+ // TODO:优化通知
|
||
virtual void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString()) = 0;
|
||
virtual void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString()) = 0;
|
||
|
||
diff --git a/src/device/device-creator.cpp b/src/device/device-creator.cpp
|
||
index d7cd926..1fb760f 100644
|
||
--- a/src/device/device-creator.cpp
|
||
+++ b/src/device/device-creator.cpp
|
||
@@ -45,7 +45,7 @@ DeviceCereator::~DeviceCereator()
|
||
{
|
||
}
|
||
|
||
-AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid, DriverPtr driver)
|
||
+AuthDeviceList DeviceCereator::createDevices(const QString &vid, const QString &pid, DriverPtr driver)
|
||
{
|
||
AuthDeviceList deviceList;
|
||
QStringList driverNameList = m_deviceFuncMap.keys();
|
||
@@ -72,12 +72,7 @@ AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid
|
||
(irisDevicePtr->init()))
|
||
{
|
||
deviceList << faceDevicePtr << irisDevicePtr;
|
||
- }
|
||
- else
|
||
- {
|
||
- KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid);
|
||
- faceDevicePtr.clear();
|
||
- irisDevicePtr.clear();
|
||
+ return deviceList;
|
||
}
|
||
}
|
||
else
|
||
@@ -87,14 +82,12 @@ AuthDeviceList DeviceCereator::getDevices(const QString &vid, const QString &pid
|
||
if (devicePtr->init())
|
||
{
|
||
deviceList << devicePtr;
|
||
- }
|
||
- else
|
||
- {
|
||
- KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid);
|
||
- devicePtr.clear();
|
||
+ return deviceList;
|
||
}
|
||
}
|
||
- return deviceList;
|
||
+
|
||
+ KLOG_ERROR() << QString("device %1:%2 init failed!").arg(vid).arg(pid);
|
||
+ return AuthDeviceList();
|
||
}
|
||
|
||
void DeviceCereator::registerDevice(QString driverName, std::function<AuthDevice *(const QString &vid, const QString &pid, DriverPtr driver)> func)
|
||
diff --git a/src/device/device-creator.h b/src/device/device-creator.h
|
||
index be074cb..9b3db32 100644
|
||
--- a/src/device/device-creator.h
|
||
+++ b/src/device/device-creator.h
|
||
@@ -36,7 +36,7 @@ public:
|
||
static DeviceCereator *getInstance();
|
||
~DeviceCereator();
|
||
|
||
- AuthDeviceList getDevices(const QString &vid, const QString &pid, DriverPtr driver);
|
||
+ AuthDeviceList createDevices(const QString &vid, const QString &pid, DriverPtr driver);
|
||
|
||
void registerDevice(QString driverName,
|
||
std::function<AuthDevice *(const QString &vid, const QString &pid, DriverPtr driver)> func);
|
||
diff --git a/src/device/finger-vein/fv-sd-device.cpp b/src/device/finger-vein/fv-sd-device.cpp
|
||
index 67dcab8..442f227 100644
|
||
--- a/src/device/finger-vein/fv-sd-device.cpp
|
||
+++ b/src/device/finger-vein/fv-sd-device.cpp
|
||
@@ -240,42 +240,21 @@ void FVSDDevice::enrollTemplateMerge()
|
||
KLOG_DEBUG() << "Finger vein template fusion failed:" << ret;
|
||
notifyEnrollProcess(ENROLL_PROCESS_MEGER_FAIL);
|
||
}
|
||
- internalStopEnroll();
|
||
}
|
||
|
||
QString FVSDDevice::isFeatureEnrolled(QByteArray fpTemplate)
|
||
{
|
||
QByteArray featureForVerify = getFeatureFromImage(fpTemplate, EXTRACT_FEATURE_VERIFY);
|
||
- QString featureID = identifyFeature(featureForVerify, QStringList());
|
||
+ QList<QByteArray> features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber());
|
||
+ QString featureID = identifyFeature(featureForVerify, features);
|
||
return featureID;
|
||
}
|
||
|
||
-QString FVSDDevice::identifyFeature(QByteArray feature, QStringList featureIDs)
|
||
+QString FVSDDevice::identifyFeature(QByteArray feature, QList<QByteArray> existedfeatures)
|
||
{
|
||
- QList<QByteArray> saveList;
|
||
QString featureID;
|
||
- DeviceInfo deviceInfo = this->deviceInfo();
|
||
- if (featureIDs.isEmpty())
|
||
- {
|
||
- saveList = FeatureDB::getInstance()->getFeatures(deviceInfo.idVendor, deviceInfo.idProduct, deviceType(), deviceSerialNumber());
|
||
- }
|
||
- else
|
||
- {
|
||
- Q_FOREACH (auto id, featureIDs)
|
||
- {
|
||
- QByteArray feature = FeatureDB::getInstance()->getFeature(id);
|
||
- if (!feature.isEmpty())
|
||
- saveList << feature;
|
||
- }
|
||
- }
|
||
-
|
||
- if (saveList.count() == 0)
|
||
- {
|
||
- return QString();
|
||
- }
|
||
-
|
||
QByteArray saveTempl;
|
||
- Q_FOREACH (auto saveFeature, saveList)
|
||
+ Q_FOREACH (auto saveFeature, existedfeatures)
|
||
{
|
||
saveTempl.append(saveFeature);
|
||
}
|
||
@@ -283,11 +262,10 @@ QString FVSDDevice::identifyFeature(QByteArray feature, QStringList featureIDs)
|
||
int matchIndex = 0;
|
||
int matchScore = 0;
|
||
unsigned char updateTmpl[TEMPLATE_SIZE] = {0}; // 自我学习后的新模板
|
||
- KLOG_DEBUG() << "saveList.count():" << saveList.count();
|
||
|
||
int matchResult = m_driver->TGFeatureMatchTmpl1N((unsigned char *)feature.data(),
|
||
(unsigned char *)saveTempl.data(),
|
||
- saveList.count(),
|
||
+ existedfeatures.count(),
|
||
&matchIndex,
|
||
&matchScore,
|
||
updateTmpl);
|
||
diff --git a/src/device/finger-vein/fv-sd-device.h b/src/device/finger-vein/fv-sd-device.h
|
||
index 0a4f5a4..0a82055 100644
|
||
--- a/src/device/finger-vein/fv-sd-device.h
|
||
+++ b/src/device/finger-vein/fv-sd-device.h
|
||
@@ -33,9 +33,9 @@ class FVSDDevice : public BioDevice
|
||
public:
|
||
explicit FVSDDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject *parent = nullptr);
|
||
~FVSDDevice();
|
||
- bool initDevice() override;
|
||
|
||
private:
|
||
+ bool initDevice() override;
|
||
QByteArray acquireFeature() override;
|
||
void acquireFeatureStop() override;
|
||
void acquireFeatureFail() override;
|
||
@@ -46,7 +46,7 @@ private:
|
||
void enrollProcessRetry() override;
|
||
|
||
QString isFeatureEnrolled(QByteArray fpTemplate) override;
|
||
- QString identifyFeature(QByteArray feature, QStringList featureIDs) override;
|
||
+ QString identifyFeature(QByteArray feature, QList<QByteArray> existedfeatures) override;
|
||
|
||
void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString()) override;
|
||
void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString()) override;
|
||
diff --git a/src/device/fingerprint/fp-zk-device.cpp b/src/device/fingerprint/fp-zk-device.cpp
|
||
index 3a26cf5..3a818f3 100644
|
||
--- a/src/device/fingerprint/fp-zk-device.cpp
|
||
+++ b/src/device/fingerprint/fp-zk-device.cpp
|
||
@@ -233,34 +233,12 @@ int FPZKDevice::enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplat
|
||
return score > 0 ? GENERAL_RESULT_OK : GENERAL_RESULT_FAIL;
|
||
}
|
||
|
||
-QString FPZKDevice::identifyFeature(QByteArray fpTemplate, QStringList featureIDs)
|
||
+QString FPZKDevice::identifyFeature(QByteArray fpTemplate, QList<QByteArray> existedfeatures)
|
||
{
|
||
- QList<QByteArray> saveList;
|
||
QString featureID;
|
||
- DeviceInfo info = this->deviceInfo();
|
||
- if (featureIDs.isEmpty())
|
||
+ for (int j = 0; j < existedfeatures.count(); j++)
|
||
{
|
||
- saveList = FeatureDB::getInstance()->getFeatures(info.idVendor, info.idProduct, deviceType(), deviceSerialNumber());
|
||
- }
|
||
- else
|
||
- {
|
||
- Q_FOREACH (auto id, featureIDs)
|
||
- {
|
||
- QByteArray feature = FeatureDB::getInstance()->getFeature(id);
|
||
- if (!feature.isEmpty())
|
||
- saveList << feature;
|
||
- }
|
||
- }
|
||
-
|
||
- if (saveList.count() == 0)
|
||
- {
|
||
- KLOG_DEBUG() << "no found feature";
|
||
- return QString();
|
||
- }
|
||
-
|
||
- for (int j = 0; j < saveList.count(); j++)
|
||
- {
|
||
- auto saveTemplate = saveList.value(j);
|
||
+ auto saveTemplate = existedfeatures.value(j);
|
||
int ret = enrollTemplateMatch(fpTemplate, saveTemplate);
|
||
// 指纹已经存在,直接返回该指纹
|
||
if (ret == GENERAL_RESULT_OK)
|
||
@@ -294,7 +272,6 @@ void FPZKDevice::enrollTemplateMerge()
|
||
{
|
||
// 三个模板merge失败,判定为录入失败,需要重新录入
|
||
notifyEnrollProcess(ENROLL_PROCESS_MEGER_FAIL);
|
||
- internalStopEnroll();
|
||
return;
|
||
}
|
||
|
||
@@ -318,7 +295,6 @@ void FPZKDevice::enrollTemplateMerge()
|
||
// 如果合成后的指纹与先前录入的指纹不匹配,判定为录入失败,需要重新录入
|
||
notifyEnrollProcess(ENROLL_PROCESS_INCONSISTENT_FEATURE_AFTER_MERGED);
|
||
}
|
||
- internalStopEnroll();
|
||
}
|
||
|
||
void FPZKDevice::notifyEnrollProcess(EnrollProcess process, const QString& featureID)
|
||
diff --git a/src/device/fingerprint/fp-zk-device.h b/src/device/fingerprint/fp-zk-device.h
|
||
index 083a6b8..d9a6b2c 100644
|
||
--- a/src/device/fingerprint/fp-zk-device.h
|
||
+++ b/src/device/fingerprint/fp-zk-device.h
|
||
@@ -30,9 +30,9 @@ public:
|
||
explicit FPZKDevice(const QString &vid, const QString &pid, DriverPtr driver,QObject* parent = nullptr);
|
||
~FPZKDevice();
|
||
|
||
- bool initDevice() override;
|
||
|
||
private:
|
||
+ bool initDevice() override;
|
||
QByteArray acquireFeature() override;
|
||
// 停止采集指纹模板
|
||
void acquireFeatureStop() override;
|
||
@@ -52,7 +52,7 @@ private:
|
||
// 对比两枚指纹是否匹配
|
||
int enrollTemplateMatch(QByteArray fpTemplate1, QByteArray fpTemplate2) override;
|
||
|
||
- QString identifyFeature(QByteArray fpTemplate, QStringList featureIDs) override;
|
||
+ QString identifyFeature(QByteArray fpTemplate, QList<QByteArray> existedfeatures) override;
|
||
|
||
bool saveFPrintTemplate(QByteArray fpTemplate, const QString& featureID);
|
||
|
||
diff --git a/src/device/multi-function/mf-iristar-device.cpp b/src/device/multi-function/mf-iristar-device.cpp
|
||
index 7a0ce84..27e1809 100644
|
||
--- a/src/device/multi-function/mf-iristar-device.cpp
|
||
+++ b/src/device/multi-function/mf-iristar-device.cpp
|
||
@@ -19,6 +19,7 @@
|
||
#include "utils.h"
|
||
#include "device/device-creator.h"
|
||
#include "config-helper.h"
|
||
+#include "feature-db.h"
|
||
|
||
namespace Kiran
|
||
{
|
||
@@ -29,8 +30,6 @@ REGISTER_DEVICE(IRISTAR_DRIVER_NAME,MFIriStarDevice);
|
||
MFIriStarDevice::MFIriStarDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) :
|
||
AuthDevice(vid, pid, driver, parent)
|
||
{
|
||
- setDeviceName(ConfigHelper::getDriverName(vid,pid));
|
||
-
|
||
m_driver = driver.dynamicCast<MFIriStarDriver>();
|
||
m_driver->ref();
|
||
m_driver->setDeviceInfo(vid,pid);
|
||
@@ -63,8 +62,10 @@ bool MFIriStarDevice::initDevice()
|
||
}
|
||
|
||
void MFIriStarDevice::doingEnrollStart(const QString &extraInfo)
|
||
-{
|
||
- m_driver->doingEnrollStart(deviceType());
|
||
+{
|
||
+ QList<QByteArray> features = FeatureDB::getInstance()->getFeatures(deviceInfo().idVendor, deviceInfo().idProduct, deviceType(), deviceSerialNumber());
|
||
+ // 注册前需要传入已经存在的特征,判断之前是否注册过
|
||
+ m_driver->doingEnrollStart(deviceType(),features);
|
||
QString message;
|
||
if (deviceType() == DEVICE_TYPE_Iris)
|
||
{
|
||
@@ -79,7 +80,7 @@ void MFIriStarDevice::doingEnrollStart(const QString &extraInfo)
|
||
|
||
void MFIriStarDevice::doingIdentifyStart(const QString &value)
|
||
{
|
||
- m_driver->doingIdentifyStart(deviceType(), m_identifyIDs);
|
||
+ m_driver->doingIdentifyStart(deviceType(), getFeaturesThatNeedToIdentify());
|
||
QString message;
|
||
if (deviceType() == DEVICE_TYPE_Iris)
|
||
{
|
||
@@ -92,27 +93,14 @@ void MFIriStarDevice::doingIdentifyStart(const QString &value)
|
||
m_dbusAdaptor->IdentifyStatus("", ENROLL_STATUS_NORMAL, message);
|
||
}
|
||
|
||
-void MFIriStarDevice::internalStopEnroll()
|
||
+void MFIriStarDevice::deviceStopEnroll()
|
||
{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL)
|
||
- {
|
||
- m_driver->stop();
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- KLOG_DEBUG() << "stop Enroll";
|
||
- }
|
||
+ m_driver->stop();
|
||
}
|
||
|
||
-void MFIriStarDevice::internalStopIdentify()
|
||
+void MFIriStarDevice::deviceStopIdentify()
|
||
{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY)
|
||
- {
|
||
- m_driver->stop();
|
||
- m_identifyIDs.clear();
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- KLOG_DEBUG() << "stop Identify";
|
||
- }
|
||
+ m_driver->stop();
|
||
}
|
||
|
||
void MFIriStarDevice::onEnrollProcess(EnrollProcess process, DeviceType type, const QString &featureID)
|
||
diff --git a/src/device/multi-function/mf-iristar-device.h b/src/device/multi-function/mf-iristar-device.h
|
||
index c204607..4e04b1c 100644
|
||
--- a/src/device/multi-function/mf-iristar-device.h
|
||
+++ b/src/device/multi-function/mf-iristar-device.h
|
||
@@ -26,13 +26,12 @@ public:
|
||
explicit MFIriStarDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr);
|
||
~MFIriStarDevice();
|
||
|
||
- bool initDevice() override;
|
||
-
|
||
private:
|
||
+ bool initDevice() override;
|
||
void doingEnrollStart(const QString &extraInfo) override;
|
||
void doingIdentifyStart(const QString &value) override;
|
||
- void internalStopEnroll() override;
|
||
- void internalStopIdentify() override;
|
||
+ void deviceStopEnroll() override;
|
||
+ void deviceStopIdentify() override;
|
||
|
||
void notifyEnrollProcess(EnrollProcess process, const QString &featureID = QString());
|
||
void notifyIdentifyProcess(IdentifyProcess process, const QString &featureID = QString());
|
||
diff --git a/src/device/ukey/ukey-skf-device.cpp b/src/device/ukey/ukey-skf-device.cpp
|
||
index 2d7f03d..82bd13d 100644
|
||
--- a/src/device/ukey/ukey-skf-device.cpp
|
||
+++ b/src/device/ukey/ukey-skf-device.cpp
|
||
@@ -16,27 +16,27 @@
|
||
#include <dlfcn.h>
|
||
#include <qt5-log-i.h>
|
||
#include <QCryptographicHash>
|
||
+#include <functional>
|
||
#include "auth-enum.h"
|
||
#include "auth_device_adaptor.h"
|
||
+#include "config-helper.h"
|
||
+#include "device/device-creator.h"
|
||
#include "feature-db.h"
|
||
#include "utils.h"
|
||
-#include "device/device-creator.h"
|
||
-#include <functional>
|
||
-#include "config-helper.h"
|
||
|
||
namespace Kiran
|
||
{
|
||
-REGISTER_DEVICE(UKEY_SKF_DRIVER_NAME,UKeySKFDevice);
|
||
+REGISTER_DEVICE(UKEY_SKF_DRIVER_NAME, UKeySKFDevice);
|
||
|
||
QStringList UKeySKFDevice::m_existingSerialNumber;
|
||
|
||
UKeySKFDevice::UKeySKFDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent) : AuthDevice{vid, pid, driver, parent}
|
||
{
|
||
- //NOTE:并未使用传递进来的DriverPtr
|
||
+ // NOTE:并未使用传递进来的DriverPtr
|
||
setDeviceType(DEVICE_TYPE_UKey);
|
||
- setDriverName(ConfigHelper::getDriverName(vid,pid));
|
||
- m_driverLibPath = ConfigHelper::getLibPath(vid,pid);
|
||
-
|
||
+ setDriverName(ConfigHelper::getDriverName(vid, pid));
|
||
+ m_driverLibPath = ConfigHelper::getLibPath(vid, pid);
|
||
+
|
||
/**
|
||
* NOTE:
|
||
* UKey设备插入时,设备可能处在未准备好的状态,无法获取到serialNumber
|
||
@@ -167,7 +167,7 @@ void UKeySKFDevice::bindingUKey(DEVHANDLE devHandle, const QString &pin)
|
||
* 不用保存PublicKey和systemUser的关系,目前只有一个用户
|
||
*/
|
||
QByteArray keyFeature;
|
||
- keyFeature.append((char *)&publicKey,sizeof(publicKey));
|
||
+ keyFeature.append((char *)&publicKey, sizeof(publicKey));
|
||
KLOG_DEBUG() << "keyFeature:" << keyFeature;
|
||
|
||
QString featureID = QCryptographicHash::hash(keyFeature, QCryptographicHash::Md5).toHex();
|
||
@@ -248,30 +248,7 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value)
|
||
{
|
||
QString message = tr("The pin code cannot be empty!");
|
||
Q_EMIT m_dbusAdaptor->IdentifyStatus("", IDENTIFY_STATUS_NOT_MATCH, message);
|
||
- KLOG_ERROR() << message;
|
||
- internalStopIdentify();
|
||
- return;
|
||
- }
|
||
-
|
||
- QList<QByteArray> saveList;
|
||
- DeviceInfo deviceInfo = this->deviceInfo();
|
||
- if (m_identifyIDs.isEmpty())
|
||
- {
|
||
- saveList = FeatureDB::getInstance()->getFeatures(deviceInfo.idVendor, deviceInfo.idProduct, deviceType(), deviceSerialNumber());
|
||
- }
|
||
- else
|
||
- {
|
||
- Q_FOREACH (auto id, m_identifyIDs)
|
||
- {
|
||
- QByteArray feature = FeatureDB::getInstance()->getFeature(id);
|
||
- saveList << feature;
|
||
- }
|
||
- }
|
||
-
|
||
- if (saveList.count() == 0)
|
||
- {
|
||
- KLOG_DEBUG() << "no found feature id";
|
||
- notifyUKeyIdentifyProcess(IDENTIFY_PROCESS_NO_MATCH);
|
||
+ KLOG_ERROR() << "The pin code cannot be empty!";
|
||
internalStopIdentify();
|
||
return;
|
||
}
|
||
@@ -284,7 +261,8 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value)
|
||
internalStopIdentify();
|
||
return;
|
||
}
|
||
-
|
||
+
|
||
+ QList<QByteArray> saveList = getFeaturesThatNeedToIdentify();
|
||
for (int j = 0; j < saveList.count(); j++)
|
||
{
|
||
auto savedKey = saveList.value(j);
|
||
@@ -294,35 +272,22 @@ void UKeySKFDevice::doingIdentifyStart(const QString &value)
|
||
internalStopIdentify();
|
||
}
|
||
|
||
-void UKeySKFDevice::internalStopEnroll()
|
||
+void UKeySKFDevice::deviceStopEnroll()
|
||
{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_ENROLL)
|
||
+ if (m_driver)
|
||
{
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- if (m_driver)
|
||
- {
|
||
- KLOG_DEBUG() << "delete driver";
|
||
- delete m_driver;
|
||
- m_driver = nullptr;
|
||
- }
|
||
- KLOG_DEBUG() << "stop Enroll";
|
||
+ KLOG_DEBUG() << "delete driver";
|
||
+ delete m_driver;
|
||
+ m_driver = nullptr;
|
||
}
|
||
}
|
||
|
||
-void UKeySKFDevice::internalStopIdentify()
|
||
+void UKeySKFDevice::deviceStopIdentify()
|
||
{
|
||
- if (deviceStatus() == DEVICE_STATUS_DOING_IDENTIFY)
|
||
+ if (m_driver)
|
||
{
|
||
- m_identifyIDs.clear();
|
||
- setDeviceStatus(DEVICE_STATUS_IDLE);
|
||
- clearWatchedServices();
|
||
- if (m_driver)
|
||
- {
|
||
- delete m_driver;
|
||
- m_driver = nullptr;
|
||
- }
|
||
- KLOG_DEBUG() << "stopIdentify";
|
||
+ delete m_driver;
|
||
+ m_driver = nullptr;
|
||
}
|
||
}
|
||
|
||
diff --git a/src/device/ukey/ukey-skf-device.h b/src/device/ukey/ukey-skf-device.h
|
||
index 73d1092..b9628ca 100644
|
||
--- a/src/device/ukey/ukey-skf-device.h
|
||
+++ b/src/device/ukey/ukey-skf-device.h
|
||
@@ -29,18 +29,18 @@ public:
|
||
explicit UKeySKFDevice(const QString &vid, const QString &pid, DriverPtr driver, QObject *parent = nullptr);
|
||
~UKeySKFDevice();
|
||
|
||
- bool initDevice() override;
|
||
void resetUkey();
|
||
|
||
private Q_SLOTS:
|
||
bool initSerialNumber();
|
||
|
||
private:
|
||
+ bool initDevice() override;
|
||
void doingEnrollStart(const QString &extraInfo) override;
|
||
void doingIdentifyStart(const QString &value) override;
|
||
|
||
- void internalStopEnroll() override;
|
||
- void internalStopIdentify() override;
|
||
+ void deviceStopEnroll() override;
|
||
+ void deviceStopIdentify() override;
|
||
|
||
void identifyKeyFeature(const QString &pin, QByteArray keyFeature);
|
||
|
||
diff --git a/src/driver/multi-function/mf-iristar-driver.cpp b/src/driver/multi-function/mf-iristar-driver.cpp
|
||
index b2153a6..7c11d43 100644
|
||
--- a/src/driver/multi-function/mf-iristar-driver.cpp
|
||
+++ b/src/driver/multi-function/mf-iristar-driver.cpp
|
||
@@ -264,11 +264,13 @@ void MFIriStarDriver::reset()
|
||
}
|
||
|
||
/**
|
||
+ * 开启注册流程,用于获取人脸/虹膜注册特征信息和图像,非阻塞调用。结果数据通过结果回调函数irsResultCallback返回
|
||
+ * 采集数据的特征类型,只支持I/F,其中I表示虹膜,F表示人脸
|
||
* 注册模式:F-人脸 I-双眼 l-单左眼 r-单右眼
|
||
* 识别模式:F-人脸 I-双眼
|
||
* 识别虹膜时不区分单双眼,只传双眼即可;只有W200设备支持注册时选择单双眼,其他设备全部是双眼
|
||
*/
|
||
-void MFIriStarDriver::doingEnrollStart(DeviceType deviceType)
|
||
+void MFIriStarDriver::doingEnrollStart(DeviceType deviceType, QList<QByteArray> existedfeatures)
|
||
{
|
||
if (deviceType == DEVICE_TYPE_Iris)
|
||
{
|
||
@@ -283,12 +285,22 @@ void MFIriStarDriver::doingEnrollStart(DeviceType deviceType)
|
||
setVideoStream(m_algorithmType.c_str());
|
||
setDeviceStatus(DEVICE_STATUS_DOING_ENROLL);
|
||
|
||
- // 开启注册流程,用于获取人脸/虹膜注册特征信息和图像,非阻塞调用。结果数据通过结果回调函数irsResultCallback返回
|
||
- // 采集数据的特征类型,只支持I/F,其中I表示虹膜,F表示人脸
|
||
- int retVal = prepareEnroll(m_algorithmType.c_str());
|
||
+ // 已经存在的特征为空,说明未录入过
|
||
+ if (existedfeatures.count() == 0)
|
||
+ {
|
||
+ Q_EMIT addFeature();
|
||
+ return;
|
||
+ }
|
||
+ // 注册前需要开启识别流程判断之前是否注册过
|
||
+ int retVal = startIdentify(existedfeatures);
|
||
+ if (retVal == -1)
|
||
+ {
|
||
+ Q_EMIT addFeature();
|
||
+ return;
|
||
+ }
|
||
}
|
||
|
||
-void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QStringList featureIDs)
|
||
+void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QList<QByteArray> features)
|
||
{
|
||
if (deviceType == DEVICE_TYPE_Iris)
|
||
{
|
||
@@ -303,7 +315,7 @@ void MFIriStarDriver::doingIdentifyStart(DeviceType deviceType, QStringList feat
|
||
setVideoStream(m_algorithmType.c_str());
|
||
setDeviceStatus(DEVICE_STATUS_DOING_IDENTIFY);
|
||
|
||
- int retVal = startIdentify(featureIDs);
|
||
+ int retVal = startIdentify(features);
|
||
|
||
if (retVal != GENERAL_RESULT_OK)
|
||
{
|
||
@@ -346,56 +358,18 @@ bool MFIriStarDriver::isLoaded()
|
||
return m_driverLib->isLoaded;
|
||
}
|
||
|
||
-int MFIriStarDriver::prepareEnroll(const char *objectType)
|
||
+int MFIriStarDriver::startIdentify(QList<QByteArray> features)
|
||
{
|
||
- KLOG_DEBUG() << "prepareEnroll";
|
||
- // 注册前需要开启识别流程判断之前是否注册过
|
||
- int retVal = startIdentify(QStringList());
|
||
- if (retVal == -1)
|
||
- {
|
||
- KLOG_DEBUG() << "add Feature";
|
||
- Q_EMIT addFeature();
|
||
- }
|
||
- return retVal;
|
||
-}
|
||
-
|
||
-int MFIriStarDriver::startIdentify(QStringList featureIDs)
|
||
-{
|
||
- KLOG_DEBUG() << "startIdentify";
|
||
- // TODO:这段代码有多处使用,可以提炼复用
|
||
- QList<QByteArray> saveList;
|
||
- QString featureID;
|
||
-
|
||
- if (featureIDs.isEmpty())
|
||
- {
|
||
- saveList = FeatureDB::getInstance()->getFeatures(m_idVendor, m_idProduct, (DeviceType)m_currentDeviceType, QString());
|
||
- }
|
||
- else
|
||
- {
|
||
- Q_FOREACH (auto id, featureIDs)
|
||
- {
|
||
- QByteArray feature = FeatureDB::getInstance()->getFeature(id);
|
||
- if (!feature.isEmpty())
|
||
- saveList << feature;
|
||
- }
|
||
- }
|
||
-
|
||
- if (saveList.count() == 0)
|
||
- {
|
||
- KLOG_DEBUG() << " no features in the database";
|
||
- return -1;
|
||
- }
|
||
-
|
||
int retVal = 0;
|
||
- m_identifyFeatureCache = saveList;
|
||
+ m_identifyFeatureCache = features;
|
||
// 识别类型,只支持I/F,其中I表示虹膜,F表示人脸
|
||
if (m_algorithmType == ALGORITHM_TYPE_IRIS)
|
||
{
|
||
- retVal = identifyIris(saveList);
|
||
+ retVal = identifyIris(features);
|
||
}
|
||
else if (m_algorithmType == ALGORITHM_TYPE_FACE)
|
||
{
|
||
- retVal = identifyFace(saveList);
|
||
+ retVal = identifyFace(features);
|
||
}
|
||
|
||
return retVal;
|
||
@@ -480,7 +454,6 @@ void MFIriStarDriver::onStartEnroll()
|
||
}
|
||
|
||
retVal = m_driverLib->IRS_control(m_irsHandle, IRS_CONTROL_START_ENROLL, (void *)m_algorithmType.c_str(), strlen(m_algorithmType.c_str()));
|
||
- KLOG_DEBUG() << "IRS_CONTROL_START_ENROLL:" << retVal;
|
||
if (retVal != GENERAL_RESULT_OK)
|
||
{
|
||
KLOG_ERROR() << "start enroll failed:" << retVal;
|
||
diff --git a/src/driver/multi-function/mf-iristar-driver.h b/src/driver/multi-function/mf-iristar-driver.h
|
||
index 9c7864c..f03035a 100644
|
||
--- a/src/driver/multi-function/mf-iristar-driver.h
|
||
+++ b/src/driver/multi-function/mf-iristar-driver.h
|
||
@@ -43,8 +43,8 @@ public:
|
||
bool initDriver(const QString &libPath = QString()) override;
|
||
bool isInitialized() { return m_isInitialized; };
|
||
|
||
- void doingEnrollStart(DeviceType deviceType);
|
||
- void doingIdentifyStart(DeviceType deviceType, QStringList featureIDs);
|
||
+ void doingEnrollStart(DeviceType deviceType, QList<QByteArray> existedfeatures);
|
||
+ void doingIdentifyStart(DeviceType deviceType, QList<QByteArray> features);
|
||
|
||
void stop();
|
||
void setDeviceInfo(const QString &idVendor, const QString &idProduct);
|
||
@@ -76,9 +76,7 @@ private:
|
||
void handleRecognized(IRS_Results *results);
|
||
void handleRecognizingFailed(IRS_Results *results);
|
||
|
||
- int prepareEnroll(const char *object);
|
||
-
|
||
- int startIdentify(QStringList featureIDs);
|
||
+ int startIdentify(QList<QByteArray> features);
|
||
int identifyIris(QList<QByteArray> features);
|
||
int identifyFace(QList<QByteArray> features);
|
||
|
||
diff --git a/src/feature-db.cpp b/src/feature-db.cpp
|
||
index 6cf8735..fee5aee 100644
|
||
--- a/src/feature-db.cpp
|
||
+++ b/src/feature-db.cpp
|
||
@@ -77,7 +77,7 @@ bool FeatureDB::createDBConnection()
|
||
|
||
if (!query.exec(createTable))
|
||
{
|
||
- KLOG_DEBUG() << "query.lastError():" << query.lastError();
|
||
+ KLOG_DEBUG() << "failed to create table in the database:" << query.lastError();
|
||
}
|
||
}
|
||
return true;
|
||
diff --git a/src/utils.cpp b/src/utils.cpp
|
||
index 1735ea8..3061263 100644
|
||
--- a/src/utils.cpp
|
||
+++ b/src/utils.cpp
|
||
@@ -18,7 +18,7 @@
|
||
#include <QJsonDocument>
|
||
#include <QJsonObject>
|
||
#include <QSettings>
|
||
-
|
||
+#include "config.h"
|
||
|
||
namespace Kiran
|
||
{
|
||
@@ -101,32 +101,5 @@ QJsonValue getValueFromJsonString(const QString& json, const QString& key)
|
||
return jsonObject.value(key);
|
||
}
|
||
|
||
-QStringList getDriverBlackList()
|
||
-{
|
||
- QSettings confSettings(DRIVER_BLACK_LIST_CONF, QSettings::NativeFormat);
|
||
- return confSettings.value(CONF_FILE_DISABLE_DRIVER_NAME).toStringList();
|
||
-}
|
||
-
|
||
-bool driverEnabled(const QString& driverName)
|
||
-{
|
||
- QSettings confSettings(DRIVER_CONF, QSettings::NativeFormat);
|
||
- QVariant value = confSettings.value(QString("%1/Enable").arg(driverName));
|
||
- if (value.isValid())
|
||
- {
|
||
- if (value.toString() == "false")
|
||
- {
|
||
- return false;
|
||
- }
|
||
- else if (value.toString() == "true")
|
||
- {
|
||
- return true;
|
||
- }
|
||
- else
|
||
- return false;
|
||
- }
|
||
- else
|
||
- return false;
|
||
-}
|
||
-
|
||
} // namespace Utils
|
||
} // namespace Kiran
|
||
\ No newline at end of file
|
||
diff --git a/src/utils.h b/src/utils.h
|
||
index d80174b..1c28065 100644
|
||
--- a/src/utils.h
|
||
+++ b/src/utils.h
|
||
@@ -28,8 +28,5 @@ QString getDeviceName(const QString& idVendor, const QString& idProduct);
|
||
|
||
QJsonValue getValueFromJsonString(const QString& json, const QString& key);
|
||
|
||
-QStringList getDriverBlackList();
|
||
-
|
||
-bool driverEnabled(const QString& driverName);
|
||
} // namespace Utils
|
||
} // namespace Kiran
|
||
diff --git a/ukey-manager/ukey-manager.cpp b/ukey-manager/ukey-manager.cpp
|
||
index d815d72..8a4e86e 100644
|
||
--- a/ukey-manager/ukey-manager.cpp
|
||
+++ b/ukey-manager/ukey-manager.cpp
|
||
@@ -4,6 +4,7 @@
|
||
#include "ukey-skf-driver.h"
|
||
#include <QSettings>
|
||
#include "auth-enum.h"
|
||
+#include "config.h"
|
||
|
||
#define DEFAULT_USER_PINCODE "12345678"
|
||
|
||
--
|
||
2.33.0
|
||
|