• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef  INTERFACES_PRIVACY_KITS_NAPI_CONTEXT_COMMON_H
16 #define  INTERFACES_PRIVACY_KITS_NAPI_CONTEXT_COMMON_H
17 
18 #include <uv.h>
19 #include "accesstoken_log.h"
20 #include "active_change_response_info.h"
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 #include "napi_common.h"
24 #include "perm_active_status_customized_cbk.h"
25 #include "privacy_kit.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace AccessToken {
30 struct PrivacyAsyncWorkData {
31     explicit PrivacyAsyncWorkData(napi_env envValue);
32     virtual ~PrivacyAsyncWorkData();
33 
34     napi_env        env = nullptr;
35     napi_async_work asyncWork = nullptr;
36     napi_deferred   deferred = nullptr;
37     napi_ref        callbackRef = nullptr;
38 };
39 
40 class PermActiveStatusPtr : public PermActiveStatusCustomizedCbk {
41 public:
42     explicit PermActiveStatusPtr(const std::vector<std::string>& permList);
43     ~PermActiveStatusPtr() override;
44     void ActiveStatusChangeCallback(ActiveChangeResponse& result) override;
45     void SetEnv(const napi_env& env);
46     void SetCallbackRef(const napi_ref& ref);
47 private:
48     napi_env env_ = nullptr;
49     napi_ref ref_ = nullptr;
50 };
51 
52 struct PermActiveStatusWorker {
53     napi_env env = nullptr;
54     napi_ref ref = nullptr;
55     ActiveChangeResponse result;
56     PermActiveStatusPtr* subscriber = nullptr; // this
57 };
58 
59 struct PermActiveChangeContext {
60     virtual ~PermActiveChangeContext();
61 
62     napi_env env = nullptr;
63     napi_ref callbackRef = nullptr;
64     std::string type;
65     std::shared_ptr<PermActiveStatusPtr> subscriber = nullptr;
66 };
67 
68 void UvQueueWorkActiveStatusChange(uv_work_t* work, int status);
69 bool ConvertActiveChangeResponse(napi_env env, napi_value value, const ActiveChangeResponse& result);
70 void NotifyChangeResponse(const PermActiveStatusWorker* permActiveStatusData);
71 }  // namespace AccessToken
72 }  // namespace Security
73 }  // namespace OHOS
74 #endif /*  INTERFACES_PRIVACY_KITS_NAPI_CONTEXT_COMMON_H */
75