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