The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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 26 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}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
@ DEBUG
Definition IMessageSvc.h:22
@ ERROR
Definition IMessageSvc.h:22

◆ 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
35 m_log.setLevel( m_level );
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}
bool isRead() const
Definition IFileMgr.h:58
bool isWrite() const
Definition IFileMgr.h:59
bool isRdWr() const
Definition IFileMgr.h:60
constexpr double mm
constexpr double m
@ APPEND
Definition IFileMgr.h:38

◆ 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 39 of file POSIXFileHandler.h.

◆ m_log

MsgStream POSIXFileHandler::m_log
private

Definition at line 38 of file POSIXFileHandler.h.


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