Commit | Line | Data |
---|---|---|
301a3ddb AM |
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 | import java.util.ArrayList; | |
24 | import java.util.List; | |
25 | ||
26 | import org.lttng.ust.agent.AbstractLttngAgent; | |
27 | ||
28 | /** | |
29 | * Session daemon command asking the Java agent to list its registered loggers, | |
30 | * which corresponds to event names in the tracing session. | |
31 | * | |
32 | * @author Alexandre Montplaisir | |
33 | * @author David Goulet | |
34 | */ | |
35 | class SessiondListLoggersCommand implements ISessiondCommand { | |
36 | ||
37 | @Override | |
38 | public ILttngAgentResponse execute(AbstractLttngAgent<?> agent) { | |
39 | final List<String> loggerList = new ArrayList<String>(); | |
40 | int dataSize = 0; | |
41 | ||
42 | for (String event : agent.listEnabledEvents()) { | |
43 | loggerList.add(event); | |
44 | dataSize += event.length() + 1; | |
45 | } | |
46 | ||
47 | return new SessiondListLoggersResponse(loggerList, dataSize); | |
48 | } | |
49 | ||
50 | private static class SessiondListLoggersResponse implements ILttngAgentResponse { | |
51 | ||
52 | private final static int SIZE = 12; | |
53 | ||
54 | private final List<String> loggers; | |
55 | private final int dataSize; | |
56 | ||
57 | public SessiondListLoggersResponse(List<String> loggers, int dataSize) { | |
58 | this.loggers = loggers; | |
59 | this.dataSize = dataSize; | |
60 | } | |
61 | ||
62 | @Override | |
63 | public ReturnCode getReturnCode() { | |
64 | /* This command can't really fail */ | |
65 | return ILttngAgentResponse.SUCESS_RESPONSE.getReturnCode(); | |
66 | } | |
67 | ||
68 | @Override | |
69 | public byte[] getBytes() { | |
70 | byte data[] = new byte[SIZE + dataSize]; | |
71 | ByteBuffer buf = ByteBuffer.wrap(data); | |
72 | buf.order(ByteOrder.BIG_ENDIAN); | |
73 | ||
74 | /* Returned code */ | |
75 | buf.putInt(getReturnCode().getCode()); | |
76 | buf.putInt(dataSize); | |
77 | buf.putInt(loggers.size()); | |
78 | ||
79 | for (String logger : loggers) { | |
80 | buf.put(logger.getBytes()); | |
81 | /* NULL terminated byte after the logger name. */ | |
82 | buf.put((byte) 0x0); | |
83 | } | |
84 | return data; | |
85 | } | |
86 | } | |
87 | ||
88 | } |