9#include <boost/lambda/lambda.hpp>
18 :
DummyBackendBase(mapFileName, dataConsistencyKeyDescriptor), _mapFile(mapFileName) {
23 std::lock_guard<std::mutex> lock(
mutex);
29 std::lock_guard<std::mutex> lock(
mutex);
32 for(
auto& barSizesInByte : barSizesInBytes) {
34 auto nwords = (barSizesInByte.second +
sizeof(int32_t) - 1) /
sizeof(int32_t);
40 std::lock_guard<std::mutex> lock(
mutex);
46 std::lock_guard<std::mutex> lock(
mutex);
52 std::lock_guard<std::mutex> lock(
mutex);
56 unsigned int wordBaseIndex = address /
sizeof(int32_t);
57 TRY_REGISTER_ACCESS(
for(
unsigned int wordIndex = 0; wordIndex < sizeInBytes /
sizeof(int32_t);
58 ++wordIndex) { data[wordIndex] =
_barContents[bar].at(wordBaseIndex + wordIndex); });
64 std::lock_guard<std::mutex> lock(
mutex);
68 uint64_t wordBaseIndex = address /
sizeof(int32_t);
69 TRY_REGISTER_ACCESS(
for(
unsigned int wordIndex = 0; wordIndex < sizeInBytes /
sizeof(int32_t); ++wordIndex) {
70 if(
isReadOnly(bar, address + wordIndex *
sizeof(int32_t))) {
73 _barContents[bar].at(wordBaseIndex + wordIndex) = data[wordIndex];
82 std::stringstream info;
83 info <<
"DummyBackend";
88 for(
size_t i = 0; i < sizeInWords; ++i) {
102 AddressRange addressRange, boost::function<
void(
void)>
const& writeCallbackFunction) {
104 std::pair<
AddressRange, boost::function<
void(
void)>>(addressRange, writeCallbackFunction));
108 std::list<boost::function<void(
void)>> callbackFunctionsForThisRange =
110 for(
auto& function : callbackFunctionsForThisRange) {
129 std::list<boost::function<void(
void)>> returnList;
130 for(
auto callbackIter = startIterator; callbackIter != endIterator; ++callbackIter) {
132 returnList.push_back(callbackIter->second);
140 if(firstRange.
bar != secondRange.
bar) {
144 uint64_t startAddress = std::max(firstRange.
offset, secondRange.
offset);
145 uint64_t endAddress =
150 for(uint64_t address = startAddress; address < endAddress; address +=
sizeof(int32_t)) {
163 std::string address, std::map<std::string, std::string> parameters) {
164 if(parameters[
"map"].empty()) {
172 return returnInstance<DummyBackend>(
185 return {shared_from_this(), module, register_name};
189 auto asyncDomain = boost::dynamic_pointer_cast<async::DomainImpl<std::nullptr_t>>(
193 return asyncDomain->distribute(
nullptr);
#define TRY_REGISTER_ACCESS(COMMAND)
static BackendFactory & getInstance()
Static function to get an instance of factory.
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
void checkActiveException() final
Function to be called by backends when needing to check for an active exception.
std::atomic< bool > _opened
flag if backend is opened
Base class for DummyBackends, provides common functionality.
static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes)
std::map< uint64_t, size_t > getBarSizesInBytesFromRegisterMapping() const
Determines the size of each bar because the DummyBackends allocate memory per bar.
void write(uint64_t bar, uint64_t address, int32_t const *data, size_t sizeInBytes) override
Write function to be implemented by backends.
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
DummyRegisterRawAccessor getRawAccessor(const std::string &module, const std::string ®ister_name)
Get a raw accessor to the underlying memory with the convenience of using register names.
void read(uint64_t bar, uint64_t address, int32_t *data, size_t sizeInBytes) override
Read function to be implemented by backends.
std::set< std::pair< uint64_t, uint64_t > > _readOnlyAddresses
void setWriteCallbackFunction(AddressRange addressRange, boost::function< void(void)> const &writeCallbackFunction)
std::multimap< AddressRange, boost::function< void(void)> > _writeCallbackFunctions
void open() override
Open the device.
std::map< uint64_t, std::vector< int32_t > > _barContents
DummyBackend(const std::string &mapFileName, const std::string &dataConsistencyKeyDescriptor="")
static std::string convertPathRelativeToDmapToAbs(std::string const &mapfileName)
void closeImpl() override
This closes the device, clears all internal registers, read-only settings and callback functions.
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
std::list< boost::function< void(void)> > findCallbackFunctionsForAddressRange(AddressRange addressRange)
bool isWriteRangeOverlap(AddressRange firstRange, AddressRange secondRange)
returns true if the ranges overlap and at least one of the overlapping registers can be written
void writeRegisterWithoutCallback(uint64_t bar, uint64_t address, int32_t data)
Not write-protected function for internal use only.
bool isReadOnly(uint64_t bar, uint64_t address) const
void setReadOnly(uint64_t bar, uint64_t address, size_t sizeInWords)
VersionNumber triggerInterrupt(uint32_t interruptNumber) override
Simulate the arrival of an interrupt.
void runWriteCallbackFunctionsForAddressRange(AddressRange addressRange)
Accessor for raw 32 bit integer access to the underlying memory space.
Class for generating and holding version numbers without exposing a numeric representation.
boost::shared_ptr< Domain > getDomain(size_t key)
Return the shared pointer to the Domain for a key.
Exception thrown when a logic error has occured.
std::string extractDirectory(std::string const &path)
Returns the path to the directory containing the file provided as the input parameter.
std::string concatenatePaths(const std::string &path1, const std::string &path2)
Concatenates two given paths using custom rules.
std::string convertToAbsolutePath(std::string const &relativePath)
Converts a relative path to its absolute path.
std::string getDMapFilePath()
Returns the dmap file name which the library currently uses for looking up device(alias) names.
const uint32_t sizeInBytes