Add preferences for LTTng 2.0 tracer control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / preferences / ControlPreferences.java
1 /**********************************************************************
2 * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.preferences;
13
14 import org.eclipse.jface.preference.IPreferenceStore;
15 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
16 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger;
17
18 /**
19 * <b><u>ControlPreference</u></b>
20 * <p>
21 * Singleton class to access LTTng tracer control preferences.
22 * </p>
23 */
24 public class ControlPreferences {
25
26 // ------------------------------------------------------------------------
27 // Constants
28 // ------------------------------------------------------------------------
29 public static final String TRACE_CONTROL_LOG_FILENAME = "lttng_control.log"; //$NON-NLS-1$
30
31 // Preference strings
32 public static final String TRACE_CONTROL_TRACING_GROUP_PREF = "trace.control.tracing.group"; //$NON-NLS-1$
33 public static final String TRACE_CONTROL_LOG_COMMANDS_PREF = "trace.control.log.commands"; //$NON-NLS-1$
34 public static final String TRACE_CONTROL_LOG_APPEND_PREF = "trace.control.log.append"; //$NON-NLS-1$
35 public static final String TRACE_CONTROL_LOG_FILE_PATH_PREF = "trace.control.log.path"; //$NON-NLS-1$
36 public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF = "trace.control.verbose.level"; //$NON-NLS-1$
37 public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE = "trace.control.verbose.level.none"; //$NON-NLS-1$
38 public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE = "trace.control.verbose.level.v"; //$NON-NLS-1$
39 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE = "trace.control.verbose.level.vv"; //$NON-NLS-1$
40 public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE = "trace.control.verbose.level.vvv"; //$NON-NLS-1$
41
42 public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP = "tracing"; //$NON-NLS-1$
43 public static final String TRACE_CONTROL_DEFAULT_LOG_PATH = "${workspace_loc}/" + TRACE_CONTROL_LOG_FILENAME; //$NON-NLS-1$
44
45 // ------------------------------------------------------------------------
46 // Attributes
47 // ------------------------------------------------------------------------
48 private static ControlPreferences fInstance = null;
49
50 // ------------------------------------------------------------------------
51 // Constructor
52 // ------------------------------------------------------------------------
53 private ControlPreferences() {
54 }
55
56 // ------------------------------------------------------------------------
57 // Accessors
58 // ------------------------------------------------------------------------
59 public synchronized static ControlPreferences getInstance() {
60 if (fInstance == null) {
61 fInstance = new ControlPreferences();
62 }
63 return fInstance;
64 }
65
66 /**
67 * @return the preference store
68 */
69 public IPreferenceStore getPreferenceStore() {
70 return Activator.getDefault().getPreferenceStore();
71 }
72
73 /**
74 * @return true if tracing group is set to default
75 */
76 public boolean isDefaultTracingGroup() {
77 IPreferenceStore store = getPreferenceStore();
78 return store.getString(TRACE_CONTROL_TRACING_GROUP_PREF).equals(store.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF));
79 }
80
81 /**
82 * @return value of tracing group preference
83 */
84 public String getTracingGroup() {
85 return getPreferenceStore().getString(TRACE_CONTROL_TRACING_GROUP_PREF);
86 }
87
88 /**
89 * @return whether is logging is enabled
90 */
91 public boolean isLoggingEnabled() {
92 return getPreferenceStore().getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF);
93 }
94
95 /**
96 * @return whether an existing log file will appended or not
97 */
98 public boolean isAppend() {
99 return getPreferenceStore().getBoolean(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF);
100 }
101
102 /**
103 * @return verbose level preference
104 */
105 public String getVerboseLevel() {
106 return getPreferenceStore().getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF);
107 }
108
109 // ------------------------------------------------------------------------
110 // Operations
111 // ------------------------------------------------------------------------
112 /**
113 * Initializes the control preferences (e.g. enable open log file)
114 */
115 public void init() {
116 if (getPreferenceStore().getBoolean(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) {
117 ControlCommandLogger.init(ControlPreferences.TRACE_CONTROL_LOG_FILENAME, isAppend());
118 }
119 }
120
121 /**
122 * Disposes any resource (e.g. close log file).
123 */
124 public void dispose() {
125 ControlCommandLogger.close();
126 }
127 }
This page took 0.048925 seconds and 5 git commands to generate.