7 #ifndef GAUDIKERNEL_IFILEMGR_H
8 #define GAUDIKERNEL_IFILEMGR_H 1
10 #include "GaudiKernel/IService.h"
11 #include "GaudiKernel/ClassID.h"
44 int f()
const {
return _f; }
47 bool operator== (
const int& fa)
const {
return (
_f == fa ); }
52 operator int()
const {
return _f; }
64 return ( (
_f&3) == (fa&3) );
67 std::string
bits()
const {
70 const int SHIFT = 8 *
sizeof( int ) - 1;
71 const unsigned MASK = 1 << SHIFT;
73 for (
int i = 1;
i <= SHIFT + 1; ++
i ) {
74 s += (
f & MASK ?
'1' :
'0' );
76 if (
i % 8 == 0 ) s +=
' ';
85 static std::string IoFlagName(IoFlags f) {
86 static const std::map<IoFlag, std::string> s_names = { {
90 if ( f.isRead() )
return s_names.at(
READ);
93 for (
int i=0;
i<32; ++
i) {
95 if ( b & f ) ff += s_names.at((
IoFlag)(b)) +
"|";
97 ff.erase(ff.length()-1);
103 static const std::map<std::string, IoFlag> s_n = { {
111 while ( (k=f.find(
"|",j)) != std::string::npos) {
112 fs = f.substr(j,k-j);
113 if (s_n.find(fs) == s_n.end()) {
116 if (fl.isInvalid()) {
119 fl = fl | s_n.at(fs);
124 if (s_n.find(fs) == s_n.end()) {
127 if (fl.isInvalid()) {
130 fl = fl | s_n.at(fs);
137 return s << IoFlagName(f);
139 inline std::ostream&
operator << (std::ostream &s,
const IoFlags &f) {
140 return s << IoFlagName(f);
160 static const std::array<const char*, SQLITE+1> tbl = {
161 "UNKNOWN",
"POSIX",
"ROOT",
162 "BS",
"HDF5",
"SQLITE" };
163 return t < tbl.size() ? s << tbl[t] :
s;
174 class FileAttr final {
179 IoFlags fa,
void* p,
bool o,
bool s=
false):
184 Fd
fd()
const {
return m_fd; }
185 const std::string&
name()
const {
return m_name; }
186 const std::string&
desc()
const {
return m_desc; }
195 void fd(Fd f) {
m_fd = f; }
197 void desc(
const std::string& d) {
m_desc = d; }
207 os <<
"name: \"" << fa.name() <<
"\" tech: " << fa.tech()
208 <<
" desc: " << fa.desc()
209 <<
" flags: " << IoFlagName(fa.flags())
210 <<
" i_flags: " << IoFlagName(fa.iflags())
211 <<
" Fd: " << fa.fd() <<
" ptr: " << fa.fptr()
212 << (fa.isOpen() ?
" [o]" :
" [c]" )
213 << (fa.isShared() ?
" [s]" :
" [u]" );
224 if (
m_name != rhs.name() ) {
225 return (
m_name < rhs.name() );
227 return (
m_flags < rhs.iflags() );
256 typedef std::function<Io::open_t(const std::string&, Io::IoFlags, const std::string&, Io::Fd&, void*&)>
bfcn_open_t;
257 typedef std::function<Io::close_t(Io::Fd)>
bfcn_close_t;
259 typedef std::function<Io::reopen_t(Io::Fd,Io::IoFlags)>
bfcn_reopen_t;
260 typedef std::function<Io::reopen_t(void*,Io::IoFlags)>
bfcn_reopenP_t;
263 struct FileHdlr final {
274 : tech(t), b_open_fcn(o), b_close_fcn(c), b_reopen_fcn(r){};
276 : tech(t), b_open_fcn(o), b_closeP_fcn(c), b_reopenP_fcn(r){};
277 FileHdlr(
IoTech t, bfcn_open_t o, bfcn_close_t c1, bfcn_closeP_t c2,
278 bfcn_reopen_t r1,bfcn_reopenP_t r2)
279 : tech(t), b_open_fcn(o), b_close_fcn(c1), b_closeP_fcn(c2),
280 b_reopen_fcn(r1), b_reopenP_fcn(r2){};
301 static const std::array<const char*, INVALID_ACTION+1> tbl = {
302 "OPEN",
"CLOSE",
"REOPEN",
303 "OPEN_ERR",
"CLOSE_ERR",
"REOPEN_ERR",
305 return t < tbl.size() ? s<< tbl[t] :
s;
308 #define FILEMGR_CALLBACK_ARGS const Io::FileAttr*, const std::string&
309 typedef std::function<StatusCode (FILEMGR_CALLBACK_ARGS) >
bfcn_action_t;
339 virtual int getFileAttr(
const std::string&,
340 std::vector<const Io::FileAttr*>&)
const = 0;
346 virtual void listHandlers()
const = 0;
347 virtual void listFiles()
const = 0;
351 virtual int getFiles(std::vector<std::string> & FILES,
352 bool onlyOpen=
true)
const = 0;
353 virtual int getFiles(std::vector<const Io::FileAttr*> & FILES,
354 bool onlyOpen=
true)
const = 0;
358 virtual int getFiles(
const Io::IoTech&, std::vector<std::string>& FILES,
359 bool onlyOpen=
true)
const = 0;
361 std::vector<const Io::FileAttr*>& FILES,
362 bool onlyOpen=
true)
const = 0;
368 std::vector<std::string> &FILES,
369 bool onlyOpen=
true)
const =0;
371 std::vector<const Io::FileAttr*> &FILES,
372 bool onlyOpen=
true)
const =0;
376 virtual int getFd (std::vector<Io::Fd > & )
const = 0;
378 virtual int getFd(
const Io::IoTech&, std::vector<Io::Fd>&)
const = 0;
382 std::vector<Io::Fd> &)
const = 0;
385 virtual const std::string& fname(
const Io::Fd&)
const = 0;
386 virtual const std::string& fname(
void*)
const = 0;
389 virtual Io::Fd fd(
const std::string&)
const = 0;
390 virtual Io::Fd fd(
void* fptr)
const = 0;
393 virtual void* fptr(
const std::string&)
const = 0;
394 virtual void* fptr(
const Io::Fd&)
const = 0;
402 const std::string& fname,
404 const std::string& desc,
405 const bool shared=
false
410 const std::string& fname,
412 const bool shared=
false
417 const std::string& fname,
418 const Io::IoFlags&,
void*&,
const std::string& desc,
419 const bool shared=
false
424 virtual Io::close_t close(
void*,
const std::string& caller) = 0;
428 const std::string& ) = 0;
430 const std::string& ) = 0;
434 const std::string& d=
"") = 0;
436 const Io::IoTech&,
const std::string& d=
"") = 0;
439 virtual void suppressAction(
const std::string&) = 0;
440 virtual void suppressAction(
const std::string&,
const Io::Action&) = 0;
std::function< Io::close_t(Io::Fd)> bfcn_close_t
std::function< Io::reopen_t(Io::Fd, Io::IoFlags)> bfcn_reopen_t
std::function< StatusCode(FILEMGR_CALLBACK_ARGS) > bfcn_action_t
bfcn_reopen_t b_reopen_fcn
GAUDI_API unsigned long getLastError()
Get last system known error.
std::function< Io::close_t(void *)> bfcn_closeP_t
bool operator==(const FileAttr &fa) const
const std::string & name() const
IoFlags IoFlagFromName(const std::string &f)
bool operator<(const FileAttr &rhs) const
const std::string & desc() const
General service interface definition.
This class is used for returning status codes from appropriate routines.
bool operator==(const IoFlags &fa) const
bfcn_closeP_t b_closeP_fcn
std::function< Io::open_t(const std::string &, Io::IoFlags, const std::string &, Io::Fd &, void *&)> bfcn_open_t
bfcn_reopenP_t b_reopenP_fcn
bool match(const IoFlags &fa, bool strict=true) const
std::ostream & operator<<(std::ostream &s, const IoFlag &f)
DeclareInterfaceID(IService, 4, 0)
InterfaceID.
std::function< Io::reopen_t(void *, Io::IoFlags)> bfcn_reopenP_t
IoFlags operator|(const IoFlags &fa) const
friend std::ostream & operator<<(std::ostream &os, const FileAttr &fa)