1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HDC_SHELL_H 16 #define HDC_SHELL_H 17 #include "task.h" 18 19 namespace Hdc { 20 class HdcShell : public HdcTaskBase { 21 public: 22 HdcShell(HTaskInfo hTaskInfo); 23 virtual ~HdcShell(); 24 bool CommandDispatch(const uint16_t command, uint8_t *payload, const int payloadSize) override; 25 void StopTask() override; 26 bool ReadyForRelease() override; 27 28 private: 29 static bool FinishShellProc(const void *context, const bool result, const string exitMsg); 30 static bool ChildReadCallback(const void *context, uint8_t *buf, const int size); 31 int StartShell(); 32 int CreateSubProcessPTY(const char *cmd, const char *arg0, const char *arg1, pid_t *pid); 33 static int ChildForkDo(int pts, const char *cmd, const char *arg0, const char *arg1); 34 bool SpecialSignal(uint8_t ch); 35 int ThreadFork(const char *cmd, const char *arg0, const char *arg1); 36 static void *ShellFork(void *arg); 37 38 HdcFileDescriptor *childShell; 39 pid_t pidShell = 0; 40 int fdPTY; 41 int ptm = 0; 42 const string devPTMX = "/dev/ptmx"; 43 static std::mutex mutexPty; 44 char devname[BUF_SIZE_SMALL] = ""; 45 }; 46 47 struct ShellParams { 48 const char *cmdParam; 49 const char *arg0Param; 50 const char *arg1Param; 51 int ptmParam; 52 char *devParam; 53 ShellParamsShellParams54 ShellParams(const char *cmdParam, const char *arg0Param, const char *arg1Param, int ptmParam, char *devParam) 55 :cmdParam(cmdParam), arg0Param(arg0Param), arg1Param(arg1Param), ptmParam(ptmParam), devParam(devParam) {}; 56 }; 57 } // namespace Hdc 58 #endif