Migrate to simpler client/server communication model
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
package com.github.boukefalos.lirc;
|
package com.github.boukefalos.lirc;
|
||||||
|
|
||||||
|
import base.Control;
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
|
|
||||||
public interface Lirc {
|
public interface Lirc extends Control {
|
||||||
public void start();
|
|
||||||
// Required for Client / ClientListen to forward from separate Thread
|
|
||||||
public void input(Object object);
|
|
||||||
public void register(Listen<Object> listen);
|
public void register(Listen<Object> listen);
|
||||||
|
public void remove(Listen<Object> listen);
|
||||||
|
//public void send(String remote, String code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,76 +2,59 @@ package com.github.boukefalos.lirc;
|
|||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.picocontainer.Parameter;
|
import base.exception.LoaderException;
|
||||||
import org.picocontainer.parameters.ConstantParameter;
|
|
||||||
|
|
||||||
import base.loader.AbstractLoader;
|
import base.loader.AbstractLoader;
|
||||||
import base.work.Work;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.client.LircTcpClient;
|
import com.github.boukefalos.lirc.implementation.Local;
|
||||||
import com.github.boukefalos.lirc.implementation.LocalImplementation;
|
import com.github.boukefalos.lirc.implementation.Remote;
|
||||||
import com.github.boukefalos.lirc.implementation.TcpImplementation;
|
|
||||||
import com.github.boukefalos.lirc.implementation.UdpImplementation;
|
|
||||||
import com.github.boukefalos.lirc.server.LircServer;
|
|
||||||
import com.github.boukefalos.lirc.server.LircTcpServer;
|
|
||||||
import com.github.boukefalos.lirc.server.LircUdpServer;
|
|
||||||
|
|
||||||
public class Loader extends AbstractLoader {
|
public class Loader extends AbstractLoader<Loader> {
|
||||||
protected static final String PROPERTIES_FILE = "lirc.properties";
|
protected static final String PROPERTIES_FILE = "lirc.properties";
|
||||||
|
|
||||||
public Loader(Properties properties) {
|
public Loader(Properties properties) throws LoaderException {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/* Add implementation */
|
/* Add implementation */
|
||||||
switch (properties.getProperty("implementation")) {
|
switch (properties.getProperty("implementation")) {
|
||||||
case "local":
|
case "local":
|
||||||
pico.addComponent(LocalImplementation.class);
|
pico.addComponent(Local.class);
|
||||||
break;
|
break;
|
||||||
case "remote":
|
case "remote":
|
||||||
//pico.addComponent(Remote.class);
|
pico.addComponent(Remote.class);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add protocol */
|
/* Add remote forwarder implementation */
|
||||||
if (properties.getProperty("protocol") != null) {
|
try {
|
||||||
switch (properties.getProperty("protocol")) {
|
String protocol = properties.getOrDefault("server.protocol", "tcp").toString();
|
||||||
case "tcp":
|
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
|
||||||
pico.addComponent(TcpImplementation.class, TcpImplementation.class, new Parameter[]{
|
int port = Integer.valueOf(properties.getProperty("remote.port"));
|
||||||
new ConstantParameter(properties.getProperty("remote.host")),
|
addForwarder(protocol, implementation, port);
|
||||||
new ConstantParameter(Integer.valueOf(properties.getProperty("remote.port")))});
|
} catch (NumberFormatException e) {
|
||||||
break;
|
throw new LoaderException("Failed to parse remote.port");
|
||||||
case "udp":
|
}
|
||||||
pico.addComponent(UdpImplementation.class, UdpImplementation.class, new Parameter[] {
|
break;
|
||||||
new ConstantParameter(properties.getProperty("remote.host")),
|
|
||||||
new ConstantParameter(Integer.valueOf(properties.getProperty("remote.port")))});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add server */
|
/* Add server */
|
||||||
if (properties.getProperty("server") != null) {
|
if (properties.getProperty("server") != null) {
|
||||||
switch (properties.getProperty("server.protocol")) {
|
pico.addComponent(Server.class);
|
||||||
case "tcp":
|
|
||||||
pico.addComponent(LircTcpServer.class, LircTcpServer.class, new Parameter[]{
|
|
||||||
new ConstantParameter(getLirc()),
|
|
||||||
new ConstantParameter(Integer.valueOf(properties.getProperty("server.port"))),
|
|
||||||
new ConstantParameter(LircTcpClient.class)});
|
|
||||||
break;
|
|
||||||
case "udp":
|
|
||||||
pico.addComponent(LircUdpServer.class, LircUdpServer.class, new Parameter[]{
|
|
||||||
new ConstantParameter(getLirc()),
|
|
||||||
new ConstantParameter(Integer.valueOf(properties.getProperty("server.port")))});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Add sender implementation */
|
||||||
|
try {
|
||||||
|
String protocol = properties.getOrDefault("server.protocol", "tcp").toString();
|
||||||
|
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
|
||||||
|
int port = Integer.valueOf(properties.getProperty("server.port"));
|
||||||
|
addSender(protocol, implementation, "localhost", port);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new LoaderException("Failed to parse server.port");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Lirc getLirc() {
|
public Lirc getLirc() {
|
||||||
return pico.getComponent(Lirc.class);
|
return pico.getComponent(Lirc.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Work getServer() {
|
public Server getServer() {
|
||||||
return (Work) pico.getComponent(LircServer.class);
|
return pico.getComponent(Server.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.github.boukefalos.lirc.listen;
|
package com.github.boukefalos.lirc;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,17 +13,39 @@ import lirc.Lirc.DirectionButton;
|
|||||||
import lirc.Lirc.Number;
|
import lirc.Lirc.Number;
|
||||||
import lirc.Lirc.NumberButton;
|
import lirc.Lirc.NumberButton;
|
||||||
import lirc.Lirc.Signal;
|
import lirc.Lirc.Signal;
|
||||||
|
import base.Control;
|
||||||
|
import base.exception.worker.ActivateException;
|
||||||
|
import base.exception.worker.DeactivateException;
|
||||||
import base.sender.Sender;
|
import base.sender.Sender;
|
||||||
import base.work.Listen;
|
import base.work.Listen;
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.LircButton;
|
|
||||||
import com.github.boukefalos.lirc.util.SignalObject;
|
import com.github.boukefalos.lirc.util.SignalObject;
|
||||||
|
|
||||||
public class ServerListen extends Listen<Object> {
|
public class Server extends Listen<Object> implements Control {
|
||||||
|
protected Lirc lirc;
|
||||||
protected Sender sender;
|
protected Sender sender;
|
||||||
|
|
||||||
public ServerListen(Sender sender) {
|
public Server(Lirc lirc, Sender sender) {
|
||||||
|
this.lirc = lirc;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
|
lirc.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activate() throws ActivateException {
|
||||||
|
lirc.start();
|
||||||
|
sender.start();
|
||||||
|
super.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deactivate() throws DeactivateException {
|
||||||
|
super.deactivate();
|
||||||
|
lirc.start();
|
||||||
|
sender.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
lirc.exit();
|
||||||
|
sender.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void input(SignalObject<Object> signalObject) {
|
public void input(SignalObject<Object> signalObject) {
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.github.boukefalos.lirc.button;
|
||||||
|
|
||||||
|
public interface RemoteButton {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.client;
|
|
||||||
|
|
||||||
import java.nio.channels.SocketChannel;
|
|
||||||
|
|
||||||
import base.server.channel.TcpServerClient;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.server.LircTcpServer;
|
|
||||||
|
|
||||||
public class LircTcpClient extends TcpServerClient {
|
|
||||||
protected LircTcpServer server;
|
|
||||||
|
|
||||||
public LircTcpClient(LircTcpServer server, SocketChannel socketChannel, Integer bufferSize) {
|
|
||||||
super(server, socketChannel, bufferSize);
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void receive(byte[] buffer) {
|
|
||||||
|
|
||||||
System.err.println(123);
|
|
||||||
System.err.println(new String(buffer).trim());
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,12 +33,12 @@ import com.github.boukefalos.lirc.LircClient;
|
|||||||
import com.github.boukefalos.lirc.util.Multiplexer;
|
import com.github.boukefalos.lirc.util.Multiplexer;
|
||||||
import com.github.boukefalos.lirc.util.SignalObject;
|
import com.github.boukefalos.lirc.util.SignalObject;
|
||||||
|
|
||||||
public class LocalImplementation extends Listen<Object> implements Lirc {
|
public class Local extends Listen<Object> implements Lirc {
|
||||||
protected ArrayList<Listen<Object>> listenList;
|
protected ArrayList<Listen<Object>> listenList;
|
||||||
protected Multiplexer<String> multiplexer;
|
protected Multiplexer<String> multiplexer;
|
||||||
protected LircClient lircClient;
|
protected LircClient lircClient;
|
||||||
|
|
||||||
public LocalImplementation() {
|
public Local() {
|
||||||
listenList = new ArrayList<Listen<Object>>();
|
listenList = new ArrayList<Listen<Object>>();
|
||||||
lircClient = new LircClient(this);
|
lircClient = new LircClient(this);
|
||||||
multiplexer = new Multiplexer<String>();
|
multiplexer = new Multiplexer<String>();
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.github.boukefalos.server.helper;
|
package com.github.boukefalos.lirc.implementation;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import lirc.Lirc.Button;
|
import lirc.Lirc.Button;
|
||||||
import lirc.Lirc.Button.Type;
|
import lirc.Lirc.Button.Type;
|
||||||
@@ -9,18 +10,40 @@ import lirc.Lirc.Color;
|
|||||||
import lirc.Lirc.Direction;
|
import lirc.Lirc.Direction;
|
||||||
import lirc.Lirc.Number;
|
import lirc.Lirc.Number;
|
||||||
import lirc.Lirc.Signal;
|
import lirc.Lirc.Signal;
|
||||||
|
import base.receiver.Forwarder;
|
||||||
import org.slf4j.Logger;
|
import base.server.forwarder.AbstractReceiver;
|
||||||
import org.slf4j.LoggerFactory;
|
import base.work.Listen;
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
import com.github.boukefalos.lirc.Lirc;
|
||||||
import com.github.boukefalos.lirc.LircButton;
|
import com.github.boukefalos.lirc.LircButton;
|
||||||
import com.github.boukefalos.lirc.util.SignalObject;
|
import com.github.boukefalos.lirc.util.SignalObject;
|
||||||
|
|
||||||
public class ServerHelper {
|
public class Remote extends AbstractReceiver implements Lirc {
|
||||||
protected static Logger logger = LoggerFactory.getLogger(ServerHelper.class);
|
protected ArrayList<Listen<Object>> listenList;
|
||||||
|
|
||||||
public static SignalObject<?> decode(Lirc lirc, byte[] buffer) {
|
public Remote(Forwarder forwarder) {
|
||||||
|
super(forwarder);
|
||||||
|
listenList = new ArrayList<Listen<Object>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(Listen<Object> listen) {
|
||||||
|
listenList.add(listen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Listen<Object> listen) {
|
||||||
|
listenList.remove(listen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receive(byte[] buffer) {
|
||||||
|
Object object = decode(buffer);
|
||||||
|
if (object != null) {
|
||||||
|
for (Listen<Object> listen : listenList) {
|
||||||
|
listen.add(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SignalObject<?> decode(byte[] buffer) {
|
||||||
ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
||||||
try {
|
try {
|
||||||
Button button = Button.parseDelimitedFrom(input);
|
Button button = Button.parseDelimitedFrom(input);
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.implementation;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
|
||||||
import base.server.socket.TcpClient; // Change to channel?
|
|
||||||
import base.work.Listen;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
|
||||||
import com.github.boukefalos.lirc.listen.ClientListen;
|
|
||||||
import com.github.boukefalos.server.helper.ServerHelper;
|
|
||||||
|
|
||||||
// Fix dual Receiver and Sender roles
|
|
||||||
public class TcpImplementation extends Listen<byte[]> implements Lirc {
|
|
||||||
protected TcpClient tcpClient;
|
|
||||||
protected ClientListen listen;
|
|
||||||
protected ArrayList<Listen<Object>> listenList;
|
|
||||||
|
|
||||||
public TcpImplementation(String host, int port) {
|
|
||||||
tcpClient = new TcpClient(host, port);
|
|
||||||
tcpClient.register(this);
|
|
||||||
listenList = new ArrayList<Listen<Object>>();
|
|
||||||
listen = new ClientListen(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
|
||||||
listen.start();
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void input(byte[] buffer) {
|
|
||||||
Object object = ServerHelper.decode(this, buffer);
|
|
||||||
if (object != null) {
|
|
||||||
for (Listen<Object> listen : listenList) {
|
|
||||||
listen.add(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(Listen<Object> listen) {
|
|
||||||
listenList.add(listen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.implementation;
|
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import base.sender.UdpSender;
|
|
||||||
import base.work.Listen;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
|
||||||
|
|
||||||
public class UdpImplementation extends UdpSender implements Lirc {
|
|
||||||
public UdpImplementation(String host, int port) throws UnknownHostException {
|
|
||||||
super(host, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void input(Object object) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(Listen<Object> listen) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// add way to receive udp packets
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.listen;
|
|
||||||
|
|
||||||
import base.work.Listen;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
|
||||||
|
|
||||||
public class ClientListen extends Listen<Object> {
|
|
||||||
protected Lirc lirc;
|
|
||||||
|
|
||||||
public ClientListen(Lirc lirc) {
|
|
||||||
this.lirc = lirc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void input(Object object) {
|
|
||||||
lirc.input(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
// forward send requests to sender
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.server;
|
|
||||||
|
|
||||||
public interface LircServer {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.server;
|
|
||||||
|
|
||||||
import base.exception.worker.ActivateException;
|
|
||||||
import base.server.channel.TcpServer;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
|
||||||
import com.github.boukefalos.lirc.listen.ServerListen;
|
|
||||||
import com.github.boukefalos.server.helper.ServerHelper;
|
|
||||||
|
|
||||||
public class LircTcpServer extends TcpServer implements LircServer {
|
|
||||||
protected Lirc lirc;
|
|
||||||
protected ServerListen listen;
|
|
||||||
|
|
||||||
public LircTcpServer(Lirc lirc, int port, Class<?> clientClass) {
|
|
||||||
super(port, clientClass);
|
|
||||||
this.lirc = lirc;
|
|
||||||
listen = new ServerListen(this);
|
|
||||||
lirc.register(listen);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
|
||||||
lirc.start();
|
|
||||||
listen.start();
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void receive(byte[] buffer) {
|
|
||||||
ServerHelper.decode(lirc, buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.github.boukefalos.lirc.server;
|
|
||||||
|
|
||||||
import base.server.datagram.UdpServer;
|
|
||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
|
||||||
import com.github.boukefalos.server.helper.ServerHelper;
|
|
||||||
|
|
||||||
public class LircUdpServer extends UdpServer implements LircServer {
|
|
||||||
protected Lirc lirc;
|
|
||||||
|
|
||||||
public LircUdpServer(Lirc lirc, int port) {
|
|
||||||
this(lirc, port, BUFFER_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LircUdpServer(Lirc lirc, int port, int bufferSize) {
|
|
||||||
super(port, bufferSize);
|
|
||||||
this.lirc = lirc;
|
|
||||||
this.bufferSize = bufferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void receive(byte[] buffer) {
|
|
||||||
ServerHelper.decode(lirc, buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.github.boukefalos.server.helper;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class SenderHelper {
|
|
||||||
protected static Logger logger = LoggerFactory.getLogger(SenderHelper.class);
|
|
||||||
|
|
||||||
public static void send(String remote, String code) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ import base.work.Listen;
|
|||||||
|
|
||||||
import com.github.boukefalos.lirc.Lirc;
|
import com.github.boukefalos.lirc.Lirc;
|
||||||
import com.github.boukefalos.lirc.LircButton;
|
import com.github.boukefalos.lirc.LircButton;
|
||||||
import com.github.boukefalos.lirc.implementation.LocalImplementation;
|
import com.github.boukefalos.lirc.implementation.Local;
|
||||||
import com.github.boukefalos.lirc.util.SignalObject;
|
import com.github.boukefalos.lirc.util.SignalObject;
|
||||||
|
|
||||||
public class TestLocal extends Listen<Object> {
|
public class TestLocal extends Listen<Object> {
|
||||||
@@ -21,12 +21,11 @@ public class TestLocal extends Listen<Object> {
|
|||||||
protected Lirc lirc;
|
protected Lirc lirc;
|
||||||
|
|
||||||
public TestLocal() {
|
public TestLocal() {
|
||||||
lirc = new LocalImplementation();
|
lirc = new Local();
|
||||||
lirc.register(this);
|
lirc.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
logger.debug("Activate " + getClass().getSimpleName());
|
|
||||||
lirc.start();
|
lirc.start();
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/test/java/test/TestRemoteImplementation.java
Normal file
52
src/test/java/test/TestRemoteImplementation.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import lirc.Lirc.Signal;
|
||||||
|
import base.exception.LoaderException;
|
||||||
|
import base.exception.worker.ActivateException;
|
||||||
|
import base.work.Listen;
|
||||||
|
|
||||||
|
import com.github.boukefalos.lirc.Lirc;
|
||||||
|
import com.github.boukefalos.lirc.LircButton;
|
||||||
|
import com.github.boukefalos.lirc.Loader;
|
||||||
|
import com.github.boukefalos.lirc.Server;
|
||||||
|
import com.github.boukefalos.lirc.util.SignalObject;
|
||||||
|
|
||||||
|
public class TestRemoteImplementation extends Listen<Object> {
|
||||||
|
protected Lirc lirc;
|
||||||
|
|
||||||
|
public TestRemoteImplementation(Loader loader) {
|
||||||
|
lirc = loader.getLirc();
|
||||||
|
lirc.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activate() throws ActivateException {
|
||||||
|
lirc.start();
|
||||||
|
super.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void input(SignalObject<LircButton> lircButtonSignal) {
|
||||||
|
Object object = lircButtonSignal.object;
|
||||||
|
if (object instanceof LircButton) {
|
||||||
|
Signal signal = lircButtonSignal.signal;
|
||||||
|
LircButton lircButton = lircButtonSignal.object;
|
||||||
|
String code = lircButton.code;
|
||||||
|
logger.error(signal.name() + " : " + code + " @ " + lircButton.remote);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(Properties localProperties, Properties remoteProperties) throws LoaderException {
|
||||||
|
Loader localLoader = new Loader(localProperties);
|
||||||
|
Loader remoteLoader = new Loader(remoteProperties);
|
||||||
|
|
||||||
|
Server server = localLoader.getServer();
|
||||||
|
|
||||||
|
server.start();
|
||||||
|
new TestRemoteImplementation(remoteLoader).start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000000);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/test/java/test/TestTcpImplementation.java
Normal file
23
src/test/java/test/TestTcpImplementation.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import base.exception.LoaderException;
|
||||||
|
|
||||||
|
public class TestTcpImplementation {
|
||||||
|
public static void main(String[] args) throws LoaderException {
|
||||||
|
Properties localProperties = new Properties();
|
||||||
|
localProperties.setProperty("implementation", "local");
|
||||||
|
localProperties.setProperty("server", "true");
|
||||||
|
localProperties.setProperty("server.port", "8883");
|
||||||
|
localProperties.setProperty("server.protocol", "tcp");
|
||||||
|
|
||||||
|
Properties remoteProperties = new Properties();
|
||||||
|
remoteProperties.setProperty("implementation", "remote");
|
||||||
|
remoteProperties.setProperty("protocol", "tcp");
|
||||||
|
remoteProperties.setProperty("remote.host", "localhost");
|
||||||
|
remoteProperties.setProperty("remote.port", "8883");
|
||||||
|
|
||||||
|
TestRemoteImplementation.main(localProperties, remoteProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/test/java/test/TestUdpImplementation.java
Normal file
23
src/test/java/test/TestUdpImplementation.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import base.exception.LoaderException;
|
||||||
|
|
||||||
|
public class TestUdpImplementation {
|
||||||
|
public static void main(String[] args) throws LoaderException {
|
||||||
|
Properties localProperties = new Properties();
|
||||||
|
localProperties.setProperty("implementation", "local");
|
||||||
|
localProperties.setProperty("server", "true");
|
||||||
|
localProperties.setProperty("server.port", "8883");
|
||||||
|
localProperties.setProperty("server.protocol", "udp");
|
||||||
|
|
||||||
|
Properties remoteProperties = new Properties();
|
||||||
|
remoteProperties.setProperty("implementation", "remote");
|
||||||
|
remoteProperties.setProperty("protocol", "udp");
|
||||||
|
remoteProperties.setProperty("remote.host", "localhost");
|
||||||
|
remoteProperties.setProperty("remote.port", "8883");
|
||||||
|
|
||||||
|
TestRemoteImplementation.main(localProperties, remoteProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user