1 /* 2 * Copyright (C) 2020 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 #include "DumpstateServer.h" 18 19 #include <iostream> 20 DumpstateServer(const ServiceSupplier & services)21DumpstateServer::DumpstateServer(const ServiceSupplier& services) { 22 mSystemLogsService = services.GetSystemLogsService(); 23 for (auto svc : services.GetServices()) { 24 mServices.emplace(svc.name(), svc); 25 } 26 27 services.dump(std::cerr); 28 } 29 GetSystemLogs(ServiceDescriptor::OutputConsumer * out)30ServiceDescriptor::Error DumpstateServer::GetSystemLogs(ServiceDescriptor::OutputConsumer* out) { 31 if (mSystemLogsService) 32 return mSystemLogsService->GetOutput(out); 33 else 34 return "system logs missing"; 35 } 36 GetAvailableServices()37std::vector<std::string> DumpstateServer::GetAvailableServices() { 38 std::vector<std::string> ret; 39 40 for (auto& svc : mServices) { 41 if (svc.second.IsAvailable()) ret.push_back(svc.first); 42 } 43 44 return ret; 45 } 46 GetServiceLogs(const std::string & svc,ServiceDescriptor::OutputConsumer * out)47ServiceDescriptor::Error DumpstateServer::GetServiceLogs(const std::string& svc, 48 ServiceDescriptor::OutputConsumer* out) { 49 auto iter = mServices.find(svc); 50 if (iter == mServices.end()) { 51 return "Bad service name: " + svc; 52 } 53 54 return iter->second.GetOutput(out); 55 } 56