xref: /aosp_15_r20/frameworks/native/cmds/lshal/Lshal.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1 /*
2  * Copyright (C) 2017 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 #pragma once
18 
19 #include <chrono>
20 #include <iostream>
21 #include <string>
22 
23 #include <android-base/macros.h>
24 #include <android/hidl/manager/1.0/IServiceManager.h>
25 #include <utils/StrongPointer.h>
26 
27 #include "Command.h"
28 #include "NullableOStream.h"
29 #include "ParentDebugInfoLevel.h"
30 #include "utils.h"
31 
32 namespace android {
33 namespace lshal {
34 
35 class Lshal {
36 public:
37     Lshal();
~Lshal()38     virtual ~Lshal() {}
39     Lshal(std::ostream &out, std::ostream &err,
40             sp<hidl::manager::V1_0::IServiceManager> serviceManager,
41             sp<hidl::manager::V1_0::IServiceManager> passthroughManager);
42     Status main(const Arg &arg);
43     // global usage
44     void usage();
45     virtual NullableOStream<std::ostream> err() const;
46     virtual NullableOStream<std::ostream> out() const;
47     const sp<hidl::manager::V1_0::IServiceManager> &serviceManager() const;
48     const sp<hidl::manager::V1_0::IServiceManager> &passthroughManager() const;
49 
50     Status emitDebugInfo(
51             const std::string &interfaceName,
52             const std::string &instanceName,
53             const std::vector<std::string> &options,
54             ParentDebugInfoLevel parentDebugInfoLevel,
55             std::ostream &out,
56             NullableOStream<std::ostream> err) const;
57 
58     Command* selectCommand(const std::string& command) const;
59 
60     void forEachCommand(const std::function<void(const Command* c)>& f) const;
61 
62     void setWaitTimeForTest(std::chrono::milliseconds ipcCallWait,
63                             std::chrono::milliseconds debugDumpWait);
64     std::chrono::milliseconds getIpcCallWait() const;
65     std::chrono::milliseconds getDebugDumpWait() const;
66 
67 private:
68     Status parseArgs(const Arg &arg);
69 
70     std::string mCommand;
71     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;
76 
77     std::vector<std::unique_ptr<Command>> mRegisteredCommands;
78 
79     std::chrono::milliseconds mIpcCallWait{500};
80     std::chrono::milliseconds mDebugDumpWait{10000};
81 
82     DISALLOW_COPY_AND_ASSIGN(Lshal);
83 };
84 
85 }  // namespace lshal
86 }  // namespace android
87