| 1 | /* |
| 2 | * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> |
| 3 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> |
| 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 | |
| 19 | package org.lttng.ust.agent.client; |
| 20 | |
| 21 | import java.nio.ByteBuffer; |
| 22 | import java.nio.ByteOrder; |
| 23 | |
| 24 | import org.lttng.ust.agent.session.EventRule; |
| 25 | import org.lttng.ust.agent.session.LogLevelSelector; |
| 26 | |
| 27 | /** |
| 28 | * Session daemon command indicating to the Java agent that some events were |
| 29 | * enabled in the tracing session. |
| 30 | * |
| 31 | * @author Alexandre Montplaisir |
| 32 | * @author David Goulet |
| 33 | */ |
| 34 | class SessiondEnableEventCommand extends SessiondCommand { |
| 35 | |
| 36 | /** Fixed event name length. Value defined by the lttng agent protocol. */ |
| 37 | private static final int EVENT_NAME_LENGTH = 256; |
| 38 | |
| 39 | private final boolean commandIsValid; |
| 40 | |
| 41 | /* Parameters of the event rule being enabled */ |
| 42 | private final String eventName; |
| 43 | private final LogLevelSelector logLevelFilter; |
| 44 | private final String filterString; |
| 45 | |
| 46 | public SessiondEnableEventCommand(byte[] data) { |
| 47 | if (data == null) { |
| 48 | throw new IllegalArgumentException(); |
| 49 | } |
| 50 | ByteBuffer buf = ByteBuffer.wrap(data); |
| 51 | buf.order(ByteOrder.BIG_ENDIAN); |
| 52 | int logLevel = buf.getInt(); |
| 53 | int logLevelType = buf.getInt(); |
| 54 | logLevelFilter = new LogLevelSelector(logLevel, logLevelType); |
| 55 | |
| 56 | /* Read the event name */ |
| 57 | byte[] eventNameBytes = new byte[EVENT_NAME_LENGTH]; |
| 58 | buf.get(eventNameBytes); |
| 59 | eventName = new String(eventNameBytes).trim(); |
| 60 | |
| 61 | /* Read the filter string */ |
| 62 | filterString = readNextString(buf); |
| 63 | |
| 64 | /* The command was invalid if the string could not be read correctly */ |
| 65 | commandIsValid = (filterString != null); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public LttngAgentResponse execute(ILttngTcpClientListener agent) { |
| 70 | if (!commandIsValid) { |
| 71 | return LttngAgentResponse.FAILURE_RESPONSE; |
| 72 | } |
| 73 | |
| 74 | EventRule rule = new EventRule(eventName, logLevelFilter, filterString); |
| 75 | boolean success = agent.eventEnabled(rule); |
| 76 | return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE); |
| 77 | } |
| 78 | } |