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_DAEMON_H 16 #define HDC_DAEMON_H 17 #include "daemon_common.h" 18 19 namespace Hdc { 20 class HdcDaemon : public HdcSessionBase { 21 public: 22 #ifdef USE_CONFIG_UV_THREADS 23 HdcDaemon(bool serverOrDaemonIn, size_t uvThreadSize = SIZE_THREAD_POOL); 24 #else 25 HdcDaemon(bool serverOrDaemonIn); 26 #endif 27 virtual ~HdcDaemon(); 28 #ifdef HDC_SUPPORT_UART 29 void InitMod(bool bEnableTCP, bool bEnableUSB, bool bEnableUART); 30 #else 31 void InitMod(bool bEnableTCP, bool bEnableUSB); 32 #endif 33 bool FetchCommand(HSession hSession, const uint32_t channelId, const uint16_t command, uint8_t *payload, 34 const int payloadSize) override; 35 bool ServerCommand(const uint32_t sessionId, const uint32_t channelId, const uint16_t command, uint8_t *bufPtr, 36 const int size) override; 37 void *clsTCPServ; 38 void *clsUSBServ; 39 #ifdef HDC_SUPPORT_UART 40 void *clsUARTServ; 41 #endif 42 void *clsJdwp; 43 44 private: 45 bool RemoveInstanceTask(const uint8_t op, HTaskInfo hTask) override; 46 bool RedirectToTask(HTaskInfo hTaskInfo, HSession hSession, const uint32_t channelId, const uint16_t command, 47 uint8_t *payload, const int payloadSize) override; 48 void JdwpNewFileDescriptor(const uint8_t *buf, const int bytesIO) override; 49 static bool CheckControl(const uint16_t command); 50 static bool IsExpectedParam(const std::string& param, const std::string& expect); 51 bool HandDaemonAuth(HSession hSession, const uint32_t channelId, SessionHandShake &handshake); 52 void ClearInstanceResource() override; 53 bool DaemonSessionHandshake(HSession hSession, const uint32_t channelId, uint8_t *payload, int payloadSize); 54 void TryStopInstance(); 55 // deprecated, remove later 56 #ifdef HDC_SUPPORT_FLASHD 57 // null 58 #else 59 void NotifyInstanceSessionFree(HSession hSession, bool freeOrClear) override; 60 #endif 61 62 bool enableSecure; 63 }; 64 } // namespace Hdc 65 #endif 66