Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
105
Src/devices/discoveryMonitor.cpp
Normal file
105
Src/devices/discoveryMonitor.cpp
Normal file
|
@ -0,0 +1,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);
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue