RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
StartRemoteVMProcessor.java
1/*
2 * Copyright (c) 2013 Creative Sphere Limited.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing,
9 * software distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 *
14 * Contributors:
15 *
16 * Creative Sphere - initial API and implementation
17 *
18 */
19package org.ah.java.remotevmlauncher.protocol;
20
21import java.io.ByteArrayOutputStream;
22import java.io.DataInputStream;
23import java.io.DataOutputStream;
24import java.io.IOException;
25import java.util.ArrayList;
26import java.util.List;
27
28
34public class StartRemoteVMProcessor extends AbstractProcessor {
35
36 public static final String ID = "VM";
37
38 public static final boolean IMPLEMENTED = true;
39
40 private int remoteDebugPort = 0;
41 private boolean remoteDebugSuspendAtStart = false;
42 private boolean stopVMonDisconnect = true;
43
44 private List<String> vmArgs = new ArrayList<String>();
45 private List<String> launcherArgs = new ArrayList<String>();
46
47 public StartRemoteVMProcessor() {
48 super(ID);
49 }
50
51 public int getRemoteDebugPort() {
52 return remoteDebugPort;
53 }
54
55 public void setRemoteDebugPort(int remoteDebugPort) {
56 this.remoteDebugPort = remoteDebugPort;
57 }
58
59 public boolean isRemoteDebugSuspendAtStart() {
60 return remoteDebugSuspendAtStart;
61 }
62
63 public void setRemoteDebugSuspendAtStart(boolean remoteDebugSuspendAtStart) {
64 this.remoteDebugSuspendAtStart = remoteDebugSuspendAtStart;
65 }
66
67 public List<String> getVmArgs() {
68 return vmArgs;
69 }
70
71 public List<String> getLauncherArgs() {
72 return launcherArgs;
73 }
74
75 public boolean isStopVMonDisconnect() {
76 return stopVMonDisconnect;
77 }
78
79 public void setStopVMonDisconnect(boolean stopVMonDisconnect) {
80 this.stopVMonDisconnect = stopVMonDisconnect;
81 }
82
83 public void receive(DataInputStream dis) throws IOException{
84 vmArgs.clear();
85 launcherArgs.clear();
86 remoteDebugPort = dis.readInt();
87 remoteDebugSuspendAtStart = dis.readBoolean();
88 stopVMonDisconnect = dis.readBoolean();
89 /*int totalSize = */dis.readShort(); // doing nothing with it
90 int argsLen = dis.readShort();
91 for (int i = 0; i < argsLen; i++) {
92 vmArgs.add(dis.readUTF());
93 }
94 argsLen = dis.readShort();
95 for (int i = 0; i < argsLen; i++) {
96 launcherArgs.add(dis.readUTF());
97 }
98
99 startVM();
100 }
101
102 public void startVM() throws IOException {
103 }
104
105 public void send(DataOutputStream dos) throws IOException {
106 dos.writeUTF(getId());
107 dos.writeInt(remoteDebugPort);
108 dos.writeBoolean(remoteDebugSuspendAtStart);
109 dos.writeBoolean(stopVMonDisconnect);
110
111 ByteArrayOutputStream cache = new ByteArrayOutputStream();
112 DataOutputStream dosCache = new DataOutputStream(cache);
113 dosCache.writeShort(vmArgs.size());
114 for (String arg : vmArgs) {
115 dosCache.writeUTF(arg);
116 }
117 dosCache.writeShort(launcherArgs.size());
118 for (String arg : launcherArgs) {
119 dosCache.writeUTF(arg);
120 }
121 dosCache.flush();
122
123 byte[] cacheBytes = cache.toByteArray();
124 if (cacheBytes.length > 32767) {
125 throw new RuntimeException("StartRemoteVM arguments longer than 32767 (" + cacheBytes.length +")");
126 }
127 dos.writeShort(cacheBytes.length);
128 dos.write(cacheBytes);
129 dos.flush();
130 }
131}