Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | /* |
| 17 | * JDWP internal interfaces. |
| 18 | */ |
| 19 | #ifndef ART_JDWP_JDWPPRIV_H_ |
| 20 | #define ART_JDWP_JDWPPRIV_H_ |
| 21 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 22 | #include "debugger.h" |
| 23 | #include "jdwp/jdwp.h" |
| 24 | #include "jdwp/jdwp_event.h" |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 25 | |
| 26 | #include <pthread.h> |
| 27 | #include <sys/uio.h> |
| 28 | |
| 29 | /* |
| 30 | * JDWP constants. |
| 31 | */ |
| 32 | #define kJDWPHeaderLen 11 |
| 33 | #define kJDWPFlagReply 0x80 |
| 34 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 35 | #define kMagicHandshake "JDWP-Handshake" |
| 36 | #define kMagicHandshakeLen (sizeof(kMagicHandshake)-1) |
| 37 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 38 | /* DDM support */ |
| 39 | #define kJDWPDdmCmdSet 199 /* 0xc7, or 'G'+128 */ |
| 40 | #define kJDWPDdmCmd 1 |
| 41 | |
| 42 | namespace art { |
| 43 | |
| 44 | namespace JDWP { |
| 45 | |
| 46 | /* |
| 47 | * Transport-specific network status. |
| 48 | */ |
| 49 | struct JdwpNetState; |
| 50 | struct JdwpState; |
| 51 | |
| 52 | /* |
| 53 | * Transport functions. |
| 54 | */ |
| 55 | struct JdwpTransport { |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 56 | bool (*startup)(JdwpState* state, const JdwpOptions* options); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 57 | bool (*accept)(JdwpState* state); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame^] | 58 | bool (*establish)(JdwpState* state, const JdwpOptions* options); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 59 | void (*close)(JdwpState* state); |
| 60 | void (*shutdown)(JdwpState* state); |
| 61 | void (*free)(JdwpState* state); |
| 62 | bool (*isConnected)(JdwpState* state); |
| 63 | bool (*awaitingHandshake)(JdwpState* state); |
| 64 | bool (*processIncoming)(JdwpState* state); |
| 65 | bool (*sendRequest)(JdwpState* state, ExpandBuf* pReq); |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 66 | bool (*sendBufferedRequest)(JdwpState* state, const iovec* iov, int iov_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | const JdwpTransport* SocketTransport(); |
| 70 | const JdwpTransport* AndroidAdbTransport(); |
| 71 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Base class for JdwpNetState |
| 74 | */ |
| 75 | class JdwpNetStateBase { |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 76 | public: |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 77 | int clientSock; /* active connection to debugger */ |
| 78 | |
| 79 | JdwpNetStateBase(); |
| 80 | ssize_t writePacket(ExpandBuf* pReply); |
Elliott Hughes | cccd84f | 2011-12-05 16:51:54 -0800 | [diff] [blame] | 81 | ssize_t writeBufferedPacket(const iovec* iov, int iov_count); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 82 | |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 83 | private: |
| 84 | // Used to serialize writes to the socket. |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 85 | Mutex socket_lock_; |
| 86 | }; |
| 87 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 88 | } // namespace JDWP |
| 89 | |
| 90 | } // namespace art |
| 91 | |
| 92 | #endif // ART_JDWP_JDWPPRIV_H_ |