blob: 3a42bd08271b00b8d95aeefc53e14e58717b3308 (
plain) (
blame)
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
|
#include "main.h"
#include "./discoveryMonitor.h"
DiscoveryMonitor::DiscoveryMonitor()
{
InitializeCriticalSection(&lock);
}
DiscoveryMonitor::~DiscoveryMonitor()
{
DeleteCriticalSection(&lock);
}
void DiscoveryMonitor::Lock()
{
EnterCriticalSection(&lock);
}
void DiscoveryMonitor::Unlock()
{
LeaveCriticalSection(&lock);
}
BOOL DiscoveryMonitor::Register(ifc_deviceprovider *provider)
{
Lock();
size_t index = activityList.size();
while(index--)
{
ActiveDiscovery *entry = &activityList[index];
if ((intptr_t)provider == entry->providerId)
{
entry->ref++;
Unlock();
return FALSE;
}
}
ActiveDiscovery record;
record.providerId = (intptr_t)provider;
record.ref = 1;
activityList.push_back(record);
index = activityList.size();
Unlock();
return (1 == index);
}
BOOL DiscoveryMonitor::Unregister(ifc_deviceprovider *provider)
{
Lock();
size_t index = activityList.size();
while(index--)
{
ActiveDiscovery *entry = &activityList[index];
if ((intptr_t)provider == entry->providerId)
{
if (1 == entry->ref)
{
activityList.erase(activityList.begin() + index);
index = activityList.size();
Unlock();
return (0 == index);
}
entry->ref--;
break;
}
}
Unlock();
return FALSE;
}
BOOL DiscoveryMonitor::IsActive()
{
size_t count;
Lock();
count = activityList.size();
Unlock();
return (0 != count);
}
BOOL DiscoveryMonitor::Reset()
{
size_t count;
Lock();
count = activityList.size();
activityList.clear();
Unlock();
return (0 != count);
}
|