1/*
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#ifndef JDWP_OUTSTREAM_H
27#define JDWP_OUTSTREAM_H
28
29#include "transport.h"
30#include "FrameID.h"
31
32struct bag;
33
34#define INITIAL_SEGMENT_SIZE   300
35#define MAX_SEGMENT_SIZE     10000
36
37typedef struct PacketData {
38    int length;
39    jbyte *data;
40    struct PacketData *next;
41} PacketData;
42
43typedef struct PacketOutputStream {
44    jbyte *current;
45    jint left;
46    struct PacketData *segment;
47    struct PacketData firstSegment;
48    jvmtiError error;
49    jboolean sent;
50    jdwpPacket packet;
51    jbyte initialSegment[INITIAL_SEGMENT_SIZE];
52    struct bag *ids;
53} PacketOutputStream;
54
55void outStream_initCommand(PacketOutputStream *stream, jint id,
56                           jbyte flags, jbyte commandSet, jbyte command);
57void outStream_initReply(PacketOutputStream *stream, jint id);
58
59jint outStream_id(PacketOutputStream *stream);
60jbyte outStream_command(PacketOutputStream *stream);
61
62jdwpError outStream_writeBoolean(PacketOutputStream *stream, jboolean val);
63jdwpError outStream_writeByte(PacketOutputStream *stream, jbyte val);
64jdwpError outStream_writeChar(PacketOutputStream *stream, jchar val);
65jdwpError outStream_writeShort(PacketOutputStream *stream, jshort val);
66jdwpError outStream_writeInt(PacketOutputStream *stream, jint val);
67jdwpError outStream_writeLong(PacketOutputStream *stream, jlong val);
68jdwpError outStream_writeFloat(PacketOutputStream *stream, jfloat val);
69jdwpError outStream_writeDouble(PacketOutputStream *stream, jdouble val);
70jdwpError outStream_writeModuleRef(JNIEnv *env, PacketOutputStream *stream, jobject val);
71jdwpError outStream_writeObjectRef(JNIEnv *env, PacketOutputStream *stream, jobject val);
72jdwpError outStream_writeObjectTag(JNIEnv *env, PacketOutputStream *stream, jobject val);
73jdwpError outStream_writeFrameID(PacketOutputStream *stream, FrameID val);
74jdwpError outStream_writeMethodID(PacketOutputStream *stream, jmethodID val);
75jdwpError outStream_writeFieldID(PacketOutputStream *stream, jfieldID val);
76jdwpError outStream_writeLocation(PacketOutputStream *stream, jlocation val);
77jdwpError outStream_writeByteArray(PacketOutputStream*stream, jint length, jbyte *bytes);
78jdwpError outStream_writeString(PacketOutputStream *stream, char *string);
79jdwpError outStream_writeValue(JNIEnv *env, struct PacketOutputStream *out,
80                          jbyte typeKey, jvalue value);
81jdwpError outStream_skipBytes(PacketOutputStream *stream, jint count);
82
83jdwpError outStream_error(PacketOutputStream *stream);
84void outStream_setError(PacketOutputStream *stream, jdwpError error);
85
86void outStream_sendReply(PacketOutputStream *stream);
87void outStream_sendCommand(PacketOutputStream *stream);
88
89void outStream_destroy(PacketOutputStream *stream);
90
91#endif
92