forked from lynx-family/lynx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLynxNodeAPI.h
More file actions
51 lines (40 loc) · 1.33 KB
/
Copy pathLynxNodeAPI.h
File metadata and controls
51 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
#ifndef EXPLORER_CPP_LYNXNODEAPI_H_
#define EXPLORER_CPP_LYNXNODEAPI_H_
#pragma once
#include <cstdint>
#include <mutex>
#include <string>
#include <unordered_map>
namespace lynx {
namespace explorer {
class LynxNodeAPI {
public:
static LynxNodeAPI& GetInstance() {
static LynxNodeAPI instance;
return instance;
}
void PutEnvByToken(uint64_t token_id, void* napi_env_ptr);
void RemoveEnvByToken(uint64_t token_id);
void RequireNodeAddonByToken(uint64_t token_id,
const std::string& addon_name);
void RequireNodeAddon(void* napi_env_ptr, const std::string& addon_name);
private:
LynxNodeAPI() = default;
~LynxNodeAPI() = default;
struct NodeAddon {
void* moduleHandle = nullptr;
void* init = nullptr;
std::string generatedName;
};
bool LoadNodeAddon(NodeAddon& addon, const std::string& libraryName) const;
bool InitializeNodeModule(void* env_ptr, NodeAddon& addon);
std::mutex env_mutex_;
std::unordered_map<uint64_t, void*> tokenEnvMap_;
std::unordered_map<std::string, NodeAddon> nodeAddons_;
};
} // namespace explorer
} // namespace lynx
#endif // EXPLORER_CPP_LYNXNODEAPI_H_