blob: 5bf0b7509b7d2b310e05b0a23faf2ca24cbede22 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +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{
niklase@google.com470e71d2011-07-07 08:21:25 +000031protected:
pbos@webrtc.org6141e132013-04-09 10:09:10 +000032 bool CreateItem(int32_t& itemId);
niklase@google.com470e71d2011-07-07 08:21:25 +000033
pbos@webrtc.org6141e132013-04-09 10:09:10 +000034 void InsertItem(int32_t itemId, void* item);
niklase@google.com470e71d2011-07-07 08:21:25 +000035
pbos@webrtc.org6141e132013-04-09 10:09:10 +000036 void* RemoveItem(int32_t itemId);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pbos@webrtc.org6141e132013-04-09 10:09:10 +000038 void* GetItem(int32_t itemId) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
40 void* GetFirstItem(void*& iterator) const ;
41
42 void* GetNextItem(void*& iterator) const;
43
44 void ReleaseItem();
45
pbos@webrtc.org6141e132013-04-09 10:09:10 +000046 void AddFreeItemId(int32_t itemId);
niklase@google.com470e71d2011-07-07 08:21:25 +000047
pbos@webrtc.org6141e132013-04-09 10:09:10 +000048 bool GetFreeItemId(int32_t& itemId);
niklase@google.com470e71d2011-07-07 08:21:25 +000049
50 void RemoveFreeItemIds();
51
52 void DestroyAllItems();
53
pbos@webrtc.org6141e132013-04-09 10:09:10 +000054 int32_t NumOfItems() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
pbos@webrtc.org6141e132013-04-09 10:09:10 +000056 int32_t MaxNumOfItems() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000057
pbos@webrtc.org6141e132013-04-09 10:09:10 +000058 void GetItemIds(int32_t* channelsArray,
59 int32_t& numOfChannels) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
61 void GetChannels(MapWrapper& channels) const;
62
pbos@webrtc.org6141e132013-04-09 10:09:10 +000063 virtual void* NewItem(int32_t itemId) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
65 virtual void DeleteItem(void* item) = 0;
66
67 ChannelManagerBase();
68
69 virtual ~ChannelManagerBase();
70
71private:
72 // Protects _items and _freeItemIds
73 CriticalSectionWrapper* _itemsCritSectPtr;
74
75 MapWrapper _items;
76
andrew@webrtc.org4a6f62d2013-02-01 23:42:44 +000077 bool _freeItemIds[kVoiceEngineMaxNumChannels];
niklase@google.com470e71d2011-07-07 08:21:25 +000078
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