All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 16 of file POSIXFileHandler.cpp.

16  :
17  m_log(msg,"POSIXFileHandler") {
18 
19  m_level = msg->outputLevel("POSIXFileHandler");
20 
21 }
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 96 of file POSIXFileHandler.cpp.

96  {
97 
98  if (m_log.level() <= MSG::DEBUG)
99  m_log << MSG::DEBUG << "closePOSIXFile(fd:" << fd << ")"
100  << endmsg;
101 
102 
103  if (fd == -1) {
104  m_log << MSG::ERROR << "Unable to close file: FD == -1 "
105  << endmsg;
106  return -1;
107  }
108 
109  if (close(fd) != 0) {
110  int ierr = errno;
111  m_log << MSG::ERROR << "Error closing POSIX file with FD " << fd
112  << strerror(ierr)
113  << endmsg;
114  return -1;
115  }
116 
117  return 0;
118 
119 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:111
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
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 27 of file POSIXFileHandler.cpp.

28  {
29 
31 
32  if (m_log.level() <= MSG::DEBUG)
33  m_log << MSG::DEBUG << "openPOSIXFile(\"" << n << "\","
34  << f << "," << desc << ")"
35  << endmsg;
36 
37  ptr = 0;
38  fd = -1;
39 
40  int mm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
41 
42  fd = open(n.c_str(), (int) f, mm);
43  int ierr = errno;
44 
45  if (fd == -1) {
46  m_log << MSG::ERROR << "Error opening POSIX file \"" << n << "\": "
47  << strerror(ierr)
48  << endmsg;
49  return 1;
50  }
51 
52  std::string m;
53  if (f.isRead()) {
54  m = "r";
55  } else if ( f.isWrite() ) {
56  if ( (f & Io::APPEND) != 0) {
57  m = "a";
58  } else {
59  m = "w";
60  }
61  } else if ( f.isRdWr() ) {
62  m = "r+";
63  } else {
64  m_log << MSG::ERROR << "unknown mode " << f
65  << " when calling fdopen on " << n
66  << endmsg;
67  return 1;
68  }
69 
70 
71  if (m_log.level() <= MSG::DEBUG)
72  m_log << MSG::DEBUG << "calling fdopen with mode " << m << endmsg;
73 
74  FILE* fp = fdopen(fd, m.c_str());
75  ierr = errno;
76  ptr = (void*) fp;
77 
78  if (ptr == 0) {
79  m_log << MSG::ERROR << "Error calling fdopen on \"" << n << "\": "
80  << strerror(ierr)
81  << endmsg;
82  return 1;
83  }
84 
85  m_log << MSG::DEBUG << "opened POSIX file, Fd: " << fd
86  << " FILE*: " << ptr
87  << endmsg;
88 
89  return 0;
90 
91 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:111
bool isWrite() const
Definition: IFileMgr.h:55
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:105
bool isRead() const
Definition: IFileMgr.h:54
bool isRdWr() const
Definition: IFileMgr.h:56
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
Io::reopen_t POSIXFileHandler::reopenPOSIXFile ( Io::Fd  fd,
const Io::IoFlags  
)

Definition at line 125 of file POSIXFileHandler.cpp.

125  {
126 
127  m_log << MSG::ERROR << "reopen not implemented" << endmsg;
128 
129  return -1;
130 
131 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243

Member Data Documentation

int POSIXFileHandler::m_level
private

Definition at line 32 of file POSIXFileHandler.h.

MsgStream POSIXFileHandler::m_log
private

Definition at line 31 of file POSIXFileHandler.h.


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