mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 14:38:14 +02:00
moving SharedMemory into namespace sls
This commit is contained in:
parent
40d2f66146
commit
bad44f5bf4
@ -26,6 +26,9 @@
|
|||||||
#include <future>
|
#include <future>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using sls::SharedMemory;
|
||||||
|
using sls::SharedMemoryError;
|
||||||
|
|
||||||
multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
|
multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
|
||||||
: detId(id) {
|
: detId(id) {
|
||||||
setupMultiDetector(verify, update);
|
setupMultiDetector(verify, update);
|
||||||
|
@ -1959,7 +1959,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
|
|||||||
int detId;
|
int detId;
|
||||||
|
|
||||||
/** Shared Memory object */
|
/** Shared Memory object */
|
||||||
SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
|
sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
|
||||||
|
|
||||||
/** pointers to the slsDetector structures */
|
/** pointers to the slsDetector structures */
|
||||||
std::vector<std::unique_ptr<slsDetector>> detectors;
|
std::vector<std::unique_ptr<slsDetector>> detectors;
|
||||||
|
@ -30,10 +30,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using sls::SharedMemoryError;
|
namespace sls {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class SharedMemory {
|
class SharedMemory {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -166,7 +167,7 @@ class SharedMemory {
|
|||||||
void UnmapSharedMemory() {
|
void UnmapSharedMemory() {
|
||||||
if (shared_struct != nullptr) {
|
if (shared_struct != nullptr) {
|
||||||
if (munmap(shared_struct, shmSize) < 0) {
|
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;
|
FILE_LOG(logERROR) << msg;
|
||||||
close(fd);
|
close(fd);
|
||||||
throw SharedMemoryError(msg);
|
throw SharedMemoryError(msg);
|
||||||
@ -236,8 +237,7 @@ class SharedMemory {
|
|||||||
|
|
||||||
std::string temp = ss.str();
|
std::string temp = ss.str();
|
||||||
if (temp.length() > NAME_MAX) {
|
if (temp.length() > NAME_MAX) {
|
||||||
std::string msg = "Shared memory initialization failed. " + temp + " has " + std::to_string(temp.length()) + " characters. \n"
|
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;
|
||||||
+ "Maximum is " + std::to_string(NAME_MAX) + ". Change the environment variable " + SHM_ENV_NAME;
|
|
||||||
FILE_LOG(logERROR) << msg;
|
FILE_LOG(logERROR) << msg;
|
||||||
throw SharedMemoryError(msg);
|
throw SharedMemoryError(msg);
|
||||||
}
|
}
|
||||||
@ -272,8 +272,7 @@ class SharedMemory {
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
// could not fstat
|
// could not fstat
|
||||||
if (fstat(fd, &sb) < 0) {
|
if (fstat(fd, &sb) < 0) {
|
||||||
std::string msg = "Could not verify existing shared memory " + name + " size match "
|
std::string msg = "Could not verify existing shared memory " + name + " size match " + "(could not fstat): " + strerror(errno);
|
||||||
+ "(could not fstat): " + strerror(errno);
|
|
||||||
FILE_LOG(logERROR) << msg;
|
FILE_LOG(logERROR) << msg;
|
||||||
close(fd);
|
close(fd);
|
||||||
throw SharedMemoryError(msg);
|
throw SharedMemoryError(msg);
|
||||||
@ -282,8 +281,7 @@ class SharedMemory {
|
|||||||
//size does not match
|
//size does not match
|
||||||
long unsigned int sz = (long unsigned int)sb.st_size;
|
long unsigned int sz = (long unsigned int)sb.st_size;
|
||||||
if (sz != expectedSize) {
|
if (sz != expectedSize) {
|
||||||
std::string msg = "Existing shared memory " + name + " size does not match"
|
std::string msg = "Existing shared memory " + name + " size does not match" + "Expected " + std::to_string(expectedSize) + ", found " + std::to_string(sz);
|
||||||
+ "Expected " + std::to_string(expectedSize) + ", found " + std::to_string(sz);
|
|
||||||
FILE_LOG(logERROR) << msg;
|
FILE_LOG(logERROR) << msg;
|
||||||
throw SharedMemoryError(msg);
|
throw SharedMemoryError(msg);
|
||||||
return 1;
|
return 1;
|
||||||
@ -302,3 +300,5 @@ class SharedMemory {
|
|||||||
|
|
||||||
T *shared_struct{nullptr};
|
T *shared_struct{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace sls
|
@ -24,6 +24,10 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
using sls::SharedMemory;
|
||||||
|
using sls::SharedMemoryError;
|
||||||
|
using sls::RuntimeError;
|
||||||
|
|
||||||
#define DEFAULT_HOSTNAME "localhost"
|
#define DEFAULT_HOSTNAME "localhost"
|
||||||
|
|
||||||
slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
|
slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
|
||||||
@ -290,7 +294,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FILE_LOG(logERROR) << "Unknown detector type! " << type;
|
FILE_LOG(logERROR) << "Unknown detector type! " << type;
|
||||||
throw std::exception();
|
throw RuntimeError("Unknown detector type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1736,7 +1736,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
|
|||||||
int detId;
|
int detId;
|
||||||
|
|
||||||
/** Shared Memory object */
|
/** Shared Memory object */
|
||||||
SharedMemory<sharedSlsDetector> detector_shm{0,0};
|
sls::SharedMemory<sharedSlsDetector> detector_shm{0,0};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ struct Data {
|
|||||||
char mess[50];
|
char mess[50];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using namespace sls;
|
||||||
|
|
||||||
TEST_CASE("Create SharedMemory read and write") {
|
TEST_CASE("Create SharedMemory read and write") {
|
||||||
|
|
||||||
SharedMemory<Data> shm(0, -1);
|
SharedMemory<Data> shm(0, -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user