tmf: Integration of the pcap parser within TMF
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.pcap.core / src / org / eclipse / linuxtools / tmf / pcap / core / event / PcapRootEventField.java
1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.pcap.core.event;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.linuxtools.pcap.core.packet.Packet;
17 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
18 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
19
20 /**
21 * Class that represents the root node of Pcap Event Field.
22 *
23 * @author Vincent Perot
24 */
25 public class PcapRootEventField extends TmfEventField {
26
27 private final TmfEventField fPacketSourceField;
28 private final TmfEventField fPacketDestinationField;
29 private final TmfEventField fProtocolField;
30 private final String fSummaryString;
31
32 /**
33 * Full constructor
34 *
35 * @param value
36 * The event field value.
37 * @param fields
38 * The list of subfields.
39 * @param packet
40 * The packet from which to take the fields from.
41 * @throws IllegalArgumentException
42 * If 'name' is null, or if 'fields' has duplicate field names.
43 */
44 public PcapRootEventField(Object value, @Nullable ITmfEventField[] fields, Packet packet) {
45 super(ITmfEventField.ROOT_FIELD_ID, value, fields);
46 fPacketSourceField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_SOURCE,
47 packet.getMostEcapsulatedPacket().getSourceEndpoint().toString(), null);
48 fPacketDestinationField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_DESTINATION,
49 packet.getMostEcapsulatedPacket().getDestinationEndpoint().toString(), null);
50 fProtocolField = new TmfEventField(PcapEvent.EVENT_FIELD_PACKET_PROTOCOL,
51 packet.getMostEcapsulatedPacket().getProtocol().getShortName().toUpperCase(), null);
52 fSummaryString = packet.getGlobalSummaryString();
53 }
54
55 /**
56 * Copy constructor
57 *
58 * @param field
59 * the other event field
60 */
61 public PcapRootEventField(final PcapRootEventField field) {
62 super(field);
63 fPacketSourceField = field.fPacketSourceField;
64 fPacketDestinationField = field.fPacketDestinationField;
65 fProtocolField = field.fProtocolField;
66 fSummaryString = field.fSummaryString;
67 }
68
69 @Override
70 public String toString() {
71 return fSummaryString;
72 }
73
74 @Override
75 public @Nullable ITmfEventField getField(@Nullable String name) {
76 if (name == null) {
77 return null;
78 }
79 switch (name) {
80 case PcapEvent.EVENT_FIELD_PACKET_SOURCE:
81 return fPacketSourceField;
82 case PcapEvent.EVENT_FIELD_PACKET_DESTINATION:
83 return fPacketDestinationField;
84 case PcapEvent.EVENT_FIELD_PACKET_PROTOCOL:
85 return fProtocolField;
86 default:
87 return super.getField(name);
88 }
89 }
90 }
This page took 0.033656 seconds and 5 git commands to generate.