gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
FDArray Class Reference

#include <fd_array.hh>

Public Member Functions

 FDArray (std::string const &input, std::string const &output, std::string const &errout)
 Initialize the file descriptor array and set the standard file descriptors to defaults or values passed in with the process params. More...
 
void updateFileOffsets ()
 Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process. More...
 
void restoreFileOffsets ()
 Restore all offsets for currently open files during the unserialize phase for the owning process class. More...
 
std::shared_ptr< FDEntryoperator[] (int tgt_fd)
 Treat this object like a normal array in using the subscript operator to pull entries out of it. More...
 
int allocFD (std::shared_ptr< FDEntry > fdp)
 Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'. More...
 
int getSize () const
 Return the size of the _fdArray field. More...
 
void setFDEntry (int tgt_fd, std::shared_ptr< FDEntry > fdep)
 Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd. More...
 
int closeFDEntry (int tgt_fd)
 Try to close the host file descriptor. More...
 

Public Attributes

std::string _input
 
std::string _output
 
std::string _errout
 

Private Member Functions

int openFile (std::string const &file_name, int flags, mode_t mode) const
 Help clarify our intention when opening files in the init and restoration code. More...
 
int openInputFile (std::string const &file_name) const
 
int openOutputFile (std::string const &file_name) const
 
std::shared_ptr< FDEntrygetFDEntry (int tgt_fd)
 Return the file descriptor entry object associated with the index provided. More...
 

Private Attributes

std::array< std::shared_ptr
< FDEntry >, NUM_FDS
_fdArray
 Hold pointers to the file descriptor entries. More...
 
std::map< std::string, int > imap
 Hold strings which represent the default values which are checked against to initialize the standard file descriptors. More...
 
std::map< std::string, int > oemap
 

Static Private Attributes

static const int NUM_FDS = 1024
 

Detailed Description

Definition at line 45 of file fd_array.hh.

Constructor & Destructor Documentation

FDArray::FDArray ( std::string const &  input,
std::string const &  output,
std::string const &  errout 
)

Initialize the file descriptor array and set the standard file descriptors to defaults or values passed in with the process params.

Parameters
inputUsed to initialize the stdin file descriptor
outputUsed to initialize the stdout file descriptor
erroutUsed to initialize the stderr file descriptor

Definition at line 49 of file fd_array.cc.

Member Function Documentation

int FDArray::allocFD ( std::shared_ptr< FDEntry fdp)

Step through the file descriptor array and find the first available entry which is denoted as being free by being a 'nullptr'.

That file descriptor entry is the new target file descriptor entry that we return as the return parameter.

Parameters
fdpAllocated beforehand and passed into this method; the fdp is meant to be a generic pointer capable of pointing to different types of file descriptors. Must cast the pointer to the correct type before dereferencing to access the needed fields.
int FDArray::closeFDEntry ( int  tgt_fd)

Try to close the host file descriptor.

If successful, set the specified file descriptor entry object pointer to nullptr. Used to "close" the target file descriptor.

Parameters
tgt_fdUse target file descriptors to index the array.
std::shared_ptr<FDEntry> FDArray::getFDEntry ( int  tgt_fd)
private

Return the file descriptor entry object associated with the index provided.

(The index is protected with bounds checking on the array size without the use of the array's at operator.)

Parameters
tgt_fdUse target file descriptors to index the array.

Referenced by operator[]().

int FDArray::getSize ( ) const
inline

Return the size of the _fdArray field.

Definition at line 104 of file fd_array.hh.

References _fdArray.

int FDArray::openFile ( std::string const &  file_name,
int  flags,
mode_t  mode 
) const
private

Help clarify our intention when opening files in the init and restoration code.

These are helper functions which are not meant to be exposed to other objects or files.

int FDArray::openInputFile ( std::string const &  file_name) const
private
int FDArray::openOutputFile ( std::string const &  file_name) const
private
std::shared_ptr<FDEntry> FDArray::operator[] ( int  tgt_fd)
inline

Treat this object like a normal array in using the subscript operator to pull entries out of it.

Parameters
tgt_fdUse target file descriptors to index the array.

Definition at line 84 of file fd_array.hh.

References getFDEntry().

void FDArray::restoreFileOffsets ( )

Restore all offsets for currently open files during the unserialize phase for the owning process class.

void FDArray::setFDEntry ( int  tgt_fd,
std::shared_ptr< FDEntry fdep 
)

Put the pointer specified by fdep into the _fdArray entry indexed by tgt_fd.

Parameters
tgt_fdUse target file descriptors to index the array.
fdepIncoming pointer used to set the entry pointed to by tgt_fd.
void FDArray::updateFileOffsets ( )

Figure out the file offsets for all currently open files and save them the offsets during the calls to drain by the owning process.

Member Data Documentation

std::string FDArray::_errout

Definition at line 64 of file fd_array.hh.

std::array<std::shared_ptr<FDEntry>, NUM_FDS> FDArray::_fdArray
private

Hold pointers to the file descriptor entries.

The array size is statically defined by the operating system.

Definition at line 144 of file fd_array.hh.

Referenced by getSize().

std::string FDArray::_input

Definition at line 62 of file fd_array.hh.

std::string FDArray::_output

Definition at line 63 of file fd_array.hh.

std::map<std::string, int> FDArray::imap
private

Hold strings which represent the default values which are checked against to initialize the standard file descriptors.

If the string provided doesn't hit against these maps, then a file is opened on the host instead of using the host's standard file descriptors.

Definition at line 152 of file fd_array.hh.

const int FDArray::NUM_FDS = 1024
staticprivate

Definition at line 48 of file fd_array.hh.

std::map<std::string, int> FDArray::oemap
private

Definition at line 153 of file fd_array.hh.


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

Generated on Fri Jun 9 2017 13:04:10 for gem5 by doxygen 1.8.6