Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfEventParserStub.java
index 131f75e128cf18e7800b78d21be1ea8e518397c1..eab0891473a8abaebd56697eb45237f183bb1f7d 100644 (file)
@@ -19,84 +19,100 @@ import java.util.Vector;
 
 import org.eclipse.linuxtools.tmf.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
-import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
 import org.eclipse.linuxtools.tmf.event.TmfEventReference;
 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
 import org.eclipse.linuxtools.tmf.event.TmfEventType;
 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
 
 /**
  * <b><u>TmfEventParserStub</u></b>
  * <p>
  * TODO: Implement me. Please.
  */
+@SuppressWarnings("nls")
 public class TmfEventParserStub implements ITmfEventParser {
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Attributes
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
-       private final int NB_FORMATS = 10;
-    private final TmfEventFormat[] fFormats;
+       private final int NB_TYPES = 10;
+    private final TmfEventType[] fTypes;
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Constructors
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
     public TmfEventParserStub() {
-       fFormats = new TmfEventFormat[NB_FORMATS];
-       for (int i = 0; i < NB_FORMATS; i++) {
+       fTypes = new TmfEventType[NB_TYPES];
+       for (int i = 0; i < NB_TYPES; i++) {
                Vector<String> format = new Vector<String>();
                for (int j = 1; j <= i; j++) {
                        format.add(new String("Fmt-" + i + "-Fld-" + j));
                }
                String[] fields = new String[i];
-               fFormats[i] = new TmfEventFormat(format.toArray(fields));
+               fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
        }
     }
 
-    // ========================================================================
+    // ------------------------------------------------------------------------
     // Operators
-    // ========================================================================
+    // ------------------------------------------------------------------------
 
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
-     */
     static final String typePrefix = "Type-";
-    public TmfEvent getNextEvent(ITmfTrace eventStream) throws IOException {
+    @Override
+       @SuppressWarnings("unchecked")
+       public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
 
         if (! (eventStream instanceof TmfTraceStub)) {
             return null;
         }
 
-        RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
-
-        try {
-            long ts        = stream.readLong();
-            String source  = stream.readUTF();
-            String type    = stream.readUTF();
-            int reference  = stream.readInt();
-            int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
-            String[] fields = new String[typeIndex];
-            for (int i = 0; i < typeIndex; i++) {
-                fields[i] = stream.readUTF();
-            }
-            String content = "[";
-            for (int i = 0; i < typeIndex - 1; i++) {
-                content += fields[i] + ", ";
-            }
-            content += "]";
-            
-            TmfEvent event = new TmfEvent(
-                    new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
-                    new TmfEventSource(source),
-                    new TmfEventType(type, fFormats[typeIndex]),
-                    new TmfEventContent(content, fFormats[typeIndex]),
-                    new TmfEventReference(reference));
-            return event;
-        } catch (EOFException e) {
-        }
+               // Highly inefficient...
+               RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
+               String name = eventStream.getName();
+               name = name.substring(name.lastIndexOf('/') + 1);
+
+               // no need to use synchronized since it's already cover by the calling method
+               
+               long location = 0;
+               if (context != null)
+                   location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
+               stream.seek(location);
+
+               try {
+                   long ts        = stream.readLong();
+                   String source  = stream.readUTF();
+                   String type    = stream.readUTF();
+                   @SuppressWarnings("unused")
+                   int reference  = stream.readInt();
+                   int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
+                   String[] fields = new String[typeIndex];
+                   for (int i = 0; i < typeIndex; i++) {
+                       fields[i] = stream.readUTF();
+                   }
+
+                   String content = "[";
+                   if (typeIndex > 0) {
+                       content += fields[0];
+                   }
+                   for (int i = 1; i < typeIndex; i++) {
+                       content += ", " + fields[i];
+                   }
+                   content += "]";
+
+                   TmfEvent event = new TmfEvent(
+                           new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
+                           new TmfEventSource(source),
+                           fTypes[typeIndex],
+                           new TmfEventReference(name));
+                   TmfEventContent cnt = new TmfEventContent(event, content);
+                   event.setContent(cnt);
+                   return event;
+               } catch (EOFException e) {
+               }
         return null;
     }
 
-}
+}
\ No newline at end of file
This page took 0.025733 seconds and 5 git commands to generate.