131 lines
3.6 KiB
C++
131 lines
3.6 KiB
C++
/*
|
||
* DeviceInfo.cpp
|
||
*
|
||
* Created on: 16 апр. 2019 г.
|
||
* Author: titov
|
||
*/
|
||
|
||
#include "DeviceInfo.hh"
|
||
|
||
using configuration::hardware::DeviceInfo;
|
||
|
||
std::size_t DeviceInfo::num_records = 0;
|
||
configuration::hardware::DeviceInfo::Record * configuration::hardware::DeviceInfo::table = nullptr;
|
||
std::size_t configuration::hardware::DeviceInfo::size = 0;
|
||
|
||
bool DeviceInfo::notice(TypeId type_id,
|
||
PeripheralId peripheral_id,
|
||
CpuId cpu_id ) {
|
||
|
||
bool result;
|
||
|
||
if( result = num_records < size )
|
||
table[num_records++] = Record( type_id, peripheral_id, cpu_id );
|
||
|
||
return result;
|
||
|
||
}
|
||
|
||
bool DeviceInfo::search(TypeId type_id,
|
||
PeripheralId peripheral_id,
|
||
CpuId cpu_id ) {
|
||
|
||
for( std::size_t i = 0; i < size; ++i )
|
||
if( table[i].peripheral_id == peripheral_id
|
||
and table[i].type_id == type_id
|
||
and table[i].cpu_id == cpu_id )
|
||
return true;
|
||
|
||
return false;
|
||
}
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator::PeripheralIterator(
|
||
CpuId cpu_id, std::size_t pos ) : position(pos), cpu_id(cpu_id) {}
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator & DeviceInfo::Peripherals::PeripheralIterator::operator++() {
|
||
|
||
position = search_from( position + 1, cpu_id );
|
||
|
||
return *this;
|
||
}
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator DeviceInfo::Peripherals::PeripheralIterator::operator++(int) {
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator temp = *this;
|
||
++(*this);
|
||
return temp;
|
||
|
||
}
|
||
|
||
bool DeviceInfo::Peripherals::PeripheralIterator::operator==(
|
||
PeripheralIterator other ) const {
|
||
|
||
return position == other.position;
|
||
|
||
}
|
||
|
||
bool DeviceInfo::Peripherals::PeripheralIterator::operator!=(
|
||
PeripheralIterator other ) const {
|
||
|
||
return position != other.position;
|
||
|
||
}
|
||
|
||
DeviceInfo::Peripherals::PeripheralInfo DeviceInfo::Peripherals::PeripheralIterator::operator*() const {
|
||
|
||
return std::make_pair( table[position].type_id, table[position].peripheral_id );
|
||
|
||
}
|
||
|
||
std::size_t DeviceInfo::search_from( std::size_t i, CpuId cpu_id ) {
|
||
|
||
if( i != size ) while ( not( table[i].cpu_id == cpu_id )
|
||
and ++i < size );
|
||
|
||
return i;
|
||
}
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator DeviceInfo::Peripherals::begin() {
|
||
|
||
return DeviceInfo::Peripherals::PeripheralIterator( cpu_id, search_from( 0, cpu_id ) );
|
||
|
||
}
|
||
|
||
DeviceInfo::Peripherals::PeripheralIterator DeviceInfo::Peripherals::end() {
|
||
|
||
return DeviceInfo::Peripherals::PeripheralIterator( cpu_id, size );
|
||
|
||
}
|
||
|
||
DeviceInfo::Peripherals DeviceInfo::getPeripherals( CpuId cpu_id ) {
|
||
|
||
return DeviceInfo::Peripherals( cpu_id );
|
||
|
||
}
|
||
|
||
configuration::hardware::DeviceInfo::Record::Record(TypeId type_id,
|
||
PeripheralId peripheral_id,
|
||
CpuId cpu_id ) :
|
||
type_id(type_id),
|
||
peripheral_id(peripheral_id),
|
||
cpu_id(cpu_id),
|
||
unknow_param( 0xFEEDu ) {}
|
||
|
||
configuration::hardware::DeviceInfo::Peripherals::Peripherals(CpuId cpu_id) :
|
||
cpu_id(cpu_id) {}
|
||
|
||
void configuration::hardware::DeviceInfo::reset( CpuId incorrect_cpu_id ) {
|
||
|
||
for( unsigned i = 0; i < size; i++ )
|
||
table[i].cpu_id = incorrect_cpu_id;
|
||
|
||
}
|
||
|
||
void configuration::hardware::DeviceInfo::initialize( Record * p_table,
|
||
std::size_t quantity) {
|
||
|
||
table = p_table;
|
||
size = quantity;
|
||
|
||
}
|