OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_NATIVE_LIBRARY_H_ | 5 #ifndef BASE_NATIVE_LIBRARY_H_ |
6 #define BASE_NATIVE_LIBRARY_H_ | 6 #define BASE_NATIVE_LIBRARY_H_ |
7 | 7 |
8 // This file defines a cross-platform "NativeLibrary" type which represents | 8 // This file defines a cross-platform "NativeLibrary" type which represents |
9 // a loadable module. | 9 // a loadable module. |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
14 #include "base/compiler_specific.h" | |
15 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_piece.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 | 17 |
18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
19 #include <windows.h> | 19 #include <windows.h> |
20 #elif defined(OS_MACOSX) | 20 #elif defined(OS_MACOSX) |
21 #import <CoreFoundation/CoreFoundation.h> | 21 #import <CoreFoundation/CoreFoundation.h> |
22 #endif // OS_* | 22 #endif // OS_* |
23 | 23 |
24 namespace base { | 24 namespace base { |
25 | 25 |
26 class FilePath; | 26 class FilePath; |
27 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 typedef HMODULE NativeLibrary; | 29 using NativeLibrary = HMODULE; |
30 #elif defined(OS_MACOSX) | 30 #elif defined(OS_MACOSX) |
31 enum NativeLibraryType { | 31 enum NativeLibraryType { |
32 BUNDLE, | 32 BUNDLE, |
33 DYNAMIC_LIB | 33 DYNAMIC_LIB |
34 }; | 34 }; |
35 enum NativeLibraryObjCStatus { | 35 enum NativeLibraryObjCStatus { |
36 OBJC_UNKNOWN, | 36 OBJC_UNKNOWN, |
37 OBJC_PRESENT, | 37 OBJC_PRESENT, |
38 OBJC_NOT_PRESENT, | 38 OBJC_NOT_PRESENT, |
39 }; | 39 }; |
40 struct NativeLibraryStruct { | 40 struct NativeLibraryStruct { |
41 NativeLibraryType type; | 41 NativeLibraryType type; |
42 CFBundleRefNum bundle_resource_ref; | 42 CFBundleRefNum bundle_resource_ref; |
43 NativeLibraryObjCStatus objc_status; | 43 NativeLibraryObjCStatus objc_status; |
44 union { | 44 union { |
45 CFBundleRef bundle; | 45 CFBundleRef bundle; |
46 void* dylib; | 46 void* dylib; |
47 }; | 47 }; |
48 }; | 48 }; |
49 typedef NativeLibraryStruct* NativeLibrary; | 49 using NativeLibrary = NativeLibraryStruct*; |
50 #elif defined(OS_POSIX) | 50 #elif defined(OS_POSIX) |
51 typedef void* NativeLibrary; | 51 using NativeLibrary = void*; |
52 #endif // OS_* | 52 #endif // OS_* |
53 | 53 |
54 struct BASE_EXPORT NativeLibraryLoadError { | 54 struct BASE_EXPORT NativeLibraryLoadError { |
55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
56 NativeLibraryLoadError() : code(0) {} | 56 NativeLibraryLoadError() : code(0) {} |
57 #endif // OS_WIN | 57 #endif // OS_WIN |
58 | 58 |
59 // Returns a string representation of the load error. | 59 // Returns a string representation of the load error. |
60 std::string ToString() const; | 60 std::string ToString() const; |
61 | 61 |
(...skipping 18 matching lines...) Expand all Loading... |
80 // import table. | 80 // import table. |
81 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically( | 81 BASE_EXPORT NativeLibrary LoadNativeLibraryDynamically( |
82 const FilePath& library_path); | 82 const FilePath& library_path); |
83 #endif // OS_WIN | 83 #endif // OS_WIN |
84 | 84 |
85 // Unloads a native library. | 85 // Unloads a native library. |
86 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); | 86 BASE_EXPORT void UnloadNativeLibrary(NativeLibrary library); |
87 | 87 |
88 // Gets a function pointer from a native library. | 88 // Gets a function pointer from a native library. |
89 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, | 89 BASE_EXPORT void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, |
90 const char* name); | 90 StringPiece name); |
91 | 91 |
92 // Returns the full platform specific name for a native library. | 92 // Returns the full platform specific name for a native library. |
93 // For example: | 93 // For example: |
94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, | 94 // "mylib" returns "mylib.dll" on Windows, "libmylib.so" on Linux, |
95 // "mylib.dylib" on Mac. | 95 // "mylib.dylib" on Mac. |
96 BASE_EXPORT string16 GetNativeLibraryName(const string16& name); | 96 BASE_EXPORT string16 GetNativeLibraryName(StringPiece16 name); |
97 | 97 |
98 } // namespace base | 98 } // namespace base |
99 | 99 |
100 #endif // BASE_NATIVE_LIBRARY_H_ | 100 #endif // BASE_NATIVE_LIBRARY_H_ |
OLD | NEW |