-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestDeviceWatcherObserver.cpp
More file actions
125 lines (111 loc) · 3.73 KB
/
Copy pathTestDeviceWatcherObserver.cpp
File metadata and controls
125 lines (111 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "StdAfx.h"
#include <Windows.h>
#include "TestDeviceWatcherObserver.h"
#include "DeviceDetectLog.h"
using namespace DeviceDetectLibrary;
CTestDeviceWatcherObserver::CTestDeviceWatcherObserver(void)
{
}
CTestDeviceWatcherObserver::~CTestDeviceWatcherObserver(void)
{
}
bool WideStrToMultiStr(const std::wstring &wstrSrc, std::string &strDst)
{
int nBytes = ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstrSrc.c_str(), -1, NULL, 0, NULL, NULL);
if(nBytes <= 0)
{
return false;
}
char* pszDst = new char[nBytes];
if(NULL == pszDst)
{
return false;
}
if(0 == ::WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstrSrc.c_str(), -1, pszDst, nBytes, NULL, NULL))
{
delete [] pszDst;
pszDst = NULL;
return false;
}
pszDst[nBytes -1] = '\0';
strDst = pszDst;
delete [] pszDst;
pszDst = NULL;
return true;
}
void CTestDeviceWatcherObserver::AppearedDevice(const CDeviceInfo::Pointer& pDeviceInfo)
{
std::string strText;
if(WideStrToMultiStr(pDeviceInfo->GetName(), strText))
{
LogMessage("\n·¢ÏÖÉ豸: %s", strText.c_str());
}
CConnectionInfo::Pointer pConnectionInfo = pDeviceInfo->GetConnectionInfo();
if(WideStrToMultiStr(pConnectionInfo->DeviceDescription, strText))
{
LogMessage(" Device description: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->DevicePath, strText))
{
LogMessage(" Device path: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->FriendlyName, strText))
{
LogMessage(" Friendly name: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->HardwareID, strText))
{
LogMessage(" Hardware ID: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->PhysicalDeviceName, strText))
{
LogMessage(" Physical device name: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->ServiceName, strText))
{
LogMessage(" Service name: %s", strText.c_str());
}
//LogMessage(" Device description: %S", connectionInfo.DeviceDescription.c_str());
//LogMessage(" Device path: %S", pDeviceInfo->GetConnectionInfo().DevicePath.c_str());
//LogMessage(" Friendly name: %S", pDeviceInfo->GetConnectionInfo().FriendlyName.c_str());
//LogMessage(" Hardware ID: %S", pDeviceInfo->GetConnectionInfo().HardwareID.c_str());
//LogMessage(" Physical device name: %S", pDeviceInfo->GetConnectionInfo().PhysicalDeviceName.c_str());
auto iter = devices_.find(pDeviceInfo->GetId());
if(iter != devices_.end())
{
devices_.erase(iter);
}
devices_.insert(std::make_pair(pDeviceInfo->GetId(), pDeviceInfo));
//devices_[pDeviceInfo->GetId()] = deviceInfo;
}
void CTestDeviceWatcherObserver::DisappearedDevice(const CDeviceInfo::Pointer& pDeviceInfo)
{
LogMessage("\nÒÆ³ýÉ豸");
CConnectionInfo::Pointer pConnectionInfo = pDeviceInfo->GetConnectionInfo();
std::string strText;
if(WideStrToMultiStr(pConnectionInfo->DeviceDescription, strText))
{
LogMessage(" Device description: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->DevicePath, strText))
{
LogMessage(" Device path: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->FriendlyName, strText))
{
LogMessage(" Friendly name: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->HardwareID, strText))
{
LogMessage(" Hardware ID: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->PhysicalDeviceName, strText))
{
LogMessage(" Physical device name: %s", strText.c_str());
}
if(WideStrToMultiStr(pDeviceInfo->GetConnectionInfo()->ServiceName, strText))
{
LogMessage(" Service name: %s", strText.c_str());
}
devices_.erase(pDeviceInfo->GetId());
}