1 /* 2 * Copyright (c) 2022-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 SHARE_OBSERVER_WRAPPER_H 17 #define SHARE_OBSERVER_WRAPPER_H 18 19 #include <initializer_list> 20 #include <string_view> 21 22 #include <napi/native_api.h> 23 24 #include "event_manager.h" 25 #include "netshare_callback_observer.h" 26 #include "refbase.h" 27 #include "singleton.h" 28 29 namespace OHOS { 30 namespace NetManagerStandard { 31 class NetShareObserverWrapper final { 32 DECLARE_DELAYED_SINGLETON(NetShareObserverWrapper); 33 34 public: 35 napi_value On(napi_env env, napi_callback_info info, const std::initializer_list<std::string_view> &events, 36 bool asyncCallback); 37 napi_value Off(napi_env env, napi_callback_info info, const std::initializer_list<std::string_view> &events, 38 bool asyncCallback); 39 std::shared_ptr<EventManager> GetEventManager() const; 40 41 private: 42 sptr<NetShareCallbackObserver> observer_ = nullptr; 43 std::shared_ptr<EventManager> manager_ = nullptr; 44 bool registed_ = false; 45 46 private: 47 int32_t Register(); 48 }; 49 } // namespace NetManagerStandard 50 } // namespace OHOS 51 #endif // SHARE_OBSERVER_WRAPPER_H 52