Commit | Line | Data |
---|---|---|
d60dfbe4 | 1 | /* |
301a3ddb | 2 | * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> |
d60dfbe4 AM |
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 | ||
3daf5cba AM |
24 | import org.lttng.ust.agent.session.EventRule; |
25 | import org.lttng.ust.agent.session.LogLevelSelector; | |
26 | ||
301a3ddb AM |
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 implements ISessiondCommand { | |
d60dfbe4 AM |
35 | |
36 | private static final int INT_SIZE = 4; | |
37 | ||
3daf5cba | 38 | /* Parameters of the event rule being enabled */ |
301a3ddb | 39 | private final String eventName; |
3daf5cba AM |
40 | private final LogLevelSelector logLevelFilter; |
41 | private final String filterString; | |
d60dfbe4 | 42 | |
301a3ddb AM |
43 | public SessiondEnableEventCommand(byte[] data) { |
44 | if (data == null) { | |
45 | throw new IllegalArgumentException(); | |
46 | } | |
d60dfbe4 AM |
47 | int dataOffset = INT_SIZE * 2; |
48 | ||
49 | ByteBuffer buf = ByteBuffer.wrap(data); | |
50 | buf.order(ByteOrder.LITTLE_ENDIAN); | |
3daf5cba AM |
51 | int logLevel = buf.getInt(); |
52 | int logLevelType = buf.getInt(); | |
53 | logLevelFilter = new LogLevelSelector(logLevel, logLevelType); | |
54 | ||
d60dfbe4 | 55 | eventName = new String(data, dataOffset, data.length - dataOffset).trim(); |
3daf5cba | 56 | filterString = null; /* Not yet sent by the sessiond */ |
d60dfbe4 AM |
57 | } |
58 | ||
59 | @Override | |
3165c2f5 | 60 | public LttngAgentResponse execute(ILttngTcpClientListener agent) { |
3daf5cba AM |
61 | EventRule rule = new EventRule(eventName, logLevelFilter, filterString); |
62 | boolean success = agent.eventEnabled(rule); | |
93253569 | 63 | return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE); |
d60dfbe4 AM |
64 | } |
65 | } |