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 
16 #include "netshare_startsharing_context.h"
17 
18 #include "constant.h"
19 #include "napi_utils.h"
20 #include "net_manager_constants.h"
21 #include "netmanager_ext_log.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
NetShareStartSharingContext(napi_env env,EventManager * manager)25 NetShareStartSharingContext::NetShareStartSharingContext(napi_env env, EventManager *manager)
26     : BaseContext(env, manager)
27 {
28 }
29 
ParseParams(napi_value * params,size_t paramsCount)30 void NetShareStartSharingContext::ParseParams(napi_value *params, size_t paramsCount)
31 {
32     if (!CheckParamsType(params, paramsCount)) {
33         NETMANAGER_EXT_LOGE("CheckParamsType failed");
34         SetErrorCode(NETMANAGER_EXT_ERR_PARAMETER_ERROR);
35         SetNeedThrowException(true);
36         return;
37     }
38     SetParam(NapiUtils::GetInt32FromValue(GetEnv(), params[ARG_INDEX_0]));
39     if (paramsCount == PARAM_OPTIONS_AND_CALLBACK) {
40         SetParseOK(SetCallback(params[ARG_INDEX_1]) == napi_ok);
41         return;
42     }
43     SetParseOK(true);
44 }
45 
CheckParamsType(napi_value * params,size_t paramsCount)46 bool NetShareStartSharingContext::CheckParamsType(napi_value *params, size_t paramsCount)
47 {
48     if (paramsCount == PARAM_JUST_OPTIONS || paramsCount == PARAM_OPTIONS_AND_CALLBACK) {
49         if (NapiUtils::GetValueType(GetEnv(), params[0]) == napi_number) {
50             return true;
51         }
52     }
53     return false;
54 }
55 
GetParam() const56 int32_t NetShareStartSharingContext::GetParam() const
57 {
58     return param_;
59 }
60 
GetBytes32() const61 int32_t NetShareStartSharingContext::GetBytes32() const
62 {
63     return bytes32_;
64 }
65 
GetIfaces() const66 std::vector<std::string> NetShareStartSharingContext::GetIfaces() const
67 {
68     return ifaces_;
69 }
70 
SetParam(int32_t param)71 void NetShareStartSharingContext::SetParam(int32_t param)
72 {
73     param_ = param;
74 }
75 
SetIface(std::vector<std::string> ifaces)76 void NetShareStartSharingContext::SetIface(std::vector<std::string> ifaces)
77 {
78     ifaces_ = ifaces;
79 }
80 
SetBytes32(int32_t bytes32)81 void NetShareStartSharingContext::SetBytes32(int32_t bytes32)
82 {
83     bytes32_ = bytes32;
84 }
85 } // namespace NetManagerStandard
86 } // namespace OHOS
87