15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2004--2010, Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_BASE_LATEBINDINGSYMBOLTABLE_H_
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_BASE_LATEBINDINGSYMBOLTABLE_H_
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <string.h>
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/common.h"
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace talk_base {
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifdef POSIX
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtypedef void *DllHandle;
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#else
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#error Not implemented for this platform
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// This is the base class for "symbol table" classes to simplify the dynamic
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// loading of symbols from DLLs. Currently the implementation only supports
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Linux and OS X, and pure C symbols (or extern "C" symbols that wrap C++
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// functions).  Sub-classes for specific DLLs are generated via the "supermacro"
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// files latebindingsymboltable.h.def and latebindingsymboltable.cc.def. See
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// talk/sound/pulseaudiosymboltable.(h|cc) for an example.
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass LateBindingSymbolTable {
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  struct TableInfo {
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    const char *dll_name;
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    int num_symbols;
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    // Array of size num_symbols.
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    const char *const *symbol_names;
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  };
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  LateBindingSymbolTable(const TableInfo *info, void **table);
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  ~LateBindingSymbolTable();
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool IsLoaded() const;
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Loads the DLL and the symbol table. Returns true iff the DLL and symbol
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // table loaded successfully.
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool Load();
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Like load, but allows overriding the dll path for when the dll path is
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // dynamic.
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool LoadFromPath(const char *dll_path);
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void Unload();
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
7059a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org  // Gets the raw OS handle to the DLL. Be careful what you do with it.
7159a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org  DllHandle GetDllHandle() const { return handle_; }
7259a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void ClearSymbols();
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  const TableInfo *info_;
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void **table_;
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  DllHandle handle_;
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool undefined_symbols_;
805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  DISALLOW_COPY_AND_ASSIGN(LateBindingSymbolTable);
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}  // namespace talk_base
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_BASE_LATEBINDINGSYMBOLTABLE_H_
87