Flutter Engine
 
Loading...
Searching...
No Matches
native_library.h
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#ifndef FLUTTER_FML_NATIVE_LIBRARY_H_
6#define FLUTTER_FML_NATIVE_LIBRARY_H_
7
8#include <optional>
9
11#include "flutter/fml/macros.h"
14
15#if defined(FML_OS_WIN)
17#endif // defined(FML_OS_WIN)
18
19namespace fml {
20class NativeLibrary : public fml::RefCountedThreadSafe<NativeLibrary> {
21 public:
22#if FML_OS_WIN
23 using Handle = HMODULE;
24 using SymbolHandle = FARPROC;
25#else // FML_OS_WIN
26 using Handle = void*;
27 using SymbolHandle = void*;
28#endif // FML_OS_WIN
29
30 static fml::RefPtr<NativeLibrary> Create(const char* path);
31
33 Handle handle,
34 bool close_handle_when_done);
35
37
38 template <typename T>
39 const std::optional<T> ResolveFunction(const char* symbol) {
40 auto* resolved_symbol = Resolve(symbol);
41 if (!resolved_symbol) {
42 return std::nullopt;
43 }
44 return std::optional<T>(reinterpret_cast<T>(resolved_symbol));
45 }
46
47 const uint8_t* ResolveSymbol(const char* symbol) {
48 auto* resolved_symbol = reinterpret_cast<const uint8_t*>(Resolve(symbol));
49 if (resolved_symbol == nullptr) {
50 FML_DLOG(INFO) << "Could not resolve symbol in library: " << symbol;
51 }
52 return resolved_symbol;
53 }
54
55 private:
56 Handle handle_ = nullptr;
57 bool close_handle_ = true;
58
59 explicit NativeLibrary(const char* path);
60
61 NativeLibrary(Handle handle, bool close_handle);
62
64
65 Handle GetHandle() const;
66 SymbolHandle Resolve(const char* symbol) const;
67
71};
72
73} // namespace fml
74
75#endif // FLUTTER_FML_NATIVE_LIBRARY_H_
static fml::RefPtr< NativeLibrary > CreateForCurrentProcess()
const std::optional< T > ResolveFunction(const char *symbol)
static fml::RefPtr< NativeLibrary > Create(const char *path)
static fml::RefPtr< NativeLibrary > CreateWithHandle(Handle handle, bool close_handle_when_done)
const uint8_t * ResolveSymbol(const char *symbol)
#define FML_DLOG(severity)
Definition logging.h:121
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
#define FML_FRIEND_REF_COUNTED_THREAD_SAFE(T)
#define FML_FRIEND_MAKE_REF_COUNTED(T)
HINSTANCE HMODULE