Michal Karpinski | be581e2 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 1 | /* |
| 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 Karpinski | 4b9b78a | 2016-10-06 19:33:55 +0100 | [diff] [blame^] | 22 | #include <mutex> |
Michal Karpinski | be581e2 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 23 | |
| 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 | */ |
| 29 | class EventReporter { |
| 30 | public: |
| 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 Karpinski | 4b9b78a | 2016-10-06 19:33:55 +0100 | [diff] [blame^] | 35 | // we do not have it already. This method is threadsafe. |
Michal Karpinski | be581e2 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 36 | android::sp<android::net::metrics::INetdEventListener> getNetdEventListener(); |
| 37 | |
| 38 | private: |
| 39 | std::atomic_int mReportingLevel{ |
Michal Karpinski | 36deff7 | 2016-10-06 18:06:00 +0100 | [diff] [blame] | 40 | android::net::metrics::INetdEventListener::REPORTING_LEVEL_FULL}; |
Michal Karpinski | 4b9b78a | 2016-10-06 19:33:55 +0100 | [diff] [blame^] | 41 | // 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 Karpinski | be581e2 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 47 | android::sp<android::net::metrics::INetdEventListener> mNetdEventListener; |
Michal Karpinski | 4b9b78a | 2016-10-06 19:33:55 +0100 | [diff] [blame^] | 48 | std::mutex mutex; |
Michal Karpinski | be581e2 | 2016-10-06 16:56:04 +0100 | [diff] [blame] | 49 | |
| 50 | }; |
| 51 | |
| 52 | #endif // NETD_SERVER_EVENT_REPORTER_H |