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. 4 5 #include "base/scoped_native_library.h" 6 7 namespace base { 8 ScopedNativeLibrary()9ScopedNativeLibrary::ScopedNativeLibrary() : library_(nullptr) {} 10 ScopedNativeLibrary(NativeLibrary library)11ScopedNativeLibrary::ScopedNativeLibrary(NativeLibrary library) 12 : library_(library) { 13 } 14 ScopedNativeLibrary(const FilePath & library_path)15ScopedNativeLibrary::ScopedNativeLibrary(const FilePath& library_path) { 16 library_ = base::LoadNativeLibrary(library_path, nullptr); 17 } 18 ~ScopedNativeLibrary()19ScopedNativeLibrary::~ScopedNativeLibrary() { 20 if (library_) 21 base::UnloadNativeLibrary(library_); 22 } 23 GetFunctionPointer(const char * function_name) const24void* ScopedNativeLibrary::GetFunctionPointer( 25 const char* function_name) const { 26 if (!library_) 27 return nullptr; 28 return base::GetFunctionPointerFromNativeLibrary(library_, function_name); 29 } 30 Reset(NativeLibrary library)31void ScopedNativeLibrary::Reset(NativeLibrary library) { 32 if (library_) 33 base::UnloadNativeLibrary(library_); 34 library_ = library; 35 } 36 Release()37NativeLibrary ScopedNativeLibrary::Release() { 38 NativeLibrary result = library_; 39 library_ = nullptr; 40 return result; 41 } 42 43 } // namespace base 44