aboutsummaryrefslogtreecommitdiff
path: root/webrtc/base/latebindingsymboltable.h
blob: 636e7d0707251579f5debc394ef304463ca3ab68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_
#define WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_

#include <string.h>

#include "webrtc/base/common.h"

namespace rtc {

#if defined(WEBRTC_POSIX)
typedef void *DllHandle;
#else
#error Not implemented for this platform
#endif

// This is the base class for "symbol table" classes to simplify the dynamic
// loading of symbols from DLLs. Currently the implementation only supports
// Linux and OS X, and pure C symbols (or extern "C" symbols that wrap C++
// functions).  Sub-classes for specific DLLs are generated via the "supermacro"
// files latebindingsymboltable.h.def and latebindingsymboltable.cc.def. See
// talk/sound/pulseaudiosymboltable.(h|cc) for an example.
class LateBindingSymbolTable {
 public:
  struct TableInfo {
    const char *dll_name;
    int num_symbols;
    // Array of size num_symbols.
    const char *const *symbol_names;
  };

  LateBindingSymbolTable(const TableInfo *info, void **table);
  ~LateBindingSymbolTable();

  bool IsLoaded() const;
  // Loads the DLL and the symbol table. Returns true iff the DLL and symbol
  // table loaded successfully.
  bool Load();
  // Like load, but allows overriding the dll path for when the dll path is
  // dynamic.
  bool LoadFromPath(const char *dll_path);
  void Unload();

  // Gets the raw OS handle to the DLL. Be careful what you do with it.
  DllHandle GetDllHandle() const { return handle_; }

 private:
  void ClearSymbols();

  const TableInfo *info_;
  void **table_;
  DllHandle handle_;
  bool undefined_symbols_;

  RTC_DISALLOW_COPY_AND_ASSIGN(LateBindingSymbolTable);
};

}  // namespace rtc

#endif  // WEBRTC_BASE_LATEBINDINGSYMBOLTABLE_H_