aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
commit2a3fad9496decd83f06ae5abf067f8d4337ec741 (patch)
tree69837f0bf89cf6ff78915d70380118575cc5c47a /src/org/traccar/BaseProtocolDecoder.java
parenta8d2a0170b7ac891ffe784320ac2d1389f11bf68 (diff)
downloadtrackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.gz
trackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.bz2
trackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.zip
Major code refacroting
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 04b1a1eec..bcd441268 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
@@ -26,33 +26,54 @@ import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import org.traccar.database.DataManager;
+import org.traccar.helper.Log;
+import org.traccar.model.Device;
/**
* Base class for protocol decoders
*/
public abstract class BaseProtocolDecoder extends OneToOneDecoder {
- private final DataManager dataManager;
private final String protocol;
- private final Properties properties;
- public final DataManager getDataManager() {
- return dataManager;
+ public String getProtocol() {
+ return protocol;
}
- public final String getProtocol() {
- return protocol;
+ private long deviceId;
+
+ public boolean hasDeviceId() {
+ return (deviceId != 0);
}
-
- public final Properties getProperties() {
- return properties;
+
+ public long getDeviceId() {
+ return deviceId;
}
-
- public BaseProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- this.dataManager = dataManager;
+ public boolean identify(String uniqueId, boolean logWarning) {
+ try {
+ Device device = Context.getDataManager().getDeviceByUniqueId(uniqueId);
+ if (device != null) {
+ deviceId = device.getId();
+ return true;
+ } else {
+ if (logWarning) {
+ Log.warning("Unknown device - " + uniqueId);
+ }
+ return false;
+ }
+ } catch (Exception error) {
+ Log.warning(error);
+ return false;
+ }
+ }
+
+ public boolean identify(String uniqueId) {
+ return identify(uniqueId, true);
+ }
+
+ public BaseProtocolDecoder(String protocol) {
this.protocol = protocol;
- this.properties = properties;
}
@Override
@@ -77,7 +98,6 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
return decode(ctx, channel, msg);
-
}
@Override
@@ -85,7 +105,6 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
return null; // default implementation
-
}
}