Fix some null warnings
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / preferences / ControlPreferences.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences;
13
14 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
15
16 import java.io.File;
17
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;
21
22 /**
23 * <p>
24 * Singleton class to access LTTng tracer control preferences.
25 * </p>
26 *
27 * @author Bernd Hufmann
28 */
29 public class ControlPreferences {
30
31 // ------------------------------------------------------------------------
32 // Constants
33 // ------------------------------------------------------------------------
34 /**
35 * Trace control log file
36 */
37 public static final String TRACE_CONTROL_LOG_FILENAME = "lttng_tracer_control.log"; //$NON-NLS-1$
38
39 // Preference strings
40 /**
41 * The tracing group preference
42 */
43 public static final String TRACE_CONTROL_TRACING_GROUP_PREF = "trace.control.tracing.group"; //$NON-NLS-1$
44 /**
45 * The log commands preference
46 */
47 public static final String TRACE_CONTROL_LOG_COMMANDS_PREF = "trace.control.log.commands"; //$NON-NLS-1$
48 /**
49 * The log append preference
50 */
51 public static final String TRACE_CONTROL_LOG_APPEND_PREF = "trace.control.log.append"; //$NON-NLS-1$
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 */
59 public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF = "trace.control.verbose.level"; //$NON-NLS-1$
60 /**
61 * The verbose level value for none
62 */
63 public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE = "trace.control.verbose.level.none"; //$NON-NLS-1$
64 /**
65 * The verbose level value for level 1 (-v)
66 */
67 public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE = "trace.control.verbose.level.v"; //$NON-NLS-1$
68 /**
69 * The verbose level value for level 2 (-vv)
70 */
71 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE = "trace.control.verbose.level.vv"; //$NON-NLS-1$
72 /**
73 * The verbose level value for level 3 (-vvv)
74 */
75 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE = "trace.control.verbose.level.vvv"; //$NON-NLS-1$
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 */
83 public static final String TRACE_CONTROL_DEFAULT_LOG_PATH = System.getProperty("user.home") + File.separator + TRACE_CONTROL_LOG_FILENAME; //$NON-NLS-1$
84 /**
85 * Default timeout value used for executing commands, in seconds
86 */
87 public static final int TRACE_CONTROL_DEFAULT_TIMEOUT_VALUE = 15;
88 /**
89 * Minimum timeout value used for executing commands, in seconds
90 */
91 public static final int TRACE_CONTROL_MIN_TIMEOUT_VALUE = 5;
92 /**
93 * Maximum timeout value used for executing commands, in seconds
94 */
95 public static final int TRACE_CONTROL_MAX_TIMEOUT_VALUE = 600;
96
97 // ------------------------------------------------------------------------
98 // Attributes
99 // ------------------------------------------------------------------------
100 /**
101 * The trace control preferences singleton instance.
102 */
103 private static ControlPreferences fInstance = null;
104 /**
105 * The preference store reference
106 */
107 private IPreferenceStore fPreferenceStore = null;
108
109 // ------------------------------------------------------------------------
110 // Constructor
111 // ------------------------------------------------------------------------
112 /**
113 * Private constructor
114 */
115 private ControlPreferences() {
116 }
117
118 // ------------------------------------------------------------------------
119 // Accessors
120 // ------------------------------------------------------------------------
121 /**
122 * Returns the trace control preferences singleton instance
123 *
124 * @return the trace control preferences singleton instance
125 */
126 public static synchronized ControlPreferences getInstance() {
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() {
137 return fPreferenceStore;
138 }
139
140 /**
141 * @return true if tracing group is set to default
142 */
143 public boolean isDefaultTracingGroup() {
144 return fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF).equals(fPreferenceStore.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF));
145 }
146
147 /**
148 * @return value of tracing group preference
149 */
150 public @NonNull String getTracingGroup() {
151 return checkNotNull(fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF));
152 }
153
154 /**
155 * @return whether is logging is enabled
156 */
157 public boolean isLoggingEnabled() {
158 return fPreferenceStore.getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF);
159 }
160
161 /**
162 * @return whether an existing log file will appended or not
163 */
164 public boolean isAppend() {
165 return fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF);
166 }
167
168 /**
169 * @return verbose level preference
170 */
171 public String getVerboseLevel() {
172 return fPreferenceStore.getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF);
173 }
174
175 /**
176 * @return absolute log file path
177 */
178 public String getLogfilePath() {
179 return fPreferenceStore.getString(TRACE_CONTROL_LOG_FILE_PATH_PREF);
180 }
181
182 // ------------------------------------------------------------------------
183 // Operations
184 // ------------------------------------------------------------------------
185
186 /**
187 * Initializes the control preferences (e.g. enable open log file)
188 *
189 * @param preferenceStore
190 * The preference store to assign
191 */
192 public void init(IPreferenceStore preferenceStore) {
193 fPreferenceStore = preferenceStore;
194
195 if (fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) {
196 ControlCommandLogger.init(getLogfilePath(), isAppend());
197 }
198 }
199
200 /**
201 * Disposes any resource (e.g. close log file).
202 */
203 public void dispose() {
204 ControlCommandLogger.close();
205 }
206 }
This page took 0.044822 seconds and 5 git commands to generate.