diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/devices/discoveryMonitor.cpp | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/devices/discoveryMonitor.cpp')
-rw-r--r-- | Src/devices/discoveryMonitor.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Src/devices/discoveryMonitor.cpp b/Src/devices/discoveryMonitor.cpp new file mode 100644 index 00000000..3a42bd08 --- /dev/null +++ b/Src/devices/discoveryMonitor.cpp @@ -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); +} + + |