Fix compilation warnings in the Java agent
[lttng-ust.git] / liblttng-ust-java-agent / java / org / lttng / ust / agent / LTTngSessiondCmd2_6.java
1 /*
2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
3 *
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 package org.lttng.ust.agent;
20
21 import java.nio.ByteBuffer;
22 import java.nio.ByteOrder;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26
27 interface LTTngSessiondCmd2_6 {
28 /**
29 * Maximum name length for a logger name to be send to sessiond.
30 */
31 final static int NAME_MAX = 255;
32
33 /*
34 * Size of a primitive type int in byte. Because you know, Java can't
35 * provide that since it does not makes sense...
36 */
37 final static int INT_SIZE = 4;
38
39 public interface SessiondResponse {
40 /**
41 * Gets a byte array of the command so that it may be streamed
42 *
43 * @return the byte array of the command
44 */
45 public byte[] getBytes();
46 }
47
48 public interface SessiondCommand {
49 /**
50 * Populate the class from a byte array
51 *
52 * @param data
53 * the byte array containing the streamed command
54 */
55 public void populate(byte[] data);
56 }
57
58 public enum lttng_agent_command {
59 /** List logger(s). */
60 CMD_LIST(1),
61 /** Enable logger by name. */
62 CMD_ENABLE(2),
63 /** Disable logger by name. */
64 CMD_DISABLE(3),
65 /** Registration done */
66 CMD_REG_DONE(4);
67
68 private int code;
69
70 private lttng_agent_command(int c) {
71 code = c;
72 }
73
74 public int getCommand() {
75 return code;
76 }
77 }
78
79 enum lttng_agent_ret_code {
80 CODE_SUCCESS_CMD(1),
81 CODE_INVALID_CMD(2),
82 CODE_UNK_LOGGER_NAME(3);
83 private int code;
84
85 private lttng_agent_ret_code(int c) {
86 code = c;
87 }
88
89 public int getCode() {
90 return code;
91 }
92 }
93
94 public class sessiond_hdr implements SessiondCommand {
95 /** ABI size of command header. */
96 public final static int SIZE = 16;
97 /** Payload size in bytes following this header. */
98 public long data_size;
99 /** Command type. */
100 public lttng_agent_command cmd;
101 /** Command version. */
102 public int cmd_version;
103
104 public void populate(byte[] data) {
105 ByteBuffer buf = ByteBuffer.wrap(data);
106 buf.order(ByteOrder.BIG_ENDIAN);
107
108 data_size = buf.getLong();
109 cmd = lttng_agent_command.values()[buf.getInt() - 1];
110 cmd_version = buf.getInt();
111 }
112 }
113
114 public class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
115 private final static int SIZE = 4;
116 public String name;
117 public int lttngLogLevel;
118 public int lttngLogLevelType;
119
120 /** Return status code to the session daemon. */
121 public lttng_agent_ret_code code;
122
123 @Override
124 public void populate(byte[] data) {
125 int data_offset = INT_SIZE * 2;
126
127 ByteBuffer buf = ByteBuffer.wrap(data);
128 buf.order(ByteOrder.LITTLE_ENDIAN);
129 lttngLogLevel = buf.getInt();
130 lttngLogLevelType = buf.getInt();
131 name = new String(data, data_offset, data.length - data_offset).trim();
132 }
133
134 @Override
135 public byte[] getBytes() {
136 byte data[] = new byte[SIZE];
137 ByteBuffer buf = ByteBuffer.wrap(data);
138 buf.order(ByteOrder.BIG_ENDIAN);
139 buf.putInt(code.getCode());
140 return data;
141 }
142
143 /**
144 * Execute enable handler action which is to enable the given handler
145 * to the received name.
146 */
147 public void execute(LogFramework log) {
148 if (log.enableLogger(this.name)) {
149 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
150 } else {
151 this.code = lttng_agent_ret_code.CODE_INVALID_CMD;
152 }
153 }
154 }
155
156 public class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
157 private final static int SIZE = 4;
158 public String name;
159
160
161 /** Return status code to the session daemon. */
162 public lttng_agent_ret_code code;
163
164 @Override
165 public void populate(byte[] data) {
166 ByteBuffer buf = ByteBuffer.wrap(data);
167 buf.order(ByteOrder.LITTLE_ENDIAN);
168 name = new String(data).trim();
169 }
170
171 @Override
172 public byte[] getBytes() {
173 byte data[] = new byte[SIZE];
174 ByteBuffer buf = ByteBuffer.wrap(data);
175 buf.order(ByteOrder.BIG_ENDIAN);
176 buf.putInt(code.getCode());
177 return data;
178 }
179
180 /**
181 * Execute disable handler action which is to disable the given handler
182 * to the received name.
183 */
184 public void execute(LogFramework log) {
185 if (log.disableLogger(this.name)) {
186 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
187 } else {
188 this.code = lttng_agent_ret_code.CODE_INVALID_CMD;
189 }
190 }
191 }
192
193 public class sessiond_list_logger implements SessiondResponse {
194 private final static int SIZE = 12;
195
196 private int data_size = 0;
197 private int nb_logger = 0;
198
199 List<String> logger_list = new ArrayList<String>();
200
201 /** Return status code to the session daemon. */
202 public lttng_agent_ret_code code;
203
204 @Override
205 public byte[] getBytes() {
206 byte data[] = new byte[SIZE + data_size];
207 ByteBuffer buf = ByteBuffer.wrap(data);
208 buf.order(ByteOrder.BIG_ENDIAN);
209
210 /* Returned code */
211 buf.putInt(code.getCode());
212 buf.putInt(data_size);
213 buf.putInt(nb_logger);
214
215 for (String logger: logger_list) {
216 buf.put(logger.getBytes());
217 /* NULL terminated byte after the logger name. */
218 buf.put((byte) 0x0);
219 }
220 return data;
221 }
222
223 public void execute(LogFramework log) {
224 String loggerName;
225
226 Iterator<String> loggers = log.listLoggers();
227 while (loggers.hasNext()) {
228 loggerName = loggers.next();
229 this.logger_list.add(loggerName);
230 this.nb_logger++;
231 this.data_size += loggerName.length() + 1;
232 }
233
234 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
235 }
236 }
237 }
This page took 0.037257 seconds and 4 git commands to generate.