Commit | Line | Data |
---|---|---|
afe13e7a | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
cfdb727a | 3 | * |
afe13e7a BH |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
afe13e7a BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9bc60be7 | 12 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences; |
afe13e7a | 13 | |
aa353506 AM |
14 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
15 | ||
0886cf00 BH |
16 | import java.io.File; |
17 | ||
aa353506 | 18 | import org.eclipse.jdt.annotation.NonNull; |
afe13e7a | 19 | import org.eclipse.jface.preference.IPreferenceStore; |
9bc60be7 | 20 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.logging.ControlCommandLogger; |
afe13e7a BH |
21 | |
22 | /** | |
afe13e7a BH |
23 | * <p> |
24 | * Singleton class to access LTTng tracer control preferences. | |
25 | * </p> | |
cfdb727a | 26 | * |
dbd4432d | 27 | * @author Bernd Hufmann |
afe13e7a BH |
28 | */ |
29 | public class ControlPreferences { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Constants | |
33 | // ------------------------------------------------------------------------ | |
9315aeee BH |
34 | /** |
35 | * Trace control log file | |
36 | */ | |
0886cf00 | 37 | public static final String TRACE_CONTROL_LOG_FILENAME = "lttng_tracer_control.log"; //$NON-NLS-1$ |
afe13e7a BH |
38 | |
39 | // Preference strings | |
9315aeee BH |
40 | /** |
41 | * The tracing group preference | |
42 | */ | |
afe13e7a | 43 | public static final String TRACE_CONTROL_TRACING_GROUP_PREF = "trace.control.tracing.group"; //$NON-NLS-1$ |
9315aeee BH |
44 | /** |
45 | * The log commands preference | |
46 | */ | |
afe13e7a | 47 | public static final String TRACE_CONTROL_LOG_COMMANDS_PREF = "trace.control.log.commands"; //$NON-NLS-1$ |
9315aeee BH |
48 | /** |
49 | * The log append preference | |
50 | */ | |
afe13e7a | 51 | public static final String TRACE_CONTROL_LOG_APPEND_PREF = "trace.control.log.append"; //$NON-NLS-1$ |
9315aeee BH |
52 | /** |
53 | * The log file path preference | |
54 | */ | |
55 | public static final String TRACE_CONTROL_LOG_FILE_PATH_PREF = "trace.control.log.path"; //$NON-NLS-1$ | |
56 | /** | |
57 | * The verbose level preference | |
58 | */ | |
afe13e7a | 59 | public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF = "trace.control.verbose.level"; //$NON-NLS-1$ |
9315aeee BH |
60 | /** |
61 | * The verbose level value for none | |
62 | */ | |
afe13e7a | 63 | public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE = "trace.control.verbose.level.none"; //$NON-NLS-1$ |
9315aeee BH |
64 | /** |
65 | * The verbose level value for level 1 (-v) | |
66 | */ | |
afe13e7a | 67 | public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE = "trace.control.verbose.level.v"; //$NON-NLS-1$ |
9315aeee BH |
68 | /** |
69 | * The verbose level value for level 2 (-vv) | |
70 | */ | |
afe13e7a | 71 | public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE = "trace.control.verbose.level.vv"; //$NON-NLS-1$ |
9315aeee BH |
72 | /** |
73 | * The verbose level value for level 3 (-vvv) | |
74 | */ | |
afe13e7a | 75 | public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE = "trace.control.verbose.level.vvv"; //$NON-NLS-1$ |
9315aeee BH |
76 | /** |
77 | * The default tracing group | |
78 | */ | |
79 | public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP = "tracing"; //$NON-NLS-1$ | |
80 | /** | |
81 | * The default tracing log file name with absolute path | |
82 | */ | |
0886cf00 | 83 | public static final String TRACE_CONTROL_DEFAULT_LOG_PATH = System.getProperty("user.home") + File.separator + TRACE_CONTROL_LOG_FILENAME; //$NON-NLS-1$ |
4bdf5f96 BH |
84 | /** |
85 | * Default timeout value used for executing commands, in seconds | |
86 | */ | |
77735e82 | 87 | public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE = 15; |
4bdf5f96 BH |
88 | /** |
89 | * Minimum timeout value used for executing commands, in seconds | |
90 | */ | |
77735e82 | 91 | public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE = 5; |
4bdf5f96 BH |
92 | /** |
93 | * Maximum timeout value used for executing commands, in seconds | |
94 | */ | |
77735e82 | 95 | public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE = 600; |
afe13e7a BH |
96 | |
97 | // ------------------------------------------------------------------------ | |
98 | // Attributes | |
99 | // ------------------------------------------------------------------------ | |
9315aeee BH |
100 | /** |
101 | * The trace control preferences singleton instance. | |
102 | */ | |
afe13e7a | 103 | private static ControlPreferences fInstance = null; |
9315aeee BH |
104 | /** |
105 | * The preference store reference | |
106 | */ | |
107 | private IPreferenceStore fPreferenceStore = null; | |
afe13e7a BH |
108 | |
109 | // ------------------------------------------------------------------------ | |
110 | // Constructor | |
111 | // ------------------------------------------------------------------------ | |
9315aeee BH |
112 | /** |
113 | * Private constructor | |
114 | */ | |
afe13e7a BH |
115 | private ControlPreferences() { |
116 | } | |
117 | ||
118 | // ------------------------------------------------------------------------ | |
119 | // Accessors | |
120 | // ------------------------------------------------------------------------ | |
9315aeee BH |
121 | /** |
122 | * Returns the trace control preferences singleton instance | |
cfdb727a | 123 | * |
9315aeee BH |
124 | * @return the trace control preferences singleton instance |
125 | */ | |
77735e82 | 126 | public static synchronized ControlPreferences getInstance() { |
afe13e7a BH |
127 | if (fInstance == null) { |
128 | fInstance = new ControlPreferences(); | |
129 | } | |
130 | return fInstance; | |
131 | } | |
132 | ||
133 | /** | |
134 | * @return the preference store | |
135 | */ | |
136 | public IPreferenceStore getPreferenceStore() { | |
9315aeee | 137 | return fPreferenceStore; |
afe13e7a BH |
138 | } |
139 | ||
140 | /** | |
141 | * @return true if tracing group is set to default | |
142 | */ | |
143 | public boolean isDefaultTracingGroup() { | |
9315aeee | 144 | return fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF).equals(fPreferenceStore.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF)); |
afe13e7a BH |
145 | } |
146 | ||
147 | /** | |
cfdb727a | 148 | * @return value of tracing group preference |
afe13e7a | 149 | */ |
aa353506 AM |
150 | public @NonNull String getTracingGroup() { |
151 | return checkNotNull(fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF)); | |
afe13e7a BH |
152 | } |
153 | ||
154 | /** | |
cfdb727a | 155 | * @return whether is logging is enabled |
afe13e7a BH |
156 | */ |
157 | public boolean isLoggingEnabled() { | |
9315aeee | 158 | return fPreferenceStore.getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF); |
afe13e7a BH |
159 | } |
160 | ||
161 | /** | |
cfdb727a | 162 | * @return whether an existing log file will appended or not |
afe13e7a BH |
163 | */ |
164 | public boolean isAppend() { | |
9315aeee | 165 | return fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF); |
afe13e7a BH |
166 | } |
167 | ||
168 | /** | |
169 | * @return verbose level preference | |
170 | */ | |
171 | public String getVerboseLevel() { | |
9315aeee | 172 | return fPreferenceStore.getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF); |
afe13e7a | 173 | } |
cfdb727a | 174 | |
0886cf00 BH |
175 | /** |
176 | * @return absolute log file path | |
177 | */ | |
178 | public String getLogfilePath() { | |
9315aeee | 179 | return fPreferenceStore.getString(TRACE_CONTROL_LOG_FILE_PATH_PREF); |
0886cf00 | 180 | } |
cfdb727a | 181 | |
afe13e7a BH |
182 | // ------------------------------------------------------------------------ |
183 | // Operations | |
184 | // ------------------------------------------------------------------------ | |
cfdb727a | 185 | |
afe13e7a BH |
186 | /** |
187 | * Initializes the control preferences (e.g. enable open log file) | |
cfdb727a AM |
188 | * |
189 | * @param preferenceStore | |
190 | * The preference store to assign | |
afe13e7a | 191 | */ |
9315aeee BH |
192 | public void init(IPreferenceStore preferenceStore) { |
193 | fPreferenceStore = preferenceStore; | |
194 | ||
195 | if (fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) { | |
0886cf00 | 196 | ControlCommandLogger.init(getLogfilePath(), isAppend()); |
cfdb727a | 197 | } |
afe13e7a BH |
198 | } |
199 | ||
200 | /** | |
cfdb727a | 201 | * Disposes any resource (e.g. close log file). |
afe13e7a BH |
202 | */ |
203 | public void dispose() { | |
204 | ControlCommandLogger.close(); | |
205 | } | |
206 | } |