lttng: Fix a package dependency in control.core
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.core / src / org / eclipse / tracecompass / internal / lttng2 / control / core / relayd / impl / LttngRelaydConnectorFactory.java
1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation
11 **********************************************************************/
12
13 package org.eclipse.tracecompass.internal.lttng2.control.core.relayd.impl;
14
15 import java.io.DataInputStream;
16 import java.io.DataOutputStream;
17 import java.io.IOException;
18 import java.net.Socket;
19
20 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.ILttngRelaydConnector;
21 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.Command;
22 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.ConnectResponse;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.ConnectionType;
24 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.ViewerCommand;
25
26 /**
27 * LTTng RelayD connector factory
28 *
29 * @author Matthew Khouzam
30 */
31 public final class LttngRelaydConnectorFactory {
32
33 private LttngRelaydConnectorFactory() {
34 }
35
36 /**
37 * Create a connection to a relayd
38 *
39 * @param myConnection
40 * a connection to the relayd
41 *
42 * @return A relayd connector
43 * @throws IOException
44 * caused by invalid sockets
45 */
46 public static ILttngRelaydConnector getNewConnector(Socket myConnection) throws IOException {
47 DataOutputStream outNet = new DataOutputStream(myConnection.getOutputStream());
48 DataInputStream inNet = new DataInputStream(myConnection.getInputStream());
49
50 ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_CONNECT, ConnectResponse.SIZE, 0);
51
52 outNet.write(connectCommand.serialize());
53 outNet.flush();
54
55 ConnectResponse payload = new ConnectResponse(0, 2, 4, ConnectionType.VIEWER_CLIENT_COMMAND);
56 outNet.write(payload.serialize());
57 outNet.flush();
58
59 ConnectResponse connectReply = new ConnectResponse(inNet);
60 switch (connectReply.getMajor()) {
61 case 2:
62 switch (connectReply.getMinor()) {
63 case 0:
64 case 1:
65 case 2:
66 case 3:
67 return new LttngRelaydConnector_Unsupported();
68 case 4:
69 default:
70 return new LttngRelaydConnector_2_4(inNet, outNet);
71 }
72 default:
73 return new LttngRelaydConnector_Unsupported();
74 }
75 }
76 }
This page took 0.032742 seconds and 5 git commands to generate.