lttng: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / relayd / lttngviewerCommands / TracePacketResponse.java
1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation and API
11 * Marc-Andre Laperle - Initial implementation and API
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
15
16 import java.io.DataInputStream;
17 import java.io.IOException;
18 import java.nio.ByteBuffer;
19 import java.nio.ByteOrder;
20
21 /**
22 * Response to getpacket command
23 *
24 * @author Matthew Khouzam
25 * @since 3.0
26 */
27 public class TracePacketResponse implements IRelayResponse {
28
29 /**
30 * Command size
31 *
32 * fStatus + fData.length + fFlags
33 */
34 private static final int SIZE = (Integer.SIZE + Integer.SIZE + Integer.SIZE) / 8;
35 /** Enum lttng_viewer_get_packet_return_code */
36 private final GetPacketReturnCode fStatus;
37 /** flags: is there new metadata or new streams? */
38 private final int fFlags;
39 /** the packet */
40 private final byte[] fData;
41
42 /**
43 * Trace packet response network constructor
44 *
45 * @param inNet
46 * network input stream
47 * @throws IOException
48 * network error
49 */
50 public TracePacketResponse(DataInputStream inNet) throws IOException {
51 byte[] data = new byte[SIZE];
52 inNet.readFully(data);
53 ByteBuffer bb = ByteBuffer.wrap(data);
54 bb.order(ByteOrder.BIG_ENDIAN);
55 fStatus = GetPacketReturnCode.values()[bb.getInt() - 1];
56 int length = bb.getInt();
57 fFlags = bb.getInt();
58 if (fStatus.equals(GetPacketReturnCode.VIEWER_GET_PACKET_OK)) {
59 fData = new byte[length];
60 inNet.readFully(fData);
61 } else {
62 fData = new byte[0];
63 }
64 }
65
66 /**
67 * Get the status
68 *
69 * @return the Status
70 */
71 public GetPacketReturnCode getStatus() {
72 return fStatus;
73 }
74
75 /**
76 * Get the flags
77 *
78 * @return the Flags
79 */
80 public int getFlags() {
81 return fFlags;
82 }
83
84 /**
85 * Get the packet data, please do not modify the data
86 *
87 * @return the Data
88 */
89 public byte[] getData() {
90 return fData;
91 }
92
93 }
This page took 0.066958 seconds and 5 git commands to generate.