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 POLICY_OBSERVER_WRAPPER_H
17 #define POLICY_OBSERVER_WRAPPER_H
18 
19 #include <initializer_list>
20 #include <string>
21 
22 #include <napi/native_api.h>
23 #include <napi/native_node_api.h>
24 
25 #include "event_manager.h"
26 #include "net_mgr_log_wrapper.h"
27 #include "net_policy_callback_observer.h"
28 #include "netmanager_base_log.h"
29 #include "refbase.h"
30 #include "singleton.h"
31 
32 namespace OHOS {
33 namespace NetManagerStandard {
34 class PolicyObserverWrapper : public Singleton<PolicyObserverWrapper> {
35 public:
36     PolicyObserverWrapper();
37     ~PolicyObserverWrapper();
38 
39     napi_value On(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events,
40                   bool asyncCallback);
41     napi_value Off(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events,
42                    bool asyncCallback);
43     void DeleteListener(size_t paramsCount, napi_value *params, std::string event);
GetEventManager()44     EventManager *GetEventManager() const
45     {
46         return manager_;
47     }
48 
49 private:
50     sptr<NetPolicyCallbackObserver> observer_;
51     EventManager *manager_;
52     bool registed_;
53 };
54 } // namespace NetManagerStandard
55 } // namespace OHOS
56 #endif // POLICY_OBSERVER_WRAPPER_H
57