xref: /aosp_15_r20/system/netd/server/EventReporter.h (revision 8542734a0dd1db395a4d42aae09c37f3c3c3e7a1)
1*8542734aSAndroid Build Coastguard Worker /*
2*8542734aSAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*8542734aSAndroid Build Coastguard Worker  *
4*8542734aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8542734aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8542734aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8542734aSAndroid Build Coastguard Worker  *
8*8542734aSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*8542734aSAndroid Build Coastguard Worker  *
10*8542734aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8542734aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8542734aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8542734aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8542734aSAndroid Build Coastguard Worker  * limitations under the License.
15*8542734aSAndroid Build Coastguard Worker  */
16*8542734aSAndroid Build Coastguard Worker 
17*8542734aSAndroid Build Coastguard Worker #ifndef NETD_SERVER_EVENT_REPORTER_H
18*8542734aSAndroid Build Coastguard Worker #define NETD_SERVER_EVENT_REPORTER_H
19*8542734aSAndroid Build Coastguard Worker 
20*8542734aSAndroid Build Coastguard Worker #include <map>
21*8542734aSAndroid Build Coastguard Worker #include <mutex>
22*8542734aSAndroid Build Coastguard Worker 
23*8542734aSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
24*8542734aSAndroid Build Coastguard Worker #include <binder/IServiceManager.h>
25*8542734aSAndroid Build Coastguard Worker #include "android/net/INetd.h"
26*8542734aSAndroid Build Coastguard Worker #include "android/net/INetdUnsolicitedEventListener.h"
27*8542734aSAndroid Build Coastguard Worker #include "android/net/metrics/INetdEventListener.h"
28*8542734aSAndroid Build Coastguard Worker 
29*8542734aSAndroid Build Coastguard Worker /*
30*8542734aSAndroid Build Coastguard Worker  * This class can be used to get the event listener service.
31*8542734aSAndroid Build Coastguard Worker  */
32*8542734aSAndroid Build Coastguard Worker class EventReporter {
33*8542734aSAndroid Build Coastguard Worker   public:
34*8542734aSAndroid Build Coastguard Worker     using UnsolListenerMap =
35*8542734aSAndroid Build Coastguard Worker             std::map<const android::sp<android::net::INetdUnsolicitedEventListener>,
36*8542734aSAndroid Build Coastguard Worker                      const android::sp<android::IBinder::DeathRecipient>>;
37*8542734aSAndroid Build Coastguard Worker 
38*8542734aSAndroid Build Coastguard Worker     // Returns the binder reference to the netd events listener service, attempting to fetch it if
39*8542734aSAndroid Build Coastguard Worker     // we do not have it already. This method is threadsafe.
40*8542734aSAndroid Build Coastguard Worker     android::sp<android::net::metrics::INetdEventListener> getNetdEventListener();
41*8542734aSAndroid Build Coastguard Worker 
42*8542734aSAndroid Build Coastguard Worker     // Returns a copy of the registered listeners.
43*8542734aSAndroid Build Coastguard Worker     UnsolListenerMap getNetdUnsolicitedEventListenerMap() const EXCLUDES(mUnsolicitedMutex);
44*8542734aSAndroid Build Coastguard Worker 
45*8542734aSAndroid Build Coastguard Worker     void registerUnsolEventListener(
46*8542734aSAndroid Build Coastguard Worker             const android::sp<android::net::INetdUnsolicitedEventListener>& listener)
47*8542734aSAndroid Build Coastguard Worker             EXCLUDES(mUnsolicitedMutex);
48*8542734aSAndroid Build Coastguard Worker     void unregisterUnsolEventListener(
49*8542734aSAndroid Build Coastguard Worker             const android::sp<android::net::INetdUnsolicitedEventListener>& listener)
50*8542734aSAndroid Build Coastguard Worker             EXCLUDES(mUnsolicitedMutex);
51*8542734aSAndroid Build Coastguard Worker 
52*8542734aSAndroid Build Coastguard Worker   private:
53*8542734aSAndroid Build Coastguard Worker     std::mutex mEventMutex;
54*8542734aSAndroid Build Coastguard Worker     mutable std::mutex mUnsolicitedMutex;
55*8542734aSAndroid Build Coastguard Worker     android::sp<android::net::metrics::INetdEventListener> mNetdEventListener
56*8542734aSAndroid Build Coastguard Worker             GUARDED_BY(mEventMutex);
57*8542734aSAndroid Build Coastguard Worker     UnsolListenerMap mUnsolListenerMap GUARDED_BY(mUnsolicitedMutex);
58*8542734aSAndroid Build Coastguard Worker };
59*8542734aSAndroid Build Coastguard Worker 
60*8542734aSAndroid Build Coastguard Worker #endif  // NETD_SERVER_EVENT_REPORTER_H
61