Packet safety in scheduler

This commit is contained in:
sirjonasxx 2022-12-27 20:36:28 +01:00
parent a5d35207e1
commit 0c74260503
2 changed files with 17 additions and 10 deletions

View File

@ -121,7 +121,7 @@ public class HPacket implements StringifyAble {
} }
public void completePacket(PacketInfoManager packetInfoManager) { public void completePacket(PacketInfoManager packetInfoManager) {
if (isCorrupted() || identifier == null) return; if (isCorrupted() || identifier == null || packetInfoManager == null) return;
PacketInfo packetInfo = packetInfoManager.getPacketInfoFromName(identifierDirection, identifier); PacketInfo packetInfo = packetInfoManager.getPacketInfoFromName(identifierDirection, identifier);
if (packetInfo == null) { if (packetInfo == null) {
@ -718,7 +718,15 @@ public class HPacket implements StringifyAble {
public String toExpression() { public String toExpression() {
if (isCorrupted()) return ""; if (isCorrupted()) return "";
return PacketStringUtils.predictedExpression(this, null); return PacketStringUtils.predictedExpression(this, dummyPacketInfo());
}
/**
* Provides dummy packet information for a packet that hasn't been completed with headerId yet
*/
private PacketInfo dummyPacketInfo() {
if (isPacketComplete()) return null;
return new PacketInfo(identifierDirection, -1, "", identifier, null, "");
} }
public void setBytes(byte[] bytes) { public void setBytes(byte[] bytes) {

View File

@ -1,14 +1,12 @@
package gearth.ui.subforms.scheduler; package gearth.ui.subforms.scheduler;
import com.tulskiy.keymaster.common.Provider; import com.tulskiy.keymaster.common.Provider;
import gearth.GEarth;
import gearth.services.scheduler.Interval; import gearth.services.scheduler.Interval;
import gearth.services.scheduler.Scheduler; import gearth.services.scheduler.Scheduler;
import gearth.ui.translations.LanguageBundle; import gearth.ui.translations.LanguageBundle;
import gearth.ui.translations.TranslatableString; import gearth.ui.translations.TranslatableString;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@ -28,7 +26,7 @@ import java.util.List;
public class SchedulerController extends SubForm { public class SchedulerController extends SubForm {
private static final Interval defaultInterval = new Interval(0, 500); private static final Interval defaultInterval = new Interval(0, 500);
private static final HPacket defaultPacket = new HPacket(0); private static final HPacket defaultPacket = new HPacket("Chat", HMessage.Direction.TOCLIENT, -1, "Frank loves G-Earth", 0, 33, 0, 0);
public VBox schedulecontainer; public VBox schedulecontainer;
public GridPane header; public GridPane header;
@ -81,6 +79,7 @@ public class SchedulerController extends SubForm {
System.setErr(err); System.setErr(err);
initLanguageBinding(); initLanguageBinding();
setInputDefault(true);
} }
@Override @Override
@ -130,7 +129,7 @@ public class SchedulerController extends SubForm {
isBeingEdited.isUpdatedTrigger(); isBeingEdited.isUpdatedTrigger();
isBeingEdited = null; isBeingEdited = null;
setInputDefault(); setInputDefault(false);
} }
} }
@ -142,7 +141,7 @@ public class SchedulerController extends SubForm {
newItem.onDelete(() -> { newItem.onDelete(() -> {
if (isBeingEdited == newItem) { if (isBeingEdited == newItem) {
setInputDefault(); setInputDefault(false);
isBeingEdited = null; isBeingEdited = null;
} }
scheduler.remove(newItem); scheduler.remove(newItem);
@ -167,16 +166,16 @@ public class SchedulerController extends SubForm {
newItem.onIsBeingUpdatedTrigger(); newItem.onIsBeingUpdatedTrigger();
} }
else { else {
setInputDefault(); setInputDefault(false);
isBeingEdited.isUpdatedTrigger(); isBeingEdited.isUpdatedTrigger();
isBeingEdited = null; isBeingEdited = null;
} }
}); });
} }
private void setInputDefault() { private void setInputDefault(boolean showDummyPacket) {
txt_delay.setText(defaultInterval.toString()); txt_delay.setText(defaultInterval.toString());
txt_packet.setText(defaultPacket.toString()); txt_packet.setText(showDummyPacket ? defaultPacket.toExpression() : "");
rb_incoming.setSelected(true); rb_incoming.setSelected(true);
rb_outgoing.setSelected(false); rb_outgoing.setSelected(false);