Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 67bf70891bb8faa7f823485dd9022623dda54dbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package org.eclipse.linuxtools.tmf.core.ctfadaptor;

import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;

public class CtfIterator extends CTFTraceReader implements ITmfContext,
        Comparable<CtfIterator> {

    private final CtfTmfTrace ctfTmfTrace;

    private CtfLocation curLocation;
    private final long curRank;

    /**
     * Create a new CTF trace iterator, which initially points at the first
     * event in the trace.
     *
     * @param trace
     */
    public CtfIterator(CtfTmfTrace trace) {
        super(trace.getCTFTrace());
        this.ctfTmfTrace = trace;

        // FIXME put the real stuff here...
        this.curLocation = new CtfLocation(trace.getStartTime());
        this.curRank = 0;
    }

    public CtfIterator(CtfTmfTrace trace, long timestampValue, long rank) {
        super(trace.getCTFTrace());
        this.ctfTmfTrace = trace;
        this.curLocation = (new CtfLocation(this.getCurrentEvent()
                .getTimestampValue()));
        if (this.getCurrentEvent().getTimestampValue() != timestampValue) {
            this.seek(timestampValue);
        }

        this.curRank = rank;
    }

    public CtfTmfTrace getCtfTmfTrace() {
        return ctfTmfTrace;
    }

    public CtfTmfEvent getCurrentEvent() {
        StreamInputReader top = super.prio.peek();
        if (top != null) {
            return new CtfTmfEvent(top.getCurrentEvent(), top, ctfTmfTrace);
        }
        return null;
    }

    @Override
    public boolean seek(long timestamp) {
        boolean ret = false;
        long offsetTimestamp = timestamp - this.getCtfTmfTrace().getCTFTrace().getOffset();
        if( offsetTimestamp < 0 ) {
            ret = super.seek(timestamp);
        } else {
            ret = super.seek(offsetTimestamp);
        }

        if (ret) {
            curLocation.setLocation(getCurrentEvent().getTimestampValue());
        }
        return ret;
    }

    public boolean seekRank(long rank) {
        boolean ret = false;
        ret = super.seekIndex(rank);

        if (ret) {
            curLocation.setLocation(getCurrentEvent().getTimestampValue());
        }
        return ret;
    }

    @Override
    public long getRank() {
        return super.getIndex();
    }

    @Override
    public void setRank(long rank) {
        seekRank(rank);
    }

    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone()
     */
    @Override
    public CtfIterator clone() {
        CtfIterator clone = null;
        clone = new CtfIterator(ctfTmfTrace, this.getCurrentEvent()
                .getTimestampValue(), curRank);
        return clone;
    }

    @Override
    public void dispose() {
        // FIXME add dispose() stuff to CTFTrace and call it here...

    }

    @Override
    public void setLocation(ITmfLocation<?> location) {
        // FIXME alex: isn't there a cleaner way than a cast here?
        this.curLocation = (CtfLocation) location;
        seek(((CtfLocation)location).getLocation());
    }

    @Override
    public CtfLocation getLocation() {
        return curLocation;
    }

    @SuppressWarnings("unused")
    @Override
    public void updateRank(int rank) {
        // not needed I think
    }

    @Override
    public boolean isValidRank() {
        return (getRank() > -1);
    }

    @Override
    public boolean advance() {
        return super.advance();
    }

    @Override
    public int compareTo(CtfIterator o) {
        if (this.getRank() < o.getRank()) {
            return -1;
        } else if (this.getRank() > o.getRank()) {
            return 1;
        }
        return 0;
    }

}

Back to the top