The Gaudi Framework  v31r0 (aeb156f0)
POSIXFileHandler Class Reference

#include <src/FileMgr/POSIXFileHandler.h>

Collaboration diagram for POSIXFileHandler:

Public Member Functions

 POSIXFileHandler (IMessageSvc *)
 
Io::open_t openPOSIXFile (const std::string &n, const Io::IoFlags &f, const std::string &desc, Io::Fd &fd, void *&ptr)
 
Io::close_t closePOSIXFile (Io::Fd fd)
 
Io::reopen_t reopenPOSIXFile (Io::Fd fd, const Io::IoFlags &)
 

Private Attributes

MsgStream m_log
 
int m_level
 

Detailed Description

Definition at line 17 of file POSIXFileHandler.h.

Constructor & Destructor Documentation

POSIXFileHandler::POSIXFileHandler ( IMessageSvc msg)

Definition at line 15 of file POSIXFileHandler.cpp.

15  : m_log( msg, "POSIXFileHandler" ) {
16 
17  m_level = msg->outputLevel( "POSIXFileHandler" );
18 }
virtual int outputLevel() const =0
Retrieve the current output level threshold.

Member Function Documentation

Io::close_t POSIXFileHandler::closePOSIXFile ( Io::Fd  fd)

Definition at line 76 of file POSIXFileHandler.cpp.

76  {
77 
78  if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "closePOSIXFile(fd:" << fd << ")" << endmsg;
79 
80  if ( fd == -1 ) {
81  m_log << MSG::ERROR << "Unable to close file: FD == -1 " << endmsg;
82  return -1;
83  }
84 
85  if ( close( fd ) != 0 ) {
86  int ierr = errno;
87  m_log << MSG::ERROR << "Error closing POSIX file with FD " << fd << strerror( ierr ) << endmsg;
88  return -1;
89  }
90 
91  return 0;
92 }
T strerror(T...args)
MSG::Level level() const
Retrieve output level.
Definition: MsgStream.h:103
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Io::open_t POSIXFileHandler::openPOSIXFile ( const std::string n,
const Io::IoFlags f,
const std::string desc,
Io::Fd fd,
void *&  ptr 
)

Definition at line 22 of file POSIXFileHandler.cpp.

23  {
24 
26 
27  if ( m_log.level() <= MSG::DEBUG )
28  m_log << MSG::DEBUG << "openPOSIXFile(\"" << n << "\"," << f << "," << desc << ")" << endmsg;
29 
30  ptr = nullptr;
31  fd = -1;
32 
33  int mm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
34 
35  fd = open( n.c_str(), (int)f, mm );
36  int ierr = errno;
37 
38  if ( fd == -1 ) {
39  m_log << MSG::ERROR << "Error opening POSIX file \"" << n << "\": " << strerror( ierr ) << endmsg;
40  return 1;
41  }
42 
43  std::string m;
44  if ( f.isRead() ) {
45  m = "r";
46  } else if ( f.isWrite() ) {
47  if ( ( f & Io::APPEND ) ) {
48  m = "a";
49  } else {
50  m = "w";
51  }
52  } else if ( f.isRdWr() ) {
53  m = "r+";
54  } else {
55  m_log << MSG::ERROR << "unknown mode " << f << " when calling fdopen on " << n << endmsg;
56  return 1;
57  }
58 
59  if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "calling fdopen with mode " << m << endmsg;
60 
61  ptr = fdopen( fd, m.c_str() );
62  ierr = errno;
63 
64  if ( !ptr ) {
65  m_log << MSG::ERROR << "Error calling fdopen on \"" << n << "\": " << strerror( ierr ) << endmsg;
66  return 1;
67  }
68 
69  m_log << MSG::DEBUG << "opened POSIX file, Fd: " << fd << " FILE*: " << ptr << endmsg;
70 
71  return 0;
72 }
T strerror(T...args)
constexpr double mm
Definition: SystemOfUnits.h:84
STL class.
constexpr double m
Definition: SystemOfUnits.h:92
bool isWrite() const
Definition: IFileMgr.h:56
T c_str(T...args)
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:98
bool isRead() const
Definition: IFileMgr.h:55
MSG::Level level() const
Retrieve output level.
Definition: MsgStream.h:103
bool isRdWr() const
Definition: IFileMgr.h:57
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Io::reopen_t POSIXFileHandler::reopenPOSIXFile ( Io::Fd  fd,
const Io::IoFlags  
)

Definition at line 96 of file POSIXFileHandler.cpp.

96  {
97 
98  m_log << MSG::ERROR << "reopen not implemented" << endmsg;
99  return -1;
100 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

Member Data Documentation

int POSIXFileHandler::m_level
private

Definition at line 30 of file POSIXFileHandler.h.

MsgStream POSIXFileHandler::m_log
private

Definition at line 29 of file POSIXFileHandler.h.


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