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.nio.ByteBuffer; | |
17 | import java.nio.ByteOrder; | |
18 | ||
19 | /** | |
20 | * The LTTng command | |
21 | * | |
22 | * @author Matthew Khouzam | |
23 | * @since 3.0 | |
24 | */ | |
25 | public class ViewerCommand implements IRelayCommand { | |
26 | ||
27 | /** | |
28 | * Command size | |
8adfbb73 MAL |
29 | * |
30 | * fDataSize + fCmdVersion + fCmd | |
8e15b929 | 31 | */ |
8adfbb73 | 32 | public static final int SIZE = (Long.SIZE + Integer.SIZE) / 8 + Command.SIZE; |
8e15b929 MK |
33 | /** |
34 | * data size following this header, you normally attach a payload that one, | |
35 | * in bytes | |
36 | */ | |
37 | private final long fDataSize; | |
38 | /** enum lttcomm_relayd_command */ | |
39 | private final Command fCmd; | |
40 | /** command version */ | |
41 | private final int fCmdVersion; | |
42 | ||
43 | /** | |
44 | * Sets the packet command | |
45 | * | |
46 | * @param viewerConnect | |
47 | * the command | |
48 | * @param size size of the command | |
49 | * @param version the version number | |
50 | */ | |
51 | public ViewerCommand(Command viewerConnect, long size, int version) { | |
52 | fCmd = viewerConnect; | |
53 | fDataSize = size; | |
54 | fCmdVersion = version; | |
55 | } | |
56 | ||
57 | /** | |
58 | * Get the data size | |
59 | * | |
60 | * @return the DataSize | |
61 | */ | |
62 | public long getDataSize() { | |
63 | return fDataSize; | |
64 | } | |
65 | ||
66 | /** | |
67 | * Get the command | |
68 | * | |
69 | * @return the Cmd | |
70 | */ | |
71 | public Command getCmd() { | |
72 | return fCmd; | |
73 | } | |
74 | ||
75 | /** | |
76 | * Get the command version | |
77 | * | |
78 | * @return the CmdVersion | |
79 | */ | |
80 | public int getCmdVersion() { | |
81 | return fCmdVersion; | |
82 | } | |
83 | ||
84 | @Override | |
85 | public byte[] serialize() { | |
86 | byte data[] = new byte[SIZE]; | |
87 | ByteBuffer bb = ByteBuffer.wrap(data); | |
88 | bb.order(ByteOrder.BIG_ENDIAN); | |
89 | bb.putLong(getDataSize()); | |
90 | bb.putInt(getCmd().getCommand()); | |
91 | bb.putInt(fCmdVersion); | |
92 | return data; | |
93 | } | |
94 | ||
95 | ||
96 | } |