9#include <boost/lambda/lambda.hpp>
22 std::lock_guard<std::mutex> lock(
mutex);
28 std::lock_guard<std::mutex> lock(
mutex);
31 for(
auto& barSizesInByte : barSizesInBytes) {
33 auto nwords = (barSizesInByte.second +
sizeof(int32_t) - 1) /
sizeof(int32_t);
39 std::lock_guard<std::mutex> lock(
mutex);
45 std::lock_guard<std::mutex> lock(
mutex);
51 std::lock_guard<std::mutex> lock(
mutex);
55 unsigned int wordBaseIndex = address /
sizeof(int32_t);
56 TRY_REGISTER_ACCESS(
for(
unsigned int wordIndex = 0; wordIndex < sizeInBytes /
sizeof(int32_t);
57 ++wordIndex) { data[wordIndex] =
_barContents[bar].at(wordBaseIndex + wordIndex); });
63 std::lock_guard<std::mutex> lock(
mutex);
67 uint64_t wordBaseIndex = address /
sizeof(int32_t);
68 TRY_REGISTER_ACCESS(
for(
unsigned int wordIndex = 0; wordIndex < sizeInBytes /
sizeof(int32_t); ++wordIndex) {
69 if(
isReadOnly(bar, address + wordIndex *
sizeof(int32_t))) {
72 _barContents[bar].at(wordBaseIndex + wordIndex) = data[wordIndex];
81 std::stringstream info;
82 info <<
"DummyBackend";
87 for(
size_t i = 0; i < sizeInWords; ++i) {
101 AddressRange addressRange, boost::function<
void(
void)>
const& writeCallbackFunction) {
103 std::pair<
AddressRange, boost::function<
void(
void)>>(addressRange, writeCallbackFunction));
107 std::list<boost::function<void(
void)>> callbackFunctionsForThisRange =
109 for(
auto& function : callbackFunctionsForThisRange) {
128 std::list<boost::function<void(
void)>> returnList;
129 for(
auto callbackIter = startIterator; callbackIter != endIterator; ++callbackIter) {
131 returnList.push_back(callbackIter->second);
139 if(firstRange.
bar != secondRange.
bar) {
143 uint64_t startAddress = std::max(firstRange.
offset, secondRange.
offset);
144 uint64_t endAddress =
149 for(uint64_t address = startAddress; address < endAddress; address +=
sizeof(int32_t)) {
162 std::string address, std::map<std::string, std::string> parameters) {
163 if(parameters[
"map"].empty()) {
183 return {shared_from_this(), module, register_name};
187 auto asyncDomain = boost::dynamic_pointer_cast<async::DomainImpl<std::nullptr_t>>(
191 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.
DummyBackend(const std::string &mapFileName)
std::map< uint64_t, std::vector< int32_t > > _barContents
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