Class Fifo_system: Class that comprises the individual fifos.
Public Methods
-
Creation and removal of the fifo system and the fifos
-
Read/write and control access to the fifos
-
Access to information about the fifo system
-
Access to information about the fifos
Documentation
Class Fifo_system: Class that comprises the individual fifos.
The fifos themselves are objects that reside in shared memory. The
Fifo_sytem itself is an object in the local address space of the
process and regulates the access to the fifos. This is necessary
as different processes attach the same shared memory at different address
locations.
The class Fifo_sytem allows to create and delete fifos, coordinates
the read/write operations and can return various status information
about the fifo system.
Note: This class (and not the Fifo class) controls all the
shared resources that controls the access to the fifos.
Modifications:
- Initialise the pointers to the fifos in shared memory to NULL
in the constructor to allow check in remove_fifo_system whether we
actually succeeded to create the IPC resources as we attempt to delete them.
CW Mar 17, 99
- Add empty_fifo member function.
Notized that the garbage demon doesn't properly handle a process that
crashed and leaves a non-empty fifo behind. We fix this by expanding
delete_fifo such that it empties the fifo. The fifo_entries that
are found in there will be put back into the INPUT fifo.
CW Dec 7, 1999
Creation and removal of the fifo system and the fifos
Fifo_system(char* filename, int nfifos, int fifo_depth)
- Creates the Fifo system.
Creates/attaches to the shared memory and semaphores and (possibly)
initialises them.
- Parameters:
- filename - : project file for the shared resources (see package otools)
nfifos - : maximum number of fifos.
fifo_depth - : default depth of the fifos.
~Fifo_system()
- Destructor
int remove_fifo_system()
- Removes the fifo system.
The destructor only deletes the fifo system for the calling process and
deletes the shared resources only if the calling process is the last
one to detach. remove_fifo_system in contrast forces the removal
of the system.
Fifo* create_fifo(const char* name, const char* type, Fifo::sFifo_mode mode, int slot_nb = -1)
- Creates a fifo in the fifo system.
Checks whether the fifo already exists or has to be created. If we
attach to an existing fifo, check the mode.
- Parameters:
- name - : name of the fifo - see constructor of class fifo for details.
type - : type of the fifo - see constructor of class fifo for details.
mode - : mode of the fifo - see constructor of class fifo for details.
slot_nb - : index of the fifo in the array of fifos - see constructor of class fifo for details.
- Returns:
- Pointer fo the fifo or NULL.
int delete_fifo( Fifo* pFifo )
- Delete the fifo pointed to by pFifo. Note that the INPUT fifo cannot be deleted.
int delete_fifo(const char* name )
- Delete the fifo with the name name
int remove_fifo(const char* name)
- Removes the fifo - same of delete - do not use - will become obsolte
int empty_fifo( Fifo* pFifo )
- Empties a fifo. It reads all remaining fifo_entries in the fifo and releases
them, i.e. they are put back into the INPUT fifo.
int empty_fifo( const char* pcFifoName )
- Empties a fifo. It reads all remaining fifo_entries in the fifo and releases
them, i.e. they are put back into the INPUT fifo.
Read/write and control access to the fifos
int write_fifo(const char* fifo_name, Fifo_entry &fev)
- Write the fifo entry fev into the fifo named name.
- Returns:
- 0 if success, -1 if error.
int write_fifo(Fifo* fifo, Fifo_entry &fev)
- Write the fifo entry fev into the fifo pointed to by fifo.
- Returns:
- 0 if success, -1 if error.
int read_fifo(const char* fifo_name, Fifo_entry &fev, int mode = -1 )
- Read the fifo given by the string name.
- Parameters:
- - fifo_name name of the fifo
fev - reference to the fifo entry
mode - (optional) if not given then the default mode from the fifo
header will be taken.
- Returns:
- 0 if success, -1 if error.
int read_fifo(Fifo* fifo, Fifo_entry &fev, int mode = -1 )
- Overloaded read_fifo to allow reading a fifo pointed to by a pointer
int unblock_fifo( const Fifo* fifo ) const
- Unlocks the fifo pointed to by fifo
int unblock_fifo( const char* fifo_name ) const
- Unlocks the named fifo
int lock()
- Locks the entire fifo system.
int unlock()
- Unlocks the entire fifo system.
Access to information about the fifo system
void print()
- Prints system information to cout
int get_status() const
- Returns the status of the system.
- Returns:
- unused, in_use, locking, locked, error
const char* get_name() const
- Returns the name of the fifo system
pid_t get_creator() const
- Returns the PID of the process that originally created the system
int get_nb_fifos() const
- Returns the maximum number of fifos.
int get_fifo_depth() const
- Returns the depth of the fifos.
int get_nproc_att() const
- Returns the number of processes that are currently attached to the fifo.
Fifo* find_fifo(const char* name) const
- Given the name of a fifo, return a pointer to it.
Access to information about the fifos
int get_nproc_waiting(const Fifo* fifo) const
- Return the number of processes that are waiting on the fifo *fifo for events.
int get_nproc_waiting(const char* Fifo_name ) const
- Return the number of processes that are waiting on the fifo Fifo_name for events.
int get_fifo_cnt( Fifo* fifo ) const
- Return the number of events in the fifo *fifo.
int get_fifo_cnt( const char* Fifo_name ) const
- Return the number of events in the fifo named Fifo_name.
int get_fifo_cnts( int &nFifos, int* &addr ) const
- Get the number of events in every fifo.
This member function returns the exact number of all the fifos at a given
point (they are the semaphore counts of the system).
- Parameters:
- nFifos - reference to the number of fifos.
addr - reference to the address of the array with the values
- Returns:
- 0 if success, -1 otherwise.
Note: The client is responsible for deleting the array *addr.
int get_fifo_locks( int &nFifos, int* &addr ) const
- Returns the lock semaphores for every fifo.
The same note as get_fifo_cnts applies here.
- This class has no child classes.
- Friends:
- class Fifo
class Fifo_iterator
- Author:
- C.Witzig
Date: Nov 20, 1997
- Version:
- Last update: Dec 7, 1999
Alphabetic index HTML hierarchy of classes or Java
This page was generated with the help of DOC++.