aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 657e56258..447bf364b 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -15,6 +15,12 @@
*/
package org.traccar;
+import java.net.SocketAddress;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import static org.jboss.netty.channel.Channels.fireMessageReceived;
+import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import org.traccar.model.DataManager;
@@ -51,5 +57,38 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
dataManager = serverManager.getDataManager();
}
}
+
+ @Override
+ public void handleUpstream(
+ ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
+ if (!(evt instanceof MessageEvent)) {
+ ctx.sendUpstream(evt);
+ return;
+ }
+
+ MessageEvent e = (MessageEvent) evt;
+ Object originalMessage = e.getMessage();
+ Object decodedMessage = decode(ctx, e.getChannel(), e.getRemoteAddress(), originalMessage);
+ if (originalMessage == decodedMessage) {
+ ctx.sendUpstream(evt);
+ } else if (decodedMessage != null) {
+ fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
+ }
+ }
+
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ return decode(ctx, channel, msg);
+
+ }
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
+
+ return null; // default implementation
+
+ }
}