• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int ChildForkDo(int pts, const char *cmd, const char *arg0, const char *arg1);
34     bool SpecialSignal(uint8_t ch);
35     int ShellFork(const char *cmd, const char *arg0, const char *arg1);
36 
37     HdcFileDescriptor *childShell;
38     pid_t pidShell = 0;
39     int fdPTY;
40     int ptm = 0;
41     const string devPTMX = "/dev/ptmx";
42     static std::mutex mutexPty;
43     char devname[BUF_SIZE_SMALL] = "";
44 };
45 }  // namespace Hdc
46 #endif