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