• 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_CLIENT_H
16 #define HDC_CLIENT_H
17 #include "host_common.h"
18 
19 namespace Hdc {
20 class HdcClient : public HdcChannelBase {
21 public:
22     HdcClient(const bool serverOrClient, const string &addrString, uv_loop_t *loopMainIn);
23     virtual ~HdcClient();
24     int Initial(const string &connectKeyIn);
25     int ExecuteCommand(const string &commandIn);
26     int CtrlServiceWork(const char *commandIn);
27 
28 protected:
29 private:
30     static void DoCtrlServiceWork(uv_check_t *handle);
31     static void Connect(uv_connect_t *connection, int status);
32     static void AllocStdbuf(uv_handle_t *handle, size_t sizeWanted, uv_buf_t *buf);
33     static void ReadStd(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
34     static void CommandWorker(uv_timer_t *handle);
35     int ConnectServerForClient(const char *ip, uint16_t port);
36     int ReadChannel(HChannel hChannel, uint8_t *buf, const int bytesIO);
37     int PreHandshake(HChannel hChannel, const uint8_t *buf);
38     string AutoConnectKey(string &doCommand, const string &preConnectKey) const;
39     uint32_t GetLastPID();
40     bool StartKillServer(const char *cmd, bool startOrKill);
41     void BindLocalStd();
42     void BindLocalStd(HChannel hChannel);
43     void ModifyTty(bool setOrRestore, uv_tty_t *tty);
44     void NotifyInstanceChannelFree(HChannel hChannel);
45 
46 #ifndef _WIN32
47     termios terminalState;
48 #endif
49     string connectKey;
50     string command;
51     uint16_t debugRetryCount;
52     bool bShellInteractive = false;
53     uv_timer_t waitTimeDoCmd;
54     uv_check_t ctrlServerWork;
55     HChannel channel;
56 };
57 }  // namespace Hdc
58 #endif