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 #ifndef NET_EXT_NAPI_VPN_MONITOR_H 17 #define NET_EXT_NAPI_VPN_MONITOR_H 18 19 #include <napi/native_api.h> 20 #include <refbase.h> 21 22 #include "event_manager.h" 23 #include "vpn_event_callback_stub.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 class VpnEventCallback : public VpnEventCallbackStub { 28 public: 29 void OnVpnStateChanged(const bool &isConnected) override; OnVpnMultiUserSetUp()30 void OnVpnMultiUserSetUp() override{}; 31 }; 32 33 class VpnMonitor { 34 private: 35 VpnMonitor(); 36 ~VpnMonitor(); 37 VpnMonitor(const VpnMonitor &) = delete; 38 VpnMonitor &operator=(const VpnMonitor &) = delete; 39 40 public: 41 static VpnMonitor &GetInstance(); 42 43 public: 44 napi_value On(napi_env env, napi_callback_info info); 45 napi_value Off(napi_env env, napi_callback_info info); 46 GetManager()47 EventManager inline *GetManager() const 48 { 49 return manager_; 50 } 51 52 private: 53 sptr<VpnEventCallback> eventCallback_ = nullptr; 54 napi_value callback_ = nullptr; 55 EventManager *manager_ = nullptr; 56 57 private: 58 bool ParseParams(napi_env env, napi_callback_info info); 59 bool UnwrapManager(napi_env env, napi_value jsObject); 60 void Register(napi_env env); 61 void Unregister(napi_env env); 62 }; 63 } // namespace NetManagerStandard 64 } // namespace OHOS 65 #endif // NET_EXT_NAPI_VPN_MONITOR_H