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
;
14 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.logging
.ControlCommandLogger
;
24 * Singleton class to access LTTng tracer control preferences.
27 * @author Bernd Hufmann
29 public class ControlPreferences
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 * Trace control log file
37 public static final String TRACE_CONTROL_LOG_FILENAME
= "lttng_tracer_control.log"; //$NON-NLS-1$
41 * The tracing group preference
43 public static final String TRACE_CONTROL_TRACING_GROUP_PREF
= "trace.control.tracing.group"; //$NON-NLS-1$
45 * The log commands preference
47 public static final String TRACE_CONTROL_LOG_COMMANDS_PREF
= "trace.control.log.commands"; //$NON-NLS-1$
49 * The log append preference
51 public static final String TRACE_CONTROL_LOG_APPEND_PREF
= "trace.control.log.append"; //$NON-NLS-1$
53 * The log file path preference
55 public static final String TRACE_CONTROL_LOG_FILE_PATH_PREF
= "trace.control.log.path"; //$NON-NLS-1$
57 * The verbose level preference
59 public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF
= "trace.control.verbose.level"; //$NON-NLS-1$
61 * The verbose level value for none
63 public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE
= "trace.control.verbose.level.none"; //$NON-NLS-1$
65 * The verbose level value for level 1 (-v)
67 public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE
= "trace.control.verbose.level.v"; //$NON-NLS-1$
69 * The verbose level value for level 2 (-vv)
71 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE
= "trace.control.verbose.level.vv"; //$NON-NLS-1$
73 * The verbose level value for level 3 (-vvv)
75 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE
= "trace.control.verbose.level.vvv"; //$NON-NLS-1$
77 * The default tracing group
79 public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP
= "tracing"; //$NON-NLS-1$
81 * The default tracing log file name with absolute path
83 public static final String TRACE_CONTROL_DEFAULT_LOG_PATH
= System
.getProperty("user.home") + File
.separator
+ TRACE_CONTROL_LOG_FILENAME
; //$NON-NLS-1$
85 * Default timeout value used for executing commands, in seconds
87 public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE
= 15;
89 * Minimum timeout value used for executing commands, in seconds
91 public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE
= 5;
93 * Maximum timeout value used for executing commands, in seconds
95 public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE
= 600;
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 * The trace control preferences singleton instance.
103 private static ControlPreferences fInstance
= null;
105 * The preference store reference
107 private IPreferenceStore fPreferenceStore
= null;
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
113 * Private constructor
115 private ControlPreferences() {
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
122 * Returns the trace control preferences singleton instance
124 * @return the trace control preferences singleton instance
126 public static synchronized ControlPreferences
getInstance() {
127 if (fInstance
== null) {
128 fInstance
= new ControlPreferences();
134 * @return the preference store
136 public IPreferenceStore
getPreferenceStore() {
137 return fPreferenceStore
;
141 * @return true if tracing group is set to default
143 public boolean isDefaultTracingGroup() {
144 return fPreferenceStore
.getString(TRACE_CONTROL_TRACING_GROUP_PREF
).equals(fPreferenceStore
.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF
));
148 * @return value of tracing group preference
150 public @NonNull String
getTracingGroup() {
151 return checkNotNull(fPreferenceStore
.getString(TRACE_CONTROL_TRACING_GROUP_PREF
));
155 * @return whether is logging is enabled
157 public boolean isLoggingEnabled() {
158 return fPreferenceStore
.getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF
);
162 * @return whether an existing log file will appended or not
164 public boolean isAppend() {
165 return fPreferenceStore
.getBoolean(ControlPreferences
.TRACE_CONTROL_LOG_APPEND_PREF
);
169 * @return verbose level preference
171 public String
getVerboseLevel() {
172 return fPreferenceStore
.getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF
);
176 * @return absolute log file path
178 public String
getLogfilePath() {
179 return fPreferenceStore
.getString(TRACE_CONTROL_LOG_FILE_PATH_PREF
);
182 // ------------------------------------------------------------------------
184 // ------------------------------------------------------------------------
187 * Initializes the control preferences (e.g. enable open log file)
189 * @param preferenceStore
190 * The preference store to assign
192 public void init(IPreferenceStore preferenceStore
) {
193 fPreferenceStore
= preferenceStore
;
195 if (fPreferenceStore
.getBoolean(ControlPreferences
.TRACE_CONTROL_LOG_COMMANDS_PREF
)) {
196 ControlCommandLogger
.init(getLogfilePath(), isAppend());
201 * Disposes any resource (e.g. close log file).
203 public void dispose() {
204 ControlCommandLogger
.close();