initial changes

This commit is contained in:
Erik Frojdh
2019-03-12 08:22:07 +01:00
parent 6765fd0dc8
commit a01d68a61f
6 changed files with 100 additions and 70 deletions

View File

@ -11,6 +11,7 @@
#include <iostream>
#include <string>
template <typename T>
class SharedMemory{
public:
/**
@ -43,21 +44,20 @@ public:
* throws a SharedMemoryException exception on failure to create, ftruncate or map
* @param sz of shared memory
*/
void* CreateSharedMemory(size_t sz);
void CreateSharedMemory(size_t sz);
/**
* Open existing Shared memory and call MapSharedMemory to map it to an address
* throws a SharedMemoryException exception on failure to open or map
* @param sz of shared memory
*/
void* OpenSharedMemory(size_t sz);
void OpenSharedMemory(size_t sz);
/**
* Unmap shared memory from an address
* throws a SharedMemoryException exception on failure
* @param addr double pointer to address to be mapped
*/
void UnmapSharedMemory(void* addr);
void UnmapSharedMemory();
/**
* Remove existing Shared memory
@ -69,6 +69,19 @@ public:
*/
static const int NAME_MAX = 255;
/*
Using the call operator to access the pointer
*/
T* operator()(){
return shared_struct;
}
const T* operator()() const{
return shared_struct;
}
private:
/**
* Create Shared memory name
@ -84,7 +97,7 @@ private:
* throws a SharedMemoryException exception on failure
* @param sz of shared memory
*/
void* MapSharedMemory(size_t sz);
T* MapSharedMemory(size_t sz);
/**
* Verify if existing shared memory size matches expected size
@ -102,4 +115,6 @@ private:
/** shm size */
size_t shmSize;
T* shared_struct;
};