class Db

Class Db: implements a simple data buffer in shared memory.

Public Methods

[more] Db(char* filename, int max_nb_ev = DB_NBEV_MAX_DEF, int max_ev_size = DB_MAXEVSIZE_DEF, int max_buf_vol = DB_MAX_BUF_VOL_DEF)
Constructor of the Data buffer Db.
[more] ~Db()
Destructor: cleans up all the IPC resources associated with Db
[more]void set_nb_buf_vol(int nb_buf_vol)
Member function that allows to change the maximum number of volatile buffers allowed
[more] Accessor member functions:
[more] Iterators over the buffer entries. A very simple iterator mechanism
[more] Member functions to handle volatile buffers.

Public Members

[more]enum db_par
Enumeration of the class specific constants.


Documentation

Class Db: implements a simple data buffer in shared memory.

The data buffer Db consists of a big chunk of shared memory that is divided into many slots of constant length. Valid data can be put into the slots by simply copying into it. The advantage of this simple approach is that it is very fast getting access to the slot: one simply has to know its offset within the shared memory. Note that we make sure that we allocate memory in chunks of PAGE_SIZE bytes.

A special case happens when one needs a buffer that is bigger than this fixed length slot: in this case we create a volatile buffer of the appropriate size to which we can attach or which we can destroy when it is no longer needed. Note that we cannot allocate memory in this way: therefore the class only allows to create a fixed number of volatile buffers. The ownership (uid) of a volatile buffer can also be set to a desired value in order to allow other processes to delete the volatile buffer once it is no longer used.

A very simple iterator mechanism exists to iterate over the fixed sized slots of the data buffer.

Modifications:

oenum db_par
Enumeration of the class specific constants.
DB_SHM_KEY is the default key for creating the shared memory.
DB_NBEV_MAX_DEF is the default value for the maximum number of buffers.
DB_MAXEVSIZE_DEF is the default size for the individual buffers in the system. DB_MAX_BUF_VOL_DEF is the default maximum number of volatile buffers.
PAGE_SIZE is the default page size.

o Db(char* filename, int max_nb_ev = DB_NBEV_MAX_DEF, int max_ev_size = DB_MAXEVSIZE_DEF, int max_buf_vol = DB_MAX_BUF_VOL_DEF)
Constructor of the Data buffer Db.
Parameters:
filename - string that uniquely identifies the data buffer.
max_nb_ev - Maximum number of events in the data buffer.
max_ev_size - Default size of every slot in the buffer.
max_buf_vol - maximum number of volatile bufferrs.

o ~Db()
Destructor: cleans up all the IPC resources associated with Db

ovoid set_nb_buf_vol(int nb_buf_vol)
Member function that allows to change the maximum number of volatile buffers allowed

o Accessor member functions:

oinline int get_slot_size() const
Returns the fixed slot size of the data buffer

oinline int get_nslots() const
Returns the number of entries in the data buffer

oinline int* get_first_addr() const
Returns the start address of the data buffer

oinline int* get_last_addr() const
Returns the end address of the data buffer

oinline int get_nbuf_vol_max() const
Returns the maximum number of volatile buffers allowed

oinline int get_nbuf_vol() const
Returns the number of volatile buffers currently in use

oint get_id()
Returns the identifier assocaited with the shared memory of the data buffer

oint get_status()
Returns the status of the data buffer.
Returns:
status: ddcFailure if a serious error occured (while creating the buffers ( volatile or not )).
ddcSuccess if good status

o Iterators over the buffer entries. A very simple iterator mechanism
exists to iterate over all the entries of the buffer. We embed this into the class Db in order not to have too many classes. The iterator is a private data member that can be incremented, reset and dereferenced.

oint get_iterator()
Return the current iterator position

ovoid reset_iterator()
Reset the iterator to the first data buffer

oint incr_iterator()
Increment the iterator. If we are at the end, we reset the iterator to the beginning.

oint* deref_iterator()
Dereference the iterator

o Member functions to handle volatile buffers.

oint create_volatile_buffer(int &size, int &id, void* &addr, BOOL valid_uid = false, const uid_t uid = 0)
Creates a volatile buffer.
Parameters:
size - : requested size of the volatile buffer. Returns actual size allocated.
id - : returns identifier of the volatile buffer.
addr - : returns the address of the volatile buffer.
valid_uid - : if true we set the ownership (uid) of the volatile buffer.
uid - : if valid_uid is true, we set the uid to this value.
Returns:
ddcSuccess if success, ddcFailure otherwise.

oint attach_volatile_buffer(int id, void* &addr)
Attaches to the volatile buffer.
Parameters:
id - : identifer of the volatile buffer.
addr - : Address where the data is located within the address space of the calling process.
Returns:
ddcSuccess if success, ddcFailure otherwise.

oint delete_volatile_buffer(const int id)
Deletes the volatile buffer. Note that deleting a volatile buffer means detaching from it. The memory associated with it is not freed.
Parameters:
id - : identifer of the volatile buffer.
Returns:
ddcSuccess if success, ddcFailure if error.

oint remove_buffer(const int id)
Removes the volatile buffer. Remove detaches and deletes the shared memory from the system. In order for this call to succeed the uid of the volatile buffer must match the one of the calling process.
Parameters:
id - : Identifier of the volatile buffer.
Returns:
ddcSuccess if success, ddcFailure if error.


This class has no child classes.
Author:
C.Witzig
Date: Dec 2, 1997
Version:
Last update:

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.