osDynLibrary.h revision 76780669f9867587693563358ccdc903e9cdcbba
1/*
2* Copyright (C) 2011 The Android Open Source Project
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16#ifndef _OSUTILS_DYN_LIBRARY_H
17#define _OSUTILS_DYN_LIBRARY_H
18
19#ifdef _WIN32
20#include <windows.h>
21#endif
22
23namespace osUtils {
24
25typedef void (*dynFuncPtr)(void);
26
27class dynLibrary
28{
29public:
30    static dynLibrary *open(const char *p_libName);
31    ~dynLibrary();
32
33    dynFuncPtr findSymbol(const char *p_symName);
34
35private:
36    dynLibrary();
37
38private:
39#ifdef _WIN32
40    HMODULE m_lib;
41#else
42    void *m_lib;
43#endif
44};
45
46} // of namespace osUtils
47
48
49
50// Macro to compose emugl shared library name under various OS and bitness
51// eg.
52//     on x86_64, EMUGL_LIBNAME("foo") --> "lib64foo.so"
53
54#ifdef _WIN32
55#  define DLL_EXTENSION  "" // _WIN32 LoadLibrary only accept name w/o .dll extension
56#elif defined(__APPLE__)
57#  define DLL_EXTENSION  ".dylib"
58#else
59#  define DLL_EXTENSION  ".so"
60#endif
61
62#if defined(__x86_64__)
63#  define EMUGL_LIBNAME(name) "lib64" name DLL_EXTENSION
64#elif defined(__i386__)
65#  define EMUGL_LIBNAME(name) "lib" name DLL_EXTENSION
66#else
67/* This header is included by target w/o using EMUGL_LIBNAME().  Don't #error, leave it undefined */
68#endif
69
70
71#endif
72