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