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 | import java.util.ArrayList; | |
23 | import java.util.List; | |
24 | ||
25 | import org.lttng.ust.agent.ILttngAgent; | |
26 | ||
27 | class SessiondListLoggersResponse implements ISessiondResponse { | |
28 | ||
29 | private final static int SIZE = 12; | |
30 | ||
31 | private int dataSize = 0; | |
32 | private int nbLogger = 0; | |
33 | ||
34 | private final List<String> loggerList = new ArrayList<String>(); | |
35 | ||
36 | /** Return status code to the session daemon. */ | |
37 | public LttngAgentRetCode code; | |
38 | ||
39 | @Override | |
40 | public byte[] getBytes() { | |
41 | byte data[] = new byte[SIZE + dataSize]; | |
42 | ByteBuffer buf = ByteBuffer.wrap(data); | |
43 | buf.order(ByteOrder.BIG_ENDIAN); | |
44 | ||
45 | /* Returned code */ | |
46 | buf.putInt(code.getCode()); | |
47 | buf.putInt(dataSize); | |
48 | buf.putInt(nbLogger); | |
49 | ||
50 | for (String logger : loggerList) { | |
51 | buf.put(logger.getBytes()); | |
52 | /* NULL terminated byte after the logger name. */ | |
53 | buf.put((byte) 0x0); | |
54 | } | |
55 | return data; | |
56 | } | |
57 | ||
58 | public void execute(ILttngAgent<?> agent) { | |
59 | for (String event : agent.listEnabledEvents()) { | |
60 | this.loggerList.add(event); | |
61 | this.nbLogger++; | |
62 | this.dataSize += event.length() + 1; | |
63 | } | |
64 | ||
65 | this.code = LttngAgentRetCode.CODE_SUCCESS_CMD; | |
66 | } | |
67 | } |