Commit | Line | Data |
---|---|---|
8e15b929 MK |
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.linuxtools.internal.lttng2.control.core.relayd; | |
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.linuxtools.internal.lttng2.control.core.relayd.impl.LttngRelaydConnector_2_4; | |
21 | import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.impl.LttngRelaydConnector_Unsupported; | |
22 | import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.Command; | |
23 | import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ConnectResponse; | |
fe25111b | 24 | import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ConnectionType; |
8e15b929 MK |
25 | import org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands.ViewerCommand; |
26 | ||
27 | /** | |
28 | * LTTng RelayD connector factory | |
29 | * | |
30 | * @author Matthew Khouzam | |
31 | * @since 3.0 | |
32 | */ | |
33 | public final class LttngRelaydConnectorFactory { | |
34 | ||
35 | private LttngRelaydConnectorFactory() { | |
36 | } | |
37 | ||
38 | /** | |
39 | * Create a connection to a relayd | |
40 | * | |
41 | * @param myConnection | |
42 | * a connection to the relayd | |
43 | * | |
44 | * @return A relayd connector | |
45 | * @throws IOException | |
46 | * caused by invalid sockets | |
47 | */ | |
48 | public static ILttngRelaydConnector getNewConnector(Socket myConnection) throws IOException { | |
49 | DataOutputStream outNet = new DataOutputStream(myConnection.getOutputStream()); | |
50 | DataInputStream inNet = new DataInputStream(myConnection.getInputStream()); | |
51 | ||
52 | ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_CONNECT, ConnectResponse.SIZE, 0); | |
53 | ||
54 | outNet.write(connectCommand.serialize()); | |
55 | outNet.flush(); | |
56 | ||
fe25111b MAL |
57 | ConnectResponse payload = new ConnectResponse(0, 2, 4, ConnectionType.VIEWER_CLIENT_COMMAND); |
58 | outNet.write(payload.serialize()); | |
59 | outNet.flush(); | |
60 | ||
8e15b929 MK |
61 | ConnectResponse connectReply = new ConnectResponse(inNet); |
62 | switch (connectReply.getMajor()) { | |
63 | case 2: | |
64 | switch (connectReply.getMinor()) { | |
65 | case 0: | |
66 | case 1: | |
67 | case 2: | |
68 | case 3: | |
69 | return new LttngRelaydConnector_Unsupported(); | |
70 | case 4: | |
71 | default: | |
72 | return new LttngRelaydConnector_2_4(inNet, outNet); | |
73 | } | |
74 | default: | |
75 | return new LttngRelaydConnector_Unsupported(); | |
76 | } | |
77 | } | |
78 | } |