• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_H_
17 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_H_
18 
19 #include "runtime/include/mem/panda_string.h"
20 #include "libpandabase/os/library_loader.h"
21 
22 namespace ark::ets {
23 class EtsNativeLibrary {
24 public:
25     static Expected<EtsNativeLibrary, os::Error> Load(const PandaString &name);
26 
27     EtsNativeLibrary(PandaString name, os::library_loader::LibraryHandle &&handle);
28     ~EtsNativeLibrary() = default;
29 
30     NO_COPY_SEMANTIC(EtsNativeLibrary);
31     DEFAULT_MOVE_SEMANTIC(EtsNativeLibrary);
32 
GetName()33     const PandaString &GetName() const
34     {
35         return name_;
36     }
37 
FindSymbol(const PandaString & name)38     Expected<void *, os::Error> FindSymbol(const PandaString &name) const
39     {
40         return os::library_loader::ResolveSymbol(handle_, name);
41     }
42 
43     bool operator<(const EtsNativeLibrary &rhs) const
44     {
45         return handle_.GetNativeHandle() < rhs.handle_.GetNativeHandle();
46     }
47 
48 private:
49     PandaString name_;
50     os::library_loader::LibraryHandle handle_;
51 };
52 }  // namespace ark::ets
53 
54 #endif  // PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_H_
55