niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_BASE_H |
| 12 | #define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_BASE_H |
| 13 | |
| 14 | #include "typedefs.h" |
| 15 | #include "map_wrapper.h" |
| 16 | #include "voice_engine_defines.h" |
| 17 | |
| 18 | namespace webrtc |
| 19 | { |
| 20 | class CriticalSectionWrapper; |
| 21 | class RWLockWrapper; |
| 22 | |
| 23 | namespace voe |
| 24 | { |
| 25 | |
| 26 | class ScopedChannel; |
| 27 | class Channel; |
| 28 | |
| 29 | class ChannelManagerBase |
| 30 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | protected: |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 32 | bool CreateItem(int32_t& itemId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 34 | void InsertItem(int32_t itemId, void* item); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 36 | void* RemoveItem(int32_t itemId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 38 | void* GetItem(int32_t itemId) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
| 40 | void* GetFirstItem(void*& iterator) const ; |
| 41 | |
| 42 | void* GetNextItem(void*& iterator) const; |
| 43 | |
| 44 | void ReleaseItem(); |
| 45 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 46 | void AddFreeItemId(int32_t itemId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 48 | bool GetFreeItemId(int32_t& itemId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
| 50 | void RemoveFreeItemIds(); |
| 51 | |
| 52 | void DestroyAllItems(); |
| 53 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 54 | int32_t NumOfItems() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 56 | int32_t MaxNumOfItems() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 58 | void GetItemIds(int32_t* channelsArray, |
| 59 | int32_t& numOfChannels) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
| 61 | void GetChannels(MapWrapper& channels) const; |
| 62 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 63 | virtual void* NewItem(int32_t itemId) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
| 65 | virtual void DeleteItem(void* item) = 0; |
| 66 | |
| 67 | ChannelManagerBase(); |
| 68 | |
| 69 | virtual ~ChannelManagerBase(); |
| 70 | |
| 71 | private: |
| 72 | // Protects _items and _freeItemIds |
| 73 | CriticalSectionWrapper* _itemsCritSectPtr; |
| 74 | |
| 75 | MapWrapper _items; |
| 76 | |
andrew@webrtc.org | 4a6f62d | 2013-02-01 23:42:44 +0000 | [diff] [blame] | 77 | bool _freeItemIds[kVoiceEngineMaxNumChannels]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
| 79 | // Protects channels from being destroyed while being used |
| 80 | RWLockWrapper* _itemsRWLockPtr; |
| 81 | }; |
| 82 | |
| 83 | } // namespace voe |
| 84 | |
| 85 | } // namespace webrtc |
| 86 | |
| 87 | #endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_BASE_H |