Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / SessiondEnableEventCommand.java
CommitLineData
d60dfbe4 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
d60dfbe4 3 *
c0c0989a
MJ
4 * Copyright (C) 2015 EfficiOS Inc.
5 * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
d60dfbe4
AM
7 */
8
9package org.lttng.ust.agent.client;
10
11import java.nio.ByteBuffer;
12import java.nio.ByteOrder;
13
3daf5cba
AM
14import org.lttng.ust.agent.session.EventRule;
15import org.lttng.ust.agent.session.LogLevelSelector;
16
301a3ddb
AM
17/**
18 * Session daemon command indicating to the Java agent that some events were
19 * enabled in the tracing session.
20 *
21 * @author Alexandre Montplaisir
22 * @author David Goulet
23 */
1d193914 24class SessiondEnableEventCommand extends SessiondCommand {
d60dfbe4 25
191f4058
AM
26 /** Fixed event name length. Value defined by the lttng agent protocol. */
27 private static final int EVENT_NAME_LENGTH = 256;
28
29 private final boolean commandIsValid;
d60dfbe4 30
3daf5cba 31 /* Parameters of the event rule being enabled */
301a3ddb 32 private final String eventName;
3daf5cba
AM
33 private final LogLevelSelector logLevelFilter;
34 private final String filterString;
d60dfbe4 35
301a3ddb
AM
36 public SessiondEnableEventCommand(byte[] data) {
37 if (data == null) {
38 throw new IllegalArgumentException();
39 }
d60dfbe4 40 ByteBuffer buf = ByteBuffer.wrap(data);
abac44cd 41 buf.order(ByteOrder.BIG_ENDIAN);
3daf5cba
AM
42 int logLevel = buf.getInt();
43 int logLevelType = buf.getInt();
44 logLevelFilter = new LogLevelSelector(logLevel, logLevelType);
45
191f4058
AM
46 /* Read the event name */
47 byte[] eventNameBytes = new byte[EVENT_NAME_LENGTH];
48 buf.get(eventNameBytes);
22191ffd 49 eventName = new String(eventNameBytes, SESSIOND_PROTOCOL_CHARSET).trim();
191f4058 50
1d193914
AM
51 /* Read the filter string */
52 filterString = readNextString(buf);
191f4058 53
1d193914
AM
54 /* The command was invalid if the string could not be read correctly */
55 commandIsValid = (filterString != null);
d60dfbe4
AM
56 }
57
58 @Override
3165c2f5 59 public LttngAgentResponse execute(ILttngTcpClientListener agent) {
191f4058
AM
60 if (!commandIsValid) {
61 return LttngAgentResponse.FAILURE_RESPONSE;
62 }
63
3daf5cba
AM
64 EventRule rule = new EventRule(eventName, logLevelFilter, filterString);
65 boolean success = agent.eventEnabled(rule);
93253569 66 return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
d60dfbe4 67 }
f35c6aa0
AM
68
69 @Override
70 public String toString() {
71 return "SessiondEnableEventCommand["
72 + "eventName=" + eventName
73 + ", logLevel=" + logLevelFilter.toString()
74 + ", filterString=" + filterString
75 +"]";
76 }
d60dfbe4 77}
This page took 0.029154 seconds and 4 git commands to generate.