• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 #ifndef HDC_JDWP_SIMULATOR
17 #define HDC_JDWP_SIMULATOR
18 #include "define.h"
19 class HdcJdwpSimulator;
20 
21 class HdcJdwpSimulator {
22 public:
23     explicit HdcJdwpSimulator(uv_loop_t *loopIn, string pkg);
24     ~HdcJdwpSimulator();
25     bool Connect();
26     void stop();
27     uv_loop_t *loop;
28 
29 protected:
30     struct ContextJdwpSimulator {
31         uv_pipe_t pipe;
32         uv_tcp_t newFd;
33         bool hasNewFd;
34         HdcJdwpSimulator *thisClass;
35     };
36     using HCtxJdwpSimulator = struct ContextJdwpSimulator *;
37 
38 private:
39     struct JsMsgHeader {
40         uint32_t msgLen;
41         uint32_t pid;
42     };
43     void *MallocContext();
44     void FreeContext();
45     static void ConnectJdwp(uv_connect_t *connection, int status);
46     static void FinishWriteCallback(uv_write_t *req, int status);
47 #ifndef JS_JDWP_CONNECT
48     static void ReceiveNewFd(uv_stream_t *q, ssize_t nread, const uv_buf_t *buf);
49     static void ProcessIncoming(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf);
50 #endif // JS_JDWP_CONNECT
51     static void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
52     static RetErrCode SendToStream(uv_stream_t *handleStream, const uint8_t *buf, const int bufLen,
53                                    const void *finishCallback);
54     HCtxJdwpSimulator ctxPoint;
55     bool exit = false;
56     string pkgName;
57 };
58 #endif
59