Internalize lttng.ui APIs
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / model / trange / TimeRangeEventResource.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.internal.lttng.ui.model.trange;
13
14 import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngTraceState;
15
16
17 /**
18 * @author alvaro
19 *
20 */
21 public abstract class TimeRangeEventResource extends TimeRangeComposite
22 implements
23 Comparable<TimeRangeEventResource> {
24
25 // ========================================================================
26 // Data
27 // =======================================================================
28 public static enum ResourceTypes {
29 UNKNOWN, IRQ, TRAP, SOFT_IRQ, BDEV, CPU
30 }
31
32 private ResourceTypes type = ResourceTypes.UNKNOWN;
33 private Long resourceId = null;
34
35 // ========================================================================
36 // Constructor
37 // =======================================================================
38 /**
39 * Constructor<br>
40 *
41 * @param newId Id used by the UI
42 * @param newStartTime normally set to the Trace start time
43 * @param newStopTime normally set to the Trace end time
44 * @param newName the name of this resource
45 * @param newGroupName the group name of this resource. Should be same as the traceId
46 * @param newClassName the classname of this resource.
47 * @param newType the type of the resource, as defined in the ResourceTypes enum
48 * @param newResourceId the resourceId, unique id identifying this resource
49 *
50 */
51 public TimeRangeEventResource(int newId, long newStartTime,
52 long newStopTime, String newName, String newGroupName,
53 String newClassName, ResourceTypes newType, Long newResourceId,
54 long insertionTime) {
55
56 super(newId, newStartTime, newStopTime, newName, newGroupName,
57 newClassName, CompositeType.RESOURCE, insertionTime);
58
59 type = newType;
60 resourceId = newResourceId;
61 }
62
63 // ========================================================================
64 // Methods
65 // =======================================================================
66
67 /**
68 * Interface to add children to this resource
69 *
70 * @param newEvent
71 */
72 public void addChildren(TimeRangeEvent newEvent) {
73 if ((newEvent != null)) {
74 this.ChildEventLeafs.add(newEvent);
75 }
76 }
77
78 /**
79 * @return
80 */
81 public Long getResourceId() {
82 return resourceId;
83 }
84
85 /**
86 * @param newResId
87 */
88 public void setResourceId(Long newResId) {
89 this.resourceId = newResId;
90 }
91
92 /**
93 * @return
94 */
95 public ResourceTypes getType() {
96 return type;
97 }
98
99 /**
100 * @param type
101 */
102 public void setType(ResourceTypes type) {
103 this.type = type;
104 }
105
106 /**
107 * Getter for traceId.<br>
108 * Note : traceId and groupName are the same for EventResource
109 *
110 * @return String
111 */
112 public String getTraceId() {
113 return groupName;
114 }
115
116 /**
117 * Getter for traceId.<br>
118 * Note : traceId and groupName are the same for EventResource
119 *
120 * @return String
121 */
122 public void setTraceId(String traceId) {
123 this.groupName = traceId;
124 }
125
126 // @Override
127 /*
128 * (non-Javadoc)
129 *
130 * @see java.lang.Object#toString()
131 */
132 // @Override
133 // public String toString() {
134 // return getResourceId().toString() + ":" + getTraceId().toString() + ":"
135 // + getType().toString();
136 // }
137
138 @Override
139 @SuppressWarnings("nls")
140 public String toString() {
141 return "[TimeRangeEventResource: " + super.toString() +
142 ",type=" + type + ",resourceId=" + resourceId + "]";
143 }
144
145 /**
146 * Compare function to implement Comparable<br>
147 * <br>
148 * Compare by traceId THEN IF EQUAL by resourceType THEN IF EQUAL by
149 * resourceId
150 *
151 * @param comparedResource
152 * The resource to compare to
153 *
154 * @return int 0 if equals, negative number if "smaller", positive if
155 * "bigger".
156 */
157 // @Override
158 @Override
159 public int compareTo(TimeRangeEventResource comparedResource) {
160 int returnedValue = 0;
161
162 if (comparedResource != null) {
163 // Compare by trace id first
164 returnedValue = this.getTraceId().compareTo(
165 comparedResource.getTraceId());
166
167 // If same, compare by resourceName
168 if (returnedValue == 0) {
169 returnedValue = this.getName().compareTo(
170 comparedResource.getName());
171
172 // Finally, if same, compare by ResourceId
173 if (returnedValue == 0) {
174 returnedValue = this.getResourceId().compareTo(
175 comparedResource.getResourceId());
176 }
177 }
178
179 }
180
181 return returnedValue;
182 }
183
184 public abstract String getStateMode(LttngTraceState traceState);
185 }
This page took 0.033786 seconds and 5 git commands to generate.