添加相机场景标定和注册码
parent
7319aa8468
commit
b305520fa0
@ -0,0 +1,54 @@
|
||||
#ifndef _H_LPSINGLETON_H_
|
||||
#define _H_LPSINGLETON_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
|
||||
template<class T>
|
||||
class lpsingleton
|
||||
{
|
||||
public:
|
||||
static T* instance()
|
||||
{
|
||||
T *sin = s_this.load(std::memory_order_acquire);
|
||||
|
||||
if (!sin) {
|
||||
std::lock_guard<std::mutex> locker(s_mutex);
|
||||
sin = s_this.load(std::memory_order_relaxed);
|
||||
if (!sin) {
|
||||
sin = new T;
|
||||
s_this.store(sin, std::memory_order_release);
|
||||
}
|
||||
}
|
||||
|
||||
return sin;
|
||||
}
|
||||
|
||||
static void uninstance()
|
||||
{
|
||||
T *sin = s_this.load(std::memory_order_relaxed);
|
||||
if (sin) {
|
||||
std::lock_guard<std::mutex> locker(s_mutex);
|
||||
delete sin;
|
||||
sin = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
lpsingleton() = default;
|
||||
virtual ~lpsingleton() = default;
|
||||
private:
|
||||
lpsingleton(const T&) = delete;
|
||||
T& operator=(const T&) = delete;
|
||||
|
||||
static std::atomic<T*> s_this;
|
||||
static std::mutex s_mutex;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
std::atomic<T*> lpsingleton<T>::s_this;
|
||||
|
||||
template<class T>
|
||||
std::mutex lpsingleton<T>::s_mutex;
|
||||
|
||||
#endif
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 9.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@ -0,0 +1,231 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AwesomeImgViewerBar</class>
|
||||
<widget class="QWidget" name="AwesomeImgViewerBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>236</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#AwesomeImgViewerBar{
|
||||
background-color:palette(window)
|
||||
}</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="wgtRoiCtrl" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboRoiType">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Rect</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnAdd">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="fa_normal_check" stdset="0">
|
||||
<string>f067,white</string>
|
||||
</property>
|
||||
<property name="fa_normal_nocheck" stdset="0">
|
||||
<string>f067</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSub">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Subtract</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="fa_normal" stdset="0">
|
||||
<string>f068</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnDelete">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>D</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="fa_normal" stdset="0">
|
||||
<string>f2ed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnHideRoi">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Hide</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>H</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>14</width>
|
||||
<height>14</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="fa_normal" stdset="0">
|
||||
<string>f06e</string>
|
||||
</property>
|
||||
<property name="fa_hover" stdset="0">
|
||||
<string>f070,white</string>
|
||||
</property>
|
||||
<property name="fa_press" stdset="0">
|
||||
<string>f070,gray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,169 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QCryptokeyUI</class>
|
||||
<widget class="QWidget" name="QCryptokeyUI">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>648</width>
|
||||
<height>334</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>注册</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>退出</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>机器码:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_lineEdit_Serial">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>注册码:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>激活</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>请输入注册码</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>激活状态:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="m_label_Active">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color:rgb(52, 101, 164)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>未激活</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -0,0 +1,293 @@
|
||||
#include "lpHardwareInfo.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#pragma comment (lib, "comsuppw.lib")
|
||||
#pragma comment (lib, "wbemuuid.lib")
|
||||
|
||||
lpHardwareInfo::lpHardwareInfo()
|
||||
: mpLoc(NULL)
|
||||
, mpSvc(NULL)
|
||||
, mbCoInited(false)
|
||||
, msCpuID("")
|
||||
, msMotherBoardID("")
|
||||
, msBiosID("")
|
||||
, msMacAddress("")
|
||||
, mbIsDesktop(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
lpHardwareInfo::~lpHardwareInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void lpHardwareInfo::Close()
|
||||
{
|
||||
deinit();
|
||||
delete this;
|
||||
}
|
||||
|
||||
int lpHardwareInfo::init()
|
||||
{
|
||||
HRESULT hres;
|
||||
hres = CoInitialize(NULL);
|
||||
if (FAILED(hres)) {
|
||||
return QUERY_ERROR_WMI_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
hres = CoInitializeSecurity(
|
||||
NULL,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
RPC_C_AUTHN_LEVEL_DEFAULT,
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE,
|
||||
NULL,
|
||||
EOAC_NONE,
|
||||
NULL
|
||||
);
|
||||
if (FAILED(hres))
|
||||
{
|
||||
CoUninitialize();
|
||||
return QUERY_ERROR_WMI_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
hres = CoCreateInstance(
|
||||
CLSID_WbemLocator,
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_IWbemLocator,
|
||||
reinterpret_cast<LPVOID*>(&mpLoc)
|
||||
);
|
||||
if (FAILED(hres))
|
||||
{
|
||||
CoUninitialize();
|
||||
return QUERY_ERROR_WMI_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
hres = mpLoc->ConnectServer(
|
||||
_bstr_t(L"ROOT\\CIMV2"),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
&mpSvc
|
||||
);
|
||||
if (FAILED(hres))
|
||||
{
|
||||
mpLoc->Release();
|
||||
CoUninitialize();
|
||||
return QUERY_ERROR_WMI_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
hres = CoSetProxyBlanket(
|
||||
mpSvc,
|
||||
RPC_C_AUTHN_WINNT,
|
||||
RPC_C_AUTHZ_NONE,
|
||||
NULL,
|
||||
RPC_C_AUTHN_LEVEL_CALL,
|
||||
RPC_C_IMP_LEVEL_IMPERSONATE,
|
||||
NULL,
|
||||
EOAC_NONE
|
||||
);
|
||||
if (FAILED(hres))
|
||||
{
|
||||
mpSvc->Release();
|
||||
mpLoc->Release();
|
||||
CoUninitialize();
|
||||
return QUERY_ERROR_WMI_CONNECT_FAILED;
|
||||
}
|
||||
|
||||
mbCoInited = true;
|
||||
deviceQuery();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lpHardwareInfo::deinit()
|
||||
{
|
||||
if (mbCoInited)
|
||||
{
|
||||
mpSvc->Release();
|
||||
mpLoc->Release();
|
||||
CoUninitialize();
|
||||
}
|
||||
}
|
||||
|
||||
void lpHardwareInfo::deviceQuery()
|
||||
{
|
||||
// WMIÏà¹ØµÄAPIÎĵµ£º
|
||||
// https://msdn.microsoft.com/en-us/library/aa394132(v=vs.85).aspx
|
||||
|
||||
|
||||
//CPU ID
|
||||
CHAR* szSelect = "SELECT * FROM Win32_Processor WHERE (ProcessorId IS NOT NULL)";
|
||||
WCHAR* szProperty = L"ProcessorId";
|
||||
deviceQuery(szSelect, szProperty, msCpuID);
|
||||
|
||||
//MotherBoard ID
|
||||
szSelect = "SELECT * FROM Win32_BaseBoard WHERE (SerialNumber IS NOT NULL)";
|
||||
szProperty = L"SerialNumber";
|
||||
deviceQuery(szSelect, szProperty, msMotherBoardID);
|
||||
|
||||
//BIOS ID
|
||||
szSelect = "SELECT * FROM Win32_BIOS WHERE (SerialNumber IS NOT NULL)";
|
||||
szProperty = L"SerialNumber";
|
||||
deviceQuery(szSelect, szProperty, msBiosID);
|
||||
|
||||
//MAC Address only Physical and not [virtual, vpn, usb, ...]
|
||||
msMacAddress = "";
|
||||
//szSelect = "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = true \
|
||||
// and NOT Name LIKE '%vpn%' and NOT Name LIKE '%virtual%' \
|
||||
// and NOT Name LIKE '%usb%' and NOT Name LIKE '%Bluetooth%'";
|
||||
szSelect = "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = true \
|
||||
and ( Name LIKE '%pci%' or PNPDeviceID LIKE '%pci%')";
|
||||
szProperty = L"MACAddress";
|
||||
deviceQuery(szSelect, szProperty, msMacAddress);
|
||||
|
||||
//hard disk only "Fixed hard disk media"
|
||||
msHardDrive = "";
|
||||
szSelect = "SELECT * FROM Win32_DiskDrive WHERE MediaType LIKE '%Fixed%'";
|
||||
szProperty = L"SerialNumber";
|
||||
deviceQuery(szSelect, szProperty, msHardDrive);
|
||||
|
||||
//Desktop or laptop
|
||||
queryIsDesktop();
|
||||
}
|
||||
|
||||
void lpHardwareInfo::deviceQuery(CHAR* szSelect, WCHAR* szProperty, std::string& strRslt)
|
||||
{
|
||||
HRESULT hres;
|
||||
DEVICE_PROPERTY dpRst;
|
||||
|
||||
// TCHAT to std::string
|
||||
auto tc2string = [&](TCHAR* ts) -> std::string {
|
||||
int iLen = WideCharToMultiByte(CP_ACP, 0, ts, -1, NULL, 0, NULL, NULL);
|
||||
|
||||
char* chRtn = new char[iLen * sizeof(char)];
|
||||
|
||||
WideCharToMultiByte(CP_ACP, 0, ts, -1, chRtn, iLen, NULL, NULL);
|
||||
|
||||
std::string str(chRtn);
|
||||
delete[] chRtn;
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
// trim string
|
||||
auto strTrim = [&](std::string& text) -> std::string& {
|
||||
if (!text.empty()) {
|
||||
text.erase(0, text.find_first_not_of(" \n\r\t"));
|
||||
text.erase(text.find_last_not_of(" \n\r\t") + 1);
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
//find sub string case insensitive
|
||||
auto findStrInCase = [&](std::string& text, std::string& sub) -> bool {
|
||||
auto it = std::search(
|
||||
text.begin(), text.end(),
|
||||
sub.begin(), sub.end(),
|
||||
[](char ch1, char ch2) { return std::tolower(ch1) == std::tolower(ch2); }
|
||||
);
|
||||
|
||||
return (it != text.end());
|
||||
};
|
||||
|
||||
IEnumWbemClassObject *pEnumerator = NULL;
|
||||
hres = mpSvc->ExecQuery(bstr_t("WQL"), bstr_t(szSelect),
|
||||
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
|
||||
if (SUCCEEDED(hres) && pEnumerator != NULL) {
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
while (pEnumerator) {
|
||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
if (0 == uReturn || !pclsObj) break;
|
||||
|
||||
VARIANT vtProperty;
|
||||
VariantInit(&vtProperty);
|
||||
|
||||
hres = pclsObj->Get(szProperty, 0, &vtProperty, NULL, NULL);
|
||||
if (vtProperty.bstrVal != NULL) {
|
||||
StringCchCopy(dpRst.szProperty, PROPERTY_MAX_LEN, W2T(vtProperty.bstrVal));
|
||||
strRslt += strTrim(tc2string(dpRst.szProperty)) + "#";
|
||||
}
|
||||
VariantClear(&vtProperty);
|
||||
pclsObj->Release();
|
||||
|
||||
}
|
||||
pEnumerator->Release();
|
||||
}
|
||||
|
||||
//remove last #
|
||||
size_t pos = strRslt.find_last_of("#");
|
||||
if (pos == strRslt.length() - 1) {
|
||||
strRslt.erase(strRslt.length() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void lpHardwareInfo::queryIsDesktop()
|
||||
{
|
||||
HRESULT hres;
|
||||
DEVICE_PROPERTY dpRst;
|
||||
|
||||
CHAR* szSelect = "SELECT * FROM Win32_SystemEnclosure";
|
||||
WCHAR* szProperty = L"ChassisTypes";
|
||||
|
||||
IEnumWbemClassObject *pEnumerator = NULL;
|
||||
hres = mpSvc->ExecQuery(bstr_t("WQL"), bstr_t(szSelect),
|
||||
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
|
||||
if (SUCCEEDED(hres) && pEnumerator != NULL) {
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
while (pEnumerator) {
|
||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||
if (0 == uReturn || !pclsObj) break;
|
||||
|
||||
VARIANT vtProperty;
|
||||
VariantInit(&vtProperty);
|
||||
pclsObj->Get(szProperty, 0, &vtProperty, NULL, NULL);
|
||||
|
||||
SAFEARRAY* parrValues = NULL;
|
||||
if (vtProperty.vt & VT_ARRAY) {
|
||||
if (VT_BYREF & vtProperty.vt)
|
||||
parrValues = *vtProperty.pparray;
|
||||
else
|
||||
parrValues = vtProperty.parray;
|
||||
}
|
||||
|
||||
if (parrValues != NULL) {
|
||||
SAFEARRAYBOUND arrayBounds[1];
|
||||
arrayBounds[0].lLbound = 0;
|
||||
arrayBounds[0].cElements = 0;
|
||||
|
||||
SafeArrayGetLBound(parrValues, 1, &arrayBounds[0].lLbound);
|
||||
SafeArrayGetUBound(parrValues, 1, (long*)&arrayBounds[0].cElements);
|
||||
arrayBounds[0].cElements -= arrayBounds[0].lLbound;
|
||||
arrayBounds[0].cElements += 1;
|
||||
|
||||
if (arrayBounds[0].cElements > 0) {
|
||||
for (ULONG i = 0; i < arrayBounds[0].cElements; i++) {
|
||||
LONG lIndex = (LONG)i;
|
||||
INT item;
|
||||
|
||||
HRESULT hr = ::SafeArrayGetElement(parrValues, &lIndex, &item);
|
||||
if (SUCCEEDED(hr)) {
|
||||
if (3 == item) {
|
||||
mbIsDesktop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariantClear(&vtProperty);
|
||||
pclsObj->Release();
|
||||
|
||||
}
|
||||
pEnumerator->Release();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
#ifndef QTPHARDWAREINFO_H__
|
||||
#define QTPHARDWAREINFO_H__
|
||||
|
||||
#include <windows.h>
|
||||
#include <comutil.h>
|
||||
#include <Wbemidl.h>
|
||||
#include <tchar.h>
|
||||
#include <strsafe.h>
|
||||
#include <algorithm>
|
||||
#include <atlconv.h>
|
||||
#include <ntddndis.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "lp_singleton_base.h"
|
||||
|
||||
#define PROPERTY_MAX_LEN 128 // ÊôÐÔ×Ö¶Î×î´ó³¤¶È
|
||||
typedef struct tagDEVICE_PROPERTY
|
||||
{
|
||||
TCHAR szProperty[PROPERTY_MAX_LEN];
|
||||
} DEVICE_PROPERTY;
|
||||
|
||||
typedef enum WQL_QUERY_TYPE
|
||||
{
|
||||
QUERY_CPU_ID = 0,
|
||||
QUERY_MOTHERBOARD_ID = 1,
|
||||
QUERY_BIOS_ID = 2,
|
||||
};
|
||||
|
||||
typedef enum WQL_QUERY_ERRORCODE
|
||||
{
|
||||
QUERY_ERROR_DEVICE_NOT_SUPPORT = -1,
|
||||
QUERY_ERROR_WMI_CONNECT_FAILED = -2,
|
||||
QUERY_ERROR_SQL_SYNTAX_ERROR = -3,
|
||||
};
|
||||
|
||||
class lpHardwareInfo : public lp_singleton_base<lpHardwareInfo>
|
||||
{
|
||||
public:
|
||||
lpHardwareInfo();
|
||||
virtual ~lpHardwareInfo();
|
||||
virtual void Close();
|
||||
|
||||
int init();
|
||||
const std::string& getCpuID() const { return msCpuID; }
|
||||
const std::string& getMotherBoardID() const { return msMotherBoardID; }
|
||||
const std::string& getBiosID() const { return msBiosID; }
|
||||
const std::string& getMacAddress() const { return msMacAddress; }
|
||||
const std::string& getHardDrive() const { return msHardDrive; }
|
||||
bool isDesktop() const { return mbIsDesktop; }
|
||||
private:
|
||||
void deinit();
|
||||
|
||||
void deviceQuery();
|
||||
void deviceQuery(CHAR* szSelect, WCHAR* szProperty, std::string& strRslt);
|
||||
void queryIsDesktop();
|
||||
private:
|
||||
|
||||
IWbemLocator *mpLoc;
|
||||
IWbemServices *mpSvc;
|
||||
|
||||
bool mbCoInited;
|
||||
|
||||
std::string msCpuID;
|
||||
std::string msMotherBoardID;
|
||||
std::string msBiosID;
|
||||
std::string msMacAddress; // probably is list, separated by #
|
||||
std::string msHardDrive; // probably is list, separated by #
|
||||
bool mbIsDesktop;
|
||||
};
|
||||
|
||||
#endif //QTPHARDWAREINFO_H__
|
||||
@ -0,0 +1,59 @@
|
||||
#ifndef _LPIMAGECALIUI_H_
|
||||
#define _LPIMAGECALIUI_H_
|
||||
|
||||
#include <QWidget>
|
||||
#include "ui_lpImageCaliUI.h"
|
||||
#include "AwesomeImgViewer.h"
|
||||
|
||||
class lpImageCaliUI : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lpImageCaliUI(QWidget *parent = Q_NULLPTR);
|
||||
~lpImageCaliUI();
|
||||
|
||||
template<typename _Widget>
|
||||
_Widget* replaceWidget(QWidget* pSrcWidget);
|
||||
|
||||
|
||||
protected:
|
||||
double CalLength(QPoint &p1, QPoint &p2);
|
||||
void AddPoint(QPoint &p, QString strName);
|
||||
void AddPoint_2(QPoint &p, QString strName);
|
||||
Q_SLOT void onButtonClicked();
|
||||
Q_SLOT void onROIChange(const AwesomeRoiInfo& roiInfo, QString strID);
|
||||
Q_SLOT void onPixelClicked(QPoint point);
|
||||
Q_SLOT void onImageScale(qreal scale);
|
||||
Q_SLOT void onRoiLockIng(QString strName);
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual void changeEvent(QEvent *event);
|
||||
virtual void timerEvent(QTimerEvent *event);
|
||||
private:
|
||||
Ui::lpImageCaliUI ui;
|
||||
|
||||
//1
|
||||
AwesomeImgViewer *m_srcImgView_1{ nullptr };
|
||||
int m_imageH_1{0};
|
||||
int m_imageW_1{0};
|
||||
|
||||
QPoint m_point1_1;
|
||||
QPoint m_point2_1;
|
||||
double m_length_1;
|
||||
double m_scale_1;
|
||||
|
||||
//2
|
||||
AwesomeImgViewer *m_srcImgView_2{ nullptr };
|
||||
int m_imageH_2{ 0 };
|
||||
int m_imageW_2{ 0 };
|
||||
|
||||
QPoint m_point1_2;
|
||||
QPoint m_point2_2;
|
||||
double m_length_2;
|
||||
double m_scale_2;
|
||||
//
|
||||
int m_timerID{ 0 };
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,80 @@
|
||||
#include "lpRawTcpClientSession.h"
|
||||
#include <QHostAddress>
|
||||
|
||||
#include <QDebug>
|
||||
#pragma execution_character_set("utf-8")
|
||||
lpRawClientSession::lpRawClientSession(int ID, QObject *parent)
|
||||
: QObject(parent),
|
||||
socket_descriptor_(ID)
|
||||
{
|
||||
psocket_ = new QTcpSocket(this);
|
||||
psocket_->setSocketDescriptor(socket_descriptor_);
|
||||
|
||||
connect(psocket_, SIGNAL(readyRead()), this, SLOT(on_ready_read()));
|
||||
connect(psocket_, SIGNAL(disconnected()), this, SLOT(on_disconnect()));
|
||||
|
||||
}
|
||||
|
||||
lpRawClientSession::~lpRawClientSession()
|
||||
{
|
||||
if (psocket_) {
|
||||
//psocket_->abort();
|
||||
psocket_->close();
|
||||
delete psocket_;
|
||||
psocket_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void lpRawClientSession::on_ready_read()
|
||||
{
|
||||
QByteArray data_recv;
|
||||
data_recv = psocket_->readAll();
|
||||
QSharedPointer<QByteArray> data_ptr = QSharedPointer<QByteArray>
|
||||
(new QByteArray(data_recv.constData(), data_recv.size()));
|
||||
|
||||
if (_func)
|
||||
{
|
||||
_func(data_recv);
|
||||
}
|
||||
emit data_received(socket_descriptor_, data_ptr);
|
||||
}
|
||||
|
||||
void lpRawClientSession::force_close()
|
||||
{
|
||||
psocket_->disconnect();
|
||||
//psocket_->disconnectFromHost();
|
||||
}
|
||||
|
||||
void lpRawClientSession::on_disconnect()
|
||||
{
|
||||
emit sess_disconnected(socket_descriptor_);
|
||||
|
||||
socket_close();
|
||||
}
|
||||
|
||||
void lpRawClientSession::on_data_to_send(int sess_id, QSharedPointer<QByteArray> data)
|
||||
{
|
||||
if (sess_id != socket_descriptor_) return;
|
||||
psocket_->write(data->constData(), data->size());
|
||||
}
|
||||
|
||||
QString lpRawClientSession::getClientIP()
|
||||
{
|
||||
return psocket_->peerAddress().toString();
|
||||
}
|
||||
|
||||
int lpRawClientSession::getClientPort()
|
||||
{
|
||||
return psocket_->peerPort();
|
||||
}
|
||||
|
||||
void lpRawClientSession::socket_close()
|
||||
{
|
||||
|
||||
if (psocket_->isOpen())
|
||||
{
|
||||
psocket_->abort();
|
||||
psocket_->close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
#ifndef __TP_RAW_CLIENTSESSION_H__
|
||||
#define __TP_RAW_CLIENTSESSION_H__
|
||||
|
||||
#include <QThread>
|
||||
#include <QTcpSocket>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
|
||||
typedef std::function<void(QByteArray)> RecvDataFunc;
|
||||
|
||||
class lpRawClientSession : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
lpRawClientSession(int ID, QObject *parent = 0);
|
||||
~lpRawClientSession();
|
||||
|
||||
void setRecvCallBackFunc(RecvDataFunc func) { _func = func; };
|
||||
void force_close();
|
||||
Q_SLOT void on_data_to_send(int sess_id, QSharedPointer<QByteArray>);
|
||||
QString getClientIP();
|
||||
int getClientPort();
|
||||
|
||||
void setClientID(QString strID) {
|
||||
m_strID = strID;
|
||||
};
|
||||
QString getClientID()const {
|
||||
return m_strID;
|
||||
};
|
||||
signals:
|
||||
void data_received(int, QSharedPointer<QByteArray>);
|
||||
void sess_disconnected(int);
|
||||
private:
|
||||
void socket_close();
|
||||
|
||||
Q_SLOT void on_ready_read();
|
||||
Q_SLOT void on_disconnect();
|
||||
private:
|
||||
QTcpSocket *psocket_{ nullptr };
|
||||
int socket_descriptor_;
|
||||
RecvDataFunc _func;
|
||||
QString m_strID;
|
||||
};
|
||||
#endif //__TP_RAW_CLIENTSESSION_H__
|
||||
@ -0,0 +1,158 @@
|
||||
#include <QFile>
|
||||
#include "lpRawTcpClientSession.h"
|
||||
#include "lptkRawTcpServer.h"
|
||||
#pragma execution_character_set("utf-8")
|
||||
lptkRawTcpServer::lptkRawTcpServer(QObject *parent /*= NULL*/)
|
||||
: QTcpServer(parent)
|
||||
{
|
||||
qRegisterMetaType<QSharedPointer<QByteArray>>();
|
||||
client_sessions_.clear();
|
||||
}
|
||||
|
||||
lptkRawTcpServer::~lptkRawTcpServer()
|
||||
{
|
||||
server_end();
|
||||
}
|
||||
|
||||
bool lptkRawTcpServer::server_begin(const QString &strIP, quint16 nPort)
|
||||
{
|
||||
QHostAddress listen_addr_ = QHostAddress::Any;
|
||||
QString ip_addr = strIP;
|
||||
quint16 listen_port_ = nPort;
|
||||
ip_addr.trimmed();
|
||||
if (ip_addr != "*")
|
||||
{
|
||||
listen_addr_.setAddress(ip_addr);
|
||||
}
|
||||
if (!this->listen(listen_addr_, nPort))
|
||||
{
|
||||
qWarning() << "Could not start server. Error: " << this->errorString()
|
||||
<< __FUNCTION__;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Server started. Listening to port " << nPort << __FUNCTION__;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::server_end()
|
||||
{
|
||||
close();
|
||||
//close all connected session
|
||||
auto it = client_sessions_.begin();
|
||||
while (it != client_sessions_.end())
|
||||
{
|
||||
TP_RAW_CLIENT_SESS cli_sess = it.value();
|
||||
disconnect(cli_sess.pSess_);
|
||||
cli_sess.pSess_->force_close();
|
||||
|
||||
cli_sess.pThrd_->quit();
|
||||
cli_sess.pThrd_->wait();
|
||||
if (cli_sess.pThrd_->isRunning()) {
|
||||
cli_sess.pThrd_->exit(0);
|
||||
}
|
||||
delete cli_sess.pThrd_;// ->deleteLater();
|
||||
delete cli_sess.pSess_;
|
||||
client_sessions_.erase(it++);
|
||||
}
|
||||
|
||||
client_sessions_.clear();
|
||||
|
||||
//stop listening
|
||||
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::incomingConnection(qintptr socketDescriptor)
|
||||
{
|
||||
lpRawClientSession *pclientSess = nullptr;
|
||||
|
||||
pclientSess = new lpRawClientSession(socketDescriptor);
|
||||
|
||||
QThread *pThrd = new QThread();
|
||||
pclientSess->moveToThread(pThrd);
|
||||
|
||||
TP_RAW_CLIENT_SESS cli_sess;
|
||||
cli_sess.pThrd_ = pThrd;
|
||||
cli_sess.pSess_ = pclientSess;
|
||||
if (_func)
|
||||
{
|
||||
pclientSess->setRecvCallBackFunc(_func);
|
||||
}
|
||||
|
||||
//connect(pThrd, &QThread::finished, pclientSess, &QObject::deleteLater);
|
||||
connect(pclientSess, &lpRawClientSession::data_received, this, &lptkRawTcpServer::on_data_received);
|
||||
connect(pclientSess, &lpRawClientSession::sess_disconnected, this, &lptkRawTcpServer::on_sess_disconnected);
|
||||
|
||||
connect(this, &lptkRawTcpServer::data_to_send, pclientSess, &lpRawClientSession::on_data_to_send);
|
||||
client_sessions_[socketDescriptor] = cli_sess;
|
||||
|
||||
pThrd->start();
|
||||
QString strIP = pclientSess->getClientIP();
|
||||
int n = strIP.lastIndexOf(":");
|
||||
strIP = strIP.mid(n).remove(":");
|
||||
int port = pclientSess->getClientPort();
|
||||
QString strID = QString("%1:%2").arg(strIP).arg(port);
|
||||
pclientSess->setClientID(strID);
|
||||
emit client_status_changed(socketDescriptor, TCPSERVER_ON_CLIENT_CONNECTED);
|
||||
emit client_connect_status(strID, TCPSERVER_ON_CLIENT_CONNECTED);
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::on_data_received(int sess_id, QSharedPointer<QByteArray> data_ptr)
|
||||
{
|
||||
auto it = client_sessions_.find(sess_id);
|
||||
if (it == client_sessions_.end())
|
||||
{
|
||||
qDebug() << "Invalid session ID : " << sess_id << __FUNCTION__;
|
||||
return;
|
||||
}
|
||||
|
||||
emit data_received(sess_id, data_ptr);
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::on_sess_disconnected(int sess_id)
|
||||
{
|
||||
auto it = client_sessions_.find(sess_id);
|
||||
if (it != client_sessions_.end())
|
||||
{
|
||||
TP_RAW_CLIENT_SESS cli_sess = it.value();
|
||||
cli_sess.pSess_->force_close();
|
||||
cli_sess.pThrd_->quit();
|
||||
cli_sess.pThrd_->wait();
|
||||
if (cli_sess.pThrd_->isRunning()) {
|
||||
cli_sess.pThrd_->exit(0);
|
||||
}
|
||||
|
||||
QString strID = cli_sess.pSess_->getClientID();
|
||||
emit client_connect_status(strID, TCPSERVER_ON_CLIENT_DISCONNECTED);
|
||||
|
||||
delete cli_sess.pThrd_;
|
||||
delete cli_sess.pSess_;
|
||||
client_sessions_.erase(it);
|
||||
}
|
||||
|
||||
emit client_status_changed(sess_id, TCPSERVER_ON_CLIENT_DISCONNECTED);
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::send_data(int sess_id, QSharedPointer<QByteArray> data_ptr)
|
||||
{
|
||||
auto it = client_sessions_.find(sess_id);
|
||||
if (it != client_sessions_.end())
|
||||
{
|
||||
TP_RAW_CLIENT_SESS cli_sess = it.value();
|
||||
emit data_to_send(it.key(), data_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void lptkRawTcpServer::broadcast_send_data(QSharedPointer<QByteArray> data_ptr)
|
||||
{
|
||||
auto it = client_sessions_.begin();
|
||||
while (it != client_sessions_.end())
|
||||
{
|
||||
TP_RAW_CLIENT_SESS cli_sess = it.value();
|
||||
emit data_to_send(it.key(), data_ptr);
|
||||
it++;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
#ifndef TP_RAW_TCPSERVER_H
|
||||
#define TP_RAW_TCPSERVER_H
|
||||
|
||||
#include <QtNetwork/qtcpserver.h>
|
||||
#include <QMap>
|
||||
#include <QTime>
|
||||
#include <QList>
|
||||
#include "lpRawTcpClientSession.h"
|
||||
|
||||
|
||||
typedef struct tagTP_RAW_CLIENT_SESS {
|
||||
QThread *pThrd_;
|
||||
lpRawClientSession *pSess_;
|
||||
}TP_RAW_CLIENT_SESS;
|
||||
typedef QMap<int, TP_RAW_CLIENT_SESS> RawClientsSessionMap;
|
||||
typedef enum emServerStatus
|
||||
{
|
||||
TCPSERVER_ON_RUNNING = 0,
|
||||
TCPSERVER_ON_SHUTDOWN,
|
||||
TCPSERVER_ON_CLIENT_CONNECTED,
|
||||
TCPSERVER_ON_CLIENT_DISCONNECTED,
|
||||
}ServerStatus;
|
||||
|
||||
class lptkRawTcpServer : public QTcpServer
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lptkRawTcpServer(QObject *parent = NULL);
|
||||
~lptkRawTcpServer();
|
||||
|
||||
bool server_begin(const QString &strIP, quint16 nPort);
|
||||
void server_end();
|
||||
|
||||
void broadcast_send_data(QSharedPointer<QByteArray> data_ptr);
|
||||
void send_data(int sess_id, QSharedPointer<QByteArray> data_ptr);
|
||||
|
||||
void setRecvCallFunc(RecvDataFunc func) {
|
||||
_func = func;
|
||||
};
|
||||
signals:
|
||||
void client_status_changed(int, ServerStatus);
|
||||
void data_received(int, QSharedPointer<QByteArray>);
|
||||
void data_to_send(int, QSharedPointer<QByteArray>);
|
||||
void client_connect_status(QString strID, ServerStatus);
|
||||
public slots:
|
||||
void on_sess_disconnected(int);
|
||||
|
||||
void on_data_received(int, QSharedPointer<QByteArray>);
|
||||
protected:
|
||||
void incomingConnection(qintptr socketDescriptor);
|
||||
|
||||
private:
|
||||
RawClientsSessionMap client_sessions_;
|
||||
|
||||
RecvDataFunc _func;
|
||||
};
|
||||
#ifndef LPQSHAREDPOINTERQBYTEARRAY
|
||||
#define LPQSHAREDPOINTERQBYTEARRAY
|
||||
Q_DECLARE_METATYPE(QSharedPointer<QByteArray>)
|
||||
#endif
|
||||
#ifndef LPTKSERVERSTATUS
|
||||
#define LPTKSERVERSTATUS
|
||||
Q_DECLARE_METATYPE(ServerStatus)
|
||||
#endif
|
||||
#endif // TP_RAW_TCPSERVER_H
|
||||
Loading…
Reference in New Issue