blob: cb2820c535e0771201784cf2e71674918e21f0a2 [file] [log] [blame]
Yifan Hongb0dde932017-02-10 17:49:58 -08001/*
Yifan Hong443df792017-05-09 18:49:45 -07002 * Copyright (C) 2017 The Android Open Source Project
Yifan Hongb0dde932017-02-10 17:49:58 -08003 *
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
Steven Moreland0b8e3872019-06-25 08:54:34 -070017#pragma once
Yifan Hongb0dde932017-02-10 17:49:58 -080018
Yifan Hong96bc7142023-12-18 21:57:56 -080019#include <chrono>
Yifan Hong443df792017-05-09 18:49:45 -070020#include <iostream>
Yifan Hongb0dde932017-02-10 17:49:58 -080021#include <string>
Yifan Hongb0dde932017-02-10 17:49:58 -080022
Yifan Hong443df792017-05-09 18:49:45 -070023#include <android-base/macros.h>
Yifan Hongb0dde932017-02-10 17:49:58 -080024#include <android/hidl/manager/1.0/IServiceManager.h>
Yifan Hong443df792017-05-09 18:49:45 -070025#include <utils/StrongPointer.h>
Yifan Hongb0dde932017-02-10 17:49:58 -080026
Yifan Hongded398e2017-09-07 13:54:28 -070027#include "Command.h"
Yifan Hong4b865492017-02-28 19:38:24 -080028#include "NullableOStream.h"
Yifan Hong6884b872020-07-09 16:38:18 -070029#include "ParentDebugInfoLevel.h"
Yifan Hong443df792017-05-09 18:49:45 -070030#include "utils.h"
Yifan Hongb0dde932017-02-10 17:49:58 -080031
32namespace android {
33namespace lshal {
34
Yifan Hongb0dde932017-02-10 17:49:58 -080035class Lshal {
36public:
Yifan Hong443df792017-05-09 18:49:45 -070037 Lshal();
Yifan Hongb2a2ecb2017-09-07 15:08:22 -070038 virtual ~Lshal() {}
Yifan Hong9881df92017-05-10 14:33:05 -070039 Lshal(std::ostream &out, std::ostream &err,
40 sp<hidl::manager::V1_0::IServiceManager> serviceManager,
41 sp<hidl::manager::V1_0::IServiceManager> passthroughManager);
Yifan Hong443df792017-05-09 18:49:45 -070042 Status main(const Arg &arg);
Yifan Honga8bedc62017-09-08 18:00:31 -070043 // global usage
44 void usage();
Yifan Hongb2a2ecb2017-09-07 15:08:22 -070045 virtual NullableOStream<std::ostream> err() const;
46 virtual NullableOStream<std::ostream> out() const;
Yifan Hong9881df92017-05-10 14:33:05 -070047 const sp<hidl::manager::V1_0::IServiceManager> &serviceManager() const;
48 const sp<hidl::manager::V1_0::IServiceManager> &passthroughManager() const;
Yifan Hongb0dde932017-02-10 17:49:58 -080049
Yifan Hong48dc9f82017-05-09 19:33:08 -070050 Status emitDebugInfo(
Andreas Huber28d35912017-03-24 13:14:11 -070051 const std::string &interfaceName,
Yifan Hong443df792017-05-09 18:49:45 -070052 const std::string &instanceName,
53 const std::vector<std::string> &options,
Yifan Hong6884b872020-07-09 16:38:18 -070054 ParentDebugInfoLevel parentDebugInfoLevel,
Yifan Hong48dc9f82017-05-09 19:33:08 -070055 std::ostream &out,
56 NullableOStream<std::ostream> err) const;
Yifan Hongded398e2017-09-07 13:54:28 -070057
Yifan Hong795b6ec2017-09-13 11:25:28 -070058 Command* selectCommand(const std::string& command) const;
59
60 void forEachCommand(const std::function<void(const Command* c)>& f) const;
Yifan Hongded398e2017-09-07 13:54:28 -070061
Yifan Hong96bc7142023-12-18 21:57:56 -080062 void setWaitTimeForTest(std::chrono::milliseconds ipcCallWait,
63 std::chrono::milliseconds debugDumpWait);
64 std::chrono::milliseconds getIpcCallWait() const;
65 std::chrono::milliseconds getDebugDumpWait() const;
66
Yifan Hong443df792017-05-09 18:49:45 -070067private:
68 Status parseArgs(const Arg &arg);
Yifan Hongded398e2017-09-07 13:54:28 -070069
Yifan Hong443df792017-05-09 18:49:45 -070070 std::string mCommand;
Yifan Hong9881df92017-05-10 14:33:05 -070071 NullableOStream<std::ostream> mOut;
72 NullableOStream<std::ostream> mErr;
73
74 sp<hidl::manager::V1_0::IServiceManager> mServiceManager;
75 sp<hidl::manager::V1_0::IServiceManager> mPassthroughManager;
Andreas Huber28d35912017-03-24 13:14:11 -070076
Yifan Hong795b6ec2017-09-13 11:25:28 -070077 std::vector<std::unique_ptr<Command>> mRegisteredCommands;
78
Yifan Hong96bc7142023-12-18 21:57:56 -080079 std::chrono::milliseconds mIpcCallWait{500};
80 std::chrono::milliseconds mDebugDumpWait{10000};
81
Yifan Hong443df792017-05-09 18:49:45 -070082 DISALLOW_COPY_AND_ASSIGN(Lshal);
Yifan Hongb0dde932017-02-10 17:49:58 -080083};
84
Yifan Hongb0dde932017-02-10 17:49:58 -080085} // namespace lshal
86} // namespace android