blob: c1f535cd2b0f61b900f23fe2927ab6ade3086f54 [file] [log] [blame]
henrike@webrtc.orgf7795df2014-05-13 18:00:26 +00001/*
2 * Copyright 2004 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_BASE_LATEBINDINGSYMBOLTABLE_H_
12#define WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_
13
14#include <string.h>
15
16#include "webrtc/base/common.h"
17
18namespace rtc {
19
20#if defined(WEBRTC_POSIX)
21typedef void *DllHandle;
22#else
23#error Not implemented for this platform
24#endif
25
26// This is the base class for "symbol table" classes to simplify the dynamic
27// loading of symbols from DLLs. Currently the implementation only supports
28// Linux and OS X, and pure C symbols (or extern "C" symbols that wrap C++
29// functions). Sub-classes for specific DLLs are generated via the "supermacro"
30// files latebindingsymboltable.h.def and latebindingsymboltable.cc.def. See
31// talk/sound/pulseaudiosymboltable.(h|cc) for an example.
32class LateBindingSymbolTable {
33 public:
34 struct TableInfo {
35 const char *dll_name;
36 int num_symbols;
37 // Array of size num_symbols.
38 const char *const *symbol_names;
39 };
40
41 LateBindingSymbolTable(const TableInfo *info, void **table);
42 ~LateBindingSymbolTable();
43
44 bool IsLoaded() const;
45 // Loads the DLL and the symbol table. Returns true iff the DLL and symbol
46 // table loaded successfully.
47 bool Load();
48 // Like load, but allows overriding the dll path for when the dll path is
49 // dynamic.
50 bool LoadFromPath(const char *dll_path);
51 void Unload();
52
53 // Gets the raw OS handle to the DLL. Be careful what you do with it.
54 DllHandle GetDllHandle() const { return handle_; }
55
56 private:
57 void ClearSymbols();
58
59 const TableInfo *info_;
60 void **table_;
61 DllHandle handle_;
62 bool undefined_symbols_;
63
64 DISALLOW_COPY_AND_ASSIGN(LateBindingSymbolTable);
65};
66
67} // namespace rtc
68
69#endif // WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_