ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.core / src / org / eclipse / tracecompass / internal / lttng2 / control / core / relayd / commands / NewStreamsResponse.java
CommitLineData
8e15b929
MK
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
41b4bff4 14package org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands;
8e15b929
MK
15
16import java.io.DataInputStream;
17import java.io.IOException;
18import java.nio.ByteBuffer;
19import java.nio.ByteOrder;
20import java.util.List;
21
22import com.google.common.collect.ImmutableList;
23
24/**
25 * Response to a "new streams" command
26 *
27 * @author Matthew Khouzam
8e15b929
MK
28 */
29public class NewStreamsResponse implements IRelayResponse {
30
8adfbb73
MAL
31 /**
32 * Response size
33 *
34 * fStatus + fNbStreams
35 */
8e15b929
MK
36 private static final int SIZE = (Integer.SIZE + Integer.SIZE) / 8;
37 /** status of the request */
38 private final NewStreamsReturnCode fStatus;
39 /** the number of streams */
40 private final int fNbStreams;
41 /** the list of streams in the response */
42 private final List<StreamResponse> fStreamList;
43
44 /**
45 * New stream response network constructor
46 *
47 * @param inNet
48 * network stream
49 * @throws IOException
50 * network error
51 */
52 public NewStreamsResponse(DataInputStream inNet) throws IOException {
53 byte[] data = new byte[SIZE];
54 inNet.readFully(data);
55 ByteBuffer bb = ByteBuffer.wrap(data);
56 bb.order(ByteOrder.BIG_ENDIAN);
57 fStatus = NewStreamsReturnCode.values()[bb.getInt() - 1];
58 fNbStreams = bb.getInt();
59 ImmutableList.Builder<StreamResponse> sl = new ImmutableList.Builder<>();
60 if (getStatus().equals(NewStreamsReturnCode.LTTNG_VIEWER_NEW_STREAMS_OK)) {
61 for (int stream = 0; stream < fNbStreams; stream++) {
62 sl.add(new StreamResponse(inNet));
63 }
64 }
65 fStreamList = sl.build();
66 }
67
68 /**
69 * Gets the status
70 *
71 * @return the status
72 */
73 public NewStreamsReturnCode getStatus() {
74 return fStatus;
75 }
76
77 /**
78 * gets the stream list
79 *
80 * @return the stream list
81 */
82 public List<StreamResponse> getStreamList() {
83 return fStreamList;
84 }
85
86 /**
87 * The number of streams
88 *
89 * @return the number of streams
90 */
91 public int getNbStreams() {
92 return fNbStreams;
93 }
94
95}
This page took 0.051899 seconds and 5 git commands to generate.