Zeer veel aanpassingen:
- omslachtigheden verbeterd - netwerking gefixt - ...
This commit is contained in:
@@ -9,7 +9,6 @@ import pm.exception.MacroException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
import pm.exception.button.UnknownDirectionException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.interrupt.Interruptible;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
@@ -33,7 +32,7 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
new Press(Extreme3DButton.TWO),
|
||||
new Press(Extreme3DButton.ELEVEN),
|
||||
new Release(Extreme3DButton.ONE)),
|
||||
new Task(Action.EXIT, Target.MAIN));
|
||||
new Task(Action.EXIT, Target.MANAGER));
|
||||
} catch (MacroException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
jit.addIntellitypeListener(this);
|
||||
add(
|
||||
new Hotkey(Key.PRIOR),
|
||||
new Task(Action.PREVIOUS, Target.MAIN));
|
||||
new Task(Action.PREVIOUS, Target.MANAGER));
|
||||
add(
|
||||
new Hotkey(Key.NEXT),
|
||||
new Task(Action.NEXT, Target.MAIN));
|
||||
new Task(Action.NEXT, Target.MANAGER));
|
||||
add(
|
||||
new Press(CommandButton.VOLUME_DOWN),
|
||||
new Task(Action.VOLUME_DOWN, Target.APPLICATIONS));
|
||||
@@ -44,7 +44,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
new Task(Action.VOLUME_UP, Target.APPLICATIONS));
|
||||
add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||
new Task(Action.EXIT, Target.MAIN));
|
||||
new Task(Action.EXIT, Target.MANAGER));
|
||||
add(
|
||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
||||
new Task(Action.NEXT, Target.APPLICATION));
|
||||
|
||||
122
java/src/pm/device/network/NetworkDevice.java
Normal file
122
java/src/pm/device/network/NetworkDevice.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package pm.device.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Event;
|
||||
import pm.Worker;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.value.Action;
|
||||
|
||||
public class NetworkDevice extends Device {
|
||||
public static final int PORT = 6789;
|
||||
|
||||
protected Log log = LogFactory.getLog(NetworkDevice.class);
|
||||
protected int port;
|
||||
protected Server server;
|
||||
protected ArrayList<Client> clientList;
|
||||
|
||||
public NetworkDevice(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public NetworkDevice() {
|
||||
this(PORT);
|
||||
}
|
||||
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
try {
|
||||
server = new Server(port);
|
||||
server.start();
|
||||
} catch (IOException e) {
|
||||
throw new DeviceInitialiseException();
|
||||
}
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
protected void add(Action action) {
|
||||
|
||||
}
|
||||
|
||||
protected class Server extends Worker {
|
||||
protected ServerSocket serverSocket;
|
||||
|
||||
public Server(int port) throws IOException {
|
||||
serverSocket = new ServerSocket(port);
|
||||
clientList = new ArrayList<Client>();
|
||||
System.out.println("Server started");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (run) {
|
||||
System.out.println("Server is waiting for clients");
|
||||
try {
|
||||
Socket socket = serverSocket.accept();
|
||||
Client client = new Client(socket);
|
||||
client.start();
|
||||
System.out.println("Client connected");
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
for (Client client : clientList) {
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class Client extends Worker {
|
||||
protected Socket socket;
|
||||
protected ObjectInputStream objectInputStream;
|
||||
protected OutputStream outputStream;
|
||||
|
||||
public Client(Socket socket) throws IOException {
|
||||
this.socket = socket;
|
||||
objectInputStream = new ObjectInputStream(socket.getInputStream());
|
||||
//outputStream = socket.getOutputStream();
|
||||
clientList.add(this);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
Object object;
|
||||
do {
|
||||
object = objectInputStream.readObject();
|
||||
if (object instanceof Event) {
|
||||
log.debug("event binnen!");
|
||||
eventSpreader.add((Event) object);
|
||||
}
|
||||
log.debug("iets te lezen!");
|
||||
} while (object != null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("stoppen");
|
||||
try {
|
||||
disconnect();
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
clientList.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
objectInputStream.close();
|
||||
outputStream.close();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
71
java/src/pm/device/network/NetworkServer.java
Normal file
71
java/src/pm/device/network/NetworkServer.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package pm.device.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Scanner;
|
||||
|
||||
import pm.Device;
|
||||
import pm.exception.task.action.ActionDeserializeException;
|
||||
import pm.value.Action;
|
||||
|
||||
public class NetworkServer extends Device {
|
||||
public static final int PORT = 1234;
|
||||
protected MessageReceiver messageReceiver;
|
||||
|
||||
public NetworkServer() {
|
||||
messageReceiver = new MessageReceiver(PORT);
|
||||
messageReceiver.start();
|
||||
System.out.println("NetworkServer started");
|
||||
}
|
||||
|
||||
public void action(Action action) {
|
||||
this.action(action);
|
||||
}
|
||||
|
||||
protected class MessageReceiver extends Thread {
|
||||
protected ServerSocket server;
|
||||
|
||||
public MessageReceiver(int port) {
|
||||
try {
|
||||
server = new ServerSocket(port);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("MessageReceiver started");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
System.out.println("MessageReceiver is waiting for clients");
|
||||
try {
|
||||
Socket socket = server.accept();
|
||||
final InputStream inputStream = socket.getInputStream();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Scanner input = new Scanner(inputStream);
|
||||
while (input.hasNext()) {
|
||||
String string = input.next().toUpperCase();
|
||||
if(string != null) {
|
||||
try {
|
||||
Action action = Action.deserialise(string);
|
||||
action(action);
|
||||
} catch (ActionDeserializeException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
System.out.println("Client connected");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package pm.device.text;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Listener;
|
||||
import pm.event.EventManager;
|
||||
import pm.event.Task;
|
||||
import pm.value.Action;
|
||||
import pm.value.Target;
|
||||
|
||||
public class TextDevice extends Device {
|
||||
InputListener inputListener;
|
||||
|
||||
public TextDevice() {
|
||||
inputListener = new InputListener(System.in);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
inputListener.start();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
inputListener.stop();
|
||||
}
|
||||
|
||||
public void add(String string) {
|
||||
EventManager.add(new Task(Action.valueOf(string), Target.APPLICATION));
|
||||
}
|
||||
|
||||
public class InputListener extends Listener {
|
||||
protected Scanner input;
|
||||
|
||||
public InputListener(InputStream inputStream) {
|
||||
input = new Scanner(inputStream);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
run = true;
|
||||
while (run && input.hasNext()) {
|
||||
String string = input.next().toUpperCase();
|
||||
if(string != null) {
|
||||
try {
|
||||
add(string);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pm.Listener;
|
||||
import pm.Worker;
|
||||
import pm.device.text.TextDevice;
|
||||
|
||||
public class SocketListener extends Listener {
|
||||
public class SocketListener extends Worker {
|
||||
protected ServerSocket server;
|
||||
protected ArrayList<TextDevice.InputListener> inputListenerList;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
new Continuous(Action.VOLUME_UP, Target.APPLICATION, 100));
|
||||
add(
|
||||
new Press(WiimoteButton.HOME),
|
||||
new Task(Action.NEXT, Target.MAIN));
|
||||
new Task(Action.NEXT, Target.MANAGER));
|
||||
try {
|
||||
add(
|
||||
new Macro(
|
||||
|
||||
Reference in New Issue
Block a user