The Gaudi Framework  master (37c0b60a)
POSIXFileHandler Class Reference

#include </builds/gaudi/Gaudi/GaudiSvc/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 27 of file POSIXFileHandler.h.

Constructor & Destructor Documentation

◆ POSIXFileHandler()

POSIXFileHandler::POSIXFileHandler ( IMessageSvc msg)

Definition at line 25 of file POSIXFileHandler.cpp.

25  : m_log( msg, "POSIXFileHandler" ) {
26 
27  m_level = msg->outputLevel( "POSIXFileHandler" );
28 }

Member Function Documentation

◆ closePOSIXFile()

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

Definition at line 86 of file POSIXFileHandler.cpp.

86  {
87 
88  if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "closePOSIXFile(fd:" << fd << ")" << endmsg;
89 
90  if ( fd == -1 ) {
91  m_log << MSG::ERROR << "Unable to close file: FD == -1 " << endmsg;
92  return -1;
93  }
94 
95  if ( close( fd ) != 0 ) {
96  int ierr = errno;
97  m_log << MSG::ERROR << "Error closing POSIX file with FD " << fd << strerror( ierr ) << endmsg;
98  return -1;
99  }
100 
101  return 0;
102 }

◆ openPOSIXFile()

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 32 of file POSIXFileHandler.cpp.

33  {
34 
36 
37  if ( m_log.level() <= MSG::DEBUG )
38  m_log << MSG::DEBUG << "openPOSIXFile(\"" << n << "\"," << f << "," << desc << ")" << endmsg;
39 
40  ptr = nullptr;
41  fd = -1;
42 
43  int mm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
44 
45  fd = open( n.c_str(), (int)f, mm );
46  int ierr = errno;
47 
48  if ( fd == -1 ) {
49  m_log << MSG::ERROR << "Error opening POSIX file \"" << n << "\": " << strerror( ierr ) << endmsg;
50  return 1;
51  }
52 
53  std::string m;
54  if ( f.isRead() ) {
55  m = "r";
56  } else if ( f.isWrite() ) {
57  if ( ( f & Io::APPEND ) ) {
58  m = "a";
59  } else {
60  m = "w";
61  }
62  } else if ( f.isRdWr() ) {
63  m = "r+";
64  } else {
65  m_log << MSG::ERROR << "unknown mode " << f << " when calling fdopen on " << n << endmsg;
66  return 1;
67  }
68 
69  if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "calling fdopen with mode " << m << endmsg;
70 
71  ptr = fdopen( fd, m.c_str() );
72  ierr = errno;
73 
74  if ( !ptr ) {
75  m_log << MSG::ERROR << "Error calling fdopen on \"" << n << "\": " << strerror( ierr ) << endmsg;
76  return 1;
77  }
78 
79  m_log << MSG::DEBUG << "opened POSIX file, Fd: " << fd << " FILE*: " << ptr << endmsg;
80 
81  return 0;
82 }

◆ reopenPOSIXFile()

Io::reopen_t POSIXFileHandler::reopenPOSIXFile ( Io::Fd  fd,
const Io::IoFlags  
)

Definition at line 106 of file POSIXFileHandler.cpp.

106  {
107 
108  m_log << MSG::ERROR << "reopen not implemented" << endmsg;
109  return -1;
110 }

Member Data Documentation

◆ m_level

int POSIXFileHandler::m_level
private

Definition at line 40 of file POSIXFileHandler.h.

◆ m_log

MsgStream POSIXFileHandler::m_log
private

Definition at line 39 of file POSIXFileHandler.h.


The documentation for this class was generated from the following files:
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::string
STL class.
gaudirun.fd
fd
Definition: gaudirun.py:630
Io::IoFlags::isRead
bool isRead() const
Definition: IFileMgr.h:65
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
POSIXFileHandler::m_level
int m_level
Definition: POSIXFileHandler.h:40
std::strerror
T strerror(T... args)
Gaudi::Units::mm
constexpr double mm
Definition: SystemOfUnits.h:100
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
cpluginsvc.n
n
Definition: cpluginsvc.py:234
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
Io::IoFlags::isWrite
bool isWrite() const
Definition: IFileMgr.h:66
Io::APPEND
@ APPEND
Definition: IFileMgr.h:45
POSIXFileHandler::m_log
MsgStream m_log
Definition: POSIXFileHandler.h:39
MsgStream::setLevel
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:107
Io::IoFlags::isRdWr
bool isRdWr() const
Definition: IFileMgr.h:67
MsgStream::level
MSG::Level level() const
Retrieve output level.
Definition: MsgStream.h:112