OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #ifndef BASE_SCOPED_NATIVE_LIBRARY_H_ |
| 6 #define BASE_SCOPED_NATIVE_LIBRARY_H_ |
| 7 |
| 8 #include "base/file_path.h" |
| 9 #include "base/native_library.h" |
| 10 |
| 11 namespace base { |
| 12 |
| 13 // A class which encapsulates a base::NativeLibrary object available only in a |
| 14 // scope. |
| 15 // This class automatically unloads the loaded library in its destructor. |
| 16 class ScopedNativeLibrary { |
| 17 public: |
| 18 explicit ScopedNativeLibrary(const FilePath& library_path) { |
| 19 library_ = base::LoadNativeLibrary(library_path); |
| 20 } |
| 21 |
| 22 ~ScopedNativeLibrary() { |
| 23 if (library_) |
| 24 base::UnloadNativeLibrary(library_); |
| 25 } |
| 26 |
| 27 void* GetFunctionPointer(const char* function_name) { |
| 28 if (!library_) |
| 29 return NULL; |
| 30 return base::GetFunctionPointerFromNativeLibrary(library_, function_name); |
| 31 } |
| 32 |
| 33 private: |
| 34 base::NativeLibrary library_; |
| 35 }; |
| 36 |
| 37 } // namespace base |
| 38 |
| 39 #endif // BASE_SCOPED_NATIVE_LIBRARY_H_ |
OLD | NEW |