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