1 /*
2 * Copyright (c) 2024-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 #include "net_handle_interface.h"
17
18 #include "connection_async_work.h"
19 #include "module_template.h"
20 #include "bindsocket_context.h"
21 #include "getaddressbyname_context.h"
22
23 namespace OHOS {
24 namespace NetManagerStandard {
25
GetAddressesByName(napi_env env,napi_callback_info info)26 napi_value NetHandleInterface::GetAddressesByName(napi_env env, napi_callback_info info)
27 {
28 return ModuleTemplate::Interface<GetAddressByNameContext>(
29 env, info, FUNCTION_GET_ADDRESSES_BY_NAME,
30 [](napi_env theEnv, napi_value thisVal, GetAddressByNameContext *context) -> bool {
31 context->netId_ = NapiUtils::GetInt32Property(theEnv, thisVal, PROPERTY_NET_ID);
32 return true;
33 },
34 ConnectionAsyncWork::NetHandleAsyncWork::ExecGetAddressesByName,
35 ConnectionAsyncWork::NetHandleAsyncWork::GetAddressesByNameCallback);
36 }
37
GetAddressByName(napi_env env,napi_callback_info info)38 napi_value NetHandleInterface::GetAddressByName(napi_env env, napi_callback_info info)
39 {
40 return ModuleTemplate::Interface<GetAddressByNameContext>(
41 env, info, FUNCTION_GET_ADDRESSES_BY_NAME,
42 [](napi_env theEnv, napi_value thisVal, GetAddressByNameContext *context) -> bool {
43 context->netId_ = NapiUtils::GetInt32Property(theEnv, thisVal, PROPERTY_NET_ID);
44 return true;
45 },
46 ConnectionAsyncWork::NetHandleAsyncWork::ExecGetAddressByName,
47 ConnectionAsyncWork::NetHandleAsyncWork::GetAddressByNameCallback);
48 }
49
BindSocket(napi_env env,napi_callback_info info)50 napi_value NetHandleInterface::BindSocket(napi_env env, napi_callback_info info)
51 {
52 return ModuleTemplate::Interface<BindSocketContext>(
53 env, info, FUNCTION_BIND_SOCKET,
54 [](napi_env theEnv, napi_value thisVal, BindSocketContext *context) -> bool {
55 context->netId_ = NapiUtils::GetInt32Property(theEnv, thisVal, PROPERTY_NET_ID);
56 return true;
57 },
58 ConnectionAsyncWork::NetHandleAsyncWork::ExecBindSocket,
59 ConnectionAsyncWork::NetHandleAsyncWork::BindSocketCallback);
60 }
61
62 } // namespace NetManagerStandard
63 } // namespace OHOS