2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 package org.lttng.ust.agent.client;
20 import java.nio.ByteBuffer;
21 import java.nio.ByteOrder;
23 import org.lttng.ust.agent.AbstractLttngAgent;
25 class SessiondEnableHandler implements ISessiondResponse, ISessiondCommand {
27 private static final int INT_SIZE = 4;
29 /** Event name to enable in the tracing session */
30 private String eventName;
32 /** Return status code to the session daemon. */
33 public LttngAgentRetCode code;
36 public void populate(byte[] data) {
37 int dataOffset = INT_SIZE * 2;
39 ByteBuffer buf = ByteBuffer.wrap(data);
40 buf.order(ByteOrder.LITTLE_ENDIAN);
41 buf.getInt(); //logLevel, currently unused
42 buf.getInt(); //logLevelType, currently unused
43 eventName = new String(data, dataOffset, data.length - dataOffset).trim();
47 public byte[] getBytes() {
48 byte data[] = new byte[INT_SIZE];
49 ByteBuffer buf = ByteBuffer.wrap(data);
50 buf.order(ByteOrder.BIG_ENDIAN);
51 buf.putInt(code.getCode());
55 public String getEventName() {
60 * Execute enable handler action which is to enable the given handler to the
64 * The agent on which to execute the command
66 public void execute(AbstractLttngAgent<?> agent) {
67 if (agent.eventEnabled(this.eventName)) {
68 this.code = LttngAgentRetCode.CODE_SUCCESS_CMD;
70 this.code = LttngAgentRetCode.CODE_INVALID_CMD;