Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffd8c0c8 authored by Yifan Hong's avatar Yifan Hong Committed by android-build-merger
Browse files

Merge changes from topic "lshal_released" am: 757fd44b am: 880df0f7

am: 163a64a3

Change-Id: I25478f2bcb117ce916e83ae51f4ef0dabc87b72e
parents f07ca338 163a64a3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ cc_library_shared {
    ],
    srcs: [
        "DebugCommand.cpp",
        "HelpCommand.cpp",
        "Lshal.cpp",
        "ListCommand.cpp",
        "PipeRelay.cpp",

cmds/lshal/Command.h

0 → 100644
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FRAMEWORK_NATIVE_CMDS_LSHAL_COMMAND_H_
#define FRAMEWORK_NATIVE_CMDS_LSHAL_COMMAND_H_

#include "utils.h"

namespace android {
namespace lshal {

class Lshal;

// Base class for all *Commands
class Command {
public:
    Command(Lshal& lshal) : mLshal(lshal) {}
    virtual ~Command() = default;
    // Expect optind to be set by Lshal::main and points to the next argument
    // to process.
    virtual Status main(const Arg &arg) = 0;

    virtual void usage() const = 0;

    // e.g. "list"
    virtual std::string getName() const = 0;

    // e.g. "list HALs"
    virtual std::string getSimpleDescription() const = 0;

protected:
    Lshal& mLshal;
};


}  // namespace lshal
}  // namespace android

#endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_
+22 −5
Original line number Diff line number Diff line
@@ -21,12 +21,16 @@
namespace android {
namespace lshal {

DebugCommand::DebugCommand(Lshal &lshal) : mLshal(lshal) {
std::string DebugCommand::getName() const {
    return "debug";
}

Status DebugCommand::parseArgs(const std::string &command, const Arg &arg) {
std::string DebugCommand::getSimpleDescription() const {
    return "Debug a specified HAL.";
}

Status DebugCommand::parseArgs(const Arg &arg) {
    if (optind >= arg.argc) {
        mLshal.usage(command);
        return USAGE;
    }
    mInterfaceName = arg.argv[optind];
@@ -37,8 +41,8 @@ Status DebugCommand::parseArgs(const std::string &command, const Arg &arg) {
    return OK;
}

Status DebugCommand::main(const std::string &command, const Arg &arg) {
    Status status = parseArgs(command, arg);
Status DebugCommand::main(const Arg &arg) {
    Status status = parseArgs(arg);
    if (status != OK) {
        return status;
    }
@@ -49,6 +53,19 @@ Status DebugCommand::main(const std::string &command, const Arg &arg) {
            mLshal.err());
}

void DebugCommand::usage() const {

    static const std::string debug =
            "debug:\n"
            "    lshal debug <interface> [options [options [...]]] \n"
            "        Print debug information of a specified interface.\n"
            "        <inteface>: Format is `android.hardware.foo@1.0::IFoo/default`.\n"
            "            If instance name is missing `default` is used.\n"
            "        options: space separated options to IBase::debug.\n";

    mLshal.err() << debug;
}

}  // namespace lshal
}  // namespace android
+9 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include <android-base/macros.h>

#include "Command.h"
#include "utils.h"

namespace android {
@@ -28,14 +29,17 @@ namespace lshal {

class Lshal;

class DebugCommand {
class DebugCommand : public Command {
public:
    DebugCommand(Lshal &lshal);
    Status main(const std::string &command, const Arg &arg);
    DebugCommand(Lshal &lshal) : Command(lshal) {}
    ~DebugCommand() = default;
    Status main(const Arg &arg) override;
    void usage() const override;
    std::string getSimpleDescription() const override;
    std::string getName() const override;
private:
    Status parseArgs(const std::string &command, const Arg &arg);
    Status parseArgs(const Arg &arg);

    Lshal &mLshal;
    std::string mInterfaceName;
    std::vector<std::string> mOptions;

+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "HelpCommand.h"

#include "Lshal.h"

namespace android {
namespace lshal {

std::string HelpCommand::GetName() {
    return "help";
}

std::string HelpCommand::getSimpleDescription() const {
    return "Print help message.";
}

Status HelpCommand::main(const Arg &arg) {
    if (optind >= arg.argc) {
        // `lshal help` prints global usage.
        mLshal.usage();
        return OK;
    }
    (void)usageOfCommand(arg.argv[optind]);
    return OK;
}

Status HelpCommand::usageOfCommand(const std::string& c) const {
    if (c.empty()) {
        mLshal.usage();
        return USAGE;
    }
    auto command = mLshal.selectCommand(c);
    if (command == nullptr) {
        // from HelpCommand::main, `lshal help unknown`
        mLshal.usage();
        return USAGE;
    }

    command->usage();
    return USAGE;

}

void HelpCommand::usage() const {
    mLshal.err()
            << "help:" << std::endl
            << "    lshal -h" << std::endl
            << "    lshal --help" << std::endl
            << "    lshal help" << std::endl
            << "        Print this help message" << std::endl;
    mLshal.forEachCommand([&](const Command* e) {
        mLshal.err() << "    lshal help " << e->getName() << std::endl
                     << "        Print help message for " << e->getName() << std::endl;
    });

}

}  // namespace lshal
}  // namespace android
Loading