1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.preferences
;
16 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
17 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
21 * Singleton class to access LTTng tracer control preferences.
24 * @author Bernd Hufmann
26 public class ControlPreferences
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 * Trace control log file
34 public static final String TRACE_CONTROL_LOG_FILENAME
= "lttng_tracer_control.log"; //$NON-NLS-1$
38 * The tracing group preference
40 public static final String TRACE_CONTROL_TRACING_GROUP_PREF
= "trace.control.tracing.group"; //$NON-NLS-1$
42 * The log commands preference
44 public static final String TRACE_CONTROL_LOG_COMMANDS_PREF
= "trace.control.log.commands"; //$NON-NLS-1$
46 * The log append preference
48 public static final String TRACE_CONTROL_LOG_APPEND_PREF
= "trace.control.log.append"; //$NON-NLS-1$
50 * The log file path preference
52 public static final String TRACE_CONTROL_LOG_FILE_PATH_PREF
= "trace.control.log.path"; //$NON-NLS-1$
54 * The verbose level preference
56 public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF
= "trace.control.verbose.level"; //$NON-NLS-1$
58 * The verbose level value for none
60 public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE
= "trace.control.verbose.level.none"; //$NON-NLS-1$
62 * The verbose level value for level 1 (-v)
64 public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
= "trace.control.verbose.level.v"; //$NON-NLS-1$
66 * The verbose level value for level 2 (-vv)
68 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
= "trace.control.verbose.level.vv"; //$NON-NLS-1$
70 * The verbose level value for level 3 (-vvv)
72 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
= "trace.control.verbose.level.vvv"; //$NON-NLS-1$
74 * The default tracing group
76 public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP
= "tracing"; //$NON-NLS-1$
78 * The default tracing log file name with absolute path
80 public static final String TRACE_CONTROL_DEFAULT_LOG_PATH
= System
.getProperty("user.home") + File
.separator
+ TRACE_CONTROL_LOG_FILENAME
; //$NON-NLS-1$
82 * Default timeout value used for executing commands, in seconds
84 public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE
= 15;
86 * Minimum timeout value used for executing commands, in seconds
88 public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE
= 5;
90 * Maximum timeout value used for executing commands, in seconds
92 public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE
= 600;
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
98 * The trace control preferences singleton instance.
100 private static ControlPreferences fInstance
= null;
102 * The preference store reference
104 private IPreferenceStore fPreferenceStore
= null;
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
110 * Private constructor
112 private ControlPreferences() {
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
119 * Returns the trace control preferences singleton instance
121 * @return the trace control preferences singleton instance
123 public static synchronized ControlPreferences
getInstance() {
124 if (fInstance
== null) {
125 fInstance
= new ControlPreferences();
131 * @return the preference store
133 public IPreferenceStore
getPreferenceStore() {
134 return fPreferenceStore
;
138 * @return true if tracing group is set to default
140 public boolean isDefaultTracingGroup() {
141 return fPreferenceStore
.getString(TRACE_CONTROL_TRACING_GROUP_PREF
).equals(fPreferenceStore
.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF
));
145 * @return value of tracing group preference
147 public String
getTracingGroup() {
148 return fPreferenceStore
.getString(TRACE_CONTROL_TRACING_GROUP_PREF
);
152 * @return whether is logging is enabled
154 public boolean isLoggingEnabled() {
155 return fPreferenceStore
.getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF
);
159 * @return whether an existing log file will appended or not
161 public boolean isAppend() {
162 return fPreferenceStore
.getBoolean(ControlPreferences
.TRACE_CONTROL_LOG_APPEND_PREF
);
166 * @return verbose level preference
168 public String
getVerboseLevel() {
169 return fPreferenceStore
.getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF
);
173 * @return absolute log file path
175 public String
getLogfilePath() {
176 return fPreferenceStore
.getString(TRACE_CONTROL_LOG_FILE_PATH_PREF
);
179 // ------------------------------------------------------------------------
181 // ------------------------------------------------------------------------
184 * Initializes the control preferences (e.g. enable open log file)
186 * @param preferenceStore
187 * The preference store to assign
189 public void init(IPreferenceStore preferenceStore
) {
190 fPreferenceStore
= preferenceStore
;
192 if (fPreferenceStore
.getBoolean(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
)) {
193 ControlCommandLogger
.init(getLogfilePath(), isAppend());
198 * Disposes any resource (e.g. close log file).
200 public void dispose() {
201 ControlCommandLogger
.close();