aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java15
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java27
2 files changed, 32 insertions, 10 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 53297c2bc..3429f41f0 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,4 +105,17 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
}
+ @Override
+ protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) {
+ if (Context.getConfig().getBoolean("database.saveEmpty") && hasDeviceId()) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+ getLastLocation(position, null);
+ return position;
+ } else {
+ return null;
+ }
+ }
+
}
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 2734f5469..ded749e6c 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,15 +59,20 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage); // call after decode
if (originalMessage == decodedMessage) {
ctx.sendUpstream(evt);
- } else if (decodedMessage != null) {
- if (decodedMessage instanceof Collection) {
- for (Object o : (Collection) decodedMessage) {
- saveOriginal(o, originalMessage);
- Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
+ } else {
+ if (decodedMessage == null) {
+ decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
+ }
+ if (decodedMessage != null) {
+ if (decodedMessage instanceof Collection) {
+ for (Object o : (Collection) decodedMessage) {
+ saveOriginal(o, originalMessage);
+ Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
+ }
+ } else {
+ saveOriginal(decodedMessage, originalMessage);
+ Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
- } else {
- saveOriginal(decodedMessage, originalMessage);
- Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
}
@@ -75,6 +80,10 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) {
}
+ protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) {
+ return null;
+ }
+
protected abstract Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception;
}