blob: 0831e434e4d59826a6a4d1491202f4af73069230 [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
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
18namespace webrtc
19{
20class CriticalSectionWrapper;
21class RWLockWrapper;
22
23namespace voe
24{
25
26class ScopedChannel;
27class Channel;
28
29class ChannelManagerBase
30{
31public:
32 enum {KMaxNumberOfItems = kVoiceEngineMaxNumOfChannels};
33
34protected:
35 bool CreateItem(WebRtc_Word32& itemId);
36
37 void InsertItem(WebRtc_Word32 itemId, void* item);
38
39 void* RemoveItem(WebRtc_Word32 itemId);
40
41 void* GetItem(WebRtc_Word32 itemId) const;
42
43 void* GetFirstItem(void*& iterator) const ;
44
45 void* GetNextItem(void*& iterator) const;
46
47 void ReleaseItem();
48
49 void AddFreeItemId(WebRtc_Word32 itemId);
50
51 bool GetFreeItemId(WebRtc_Word32& itemId);
52
53 void RemoveFreeItemIds();
54
55 void DestroyAllItems();
56
57 WebRtc_Word32 NumOfItems() const;
58
59 WebRtc_Word32 MaxNumOfItems() const;
60
61 void GetItemIds(WebRtc_Word32* channelsArray,
62 WebRtc_Word32& numOfChannels) const;
63
64 void GetChannels(MapWrapper& channels) const;
65
66 virtual void* NewItem(WebRtc_Word32 itemId) = 0;
67
68 virtual void DeleteItem(void* item) = 0;
69
70 ChannelManagerBase();
71
72 virtual ~ChannelManagerBase();
73
74private:
75 // Protects _items and _freeItemIds
76 CriticalSectionWrapper* _itemsCritSectPtr;
77
78 MapWrapper _items;
79
80 bool _freeItemIds[KMaxNumberOfItems];
81
82 // Protects channels from being destroyed while being used
83 RWLockWrapper* _itemsRWLockPtr;
84};
85
86} // namespace voe
87
88} // namespace webrtc
89
90#endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_BASE_H