1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
;
15 import java
.nio
.ByteOrder
;
16 import java
.util
.HashMap
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.CTFStrings
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Encoding
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IntegerDeclaration
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
26 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.Stream
;
27 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
30 * Representation of one type of event. A bit like "int" or "long" but for trace
33 public class EventDeclaration
implements IEventDeclaration
{
35 /** Id of lost events */
36 public static final long LOST_EVENT_ID
= -1L;
38 /** Id of events when not set */
39 public static final long UNSET_EVENT_ID
= -2L;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
51 * Event context structure declaration
53 private StructDeclaration fContext
= null;
56 * Event fields structure declaration
58 private StructDeclaration fFields
= null;
61 * Event id (can be null if only event in the stream).
63 private Long fId
= UNSET_EVENT_ID
;
66 * Stream to which belongs this event.
68 private Stream fStream
= null;
71 * Loglevel of an event
73 private long fLogLevel
;
75 /** Map of this event type's custom CTF attributes */
76 private final Map
<String
, String
> fCustomAttributes
= new HashMap
<>();
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 * Default constructor. Use the setters afterwards to set the fields
86 public EventDeclaration() {
90 public EventDefinition
createDefinition(StreamInputReader streamInputReader
) {
91 EventDefinition event
= new EventDefinition(this, streamInputReader
);
93 if (fContext
!= null) {
94 event
.setContext(fContext
.createDefinition(event
, "context")); //$NON-NLS-1$
97 if (fFields
!= null) {
98 event
.setFields(fFields
.createDefinition(event
, "fields")); //$NON-NLS-1$
105 * Creates a "lost" event. This is a synthetic event that is there to show
106 * that there should be something there.
108 * @return the lost event
110 public static synchronized EventDeclaration
getLostEventDeclaration() {
111 EventDeclaration lostEvent
= new EventDeclaration();
112 IntegerDeclaration lostEventsDeclaration
= new IntegerDeclaration(32, false, 10, ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
113 IntegerDeclaration timestampDeclaration
= new IntegerDeclaration(64, false, 10, ByteOrder
.BIG_ENDIAN
, Encoding
.ASCII
, null, 8);
115 lostEvent
.fFields
= new StructDeclaration(1);
116 lostEvent
.fFields
.addField(CTFStrings
.LOST_EVENTS_FIELD
, lostEventsDeclaration
);
117 lostEvent
.fFields
.addField(CTFStrings
.LOST_EVENTS_DURATION
, timestampDeclaration
);
118 lostEvent
.fId
= LOST_EVENT_ID
;
119 lostEvent
.fName
= CTFStrings
.LOST_EVENT_NAME
;
124 // ------------------------------------------------------------------------
125 // Getters/Setters/Predicates
126 // ------------------------------------------------------------------------
129 * Sets a name for an event Declaration
134 public void setName(String name
) {
139 public String
getName() {
144 * Sets the context for an event declaration (see CTF specification)
147 * the context in structdeclaration format
149 public void setContext(StructDeclaration context
) {
154 * Sets the fields of an event declaration
157 * the fields in structdeclaration format
159 public void setFields(StructDeclaration fields
) {
164 public StructDeclaration
getFields() {
169 public StructDeclaration
getContext() {
174 * Sets the id of an event declaration
179 public void setId(long id
) {
184 public Long
getId() {
189 * Sets the stream of an event declaration
195 public void setStream(Stream stream
) {
200 public Stream
getStream() {
205 * Is the name of the event declaration set
207 * @return is the name set?
209 public boolean nameIsSet() {
210 return fName
!= null;
216 * @return is the context set
218 public boolean contextIsSet() {
219 return fContext
!= null;
225 * @return Is the field set?
227 public boolean fieldsIsSet() {
228 return fFields
!= null;
234 * @return is the id set?
236 public boolean idIsSet() {
237 return (fId
!= null && fId
!= UNSET_EVENT_ID
);
243 * @return is the stream set?
245 public boolean streamIsSet() {
246 return fStream
!= null;
250 public long getLogLevel() {
260 public void setLogLevel(long level
) {
265 public Set
<String
> getCustomAttributes() {
266 return fCustomAttributes
.keySet();
270 public String
getCustomAttribute(String key
) {
271 return fCustomAttributes
.get(key
);
275 * Sets a custom attribute value.
278 * the key of the attribute
280 * the value of the attribute
283 public void setCustomAttribute(String key
, String value
) {
284 fCustomAttributes
.put(key
, value
);
287 // ------------------------------------------------------------------------
289 // ------------------------------------------------------------------------
292 public boolean equals(Object obj
) {
299 if (!(obj
instanceof EventDeclaration
)) {
302 EventDeclaration other
= (EventDeclaration
) obj
;
303 if (fContext
== null) {
304 if (other
.fContext
!= null) {
307 } else if (!fContext
.equals(other
.fContext
)) {
310 if (fFields
== null) {
311 if (other
.fFields
!= null) {
314 } else if (!fFields
.equals(other
.fFields
)) {
318 if (other
.fId
!= null) {
321 } else if (!fId
.equals(other
.fId
)) {
325 if (other
.fName
!= null) {
328 } else if (!fName
.equals(other
.fName
)) {
331 if (fStream
== null) {
332 if (other
.fStream
!= null) {
335 } else if (!fStream
.equals(other
.fStream
)) {
338 if (!fCustomAttributes
.equals(other
.fCustomAttributes
)) {
345 public int hashCode() {
346 final int prime
= 31;
348 result
= (prime
* result
)
349 + ((fContext
== null) ?
0 : fContext
.hashCode());
350 result
= (prime
* result
) + ((fFields
== null) ?
0 : fFields
.hashCode());
351 result
= (prime
* result
) + ((fId
== null) ?
0 : fId
.hashCode());
352 result
= (prime
* result
) + ((fName
== null) ?
0 : fName
.hashCode());
353 result
= (prime
* result
) + ((fStream
== null) ?
0 : fStream
.hashCode());
354 result
= (prime
* result
) + fCustomAttributes
.hashCode();