7 #ifndef GAUDIKERNEL_IFILEMGR_H
8 #define GAUDIKERNEL_IFILEMGR_H 1
17 #include "boost/function.hpp"
44 int f()
const {
return _f; }
52 operator int()
const {
return _f; }
64 return ( (
_f&3) == (fa&3) );
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' );
86 static std::string IoFlagName(
IoFlags f) {
87 static std::map<IoFlag, std::string> s_names;
88 if (s_names.empty()) {
89 s_names[
READ] =
"READ";
90 s_names[
WRITE] =
"WRITE";
91 s_names[
RDWR] =
"RDWR";
92 s_names[
CREATE] =
"CREATE";
93 s_names[
EXCL] =
"EXCL";
94 s_names[
TRUNC] =
"TRUNC";
95 s_names[
APPEND] =
"APPEND";
100 return s_names[
READ];
104 for (
int i=0;
i<32; ++
i) {
105 if ( ( (1<<
i) & f) != 0) {
106 ff += s_names[ (
IoFlag)(1<<
i) ] +
"|";
109 ff.erase(ff.length()-1);
115 static std::map<std::string, IoFlag> s_n;
130 while ( (k=f.find(
"|",j)) != std::string::npos) {
131 fs = f.substr(j,k-j);
132 if (s_n.find(fs) == s_n.end()) {
142 fs = f.substr(j,f.length()-j);
143 if (s_n.find(fs) == s_n.end()) {
157 return s << IoFlagName(f);
160 return s << IoFlagName(f);
181 case UNKNOWN :
return s <<
"UNKNOWN";
182 case POSIX :
return s <<
"POSIX";
183 case ROOT :
return s <<
"ROOT";
184 case BS :
return s <<
"BS";
185 case HDF5 :
return s <<
"HDF5";
186 case SQLITE :
return s <<
"SQLITE";
205 IoFlags fa,
void* p,
bool o,
bool s=
false):
232 os <<
"name: \"" << fa.
name() <<
"\" tech: " << fa.
tech()
233 <<
" desc: " << fa.
desc()
234 <<
" flags: " << IoFlagName(fa.
flags())
235 <<
" i_flags: " << IoFlagName(fa.
iflags())
236 <<
" Fd: " << fa.
fd() <<
" ptr: " << fa.
fptr()
237 << (fa.
isOpen() ?
" [o]" :
" [c]" )
238 << (fa.
isShared() ?
" [s]" :
" [u]" );
282 typedef boost::function<Io::open_t(const std::string&, Io::IoFlags, const std::string&, Io::Fd&, void*&)>
bfcn_open_t;
328 case OPEN :
return s <<
"OPEN";
329 case CLOSE :
return s <<
"CLOSE";
330 case REOPEN :
return s <<
"REOPEN";
331 case OPEN_ERR :
return s <<
"OPEN_ERR";
332 case CLOSE_ERR :
return s <<
"CLOSE_ERR";
339 #define FILEMGR_CALLBACK_ARGS const Io::FileAttr*, const std::string&
370 virtual int getFileAttr(
const std::string&,
371 std::vector<const Io::FileAttr*>&)
const = 0;
377 virtual void listHandlers()
const = 0;
378 virtual void listFiles()
const = 0;
382 virtual int getFiles(std::vector<std::string> & FILES,
383 bool onlyOpen=
true)
const = 0;
384 virtual int getFiles(std::vector<const Io::FileAttr*> & FILES,
385 bool onlyOpen=
true)
const = 0;
389 virtual int getFiles(
const Io::IoTech&, std::vector<std::string>& FILES,
390 bool onlyOpen=
true)
const = 0;
392 std::vector<const Io::FileAttr*>& FILES,
393 bool onlyOpen=
true)
const = 0;
399 std::vector<std::string> &FILES,
400 bool onlyOpen=
true)
const =0;
402 std::vector<const Io::FileAttr*> &FILES,
403 bool onlyOpen=
true)
const =0;
407 virtual int getFd (std::vector<Io::Fd > & )
const = 0;
409 virtual int getFd(
const Io::IoTech&, std::vector<Io::Fd>&)
const = 0;
413 std::vector<Io::Fd> &)
const = 0;
416 virtual const std::string& fname(
const Io::Fd&)
const = 0;
417 virtual const std::string& fname(
void*)
const = 0;
420 virtual Io::Fd fd(
const std::string&)
const = 0;
421 virtual Io::Fd fd(
void* fptr)
const = 0;
424 virtual void* fptr(
const std::string&)
const = 0;
425 virtual void* fptr(
const Io::Fd&)
const = 0;
433 const std::string& fname,
435 const std::string& desc,
436 const bool shared=
false
441 const std::string& fname,
443 const bool shared=
false
448 const std::string& fname,
449 const Io::IoFlags&,
void*&,
const std::string& desc,
450 const bool shared=
false
456 virtual Io::close_t close(
void*,
const std::string& caller) = 0;
460 const std::string& ) = 0;
462 const std::string& ) = 0;
467 const std::string& d=
"") = 0;
469 const Io::IoTech&,
const std::string& d=
"") = 0;
472 virtual void suppressAction(
const std::string&) = 0;
473 virtual void suppressAction(
const std::string&,
const Io::Action&) = 0;
boost::function< Io::open_t(const std::string &, Io::IoFlags, const std::string &, Io::Fd &, void *&)> bfcn_open_t
void flags(const IoFlags &f)
GAUDI_API unsigned long getLastError()
Get last system known error.
boost::function< Io::close_t(void *)> bfcn_closeP_t
bfcn_reopen_t b_reopen_fcn
void name(const std::string &n)
boost::function< Io::close_t(Io::Fd)> bfcn_close_t
bool operator==(const FileAttr &fa) const
FileHdlr(IoTech t, bfcn_open_t o, bfcn_close_t c, bfcn_reopen_t r)
const std::string & name() const
void iflags(const IoFlags &f)
DeclareInterfaceID(IService, 3, 0)
InterfaceID.
IoFlags IoFlagFromName(const std::string &f)
bool operator<(const FileAttr &rhs) const
const std::string & desc() const
boost::function< StatusCode(FILEMGR_CALLBACK_ARGS) > bfcn_action_t
General service interface definition.
This class is used for returning status codes from appropriate routines.
bool operator==(const IoFlags &fa) const
std::ostream & operator<<(std::ostream &s, const IoFlag &f)
bfcn_closeP_t b_closeP_fcn
FileHdlr(IoTech t, bfcn_open_t o, bfcn_closeP_t c, bfcn_reopenP_t r)
bfcn_reopenP_t b_reopenP_fcn
FileAttr(Fd f, const std::string &n, const std::string &d, IoTech t, IoFlags fa, void *p, bool o, bool s=false)
void tech(const IoTech &t)
FileHdlr(IoTech t, bfcn_open_t o, bfcn_close_t c1, bfcn_closeP_t c2, bfcn_reopen_t r1, bfcn_reopenP_t r2)
bool match(const IoFlags &fa, bool strict=true) const
boost::function< Io::reopen_t(Io::Fd, Io::IoFlags)> bfcn_reopen_t
void desc(const std::string &d)
IoFlags operator|(const IoFlags &fa) const
boost::function< Io::reopen_t(void *, Io::IoFlags)> bfcn_reopenP_t
friend std::ostream & operator<<(std::ostream &os, const FileAttr &fa)