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