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 STATISTICS_OBSERVER_WRAPPER_H
17 #define STATISTICS_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 "statistics_callback_observer.h"
29 
30 namespace OHOS {
31 namespace NetManagerStandard {
32 class StatisticsObserverWrapper : public Singleton<StatisticsObserverWrapper> {
33 public:
34     StatisticsObserverWrapper();
35     ~StatisticsObserverWrapper();
36 
37     napi_value On(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events,
38                   bool asyncCallback);
39     napi_value Off(napi_env env, napi_callback_info info, const std::initializer_list<std::string> &events,
40                    bool asyncCallback);
41 
GetEventManager()42     EventManager *GetEventManager() const
43     {
44         return manager_;
45     }
46 
47 private:
48     sptr<StatisticsCallbackObserver> observer_ = nullptr;
49     EventManager *manager_ = nullptr;
50     bool registered_ = false;
51 };
52 } // namespace NetManagerStandard
53 } // namespace OHOS
54 #endif // STATISTICS_OBSERVER_WRAPPER_H
55