• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "flutter/fml/build_config.h"
9 #include "flutter/fml/macros.h"
10 #include "flutter/fml/memory/ref_counted.h"
11 #include "flutter/fml/memory/ref_ptr.h"
12 
13 #if OS_WIN
14 
15 #include <windows.h>
16 
17 #endif  // OS_WIN
18 
19 namespace fml {
20 class NativeLibrary : public fml::RefCountedThreadSafe<NativeLibrary> {
21  public:
22 #if OS_WIN
23   using Handle = HMODULE;
24 #else   // OS_WIN
25   using Handle = void*;
26 #endif  // OS_WIN
27 
28   static fml::RefPtr<NativeLibrary> Create(const char* path);
29 
30   static fml::RefPtr<NativeLibrary> CreateWithHandle(
31       Handle handle,
32       bool close_handle_when_done);
33 
34   static fml::RefPtr<NativeLibrary> CreateForCurrentProcess();
35 
36   const uint8_t* ResolveSymbol(const char* symbol);
37 
38  private:
39   Handle handle_ = nullptr;
40   bool close_handle_ = true;
41 
42   NativeLibrary(const char* path);
43 
44   NativeLibrary(Handle handle, bool close_handle);
45 
46   ~NativeLibrary();
47 
48   Handle GetHandle() const;
49 
50   FML_DISALLOW_COPY_AND_ASSIGN(NativeLibrary);
51   FML_FRIEND_REF_COUNTED_THREAD_SAFE(NativeLibrary);
52   FML_FRIEND_MAKE_REF_COUNTED(NativeLibrary);
53 };
54 
55 }  // namespace fml
56 
57 #endif  // FLUTTER_FML_NATIVE_LIBRARY_H_
58