scoped_native_library.cc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "base/scoped_native_library.h"
  5. namespace base {
  6. void NativeLibraryTraits::Free(NativeLibrary library) {
  7. UnloadNativeLibrary(library);
  8. }
  9. using BaseClass = ScopedGeneric<NativeLibrary, NativeLibraryTraits>;
  10. ScopedNativeLibrary::ScopedNativeLibrary() : BaseClass(), error_() {}
  11. ScopedNativeLibrary::~ScopedNativeLibrary() = default;
  12. ScopedNativeLibrary::ScopedNativeLibrary(NativeLibrary library)
  13. : BaseClass(library), error_() {}
  14. ScopedNativeLibrary::ScopedNativeLibrary(const FilePath& library_path)
  15. : ScopedNativeLibrary() {
  16. reset(LoadNativeLibrary(library_path, &error_));
  17. }
  18. ScopedNativeLibrary::ScopedNativeLibrary(ScopedNativeLibrary&& scoped_library)
  19. : BaseClass(scoped_library.release()), error_() {}
  20. void* ScopedNativeLibrary::GetFunctionPointer(const char* function_name) const {
  21. if (!is_valid())
  22. return nullptr;
  23. return GetFunctionPointerFromNativeLibrary(get(), function_name);
  24. }
  25. const NativeLibraryLoadError* ScopedNativeLibrary::GetError() const {
  26. return &error_;
  27. }
  28. } // namespace base