blob: d153e9cd42b662529ca4b51d329d52a7ab33f7c5 (
plain)
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
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et ft=cpp : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_DeviceChangeCallback_h
#define mozilla_DeviceChangeCallback_h
namespace mozilla {
class DeviceChangeCallback
{
public:
virtual void OnDeviceChange()
{
MutexAutoLock lock(mCallbackMutex);
for (DeviceChangeCallback* observer : mDeviceChangeCallbackList)
{
observer->OnDeviceChange();
}
}
virtual int AddDeviceChangeCallback(DeviceChangeCallback* aCallback)
{
MutexAutoLock lock(mCallbackMutex);
if (mDeviceChangeCallbackList.IndexOf(aCallback) == mDeviceChangeCallbackList.NoIndex)
mDeviceChangeCallbackList.AppendElement(aCallback);
return 0;
}
virtual int RemoveDeviceChangeCallback(DeviceChangeCallback* aCallback)
{
MutexAutoLock lock(mCallbackMutex);
return RemoveDeviceChangeCallbackLocked(aCallback);
}
virtual int RemoveDeviceChangeCallbackLocked(DeviceChangeCallback* aCallback)
{
mCallbackMutex.AssertCurrentThreadOwns();
if (mDeviceChangeCallbackList.IndexOf(aCallback) != mDeviceChangeCallbackList.NoIndex)
mDeviceChangeCallbackList.RemoveElement(aCallback);
return 0;
}
DeviceChangeCallback() : mCallbackMutex("mozilla::media::DeviceChangeCallback::mCallbackMutex")
{
}
virtual ~DeviceChangeCallback()
{
}
protected:
nsTArray<DeviceChangeCallback*> mDeviceChangeCallbackList;
Mutex mCallbackMutex;
};
} // namespace mozilla
#endif // mozilla_DeviceChangeCallback_h
|