Flutter Engine
The Flutter Engine
native_library_posix.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 "flutter/fml/native_library.h"
6
7#include <dlfcn.h>
8#include <fcntl.h>
9
10namespace fml {
11
12NativeLibrary::NativeLibrary(const char* path) {
13 ::dlerror();
14 handle_ = ::dlopen(path, RTLD_NOW);
15 if (handle_ == nullptr) {
16 FML_DLOG(ERROR) << "Could not open library '" << path << "' due to error '"
17 << ::dlerror() << "'.";
18 }
19}
20
21NativeLibrary::NativeLibrary(Handle handle, bool close_handle)
22 : handle_(handle), close_handle_(close_handle) {}
23
24NativeLibrary::~NativeLibrary() {
25 if (handle_ == nullptr) {
26 return;
27 }
28
29 if (close_handle_) {
30 ::dlerror();
31 if (::dlclose(handle_) != 0) {
32 handle_ = nullptr;
33 FML_LOG(ERROR) << "Could not close library due to error '" << ::dlerror()
34 << "'.";
35 }
36 }
37}
38
39NativeLibrary::Handle NativeLibrary::GetHandle() const {
40 return handle_;
41}
42
44 auto library = fml::AdoptRef(new NativeLibrary(path));
45 return library->GetHandle() != nullptr ? library : nullptr;
46}
47
48fml::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
49 Handle handle,
50 bool close_handle_when_done) {
51 auto library =
52 fml::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
53 return library->GetHandle() != nullptr ? library : nullptr;
54}
55
56fml::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
57 return fml::AdoptRef(new NativeLibrary(RTLD_DEFAULT, false));
58}
59
61 return ::dlsym(handle_, symbol);
62}
63
64} // namespace fml
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_LOG(severity)
Definition: logging.h:82
static FunctionPtr Resolve(Thread *thread, Zone *zone, const GrowableArray< const Instance * > &caller_arguments, const Class &receiver_class, const String &name, const Array &descriptor)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
Definition: ascii_trie.cc:9
RefPtr< T > AdoptRef(T *ptr)
Definition: ref_ptr.h:222
fuchsia::ui::composition::ParentViewportWatcherHandle handle_
#define ERROR(message)
Definition: elf_loader.cc:260