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