Home | History | Annotate | Download | only in lshal
      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 #ifndef FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_
     18 #define FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_
     19 
     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 "HelpCommand.h"
     29 #include "NullableOStream.h"
     30 #include "utils.h"
     31 
     32 namespace android {
     33 namespace lshal {
     34 
     35 class Lshal {
     36 public:
     37     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             bool excludesParentInstances,
     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 private:
     63     Status parseArgs(const Arg &arg);
     64 
     65     std::string mCommand;
     66     NullableOStream<std::ostream> mOut;
     67     NullableOStream<std::ostream> mErr;
     68 
     69     sp<hidl::manager::V1_0::IServiceManager> mServiceManager;
     70     sp<hidl::manager::V1_0::IServiceManager> mPassthroughManager;
     71 
     72     std::vector<std::unique_ptr<Command>> mRegisteredCommands;
     73 
     74     DISALLOW_COPY_AND_ASSIGN(Lshal);
     75 };
     76 
     77 }  // namespace lshal
     78 }  // namespace android
     79 
     80 #endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_
     81