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

Commit ded398e5 authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: Add class Command.

Command is the base class for all *Command classes.

Test: lshal_test

Bug: 35389839
Change-Id: I9aca19e66824536d13e618ffd0f012ac3da9880d
parent 91e655dc
Loading
Loading
Loading
Loading

cmds/lshal/Command.h

0 → 100644
+44 −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 std::string &command, const Arg &arg) = 0;

protected:
    Lshal& mLshal;
};


}  // namespace lshal
}  // namespace android

#endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_
+0 −3
Original line number Diff line number Diff line
@@ -21,9 +21,6 @@
namespace android {
namespace lshal {

DebugCommand::DebugCommand(Lshal &lshal) : mLshal(lshal) {
}

Status DebugCommand::parseArgs(const std::string &command, const Arg &arg) {
    if (optind >= arg.argc) {
        mLshal.usage(command);
+5 −4
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,14 @@ 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 std::string &command, const Arg &arg) override;
private:
    Status parseArgs(const std::string &command, const Arg &arg);

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

+0 −3
Original line number Diff line number Diff line
@@ -44,9 +44,6 @@ using ::android::hidl::manager::V1_0::IServiceManager;
namespace android {
namespace lshal {

ListCommand::ListCommand(Lshal &lshal) : mLshal(lshal) {
}

NullableOStream<std::ostream> ListCommand::out() const {
    return mLshal.out();
}
+4 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <android-base/macros.h>
#include <android/hidl/manager/1.0/IServiceManager.h>

#include "Command.h"
#include "NullableOStream.h"
#include "TableEntry.h"
#include "TextTable.h"
@@ -42,11 +43,11 @@ struct PidInfo {
    uint32_t threadCount; // number of threads total
};

class ListCommand {
class ListCommand : public Command {
public:
    ListCommand(Lshal &lshal);
    ListCommand(Lshal &lshal) : Command(lshal) {}
    virtual ~ListCommand() = default;
    Status main(const std::string &command, const Arg &arg);
    Status main(const std::string &command, const Arg &arg) override;
protected:
    Status parseArgs(const std::string &command, const Arg &arg);
    Status fetch();
@@ -79,8 +80,6 @@ protected:
    NullableOStream<std::ostream> err() const;
    NullableOStream<std::ostream> out() const;

    Lshal &mLshal;

    Table mServicesTable{};
    Table mPassthroughRefTable{};
    Table mImplementationsTable{};
Loading