Doc: add LTTNG_UST_CLOCK_PLUGIN to man page
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / 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 /**
30 * Maximum name length for a logger name to be send to sessiond.
31 */
32 int NAME_MAX = 255;
33
34 /*
35 * Size of a primitive type int in byte. Because you know, Java can't
36 * provide that since it does not makes sense...
37 *
38 *
39 */
40 int INT_SIZE = 4;
41
42 interface SessiondResponse {
43 /**
44 * Gets a byte array of the command so that it may be streamed
45 *
46 * @return the byte array of the command
47 */
48 public byte[] getBytes();
49 }
50
51 interface SessiondCommand {
52 /**
53 * Populate the class from a byte array
54 *
55 * @param data
56 * the byte array containing the streamed command
57 */
58 public void populate(byte[] data);
59 }
60
61 enum lttng_agent_command {
62 /** List logger(s). */
63 CMD_LIST(1),
64 /** Enable logger by name. */
65 CMD_ENABLE(2),
66 /** Disable logger by name. */
67 CMD_DISABLE(3),
68 /** Registration done */
69 CMD_REG_DONE(4);
70
71 private int code;
72
73 private lttng_agent_command(int c) {
74 code = c;
75 }
76
77 public int getCommand() {
78 return code;
79 }
80 }
81
82 enum lttng_agent_ret_code {
83 CODE_SUCCESS_CMD(1),
84 CODE_INVALID_CMD(2),
85 CODE_UNK_LOGGER_NAME(3);
86 private int code;
87
88 private lttng_agent_ret_code(int c) {
89 code = c;
90 }
91
92 public int getCode() {
93 return code;
94 }
95 }
96
97 class sessiond_hdr implements SessiondCommand {
98
99 /** ABI size of command header. */
100 public final static int SIZE = 16;
101 /** Payload size in bytes following this header. */
102 public long dataSize;
103 /** Command type. */
104 public lttng_agent_command cmd;
105 /** Command version. */
106 public int cmdVersion;
107
108 @Override
109 public void populate(byte[] data) {
110 ByteBuffer buf = ByteBuffer.wrap(data);
111 buf.order(ByteOrder.BIG_ENDIAN);
112
113 dataSize = buf.getLong();
114 cmd = lttng_agent_command.values()[buf.getInt() - 1];
115 cmdVersion = buf.getInt();
116 }
117 }
118
119 class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
120
121 private static final int SIZE = 4;
122 public String name;
123 public int lttngLogLevel;
124 public int lttngLogLevelType;
125
126 /** Return status code to the session daemon. */
127 public lttng_agent_ret_code code;
128
129 @Override
130 public void populate(byte[] data) {
131 int dataOffset = INT_SIZE * 2;
132
133 ByteBuffer buf = ByteBuffer.wrap(data);
134 buf.order(ByteOrder.LITTLE_ENDIAN);
135 lttngLogLevel = buf.getInt();
136 lttngLogLevelType = buf.getInt();
137 name = new String(data, dataOffset, data.length - dataOffset).trim();
138 }
139
140 @Override
141 public byte[] getBytes() {
142 byte data[] = new byte[SIZE];
143 ByteBuffer buf = ByteBuffer.wrap(data);
144 buf.order(ByteOrder.BIG_ENDIAN);
145 buf.putInt(code.getCode());
146 return data;
147 }
148
149 /**
150 * Execute enable handler action which is to enable the given handler
151 * to the received name.
152 *
153 * @param log
154 */
155 public void execute(LogFramework log) {
156 if (log.enableLogger(this.name)) {
157 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
158 } else {
159 this.code = lttng_agent_ret_code.CODE_INVALID_CMD;
160 }
161 }
162 }
163
164 class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
165
166 private final static int SIZE = 4;
167 public String name;
168
169
170 /** Return status code to the session daemon. */
171 public lttng_agent_ret_code code;
172
173 @Override
174 public void populate(byte[] data) {
175 ByteBuffer buf = ByteBuffer.wrap(data);
176 buf.order(ByteOrder.LITTLE_ENDIAN);
177 name = new String(data).trim();
178 }
179
180 @Override
181 public byte[] getBytes() {
182 byte data[] = new byte[SIZE];
183 ByteBuffer buf = ByteBuffer.wrap(data);
184 buf.order(ByteOrder.BIG_ENDIAN);
185 buf.putInt(code.getCode());
186 return data;
187 }
188
189 /**
190 * Execute disable handler action which is to disable the given handler
191 * to the received name.
192 *
193 * @param log
194 */
195 public void execute(LogFramework log) {
196 if (log.disableLogger(this.name)) {
197 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
198 } else {
199 this.code = lttng_agent_ret_code.CODE_INVALID_CMD;
200 }
201 }
202 }
203
204 class sessiond_list_logger implements SessiondResponse {
205
206 private final static int SIZE = 12;
207
208 private int dataSize = 0;
209 private int nbLogger = 0;
210
211 List<String> loggerList = new ArrayList<String>();
212
213 /** Return status code to the session daemon. */
214 public lttng_agent_ret_code code;
215
216 @Override
217 public byte[] getBytes() {
218 byte data[] = new byte[SIZE + dataSize];
219 ByteBuffer buf = ByteBuffer.wrap(data);
220 buf.order(ByteOrder.BIG_ENDIAN);
221
222 /* Returned code */
223 buf.putInt(code.getCode());
224 buf.putInt(dataSize);
225 buf.putInt(nbLogger);
226
227 for (String logger: loggerList) {
228 buf.put(logger.getBytes());
229 /* NULL terminated byte after the logger name. */
230 buf.put((byte) 0x0);
231 }
232 return data;
233 }
234
235 public void execute(LogFramework log) {
236 String loggerName;
237
238 Iterator<String> loggers = log.listLoggers();
239 while (loggers.hasNext()) {
240 loggerName = loggers.next();
241 this.loggerList.add(loggerName);
242 this.nbLogger++;
243 this.dataSize += loggerName.length() + 1;
244 }
245
246 this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
247 }
248 }
249 }
This page took 0.034637 seconds and 4 git commands to generate.