1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.pcap
.core
.event
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.internal
.tmf
.pcap
.core
.util
.ProtocolConversion
;
19 import org
.eclipse
.linuxtools
.pcap
.core
.packet
.Packet
;
20 import org
.eclipse
.linuxtools
.pcap
.core
.protocol
.Protocol
;
21 import org
.eclipse
.linuxtools
.pcap
.core
.protocol
.pcap
.PcapPacket
;
22 import org
.eclipse
.linuxtools
.pcap
.core
.stream
.PacketStream
;
23 import org
.eclipse
.linuxtools
.pcap
.core
.stream
.PacketStreamBuilder
;
24 import org
.eclipse
.linuxtools
.tmf
.pcap
.core
.protocol
.TmfProtocol
;
27 * Class that wraps a PacketStreamBuilder.
29 * @author Vincent Perot
31 public class TmfPacketStreamBuilder
{
33 private final PacketStreamBuilder fBuilder
;
39 * The protocol of the streams to build.
41 public TmfPacketStreamBuilder(TmfProtocol protocol
) {
42 fBuilder
= new PacketStreamBuilder(ProtocolConversion
.unwrap(protocol
));
46 * Method that adds an event to this builder.
51 public synchronized void addEventToStream(PcapEvent event
) {
52 Packet packet
= event
.getPacket().getPacket(Protocol
.PCAP
);
53 if (packet
== null || !(packet
instanceof PcapPacket
)) {
56 PcapPacket pcapPacket
= (PcapPacket
) packet
;
57 fBuilder
.addPacketToStream(pcapPacket
);
61 * Method that returns the number of streams built.
63 * @return The number of streams built.
65 public synchronized int getNbStreams() {
66 return fBuilder
.getNbStreams();
70 * Method that returns an iterable on the streams built so far.
72 * @return An iterable on the streams.
74 public synchronized Iterable
<TmfPacketStream
> getStreams() {
75 // We can't store in immutable list since the stream number/content can
76 // change dynamically.
77 List
<TmfPacketStream
> list
= new ArrayList
<>();
78 for (PacketStream stream
: fBuilder
.getStreams()) {
80 list
.add(new TmfPacketStream(stream
));