andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |
| 13 | |
| 14 | namespace webrtc { |
| 15 | |
| 16 | class RWLockWrapper; |
| 17 | |
| 18 | class ViEManagerBase { |
| 19 | friend class ViEManagedItemScopedBase; |
| 20 | friend class ViEManagerScopedBase; |
| 21 | friend class ViEManagerWriteScoped; |
| 22 | public: |
| 23 | ViEManagerBase(); |
| 24 | ~ViEManagerBase(); |
| 25 | |
| 26 | private: |
| 27 | // Exclusive lock, used by ViEManagerWriteScoped. |
| 28 | void WriteLockManager(); |
| 29 | |
| 30 | // Releases exclusive lock, used by ViEManagerWriteScoped. |
| 31 | void ReleaseWriteLockManager(); |
| 32 | |
| 33 | // Increases lock count, used by ViEManagerScopedBase. |
| 34 | void ReadLockManager() const; |
| 35 | |
| 36 | // Releases the lock count, used by ViEManagerScopedBase. |
| 37 | void ReleaseLockManager() const; |
| 38 | |
| 39 | RWLockWrapper& instance_rwlock_; |
| 40 | }; |
| 41 | |
| 42 | class ViEManagerWriteScoped { |
| 43 | public: |
| 44 | explicit ViEManagerWriteScoped(ViEManagerBase* vie_manager); |
| 45 | ~ViEManagerWriteScoped(); |
| 46 | |
| 47 | private: |
| 48 | ViEManagerBase* vie_manager_; |
| 49 | }; |
| 50 | |
| 51 | class ViEManagerScopedBase { |
| 52 | friend class ViEManagedItemScopedBase; |
| 53 | public: |
| 54 | explicit ViEManagerScopedBase(const ViEManagerBase& vie_manager); |
| 55 | ~ViEManagerScopedBase(); |
| 56 | |
| 57 | protected: |
| 58 | const ViEManagerBase* vie_manager_; |
| 59 | |
| 60 | private: |
| 61 | int ref_count_; |
| 62 | }; |
| 63 | |
| 64 | class ViEManagedItemScopedBase { |
| 65 | public: |
| 66 | explicit ViEManagedItemScopedBase(ViEManagerScopedBase* vie_scoped_manager); |
| 67 | ~ViEManagedItemScopedBase(); |
| 68 | |
| 69 | protected: |
| 70 | ViEManagerScopedBase* vie_scoped_manager_; |
| 71 | }; |
| 72 | |
| 73 | } // namespace webrtc |
| 74 | |
| 75 | #endif // WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |