blob: d4dc93d9d6a8146923240602d683dcb260288af9 [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
20#include <atomic>
21#include <binder/IServiceManager.h>
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010022#include <mutex>
Michal Karpinskibe581e22016-10-06 16:56:04 +010023
24#include "android/net/metrics/INetdEventListener.h"
25
26/*
Bernie Innocenticd257642018-12-20 15:56:40 +090027 * This class can be used to get the event listener service.
Michal Karpinskibe581e22016-10-06 16:56:04 +010028 */
29class EventReporter {
30public:
Michal Karpinskibe581e22016-10-06 16:56:04 +010031 // Returns the binder reference to the netd events listener service, attempting to fetch it if
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010032 // we do not have it already. This method is threadsafe.
Michal Karpinskibe581e22016-10-06 16:56:04 +010033 android::sp<android::net::metrics::INetdEventListener> getNetdEventListener();
34
35private:
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010036 // TODO: consider changing this into an atomic type such as
37 // std::atomic<android::net::metrics::INetdEventListener> and deleting the mutex.
38 //
39 // Alternatively, if this locking causes a performance penalty, have each single-threaded
40 // caller (DnsProxyListener, FwmarkServer) keep their own per-thread copy of NetdEventListener
41 // and remove mNetdEventListener entirely.
Michal Karpinskibe581e22016-10-06 16:56:04 +010042 android::sp<android::net::metrics::INetdEventListener> mNetdEventListener;
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010043 std::mutex mutex;
Michal Karpinskibe581e22016-10-06 16:56:04 +010044
45};
46
47#endif // NETD_SERVER_EVENT_REPORTER_H