-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractDeviceWatcher.cpp
More file actions
70 lines (60 loc) · 1.53 KB
/
AbstractDeviceWatcher.cpp
File metadata and controls
70 lines (60 loc) · 1.53 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
#include "StdAfx.h"
#include "AbstractDeviceWatcher.h"
#include "AutoCriticalSection.h"
#include "IDeviceWatcherObserver.h"
using namespace DeviceDetectLibrary;
CAbstractDeviceWatcher::CAbstractDeviceWatcher(IDeviceWatcherObserver* observer) : observer_(observer)
{
}
CAbstractDeviceWatcher::~CAbstractDeviceWatcher(void)
{
}
void CAbstractDeviceWatcher::Start(void)
{
StartEnumerators();
tempDevices_.clear();
}
void CAbstractDeviceWatcher::Stop(void)
{
StopEnumerators();
actualDevices_.clear();
}
CNotifyWindow& CAbstractDeviceWatcher::CreateNotifyWindow(void)
{
if(NULL == window_.get())
{
// Create NotifyWindow
window_.reset(new CNotifyWindow(*this));
}
return *window_;
}
void CAbstractDeviceWatcher::RemoveNotifyWindow(void)
{
// Remove NotifyWindow
window_.reset(nullptr);
}
void CAbstractDeviceWatcher::Found(const CDeviceInfo::Pointer& pDeviceInfo)
{
CAutoCriticalSection lock(section_);
auto iter = tempDevices_.find(pDeviceInfo->GetId());
if(iter != tempDevices_.end())
{
tempDevices_.erase(iter);
}
tempDevices_.insert(std::make_pair(pDeviceInfo->GetId(), pDeviceInfo));
if(actualDevices_.count(pDeviceInfo->GetId()) == 0)
{
actualDevices_.insert(std::make_pair(pDeviceInfo->GetId(), pDeviceInfo));
observer_->AppearedDevice(pDeviceInfo);
}
}
void CAbstractDeviceWatcher::Lost(const std::wstring& deviceId)
{
CAutoCriticalSection lock(section_);
auto iter = actualDevices_.find(deviceId);
if(iter != actualDevices_.end())
{
observer_->DisappearedDevice(iter->second);
actualDevices_.erase(deviceId);
}
}