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