@ -21,6 +21,12 @@ using namespace lookups;
# include <string>
# include <string>
# include <vector>
# include <vector>
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std : : mutex TalkgroupRulesLookup : : m_mutex ;
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Public Class Members
// Public Class Members
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
@ -105,11 +111,8 @@ bool TalkgroupRulesLookup::read()
/// </summary>
/// </summary>
void TalkgroupRulesLookup : : clear ( )
void TalkgroupRulesLookup : : clear ( )
{
{
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
m_groupVoice . clear ( ) ;
m_groupVoice . clear ( ) ;
}
m_mutex . unlock ( ) ;
}
}
/// <summary>
/// <summary>
@ -126,8 +129,7 @@ void TalkgroupRulesLookup::addEntry(uint32_t id, uint8_t slot, bool enabled)
source . tgSlot ( slot ) ;
source . tgSlot ( slot ) ;
config . active ( enabled ) ;
config . active ( enabled ) ;
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
[ & ] ( TalkgroupRuleGroupVoice x )
[ & ] ( TalkgroupRuleGroupVoice x )
{
{
@ -158,8 +160,6 @@ void TalkgroupRulesLookup::addEntry(uint32_t id, uint8_t slot, bool enabled)
m_groupVoice . push_back ( entry ) ;
m_groupVoice . push_back ( entry ) ;
}
}
}
m_mutex . unlock ( ) ;
}
}
/// <summary>
/// <summary>
@ -175,8 +175,7 @@ void TalkgroupRulesLookup::addEntry(TalkgroupRuleGroupVoice groupVoice)
uint32_t id = entry . source ( ) . tgId ( ) ;
uint32_t id = entry . source ( ) . tgId ( ) ;
uint8_t slot = entry . source ( ) . tgSlot ( ) ;
uint8_t slot = entry . source ( ) . tgSlot ( ) ;
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
[ & ] ( TalkgroupRuleGroupVoice x )
[ & ] ( TalkgroupRuleGroupVoice x )
{
{
@ -192,8 +191,6 @@ void TalkgroupRulesLookup::addEntry(TalkgroupRuleGroupVoice groupVoice)
else {
else {
m_groupVoice . push_back ( entry ) ;
m_groupVoice . push_back ( entry ) ;
}
}
}
m_mutex . unlock ( ) ;
}
}
/// <summary>
/// <summary>
@ -203,14 +200,11 @@ void TalkgroupRulesLookup::addEntry(TalkgroupRuleGroupVoice groupVoice)
/// <param name="slot">DMR slot this talkgroup is valid on.</param>
/// <param name="slot">DMR slot this talkgroup is valid on.</param>
void TalkgroupRulesLookup : : eraseEntry ( uint32_t id , uint8_t slot )
void TalkgroupRulesLookup : : eraseEntry ( uint32_t id , uint8_t slot )
{
{
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) , [ & ] ( TalkgroupRuleGroupVoice x ) { return x . source ( ) . tgId ( ) = = id & & x . source ( ) . tgSlot ( ) = = slot ; } ) ;
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) , [ & ] ( TalkgroupRuleGroupVoice x ) { return x . source ( ) . tgId ( ) = = id & & x . source ( ) . tgSlot ( ) = = slot ; } ) ;
if ( it ! = m_groupVoice . end ( ) ) {
if ( it ! = m_groupVoice . end ( ) ) {
m_groupVoice . erase ( it ) ;
m_groupVoice . erase ( it ) ;
}
}
}
m_mutex . unlock ( ) ;
}
}
/// <summary>
/// <summary>
@ -223,8 +217,7 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::find(uint32_t id, uint8_t slot)
{
{
TalkgroupRuleGroupVoice entry ;
TalkgroupRuleGroupVoice entry ;
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
[ & ] ( TalkgroupRuleGroupVoice x )
[ & ] ( TalkgroupRuleGroupVoice x )
{
{
@ -239,8 +232,6 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::find(uint32_t id, uint8_t slot)
} else {
} else {
entry = TalkgroupRuleGroupVoice ( ) ;
entry = TalkgroupRuleGroupVoice ( ) ;
}
}
}
m_mutex . unlock ( ) ;
return entry ;
return entry ;
}
}
@ -256,8 +247,7 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByRewrite(uint32_t peerId, uin
{
{
TalkgroupRuleGroupVoice entry ;
TalkgroupRuleGroupVoice entry ;
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
auto it = std : : find_if ( m_groupVoice . begin ( ) , m_groupVoice . end ( ) ,
[ & ] ( TalkgroupRuleGroupVoice x )
[ & ] ( TalkgroupRuleGroupVoice x )
{
{
@ -284,8 +274,6 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByRewrite(uint32_t peerId, uin
} else {
} else {
entry = TalkgroupRuleGroupVoice ( ) ;
entry = TalkgroupRuleGroupVoice ( ) ;
}
}
}
m_mutex . unlock ( ) ;
return entry ;
return entry ;
}
}
@ -336,8 +324,7 @@ bool TalkgroupRulesLookup::load()
// clear table
// clear table
clear ( ) ;
clear ( ) ;
m_mutex . lock ( ) ;
std : : lock_guard < std : : mutex > lock ( m_mutex ) ;
{
yaml : : Node & groupVoiceList = m_rules [ " groupVoice " ] ;
yaml : : Node & groupVoiceList = m_rules [ " groupVoice " ] ;
if ( groupVoiceList . size ( ) = = 0U ) {
if ( groupVoiceList . size ( ) = = 0U ) {
@ -365,8 +352,6 @@ bool TalkgroupRulesLookup::load()
: : LogInfoEx ( LOG_HOST , " Talkgroup NAME: %s SRC_TGID: %u SRC_TS: %u ACTIVE: %u PARROT: %u INCLUSIONS: %u EXCLUSIONS: %u REWRITES: %u " , groupName . c_str ( ) , tgId , tgSlot , active , parrot , incCount , excCount , rewrCount ) ;
: : LogInfoEx ( LOG_HOST , " Talkgroup NAME: %s SRC_TGID: %u SRC_TS: %u ACTIVE: %u PARROT: %u INCLUSIONS: %u EXCLUSIONS: %u REWRITES: %u " , groupName . c_str ( ) , tgId , tgSlot , active , parrot , incCount , excCount , rewrCount ) ;
}
}
}
m_mutex . unlock ( ) ;
size_t size = m_groupVoice . size ( ) ;
size_t size = m_groupVoice . size ( ) ;
if ( size = = 0U )
if ( size = = 0U )
@ -388,7 +373,7 @@ bool TalkgroupRulesLookup::save()
return false ;
return false ;
}
}
m_mutex. lock ( ) ;
std: : lock_guard < std : : mutex > lock ( m_mutex ) ;
// New list for our new group voice rules
// New list for our new group voice rules
yaml : : Node groupVoiceList ;
yaml : : Node groupVoiceList ;
@ -405,8 +390,6 @@ bool TalkgroupRulesLookup::save()
// Set the new rules
// Set the new rules
newRules [ " groupVoice " ] = groupVoiceList ;
newRules [ " groupVoice " ] = groupVoiceList ;
m_mutex . unlock ( ) ;
// Make sure we actually did stuff right
// Make sure we actually did stuff right
if ( newRules [ " groupVoice " ] . size ( ) ! = m_groupVoice . size ( ) ) {
if ( newRules [ " groupVoice " ] . size ( ) ! = m_groupVoice . size ( ) ) {
LogError ( LOG_HOST , " Generated YAML node for group lists did not match loaded group size! (%u != %u) " , newRules [ " groupVoice " ] . size ( ) , m_groupVoice . size ( ) ) ;
LogError ( LOG_HOST , " Generated YAML node for group lists did not match loaded group size! (%u != %u) " , newRules [ " groupVoice " ] . size ( ) , m_groupVoice . size ( ) ) ;