1 /*
2  * Copyright (c) 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 #include "vpn_connection_ext.h"
17 
18 #include "destroy_context_ext.h"
19 #include "module_template.h"
20 #include "prepare_context_ext.h"
21 #include "protect_context_ext.h"
22 #include "setup_context_ext.h"
23 #include "vpn_async_work_ext.h"
24 #include "vpn_monitor_ext.h"
25 #include "netmanager_ext_log.h"
26 
27 namespace OHOS {
28 namespace NetManagerStandard {
29 namespace VpnConnectionExt {
Prepare(napi_env env,napi_callback_info info)30 napi_value Prepare(napi_env env, napi_callback_info info)
31 {
32     return ModuleTemplate::Interface<PrepareContext>(env, info, PREPARE, nullptr, VpnAsyncWorkExt::ExecPrepare,
33                                                      VpnAsyncWorkExt::PrepareCallback);
34 }
35 
SetUp(napi_env env,napi_callback_info info)36 napi_value SetUp(napi_env env, napi_callback_info info)
37 {
38     NETMANAGER_EXT_LOGI("enter VpnConnectionExt SetUp");
39     return ModuleTemplate::Interface<SetUpContext>(env, info, SET_UP_EXT, nullptr, VpnAsyncWorkExt::ExecSetUp,
40                                                    VpnAsyncWorkExt::SetUpCallback);
41 }
42 
Protect(napi_env env,napi_callback_info info)43 napi_value Protect(napi_env env, napi_callback_info info)
44 {
45     NETMANAGER_EXT_LOGI("enter VpnConnectionExt Protect");
46     return ModuleTemplate::Interface<ProtectContext>(env, info, PROTECT_EXT, nullptr, VpnAsyncWorkExt::ExecProtect,
47                                                      VpnAsyncWorkExt::ProtectCallback);
48 }
49 
Destroy(napi_env env,napi_callback_info info)50 napi_value Destroy(napi_env env, napi_callback_info info)
51 {
52     NETMANAGER_EXT_LOGI("enter VpnConnectionExt Destroy");
53     return ModuleTemplate::Interface<DestroyContext>(env, info, DESTROY_EXT, nullptr, VpnAsyncWorkExt::ExecDestroy,
54                                                      VpnAsyncWorkExt::DestroyCallback);
55 }
56 
On(napi_env env,napi_callback_info info)57 napi_value On(napi_env env, napi_callback_info info)
58 {
59     return VpnMonitor::GetInstance().On(env, info);
60 }
61 
Off(napi_env env,napi_callback_info info)62 napi_value Off(napi_env env, napi_callback_info info)
63 {
64     return VpnMonitor::GetInstance().Off(env, info);
65 }
66 } // namespace VpnConnectionExt
67 } // namespace NetManagerStandard
68 } // namespace OHOS