gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / relayd / lttngviewerCommands / ConnectResponse.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 * CONNECT payload.
23 *
24 * @author Matthew Khouzam
25 * @since 3.0
26 */
27 public class ConnectResponse implements IRelayResponse, IRelayCommand {
28
29 /**
30 * Response or command size
31 *
32 * fViewerSessionId + fMajor + fMinor + fType
33 */
34 public static final int SIZE = (Long.SIZE + Integer.SIZE + Integer.SIZE + Integer.SIZE) / 8;
35 /** session id, counts from 1 and increments by session */
36 private final long fViewerSessionId;
37 /**
38 * Major version, hint, it's at least 2
39 */
40 private final int fMajor;
41 /**
42 * Minor version, hint, it's at least 4
43 */
44 private final int fMinor;
45 /**
46 * type of connect to {@link ConnectionType}
47 */
48 private final ConnectionType fType;
49
50 /**
51 * Connection response reply constructor
52 *
53 * @param inStream
54 * the data input stream
55 * @throws IOException
56 * a network error
57 */
58 public ConnectResponse(DataInputStream inStream) throws IOException {
59 byte data[] = new byte[SIZE];
60 inStream.readFully(data);
61 ByteBuffer bb = ByteBuffer.wrap(data);
62 bb.order(ByteOrder.BIG_ENDIAN);
63 fViewerSessionId = bb.getLong();
64 fMajor = bb.getInt();
65 fMinor = bb.getInt();
66 bb.getInt(); // Should not be used, see http://bugs.lttng.org/issues/728
67 fType = ConnectionType.VIEWER_CLIENT_COMMAND;
68 }
69
70 /**
71 * Constructor for command
72 *
73 * @param sessionID
74 * session id
75 * @param major
76 * the major version
77 * @param minor
78 * the minor version
79 * @param connection
80 * the connection type, typically VIEWER_CLIENT_COMMAND
81 */
82 public ConnectResponse(long sessionID, int major, int minor, ConnectionType connection) {
83 fViewerSessionId = sessionID;
84 fMajor = major;
85 fMinor = minor;
86 fType = connection;
87 }
88
89 /**
90 * get the major version
91 *
92 * @return the major version
93 */
94 public int getMajor() {
95 return fMajor;
96 }
97
98 /**
99 * get the minor version
100 *
101 * @return the minor version
102 */
103 public int getMinor() {
104 return fMinor;
105 }
106
107 @Override
108 public byte[] serialize() {
109 byte data[] = new byte[SIZE];
110 ByteBuffer bb = ByteBuffer.wrap(data);
111 bb.order(ByteOrder.BIG_ENDIAN);
112 bb.putLong(fViewerSessionId);
113 bb.putInt(fMajor);
114 bb.putInt(fMinor);
115 bb.putInt(fType.getCommand());
116 return data;
117 }
118
119 }
This page took 0.063828 seconds and 5 git commands to generate.