p26001-store-acs-soc-fw-app/video/core/SerialCode.cpp
2026-09-28 21:33:04 +08:00

107 lines
2.1 KiB
C++

/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include "SerialCode.h"
#include <Poco/Random.h>
namespace Video
{
namespace Core
{
/*
*******************************************************************************
* CLASS DEFINE
*******************************************************************************
*/
bool SerialCode::empty() const
{
return _value.isNull();
}
void SerialCode::reset()
{
return _value.clear();
}
const SerialCode& SerialCode::operator++()
{
if (empty())
_value = 0;
++_value;
return *this;
}
const SerialCode& SerialCode::operator++(int)
{
if (empty())
_value = 0;
_value++;
return *this;
}
bool SerialCode::operator!=(const SerialCode& other)
{
return _value != other._value;
}
const SerialCode& SerialCode::operator=(const SerialCode& other)
{
_value = other._value;
return *this;
}
const SerialCode& SerialCode::operator=(const uint32_t value)
{
_value = value;
return *this;
}
/*
*******************************************************************************
* CLASS DEFINE
*******************************************************************************
*/
SerialCodeManager::SerialCodeManager()
{
Poco::Random r;
r.seed();
_code = r.next();
}
void SerialCodeManager::increment()
{
_code++;
}
/*
*******************************************************************************
* CLASS DEFINE
*******************************************************************************
*/
bool SerialCodeWatcher::isChanged(const SerialCode& code, bool firstAsChanged)
{
if (_code.empty())
{
_code = code;
return firstAsChanged;
}
if (_code != code)
{
_code = code;
return true;
}
return false;
}
void SerialCodeWatcher::reset()
{
_code.reset();
}
}
}