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> |
| 22 | |
| 23 | #include "android/net/metrics/INetdEventListener.h" |
| 24 | |
| 25 | /* |
| 26 | * This class stores the reporting level and can be used to get the event listener service. |
| 27 | */ |
| 28 | class EventReporter { |
| 29 | public: |
| 30 | int setMetricsReportingLevel(const int level); |
| 31 | int getMetricsReportingLevel() const; |
| 32 | |
| 33 | // Returns the binder reference to the netd events listener service, attempting to fetch it if |
| 34 | // we do not have it already. This method mutates internal state without taking a lock and must |
| 35 | // only be called on one thread. This is safe because we only call this in the runCommand |
| 36 | // methods of our commands, which are only called by FrameworkListener::onDataAvailable, which |
| 37 | // is only called from SocketListener::runListener, which is a single-threaded select loop. |
| 38 | android::sp<android::net::metrics::INetdEventListener> getNetdEventListener(); |
| 39 | |
| 40 | private: |
| 41 | std::atomic_int mReportingLevel{ |
| 42 | android::net::metrics::INetdEventListener::REPORTING_LEVEL_METRICS}; |
| 43 | android::sp<android::net::metrics::INetdEventListener> mNetdEventListener; |
| 44 | |
| 45 | }; |
| 46 | |
| 47 | #endif // NETD_SERVER_EVENT_REPORTER_H |