1 /* 2 * Copyright (C) 2021-2022 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 */ 16 17 #ifndef REGISTER_HDC_JDWP_H 18 #define REGISTER_HDC_JDWP_H 19 20 #include "define_register.h" 21 22 namespace Hdc { 23 class HdcJdwpSimulator; 24 25 class HdcJdwpSimulator { 26 public: 27 explicit HdcJdwpSimulator(std::string processName, std::string pkgName, bool isDebug, Callback cb); 28 ~HdcJdwpSimulator(); 29 bool Connect(); 30 void Disconnect(); 31 32 protected: 33 struct ContextJdwpSimulator { 34 int cfd; 35 HdcJdwpSimulator *thisClass; 36 }; 37 using HCtxJdwpSimulator = struct ContextJdwpSimulator *; 38 39 private: 40 struct JsMsgHeader { 41 uint32_t msgLen; 42 uint32_t pid; 43 uint8_t isDebug; // 1:debug 0:release 44 }; 45 void *MallocContext(); 46 static bool ConnectJpid(HdcJdwpSimulator *param); 47 static bool SendToJpid(int fd, const uint8_t *buf, const int bufLen); 48 HCtxJdwpSimulator ctxPoint_; 49 std::string processName_; 50 std::string pkgName_; 51 bool isDebug_; 52 Callback cb_; 53 int cfd_; 54 std::atomic<bool> disconnectFlag_; 55 std::atomic<bool> startOnce_; 56 std::thread readThread_; 57 static void ReadWork(HdcJdwpSimulator *param); 58 void Read(); 59 void ReadStart(); 60 void Reconnect(); 61 }; 62 } // namespace Hdc 63 #endif // REGISTER_HDC_JDWP_H 64