#1368 Restructures Message and Event filter framework.

This commit is contained in:
Dennis Sheirer
2023-07-12 04:41:57 -04:00
parent d246ffff30
commit b0a524cf62
121 changed files with 4869 additions and 4950 deletions

View File

@@ -2,24 +2,19 @@
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* * ******************************************************************************
* * Copyright (C) 2014-2019 Dennis Sheirer
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>
* * *****************************************************************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.module.decode.fleetsync2;
@@ -125,10 +120,8 @@ public class Fleetsync2DecoderState extends DecoderState
broadcast(new DecoderStateEvent(this, DecoderStateEvent.Event.DECODE, State.DATA));
break;
case GPS:
PlottableDecodeEvent plottableDecodeEvent = PlottableDecodeEvent.plottableBuilder(fleetsync.getTimestamp())
PlottableDecodeEvent plottableDecodeEvent = PlottableDecodeEvent.plottableBuilder(DecodeEventType.GPS, fleetsync.getTimestamp())
.channel(getCurrentChannel())
.eventType(DecodeEventType.GPS)
.eventDescription(DecodeEventType.GPS.toString())
.details(fleetsync.toString())
.identifiers(getIdentifierCollection().copyOf())
.protocol(Protocol.FLEETSYNC)
@@ -143,11 +136,9 @@ public class Fleetsync2DecoderState extends DecoderState
}
private DecodeEvent getDecodeEvent(Fleetsync2Message fleetsync, DecodeEventType eventType) {
return DecodeEvent.builder(fleetsync.getTimestamp())
return DecodeEvent.builder(eventType, fleetsync.getTimestamp())
.channel(getCurrentChannel())
.eventType(eventType)
.eventDescription(fleetsync.getMessageType().toString())
.details(fleetsync.toString())
.details(fleetsync.getMessageType() + " " + fleetsync)
.identifiers(getIdentifierCollection().copyOf())
.protocol(Protocol.FLEETSYNC)
.build();

View File

@@ -1,7 +1,6 @@
/*
* ******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2018 Dennis Sheirer
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,7 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* *****************************************************************************
* ****************************************************************************
*/
package io.github.dsheirer.module.decode.fleetsync2;
@@ -24,52 +23,63 @@ import io.github.dsheirer.filter.Filter;
import io.github.dsheirer.filter.FilterElement;
import io.github.dsheirer.message.IMessage;
import io.github.dsheirer.module.decode.fleetsync2.message.Fleetsync2Message;
import io.github.dsheirer.module.decode.ltrnet.LtrNetMessageType;
import java.util.function.Function;
import java.util.*;
public class FleetsyncMessageFilter extends Filter<IMessage>
/**
* Filter for Fleetsync messages.
*/
public class FleetsyncMessageFilter extends Filter<IMessage,FleetsyncMessageType>
{
private Map<FleetsyncMessageType,FilterElement<FleetsyncMessageType>> mElements = new EnumMap<>(FleetsyncMessageType.class);
private final KeyExtractor mKeyExtractor = new KeyExtractor();
/**
* Constructor
*/
public FleetsyncMessageFilter()
{
super("Fleetsync Message Filter");
super("Fleetsync Messages");
for(FleetsyncMessageType type : FleetsyncMessageType.values())
{
if(type != FleetsyncMessageType.UNKNOWN)
{
mElements.put(type, new FilterElement<FleetsyncMessageType>(type));
}
add(new FilterElement<>(type));
}
}
@Override
public boolean passes(IMessage message)
{
if(mEnabled && canProcess(message))
{
Fleetsync2Message fleet = (Fleetsync2Message)message;
if(mElements.containsKey(fleet.getMessageType()))
{
return mElements.get(fleet.getMessageType()).isEnabled();
}
}
return false;
}
/**
* Limits processing to only fleetsync messages.
* @param message to test
* @return true if message type is correct.
*/
@Override
public boolean canProcess(IMessage message)
{
return message instanceof Fleetsync2Message;
return message instanceof Fleetsync2Message && super.canProcess(message);
}
/**
* Key extractor for fleetsync messages
* @return key extractor
*/
@Override
public List<FilterElement<?>> getFilterElements()
public Function<IMessage, FleetsyncMessageType> getKeyExtractor()
{
return new ArrayList<FilterElement<?>>(mElements.values());
return mKeyExtractor;
}
/**
* Key extractor for Fleetsync 2 Messages.
*/
private class KeyExtractor implements Function<IMessage, FleetsyncMessageType>
{
@Override
public FleetsyncMessageType apply(IMessage message)
{
if(message instanceof Fleetsync2Message f2m)
{
return f2m.getMessageType();
}
return null;
}
}
}