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
{
29 * Maximum name length for a logger name to be send to sessiond.
31 final static int NAME_MAX
= 255;
34 * Size of a primitive type int in byte. Because you know, Java can't
35 * provide that since it does not makes sense...
37 final static int INT_SIZE
= 4;
39 public interface SessiondResponse
{
41 * Gets a byte array of the command so that it may be streamed
43 * @return the byte array of the command
45 public byte[] getBytes();
48 public interface SessiondCommand
{
50 * Populate the class from a byte array
53 * the byte array containing the streamed command
55 public void populate(byte[] data
);
58 public enum lttng_agent_command
{
59 /** List logger(s). */
61 /** Enable logger by name. */
63 /** Disable logger by name. */
65 /** Registration done */
70 private lttng_agent_command(int c
) {
74 public int getCommand() {
79 enum lttng_agent_ret_code
{
82 CODE_UNK_LOGGER_NAME(3);
85 private lttng_agent_ret_code(int c
) {
89 public int getCode() {
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
;
100 public lttng_agent_command cmd
;
101 /** Command version. */
102 public int cmd_version
;
104 public void populate(byte[] data
) {
105 ByteBuffer buf
= ByteBuffer
.wrap(data
);
106 buf
.order(ByteOrder
.BIG_ENDIAN
);
108 data_size
= buf
.getLong();
109 cmd
= lttng_agent_command
.values()[buf
.getInt() - 1];
110 cmd_version
= buf
.getInt();
114 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
115 private final static int SIZE
= 4;
117 public int lttngLogLevel
;
118 public int lttngLogLevelType
;
120 /** Return status code to the session daemon. */
121 public lttng_agent_ret_code code
;
124 public void populate(byte[] data
) {
125 int data_offset
= INT_SIZE
* 2;
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();
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());
144 * Execute enable handler action which is to enable the given handler
145 * to the received name.
147 public void execute(LogFramework log
) {
148 if (log
.enableLogger(this.name
)) {
149 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
151 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
156 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
157 private final static int SIZE
= 4;
161 /** Return status code to the session daemon. */
162 public lttng_agent_ret_code code
;
165 public void populate(byte[] data
) {
166 ByteBuffer buf
= ByteBuffer
.wrap(data
);
167 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
168 name
= new String(data
).trim();
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());
181 * Execute disable handler action which is to disable the given handler
182 * to the received name.
184 public void execute(LogFramework log
) {
185 if (log
.disableLogger(this.name
)) {
186 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
188 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
193 public class sessiond_list_logger
implements SessiondResponse
{
194 private final static int SIZE
= 12;
196 private int data_size
= 0;
197 private int nb_logger
= 0;
199 List
<String
> logger_list
= new ArrayList
<String
>();
201 /** Return status code to the session daemon. */
202 public lttng_agent_ret_code code
;
205 public byte[] getBytes() {
206 byte data
[] = new byte[SIZE
+ data_size
];
207 ByteBuffer buf
= ByteBuffer
.wrap(data
);
208 buf
.order(ByteOrder
.BIG_ENDIAN
);
211 buf
.putInt(code
.getCode());
212 buf
.putInt(data_size
);
213 buf
.putInt(nb_logger
);
215 for (String logger
: logger_list
) {
216 buf
.put(logger
.getBytes());
217 /* NULL terminated byte after the logger name. */
223 public void execute(LogFramework log
) {
226 Iterator
<String
> loggers
= log
.listLoggers();
227 while (loggers
.hasNext()) {
228 loggerName
= loggers
.next();
229 this.logger_list
.add(loggerName
);
231 this.data_size
+= loggerName
.length() + 1;
234 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;