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 22namespace Hdc { 23const char PERSIST_HDC_JDWP[] = "persist.hdc.jdwp"; 24class HdcJdwpSimulator; 25 26class HdcJdwpSimulator { 27public: 28 explicit HdcJdwpSimulator(std::string processName, std::string pkgName, bool isDebug, Callback cb); 29 ~HdcJdwpSimulator(); 30 bool Connect(); 31 void Disconnect(); 32 33private: 34 struct JsMsgHeader { 35 uint32_t msgLen; 36 uint32_t pid; 37 uint8_t isDebug; // 1:debug 0:release 38 }; 39 40 std::string processName_; 41 std::string pkgName_; 42 bool isDebug_; 43 Callback cb_; 44 int cfd_; 45 std::atomic<bool> disconnectFlag_; 46 std::atomic<bool> notified_; 47 std::mutex mutex_; 48 std::condition_variable cv_; 49 50 void AddWatchHdcdJdwp(); 51 void DelWatchHdcdJdwp(); 52 void WaitForJdwp(); 53 bool SendBuf(const uint8_t *buf, const int bufLen); 54 bool Connect2Jdwp(); 55 bool Send2Jdwp(); 56 void ReadFromJdwp(); 57}; 58} // namespace Hdc 59#endif // REGISTER_HDC_JDWP_H 60