NaCl: Update revision in DEPS, b3d4cc1 -> a0efd24, update UMA test
[chromium-blink-merge.git] / base / native_library.h
blob1e764da89aa6846c4d5b646a301d0d28ad9de799
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_NATIVE_LIBRARY_H_
6 #define BASE_NATIVE_LIBRARY_H_
8 // This file defines a cross-platform "NativeLibrary" type which represents
9 // a loadable module.
11 #include <string>
13 #include "base/base_export.h"
14 #include "base/compiler_specific.h"
15 #include "base/strings/string16.h"
16 #include "build/build_config.h"
18 #if defined(OS_WIN)
19 #include <windows.h>
20 #elif defined(OS_MACOSX)
21 #import <CoreFoundation/CoreFoundation.h>
22 #endif // OS_*
24 namespace base {
26 class FilePath;
28 #if defined(OS_WIN)
29 typedef HMODULE NativeLibrary;
30 #elif defined(OS_MACOSX)
31 enum NativeLibraryType {
32 BUNDLE,
33 DYNAMIC_LIB
35 enum NativeLibraryObjCStatus {
36 OBJC_UNKNOWN,
37 OBJC_PRESENT,
38 OBJC_NOT_PRESENT,
40 struct NativeLibraryStruct {
41 NativeLibraryType type;
42 CFBundleRefNum bundle_resource_ref;
43 NativeLibraryObjCStatus objc_status;
44 union {
45 CFBundleRef bundle;
46 void* dylib;
49 typedef NativeLibraryStruct* NativeLibrary;
50 #elif defined(OS_POSIX)
51 typedef void* NativeLibrary;
52 #endif // OS_*
54 struct BASE_EXPORT NativeLibraryLoadError {
55 #if defined(OS_WIN)
56 NativeLibraryLoadError() : code(0) {}
57 #endif // OS_WIN
59 // Returns a string representation of the load error.
60 std::string ToString() const;
62 #if defined(OS_WIN)
63 DWORD code;
64 #else
65 std::string message;
66 #endif // OS_WIN
69 // Loads a native library from disk. Release it with UnloadNativeLibrary when
70 // you're done. Returns NULL on failure.
71 // If |error| is not NULL, it may be filled in on load error.
72 BASE_EXPORT NativeLibrary LoadNativeLibrary(const FilePath& library_path,
73 NativeLibraryLoadError* error);
75 #if defined(OS_WIN)
76 // Loads a native library from disk. Release it with UnloadNativeLibrary when
77 // you're done.
78 // This function retrieves the LoadLibrary function exported from kernel32.dll
79 // and calls it instead of directly calling the LoadLibrary function via the
80 // import table.
81 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically(
82 const FilePath& library_path);
83 #endif // OS_WIN
85 // Unloads a native library.
86 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library);
88 // Gets a function pointer from a native library.
89 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
90 const char* name);
92 // Returns the full platform specific name for a native library.
93 // For example:
94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux,
95 // "mylib.dylib" on Mac.
96 BASE_EXPORT string16 GetNativeLibraryName(const string16& name);
98 } // namespace base
100 #endif // BASE_NATIVE_LIBRARY_H_