TGHandler: per-peer attribution for trunk-talker state
Add setTrunkTalkerForTGViaPeer, clearTrunkTalkersForPeer, and peerIdForTG to support selective cleanup of trunk-talker state when a specific peer disconnects (needed by the TWIN link protocol). Also ensure clearTrunkTalkerForTG and clearAllTrunkTalkers keep the new m_trunk_talker_peer_ids map in sync.
This commit is contained in:
1 parent
e6946d0da8
commit
c76f07af31
2 files changed
+68
-1
No files matched your search
@@ -299,12 +299,14 @@ void TGHandler::setTrunkTalkerForTG(uint32_t tg, const std::string& callsign)
|
||||
|
||||
void TGHandler::clearTrunkTalkerForTG(uint32_t tg)
|
||||
{
|
||||
m_trunk_talker_peer_ids.erase(tg);
|
||||
setTrunkTalkerForTG(tg, "");
|
||||
} /* TGHandler::clearTrunkTalkerForTG */
|
||||
|
||||
|
||||
void TGHandler::clearAllTrunkTalkers(void)
|
||||
{
|
||||
m_trunk_talker_peer_ids.clear();
|
||||
std::vector<uint32_t> keys;
|
||||
for (auto& kv : m_trunk_talkers)
|
||||
{
|
||||
@@ -312,11 +314,53 @@ void TGHandler::clearAllTrunkTalkers(void)
|
||||
}
|
||||
for (uint32_t tg : keys)
|
||||
{
|
||||
clearTrunkTalkerForTG(tg);
|
||||
setTrunkTalkerForTG(tg, "");
|
||||
}
|
||||
} /* TGHandler::clearAllTrunkTalkers */
|
||||
|
||||
|
||||
void TGHandler::setTrunkTalkerForTGViaPeer(uint32_t tg,
|
||||
const std::string& callsign,
|
||||
const std::string& peer_id)
|
||||
{
|
||||
setTrunkTalkerForTG(tg, callsign);
|
||||
if (callsign.empty())
|
||||
{
|
||||
m_trunk_talker_peer_ids.erase(tg);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_trunk_talker_peer_ids[tg] = peer_id;
|
||||
}
|
||||
} /* TGHandler::setTrunkTalkerForTGViaPeer */
|
||||
|
||||
|
||||
void TGHandler::clearTrunkTalkersForPeer(const std::string& peer_id)
|
||||
{
|
||||
for (auto it = m_trunk_talker_peer_ids.begin();
|
||||
it != m_trunk_talker_peer_ids.end(); )
|
||||
{
|
||||
if (it->second == peer_id)
|
||||
{
|
||||
uint32_t tg = it->first;
|
||||
it = m_trunk_talker_peer_ids.erase(it);
|
||||
setTrunkTalkerForTG(tg, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
} /* TGHandler::clearTrunkTalkersForPeer */
|
||||
|
||||
|
||||
std::string TGHandler::peerIdForTG(uint32_t tg) const
|
||||
{
|
||||
auto it = m_trunk_talker_peer_ids.find(tg);
|
||||
return (it != m_trunk_talker_peer_ids.end()) ? it->second : std::string();
|
||||
} /* TGHandler::peerIdForTG */
|
||||
|
||||
|
||||
std::string TGHandler::trunkTalkerForTG(uint32_t tg) const
|
||||
{
|
||||
auto it = m_trunk_talkers.find(tg);
|
||||
|
||||
@@ -174,6 +174,28 @@ class TGHandler : public sigc::trackable
|
||||
return m_trunk_talkers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Like setTrunkTalkerForTG, but also records which external
|
||||
* peer (by TRUNK section id) holds the TG. Used by the twin
|
||||
* link so state can be cleaned up per-peer on disconnect.
|
||||
*
|
||||
* Passing an empty callsign clears the talker for this TG.
|
||||
*/
|
||||
void setTrunkTalkerForTGViaPeer(uint32_t tg,
|
||||
const std::string& callsign,
|
||||
const std::string& peer_id);
|
||||
|
||||
/**
|
||||
* @brief Clear all trunk-talker entries attributed to a given peer
|
||||
* (e.g. when that peer's trunk disconnects).
|
||||
*/
|
||||
void clearTrunkTalkersForPeer(const std::string& peer_id);
|
||||
|
||||
/**
|
||||
* @brief Return the peer_id that holds the TG, or "" if none.
|
||||
*/
|
||||
std::string peerIdForTG(uint32_t tg) const;
|
||||
|
||||
bool allowTgSelection(ReflectorClient *client, uint32_t tg);
|
||||
|
||||
bool allowTgMonitoring(ReflectorClient *client, uint32_t tg);
|
||||
@@ -221,6 +243,7 @@ class TGHandler : public sigc::trackable
|
||||
IdMap m_id_map;
|
||||
ClientMap m_client_map;
|
||||
std::map<uint32_t, std::string> m_trunk_talkers;
|
||||
std::map<uint32_t, std::string> m_trunk_talker_peer_ids; // tg -> peer_id
|
||||
Async::Timer m_timeout_timer;
|
||||
unsigned m_sql_timeout;
|
||||
unsigned m_sql_timeout_blocktime;
|
||||
|
||||
Reference in new issue
Block a user