Class DataBlockAccessor

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class DataBlockAccessor : public ska::pst::smrb::DataBlock

Abstract base class that provides an Object Oriented interface to interact with an existing PSRDADA Shared Memory Ring Buffer (SMRB).

Subclassed by ska::pst::smrb::DataBlockRead, ska::pst::smrb::DataBlockView, ska::pst::smrb::DataBlockWrite

Public Functions

explicit DataBlockAccessor(const std::string &key_string)

Construct a new DataBlock with specified key.

Parameters

key_string – 4 character hexidecimal key that identifies the SMRB in shared memory.

virtual ~DataBlockAccessor() = default

Destroy the Data Block object.

virtual void connect(int timeout) override

Attempt to connect to the existing SMRB within the specified timeout.

Parameters

timeout – the timeout for SMRB connection in seconds

virtual void disconnect() override

Disconnect from the SMRB.

virtual void lock() = 0

Obtain a exclusive lock on the SMRB (reader or writer) to prevent other clients from accessing.

virtual void unlock() = 0

Release the exclusive lock on the SMRB.

virtual void open() = 0

Open the SMRB for access.

virtual void close() = 0

Close the SMRB for access.

virtual char *open_block() = 0

Open a DataBlock buffer in the SMRB.

Returns

pointer to the opened DataBlock buffer

virtual ssize_t close_block(uint64_t bytes) = 0

Close a DataBlock buffer in the SMRB.

Parameters

bytes – number of bytes transacted in the DataBlock buffer

Returns

ssize_t Return 0 on success, -1 on failure

inline bool is_block_open() const

Return true if a DataBlock buffer is open.

Returns

true

Returns

false

inline bool is_block_full() const

Return true if the DataBlock buffer is full of data.

Returns

true

Returns

false

inline uint64_t get_buf_id() const

Return the DataBlock buffer index.

Returns

uint64_t current data block index

inline uint64_t get_buf_bytes() const

Return the current number of bytes in the opened block.

Returns

uint64_t number of bytes of data in the opened block

inline const char *get_config()

Return a pointer to a copy of the current HeaderBlock C-string.

Returns

const char* pointer to HeaderBlock C-string

inline const char *get_header()

Return a pointer to a copy of the current HeaderBlock C-string.

Returns

const char* pointer to HeaderBlock C-string

inline int get_device()

Return the CUDA device ID for the data block. If the DataBlock buffers exist in CUDA memory, the device will be >=0.

Returns

int CUDA device on which the DataBlock buffers reside, -1 if in CPU memory

inline bool get_locked()

Return true if the data block access has been locked for exclusivity.

Returns

true

Returns

false

inline bool get_opened()

Return true if the data block has been opened for I/O.

Returns

true

Returns

false

void check_have_config(bool expected)

Check if the have_config attribute matches expected, throw exception if not.

Parameters

expected – the expected value of the have_config attribute

void check_have_header(bool expected)

Check if the have_header attribute matches expected, throw exception if not.

Parameters

expected – the expected value of the have_header attribute

void clear_header()

Clear the header contents and set have_header = false.

void clear_config()

Clear the config contents and set have_config = false.

Protected Functions

void check_locked(bool expected)

helper method that throws runtime error if not locked

void check_opened(bool expected)

helper method that throws runtime error if not opened

Protected Attributes

bool locked = {false}

True if connection to PSRDADA SMRB is locked.

bool opened = {false}

True if the data block has been opened for reading or writing.

bool block_open = {false}

True if a PSRDADA SMRB DataBlock is opened for DMA.

char *curr_buf = {nullptr}

Pointer to the currently open data_block buffer.

uint64_t curr_buf_id = {0}

Index of the currently open data_block buffer.

uint64_t curr_buf_bytes = {0}

Number of bytes transacted on the currently open data_block buffer.

std::vector<char> config

copy of the current scan configuration from the header_block buffer

std::vector<char> header

copy of the current header configuration header_block buffer

bool have_config = {false}
bool have_header = {false}