blob: 7717e1155fb37c618b177a0d72ee444db8dd1e70 [file] [log] [blame]
Yifan Hongb84fb572019-03-15 14:19:08 -07001/*
2 * Copyright (C) 2019 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 <limits>
18#include <sstream>
19#include <string>
20#include <vector>
21
22#include <android-base/logging.h>
23#include <android-base/strings.h>
24#include <android/lpdump/BnLpdump.h>
25#include <android/lpdump/ILpdump.h>
26#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
28#include <binder/ProcessState.h>
29
30int LpdumpMain(int argc, char* argv[], std::ostream&, std::ostream&);
31
32namespace android {
33namespace lpdump {
34
35using binder::Status;
36
37class Lpdump : public BnLpdump {
38 public:
39 Lpdump() = default;
40 virtual ~Lpdump() = default;
41
42 Status run(const std::vector<std::string>& args, std::string* aidl_return) override {
David Anderson6b7a5822019-11-19 17:04:39 -080043 std::vector<char*> local_argv;
44 std::vector<std::string> local_args = args;
45 for (auto& arg : local_args) {
46 local_argv.push_back(arg.data());
Yifan Hongb84fb572019-03-15 14:19:08 -070047 }
48 LOG(DEBUG) << "Dumping with args: " << base::Join(args, " ");
49 std::stringstream output;
Yifan Hong9960b982019-03-28 10:42:05 -070050 std::stringstream error;
David Anderson6b7a5822019-11-19 17:04:39 -080051 int ret = LpdumpMain((int)local_argv.size(), local_argv.data(), output, error);
Yifan Hong9960b982019-03-28 10:42:05 -070052 std::string error_str = error.str();
Yifan Hongb84fb572019-03-15 14:19:08 -070053 if (ret == 0) {
Yifan Hong9960b982019-03-28 10:42:05 -070054 if (!error_str.empty()) {
55 LOG(WARNING) << error_str;
56 }
Yifan Hongb84fb572019-03-15 14:19:08 -070057 *aidl_return = output.str();
58 return Status::ok();
59 } else {
Yifan Hong9960b982019-03-28 10:42:05 -070060 return Status::fromServiceSpecificError(ret, error_str.c_str());
Yifan Hongb84fb572019-03-15 14:19:08 -070061 }
62 }
63};
64
65} // namespace lpdump
66} // namespace android
67
68int main(int, char**) {
69 using namespace android;
70
71 sp<lpdump::Lpdump> service = new lpdump::Lpdump();
72 defaultServiceManager()->addService(String16("lpdump_service"), service);
73 LOG(VERBOSE) << "lpdumpd starting";
74 ProcessState::self()->startThreadPool();
75 IPCThreadState::self()->joinThreadPool();
76 return 0;
77}