~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2009 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
 
 *   Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11
 
 *******************************************************************************/
12
 
 
13
 
package org.eclipse.linuxtools.internal.lttng.stubs;
14
 
 
15
 
import java.io.FileNotFoundException;
16
 
import java.io.IOException;
17
 
import java.io.RandomAccessFile;
18
 
 
19
 
import org.eclipse.core.resources.IProject;
20
 
import org.eclipse.core.resources.IResource;
21
 
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
22
 
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
23
 
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
24
 
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
25
 
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
26
 
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
27
 
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
28
 
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
29
 
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
30
 
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
31
 
 
32
 
/**
33
 
 * <b><u>LTTngTraceStub</u></b>
34
 
 * <p>
35
 
 * Dummy test trace. Use in conjunction with LTTngEventParserStub.
36
 
 */
37
 
@SuppressWarnings("nls")
38
 
public class LTTngTraceStub extends TmfTrace<LttngEvent> implements ITmfEventParser<LttngEvent> {
39
 
 
40
 
    // ========================================================================
41
 
    // Attributes
42
 
    // ========================================================================
43
 
 
44
 
    // The actual stream
45
 
    private final RandomAccessFile fTrace;
46
 
 
47
 
    // The associated event parser
48
 
    private final ITmfEventParser<LttngEvent> fParser;
49
 
 
50
 
    // ========================================================================
51
 
    // Constructors
52
 
    // ========================================================================
53
 
 
54
 
    /**
55
 
     * @param filename
56
 
     * @param parser
57
 
     * @throws FileNotFoundException
58
 
     */
59
 
    public LTTngTraceStub(final IResource resource) throws TmfTraceException {
60
 
        this(resource, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE);
61
 
    }
62
 
 
63
 
    /**
64
 
     * @param filename
65
 
     * @param parser
66
 
     * @param cacheSize
67
 
     * @throws FileNotFoundException
68
 
     */
69
 
    public LTTngTraceStub(final IResource resource, final int cacheSize) throws TmfTraceException {
70
 
        //      super(resource, LttngEvent.class, resource.getName(), cacheSize, true);
71
 
        super(resource, LttngEvent.class, resource.getName(), cacheSize);
72
 
        try {
73
 
            fTrace = new RandomAccessFile(resource.getName(), "r");
74
 
        } catch (FileNotFoundException e) {
75
 
            throw new TmfTraceException(e.getMessage());
76
 
        }
77
 
        fParser = new LTTngEventParserStub();
78
 
    }
79
 
 
80
 
    public void indexTrace() {
81
 
        getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
82
 
    }
83
 
 
84
 
    // ========================================================================
85
 
    // Accessors
86
 
    // ========================================================================
87
 
 
88
 
    public RandomAccessFile getStream() {
89
 
        return fTrace;
90
 
    }
91
 
 
92
 
    // ========================================================================
93
 
    // Operators
94
 
    // ========================================================================
95
 
 
96
 
    /* (non-Javadoc)
97
 
     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
98
 
     */
99
 
    @Override
100
 
    @SuppressWarnings("unchecked")
101
 
    public TmfContext seekEvent(final ITmfLocation<?> location) {
102
 
        TmfContext context = null;
103
 
        try {
104
 
            synchronized(fTrace) {
105
 
                fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
106
 
                context = new TmfContext(getCurrentLocation(), 0);
107
 
                //                      TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
108
 
                //                      TmfEvent event = parseEvent(context2);
109
 
                //                      context.setTimestamp(event.getTimestamp());
110
 
            }
111
 
        } catch (final IOException e) {
112
 
            // TODO Auto-generated catch block
113
 
            e.printStackTrace();
114
 
        }
115
 
        return context;
116
 
    }
117
 
 
118
 
    @Override
119
 
    public TmfContext seekEvent(final double ratio) {
120
 
        // TODO Auto-generated method stub
121
 
        return null;
122
 
    }
123
 
 
124
 
    @Override
125
 
    public double getLocationRatio(final ITmfLocation<?> location) {
126
 
        // TODO Auto-generated method stub
127
 
        return 0;
128
 
    }
129
 
 
130
 
    /* (non-Javadoc)
131
 
     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
132
 
     */
133
 
    @Override
134
 
    public ITmfLocation<?> getCurrentLocation() {
135
 
        try {
136
 
            return new TmfLocation<Long>(fTrace.getFilePointer());
137
 
        } catch (final IOException e) {
138
 
            // TODO Auto-generated catch block
139
 
            e.printStackTrace();
140
 
        }
141
 
        return null;
142
 
    }
143
 
 
144
 
    /* (non-Javadoc)
145
 
     * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
146
 
     */
147
 
    @Override
148
 
    public LttngEvent parseEvent(final ITmfContext context) {
149
 
//        try {
150
 
            // paserNextEvent updates the context
151
 
            final LttngEvent event = (LttngEvent) fParser.parseEvent(context);
152
 
            //                          if (event != null) {
153
 
            //                                  context.setTimestamp(event.getTimestamp());
154
 
            //                          }
155
 
            return event;
156
 
//        }
157
 
//        catch (final IOException e) {
158
 
//            e.printStackTrace();
159
 
//        }
160
 
//        return null;
161
 
    }
162
 
 
163
 
    /* (non-Javadoc)
164
 
     * @see java.lang.Object#toString()
165
 
     */
166
 
    @Override
167
 
    public String toString() {
168
 
        return "[LTTngTraceStub]";
169
 
    }
170
 
 
171
 
    /* (non-Javadoc)
172
 
     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
173
 
     */
174
 
    @Override
175
 
    public boolean validate(IProject project, String path) {
176
 
        return fileExists(path);
177
 
    }
178
 
 
179
 
    //    // ========================================================================
180
 
    //    // Helper functions
181
 
    //    // ========================================================================
182
 
    //
183
 
    //    /* (non-Javadoc)
184
 
    //     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
185
 
    //     */
186
 
    //    public Map<String, Object> getAttributes() {
187
 
    //        // TODO Auto-generated method stub
188
 
    //        return null;
189
 
    //    }
190
 
 
191
 
}
 
 
b'\\ No newline at end of file'