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_SERVER_H 16 #define HDC_SERVER_H 17 #include "host_common.h" 18 19 namespace Hdc { 20 class HdcServer : public HdcSessionBase { 21 public: 22 HdcServer(bool serverOrDaemonIn); 23 virtual ~HdcServer(); 24 bool FetchCommand(HSession hSession, const uint32_t channelId, const uint16_t command, uint8_t *payload, 25 const int payloadSize) override; 26 virtual string AdminDaemonMap(uint8_t opType, const string &connectKey, HDaemonInfo &hDaemonInfoInOut); 27 string AdminForwardMap(uint8_t opType, const string &taskString, HForwardInfo &hForwardInfoInOut); 28 void CleanForwardMap(uint32_t sessionId); 29 int CreateConnect(const string &connectKey, bool isCheck); 30 bool Initial(const char *listenString); 31 void AttachChannel(HSession hSession, const uint32_t channelId) override; 32 void DeatchChannel(HSession hSession, const uint32_t channelId) override; 33 virtual void EchoToClientsForSession(uint32_t targetSessionId, const string &echo); 34 static bool PullupServer(const char *listenString); 35 static void UsbPreConnect(uv_timer_t *handle); 36 void NotifyInstanceSessionFree(HSession hSession, bool freeOrClear) override; 37 38 HdcHostTCP *clsTCPClt; 39 HdcHostUSB *clsUSBClt; 40 #ifdef HDC_SUPPORT_UART 41 void CreatConnectUart(HSession hSession); 42 static void UartPreConnect(uv_timer_t *handle); 43 HdcHostUART *clsUARTClt = nullptr; 44 #endif 45 void *clsServerForClient; 46 47 private: 48 void ClearInstanceResource() override; 49 void BuildDaemonVisableLine(HDaemonInfo hdi, bool fullDisplay, string &out); 50 void BuildForwardVisableLine(bool fullOrSimble, HForwardInfo hfi, string &echo); 51 void ClearMapDaemonInfo(); 52 bool ServerCommand(const uint32_t sessionId, const uint32_t channelId, const uint16_t command, uint8_t *bufPtr, 53 const int size) override; 54 bool RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, const uint16_t command, 55 uint8_t *payload, const int payloadSize) override; 56 bool RemoveInstanceTask(const uint8_t op, HTaskInfo hTask) override; 57 void BuildForwardVisableLine(HDaemonInfo hdi, char *out, int sizeOutBuf); 58 bool HandServerAuth(HSession hSession, SessionHandShake &handshake); 59 string GetDaemonMapList(uint8_t opType); 60 void UpdateHdiInfo(Hdc::HdcSessionBase::SessionHandShake &handshake, const string &connectKey); 61 bool ServerSessionHandshake(HSession hSession, uint8_t *payload, int payloadSize); 62 void GetDaemonMapOnlyOne(HDaemonInfo &hDaemonInfoInOut); 63 void TryStopInstance(); 64 static bool PullupServerWin32(const char *path, const char *listenString); 65 66 uv_rwlock_t daemonAdmin; 67 map<string, HDaemonInfo> mapDaemon; 68 uv_rwlock_t forwardAdmin; 69 map<string, HForwardInfo> mapForward; 70 }; 71 } // namespace Hdc 72 #endif 73