Commit | Line | Data |
---|---|---|
d60dfbe4 AM |
1 | /* |
2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
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. | |
7 | * | |
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 | |
11 | * for more details. | |
12 | * | |
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 | |
16 | */ | |
17 | ||
18 | package org.lttng.ust.agent.client; | |
19 | ||
20 | import java.nio.ByteBuffer; | |
21 | import java.nio.ByteOrder; | |
22 | ||
23 | import org.lttng.ust.agent.AbstractLttngAgent; | |
24 | ||
25 | class SessiondDisableHandler implements ISessiondResponse, ISessiondCommand { | |
26 | ||
27 | private static final int INT_SIZE = 4; | |
28 | ||
29 | /** Event name to disable from the tracing session */ | |
30 | private String eventName; | |
31 | ||
32 | /** Return status code to the session daemon. */ | |
33 | private LttngAgentRetCode code; | |
34 | ||
35 | @Override | |
36 | public void populate(byte[] data) { | |
37 | ByteBuffer buf = ByteBuffer.wrap(data); | |
38 | buf.order(ByteOrder.LITTLE_ENDIAN); | |
39 | eventName = new String(data).trim(); | |
40 | } | |
41 | ||
42 | @Override | |
43 | public byte[] getBytes() { | |
44 | byte data[] = new byte[INT_SIZE]; | |
45 | ByteBuffer buf = ByteBuffer.wrap(data); | |
46 | buf.order(ByteOrder.BIG_ENDIAN); | |
47 | buf.putInt(code.getCode()); | |
48 | return data; | |
49 | } | |
50 | ||
51 | public String getEventName() { | |
52 | return eventName; | |
53 | } | |
54 | ||
55 | public void setRetCode(LttngAgentRetCode code) { | |
56 | this.code = code; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Execute disable handler action which is to disable the given handler to | |
61 | * the received name. | |
62 | * | |
63 | * @param agent | |
64 | * The agent on which to execute the command | |
65 | */ | |
66 | public void execute(AbstractLttngAgent<?> agent) { | |
67 | if (agent.eventDisabled(this.eventName)) { | |
68 | this.code = LttngAgentRetCode.CODE_SUCCESS_CMD; | |
69 | } else { | |
70 | this.code = LttngAgentRetCode.CODE_INVALID_CMD; | |
71 | } | |
72 | } | |
73 | } |