2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
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.
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
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
19 package org
.lttng
.ust
.agent
;
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
;
27 interface LTTngSessiondCmd2_6
{
30 * Maximum name length for a logger name to be send to sessiond.
35 * Size of a primitive type int in byte. Because you know, Java can't
36 * provide that since it does not makes sense...
42 interface SessiondResponse
{
44 * Gets a byte array of the command so that it may be streamed
46 * @return the byte array of the command
48 public byte[] getBytes();
51 interface SessiondCommand
{
53 * Populate the class from a byte array
56 * the byte array containing the streamed command
58 public void populate(byte[] data
);
61 enum lttng_agent_command
{
62 /** List logger(s). */
64 /** Enable logger by name. */
66 /** Disable logger by name. */
68 /** Registration done */
73 private lttng_agent_command(int c
) {
77 public int getCommand() {
82 enum lttng_agent_ret_code
{
85 CODE_UNK_LOGGER_NAME(3);
88 private lttng_agent_ret_code(int c
) {
92 public int getCode() {
97 class sessiond_hdr
implements SessiondCommand
{
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
;
104 public lttng_agent_command cmd
;
105 /** Command version. */
106 public int cmdVersion
;
109 public void populate(byte[] data
) {
110 ByteBuffer buf
= ByteBuffer
.wrap(data
);
111 buf
.order(ByteOrder
.BIG_ENDIAN
);
113 dataSize
= buf
.getLong();
114 cmd
= lttng_agent_command
.values()[buf
.getInt() - 1];
115 cmdVersion
= buf
.getInt();
119 class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
121 private static final int SIZE
= 4;
123 public int lttngLogLevel
;
124 public int lttngLogLevelType
;
126 /** Return status code to the session daemon. */
127 public lttng_agent_ret_code code
;
130 public void populate(byte[] data
) {
131 int dataOffset
= INT_SIZE
* 2;
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();
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());
150 * Execute enable handler action which is to enable the given handler
151 * to the received name.
155 public void execute(LogFramework log
) {
156 if (log
.enableLogger(this.name
)) {
157 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
159 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
164 class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
166 private final static int SIZE
= 4;
170 /** Return status code to the session daemon. */
171 public lttng_agent_ret_code code
;
174 public void populate(byte[] data
) {
175 ByteBuffer buf
= ByteBuffer
.wrap(data
);
176 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
177 name
= new String(data
).trim();
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());
190 * Execute disable handler action which is to disable the given handler
191 * to the received name.
195 public void execute(LogFramework log
) {
196 if (log
.disableLogger(this.name
)) {
197 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
199 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
204 class sessiond_list_logger
implements SessiondResponse
{
206 private final static int SIZE
= 12;
208 private int dataSize
= 0;
209 private int nbLogger
= 0;
211 List
<String
> loggerList
= new ArrayList
<String
>();
213 /** Return status code to the session daemon. */
214 public lttng_agent_ret_code code
;
217 public byte[] getBytes() {
218 byte data
[] = new byte[SIZE
+ dataSize
];
219 ByteBuffer buf
= ByteBuffer
.wrap(data
);
220 buf
.order(ByteOrder
.BIG_ENDIAN
);
223 buf
.putInt(code
.getCode());
224 buf
.putInt(dataSize
);
225 buf
.putInt(nbLogger
);
227 for (String logger
: loggerList
) {
228 buf
.put(logger
.getBytes());
229 /* NULL terminated byte after the logger name. */
235 public void execute(LogFramework log
) {
238 Iterator
<String
> loggers
= log
.listLoggers();
239 while (loggers
.hasNext()) {
240 loggerName
= loggers
.next();
241 this.loggerList
.add(loggerName
);
243 this.dataSize
+= loggerName
.length() + 1;
246 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;