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 uint16_t GetTCPListenPort(); 29 void Stop(); 30 31 protected: 32 private: 33 static void AcceptClient(uv_stream_t *server, int status); 34 void SetTCPListen(); 35 int ReadChannel(HChannel hChannel, uint8_t *bufPtr, const int bytesIO); 36 bool DoCommand(HChannel hChannel, void *formatCommandInput); 37 void OrderFindTargets(HChannel hChannel); 38 bool NewConnectTry(void *ptrServer, HChannel hChannel, const string &connectKey); 39 static void OrderConnecTargetResult(uv_timer_t *req); 40 bool SendToDaemon(HChannel hChannel, const uint16_t commandFlag, uint8_t *bufPtr, const int bufSize); 41 int BindChannelToSession(HChannel hChannel, uint8_t *bufPtr, const int bytesIO); 42 bool CheckAutoFillTarget(HChannel hChannel); 43 bool CommandRemoveSession(HChannel hChannel, const char *connectKey); 44 bool CommandRemoveForward(const string &forwardKey); 45 bool DoCommandLocal(HChannel hChannel, void *formatCommandInput); 46 bool DoCommandRemote(HChannel hChannel, void *formatCommandInput); 47 void GetTargetList(HChannel hChannel, void *formatCommandInput); 48 bool GetAnyTarget(HChannel hChannel); 49 bool RemoveForward(HChannel hChannel, const char *parameterString); 50 bool TaskCommand(HChannel hChannel, void *formatCommandInput); 51 int ChannelHandShake(HChannel hChannel, uint8_t *bufPtr, const int bytesIO); 52 bool ChannelSendSessionCtrlMsg(vector<uint8_t> &ctrlMsg, uint32_t sessionId); 53 HSession FindAliveSession(uint32_t sessionId); 54 HSession FindAliveSessionFromDaemonMap(const HChannel hChannel); 55 56 uv_tcp_t tcpListen; 57 void *clsServer; 58 }; 59 } // namespace Hdc 60 #endif