1 /* 2 * Copyright (C) 2018 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 ANDROID_OS_DUMPSTATESECTIONREPORTER_H_ 18 #define ANDROID_OS_DUMPSTATESECTIONREPORTER_H_ 19 20 #include <android/os/IDumpstateListener.h> 21 #include <utils/StrongPointer.h> 22 23 namespace android { 24 namespace os { 25 namespace dumpstate { 26 27 28 /* 29 * Helper class used to report per section details to a listener. 30 * 31 * Typical usage: 32 * 33 * DumpstateSectionReporter sectionReporter(title, listener, sendReport); 34 * sectionReporter.setSize(5000); 35 * 36 */ 37 class DumpstateSectionReporter { 38 public: 39 DumpstateSectionReporter(const std::string& title, sp<android::os::IDumpstateListener> listener, 40 bool sendReport); 41 42 ~DumpstateSectionReporter(); 43 setStatus(status_t status)44 void setStatus(status_t status) { 45 status_ = status; 46 } 47 setSize(int size)48 void setSize(int size) { 49 size_ = size; 50 } 51 52 private: 53 std::string title_; 54 android::sp<android::os::IDumpstateListener> listener_; 55 bool sendReport_; 56 status_t status_; 57 int size_; 58 std::chrono::time_point<std::chrono::steady_clock> started_; 59 }; 60 61 } // namespace dumpstate 62 } // namespace os 63 } // namespace android 64 65 #endif // ANDROID_OS_DUMPSTATESECTIONREPORTER_H_ 66