162 lines
4.8 KiB
C++
Executable File
162 lines
4.8 KiB
C++
Executable File
// **************************************************************************
|
|
//
|
|
// (C) Copyright 2009 Swiss SIMTEC AG
|
|
//
|
|
// **************************************************************************
|
|
//
|
|
// $HeadURL$
|
|
// $LastChangedBy$
|
|
// $LastChangedDate$
|
|
// $LastChangedRevision$
|
|
//
|
|
// **************************************************************************
|
|
|
|
// manual class headers
|
|
#include "GeoPairingImplAirTargetCache.hpp"
|
|
#include <GBL_ConfigSystem/geoconfig.h>
|
|
|
|
// from cpp_includes
|
|
#include "GeoPairingImplAirTargetCacheData.hpp"
|
|
|
|
namespace N_GeoPairingImpl
|
|
{
|
|
|
|
// ---------------------------------------------------------------
|
|
// Constructor
|
|
// ---------------------------------------------------------------
|
|
GeoPairingImplAirTargetCache::GeoPairingImplAirTargetCache(SInt32 a_player, CacheType *a_cacheData)
|
|
: m_CacheData(a_cacheData),
|
|
m_PlayerID(a_player),
|
|
m_Timeout(0),
|
|
m_logger(CesGeoPairing::getLogger("Plugin.GeoPairing.GeoPairingImplAirTargetCache"))
|
|
{
|
|
auto l_config = N_ConfigSystem::GeoConfig::getInstance();
|
|
m_Timeout = l_config->getInteger(QStringLiteral("IGLA"), QStringLiteral("CacheTimeout"), 5);
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
// retrieves the last cached tracking state
|
|
// ---------------------------------------------------------------
|
|
bool GeoPairingImplAirTargetCache::getLatestTrackState(SInt32 a_targetID) const
|
|
{
|
|
GeoPairingImplAirTargetCacheData *l_Cache = getLatestCacheData(a_targetID);
|
|
if (l_Cache == nullptr)
|
|
return false;
|
|
|
|
return l_Cache->m_TrackState;
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
// retrieves the last cached tracking time
|
|
// ---------------------------------------------------------------
|
|
UInt32 GeoPairingImplAirTargetCache::getLatestTrackTime(SInt32 a_targetID) const
|
|
{
|
|
GeoPairingImplAirTargetCacheData *l_Cache = getLatestCacheData(a_targetID);
|
|
if (l_Cache == nullptr)
|
|
return 0;
|
|
|
|
return l_Cache->m_TrackTime;
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
GeoPairingImplAirTargetCacheData *GeoPairingImplAirTargetCache::getLatestCacheData(SInt32 a_targetID) const
|
|
{
|
|
if (m_CacheData == nullptr)
|
|
{
|
|
ERROR_LOG(m_logger) << "No global Cache pointer present!";
|
|
return nullptr;
|
|
}
|
|
|
|
if (m_CacheData->empty())
|
|
{
|
|
INFO_LOG(m_logger) << "Global Cache empty";
|
|
return nullptr;
|
|
}
|
|
|
|
CacheType::iterator it = m_CacheData->find(m_PlayerID);
|
|
if (it == m_CacheData->end())
|
|
{
|
|
INFO_LOG(m_logger) << "No Cache present for Player " << m_PlayerID
|
|
<< " tracking Target " << a_targetID;
|
|
return nullptr;
|
|
}
|
|
|
|
CacheDataType *l_Cache = (it->second);
|
|
|
|
if (l_Cache->empty())
|
|
{
|
|
INFO_LOG(m_logger) << "Cache for Player " << m_PlayerID << " is empty";
|
|
return nullptr;
|
|
}
|
|
|
|
CacheDataType::iterator itC = l_Cache->find(a_targetID);
|
|
if (itC == l_Cache->end())
|
|
{
|
|
INFO_LOG(m_logger) << "Target " << a_targetID
|
|
<< " not found in Cache of Player "
|
|
<< m_PlayerID;
|
|
return nullptr;
|
|
}
|
|
|
|
return itC->second;
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
// store latest state
|
|
// ---------------------------------------------------------------
|
|
bool GeoPairingImplAirTargetCache::storeLatestTrackState(SInt32 a_targetID, UInt32 a_trackingTime, bool a_trackingState)
|
|
{
|
|
if (m_CacheData == nullptr)
|
|
{
|
|
ERROR_LOG(m_logger) << "No global Cache pointer present!";
|
|
return false;
|
|
}
|
|
|
|
CacheType::iterator it = m_CacheData->find(m_PlayerID);
|
|
if (it == m_CacheData->end())
|
|
{
|
|
(*m_CacheData)[m_PlayerID] = new CacheDataType();
|
|
INFO_LOG(m_logger) << "Create new Cache for Player " << m_PlayerID;
|
|
}
|
|
|
|
CacheDataType *l_Cache = (*m_CacheData)[m_PlayerID];
|
|
|
|
GeoPairingImplAirTargetCacheData *l_CacheData = nullptr;
|
|
CacheDataType::iterator itC = l_Cache->find(a_targetID);
|
|
if (itC == l_Cache->end())
|
|
{
|
|
l_CacheData = new GeoPairingImplAirTargetCacheData();
|
|
(*l_Cache)[a_targetID] = l_CacheData;
|
|
INFO_LOG(m_logger) << "Create new CacheObject for Target "
|
|
<< a_targetID << " in Cache of Player "
|
|
<< m_PlayerID;
|
|
}
|
|
else
|
|
l_CacheData = (*l_Cache)[a_targetID];
|
|
|
|
l_CacheData->m_TrackTime = a_trackingTime;
|
|
l_CacheData->m_TrackState = a_trackingState;
|
|
|
|
INFO_LOG(m_logger) << "Stored Tracking Time and State for Target "
|
|
<< a_targetID << " in Cache of Player "
|
|
<< m_PlayerID;
|
|
INFO_LOG(m_logger) << "-> Cached Time : " << a_trackingTime
|
|
<< " State : " << a_trackingState;
|
|
return true;
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
// get cache timeout
|
|
// ---------------------------------------------------------------
|
|
UInt32 GeoPairingImplAirTargetCache::getCacheTimeout() const
|
|
{
|
|
return m_Timeout;
|
|
}
|
|
|
|
} // namespace N_GeoPairingImpl;
|