1 /*
2  * Copyright (c) 2023 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 NAPI_REQUEST_DATA_MANAGER_H
17 #define NAPI_REQUEST_DATA_MANAGER_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "security_guard_napi.h"
23 
24 namespace OHOS::Security::SecurityGuard {
25 class NapiRequestDataManager {
26 public:
27     static NapiRequestDataManager& GetInstance();
28     std::shared_ptr<RequestSecurityEventInfoContext> GetContext(napi_env env);
29     std::shared_ptr<RequestSecurityEventInfoContext> GetContext(napi_env env, bool &isExist);
30     void DeleteContext(napi_env env);
31     uint32_t AddDataCallback(napi_env env);
32     uint32_t DelDataCallback(napi_env env);
33     bool GetDataCallback(napi_env env);
34 
35 private:
36     std::unordered_map<napi_env, std::shared_ptr<RequestSecurityEventInfoContext>> envContextMap_;
37     std::unordered_map<napi_env, uint32_t> envQuerierMap_;
38     std::mutex mutex_;
39     std::mutex envQuerierMutex_;
40     NapiRequestDataManager() = default;
41     ~NapiRequestDataManager() = default;
42 };
43 } // OHOS::Security::SecurityGuard
44 
45 #endif // NAPI_REQUEST_DATA_MANAGER_H
46