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