// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector
// Copyright © 2021 Thomas A. Early N7TAE
//
// 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 .
#include
#include
#include "User.h"
CUser::CUser()
{
m_LastHeardTime = std::time(nullptr);
}
CUser::CUser(const CCallsign &my, const CCallsign &rpt1, const CCallsign &rpt2, const CCallsign &xlx)
{
m_My = my;
m_Rpt1 = rpt1;
m_Rpt2 = rpt2;
m_Xlx = xlx;
m_LastHeardTime = std::time(nullptr);
}
CUser::CUser(const CUser &user)
{
m_My = user.m_My;
m_Rpt1 = user.m_Rpt1;
m_Rpt2 = user.m_Rpt2;
m_Xlx = user.m_Xlx;
m_LastHeardTime = user.m_LastHeardTime;
}
////////////////////////////////////////////////////////////////////////////////////////
// operators
bool CUser::operator ==(const CUser &user) const
{
return ((user.m_My == m_My) && (user.m_Rpt1 == m_Rpt1) && (user.m_Rpt2 == m_Rpt2) && (user.m_Xlx == m_Xlx));
}
bool CUser::operator <(const CUser &user) const
{
// smallest is youngest
return (std::difftime(m_LastHeardTime, user.m_LastHeardTime) > 0);
}
////////////////////////////////////////////////////////////////////////////////////////
// reporting
void CUser::WriteXml(std::ofstream &xmlFile)
{
xmlFile << "" << std::endl;
xmlFile << "\t" << m_My << "" << std::endl;
xmlFile << "\t" << m_Rpt1 << "" << std::endl;
xmlFile << "\t" << m_Rpt2.GetCSModule() << "" << std::endl;
xmlFile << "\t" << m_Xlx << "" << std::endl;
char mbstr[100];
if (std::strftime(mbstr, sizeof(mbstr), "%FT%TZ", std::gmtime(&m_LastHeardTime)))
{
xmlFile << "\t" << mbstr << "" << std::endl;
}
xmlFile << "" << std::endl;
}
void CUser::JsonReport(nlohmann::json &report)
{
nlohmann::json juser;
juser["Callsign"] = m_My.GetCS();
juser["Repeater"] = m_Rpt1.GetCS();
juser["OnModule"] = std::string(1, m_Rpt2.GetCSModule());
juser["ViaPeer"] = m_Xlx.GetCS();
char s[100];
if (std::strftime(s, sizeof(s), "%FT%TZ", std::gmtime(&m_LastHeardTime)))
{
juser["LastHeard"] = s;
}
report["Users"].push_back(juser);
}