lttng: Fix Javadoc and formatting in lttng2.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / preferences / ControlPreferences.java
CommitLineData
afe13e7a
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences;
13
0886cf00
BH
14import java.io.File;
15
afe13e7a 16import org.eclipse.jface.preference.IPreferenceStore;
afe13e7a
BH
17import 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 */
26public 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$
9315aeee
BH
57 /**
58 * The verbose level value for none
59 */
afe13e7a 60 public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE = "trace.control.verbose.level.none"; //$NON-NLS-1$
9315aeee
BH
61 /**
62 * The verbose level value for level 1 (-v)
63 */
afe13e7a 64 public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE = "trace.control.verbose.level.v"; //$NON-NLS-1$
9315aeee
BH
65 /**
66 * The verbose level value for level 2 (-vv)
67 */
afe13e7a 68 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE = "trace.control.verbose.level.vv"; //$NON-NLS-1$
9315aeee
BH
69 /**
70 * The verbose level value for level 3 (-vvv)
71 */
afe13e7a 72 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE = "trace.control.verbose.level.vvv"; //$NON-NLS-1$
9315aeee
BH
73 /**
74 * The default tracing group
75 */
76 public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP = "tracing"; //$NON-NLS-1$
77 /**
78 * The default tracing log file name with absolute path
79 */
0886cf00 80 public static final String TRACE_CONTROL_DEFAULT_LOG_PATH = System.getProperty("user.home") + File.separator + TRACE_CONTROL_LOG_FILENAME; //$NON-NLS-1$
afe13e7a
BH
81
82 // ------------------------------------------------------------------------
83 // Attributes
84 // ------------------------------------------------------------------------
9315aeee
BH
85 /**
86 * The trace control preferences singleton instance.
87 */
afe13e7a 88 private static ControlPreferences fInstance = null;
9315aeee
BH
89 /**
90 * The preference store reference
91 */
92 private IPreferenceStore fPreferenceStore = null;
afe13e7a
BH
93
94 // ------------------------------------------------------------------------
95 // Constructor
96 // ------------------------------------------------------------------------
9315aeee
BH
97 /**
98 * Private constructor
99 */
afe13e7a
BH
100 private ControlPreferences() {
101 }
102
103 // ------------------------------------------------------------------------
104 // Accessors
105 // ------------------------------------------------------------------------
9315aeee
BH
106 /**
107 * Returns the trace control preferences singleton instance
cfdb727a 108 *
9315aeee
BH
109 * @return the trace control preferences singleton instance
110 */
afe13e7a
BH
111 public synchronized static ControlPreferences getInstance() {
112 if (fInstance == null) {
113 fInstance = new ControlPreferences();
114 }
115 return fInstance;
116 }
117
118 /**
119 * @return the preference store
120 */
121 public IPreferenceStore getPreferenceStore() {
9315aeee 122 return fPreferenceStore;
afe13e7a
BH
123 }
124
125 /**
126 * @return true if tracing group is set to default
127 */
128 public boolean isDefaultTracingGroup() {
9315aeee 129 return fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF).equals(fPreferenceStore.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF));
afe13e7a
BH
130 }
131
132 /**
cfdb727a 133 * @return value of tracing group preference
afe13e7a
BH
134 */
135 public String getTracingGroup() {
9315aeee 136 return fPreferenceStore.getString(TRACE_CONTROL_TRACING_GROUP_PREF);
afe13e7a
BH
137 }
138
139 /**
cfdb727a 140 * @return whether is logging is enabled
afe13e7a
BH
141 */
142 public boolean isLoggingEnabled() {
9315aeee 143 return fPreferenceStore.getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF);
afe13e7a
BH
144 }
145
146 /**
cfdb727a 147 * @return whether an existing log file will appended or not
afe13e7a
BH
148 */
149 public boolean isAppend() {
9315aeee 150 return fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF);
afe13e7a
BH
151 }
152
153 /**
154 * @return verbose level preference
155 */
156 public String getVerboseLevel() {
9315aeee 157 return fPreferenceStore.getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF);
afe13e7a 158 }
cfdb727a 159
0886cf00
BH
160 /**
161 * @return absolute log file path
162 */
163 public String getLogfilePath() {
9315aeee 164 return fPreferenceStore.getString(TRACE_CONTROL_LOG_FILE_PATH_PREF);
0886cf00 165 }
cfdb727a 166
afe13e7a
BH
167 // ------------------------------------------------------------------------
168 // Operations
169 // ------------------------------------------------------------------------
cfdb727a 170
afe13e7a
BH
171 /**
172 * Initializes the control preferences (e.g. enable open log file)
cfdb727a
AM
173 *
174 * @param preferenceStore
175 * The preference store to assign
afe13e7a 176 */
9315aeee
BH
177 public void init(IPreferenceStore preferenceStore) {
178 fPreferenceStore = preferenceStore;
179
180 if (fPreferenceStore.getBoolean(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) {
0886cf00 181 ControlCommandLogger.init(getLogfilePath(), isAppend());
cfdb727a 182 }
afe13e7a
BH
183 }
184
185 /**
cfdb727a 186 * Disposes any resource (e.g. close log file).
afe13e7a
BH
187 */
188 public void dispose() {
189 ControlCommandLogger.close();
190 }
191}
This page took 0.034605 seconds and 5 git commands to generate.