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_SERVERFORCLIENT_H 16 #define HDC_SERVERFORCLIENT_H 17 #include "host_common.h" 18 #include "translate.h" 19 20 namespace Hdc { 21 class HdcServerForClient : public HdcChannelBase { 22 public: 23 HdcServerForClient(const bool serverOrClient, const string &addrString, void *pClsServer, uv_loop_t *loopMainIn); 24 virtual ~HdcServerForClient(); 25 int Initial(); 26 void EchoClient(HChannel hChannel, MessageLevel level, const char *msg, ...); 27 void EchoClientRaw(const HChannel hChannel, uint8_t *payload, const int payloadSize); 28 void SendCommandToClient(const HChannel hChannel, const uint16_t commandFlag, uint8_t *payload, 29 const int payloadSize); 30 uint16_t GetTCPListenPort(); 31 void Stop(); 32 33 protected: 34 private: 35 static void AcceptClient(uv_stream_t *server, int status); 36 bool SetTCPListen(); 37 int ReadChannel(HChannel hChannel, uint8_t *bufPtr, const int bytesIO) override; 38 void ReportServerVersion(HChannel hChannel); 39 bool DoCommand(HChannel hChannel, void *formatCommandInput); 40 void OrderFindTargets(HChannel hChannel); 41 bool NewConnectTry(void *ptrServer, HChannel hChannel, const string &connectKey, bool isCheck = false); 42 static void OrderConnecTargetResult(uv_timer_t *req); 43 bool SendToDaemon(HChannel hChannel, const uint16_t commandFlag, uint8_t *bufPtr, const int bufSize); 44 int BindChannelToSession(HChannel hChannel, uint8_t *bufPtr, const int bytesIO); 45 bool CheckAutoFillTarget(HChannel hChannel); 46 bool CommandRemoveSession(HChannel hChannel, const char *connectKey); 47 bool CommandRemoveForward(const string &forwardKey); 48 bool RemoveFportkey(const string &forwardKey); 49 bool DoCommandLocal(HChannel hChannel, void *formatCommandInput); 50 bool DoCommandRemote(HChannel hChannel, void *formatCommandInput); 51 void GetTargetList(HChannel hChannel, void *formatCommandInput); 52 bool GetAnyTarget(HChannel hChannel); 53 bool WaitForAny(HChannel hChannel); 54 bool RemoveForward(HChannel hChannel, const char *parameterString); 55 bool TaskCommand(HChannel hChannel, void *formatCommandInput); 56 void HandleRemote(HChannel hChannel, string ¶meters, RemoteType flag); 57 int ChannelHandShake(HChannel hChannel, uint8_t *bufPtr, const int bytesIO); 58 bool ChannelSendSessionCtrlMsg(vector<uint8_t> &ctrlMsg, uint32_t sessionId) override; 59 HSession FindAliveSession(uint32_t sessionId); 60 HSession FindAliveSessionFromDaemonMap(const HChannel hChannel); 61 62 uv_tcp_t tcpListen; 63 void *clsServer; 64 }; 65 } // namespace Hdc 66 #endif 67