Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2014-04-18 18:11:37 +0000
committerMatthew Khouzam2014-05-02 16:50:06 +0000
commitafe42d45e4465a5afc3e92c97329d71c46443932 (patch)
treeb4802119d36f6c4a73ea34c16ad60b4b2f619e90
parentb49974f099c89f5ddc4c6f5b11c8f4db4c820459 (diff)
downloadorg.eclipse.linuxtools-afe42d45e4465a5afc3e92c97329d71c46443932.tar.gz
org.eclipse.linuxtools-afe42d45e4465a5afc3e92c97329d71c46443932.tar.xz
org.eclipse.linuxtools-afe42d45e4465a5afc3e92c97329d71c46443932.zip
lttng: Add Lttng relayd connector
This allows connections to the lttng session daemon so that live trace reading can work. (rebased on lttng: Rename lttng2 feature/plugins to lttng2.control) Conflicts: Everything (then rebased on ctf: immutable events) LttngRelaydConsumer updated Change-Id: Ida7f76f09d3f01a25b67cc552cb5869dc5e4c3a4 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/23564 Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java3
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java41
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java24
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java32
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java39
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core.tests/META-INF/MANIFEST.MF4
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/relayd/LttngRelayd24Test.java107
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/META-INF/MANIFEST.MF9
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/build.properties2
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/ILttngRelaydConnector.java119
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConnectorFactory.java73
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConsumer.java135
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_2_4.java181
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_Unsupported.java76
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachReturnCode.java47
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionRequest.java81
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionResponse.java92
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/Command.java56
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectResponse.java126
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectionType.java40
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionResponse.java62
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionReturnCode.java39
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadata.java65
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadataReturnCode.java42
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetNextIndex.java64
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacket.java92
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacketReturnCode.java44
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IBaseCommand.java30
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayCommand.java31
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayResponse.java24
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IndexResponse.java160
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ListSessionsResponse.java72
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/LttngViewerCommands.java37
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/MetadataPacketResponse.java74
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsRequest.java54
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsResponse.java91
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsReturnCode.java43
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NextIndexReturnCode.java47
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SeekCommand.java44
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SessionResponse.java126
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/StreamResponse.java125
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/TracePacketResponse.java88
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ViewerCommand.java94
43 files changed, 2796 insertions, 39 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
index 44732da1fe..82e78514c0 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
@@ -16,7 +16,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import java.io.File;
-import java.nio.channels.FileChannel;
import java.util.Set;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
@@ -114,7 +113,7 @@ public class StreamInputReaderTest {
@Test(expected = CTFReaderException.class)
public void testStreamInputReader_invalid() throws CTFReaderException {
StreamInput streamInput = new StreamInput(
- new Stream(new CTFTrace("")), (FileChannel) null, new File(""));
+ new Stream(new CTFTrace("")), new File(""));
StreamInputReader result = new StreamInputReader(streamInput);
assertNotNull(result);
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
index 641db4babb..472ef02068 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.io.File;
-import java.nio.channels.FileChannel;
+import java.io.FilenameFilter;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
@@ -51,13 +51,21 @@ public class StreamInputTest {
@Before
public void setUp() throws CTFReaderException {
assumeTrue(testTrace.exists());
- fixture = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
+ fixture = new StreamInput(new Stream(testTrace.getTrace()), createFile());
fixture.setTimestampEnd(1L);
}
private static File createFile() {
- return new File("Tests/traces/trace20m/channel_0");
+ File path = new File(testTrace.getPath());
+ return path.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ if (name.contains("hann")) {
+ return true;
+ }
+ return false;
+ }
+ })[0];
}
/**
@@ -125,34 +133,35 @@ public class StreamInputTest {
StreamInput s1;
StreamInput s2;
-
@Test
- public void testEquals1() throws CTFReaderException{
+ public void testEquals1() throws CTFReaderException {
s1 = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
+ createFile());
assertFalse(s1.equals(null));
}
@Test
- public void testEquals2() throws CTFReaderException{
+ public void testEquals2() throws CTFReaderException {
s1 = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
+ createFile());
assertFalse(s1.equals(new Long(23L)));
}
+
@Test
- public void testEquals3() throws CTFReaderException{
+ public void testEquals3() throws CTFReaderException {
s1 = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
- assertEquals(s1,s1);
+ createFile());
+ assertEquals(s1, s1);
}
+
@Test
- public void testEquals4() throws CTFReaderException{
+ public void testEquals4() throws CTFReaderException {
s1 = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
+ createFile());
s2 = new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, createFile());
- assertEquals(s1,s2);
+ createFile());
+ assertEquals(s1, s2);
}
} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java
index 4826e66313..68fe8a81f9 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamTest.java
@@ -16,7 +16,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.io.File;
-import java.nio.channels.FileChannel;
+import java.io.FilenameFilter;
import java.util.Map;
import java.util.Set;
@@ -59,8 +59,20 @@ public class StreamTest {
fixture.setPacketContext(new StructDeclaration(1L));
fixture.setEventHeader(new StructDeclaration(1L));
fixture.setId(1L);
- fixture.addInput(new StreamInput(new Stream(testTrace.getTrace()),
- (FileChannel) null, new File("")));
+ fixture.addInput(new StreamInput(new Stream(testTrace.getTrace()), createFile()));
+ }
+
+ private static File createFile() {
+ File path = new File(testTrace.getPath());
+ return path.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ if (name.contains("hann")) {
+ return true;
+ }
+ return false;
+ }
+ })[0];
}
/**
@@ -76,8 +88,8 @@ public class StreamTest {
}
/**
- * Run the void addEvent(EventDeclaration) method test with the basic
- * event.
+ * Run the void addEvent(EventDeclaration) method test with the basic event.
+ *
* @throws ParseException
*/
@Test
@@ -93,6 +105,7 @@ public class StreamTest {
public void testEventContextIsSet() {
assertTrue(fixture.isEventContextSet());
}
+
/**
* Run the boolean eventContextIsSet() method test.
*/
@@ -188,7 +201,6 @@ public class StreamTest {
assertTrue(result);
}
-
/**
* Run the void setEventContext(StructDeclaration) method test.
*/
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
index 757dc917ab..b945cf12d6 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
@@ -576,11 +576,11 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
throw new CTFReaderException("Unexpected end of stream"); //$NON-NLS-1$
}
- /* Create the stream input */
- StreamInput streamInput = new StreamInput(stream, fc, streamFile);
-
- /* Add a reference to the streamInput in the stream */
- stream.addInput(streamInput);
+ /*
+ * Create the stream input and add a reference to the streamInput in the
+ * stream
+ */
+ stream.addInput(new StreamInput(stream, streamFile));
return stream;
}
@@ -892,6 +892,28 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
}
return callsite;
}
+
+ /**
+ * Add a new stream
+ *
+ * @param id
+ * the ID of the stream
+ * @param streamFile
+ * new file in the stream
+ * @throws CTFReaderException
+ * The file must exist
+ * @since 3.0
+ */
+ public void addStream(long id, File streamFile) throws CTFReaderException {
+ Stream stream = null;
+ if (fStreams.containsKey(id)) {
+ stream = fStreams.get(id);
+ } else {
+ stream = new Stream(this);
+ fStreams.put(id, stream);
+ }
+ stream.addInput(new StreamInput(stream, streamFile));
+ }
}
class MetadataFileFilter implements FileFilter {
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
index 5ae963aa25..10f41626ff 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
@@ -13,6 +13,8 @@
package org.eclipse.linuxtools.ctf.core.trace;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@@ -41,7 +43,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr
*
* @since 2.0
*/
-public class StreamInput implements IDefinitionScope {
+public class StreamInput implements IDefinitionScope, AutoCloseable {
// ------------------------------------------------------------------------
// Attributes
@@ -69,21 +71,26 @@ public class StreamInput implements IDefinitionScope {
private long fTimestampEnd;
- /*
+ /**
* Definition of trace packet header
*/
private StructDeclaration fTracePacketHeaderDecl = null;
- /*
+ /**
* Definition of trace stream packet context
*/
private StructDeclaration fStreamPacketContextDecl = null;
- /*
+ /**
* Total number of lost events in this stream
*/
private long fLostSoFar = 0;
+ /**
+ * File input stream, the parent input file
+ */
+ private final FileInputStream fFileInputStream;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
@@ -93,18 +100,34 @@ public class StreamInput implements IDefinitionScope {
*
* @param stream
* The stream to which this StreamInput belongs to.
- * @param fileChannel
- * The FileChannel to the trace file.
* @param file
* Information about the trace file (for debugging purposes).
+ * @throws CTFReaderException
+ * The file must exist
+ * @since 3.0
*/
- public StreamInput(Stream stream, FileChannel fileChannel, File file) {
+ public StreamInput(Stream stream, File file) throws CTFReaderException {
fStream = stream;
- fFileChannel = fileChannel;
fFile = file;
+ try {
+ fFileInputStream = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new CTFReaderException(e);
+ }
+
+ fFileChannel = fFileInputStream.getChannel();
fIndex = new StreamInputPacketIndex();
}
+ /**
+ * @since 3.0
+ */
+ @Override
+ public void close() throws IOException {
+ fFileChannel.close();
+ fFileInputStream.close();
+ }
+
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/META-INF/MANIFEST.MF
index 70582811f9..3400863498 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/META-INF/MANIFEST.MF
@@ -11,4 +11,6 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
org.eclipse.core.runtime,
org.eclipse.linuxtools.lttng2.control.core;bundle-version="3.0.0"
Export-Package: org.eclipse.linuxtools.lttng2.control.core.tests;x-friends:="org.eclipse.linuxtools.lttng.alltests",
- org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;x-internal:=true
+ org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;x-internal:=true,
+ org.eclipse.linuxtools.lttng2.control.core.tests.relayd,
+ org.eclipse.linuxtools.lttng2.control.core.tests.session
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/relayd/LttngRelayd24Test.java b/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/relayd/LttngRelayd24Test.java
new file mode 100644
index 0000000000..4914b94adf
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/relayd/LttngRelayd24Test.java
@@ -0,0 +1,107 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.lttng2.control.core.tests.relayd;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.ILttngRelaydConnector;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.LttngRelaydConnectorFactory;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.Command;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ConnectResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.CreateSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.CreateSessionReturnCode;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.GetNextIndex;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.IndexResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.NextIndexReturnCode;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.StreamResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ViewerCommand;
+import org.junit.Test;
+
+/**
+ * Unit tests for lttng-relayd. It actually allows us to test the API.
+ *
+ * @author Matthew Khouzam
+ */
+public class LttngRelayd24Test {
+
+ private static final int PACKETS_TO_READ = 100;
+ private static final String ADDRESS = "127.0.0.1"; // change me //$NON-NLS-1$
+ private static final int PORT = 5344;
+
+ private static void getPackets(AttachSessionResponse attachedSession, Socket connection, ILttngRelaydConnector relayD) throws IOException {
+ int numPacketsReceived = 0;
+ DataOutputStream fOutNet = new DataOutputStream(connection.getOutputStream());
+ DataInputStream fInNet = new DataInputStream(connection.getInputStream());
+ while (numPacketsReceived < PACKETS_TO_READ) {
+ for (StreamResponse stream : attachedSession.getStreamList()) {
+ if (stream.getMetadataFlag() != 1) {
+ ConnectResponse connectPayload = new ConnectResponse(fInNet);
+ assertNotNull(connectPayload);
+
+ ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_GET_NEXT_INDEX, ConnectResponse.SIZE, 0);
+ fOutNet.write(connectCommand.serialize());
+ fOutNet.flush();
+
+ GetNextIndex indexRequest = new GetNextIndex(stream.getId());
+ fOutNet.write(indexRequest.serialize());
+ fOutNet.flush();
+
+ IndexResponse indexReply = new IndexResponse(fInNet);
+ // Nothing else supported for now
+ if (indexReply.getStatus() == NextIndexReturnCode.VIEWER_INDEX_OK) {
+ if (relayD.getPacketFromStream(indexReply, stream.getId()) != null) {
+ numPacketsReceived++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Test a connection
+ *
+ * @throws IOException
+ * network timeout?
+ */
+ @Test
+ public void testViewerConnection() throws IOException {
+ InetAddress addr = InetAddress.getByName(ADDRESS);
+ try (Socket connection = new Socket(addr, PORT)) {
+ ILttngRelaydConnector relayD = LttngRelaydConnectorFactory.getNewConnector(connection);
+ List<SessionResponse> sessions = relayD.getSessions();
+ assertTrue(sessions.size() > 0);
+ SessionResponse lttngViewerSession = sessions.get(0);
+ assertNotNull(lttngViewerSession);
+ CreateSessionResponse createSession = relayD.createSession();
+ assertEquals(createSession.getStatus(), CreateSessionReturnCode.LTTNG_VIEWER_CREATE_SESSION_OK);
+ AttachSessionResponse attachedSession = relayD.attachToSession(lttngViewerSession);
+
+ String metaData = relayD.getMetadata(attachedSession);
+ assertNotNull(metaData);
+
+ getPackets(attachedSession, connection, relayD);
+ }
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.lttng2.control.core/META-INF/MANIFEST.MF
index 342881b044..8f45a6c349 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.control.core/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/META-INF/MANIFEST.MF
@@ -8,8 +8,15 @@ Bundle-SymbolicName: org.eclipse.linuxtools.lttng2.control.core;singleton:=true
Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.control.core.Activator
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
-Require-Bundle: org.eclipse.core.runtime
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.linuxtools.ctf.core;bundle-version="3.0.0",
+ org.eclipse.linuxtools.tmf.core;bundle-version="3.0.0",
+ org.eclipse.linuxtools.tmf.ctf.core;bundle-version="3.0.0"
Export-Package: org.eclipse.linuxtools.internal.lttng2.control.core;x-friends:="org.eclipse.linuxtools.lttng2.control.core.tests",
org.eclipse.linuxtools.internal.lttng2.control.core.model;x-friends:="org.eclipse.linuxtools.lttng2.control.ui,org.eclipse.linuxtools.lttng2.control.ui.tests,org.eclipse.linuxtools.lttng2.control.core.tests",
org.eclipse.linuxtools.internal.lttng2.control.core.model.impl;x-friends:="org.eclipse.linuxtools.lttng2.control.ui,org.eclipse.linuxtools.lttng2.control.ui.tests,org.eclipse.linuxtools.lttng2.control.core.tests",
+ org.eclipse.linuxtools.internal.lttng2.control.core.relayd;x-friends:="org.eclipse.linuxtools.lttng2.control.core.tests,org.eclipse.linuxtools.lttng2.control.ui,org.eclipse.linuxtools.lttng2.control.ui.tests",
+ org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl;x-friends:="org.eclipse.linuxtools.lttng2.control.core.tests,org.eclipse.linuxtools.lttng2.control.ui,org.eclipse.linuxtools.lttng2.control.ui.tests",
+ org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;x-friends:="org.eclipse.linuxtools.lttng2.control.core.tests,org.eclipse.linuxtools.lttng2.control.ui,org.eclipse.linuxtools.lttng2.control.ui.tests",
org.eclipse.linuxtools.lttng2.control.core.session
+Import-Package: com.google.common.collect
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/build.properties b/lttng/org.eclipse.linuxtools.lttng2.control.core/build.properties
index ddfbe617f6..7a2207a1a0 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.control.core/build.properties
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/build.properties
@@ -17,3 +17,5 @@ bin.includes = META-INF/,\
about.html,\
plugin.properties
src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/ILttngRelaydConnector.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/ILttngRelaydConnector.java
new file mode 100644
index 0000000000..88f376b566
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/ILttngRelaydConnector.java
@@ -0,0 +1,119 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.CreateSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.IndexResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.StreamResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.TracePacketResponse;
+
+/**
+ * Connector for Lttng Relayd
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface ILttngRelaydConnector extends AutoCloseable {
+
+ /**
+ * Gets a list of active Lttng sessions
+ *
+ * @return the session List (we need the get function)
+ * @throws IOException
+ * timeout and such
+ */
+ List<SessionResponse> getSessions() throws IOException;
+
+ /**
+ * Create a session
+ *
+ * @return create session response
+ * @throws IOException
+ * timeout and such
+ */
+ CreateSessionResponse createSession() throws IOException;
+
+ /**
+ * Attach the trace viewer to a Session
+ *
+ * @param lttngViewerSession
+ * viewer session
+ * @return An AttachSessionResponse
+ * @throws IOException
+ * timeout and such
+ */
+ AttachSessionResponse attachToSession(SessionResponse lttngViewerSession) throws IOException;
+
+ /**
+ * Get the metadata from the relayd
+ *
+ * @param attachedSession
+ * the attached session
+ * @return a chunk of TSDL metadata
+ * @throws IOException
+ * timeout and such
+ */
+ String getMetadata(AttachSessionResponse attachedSession) throws IOException;
+
+ /**
+ * Get the next index
+ *
+ * @param stream
+ * the stream
+ * @return the stream input packet entry
+ * @throws IOException
+ * timeout and such
+ */
+ IndexResponse getNextIndex(StreamResponse stream) throws IOException;
+
+ /**
+ * Get the next packet in a stream
+ *
+ * @param stream
+ * the stream response
+ * @return the packet response
+ * @throws IOException
+ * timeout and such
+ */
+ TracePacketResponse getNextPacket(StreamResponse stream) throws IOException;
+
+ /**
+ * Gets the packet from the stream
+ *
+ * @param index
+ * the index of the stream
+ * @param id
+ * the stream id
+ * @return the packet response
+ * @throws IOException
+ * timeout and such
+ */
+ TracePacketResponse getPacketFromStream(IndexResponse index, long id) throws IOException;
+
+ /**
+ * Gets the new streams
+ *
+ * @return a list of stream responses
+ * @throws IOException
+ * timeout and such
+ */
+ Iterable<StreamResponse> getNewStreams() throws IOException;
+
+ @Override
+ void close() throws IOException;
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConnectorFactory.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConnectorFactory.java
new file mode 100644
index 0000000000..a3f4113712
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConnectorFactory.java
@@ -0,0 +1,73 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl.LttngRelaydConnector_2_4;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl.LttngRelaydConnector_Unsupported;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.Command;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ConnectResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ViewerCommand;
+
+/**
+ * LTTng RelayD connector factory
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public final class LttngRelaydConnectorFactory {
+
+ private LttngRelaydConnectorFactory() {
+ }
+
+ /**
+ * Create a connection to a relayd
+ *
+ * @param myConnection
+ * a connection to the relayd
+ *
+ * @return A relayd connector
+ * @throws IOException
+ * caused by invalid sockets
+ */
+ public static ILttngRelaydConnector getNewConnector(Socket myConnection) throws IOException {
+ DataOutputStream outNet = new DataOutputStream(myConnection.getOutputStream());
+ DataInputStream inNet = new DataInputStream(myConnection.getInputStream());
+
+ ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_CONNECT, ConnectResponse.SIZE, 0);
+
+ outNet.write(connectCommand.serialize());
+ outNet.flush();
+
+ ConnectResponse connectReply = new ConnectResponse(inNet);
+ switch (connectReply.getMajor()) {
+ case 2:
+ switch (connectReply.getMinor()) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ return new LttngRelaydConnector_Unsupported();
+ case 4:
+ default:
+ return new LttngRelaydConnector_2_4(inNet, outNet);
+ }
+ default:
+ return new LttngRelaydConnector_Unsupported();
+ }
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConsumer.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConsumer.java
new file mode 100644
index 0000000000..ad669de747
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/LttngRelaydConsumer.java
@@ -0,0 +1,135 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.Metadata;
+import org.eclipse.linuxtools.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.lttng2.control.core.Activator;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.LttngViewerCommands;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.StreamResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.TracePacketResponse;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
+
+/**
+ * Consumer of the relay d
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class LttngRelaydConsumer {
+
+ private final Job fConsumerJob;
+ private final String fAddress;
+ private final int fPort;
+ private final int fSession;
+ private final CtfTmfTrace fCtfTrace;
+ /**
+ * Map with the Lttng streams
+ *
+ * key: stream id value: stream file
+ */
+ private final Map<Long, File> fStreams = new TreeMap<>();
+
+ /**
+ * Start a lttng consumer
+ *
+ * @param address
+ * the ip address in string format
+ * @param port
+ * the port, an integer
+ * @param session
+ * the session id
+ * @param ctfTrace
+ * the parent trace
+ */
+ public LttngRelaydConsumer(String address, final int port, final int session, final CtfTmfTrace ctfTrace) {
+ fAddress = address;
+ fPort = port;
+ fSession = session;
+ fCtfTrace = ctfTrace;
+ for (Stream s : fCtfTrace.getCTFTrace().getStreams()) {
+ for (StreamInput si : s.getStreamInputs()) {
+ fStreams.put(si.getStream().getId(), new File(si.getStream().getTrace().getPath() + si.getFilename()));
+ }
+ }
+
+ fConsumerJob = new Job("RelayD consumer") { //$NON-NLS-1$
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try (Socket connection = new Socket(fAddress, fPort);
+ ILttngRelaydConnector relayd = LttngRelaydConnectorFactory.getNewConnector(connection);) {
+
+ List<SessionResponse> sessions = relayd.getSessions();
+ AttachSessionResponse attachedSession = relayd.attachToSession(sessions.get(fSession));
+
+ while (!monitor.isCanceled()) {
+
+ List<StreamResponse> attachedStreams = attachedSession.getStreamList();
+ for (StreamResponse stream : attachedStreams) {
+
+ TracePacketResponse packet = relayd.getNextPacket(stream);
+ // more streams
+ if ((packet.getFlags() & LttngViewerCommands.NEW_STREAM) == LttngViewerCommands.NEW_STREAM) {
+ Iterable<StreamResponse> newStreams = relayd.getNewStreams();
+ for (StreamResponse streamToAdd : newStreams) {
+
+ File f = new File(fCtfTrace.getPath() + File.separator + streamToAdd.getPathName() + streamToAdd.getChannelName());
+ // touch the file
+ f.setLastModified(System.currentTimeMillis());
+ fStreams.put(Long.valueOf(streamToAdd.getId()), f);
+ fCtfTrace.getCTFTrace().addStream(streamToAdd.getId(), f);
+
+ }
+
+ }
+ // more metadata
+ if ((packet.getFlags() & LttngViewerCommands.NEW_METADATA) == LttngViewerCommands.NEW_METADATA) {
+
+ String metaData = relayd.getMetadata(attachedSession);
+ (new Metadata(ctfTrace.getCTFTrace())).parseTextFragment(metaData);
+ }
+
+ try (FileOutputStream fos = new FileOutputStream(fStreams.get(stream.getId()), true)) {
+ fos.write(packet.getData());
+ monitor.worked(1);
+ }
+ }
+
+ }
+
+ } catch (IOException | CTFReaderException e) {
+ Activator.getDefault().logError("Error during live trace reading", e); //$NON-NLS-1$
+ }
+ return null;
+ }
+ };
+ fConsumerJob.schedule();
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_2_4.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_2_4.java
new file mode 100644
index 0000000000..05435c6eea
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_2_4.java
@@ -0,0 +1,181 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ * Marc-Andre Laperle - Create session and split getNextIndex from getNextPacket
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.ILttngRelaydConnector;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionRequest;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.Command;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ConnectResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.CreateSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.GetMetadata;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.GetNextIndex;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.GetPacket;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.IndexResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ListSessionsResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.MetadataPacketResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.NewStreamsResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.NextIndexReturnCode;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SeekCommand;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.StreamResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.TracePacketResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ViewerCommand;
+
+/**
+ * Lttng 2.4 implementation
+ *
+ * @author Matthew Khouzam
+ */
+public class LttngRelaydConnector_2_4 implements ILttngRelaydConnector {
+
+ private final @NonNull DataInputStream fInNet;
+ private final @NonNull DataOutputStream fOutNet;
+
+ /**
+ * Constructor needs two network streams
+ *
+ * @param inNet
+ * network incoming data
+ * @param outNet
+ * network outgoing data
+ */
+ public LttngRelaydConnector_2_4(@NonNull DataInputStream inNet, @NonNull DataOutputStream outNet) {
+ fInNet = inNet;
+ fOutNet = outNet;
+ }
+
+ // ------------------------------------------------------------------------
+ // AutoCloseable
+ // ------------------------------------------------------------------------
+
+ @Override
+ public void close() throws IOException {
+ fInNet.close();
+ fOutNet.close();
+ }
+
+ // ------------------------------------------------------------------------
+ // ILttngRelaydConnector
+ // ------------------------------------------------------------------------
+
+ @Override
+ public List<SessionResponse> getSessions() throws IOException {
+ ViewerCommand listSessionsCmd = new ViewerCommand(Command.VIEWER_LIST_SESSIONS, 0,0);
+
+ fOutNet.write(listSessionsCmd.serialize());
+ fOutNet.flush();
+
+ return new ListSessionsResponse(fInNet).getSessionsList();
+ }
+
+ @Override
+ public CreateSessionResponse createSession() throws IOException {
+ ViewerCommand listSessionsCmd = new ViewerCommand(Command.VIEWER_CREATE_SESSION, 0, 0);
+ fOutNet.write(listSessionsCmd.serialize());
+ fOutNet.flush();
+
+ return new CreateSessionResponse(fInNet);
+ }
+
+ @Override
+ public AttachSessionResponse attachToSession(SessionResponse lttngViewerSession) throws IOException {
+ ViewerCommand listSessionsCmd = new ViewerCommand(Command.VIEWER_ATTACH_SESSION, 0,0);
+ fOutNet.write(listSessionsCmd.serialize());
+ /*
+ * only flush if you read after
+ */
+
+ AttachSessionRequest attachRequest = new AttachSessionRequest(lttngViewerSession.getId(), SeekCommand.VIEWER_SEEK_BEGINNING);
+ fOutNet.write(attachRequest.serialize());
+ fOutNet.flush();
+
+ return new AttachSessionResponse(fInNet);
+ }
+
+ @Override
+ public String getMetadata(AttachSessionResponse attachedSession) throws IOException {
+
+ for (StreamResponse stream : attachedSession.getStreamList()) {
+ if (stream.getMetadataFlag() == 1) {
+ issueCommand(Command.VIEWER_GET_METADATA);
+
+ GetMetadata metadataRequest = new GetMetadata(stream.getId());
+ fOutNet.write(metadataRequest.serialize());
+ fOutNet.flush();
+
+ MetadataPacketResponse metaDataPacket = new MetadataPacketResponse(fInNet);
+ return new String(metaDataPacket.getData());
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public TracePacketResponse getPacketFromStream(IndexResponse index, long id) throws IOException {
+
+ issueCommand(Command.VIEWER_GET_PACKET);
+
+ GetPacket packetRequest = new GetPacket(id, index.getOffset(), (int) (index.getPacketSize() / 8));
+ fOutNet.write(packetRequest.serialize());
+ fOutNet.flush();
+
+ return new TracePacketResponse(fInNet);
+ }
+
+ @Override
+ public TracePacketResponse getNextPacket(StreamResponse stream) throws IOException {
+ IndexResponse indexReply = getNextIndex(stream);
+
+ TracePacketResponse packet = null;
+ if (indexReply.getStatus() == NextIndexReturnCode.VIEWER_INDEX_OK) {
+ packet = getPacketFromStream(indexReply, stream.getId());
+ }
+ return packet;
+ }
+
+ @Override
+ public IndexResponse getNextIndex(StreamResponse stream) throws IOException {
+ issueCommand(Command.VIEWER_GET_NEXT_INDEX);
+
+ GetNextIndex indexRequest = new GetNextIndex(stream.getId());
+ fOutNet.write(indexRequest.serialize());
+ fOutNet.flush();
+
+ return new IndexResponse(fInNet);
+ }
+
+ @Override
+ public List<StreamResponse> getNewStreams() throws IOException {
+
+ Command viewerGetNewStreams = Command.VIEWER_GET_NEW_STREAMS;
+
+ issueCommand(viewerGetNewStreams);
+
+ return new NewStreamsResponse(fInNet).getStreamList();
+ }
+
+ private void issueCommand(Command command) throws IOException {
+ ViewerCommand connectCommand = new ViewerCommand(command, ConnectResponse.SIZE, 0);
+ fOutNet.write(connectCommand.serialize());
+ fOutNet.flush();
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_Unsupported.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_Unsupported.java
new file mode 100644
index 0000000000..85ad22a81c
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/impl/LttngRelaydConnector_Unsupported.java
@@ -0,0 +1,76 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl;
+
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.ILttngRelaydConnector;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.AttachSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.CreateSessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.IndexResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.SessionResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.StreamResponse;
+import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.TracePacketResponse;
+
+/**
+ * Unsupported version of the relay daemon
+ *
+ * @author Matthew Khouzam
+ */
+public class LttngRelaydConnector_Unsupported implements ILttngRelaydConnector {
+
+ @Override
+ public List<SessionResponse> getSessions() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public AttachSessionResponse attachToSession(SessionResponse lttngViewerSession) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getMetadata(AttachSessionResponse attachedSession) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TracePacketResponse getNextPacket(StreamResponse stream) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public TracePacketResponse getPacketFromStream(IndexResponse index, long id) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<StreamResponse> getNewStreams() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public CreateSessionResponse createSession() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IndexResponse getNextIndex(StreamResponse stream) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachReturnCode.java
new file mode 100644
index 0000000000..4ec77c5ca5
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachReturnCode.java
@@ -0,0 +1,47 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Return codes for "viewer attach" command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum AttachReturnCode implements IBaseCommand {
+
+ /** If the attach command succeeded. */
+ VIEWER_ATTACH_OK(1),
+ /** If a viewer is already attached. */
+ VIEWER_ATTACH_ALREADY(2),
+ /** If the session ID is unknown. */
+ VIEWER_ATTACH_UNK(3),
+ /** If the session is not live. */
+ VIEWER_ATTACH_NOT_LIVE(4),
+ /** Seek error. */
+ VIEWER_ATTACH_SEEK_ERR(5),
+ /** No session */
+ VIEWER_ATTACH_NO_SESSION(6);
+
+ private final int fCode;
+
+ private AttachReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionRequest.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionRequest.java
new file mode 100644
index 0000000000..246b96e9d6
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionRequest.java
@@ -0,0 +1,81 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * VIEWER_ATTACH_SESSION payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class AttachSessionRequest implements IRelayCommand {
+
+ /**
+ * Command size
+ *
+ * long + int + seek command which is 2 ints
+ */
+ public static final int SIZE =(Long.SIZE + Integer.SIZE + SeekCommand.SIZE) / 8;
+ /** the id of a session */
+ private final long fSessionId;
+ /** unused for now */
+ private final long fOffset;
+ /** enum lttng_viewer_seek */
+ private final SeekCommand fSeek;
+
+ /**
+ * Attach session request constructor
+ *
+ * @param id
+ * the session id
+ * @param seekCommand
+ * the seek command
+ */
+ public AttachSessionRequest(long id, SeekCommand seekCommand) {
+ this(id, 0, seekCommand);
+ }
+
+ /**
+ * Attach session request constructor
+ *
+ * @param id
+ * the session id
+ * @param offset
+ * unused for now
+ * @param seekCommand
+ * the seek command
+ */
+
+ public AttachSessionRequest(long id, int offset, SeekCommand seekCommand) {
+ fSessionId = id;
+ fOffset = offset;
+ fSeek = seekCommand;
+
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(fSessionId);
+ bb.putLong(fOffset);
+ bb.putInt(fSeek.getCommand());
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionResponse.java
new file mode 100644
index 0000000000..64f665f93f
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/AttachSessionResponse.java
@@ -0,0 +1,92 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+/**
+ * Attach session response
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class AttachSessionResponse implements IRelayResponse {
+
+ /* enum + stream count, first half of a packet */
+ private static final int SIZE = (Integer.SIZE + Integer.SIZE) / 8;
+ /** enum lttng_viewer_attach_return_code */
+ private final AttachReturnCode fStatus;
+ /** how many streams are there */
+ private final int fStreamsCount;
+ /** public class lttng_viewer_stream */
+ private final List<StreamResponse> fStreamList;
+
+ /**
+ * Attach session response network constructor
+ *
+ * @param inNet
+ * network input stream
+ * @throws IOException
+ * network error
+ */
+ public AttachSessionResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data, 0, SIZE);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fStatus = AttachReturnCode.values()[bb.getInt() - 1];
+ fStreamsCount = bb.getInt();
+ Builder<StreamResponse> streamResponses = ImmutableList.builder();
+ for (int i = 0; i < getNbStreams(); i++) {
+ streamResponses.add(new StreamResponse(inNet));
+ }
+ fStreamList = streamResponses.build();
+
+ }
+
+ /**
+ * Gets the Status
+ *
+ * @return the Status
+ */
+ public AttachReturnCode getStatus() {
+ return fStatus;
+ }
+
+ /**
+ * Gets the StreamsCount
+ *
+ * @return the StreamsCount
+ */
+ public int getNbStreams() {
+ return fStreamsCount;
+ }
+
+ /**
+ * Gets the StreamList
+ *
+ * @return the StreamList
+ */
+ public List<StreamResponse> getStreamList() {
+ return fStreamList;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/Command.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/Command.java
new file mode 100644
index 0000000000..a4bb2c8549
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/Command.java
@@ -0,0 +1,56 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Viewer commands
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum Command implements IBaseCommand {
+
+ /** get version */
+ VIEWER_CONNECT(1),
+ /** list all lttng sessions */
+ VIEWER_LIST_SESSIONS(2),
+ /** attach to a session */
+ VIEWER_ATTACH_SESSION(3),
+ /** get the next index */
+ VIEWER_GET_NEXT_INDEX(4),
+ /** get packet */
+ VIEWER_GET_PACKET(5),
+ /** get metadata */
+ VIEWER_GET_METADATA(6),
+ /** get new streams */
+ VIEWER_GET_NEW_STREAMS(7),
+ /** create a new session */
+ VIEWER_CREATE_SESSION(8);
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = Integer.SIZE / 8;
+
+ private final int fCode;
+
+ private Command(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectResponse.java
new file mode 100644
index 0000000000..3a63ba5ce3
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectResponse.java
@@ -0,0 +1,126 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * CONNECT payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class ConnectResponse implements IRelayResponse, IRelayCommand {
+
+ /**
+ * Response or command size
+ */
+ public static final int SIZE = (Long.SIZE + Integer.SIZE + Integer.SIZE + Integer.SIZE) / 8;
+ /** session id, counts from 1 and increments by session */
+ private final long fViewerSessionId;
+ /**
+ * Major version, hint, it's at least 2
+ */
+ private final int fMajor;
+ /**
+ * Minor version, hint, it's at least 4
+ */
+ private final int fMinor;
+ /**
+ * type of connect to {@link ConnectionType}
+ */
+ private final ConnectionType fType;
+
+ /**
+ * Connection response reply constructor
+ *
+ * @param inStream
+ * the data input stream
+ * @throws IOException
+ * a network error
+ */
+ public ConnectResponse(DataInputStream inStream) throws IOException {
+ byte data[] = new byte[SIZE];
+ inStream.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fViewerSessionId = bb.getLong();
+ fMajor = bb.getInt();
+ fMinor = bb.getInt();
+ int connectType = bb.getInt();
+ switch (connectType) {
+ case 1:
+ fType = ConnectionType.VIEWER_CLIENT_COMMAND;
+ break;
+ case 2:
+ fType = ConnectionType.VIEWER_CLIENT_NOTIFICATION;
+ break;
+ default:
+ throw new IOException("Invalid connection type " + connectType); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Constructor for command
+ *
+ * @param sessionID
+ * session id
+ * @param major
+ * the major version
+ * @param minor
+ * the minor version
+ * @param connection
+ * the connection type, typically VIEWER_CLIENT_COMMAND
+ */
+ public ConnectResponse(long sessionID, int major, int minor, ConnectionType connection) {
+ fViewerSessionId = sessionID;
+ fMajor = major;
+ fMinor = minor;
+ fType = connection;
+ }
+
+ /**
+ * get the major version
+ *
+ * @return the major version
+ */
+ public int getMajor() {
+ return fMajor;
+ }
+
+ /**
+ * get the minor version
+ *
+ * @return the minor version
+ */
+ public int getMinor() {
+ return fMinor;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(fViewerSessionId);
+ bb.putInt(fMajor);
+ bb.putInt(fMinor);
+ bb.putInt(fType.getCommand());
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectionType.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectionType.java
new file mode 100644
index 0000000000..0b650741a6
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ConnectionType.java
@@ -0,0 +1,40 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Get viewer connection type
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum ConnectionType implements IBaseCommand {
+
+ /** Command sent */
+ VIEWER_CLIENT_COMMAND(1),
+ /** Notification sent */
+ VIEWER_CLIENT_NOTIFICATION(2);
+
+ private final int fCode;
+
+ private ConnectionType(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionResponse.java
new file mode 100644
index 0000000000..5b9d5ba79d
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionResponse.java
@@ -0,0 +1,62 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Response to a "create session" command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class CreateSessionResponse implements IRelayResponse {
+
+ /**
+ * Response size
+ */
+ public static final int SIZE = Integer.SIZE / 8;
+
+ /** enum lttng_viewer_create_session_return_code */
+ private final CreateSessionReturnCode fStatus;
+
+ /**
+ * Create session response network constructor
+ *
+ * @param inNet
+ * network input stream
+ * @throws IOException
+ * network error
+ */
+ public CreateSessionResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fStatus = (CreateSessionReturnCode.values()[bb.getInt() - 1]);
+ }
+
+ /**
+ * Get status
+ *
+ * @return the status
+ */
+ public CreateSessionReturnCode getStatus() {
+ return fStatus;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionReturnCode.java
new file mode 100644
index 0000000000..6c3f6b4d9b
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/CreateSessionReturnCode.java
@@ -0,0 +1,39 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Create new session return code
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum CreateSessionReturnCode implements IBaseCommand {
+
+ /** If new streams are being sent. */
+ LTTNG_VIEWER_CREATE_SESSION_OK(1),
+ /** Fatal error on the server-side. */
+ LTTNG_VIEWER_CREATE_SESSION_ERR(2);
+
+ private final int fCode;
+
+ private CreateSessionReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadata.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadata.java
new file mode 100644
index 0000000000..a89c9030b7
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadata.java
@@ -0,0 +1,65 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * VIEWER_GET_METADATA payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class GetMetadata implements IRelayCommand {
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = Long.SIZE / 8;
+
+ /**
+ * The stream id
+ */
+ private final long fStreamId;
+
+ /**
+ * Set the stream id
+ *
+ * @param streamId
+ * the stream id
+ */
+ public GetMetadata(long streamId) {
+ fStreamId = streamId;
+ }
+
+ /**
+ * Get the stream id
+ *
+ * @return the stream id
+ */
+ public long getStreamId() {
+ return fStreamId;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(getStreamId());
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadataReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadataReturnCode.java
new file mode 100644
index 0000000000..0df4b60316
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetMetadataReturnCode.java
@@ -0,0 +1,42 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Get metadata return code
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum GetMetadataReturnCode implements IBaseCommand {
+
+ /** Response was OK */
+ VIEWER_METADATA_OK(1),
+ /** Response was nothing new */
+ VIEWER_NO_NEW_METADATA(2),
+ /** Response was Error */
+ VIEWER_METADATA_ERR(3);
+
+ private final int fCode;
+
+ private GetMetadataReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetNextIndex.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetNextIndex.java
new file mode 100644
index 0000000000..72da00eeea
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetNextIndex.java
@@ -0,0 +1,64 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * VIEWER_GET_NEXT_INDEX payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class GetNextIndex implements IRelayCommand {
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = Long.SIZE / 8;
+ /**
+ * the id of the stream
+ */
+ private final long fStreamId;
+
+ /**
+ * Constructor
+ *
+ * @param streamId
+ * the index stream id
+ */
+ public GetNextIndex(long streamId) {
+ fStreamId = streamId;
+ }
+
+ /**
+ * Gets the stream id
+ *
+ * @return the stream id
+ */
+ public long getStreamId() {
+ return fStreamId;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(getStreamId());
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacket.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacket.java
new file mode 100644
index 0000000000..df5bbcd810
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacket.java
@@ -0,0 +1,92 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * VIEWER_GET_PACKET payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class GetPacket implements IRelayCommand {
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = (Long.SIZE + Long.SIZE + Integer.SIZE) / 8;
+ /** the stream Id */
+ private final long fStreamId;
+ /** the offset */
+ private final long fOffset;
+ /** the length of the packet */
+ private final int fLength;
+
+ /**
+ * Get packet constructor
+ *
+ * @param streamId
+ * the stream id
+ * @param offset
+ * the offset
+ * @param length
+ * the packet length
+ */
+ public GetPacket(long streamId, long offset, int length) {
+ fStreamId = streamId;
+ fOffset = offset;
+ fLength = length;
+ }
+
+ /**
+ * Get the length of the packet
+ *
+ * @return the length of the packet in bytes
+ */
+ public int getLength() {
+ return fLength;
+ }
+
+ /**
+ * Gets the offset of the packet
+ *
+ * @return the offset
+ */
+ public long getOffset() {
+ return fOffset;
+ }
+
+ /**
+ * Gets the stream id
+ *
+ * @return the stream id
+ */
+ public long getStreamId() {
+ return fStreamId;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(getStreamId());
+ bb.putLong(getOffset());
+ bb.putInt(getLength());
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacketReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacketReturnCode.java
new file mode 100644
index 0000000000..b5fab2b21a
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/GetPacketReturnCode.java
@@ -0,0 +1,44 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Get packet return code
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum GetPacketReturnCode implements IBaseCommand {
+
+ /** Response was OK */
+ VIEWER_GET_PACKET_OK(1),
+ /** Response was RETRY */
+ VIEWER_GET_PACKET_RETRY(2),
+ /** Response was ERROR */
+ VIEWER_GET_PACKET_ERR(3),
+ /** Response was End of File */
+ VIEWER_GET_PACKET_EOF(4);
+
+ private final int fCode;
+
+ private GetPacketReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IBaseCommand.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IBaseCommand.java
new file mode 100644
index 0000000000..905cfa8f6b
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IBaseCommand.java
@@ -0,0 +1,30 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Instruction to send to relayd
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface IBaseCommand {
+
+ /**
+ * gets the numerical value of the command
+ *
+ * @return the numerical value of the command
+ */
+ int getCommand();
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayCommand.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayCommand.java
new file mode 100644
index 0000000000..2a47c05061
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayCommand.java
@@ -0,0 +1,31 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+
+/**
+ * Command sent, needs a getBytes to stream the data
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface IRelayCommand {
+
+ /**
+ * Gets a byte array of the command so that it may be streamed
+ *
+ * @return the byte array of the command
+ */
+ byte[] serialize();
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayResponse.java
new file mode 100644
index 0000000000..153349d362
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IRelayResponse.java
@@ -0,0 +1,24 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Command response, this will allow sorting commands easier
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface IRelayResponse {
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IndexResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IndexResponse.java
new file mode 100644
index 0000000000..3f26b71c2f
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/IndexResponse.java
@@ -0,0 +1,160 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * An Lttng packet index
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class IndexResponse implements IRelayResponse {
+
+ // Sum of the field sizes / 8 ( 7 longs and 2 ints)
+ /**
+ * Command size
+ */
+ public final static int SIZE =
+ (Long.SIZE * 7 + Integer.SIZE * 2) / 8;
+
+ /** the offset */
+ private final long fOffset;
+ /** packet_size */
+ private final long fPacketSize;
+ /** the content size - how much of the packet is used */
+ private final long fContentSize;
+ /** timestamp of the beginning of the packet */
+ private final long fTimestampBegin;
+ /** timestamp of the end of the packet */
+ private final long fTimestampEnd;
+ /** number of discarded events BEFORE this packet */
+ private final long fEventsDiscarded;
+ /** the CTF stream id */
+ private final long fStreamId;
+ /** the status of the getNextIndex request */
+ private final NextIndexReturnCode fStatus;
+ /** whether there are new streams or metadata */
+ private final int fFlags;
+
+ /**
+ * IndexResposne from network
+ *
+ * @param inNet
+ * data input stream
+ * @throws IOException
+ * network error
+ */
+ public IndexResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fOffset = bb.getLong();
+ fPacketSize = bb.getLong();
+ fContentSize = bb.getLong();
+ fTimestampBegin = bb.getLong();
+ fTimestampEnd = bb.getLong();
+ fEventsDiscarded = bb.getLong();
+ fStreamId = bb.getLong();
+ fStatus = NextIndexReturnCode.values()[bb.getInt() - 1];
+ fFlags = bb.getInt();
+ }
+
+ /**
+ * Gets the offset
+ *
+ * @return the offset
+ */
+ public long getOffset() {
+ return fOffset;
+ }
+
+ /**
+ * Gets the packet size
+ *
+ * @return the packet size
+ */
+ public long getPacketSize() {
+ return fPacketSize;
+ }
+
+ /**
+ * Gets the content size - how much of the packet is used
+ *
+ * @return the content size
+ */
+ public long getContentSize() {
+ return fContentSize;
+ }
+
+ /**
+ * Gets the timestamp of the beginning of the packet
+ *
+ * @return the timestamp of the beginning of the packet
+ */
+ public long getTimestampBegin() {
+ return fTimestampBegin;
+ }
+
+ /**
+ * Gets the timestamp of the end of the packet
+ *
+ * @return the timestamp of the end of the packet
+ */
+ public long getTimestampEnd() {
+ return fTimestampEnd;
+ }
+
+ /**
+ * Gets the number of discarded events BEFORE this packet
+ *
+ * @return the number of discarded events BEFORE this packet
+ */
+ public long getEventsDiscarded() {
+ return fEventsDiscarded;
+ }
+
+ /**
+ * Gets the CTF stream id
+ *
+ * @return the CTF stream id
+ */
+ public long getStreamId() {
+ return fStreamId;
+ }
+
+ /**
+ * Gets the status
+ *
+ * @return the status
+ */
+ public NextIndexReturnCode getStatus() {
+ return fStatus;
+ }
+
+ /**
+ * Gets the flags that describe whether there are new streams or metadata
+ *
+ * @return the flags
+ */
+ public int getFlags() {
+ return fFlags;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ListSessionsResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ListSessionsResponse.java
new file mode 100644
index 0000000000..14b2b63a86
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ListSessionsResponse.java
@@ -0,0 +1,72 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+/**
+ * VIEWER_LIST_SESSIONS payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class ListSessionsResponse implements IRelayResponse {
+
+ /**
+ * Response size
+ */
+ public static final int PACKET_FIXED_SIZE = Integer.SIZE / 8;
+
+ /** the list of sessions */
+ private final List<SessionResponse> fSessionList;
+
+ /**
+ * List Sessions response from network
+ *
+ * @param inNet
+ * the network stream
+ * @throws IOException
+ * network error
+ */
+ public ListSessionsResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[PACKET_FIXED_SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ int nbSessions = bb.getInt();
+ Builder<SessionResponse> sl = new ImmutableList.Builder<>();
+ for (int session = 0; session < nbSessions; session++) {
+ sl.add(new SessionResponse(inNet));
+ }
+ fSessionList = sl.build();
+ }
+
+ /**
+ * Gets the session list
+ *
+ * @return the sessions list
+ */
+ public List<SessionResponse> getSessionsList() {
+ return fSessionList;
+ }
+
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/LttngViewerCommands.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/LttngViewerCommands.java
new file mode 100644
index 0000000000..45b246c9a9
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/LttngViewerCommands.java
@@ -0,0 +1,37 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * LTTng Relay Daemon API. needs a TCP connection, API is defined from
+ * BSD-licensed implementation in Lttng tools: <a href=
+ * "http://git.lttng.org/?p=lttng-tools.git;a=blob;f=src/bin/lttng-relayd/lttng-viewer-abi.h"
+ * > src/bin/lttng-relayd/lttng-viewer-abi.h</a>
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface LttngViewerCommands {
+
+ /** Maximum path name length */
+ static final int LTTNG_VIEWER_PATH_MAX = 4096;
+ /** Maximum name length */
+ static final int LTTNG_VIEWER_NAME_MAX = 255;
+ /** Maximum host name length */
+ static final int LTTNG_VIEWER_HOST_NAME_MAX = 64;
+ /** New stream in the trace */
+ static final int NEW_STREAM = (1 << 1);
+ /** New metadata in the trace */
+ static final int NEW_METADATA = (1 << 0);
+
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/MetadataPacketResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/MetadataPacketResponse.java
new file mode 100644
index 0000000000..7d46aa25e5
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/MetadataPacketResponse.java
@@ -0,0 +1,74 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Metadata packet response containing a packet of metadata
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class MetadataPacketResponse implements IRelayResponse {
+
+ private static final int SIZE = (Long.SIZE + Integer.SIZE) / 8;
+ /** status of the metadata request */
+ private final GetMetadataReturnCode fStatus;
+ /** the packet */
+ private final byte fData[];
+
+ /**
+ * Read new metadata packet from the network
+ *
+ * @param inNet
+ * network input reader
+ * @throws IOException
+ * network error
+ */
+ public MetadataPacketResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ long length = bb.getLong();
+ fStatus = GetMetadataReturnCode.values()[bb.getInt() - 1];
+ if (length >= Integer.MAX_VALUE) {
+ throw new IOException("Metadata Packet too big " + length); //$NON-NLS-1$
+ }
+ fData = new byte[(int) length];
+ inNet.readFully(fData);
+ }
+
+ /**
+ * Get the packet
+ *
+ * @return the packet
+ */
+ public byte[] getData() {
+ return fData;
+ }
+
+ /**
+ * Gets the status
+ *
+ * @return the status
+ */
+ public GetMetadataReturnCode getStatus() {
+ return fStatus;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsRequest.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsRequest.java
new file mode 100644
index 0000000000..3e3392525d
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsRequest.java
@@ -0,0 +1,54 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * LTTNG_VIEWER_GET_NEW_STREAMS payload.
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class NewStreamsRequest implements IRelayCommand {
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = Long.SIZE / 8;
+
+ /** session ID */
+ private final long fSessionId;
+
+ /**
+ * Constructor
+ *
+ * @param sessionId
+ * the session id we want
+ */
+ public NewStreamsRequest(long sessionId) {
+ fSessionId = sessionId;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(fSessionId);
+ return data;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsResponse.java
new file mode 100644
index 0000000000..eabb18f129
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsResponse.java
@@ -0,0 +1,91 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.List;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Response to a "new streams" command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class NewStreamsResponse implements IRelayResponse {
+
+ private static final int SIZE = (Integer.SIZE + Integer.SIZE) / 8;
+ /** status of the request */
+ private final NewStreamsReturnCode fStatus;
+ /** the number of streams */
+ private final int fNbStreams;
+ /** the list of streams in the response */
+ private final List<StreamResponse> fStreamList;
+
+ /**
+ * New stream response network constructor
+ *
+ * @param inNet
+ * network stream
+ * @throws IOException
+ * network error
+ */
+ public NewStreamsResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fStatus = NewStreamsReturnCode.values()[bb.getInt() - 1];
+ fNbStreams = bb.getInt();
+ ImmutableList.Builder<StreamResponse> sl = new ImmutableList.Builder<>();
+ if (getStatus().equals(NewStreamsReturnCode.LTTNG_VIEWER_NEW_STREAMS_OK)) {
+ for (int stream = 0; stream < fNbStreams; stream++) {
+ sl.add(new StreamResponse(inNet));
+ }
+ }
+ fStreamList = sl.build();
+ }
+
+ /**
+ * Gets the status
+ *
+ * @return the status
+ */
+ public NewStreamsReturnCode getStatus() {
+ return fStatus;
+ }
+
+ /**
+ * gets the stream list
+ *
+ * @return the stream list
+ */
+ public List<StreamResponse> getStreamList() {
+ return fStreamList;
+ }
+
+ /**
+ * The number of streams
+ *
+ * @return the number of streams
+ */
+ public int getNbStreams() {
+ return fNbStreams;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsReturnCode.java
new file mode 100644
index 0000000000..7bb534c987
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NewStreamsReturnCode.java
@@ -0,0 +1,43 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Return codes for "new streams" command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum NewStreamsReturnCode implements IBaseCommand {
+
+ /** If new streams are being sent. */
+ LTTNG_VIEWER_NEW_STREAMS_OK(1),
+ /** If no new streams are available. */
+ LTTNG_VIEWER_NEW_STREAMS_NO_NEW(2),
+ /** Error. */
+ LTTNG_VIEWER_NEW_STREAMS_ERR(3),
+ /** Session closed. */
+ LTTNG_VIEWER_NEW_STREAMS_HUP(4);
+
+ private final int fCode;
+
+ private NewStreamsReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NextIndexReturnCode.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NextIndexReturnCode.java
new file mode 100644
index 0000000000..6345ac5436
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/NextIndexReturnCode.java
@@ -0,0 +1,47 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Get next index return code (hope it's viewer_index_ok)
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum NextIndexReturnCode implements IBaseCommand {
+
+ /** Index is available. */
+ VIEWER_INDEX_OK(1),
+ /** Index not yet available. */
+ VIEWER_INDEX_RETRY(2),
+ /** Index closed (trace destroyed). */
+ VIEWER_INDEX_HUP(3),
+ /** Unknown error. */
+ VIEWER_INDEX_ERR(4),
+ /** Inactive stream beacon. */
+ VIEWER_INDEX_INACTIVE(5),
+ /** End of index file. */
+ VIEWER_INDEX_EOF(6);
+
+ private final int fCode;
+
+ private NextIndexReturnCode(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SeekCommand.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SeekCommand.java
new file mode 100644
index 0000000000..b84178c94b
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SeekCommand.java
@@ -0,0 +1,44 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+/**
+ * Seek command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public enum SeekCommand implements IBaseCommand {
+
+ /** Receive the trace packets from the beginning. */
+ VIEWER_SEEK_BEGINNING(1),
+ /** Receive the trace packets from now. */
+ VIEWER_SEEK_LAST(2);
+
+ private final int fCode;
+
+ /**
+ * Size of the enum
+ */
+ public static final int SIZE = Integer.SIZE / 8;
+
+ private SeekCommand(int c) {
+ fCode = c;
+ }
+
+ @Override
+ public int getCommand() {
+ return fCode;
+ }
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SessionResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SessionResponse.java
new file mode 100644
index 0000000000..dc36e5c3c7
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/SessionResponse.java
@@ -0,0 +1,126 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Get viewer session response to command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class SessionResponse implements IRelayResponse {
+
+ /**
+ * Response size
+ */
+ public static final int SIZE =
+ LttngViewerCommands.LTTNG_VIEWER_HOST_NAME_MAX + LttngViewerCommands.LTTNG_VIEWER_NAME_MAX + (Long.SIZE + Integer.SIZE + Integer.SIZE + Integer.SIZE) / 8;
+ /** id of the session */
+ private final long fId;
+ /** live timer */
+ private final int fLiveTimer;
+ /** number of clients */
+ private final int fClients;
+ /** number streams */
+ private final int fStreams;
+ /** Hostname, like 'localhost' */
+ private final String fHostname;
+ /** Session name, like 'streaming session' */
+ private final String fSessionName;
+
+ /**
+ * Session response network constructor
+ *
+ * @param inNet
+ * input network stream
+ * @throws IOException
+ * network error
+ */
+ public SessionResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fId = bb.getLong();
+ fLiveTimer = bb.getInt();
+ fClients = bb.getInt();
+ fStreams = bb.getInt();
+ byte[] hostName = new byte[LttngViewerCommands.LTTNG_VIEWER_HOST_NAME_MAX];
+ byte[] sessionName = new byte[LttngViewerCommands.LTTNG_VIEWER_NAME_MAX];
+ bb.get(hostName, 0, hostName.length);
+ bb.get(sessionName, 0, sessionName.length);
+ fHostname = new String(hostName);
+ fSessionName = new String(sessionName);
+ }
+
+ /**
+ * Gets the id of the session
+ *
+ * @return the id of the session
+ */
+ public long getId() {
+ return fId;
+ }
+
+ /**
+ * Gets the live timer
+ *
+ * @return the live timer
+ */
+ public int getLiveTimer() {
+ return fLiveTimer;
+ }
+
+ /**
+ * Gets the number of clients
+ *
+ * @return the number of clients
+ */
+ public int getClients() {
+ return fClients;
+ }
+
+ /**
+ * Gets the number streams
+ *
+ * @return the number streams
+ */
+ public int getStreams() {
+ return fStreams;
+ }
+
+ /**
+ * Gets the Hostname
+ *
+ * @return the Hostname
+ */
+ public String getHostname() {
+ return fHostname;
+ }
+
+ /**
+ * Gets the session name
+ *
+ * @return the session name
+ */
+ public String getSessionName() {
+ return fSessionName;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/StreamResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/StreamResponse.java
new file mode 100644
index 0000000000..6f124d807e
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/StreamResponse.java
@@ -0,0 +1,125 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Get response of viewer stream
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class StreamResponse implements IRelayResponse {
+
+ /**
+ * Response size
+ */
+ public static final int SIZE = (Long.SIZE + Long.SIZE + Integer.SIZE) / 8 + LttngViewerCommands.LTTNG_VIEWER_PATH_MAX + LttngViewerCommands.LTTNG_VIEWER_NAME_MAX;
+
+ /**
+ * id of the stream
+ */
+ private final long fId;
+ /**
+ * It is guaranteed to be unique, because the value is assigned sequentially
+ * by the relay.
+ */
+ private final long fCtfTraceId;
+ /**
+ * if the stream is a metadata stream
+ */
+ private final int fMetadataFlag;
+ /**
+ * the path
+ */
+ private final String fPathName;
+ /**
+ * The channel, traditionally channel0
+ */
+ private final String fChannelName;
+
+ /**
+ * Stream response
+ *
+ * @param inNet
+ * input data stream
+ * @throws IOException
+ * network time
+ */
+ public StreamResponse(DataInputStream inNet) throws IOException {
+ byte[] streamData = new byte[SIZE];
+ inNet.readFully(streamData, 0, SIZE);
+ ByteBuffer bb = ByteBuffer.wrap(streamData);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fId = (bb.getLong());
+ fCtfTraceId = bb.getLong();
+ fMetadataFlag = bb.getInt();
+ byte pathName[] = new byte[LttngViewerCommands.LTTNG_VIEWER_PATH_MAX];
+ byte channelName[] = new byte[LttngViewerCommands.LTTNG_VIEWER_NAME_MAX];
+ bb.get(pathName, 0, LttngViewerCommands.LTTNG_VIEWER_PATH_MAX);
+ bb.get(channelName, 0, LttngViewerCommands.LTTNG_VIEWER_NAME_MAX);
+ fPathName = new String(pathName);
+ fChannelName = new String(channelName);
+ }
+
+ /**
+ * Get the id
+ *
+ * @return the Id
+ */
+ public long getId() {
+ return fId;
+ }
+
+ /**
+ * Get the CtfTraceId
+ *
+ * @return the CtfTraceId
+ */
+ public long getCtfTraceId() {
+ return fCtfTraceId;
+ }
+
+ /**
+ * Get the metadata flag
+ *
+ * @return the MetadataFlag
+ */
+ public int getMetadataFlag() {
+ return fMetadataFlag;
+ }
+
+ /**
+ * Get the path name
+ *
+ * @return the PathName
+ */
+ public String getPathName() {
+ return fPathName;
+ }
+
+ /**
+ * get the Channel name
+ *
+ * @return the ChannelName
+ */
+ public String getChannelName() {
+ return fChannelName;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/TracePacketResponse.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/TracePacketResponse.java
new file mode 100644
index 0000000000..8b8f88db39
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/TracePacketResponse.java
@@ -0,0 +1,88 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Response to getpacket command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class TracePacketResponse implements IRelayResponse {
+
+ private static final int SIZE = (Integer.SIZE + Integer.SIZE) / 8;
+ /** Enum lttng_viewer_get_packet_return_code */
+ private final GetPacketReturnCode fStatus;
+ /** flags: is there new metadata or new streams? */
+ private final int fFlags;
+ /** the packet */
+ private final byte[] fData;
+
+ /**
+ * Trace packet response network constructor
+ *
+ * @param inNet
+ * network input stream
+ * @throws IOException
+ * network error
+ */
+ public TracePacketResponse(DataInputStream inNet) throws IOException {
+ byte[] data = new byte[SIZE];
+ inNet.readFully(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fStatus = GetPacketReturnCode.values()[bb.getInt() - 1];
+ int length = bb.getInt();
+ fFlags = bb.getInt();
+ if (fStatus.equals(GetPacketReturnCode.VIEWER_GET_PACKET_OK)) {
+ fData = new byte[length];
+ inNet.readFully(fData);
+ } else {
+ fData = new byte[0];
+ }
+ }
+
+ /**
+ * Get the status
+ *
+ * @return the Status
+ */
+ public GetPacketReturnCode getStatus() {
+ return fStatus;
+ }
+
+ /**
+ * Get the flags
+ *
+ * @return the Flags
+ */
+ public int getFlags() {
+ return fFlags;
+ }
+
+ /**
+ * Get the packet data, please do not modify the data
+ *
+ * @return the Data
+ */
+ public byte[] getData() {
+ return fData;
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ViewerCommand.java b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ViewerCommand.java
new file mode 100644
index 0000000000..80d97061ab
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/relayd/lttngviewerCommands/ViewerCommand.java
@@ -0,0 +1,94 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial implementation and API
+ * Marc-Andre Laperle - Initial implementation and API
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * The LTTng command
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public class ViewerCommand implements IRelayCommand {
+
+ /**
+ * Command size
+ */
+ public static final int SIZE = (Long.SIZE + Command.SIZE + Integer.SIZE) / 8;
+ /**
+ * data size following this header, you normally attach a payload that one,
+ * in bytes
+ */
+ private final long fDataSize;
+ /** enum lttcomm_relayd_command */
+ private final Command fCmd;
+ /** command version */
+ private final int fCmdVersion;
+
+ /**
+ * Sets the packet command
+ *
+ * @param viewerConnect
+ * the command
+ * @param size size of the command
+ * @param version the version number
+ */
+ public ViewerCommand(Command viewerConnect, long size, int version) {
+ fCmd = viewerConnect;
+ fDataSize = size;
+ fCmdVersion = version;
+ }
+
+ /**
+ * Get the data size
+ *
+ * @return the DataSize
+ */
+ public long getDataSize() {
+ return fDataSize;
+ }
+
+ /**
+ * Get the command
+ *
+ * @return the Cmd
+ */
+ public Command getCmd() {
+ return fCmd;
+ }
+
+ /**
+ * Get the command version
+ *
+ * @return the CmdVersion
+ */
+ public int getCmdVersion() {
+ return fCmdVersion;
+ }
+
+ @Override
+ public byte[] serialize() {
+ byte data[] = new byte[SIZE];
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ bb.order(ByteOrder.BIG_ENDIAN);
+ bb.putLong(getDataSize());
+ bb.putInt(getCmd().getCommand());
+ bb.putInt(fCmdVersion);
+ return data;
+ }
+
+
+} \ No newline at end of file

Back to the top