• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "network_module.h"
17 #include "gettype_context.h"
18 #include "netmanager_base_log.h"
19 #include "module_template.h"
20 #include "network_async_work.h"
21 #include "subscribe_context.h"
22 #include "unsubscribe_context.h"
23 
24 namespace OHOS::NetManagerStandard {
InitNetworkModule(napi_env env,napi_value exports)25 napi_value NetworkModule::InitNetworkModule(napi_env env, napi_value exports)
26 {
27     std::initializer_list<napi_property_descriptor> properties = {
28         DECLARE_NAPI_FUNCTION(FUNCTION_GET_TYPE, GetType),
29         DECLARE_NAPI_FUNCTION(FUNCTION_SUBSCRIBE, Subscribe),
30         DECLARE_NAPI_FUNCTION(FUNCTION_UNSUBSCRIBE, Unsubscribe),
31     };
32     NapiUtils::DefineProperties(env, exports, properties);
33     return exports;
34 }
35 
GetType(napi_env env,napi_callback_info info)36 napi_value NetworkModule::GetType(napi_env env, napi_callback_info info)
37 {
38     NETMANAGER_BASE_LOGI("NetworkModule::GetType is called");
39     return ModuleTemplate::InterfaceWithoutManager<GetTypeContext>(
40         env, info, "SystemNetworkGetType", nullptr, NetworkAsyncWork::ExecGetType, NetworkAsyncWork::GetTypeCallback);
41 }
42 
Subscribe(napi_env env,napi_callback_info info)43 napi_value NetworkModule::Subscribe(napi_env env, napi_callback_info info)
44 {
45     NETMANAGER_BASE_LOGI("NetworkModule::Subscribe is called");
46     return ModuleTemplate::InterfaceWithoutManager<SubscribeContext>(env, info, "SystemNetworkSubscribe", nullptr,
47                                                                      NetworkAsyncWork::ExecSubscribe,
48                                                                      NetworkAsyncWork::SubscribeCallback);
49 }
50 
Unsubscribe(napi_env env,napi_callback_info info)51 napi_value NetworkModule::Unsubscribe(napi_env env, napi_callback_info info)
52 {
53     NETMANAGER_BASE_LOGI("NetworkModule::Unsubscribe is called");
54     return ModuleTemplate::InterfaceWithoutManager<UnsubscribeContext>(env, info, "SystemNetworkUnsubscribe", nullptr,
55                                                                        NetworkAsyncWork::ExecUnsubscribe,
56                                                                        NetworkAsyncWork::UnsubscribeCallback);
57 }
58 
59 NAPI_MODULE(network, NetworkModule::InitNetworkModule)
60 } // namespace OHOS::NetManagerStandard