diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index fda6a1a9c..2bb767dfa 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -26,6 +26,9 @@ #include #include +using sls::SharedMemory; +using sls::SharedMemoryError; + multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) : detId(id) { setupMultiDetector(verify, update); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index e555d0c9e..7162d1098 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1959,7 +1959,7 @@ class multiSlsDetector : public virtual slsDetectorDefs, int detId; /** Shared Memory object */ - SharedMemory multi_shm{0, -1}; + sls::SharedMemory multi_shm{0, -1}; /** pointers to the slsDetector structures */ std::vector> detectors; diff --git a/slsDetectorSoftware/sharedMemory/SharedMemory.h b/slsDetectorSoftware/sharedMemory/SharedMemory.h index fa3ee8fc3..9faa6e5bf 100644 --- a/slsDetectorSoftware/sharedMemory/SharedMemory.h +++ b/slsDetectorSoftware/sharedMemory/SharedMemory.h @@ -30,10 +30,11 @@ #include #include -using sls::SharedMemoryError; +namespace sls { template class SharedMemory { + public: /** * Constructor @@ -166,7 +167,7 @@ class SharedMemory { void UnmapSharedMemory() { if (shared_struct != nullptr) { if (munmap(shared_struct, shmSize) < 0) { - std::string msg = "Unmapping shared memory " + name +" failed: " + strerror(errno); + std::string msg = "Unmapping shared memory " + name + " failed: " + strerror(errno); FILE_LOG(logERROR) << msg; close(fd); throw SharedMemoryError(msg); @@ -236,8 +237,7 @@ class SharedMemory { std::string temp = ss.str(); if (temp.length() > NAME_MAX) { - std::string msg = "Shared memory initialization failed. " + temp + " has " + std::to_string(temp.length()) + " characters. \n" - + "Maximum is " + std::to_string(NAME_MAX) + ". Change the environment variable " + SHM_ENV_NAME; + std::string msg = "Shared memory initialization failed. " + temp + " has " + std::to_string(temp.length()) + " characters. \n" + "Maximum is " + std::to_string(NAME_MAX) + ". Change the environment variable " + SHM_ENV_NAME; FILE_LOG(logERROR) << msg; throw SharedMemoryError(msg); } @@ -272,8 +272,7 @@ class SharedMemory { struct stat sb; // could not fstat if (fstat(fd, &sb) < 0) { - std::string msg = "Could not verify existing shared memory " + name + " size match " - + "(could not fstat): " + strerror(errno); + std::string msg = "Could not verify existing shared memory " + name + " size match " + "(could not fstat): " + strerror(errno); FILE_LOG(logERROR) << msg; close(fd); throw SharedMemoryError(msg); @@ -282,8 +281,7 @@ class SharedMemory { //size does not match long unsigned int sz = (long unsigned int)sb.st_size; if (sz != expectedSize) { - std::string msg = "Existing shared memory " + name + " size does not match" - + "Expected " + std::to_string(expectedSize) + ", found " + std::to_string(sz); + std::string msg = "Existing shared memory " + name + " size does not match" + "Expected " + std::to_string(expectedSize) + ", found " + std::to_string(sz); FILE_LOG(logERROR) << msg; throw SharedMemoryError(msg); return 1; @@ -302,3 +300,5 @@ class SharedMemory { T *shared_struct{nullptr}; }; + +} // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 905f4053f..afd0df94a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -24,6 +24,10 @@ #include #include +using sls::SharedMemory; +using sls::SharedMemoryError; +using sls::RuntimeError; + #define DEFAULT_HOSTNAME "localhost" slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify) @@ -290,7 +294,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL break; default: FILE_LOG(logERROR) << "Unknown detector type! " << type; - throw std::exception(); + throw RuntimeError("Unknown detector type"); } } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 713e3d228..0b60ddba0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1736,7 +1736,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs { int detId; /** Shared Memory object */ - SharedMemory detector_shm{0,0}; + sls::SharedMemory detector_shm{0,0}; }; diff --git a/slsDetectorSoftware/tests/test-SharedMemory.cpp b/slsDetectorSoftware/tests/test-SharedMemory.cpp index 5746cebd9..e8268d379 100644 --- a/slsDetectorSoftware/tests/test-SharedMemory.cpp +++ b/slsDetectorSoftware/tests/test-SharedMemory.cpp @@ -11,6 +11,8 @@ struct Data { char mess[50]; }; +using namespace sls; + TEST_CASE("Create SharedMemory read and write") { SharedMemory shm(0, -1);