xref: /aosp_15_r20/external/cronet/base/scoped_native_library.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 The Chromium Authors
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 
Free(NativeLibrary library)9 void NativeLibraryTraits::Free(NativeLibrary library) {
10   UnloadNativeLibrary(library);
11 }
12 
13 using BaseClass = ScopedGeneric<NativeLibrary, NativeLibraryTraits>;
14 
ScopedNativeLibrary()15 ScopedNativeLibrary::ScopedNativeLibrary() : BaseClass(), error_() {}
16 
17 ScopedNativeLibrary::~ScopedNativeLibrary() = default;
18 
ScopedNativeLibrary(NativeLibrary library)19 ScopedNativeLibrary::ScopedNativeLibrary(NativeLibrary library)
20     : BaseClass(library), error_() {}
21 
ScopedNativeLibrary(const FilePath & library_path)22 ScopedNativeLibrary::ScopedNativeLibrary(const FilePath& library_path)
23     : ScopedNativeLibrary() {
24   reset(LoadNativeLibrary(library_path, &error_));
25 }
26 
ScopedNativeLibrary(ScopedNativeLibrary && scoped_library)27 ScopedNativeLibrary::ScopedNativeLibrary(ScopedNativeLibrary&& scoped_library)
28     : BaseClass(scoped_library.release()), error_() {}
29 
GetFunctionPointer(const char * function_name) const30 void* ScopedNativeLibrary::GetFunctionPointer(const char* function_name) const {
31   if (!is_valid())
32     return nullptr;
33   return GetFunctionPointerFromNativeLibrary(get(), function_name);
34 }
35 
GetError() const36 const NativeLibraryLoadError* ScopedNativeLibrary::GetError() const {
37   return &error_;
38 }
39 
40 }  // namespace base
41