blob: f471d7fbb00a9529dd5a19bebc4ab5d45672fe1a [file] [log] [blame]
Michal Karpinskibe581e22016-10-06 16:56:04 +01001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NETD_SERVER_EVENT_REPORTER_H
18#define NETD_SERVER_EVENT_REPORTER_H
19
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010020#include <mutex>
Bernie Innocenti9ee088d2019-02-01 17:14:32 +090021#include <set>
Michal Karpinskibe581e22016-10-06 16:56:04 +010022
Luke Huang528af602018-08-29 19:06:05 +080023#include <android-base/thread_annotations.h>
24#include <binder/IServiceManager.h>
25#include "android/net/INetd.h"
26#include "android/net/INetdUnsolicitedEventListener.h"
Michal Karpinskibe581e22016-10-06 16:56:04 +010027#include "android/net/metrics/INetdEventListener.h"
28
29/*
Bernie Innocenticd257642018-12-20 15:56:40 +090030 * This class can be used to get the event listener service.
Michal Karpinskibe581e22016-10-06 16:56:04 +010031 */
32class EventReporter {
Luke Huang528af602018-08-29 19:06:05 +080033 public:
Bernie Innocenti9ee088d2019-02-01 17:14:32 +090034 using UnsolListeners = std::set<const android::sp<android::net::INetdUnsolicitedEventListener>>;
35
Michal Karpinskibe581e22016-10-06 16:56:04 +010036 // Returns the binder reference to the netd events listener service, attempting to fetch it if
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010037 // we do not have it already. This method is threadsafe.
Michal Karpinskibe581e22016-10-06 16:56:04 +010038 android::sp<android::net::metrics::INetdEventListener> getNetdEventListener();
Bernie Innocenti9ee088d2019-02-01 17:14:32 +090039
40 // Returns a copy of the registered listeners.
41 UnsolListeners getNetdUnsolicitedEventListeners() EXCLUDES(mUnsolicitedMutex);
42
Luke Huang528af602018-08-29 19:06:05 +080043 void registerUnsolEventListener(
Bernie Innocenti9ee088d2019-02-01 17:14:32 +090044 const android::sp<android::net::INetdUnsolicitedEventListener>& listener)
Luke Huang528af602018-08-29 19:06:05 +080045 EXCLUDES(mUnsolicitedMutex);
Michal Karpinskibe581e22016-10-06 16:56:04 +010046
Luke Huang528af602018-08-29 19:06:05 +080047 private:
Luke Huang528af602018-08-29 19:06:05 +080048 std::mutex mEventMutex;
49 std::mutex mUnsolicitedMutex;
Bernie Innocenti9ee088d2019-02-01 17:14:32 +090050 android::sp<android::net::metrics::INetdEventListener> mNetdEventListener
51 GUARDED_BY(mEventMutex);
52 UnsolListeners mUnsolListeners GUARDED_BY(mUnsolicitedMutex);
Michal Karpinskibe581e22016-10-06 16:56:04 +010053};
54
55#endif // NETD_SERVER_EVENT_REPORTER_H