blob: 3338a044c1a0b93378338f32aef5aadb52147b5e [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/*
27 * This class stores the reporting level and can be used to get the event listener service.
28 */
29class EventReporter {
30public:
31 int setMetricsReportingLevel(const int level);
32 int getMetricsReportingLevel() const;
33
34 // Returns the binder reference to the netd events listener service, attempting to fetch it if
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010035 // we do not have it already. This method is threadsafe.
Michal Karpinskibe581e22016-10-06 16:56:04 +010036 android::sp<android::net::metrics::INetdEventListener> getNetdEventListener();
37
38private:
39 std::atomic_int mReportingLevel{
Michal Karpinski36deff72016-10-06 18:06:00 +010040 android::net::metrics::INetdEventListener::REPORTING_LEVEL_FULL};
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010041 // TODO: consider changing this into an atomic type such as
42 // std::atomic<android::net::metrics::INetdEventListener> and deleting the mutex.
43 //
44 // Alternatively, if this locking causes a performance penalty, have each single-threaded
45 // caller (DnsProxyListener, FwmarkServer) keep their own per-thread copy of NetdEventListener
46 // and remove mNetdEventListener entirely.
Michal Karpinskibe581e22016-10-06 16:56:04 +010047 android::sp<android::net::metrics::INetdEventListener> mNetdEventListener;
Michal Karpinski4b9b78a2016-10-06 19:33:55 +010048 std::mutex mutex;
Michal Karpinskibe581e22016-10-06 16:56:04 +010049
50};
51
52#endif // NETD_SERVER_EVENT_REPORTER_H