• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OS_ACCOUNT_INTERFACES_KITS_NAPI_DISTRIBUTEDACCOUNT_INCLUDE_NAPI_DISTRIBUTED_ACCOUNT_H
17 #define OS_ACCOUNT_INTERFACES_KITS_NAPI_DISTRIBUTEDACCOUNT_INCLUDE_NAPI_DISTRIBUTED_ACCOUNT_H
18 
19 #include <string>
20 #include "account_info.h"
21 #include "napi/native_api.h"
22 
23 namespace OHOS {
24 namespace AccountJsKit {
25 struct DistributedAccountAsyncContext {
26     DistributedAccountAsyncContext(napi_env napiEnv);
27     ~DistributedAccountAsyncContext();
28     napi_env env = nullptr;
29     napi_async_work work = nullptr;
30 
31     bool throwErr = false;
32     bool withLocalId = false;
33     int32_t errCode = 0;
34     int32_t localId = -1;  // invalid local id
35 
36     std::string event;
37     AccountSA::OhosAccountInfo ohosAccountInfo;
38     std::string nativeErrMsg;
39 
40     napi_deferred deferred = nullptr;
41     napi_ref callbackRef = nullptr;
42     napi_status status = napi_generic_failure;
43 };
44 
45 class NapiDistributedAccount {
46 public:
47     static napi_value Init(napi_env env, napi_value exports);
48 
49 private:
50     static napi_value GetDistributedAccountAbility(napi_env env, napi_callback_info cbInfo);
51 
52     static napi_value QueryOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
53     static napi_value GetOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
54     static napi_value QueryOhosAccountInfo(napi_env env, napi_callback_info cbInfo, bool throwErr);
55 
56     static napi_value UpdateOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
57     static napi_value SetOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
58     static napi_value SetOsAccountDistributedInfoByLocalId(napi_env env, napi_callback_info cbInfo);
59     static napi_value GetOsAccountDistributedInfoByLocalId(napi_env env, napi_callback_info cbInfo);
60     static napi_value UpdateOhosAccountInfo(napi_env env, napi_callback_info cbInfo, bool throwErr);
61     static napi_value SetCurrentOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
62 
63     static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo);
64 };
65 } // namespace AccountJsKit
66 } // namespace OHOS
67 
68 #endif // OS_ACCOUNT_INTERFACES_KITS_NAPI_DISTRIBUTEDACCOUNT_INCLUDE_NAPI_DISTRIBUTED_ACCOUNT_H
69