aboutsummaryrefslogtreecommitdiff
path: root/Src/omBrowser/serviceEventMngr.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/omBrowser/serviceEventMngr.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/omBrowser/serviceEventMngr.cpp')
-rw-r--r--Src/omBrowser/serviceEventMngr.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/Src/omBrowser/serviceEventMngr.cpp b/Src/omBrowser/serviceEventMngr.cpp
new file mode 100644
index 00000000..4d9b100e
--- /dev/null
+++ b/Src/omBrowser/serviceEventMngr.cpp
@@ -0,0 +1,119 @@
+#include "main.h"
+#include "./service.h"
+#include "./ifc_omserviceevent.h"
+
+HRESULT OmService::RegisterEventHandler(ifc_omserviceevent *handler)
+{
+ if (NULL == handler)
+ return E_POINTER;
+
+ HRESULT hr;
+
+ EnterCriticalSection(&eventLock);
+
+ size_t index = eventList.size();
+ while (index--)
+ {
+ if (handler == eventList[index])
+ {
+ break;
+ }
+ }
+
+ if (((size_t)-1) == index)
+ {
+ eventList.push_back(handler);
+ handler->AddRef();
+ hr = S_OK;
+ }
+ else
+ {
+ hr = E_UNEXPECTED;
+ }
+
+ LeaveCriticalSection(&eventLock);
+
+ return hr;
+}
+
+HRESULT OmService::UnregisterEventHandler(ifc_omserviceevent *handler)
+{
+ if (NULL == handler)
+ return E_POINTER;
+
+ HRESULT hr;
+
+ EnterCriticalSection(&eventLock);
+
+ size_t index = eventList.size();
+ while (index--)
+ {
+ if (handler == eventList[index])
+ {
+ break;
+ }
+ }
+
+ if (((size_t)-1) != index)
+ {
+ ifc_omserviceevent *h = eventList[index];
+ eventList.erase(eventList.begin() + index);
+ h->Release();
+ hr = S_OK;
+ }
+ else
+ {
+ hr = S_FALSE;
+ }
+
+ LeaveCriticalSection(&eventLock);
+
+ return hr;
+}
+
+void OmService::UnregisterAllEventHandlers()
+{
+ EnterCriticalSection(&eventLock);
+
+ size_t index = eventList.size();
+ while(index--)
+ {
+ ifc_omserviceevent *handler = eventList[index];
+ if (NULL != handler) handler->Release();
+ }
+ eventList.clear();
+
+ LeaveCriticalSection(&eventLock);
+}
+
+HRESULT OmService::Signal_ServiceChange(unsigned int modifiedFlags)
+{
+ EnterCriticalSection(&eventLock);
+
+ size_t index = eventList.size();
+ while (index--)
+ {
+ ifc_omserviceevent *handler = eventList[index];
+ if (NULL != handler)
+ handler->ServiceChange(this, modifiedFlags);
+ }
+
+ LeaveCriticalSection(&eventLock);
+ return S_OK;
+}
+
+HRESULT OmService::Signal_CommandStateChange(const GUID *commandGroup, UINT commandId)
+{
+ EnterCriticalSection(&eventLock);
+
+ size_t index = eventList.size();
+ while (index--)
+ {
+ ifc_omserviceevent *handler = eventList[index];
+ if (NULL != handler)
+ handler->CommandStateChange(this, commandGroup, commandId);
+ }
+
+ LeaveCriticalSection(&eventLock);
+ return S_OK;
+} \ No newline at end of file