Fawkes API  Fawkes Development Version
fawkes::SharedMemoryRegistry Class Reference

Shared memory registry. More...

#include <>>

List of all members.

Classes

struct  SharedMemID
 Shared memory identifier. More...

Public Member Functions

 SharedMemoryRegistry (bool master=false, const char *name=0)
 Constructor.
 ~SharedMemoryRegistry ()
 Destructor.
std::list
< SharedMemoryRegistry::SharedMemID
get_snapshot () const
 Get a snapshot of currently registered segments.
std::list
< SharedMemoryRegistry::SharedMemID
find_segments (const char *magic_token) const
 Find segments with particular magic token.
void add_segment (int shmid, const char *magic_token)
 Register a segment.
void remove_segment (int shmid)
 Remove segment.

Static Public Member Functions

static void cleanup (const char *name=0)
 Cleanup existing shared memory segments.

Detailed Description

Shared memory registry.

This class opens a named POSIX shared memory segment, which contains one instance of the MemInfo struct. It is used to detect and maintain existing SysV IPC shared memory segments in a platform independent way. SysV IPC shared memory segments have some advanced functionality, for example reporting how many processes have attached to the segment. For the registry however, we are more interested in using a symbolic name which is the same for registry entries. Therefore, we use this here. The struct is protected by a lock implemented as a semaphore. Whenever a shared memory segment is created, it is registered to the registry so others can find it. On destruction, it is unregistered from the registry.

Author:
Tim Niemueller

Constructor & Destructor Documentation

fawkes::SharedMemoryRegistry::SharedMemoryRegistry ( bool  master = false,
const char *  name = 0 
)

Constructor.

Parameters:
masterif true, the shared memory is first deleted, if it existed, and then created fresh. It is resized to contain one struct and initialized as an empty registry.
namename of the shared memory region. Must follow the rules set by shm_open(). If NULL defaults to "/fawkes-shmem-registry".

Definition at line 65 of file shm_registry.cpp.

fawkes::SharedMemoryRegistry::~SharedMemoryRegistry ( )

Destructor.

Definition at line 130 of file shm_registry.cpp.


Member Function Documentation

void fawkes::SharedMemoryRegistry::add_segment ( int  shmid,
const char *  magic_token 
)

Register a segment.

Parameters:
shmidshared memory ID of the SysV IPC segment
magic_tokenmagic token for the new segment

Definition at line 203 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::attach().

void fawkes::SharedMemoryRegistry::cleanup ( const char *  name = 0) [static]

Cleanup existing shared memory segments.

Parameters:
nameshared memory segment name

Definition at line 143 of file shm_registry.cpp.

std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::find_segments ( const char *  magic_token) const

Find segments with particular magic token.

Parameters:
magic_tokenmagic token to return IDs for
Returns:
list of segments that currently exist with the given magic token

Definition at line 177 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::attach(), and fawkes::SharedMemory::find().

std::list< SharedMemoryRegistry::SharedMemID > fawkes::SharedMemoryRegistry::get_snapshot ( ) const

Get a snapshot of currently registered segments.

Returns:
list of all currently registered segments

Definition at line 153 of file shm_registry.cpp.

void fawkes::SharedMemoryRegistry::remove_segment ( int  shmid)

Remove segment.

Parameters:
shmidshared memory ID of the segment to remove.

Definition at line 235 of file shm_registry.cpp.

Referenced by fawkes::SharedMemory::free().


The documentation for this class was generated from the following files: