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 
39     napi_deferred deferred = nullptr;
40     napi_ref callbackRef = nullptr;
41     napi_status status = napi_generic_failure;
42 };
43 
44 class NapiDistributedAccount {
45 public:
46     static napi_value Init(napi_env env, napi_value exports);
47 
48 private:
49     static napi_value GetDistributedAccountAbility(napi_env env, napi_callback_info cbInfo);
50 
51     static napi_value QueryOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
52     static napi_value GetOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
53     static napi_value QueryOhosAccountInfo(napi_env env, napi_callback_info cbInfo, bool throwErr);
54 
55     static napi_value UpdateOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
56     static napi_value SetOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
57     static napi_value SetOsAccountDistributedInfoByLocalId(napi_env env, napi_callback_info cbInfo);
58     static napi_value GetOsAccountDistributedInfoByLocalId(napi_env env, napi_callback_info cbInfo);
59     static napi_value UpdateOhosAccountInfo(napi_env env, napi_callback_info cbInfo, bool throwErr);
60     static napi_value SetCurrentOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
61 
62     static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo);
63 };
64 } // namespace AccountJsKit
65 } // namespace OHOS
66 
67 #endif // OS_ACCOUNT_INTERFACES_KITS_NAPI_DISTRIBUTEDACCOUNT_INCLUDE_NAPI_DISTRIBUTED_ACCOUNT_H
68