#include <wefts_coffee_base.h>
Inheritance diagram for Wefts::OSFileFuncBase:
This class provides basic cooperative file access; cooperative file access means that the os specific implementation will have to take care of messages that wefts sends to them to i.e. interrupt operations and eventually terminate calling thread, doing a cleanup function.
The class implementations must be made so that their data is fungible also to standard non-cooperative functions that are present in the system.
This class and subclasses methods are not required to be locked. Underlying OS operations are generally thread safe, and this would make locking of this class methods generally an overkill; the risk of concurrent access to the method of this class must be minimized with correct programming techniques (i.e. accessing to an object only within a thread) or with outher mutex encapsulation (i.e. deriving a class both from this one and from a mutex of some kind).
Public Member Functions | |
virtual CffStatus | open (std::string filespec, OpenMode openMode=OM_RO, LockMode lockMode=LM_SHARED)=0 |
Creates a file. | |
virtual CffStatus | create (std::string filespec, CreateMode cMode=CM_ARCHIVE, LockMode lockMode=LM_EXCLUSIVE)=0 |
Creates the file. | |
virtual void | getDescriptor (void *data) const =0 |
Get the descriptor OS value. | |
virtual void | setDescriptor (void *data)=0 |
Set the descriptor OS value. | |
CffStatus | status () const |
Get the status returned by the last operation. | |
void | status (const CffStatus st) |
Set the internal status. | |
int | osError () const |
Get OS dependant error code caused by the last operation. | |
void | osError (const int osError) |
Set the OS dependant error. | |
double | timeout () const |
Get the standard operation timeout. | |
void | timeout (const double to) |
Set the standard operation timeout. | |
void | clearTimeout () |
void | dontBlock () |
virtual file_size_t | read (void *buffer, const file_size_t len)=0 |
Read data from the underlying file. | |
virtual file_size_t | write (void *buffer, const file_size_t len)=0 |
Write data to the underlying file. | |
virtual file_size_t | seek (const file_size_t position, const SeekWhence swFrom=SW_FROM_BEGIN)=0 |
Change the position in the file. | |
virtual CffStatus | close ()=0 |
Closes a file. | |
virtual void | setStdIn ()=0 |
Set this file to stdin. | |
virtual void | setStdOut ()=0 |
Set this file to stdout. | |
virtual void | setStdErr ()=0 |
Set this file to stderr. | |
Protected Member Functions | |
OSFileFuncBase () | |
Initializes the internal data of the FileFunction. | |
Protected Attributes | |
double | m_timeout |
CffStatus | m_status |
int | m_osError |
|
Initializes the internal data of the FileFunction. This constructor forces subclassess to accept an OS dependant descriptor that may be open with other functions outside the OS-COFFEE model. Refer to specific OS-COFFEE implementation to know what kind of descriptor they can accept. Accepting the descriptor is done via acall to the setDescriptior() pure virtual method. |
|
|
|
Closes a file.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Creates the file. The create-lock parameter is provided because some systems may not allow to lock the file after the create step (the lock politic must be chosen at open time). The timeout is provided because the file may be located on a network disk, or a COFFEE implementation may use a network protocol as underlying layer. It is theoretically possible to provide a COFFEE for FTP. Anyhow, a reasonable timeout may also protect against program deadlocks due to local filesystem failure on systems that do not provide a prompt error diagniostic. File is always created with read-write access from the creator, and it can be locked against concurrent access from other processes. By default, the timeout is not set; to set a given timeout, use the setTimeout() method.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
|
|
Get the descriptor OS value. This function can be hooked by OS specific implementation to copy the descriptor value in the address passed as parameter. This allows to extract the handle, descriptor or structure of that represents the file from this class and use non-cooperative functions (or os-level function that provide native cooperation with the OSTAIL).
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Creates a file. The file may be opened with a locking sckeme, if the underlying provides it, and may be triggered with a given timeout. The open-lock parameter is provided because some systems may not allow to lock the file after the open step (the lock politic must be chosen at open time). The timeout is provided because the file may be located on a network disk, or a COFFEE implementation may use a network protocol as underlying layer. It is theoretically possible to provide a COFFEE for FTP. Anyhow, a reasonable timeout may also protect against program deadlocks due to local filesystem failure on systems that do not provide a prompt error diagniostic. File can be opened for reading, for writing, can be open truncated or in append mode (see OpenMode). Text-to-binary translation is not provided: data is read as is on all systems. By default, the timeout is not set; to set a given timeout, use the setTimeout() method.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set the OS dependant error. Generally, applications should not use this. |
|
Get OS dependant error code caused by the last operation. Implementations must not use shorthands as returing directly the OS error, as it may have changed before the thread has a chance to call this function. Even if the OS error is thread specific at OS level, the thread may do other operations before calling this function, or it mai send this object to another thread that is responsible to retreive the error that has been found. |
|
Read data from the underlying file. Application should not rely on osError() if the function retunrs a vaild number. file_size_t is the longest integer type provided by the platform.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Change the position in the file. Must return current position after change, so that seek( 0, SW_FROM_END ) return the current file length (that is one past last byte).
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set the descriptor OS value. This function can be hooked by OS specific implementation to copy the descriptor value from the address passed as parameter. The implementations must just discard the previous value of the internal descriptor, and applications must take care to retreive it before destriong it with getDescriptor and correctly dispose it following the OS requirements.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set this file to stderr. This method is to be overloaded by subclasses so that following operations on this OSFileFunc are applied to the standard error file. Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set this file to stdin. This method is to be overloaded by subclasses so that following operations on this OSFileFunc are applied to the standard input file. Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set this file to stdout. This method is to be overloaded by subclasses so that following operations on this OSFileFunc are applied to the standard output file. Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
Set the internal status. Generally, applications should not use this.
|
|
Get the status returned by the last operation.
|
|
Set the standard operation timeout. Timeout can be also set to 0.0 (never block) or less than zero (block forever). Methods clearTimeout() and dontBlock() are inline provided for candy grammar.
|
|
Get the standard operation timeout.
|
|
Write data to the underlying file. Application should not rely on osError() if the function retunrs a vaild number. file_size_t is the longest integer type provided by the platform.
Implemented in Wefts::OSFileFuncUnix, and Wefts::OSFileFuncWin. |
|
|
|
|
|
|