diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-17 22:51:09 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-17 22:51:09 +1200 |
commit | 466e704934894ed44458bec798fa9fad0532bb4c (patch) | |
tree | eaf48175234c9d4d1b0456a542887a90c1377d00 /src/org/traccar/BaseProtocol.java | |
parent | 6bfaa4bdedcf6719de75afa905a309296aa1bd9d (diff) | |
parent | ff640cf8eb19cfeb3c8475ffd9b0aeccbd769f96 (diff) | |
download | trackermap-server-466e704934894ed44458bec798fa9fad0532bb4c.tar.gz trackermap-server-466e704934894ed44458bec798fa9fad0532bb4c.tar.bz2 trackermap-server-466e704934894ed44458bec798fa9fad0532bb4c.zip |
Merge commands implementation (fix #7)
Diffstat (limited to 'src/org/traccar/BaseProtocol.java')
-rw-r--r-- | src/org/traccar/BaseProtocol.java | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 86bebacc7..aa98d776c 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -15,42 +15,36 @@ */ package org.traccar; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import org.traccar.database.ActiveDevice; -import org.traccar.command.CommandType; -import org.traccar.command.CommandTemplate; -import org.traccar.command.GpsCommand; - -import java.util.HashMap; -import java.util.Map; +import org.traccar.model.Command; public abstract class BaseProtocol implements Protocol { private final String name; - private Map<CommandType, CommandTemplate> commandTemplates = new HashMap<>(); + private final Set<String> supportedCommands = new HashSet<>(); public BaseProtocol(String name) { this.name = name; - this.initCommandsTemplates(commandTemplates); } + @Override public String getName() { return name; } - @Override - public void sendCommand(ActiveDevice activeDevice, GpsCommand command) { - CommandTemplate commandMessage = commandTemplates.get(command.getType()); - - if (commandMessage == null) { - throw new RuntimeException("The command " + command + " is not yet supported in protocol " + this.getName()); - } - - Object response = commandMessage.applyTo(activeDevice, command); - - activeDevice.write(response); + public void setSupportedCommands(String... commands) { + supportedCommands.addAll(Arrays.asList(commands)); } - protected void initCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + @Override + public void sendCommand(ActiveDevice activeDevice, Command command) { + if (!supportedCommands.contains(command.getType())) { + throw new RuntimeException("Command " + command + " is not supported in protocol " + getName()); + } + activeDevice.write(command); } } |