lttng: Add Lttng relayd connector
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / relayd / lttngviewerCommands / AttachSessionResponse.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 import java.util.List;
21
22 import com.google.common.collect.ImmutableList;
23 import com.google.common.collect.ImmutableList.Builder;
24
25 /**
26 * Attach session response
27 *
28 * @author Matthew Khouzam
29 * @since 3.0
30 */
31 public class AttachSessionResponse implements IRelayResponse {
32
33 /* enum + stream count, first half of a packet */
34 private static final int SIZE = (Integer.SIZE + Integer.SIZE) / 8;
35 /** enum lttng_viewer_attach_return_code */
36 private final AttachReturnCode fStatus;
37 /** how many streams are there */
38 private final int fStreamsCount;
39 /** public class lttng_viewer_stream */
40 private final List<StreamResponse> fStreamList;
41
42 /**
43 * Attach session response network constructor
44 *
45 * @param inNet
46 * network input stream
47 * @throws IOException
48 * network error
49 */
50 public AttachSessionResponse(DataInputStream inNet) throws IOException {
51 byte[] data = new byte[SIZE];
52 inNet.readFully(data, 0, SIZE);
53 ByteBuffer bb = ByteBuffer.wrap(data);
54 bb.order(ByteOrder.BIG_ENDIAN);
55 fStatus = AttachReturnCode.values()[bb.getInt() - 1];
56 fStreamsCount = bb.getInt();
57 Builder<StreamResponse> streamResponses = ImmutableList.builder();
58 for (int i = 0; i < getNbStreams(); i++) {
59 streamResponses.add(new StreamResponse(inNet));
60 }
61 fStreamList = streamResponses.build();
62
63 }
64
65 /**
66 * Gets the Status
67 *
68 * @return the Status
69 */
70 public AttachReturnCode getStatus() {
71 return fStatus;
72 }
73
74 /**
75 * Gets the StreamsCount
76 *
77 * @return the StreamsCount
78 */
79 public int getNbStreams() {
80 return fStreamsCount;
81 }
82
83 /**
84 * Gets the StreamList
85 *
86 * @return the StreamList
87 */
88 public List<StreamResponse> getStreamList() {
89 return fStreamList;
90 }
91
92 }
This page took 0.047677 seconds and 6 git commands to generate.