reformat SharedMemoryFactory according to code guidelines

This commit is contained in:
Dennis Luxen 2014-06-11 15:22:51 +02:00
parent 096f187d6f
commit ed01eeaeb3

View File

@ -204,6 +204,7 @@ class SharedMemory : boost::noncopyable
private: private:
char *m_shmid; char *m_shmid;
bool m_initialized; bool m_initialized;
public: public:
void SetID(char *shmid) void SetID(char *shmid)
{ {
@ -217,8 +218,7 @@ class SharedMemory : boost::noncopyable
{ {
if (m_initialized) if (m_initialized)
{ {
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "automatic memory deallocation";
"automatic memory deallocation";
if (!boost::interprocess::shared_memory_object::remove(m_shmid)) if (!boost::interprocess::shared_memory_object::remove(m_shmid))
{ {
SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid; SimpleLogger().Write(logDEBUG) << "could not deallocate id " << m_shmid;
@ -228,13 +228,9 @@ class SharedMemory : boost::noncopyable
}; };
public: public:
void * Ptr() const void *Ptr() const { return region.get_address(); }
{
return region.get_address();
}
SharedMemory( SharedMemory(const boost::filesystem::path &lock_file,
const boost::filesystem::path & lock_file,
const int id, const int id,
const uint64_t size = 0, const uint64_t size = 0,
bool read_write = false, bool read_write = false,
@ -249,7 +245,8 @@ class SharedMemory : boost::noncopyable
read_write ? boost::interprocess::read_write : boost::interprocess::read_only); read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
region = boost::interprocess::mapped_region( region = boost::interprocess::mapped_region(
shm, read_write ? boost::interprocess::read_write : boost::interprocess::read_only); shm, read_write ? boost::interprocess::read_write : boost::interprocess::read_only);
} else }
else
{ // writeable pointer { // writeable pointer
// remove previously allocated mem // remove previously allocated mem
if (remove_prev) if (remove_prev)
@ -262,8 +259,7 @@ class SharedMemory : boost::noncopyable
region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write); region = boost::interprocess::mapped_region(shm, boost::interprocess::read_write);
remover.SetID(key); remover.SetID(key);
SimpleLogger().Write(logDEBUG) << SimpleLogger().Write(logDEBUG) << "writeable memory allocated " << size << " bytes";
"writeable memory allocated " << size << " bytes";
} }
} }
@ -275,10 +271,8 @@ class SharedMemory : boost::noncopyable
char k[500]; char k[500];
build_key(id, k); build_key(id, k);
result = RegionExists(k); result = RegionExists(k);
} catch(...)
{
result = false;
} }
catch (...) { result = false; }
return result; return result;
} }
@ -302,10 +296,8 @@ class SharedMemory : boost::noncopyable
{ {
boost::interprocess::shared_memory_object shm( boost::interprocess::shared_memory_object shm(
boost::interprocess::open_only, key, boost::interprocess::read_write); boost::interprocess::open_only, key, boost::interprocess::read_write);
} catch(...)
{
result = false;
} }
catch (...) { result = false; }
return result; return result;
} }
@ -316,7 +308,8 @@ class SharedMemory : boost::noncopyable
{ {
SimpleLogger().Write(logDEBUG) << "deallocating prev memory"; SimpleLogger().Write(logDEBUG) << "deallocating prev memory";
ret = boost::interprocess::shared_memory_object::remove(key); ret = boost::interprocess::shared_memory_object::remove(key);
} catch(const boost::interprocess::interprocess_exception &e) }
catch (const boost::interprocess::interprocess_exception &e)
{ {
if (e.get_error_code() != boost::interprocess::not_found_error) if (e.get_error_code() != boost::interprocess::not_found_error)
{ {