e57::PacketReadCache Class Reference

#include <Packet.h>

Classes

struct  CacheEntry
 

Public Member Functions

std::unique_ptr< PacketLocklock (uint64_t packetLogicalOffset, char *&pkt)
 
 PacketReadCache (CheckedFile *cFile, unsigned packetCount)
 

Protected Member Functions

void readPacket (unsigned oldestEntry, uint64_t packetLogicalOffset)
 
void unlock (unsigned cacheIndex)
 

Protected Attributes

CheckedFilecFile_ = nullptr
 
std::vector< CacheEntryentries_
 
unsigned lockCount_ = 0
 
unsigned useCount_ = 0
 

Friends

class PacketLock
 Only PacketLock can unlock the cache. More...
 

Constructor & Destructor Documentation

◆ PacketReadCache()

PacketReadCache::PacketReadCache ( CheckedFile cFile,
unsigned  packetCount 
)

Member Function Documentation

◆ lock()

std::unique_ptr< PacketLock > PacketReadCache::lock ( uint64_t  packetLogicalOffset,
char *&  pkt 
)

Only allow one locked packet at a time.

Offset can't be 0

Linear scan for matching packet offset in cache

Found a match, so don't have to read anything

Mark entry with current useCount (keeps track of age of entry).

Publish buffer address to caller

Create lock so we are sure that we will be unlocked when use is finished.

Increment cache lock just before return

Get here if didn't find a match already in cache.

Find least recently used (LRU) packet buffer

Publish buffer address to caller

Create lock so we are sure we will be unlocked when use is finished.

Increment cache lock just before return

References e57::E57_ERROR_INTERNAL, entries_, lockCount_, PacketLock, readPacket(), e57::toString(), and useCount_.

Referenced by e57::CompressedVectorReaderImpl::CompressedVectorReaderImpl(), AddonManager.CommandAddonManager::on_package_updated(), drafttaskpanels.task_scale.ScaleTaskPanel::retranslateUi(), drafttaskpanels.task_scale.ScaleTaskPanel::setValue(), addonmanager_workers.CacheMacroCode::terminate(), and addonmanager_workers.CacheMacroCode::update_and_advance().

◆ readPacket()

void PacketReadCache::readPacket ( unsigned  oldestEntry,
uint64_t  packetLogicalOffset 
)
protected

Read header of packet first to get length. Use EmptyPacketHeader since it has the fields common to all packets.

Can't verify packet header here, because it is not really an EmptyPacketHeader.

Be paranoid about packetLength before read

Now read in whole packet into preallocated buffer_. Note buffer is

Verify that packet is good.

Mark entry with current useCount (keeps track of age of entry). This is a cache, so a small hiccup when useCount_ overflows won't hurt.

References cFile_, e57::DATA_PACKET, e57::DATA_PACKET_MAX, e57::E57_ERROR_BAD_CV_PACKET, e57::E57_ERROR_INTERNAL, e57::EMPTY_PACKET, entries_, e57::INDEX_PACKET, e57::CheckedFile::Logical, EmptyPacketHeader::packetLogicalLengthMinus1, EmptyPacketHeader::packetType, e57::CheckedFile::read(), e57::CheckedFile::seek(), e57::toString(), useCount_, EmptyPacketHeader::verify(), e57::DataPacket::verify(), and IndexPacket::verify().

Referenced by lock().

◆ unlock()

void PacketReadCache::unlock ( unsigned  cacheIndex)
protected

Friends And Related Function Documentation

◆ PacketLock

friend class PacketLock
friend

Only PacketLock can unlock the cache.

Referenced by lock().

Member Data Documentation

◆ cFile_

CheckedFile* e57::PacketReadCache::cFile_ = nullptr
protected

Referenced by readPacket().

◆ entries_

std::vector<CacheEntry> e57::PacketReadCache::entries_
protected

Referenced by lock(), and readPacket().

◆ lockCount_

unsigned e57::PacketReadCache::lockCount_ = 0
protected

Referenced by lock(), and unlock().

◆ useCount_

unsigned e57::PacketReadCache::useCount_ = 0
protected

Referenced by lock(), and readPacket().


The documentation for this class was generated from the following files: