| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H | 11 #ifndef WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H |
| 12 #define WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H | 12 #define WEBRTC_AUDIO_DEVICE_LATEBINDINGSYMBOLTABLE_LINUX_H |
| 13 | 13 |
| 14 #include <assert.h> | 14 #include <assert.h> |
| 15 #include <stddef.h> // for NULL | 15 #include <stddef.h> // for NULL |
| 16 #include <string.h> | 16 #include <string.h> |
| 17 | 17 |
| 18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 | 19 |
| 20 // This file provides macros for creating "symbol table" classes to simplify the | 20 // This file provides macros for creating "symbol table" classes to simplify the |
| 21 // dynamic loading of symbols from DLLs. Currently the implementation only | 21 // dynamic loading of symbols from DLLs. Currently the implementation only |
| 22 // supports Linux and pure C symbols. | 22 // supports Linux and pure C symbols. |
| 23 // See talk/sound/pulseaudiosymboltable.(h|cc) for an example. | 23 // See talk/sound/pulseaudiosymboltable.(h|cc) for an example. |
| 24 | 24 |
| 25 namespace webrtc_adm_linux { | 25 namespace webrtc { |
| 26 namespace adm_linux { |
| 26 | 27 |
| 27 #ifdef WEBRTC_LINUX | 28 #ifdef WEBRTC_LINUX |
| 28 typedef void *DllHandle; | 29 typedef void *DllHandle; |
| 29 | 30 |
| 30 const DllHandle kInvalidDllHandle = NULL; | 31 const DllHandle kInvalidDllHandle = NULL; |
| 31 #else | 32 #else |
| 32 #error Not implemented | 33 #error Not implemented |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 // These are helpers for use only by the class below. | 36 // These are helpers for use only by the class below. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 // This macro must be invoked in the header declaration once for each symbol | 127 // This macro must be invoked in the header declaration once for each symbol |
| 127 // (recommended to use an X-Macro to avoid duplication). | 128 // (recommended to use an X-Macro to avoid duplication). |
| 128 // This macro defines an enum with names built from the symbols, which | 129 // This macro defines an enum with names built from the symbols, which |
| 129 // essentially creates a hash table in the compiler from symbol names to their | 130 // essentially creates a hash table in the compiler from symbol names to their |
| 130 // indices in the symbol table class. | 131 // indices in the symbol table class. |
| 131 #define LATE_BINDING_SYMBOL_TABLE_DECLARE_ENTRY(ClassName, sym) \ | 132 #define LATE_BINDING_SYMBOL_TABLE_DECLARE_ENTRY(ClassName, sym) \ |
| 132 ClassName##_SYMBOL_TABLE_INDEX_##sym, | 133 ClassName##_SYMBOL_TABLE_INDEX_##sym, |
| 133 | 134 |
| 134 // This macro completes the header declaration. | 135 // This macro completes the header declaration. |
| 135 #define LATE_BINDING_SYMBOL_TABLE_DECLARE_END(ClassName) \ | 136 #define LATE_BINDING_SYMBOL_TABLE_DECLARE_END(ClassName) \ |
| 136 ClassName##_SYMBOL_TABLE_SIZE \ | 137 ClassName##_SYMBOL_TABLE_SIZE \ |
| 137 }; \ | 138 } \ |
| 138 \ | 139 ; \ |
| 139 extern const char ClassName##_kDllName[]; \ | 140 \ |
| 140 extern const char *const \ | 141 extern const char ClassName##_kDllName[]; \ |
| 141 ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE]; \ | 142 extern const char* const \ |
| 142 \ | 143 ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE]; \ |
| 143 typedef ::webrtc_adm_linux::LateBindingSymbolTable<ClassName##_SYMBOL_TABLE_SIZE
, \ | 144 \ |
| 144 ClassName##_kDllName, \ | 145 typedef ::webrtc::adm_linux::LateBindingSymbolTable< \ |
| 145 ClassName##_kSymbolNames> \ | 146 ClassName##_SYMBOL_TABLE_SIZE, ClassName##_kDllName, \ |
| 146 ClassName; | 147 ClassName##_kSymbolNames> \ |
| 148 ClassName; |
| 147 | 149 |
| 148 // This macro must be invoked in a .cc file to define a previously-declared | 150 // This macro must be invoked in a .cc file to define a previously-declared |
| 149 // symbol table class. | 151 // symbol table class. |
| 150 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_BEGIN(ClassName, dllName) \ | 152 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_BEGIN(ClassName, dllName) \ |
| 151 const char ClassName##_kDllName[] = dllName; \ | 153 const char ClassName##_kDllName[] = dllName; \ |
| 152 const char *const ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE] = { | 154 const char *const ClassName##_kSymbolNames[ClassName##_SYMBOL_TABLE_SIZE] = { |
| 153 | 155 |
| 154 // This macro must be invoked in the .cc definition once for each symbol | 156 // This macro must be invoked in the .cc definition once for each symbol |
| 155 // (recommended to use an X-Macro to avoid duplication). | 157 // (recommended to use an X-Macro to avoid duplication). |
| 156 // This would have to use the mangled name if we were to ever support C++ | 158 // This would have to use the mangled name if we were to ever support C++ |
| 157 // symbols. | 159 // symbols. |
| 158 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_ENTRY(ClassName, sym) \ | 160 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_ENTRY(ClassName, sym) \ |
| 159 #sym, | 161 #sym, |
| 160 | 162 |
| 161 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_END(ClassName) \ | 163 #define LATE_BINDING_SYMBOL_TABLE_DEFINE_END(ClassName) \ |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 // Index of a given symbol in the given symbol table class. | 166 // Index of a given symbol in the given symbol table class. |
| 165 #define LATESYM_INDEXOF(ClassName, sym) \ | 167 #define LATESYM_INDEXOF(ClassName, sym) \ |
| 166 (ClassName##_SYMBOL_TABLE_INDEX_##sym) | 168 (ClassName##_SYMBOL_TABLE_INDEX_##sym) |
| 167 | 169 |
| 168 // Returns a reference to the given late-binded symbol, with the correct type. | 170 // Returns a reference to the given late-binded symbol, with the correct type. |
| 169 #define LATESYM_GET(ClassName, inst, sym) \ | 171 #define LATESYM_GET(ClassName, inst, sym) \ |
| 170 (*reinterpret_cast<typeof(&sym)>( \ | 172 (*reinterpret_cast<typeof(&sym)>( \ |
| 171 (inst)->GetSymbol(LATESYM_INDEXOF(ClassName, sym)))) | 173 (inst)->GetSymbol(LATESYM_INDEXOF(ClassName, sym)))) |
| 172 | 174 |
| 173 } // namespace webrtc_adm_linux | 175 } // namespace adm_linux |
| 176 } // namespace webrtc |
| 174 | 177 |
| 175 #endif // WEBRTC_ADM_LATEBINDINGSYMBOLTABLE_LINUX_H | 178 #endif // WEBRTC_ADM_LATEBINDINGSYMBOLTABLE_LINUX_H |
| OLD | NEW |