Merge pull request #109 from DSheirer/#100-patch_group_aliases

#100 patch group alias enhancement
This commit is contained in:
Denny Sheirer
2017-01-13 15:48:56 -05:00
committed by GitHub
3 changed files with 136 additions and 27 deletions

View File

@@ -218,7 +218,7 @@ public class AliasList implements Listener<AliasEvent>
//We don't maintain lookups for these items //We don't maintain lookups for these items
break; break;
default: default:
mLog.warn("Unrecognized Alias ID Type:" + id.getType().name()); mLog.warn("Unrecognized Alias ID Type:" + id.getType().name() + " - can't ADD to lookup table");
break; break;
} }
} }
@@ -358,10 +358,11 @@ public class AliasList implements Listener<AliasEvent>
break; break;
case NON_RECORDABLE: case NON_RECORDABLE:
case PRIORITY: case PRIORITY:
case BROADCAST_CHANNEL:
//We don't maintain lookups for these items //We don't maintain lookups for these items
break; break;
default: default:
mLog.warn("Unrecognized Alias ID Type:" + id.getType().name()); mLog.warn("Unrecognized Alias ID Type:" + id.getType().name() + " - can't REMOVE from lookup table");
break; break;
} }
} }

View File

@@ -30,7 +30,9 @@ import java.util.List;
public class PatchGroupAlias extends Alias public class PatchGroupAlias extends Alias
{ {
private Alias mPatchGroupAlias;
private List<Alias> mPatchedAliases = new ArrayList<>(); private List<Alias> mPatchedAliases = new ArrayList<>();
private List<String> mPatchedTalkgroupIDs = new ArrayList<>();
/** /**
* Patch group alias is a single alias for a group of aliases that are temporarily patched together. This will * Patch group alias is a single alias for a group of aliases that are temporarily patched together. This will
@@ -38,13 +40,37 @@ public class PatchGroupAlias extends Alias
* temporarily joined to form a patch group. * temporarily joined to form a patch group.
* *
* Alias properties such as recordable, streamable and call priority are an aggregation from the set of patched * Alias properties such as recordable, streamable and call priority are an aggregation from the set of patched
* aliases contained in this patch group alias and where applicable, return the highest value/priority from the * aliases contained in this patch group alias and the patch group ID alias and where applicable, return the highest
* group of patched aliases. * value/priority from the group of patched aliases.
*/ */
public PatchGroupAlias() public PatchGroupAlias()
{ {
} }
/**
* Sets an alias for this patch group ID
*/
public void setPatchGroupAlias(Alias alias)
{
mPatchGroupAlias = alias;
}
/**
* Alias for this patch group
*/
public Alias getPatchGroupAlias()
{
return mPatchGroupAlias;
}
/**
* Indicates if this patch group has an alias
*/
public boolean hasPatchGroupAlias()
{
return mPatchGroupAlias != null;
}
/** /**
* List of patched aliases contained in this patch group * List of patched aliases contained in this patch group
*/ */
@@ -66,6 +92,11 @@ public class PatchGroupAlias extends Alias
*/ */
public void addPatchedAlias(Alias alias) public void addPatchedAlias(Alias alias)
{ {
if(alias == PatchGroupAlias.this)
{
throw new IllegalArgumentException("Can't add patch group alias to itself - would create an infinite loop");
}
mPatchedAliases.add(alias); mPatchedAliases.add(alias);
} }
@@ -77,16 +108,39 @@ public class PatchGroupAlias extends Alias
mPatchedAliases.remove(alias); mPatchedAliases.remove(alias);
} }
/**
* Sets the list of patched talkgroup IDs for this patch group
*/
public void setPatchedTalkgroupIDs(List<String> talkgroupIDs)
{
mPatchedTalkgroupIDs = talkgroupIDs;
}
/**
* List of patched talkgroup IDs for this patch group
*/
public List<String> getPatchedTalkgroupIDs()
{
return mPatchedTalkgroupIDs;
}
@Override @Override
public String getName() public String getName()
{ {
if(getId().size() > 0) if(hasPatchGroupAlias())
{ {
for(AliasID id: getId()) return getPatchGroupAlias().getName();
}
else
{
if(getId().size() > 0)
{ {
if(id.getType() == AliasIDType.TALKGROUP) for(AliasID id: getId())
{ {
return "PATCH:" + ((TalkgroupID)id).getTalkgroup(); if(id.getType() == AliasIDType.TALKGROUP)
{
return "PATCH:" + ((TalkgroupID)id).getTalkgroup();
}
} }
} }
} }
@@ -104,6 +158,11 @@ public class PatchGroupAlias extends Alias
aliasActions.addAll(alias.getAction()); aliasActions.addAll(alias.getAction());
} }
if(hasPatchGroupAlias())
{
aliasActions.addAll(getPatchGroupAlias().getAction());
}
return aliasActions; return aliasActions;
} }
@@ -118,13 +177,13 @@ public class PatchGroupAlias extends Alias
} }
} }
return false; return hasPatchGroupAlias() && getPatchGroupAlias().hasActions();
} }
@Override @Override
public int getCallPriority() public int getCallPriority()
{ {
int highestPriority = Priority.DEFAULT_PRIORITY; int highestPriority = (hasPatchGroupAlias() ? getPatchGroupAlias().getCallPriority() : Priority.DEFAULT_PRIORITY);
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
@@ -140,6 +199,11 @@ public class PatchGroupAlias extends Alias
@Override @Override
public boolean hasCallPriority() public boolean hasCallPriority()
{ {
if(hasPatchGroupAlias() && getPatchGroupAlias().hasCallPriority())
{
return true;
}
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
if(alias.hasCallPriority()) if(alias.hasCallPriority())
@@ -154,6 +218,11 @@ public class PatchGroupAlias extends Alias
@Override @Override
public boolean isRecordable() public boolean isRecordable()
{ {
if(hasPatchGroupAlias() && getPatchGroupAlias().isRecordable())
{
return true;
}
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
if(alias.isRecordable()) if(alias.isRecordable())
@@ -168,6 +237,11 @@ public class PatchGroupAlias extends Alias
@Override @Override
public boolean isStreamable() public boolean isStreamable()
{ {
if(hasPatchGroupAlias() && getPatchGroupAlias().isStreamable())
{
return true;
}
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
if(alias.isStreamable()) if(alias.isStreamable())
@@ -184,6 +258,11 @@ public class PatchGroupAlias extends Alias
{ {
List<BroadcastChannel> broadcastChannels = new ArrayList<>(); List<BroadcastChannel> broadcastChannels = new ArrayList<>();
if(hasPatchGroupAlias())
{
broadcastChannels.addAll(getPatchGroupAlias().getBroadcastChannels());
}
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
for(BroadcastChannel broadcastChannel: alias.getBroadcastChannels()) for(BroadcastChannel broadcastChannel: alias.getBroadcastChannels())
@@ -201,6 +280,11 @@ public class PatchGroupAlias extends Alias
@Override @Override
public boolean hasBroadcastChannel(String channel) public boolean hasBroadcastChannel(String channel)
{ {
if(hasPatchGroupAlias() && getPatchGroupAlias().hasBroadcastChannel(channel))
{
return true;
}
for(Alias alias: mPatchedAliases) for(Alias alias: mPatchedAliases)
{ {
if(alias.hasBroadcastChannel(channel)) if(alias.hasBroadcastChannel(channel))

View File

@@ -2719,11 +2719,11 @@ public class P25DecoderState extends DecoderState
switch(((MotorolaTSBKMessage) tsbk).getMotorolaOpcode()) switch(((MotorolaTSBKMessage) tsbk).getMotorolaOpcode())
{ {
case PATCH_GROUP_CHANNEL_GRANT: case PATCH_GROUP_CHANNEL_GRANT:
PatchGroupVoiceChannelGrant gvcg = (PatchGroupVoiceChannelGrant) tsbk; PatchGroupVoiceChannelGrant pgvcg = (PatchGroupVoiceChannelGrant) tsbk;
channel = gvcg.getChannel(); channel = pgvcg.getChannel();
from = gvcg.getSourceAddress(); from = pgvcg.getSourceAddress();
to = gvcg.getPatchGroupAddress(); to = pgvcg.getPatchGroupAddress();
if(hasCallEvent(channel, from, to)) if(hasCallEvent(channel, from, to))
{ {
@@ -2734,10 +2734,10 @@ public class P25DecoderState extends DecoderState
P25CallEvent event = new P25CallEvent.Builder(CallEventType.PATCH_GROUP_CALL) P25CallEvent event = new P25CallEvent.Builder(CallEventType.PATCH_GROUP_CALL)
.aliasList(getAliasList()) .aliasList(getAliasList())
.channel(channel) .channel(channel)
.details((gvcg.isEncrypted() ? "ENCRYPTED " : "") + .details((pgvcg.isEncrypted() ? "ENCRYPTED " : "") +
(gvcg.isEmergency() ? " EMERGENCY " : "") + (pgvcg.isEmergency() ? " EMERGENCY " : "") +
"PATCH SESSION MODE:" + gvcg.getSessionMode().name()) "PATCH SESSION MODE:" + pgvcg.getSessionMode().name())
.frequency(gvcg.getDownlinkFrequency()) .frequency(pgvcg.getDownlinkFrequency())
.from(from) .from(from)
.to(to) .to(to)
.build(); .build();
@@ -2845,6 +2845,13 @@ public class P25DecoderState extends DecoderState
for(String talkgroupToAdd: talkgroupsToAdd) for(String talkgroupToAdd: talkgroupsToAdd)
{ {
//Exclude the patch group ID if it is included in the patched talkgroup list so that we don't have
//an infinite loop situation
if(talkgroupToAdd.equals(patchGroupID))
{
continue;
}
if(!patchedTalkgroups.contains(talkgroupToAdd)) if(!patchedTalkgroups.contains(talkgroupToAdd))
{ {
patchedTalkgroups.add(talkgroupToAdd); patchedTalkgroups.add(talkgroupToAdd);
@@ -2906,7 +2913,9 @@ public class P25DecoderState extends DecoderState
} }
/** /**
* Adds/updates a patch group alias to the alias list containing aliases for each of the patched talkgroups * Adds/updates a patch group alias to the alias list containing aliases for each of the patched talkgroups. If the
* patch group alias already exists, any patched talkgroups will be removed from the existing patch group alias and
* replaced with the aliases corresponding to the patched talkgroup aliases.
* *
* @param patchGroupID for the patch group * @param patchGroupID for the patch group
* @param patchedTalkgroups containing the talkgroup IDs for each of the patched talkgroups * @param patchedTalkgroups containing the talkgroup IDs for each of the patched talkgroups
@@ -2916,25 +2925,32 @@ public class P25DecoderState extends DecoderState
PatchGroupAlias patchGroupAlias = null; PatchGroupAlias patchGroupAlias = null;
//Check for an existing alias for the patch talkgroup //Check for an existing alias for the patch talkgroup
Alias alias = getAliasList().getTalkgroupAlias(patchGroupID); Alias existingAlias = getAliasList().getTalkgroupAlias(patchGroupID);
if(alias instanceof PatchGroupAlias) if(existingAlias instanceof PatchGroupAlias)
{ {
patchGroupAlias = (PatchGroupAlias)alias; patchGroupAlias = (PatchGroupAlias)existingAlias;
}
else if(alias != null)
{
//If the talkgroup is already aliased to a non-patch group, do nothing
} }
else else
{ {
patchGroupAlias = new PatchGroupAlias(); patchGroupAlias = new PatchGroupAlias();
if(existingAlias != null)
{
getAliasList().removeAlias(existingAlias);
patchGroupAlias.setPatchGroupAlias(existingAlias);
}
patchGroupAlias.addAliasID(new TalkgroupID(patchGroupID)); patchGroupAlias.addAliasID(new TalkgroupID(patchGroupID));
getAliasList().addAlias(patchGroupAlias); getAliasList().addAlias(patchGroupAlias);
} }
if(patchGroupAlias != null) if(patchGroupAlias != null)
{ {
patchGroupAlias.setPatchedTalkgroupIDs(patchedTalkgroups);
patchGroupAlias.clearPatchedAliases(); patchGroupAlias.clearPatchedAliases();
for(String patchedTalkgroup: patchedTalkgroups) for(String patchedTalkgroup: patchedTalkgroups)
@@ -2958,7 +2974,15 @@ public class P25DecoderState extends DecoderState
if(alias instanceof PatchGroupAlias) if(alias instanceof PatchGroupAlias)
{ {
getAliasList().removeAlias(alias); PatchGroupAlias patchGroupAlias = (PatchGroupAlias)alias;
getAliasList().removeAlias(patchGroupAlias);
//Replace our temporary patch group alias with the original alias for the patch group ID
if(patchGroupAlias.hasPatchGroupAlias())
{
getAliasList().addAlias(patchGroupAlias.getPatchGroupAlias());
}
} }
} }