Commit | Line | Data |
---|---|---|
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 | ||
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 | * Get response of viewer stream | |
23 | * | |
24 | * @author Matthew Khouzam | |
25 | * @since 3.0 | |
26 | */ | |
27 | public class StreamResponse implements IRelayResponse { | |
28 | ||
29 | /** | |
30 | * Response size | |
8adfbb73 MAL |
31 | * |
32 | * fId + fCtfTraceId + fMetadataFlag + fPathName + fChannelName | |
8e15b929 MK |
33 | */ |
34 | public static final int SIZE = (Long.SIZE + Long.SIZE + Integer.SIZE) / 8 + LttngViewerCommands.LTTNG_VIEWER_PATH_MAX + LttngViewerCommands.LTTNG_VIEWER_NAME_MAX; | |
35 | ||
36 | /** | |
37 | * id of the stream | |
38 | */ | |
39 | private final long fId; | |
40 | /** | |
41 | * It is guaranteed to be unique, because the value is assigned sequentially | |
42 | * by the relay. | |
43 | */ | |
44 | private final long fCtfTraceId; | |
45 | /** | |
46 | * if the stream is a metadata stream | |
47 | */ | |
48 | private final int fMetadataFlag; | |
49 | /** | |
50 | * the path | |
51 | */ | |
52 | private final String fPathName; | |
53 | /** | |
54 | * The channel, traditionally channel0 | |
55 | */ | |
56 | private final String fChannelName; | |
57 | ||
58 | /** | |
59 | * Stream response | |
60 | * | |
61 | * @param inNet | |
62 | * input data stream | |
63 | * @throws IOException | |
64 | * network time | |
65 | */ | |
66 | public StreamResponse(DataInputStream inNet) throws IOException { | |
67 | byte[] streamData = new byte[SIZE]; | |
68 | inNet.readFully(streamData, 0, SIZE); | |
69 | ByteBuffer bb = ByteBuffer.wrap(streamData); | |
70 | bb.order(ByteOrder.BIG_ENDIAN); | |
71 | fId = (bb.getLong()); | |
72 | fCtfTraceId = bb.getLong(); | |
73 | fMetadataFlag = bb.getInt(); | |
74 | byte pathName[] = new byte[LttngViewerCommands.LTTNG_VIEWER_PATH_MAX]; | |
75 | byte channelName[] = new byte[LttngViewerCommands.LTTNG_VIEWER_NAME_MAX]; | |
76 | bb.get(pathName, 0, LttngViewerCommands.LTTNG_VIEWER_PATH_MAX); | |
77 | bb.get(channelName, 0, LttngViewerCommands.LTTNG_VIEWER_NAME_MAX); | |
78 | fPathName = new String(pathName); | |
79 | fChannelName = new String(channelName); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Get the id | |
84 | * | |
85 | * @return the Id | |
86 | */ | |
87 | public long getId() { | |
88 | return fId; | |
89 | } | |
90 | ||
91 | /** | |
92 | * Get the CtfTraceId | |
93 | * | |
94 | * @return the CtfTraceId | |
95 | */ | |
96 | public long getCtfTraceId() { | |
97 | return fCtfTraceId; | |
98 | } | |
99 | ||
100 | /** | |
101 | * Get the metadata flag | |
102 | * | |
103 | * @return the MetadataFlag | |
104 | */ | |
105 | public int getMetadataFlag() { | |
106 | return fMetadataFlag; | |
107 | } | |
108 | ||
109 | /** | |
110 | * Get the path name | |
111 | * | |
112 | * @return the PathName | |
113 | */ | |
114 | public String getPathName() { | |
115 | return fPathName; | |
116 | } | |
117 | ||
118 | /** | |
119 | * get the Channel name | |
120 | * | |
121 | * @return the ChannelName | |
122 | */ | |
123 | public String getChannelName() { | |
124 | return fChannelName; | |
125 | } | |
126 | ||
127 | } |