• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_STRUCTS_BASE_H
17 #define NAPI_STRUCTS_BASE_H
18 
19 #include <functional>
20 
21 #include "common_error_define.h"
22 #include "napi_common_define.h"
23 
24 namespace OHOS::UpdateEngine {
25 struct SessionParams {
26     uint32_t type;
27     size_t callbackStartIndex;
28     bool isNeedBusinessError;
29     bool isAsyncCompleteWork;
30 
31     SessionParams(uint32_t typeValue = UINT32_MAX, size_t callbackPosition = CALLBACK_POSITION_ONE,
32         bool isNeedBusinessErrorValue = false, bool isAsyncCompleteWorkValue = false)
typeSessionParams33         : type(typeValue),
34         callbackStartIndex(INDEX(callbackPosition)),
35         isNeedBusinessError(isNeedBusinessErrorValue),
36         isAsyncCompleteWork(isAsyncCompleteWorkValue) {}
37 };
38 
39 struct NapiResult {
40     uint32_t type;
41     BusinessError businessError;
42 
43     template <typename T>
AssignValueNapiResult44     void AssignValue(T *const source, T *&target)
45     {
46         if (target == nullptr) {
47             target = new (std::nothrow) T();
48         }
49         if ((target != nullptr) && (source != nullptr)) {
50             *(target) = *(source);
51         }
52     }
53 
54     template <typename T>
ReleaseValueNapiResult55     void ReleaseValue(T *&obj)
56     {
57         delete obj;
58         obj = nullptr;
59     }
60 };
61 } // namespace OHOS::UpdateEngine
62 #endif // NAPI_STRUCTS_BASE_H