ATLAS Offline Software
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
IoSvc Class Reference

#include <IoSvc.h>

Inheritance diagram for IoSvc:
Collaboration diagram for IoSvc:

Classes

struct  FdInfos
 

Public Types

typedef IIoSvc::Fd Fd
 

Public Member Functions

 IoSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters: More...
 
virtual ~IoSvc ()
 Destructor: More...
 
virtual StatusCode initialize () override
 Gaudi Service Implementation. More...
 
virtual StatusCode finalize () override
 
virtual bool has_fd (Fd fd) const override
 test if a given file descriptor fd is known to us More...
 
virtual Fd fd (const std::string &fname) const override
 retrieve the file descriptor associated with file fname More...
 
virtual const std::string & fname (Fd fd) const override
 retrieve the file fname associated with file descriptor fd More...
 
virtual IoType mode (Fd fd) const override
 retrieve the open mode associated with file descriptor fd More...
 
virtual Fd open (const std::string &fname, IoType mode) override
 open file fname with open mode mode More...
 
virtual StatusCode close (Fd fd) override
 close file fd More...
 

Private Types

typedef std::unordered_map< Fd, FdInfosFdMap_t
 

Private Member Functions

 IoSvc ()
 Default constructor: More...
 

Private Attributes

FdMap_t m_fds
 map of fd->fdinfos More...
 
Fd m_last_fd
 last created Fd More...
 

Friends

class SvcFactory< IoSvc >
 

Detailed Description

Definition at line 30 of file IoSvc.h.

Member Typedef Documentation

◆ Fd

Definition at line 39 of file IoSvc.h.

◆ FdMap_t

typedef std::unordered_map<Fd, FdInfos> IoSvc::FdMap_t
private

Definition at line 98 of file IoSvc.h.

Constructor & Destructor Documentation

◆ IoSvc() [1/2]

IoSvc::IoSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor with parameters:

Definition at line 31 of file IoSvc.cxx.

32  :
33  base_class( name, pSvcLocator ),
34  m_fds(),
35  m_last_fd(3) // 1==cout, 2==cerr, 3==clog
36 {
37  //
38  // Property declaration
39  //
40  //declareProperty( "Property", m_nProperty );
41 
42 }

◆ ~IoSvc()

IoSvc::~IoSvc ( )
virtual

Destructor:

Definition at line 46 of file IoSvc.cxx.

47 {}

◆ IoSvc() [2/2]

IoSvc::IoSvc ( )
private

Default constructor:

Member Function Documentation

◆ close()

StatusCode IoSvc::close ( Fd  fd)
overridevirtual

close file fd

Definition at line 147 of file IoSvc.cxx.

148 {
149  FdMap_t::const_iterator itr = m_fds.find(fd);
150  if (itr != m_fds.end()) {
151  m_fds.erase(itr);
152  return StatusCode::SUCCESS;
153  }
154  return StatusCode::FAILURE;
155 }

◆ fd()

Fd IoSvc::fd ( const std::string &  fname) const
overridevirtual

retrieve the file descriptor associated with file fname

Returns
-1 if no such fname is known

Definition at line 79 of file IoSvc.cxx.

80 {
81  for (FdMap_t::const_iterator
82  itr = m_fds.begin(),
83  iend= m_fds.end();
84  itr != iend;
85  ++itr) {
86  if (itr->second.fname == fname) {
87  return itr->first;
88  }
89  }
90  return -1;
91 }

◆ finalize()

StatusCode IoSvc::finalize ( )
overridevirtual

Definition at line 58 of file IoSvc.cxx.

59 {
60  ATH_MSG_INFO ("Finalizing " << name() << "...");
61 
62  return StatusCode::SUCCESS;
63 }

◆ fname()

const std::string & IoSvc::fname ( Fd  fd) const
overridevirtual

retrieve the file fname associated with file descriptor fd

Returns
empty string if no such fd is known

Definition at line 96 of file IoSvc.cxx.

97 {
98  FdMap_t::const_iterator itr = m_fds.find(fd);
99  if (itr != m_fds.end()) {
100  return itr->second.fname;
101  }
102  static const std::string s_empty = "";
103  return s_empty;
104 }

◆ has_fd()

bool IoSvc::has_fd ( Fd  fd) const
overridevirtual

test if a given file descriptor fd is known to us

Definition at line 71 of file IoSvc.cxx.

72 {
73  return m_fds.find(fd) != m_fds.end();
74 }

◆ initialize()

StatusCode IoSvc::initialize ( )
overridevirtual

Gaudi Service Implementation.

Definition at line 51 of file IoSvc.cxx.

52 {
53  ATH_MSG_INFO ("Initializing " << name() << "...");
54 
55  return StatusCode::SUCCESS;
56 }

◆ mode()

IoType IoSvc::mode ( Fd  fd) const
overridevirtual

retrieve the open mode associated with file descriptor fd

Definition at line 108 of file IoSvc.cxx.

109 {
110  FdMap_t::const_iterator itr = m_fds.find(fd);
111  if (itr != m_fds.end()) {
112  return itr->second.mode;
113  }
114  return IIoSvc::INVALID;
115 }

◆ open()

Fd IoSvc::open ( const std::string &  fname,
IoType  mode 
)
overridevirtual

open file fname with open mode mode

Returns
-1 if not successful

Definition at line 120 of file IoSvc.cxx.

121 {
122  // check this `fname` hasn't been already associated.
123  Fd fd = this->fd(fname);
124  if (fd == -1) {
125  // FIXME: use a recycle bin of fds ?
126  if ( m_last_fd == (std::numeric_limits<Fd>::max()-1)) {
127  ATH_MSG_ERROR("too many file descriptors opened!");
128  return -1;
129  }
130  fd = ++m_last_fd;
131  FdInfos infos = {fname, mode};
132  m_fds.insert(std::make_pair(fd, infos));
133  return fd;
134  }
135 
136  // check the previous open mode is the same
137  if (mode == this->mode(fd)) {
138  return fd;
139  }
140 
141  // inconsistency...
142  return -1;
143 }

Friends And Related Function Documentation

◆ SvcFactory< IoSvc >

friend class SvcFactory< IoSvc >
friend

Definition at line 1 of file IoSvc.h.

Member Data Documentation

◆ m_fds

FdMap_t IoSvc::m_fds
private

map of fd->fdinfos

Definition at line 101 of file IoSvc.h.

◆ m_last_fd

Fd IoSvc::m_last_fd
private

last created Fd

Definition at line 104 of file IoSvc.h.


The documentation for this class was generated from the following files:
IoSvc::fd
virtual Fd fd(const std::string &fname) const override
retrieve the file descriptor associated with file fname
Definition: IoSvc.cxx:79
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Fd
IIoSvc::Fd Fd
Definition: IoSvc.cxx:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IoSvc::m_last_fd
Fd m_last_fd
last created Fd
Definition: IoSvc.h:104
IoSvc::mode
virtual IoType mode(Fd fd) const override
retrieve the open mode associated with file descriptor fd
Definition: IoSvc.cxx:108
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
IoSvc::fname
virtual const std::string & fname(Fd fd) const override
retrieve the file fname associated with file descriptor fd
Definition: IoSvc.cxx:96
IoSvc::m_fds
FdMap_t m_fds
map of fd->fdinfos
Definition: IoSvc.h:101
IIoSvc::INVALID
@ INVALID
Definition: IIoSvc.h:42