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 INTERFACE_OBSERVER_WRAPPER_H 17 #define INTERFACE_OBSERVER_WRAPPER_H 18 19 #include <initializer_list> 20 #include <string> 21 22 #include <napi/native_api.h> 23 24 #include "refbase.h" 25 #include "singleton.h" 26 27 #include "event_manager.h" 28 #include "interface_state_observer.h" 29 30 namespace OHOS { 31 namespace NetManagerStandard { 32 class InterfaceStateObserverWrapper { 33 DISALLOW_COPY_AND_MOVE(InterfaceStateObserverWrapper); 34 35 public: 36 napi_value On(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events, 37 bool asyncCallback); 38 napi_value Off(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events, 39 bool asyncCallback); 40 41 static InterfaceStateObserverWrapper &GetInstance(); 42 GetEventManager()43 EventManager *GetEventManager() const 44 { 45 return manager_; 46 } 47 48 private: 49 InterfaceStateObserverWrapper(); 50 ~InterfaceStateObserverWrapper(); 51 52 sptr<InterfaceStateObserver> observer_ = nullptr; 53 EventManager *manager_ = nullptr; 54 bool registered_ = false; 55 }; 56 } // namespace NetManagerStandard 57 } // namespace OHOS 58 #endif // statistics_observer_wrapper_H 59