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
.lang
.Object
;
24 import java
.util
.ArrayList
;
25 import java
.util
.List
;
26 import java
.util
.Enumeration
;
27 import java
.util
.Iterator
;
29 interface LTTngSessiondCmd2_6
{
31 * Maximum name length for a logger name to be send to sessiond.
33 final static int NAME_MAX
= 255;
36 * Size of a primitive type int in byte. Because you know, Java can't
37 * provide that since it does not makes sense...
39 final static int INT_SIZE
= 4;
41 public interface SessiondResponse
{
43 * Gets a byte array of the command so that it may be streamed
45 * @return the byte array of the command
47 public byte[] getBytes();
50 public interface SessiondCommand
{
52 * Populate the class from a byte array
55 * the byte array containing the streamed command
57 public void populate(byte[] data
);
60 public enum lttng_agent_command
{
61 /** List logger(s). */
63 /** Enable logger by name. */
65 /** Disable logger by name. */
67 /** Registration done */
72 private lttng_agent_command(int c
) {
76 public int getCommand() {
81 enum lttng_agent_ret_code
{
84 CODE_UNK_LOGGER_NAME(3);
87 private lttng_agent_ret_code(int c
) {
91 public int getCode() {
96 public class sessiond_hdr
implements SessiondCommand
{
97 /** ABI size of command header. */
98 public final static int SIZE
= 16;
99 /** Payload size in bytes following this header. */
100 public long data_size
;
102 public lttng_agent_command cmd
;
103 /** Command version. */
104 public int cmd_version
;
106 public void populate(byte[] data
) {
107 ByteBuffer buf
= ByteBuffer
.wrap(data
);
108 buf
.order(ByteOrder
.BIG_ENDIAN
);
110 data_size
= buf
.getLong();
111 cmd
= lttng_agent_command
.values()[buf
.getInt() - 1];
112 cmd_version
= buf
.getInt();
116 public class sessiond_enable_handler
implements SessiondResponse
, SessiondCommand
{
117 private final static int SIZE
= 4;
119 public int lttngLogLevel
;
120 public int lttngLogLevelType
;
122 /** Return status code to the session daemon. */
123 public lttng_agent_ret_code code
;
126 public void populate(byte[] data
) {
127 int data_offset
= INT_SIZE
* 2;
129 ByteBuffer buf
= ByteBuffer
.wrap(data
);
130 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
131 lttngLogLevel
= buf
.getInt();
132 lttngLogLevelType
= buf
.getInt();
133 name
= new String(data
, data_offset
, data
.length
- data_offset
).trim();
137 public byte[] getBytes() {
138 byte data
[] = new byte[SIZE
];
139 ByteBuffer buf
= ByteBuffer
.wrap(data
);
140 buf
.order(ByteOrder
.BIG_ENDIAN
);
141 buf
.putInt(code
.getCode());
146 * Execute enable handler action which is to enable the given handler
147 * to the received name.
149 public void execute(LogFramework log
) {
150 if (log
.enableLogger(this.name
)) {
151 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
153 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
158 public class sessiond_disable_handler
implements SessiondResponse
, SessiondCommand
{
159 private final static int SIZE
= 4;
163 /** Return status code to the session daemon. */
164 public lttng_agent_ret_code code
;
167 public void populate(byte[] data
) {
168 ByteBuffer buf
= ByteBuffer
.wrap(data
);
169 buf
.order(ByteOrder
.LITTLE_ENDIAN
);
170 name
= new String(data
).trim();
174 public byte[] getBytes() {
175 byte data
[] = new byte[SIZE
];
176 ByteBuffer buf
= ByteBuffer
.wrap(data
);
177 buf
.order(ByteOrder
.BIG_ENDIAN
);
178 buf
.putInt(code
.getCode());
183 * Execute disable handler action which is to disable the given handler
184 * to the received name.
186 public void execute(LogFramework log
) {
187 if (log
.disableLogger(this.name
)) {
188 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;
190 this.code
= lttng_agent_ret_code
.CODE_INVALID_CMD
;
195 public class sessiond_list_logger
implements SessiondResponse
{
196 private final static int SIZE
= 12;
198 private int data_size
= 0;
199 private int nb_logger
= 0;
201 List
<String
> logger_list
= new ArrayList
<String
>();
203 /** Return status code to the session daemon. */
204 public lttng_agent_ret_code code
;
207 public byte[] getBytes() {
208 byte data
[] = new byte[SIZE
+ data_size
];
209 ByteBuffer buf
= ByteBuffer
.wrap(data
);
210 buf
.order(ByteOrder
.BIG_ENDIAN
);
213 buf
.putInt(code
.getCode());
214 buf
.putInt(data_size
);
215 buf
.putInt(nb_logger
);
217 for (String logger
: logger_list
) {
218 buf
.put(logger
.getBytes());
219 /* NULL terminated byte after the logger name. */
225 public void execute(LogFramework log
) {
228 Iterator
<String
> loggers
= log
.listLoggers();
229 while (loggers
.hasNext()) {
230 loggerName
= loggers
.next();
231 this.logger_list
.add(loggerName
);
233 this.data_size
+= loggerName
.length() + 1;
236 this.code
= lttng_agent_ret_code
.CODE_SUCCESS_CMD
;