The Gaudi Framework  v29r0 (ff2e7097)
FileMgr.cpp
Go to the documentation of this file.
1 #include "FileMgr.h"
2 
3 #include <fstream>
4 
7 
8 #include "POSIXFileHandler.h"
9 #include "RootFileHandler.h"
10 
11 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
12 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
13 
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16 
17 using namespace std;
18 using namespace Io;
19 
20 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 namespace
23 {
24 
25  void set_bit( int& f, const unsigned int& b ) { f |= 1 << b; }
26 
27  bool get_bit( const int& f, const unsigned int& b ) { return f & ( 1 << b ); }
28 
29  static const std::string s_empty = "";
30 
31  constexpr struct to_name_t {
32  std::string operator()( const FileAttr* f ) const { return f->name(); }
33  std::string operator()( const std::pair<std::string, FileAttr*>& f ) const { return f.first; }
34  } to_name{};
35 
36  constexpr struct select1st_t {
37  template <typename T, typename S>
38  const T& operator()( const std::pair<T, S>& p ) const
39  {
40  return p.first;
41  }
42  } select1st{};
43 
44  constexpr struct select2nd_t {
45  template <typename T, typename S>
46  const S& operator()( const std::pair<T, S>& p ) const
47  {
48  return p.second;
49  }
50  } select2nd{};
51 
52  template <typename InputIterator, typename OutputIterator, typename UnaryOperation, typename UnaryPredicate>
53  OutputIterator transform_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
54  UnaryPredicate pred )
55  {
56  while ( first != last ) {
57  if ( pred( *first ) ) *result++ = op( *first );
58  ++first;
59  }
60  return result;
61  }
62 
63  template <typename InputIterator, typename OutputIterator, typename UnaryOperation, typename UnaryPredicate>
64  OutputIterator transform_copy_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
65  UnaryPredicate pred )
66  {
67  while ( first != last ) {
68  auto t = op( *first );
69  if ( pred( t ) ) *result++ = std::move( t );
70  ++first;
71  }
72  return result;
73  }
74 }
75 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
76 
78 {
79  // Where do the new-ed FileAttr get deleted?
80  // they get pushed into m_descriptors, but m_attr is presumably
81  // where they _also_ should be pushed in order to track ownership...
82 }
83 
84 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
85 
87 {
89 
90  if ( status.isFailure() ) {
91 
92  ON_DEBUG
93  debug() << "Failed to initialize the base class (Service)" << endmsg;
94  return status;
95  }
96 
98  verbose() << "Initializing FileMgr" << endmsg;
99 
100  if ( m_loadRootHandler.value() ) {
101 
102  // setup file handler for ROOT
103 
104  msgSvc()->setOutputLevel( "RootFileHandler", m_outputLevel.value() );
105  m_rfh.reset( new RootFileHandler( msgSvc(), m_ssl_proxy, m_ssl_cert ) );
106 
107  auto rfh = m_rfh.get(); // used in the lambdas to avoid capturing 'this'
108  Io::FileHdlr hdlr(
109  Io::ROOT, [rfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
110  void*& ptr ) -> Io::open_t { return rfh->openRootFile( n, f, desc, fd, ptr ); },
111  [rfh]( void* ptr ) -> Io::close_t { return rfh->closeRootFile( ptr ); },
112  [rfh]( void* ptr, const Io::IoFlags& f ) -> Io::reopen_t { return rfh->reopenRootFile( ptr, f ); } );
113 
114  if ( regHandler( hdlr ).isFailure() ) {
115  error() << "unable to register ROOT file handler with FileMgr" << endmsg;
116  }
117  }
118 
119  if ( m_loadPosixHandler.value() ) {
120 
121  // setup file handler for POSIX
122 
123  msgSvc()->setOutputLevel( "POSIXFileHandler", m_outputLevel.value() );
124  m_pfh.reset( new POSIXFileHandler( msgSvc() ) );
125 
126  auto pfh = m_pfh.get(); // used in the lambdas to avoid capturing 'this'
127  Io::FileHdlr hdlp(
128  Io::POSIX, [pfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
129  void*& ptr ) -> Io::open_t { return pfh->openPOSIXFile( n, f, desc, fd, ptr ); },
130  [pfh]( Io::Fd fd ) -> Io::close_t { return pfh->closePOSIXFile( fd ); },
131  [pfh]( Io::Fd fd, const Io::IoFlags& f ) -> Io::reopen_t { return pfh->reopenPOSIXFile( fd, f ); } );
132 
133  if ( regHandler( hdlp ).isFailure() ) {
134  error() << "unable to register ROOT file handler with FileMgr" << endmsg;
135  }
136  }
137 
138  return StatusCode::SUCCESS;
139 }
140 
141 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
142 
144 {
145  ON_VERBOSE
146  verbose() << "FileMgr::finalize()" << endmsg;
147 
148  if ( m_printSummary || msgLevel( MSG::DEBUG ) ) {
149  listHandlers();
150  listFiles();
151  listActions();
152  listSuppression();
153  }
154 
155  if ( !m_files.empty() ) {
156  auto& log = warning();
157  log << "At finalize, the following files remained open:" << endl;
158  for ( const auto& itr : m_files ) log << *( itr.second ) << endl;
159  log << endmsg;
160  }
161 
162  if ( m_logfile.value() != "" ) {
163  std::ofstream ofs;
164  ofs.open( m_logfile.value().c_str() );
165  if ( !ofs ) {
166  error() << "Unable to open output file \"" << m_logfile.value() << "\" for writing" << endmsg;
167  } else {
168  ON_DEBUG
169  debug() << "Saving log to \"" << m_logfile.value() << "\"" << endmsg;
170  for ( const auto& itr : m_files ) {
171  ofs << itr.second->name() << " " << itr.second->tech() << " " << itr.second->desc() << " "
172  << itr.second->iflags() << endl;
173  }
174 
175  set<FileAttr> fs;
176  for ( const auto& it2 : m_oldFiles ) fs.insert( *it2 );
177  for ( const auto& it3 : fs ) {
178  ofs << it3.name() << " " << it3.tech() << " " << it3.desc() << " " << it3.iflags()
179  << ( it3.isShared() ? " SHARED" : "" ) << endl;
180  }
181  ofs.close();
182  }
183  }
184 
185  // cleanup FileAttrs
186  m_attr.clear();
187 
188  m_rfh.reset();
189  m_pfh.reset();
190 
191  StatusCode status = Service::finalize();
192 
193  ON_DEBUG
194  if ( status.isSuccess() ) debug() << "Service finalised successfully" << endmsg;
195 
196  return status;
197 }
198 
199 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
200 
201 void FileMgr::handle( const Incident& /*inc*/ ) {}
202 
203 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
204 
206 {
207 
208  IoTech tech = fh.tech;
209 
210  if ( m_handlers.find( tech ) != m_handlers.end() ) {
211  warning() << "Handler for IoTech " << tech << " already registered. Ignoring." << endmsg;
212  return StatusCode::SUCCESS;
213  }
214 
215  if ( !fh.b_open_fcn ) {
216  error() << "open handler for tech " << tech << " is NULL" << endmsg;
217  return StatusCode::FAILURE;
218  }
219 
220  if ( !fh.b_close_fcn && !fh.b_closeP_fcn ) {
221  error() << "no close handler for tech " << tech << " registered" << endmsg;
222  return StatusCode::FAILURE;
223  }
224 
225  if ( !fh.b_reopen_fcn && !fh.b_reopenP_fcn ) {
226  error() << "no reopen handler for tech " << tech << " registered" << endmsg;
227  return StatusCode::FAILURE;
228  }
229 
230  ON_DEBUG
231  debug() << "Successfully registered handler for tech \"" << tech << "\"" << endmsg;
232 
233  m_handlers[tech] = fh;
234 
235  return StatusCode::SUCCESS;
236 }
237 
238 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
239 
241 {
242  FileHdlr hdlr;
243 
244  auto itr = m_handlers.find( tech );
245  if ( itr == m_handlers.end() ) {
246  error() << "Can't de-register tech " << tech << " as it hasn't been registered!" << endmsg;
247  return StatusCode::FAILURE;
248  }
249 
250  m_handlers.erase( itr );
251  return StatusCode::SUCCESS;
252 }
253 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
254 
256 {
257 
258  auto itr = m_handlers.find( tech );
259  return ( itr != m_handlers.end() ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
260 }
261 
262 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
263 
264 open_t FileMgr::open( const IoTech& tech, const std::string& caller, const std::string& fname, const IoFlags& flags,
265  Fd& fd, void*& ptr, const std::string& desc, bool sh )
266 {
267 
268  return open( tech, caller, fname, desc, flags, fd, ptr, sh );
269 }
270 
271 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
272 open_t FileMgr::open( const IoTech& tech, const std::string& caller, const std::string& fname, const IoFlags& flags,
273  Fd& fd, const std::string& desc, bool sh )
274 {
275 
276  void* dummy( 0 );
277  return open( tech, caller, fname, desc, flags, fd, dummy, sh );
278 }
279 
280 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
281 open_t FileMgr::open( const IoTech& tech, const std::string& caller, const std::string& fname, const IoFlags& flags,
282  void*& ptr, const std::string& desc, bool sh )
283 {
284 
285  Fd dummy( -1 );
286  return open( tech, caller, fname, desc, flags, dummy, ptr, sh );
287 }
288 
289 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
290 
291 open_t FileMgr::open( const IoTech& tech, const std::string& caller, const std::string& fname, const std::string& desc,
292  const IoFlags& flags, Fd& fd, void*& ptr, bool shared )
293 {
294 
295  // return codes: ok == 0, warning > 0, error < 0
296  // 0: ok
297  //
298  // WARNING:
299  // 1: file already open with existing FileAttributes
300  // 2: file already open with different FileAttributes
301  // 3: file opened, but fd and ptr are both invalid
302  //
303  // ERRORS:
304  // -1: no handler for TECH
305  // -2: file already open with different tech
306  // -3: file asked to be opened in shared mode, but other open file
307  // exist that are marked unshared
308  // -4: error calling tech specific open function
309 
310  ON_VERBOSE
311  verbose() << "open(" << tech << "," << caller << ",\"" << fname << "\",\"" << desc << "\"," << flags
312  << ( shared ? ",shared" : ",unshared" ) << ")" << endmsg;
313 
314  open_t r = -1;
315  FileHdlr fh;
316  if ( getHandler( tech, fh ).isFailure() ) return r;
317 
318  auto fitr = m_files.equal_range( fname );
319 
320  // make sure all files with same name have same tech
321 
322  auto itr =
323  std::find_if( fitr.first, fitr.second, [&]( fileMap::const_reference i ) { return i.second->tech() != tech; } );
324  if ( itr != fitr.second ) {
325  error() << "when calling open on " << fname << " with tech " << tech << ", file already opened with different tech "
326  << itr->second->tech() << endmsg;
327  r = -1;
328  return r;
329  }
330 
331  // check for sharing
332 
333  if ( shared ) {
334 
335  bool shareable( true );
336 
337  for ( auto itr = fitr.first; itr != fitr.second; ++itr ) {
338  FileAttr* fa = itr->second;
339 
340  if ( !fa->isShared() ) shareable = false;
341 
342  // if ( shareable && accessMatch(fa->flags(),flags) )
343  if ( shareable && fa->flags().match( flags, false ) ) {
344 
345  ON_DEBUG
346  debug() << " found shared file: " << *fa << endmsg;
347 
348  fd = fa->fd();
349  ptr = fa->fptr();
350  r = 0;
351  }
352  }
353 
354  if ( !shareable ) {
355  // at least one of the other files was not marked shared.
356  fd = -1;
357  ptr = 0;
358  r = -1;
359  }
360  }
361 
362  if ( r != 0 ) {
363 
364  try {
365  r = fh.b_open_fcn( fname, flags, desc, fd, ptr );
366  } catch ( const std::bad_function_call& err ) {
367  error() << "when calling open handler for " << tech << " on file " << fname << " caught " << err.what() << endmsg;
368  return -4;
369  } catch ( ... ) {
370  error() << "when calling open handler for " << tech << " on file " << fname << " caught an unknown exception."
371  << endmsg;
372  return -4;
373  }
374 
375  if ( r != 0 ) {
376  warning() << "open of file \"" << fname << "\", tech: \"" << tech << "\", flags: \"" << flags
377  << "\" requested by " << caller << " failed. return code: " << r << endmsg;
378 
379  FileAttr xfa( -1, fname, desc, tech, flags, 0, false );
380  execAction( &xfa, caller, Io::OPEN_ERR ).ignore();
381 
382  return r;
383  }
384  }
385 
386  //@TODO/@FIXME: should this not be pushed into m_attr???
387  // eg. m_attr.emplace_back( new FileAttr(fd,fname,desc,tech,flags,ptr,true,shared) );
388  // FileAttr* fa = m_attr.back().get();
389  FileAttr* fa = new FileAttr( fd, fname, desc, tech, flags, ptr, true, shared );
390 
391  ON_DEBUG
392  debug() << "opened file " << *fa << endmsg;
393 
394  if ( fd == -1 && ptr == 0 ) {
395  warning() << "when opening " << *fa << " both File Descriptor"
396  << " and File Ptr are invalid" << endmsg;
397  r = 3;
398  }
399 
400  for ( auto itr = fitr.first; itr != fitr.second; ++itr ) {
401  if ( fa->flags() == Io::READ || shared ) {
402  // ok
403  } else if ( *fa == *( itr->second ) ) {
404  warning() << "open call for file \"" << fname << "\" returned a pre-existing file with identical"
405  << " FileAttributes: " << *fa << endmsg;
406  r = 1;
407  } else {
408  warning() << "open call for file \"" << fname << "\" returned a pre-existing file with different"
409  << " FileAttributes -" << endl
410  << "old: " << *( itr->second ) << endl
411  << "new: " << *fa << endmsg;
412  r = 2;
413  }
414  }
415 
416  m_files.emplace( fname, fa );
417 
418  // execute all our open callbacks
419  if ( execAction( fa, caller, Io::OPEN ).isFailure() ) {
420  warning() << "at least one open callback action failed" << endmsg;
421  }
422 
423  return r;
424 }
425 
426 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
427 
428 close_t FileMgr::close( Fd fd, const std::string& caller )
429 {
430 
431  // return codes:
432  // < 0 : error condition
433  // 0 : actual close of one file
434  // > 0 : shared file, removed from list, no actual close, returns
435  // number of shared files still open.
436 
437  ON_VERBOSE
438  verbose() << "close(" << fd << ")" << endmsg;
439 
440  close_t r = -1;
441 
442  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
443  [&]( fileMap::const_reference i ) { return i.second->fd() == fd; } );
444 
445  if ( itr == std::end( m_files ) ) {
446  error() << "unknown file descriptor \"" << fd << "\" when calling close()" << endmsg;
447  return r;
448  }
449 
450  IoTech tech = itr->second->tech();
451 
452  FileHdlr fh;
453 
454  if ( getHandler( tech, fh ).isFailure() ) {
455  return r;
456  }
457 
458  if ( !fh.b_close_fcn ) {
459  error() << "no close(" << tech << ",Fd) function registered" << endmsg;
460  return -1;
461  }
462 
463  FileAttr* fa = itr->second;
464 
465  // find how many times this file is open
466  auto fitr = m_files.equal_range( fa->name() );
467  int i = std::count_if( fitr.first, fitr.second, [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
468 
469  ON_VERBOSE
470  verbose() << " ref count: " << i << endmsg;
471 
472  if ( i > 1 && fa->isShared() ) {
473  // file open multiple times. don't do the actual close
474  ON_DEBUG
475  debug() << "closing file " << fa->name() << " opened " << i << " times with Fd " << fd << endmsg;
476  m_files.erase( itr );
477 
478  r = i - 1;
479 
480  } else if ( i == 1 || ( i > 1 && !fa->isShared() ) ) {
481  ON_DEBUG
482  debug() << "closing " << *fa << endmsg;
483 
484  try {
485  r = fh.b_close_fcn( fd );
486  } catch ( const std::bad_function_call& err ) {
487  error() << "when calling close handler for " << tech << " on file descriptor " << fd << " caught " << err.what()
488  << endmsg;
489  execAction( fa, caller, Io::CLOSE_ERR ).ignore();
490  return -1;
491  } catch ( ... ) {
492  error() << "when calling close handler for " << tech << " on file descriptor " << fd
493  << " caught an unknown exception." << endmsg;
494  execAction( fa, caller, Io::CLOSE_ERR ).ignore();
495  return -1;
496  }
497 
498  if ( r < 0 ) {
499  warning() << "close of file with FD \"" << fd << "\", name: \"" << fa->name() << "\", tech: \"" << tech
500  << "\" failed" << endmsg;
501 
502  execAction( fa, caller, Io::CLOSE_ERR ).ignore();
503 
504  return r;
505  }
506 
507  m_files.erase( itr );
508 
509  } else if ( i <= 0 ) {
510  // this should never happen!
511  error() << "ref count < 0 when closing " << fa << ". This should never happen" << endmsg;
512  return -1;
513  }
514 
515  fa->fd( -1 );
516  fa->flags( INVALID );
517  fa->isOpen( false );
518  fa->fptr( 0 );
519  m_oldFiles.push_back( fa );
520 
521  // exec all callbacks
522  if ( execAction( fa, caller, Io::CLOSE ).isFailure() ) {
523  warning() << "at least one close callback action failed" << endmsg;
524  }
525 
526  return r;
527 }
528 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
529 
530 close_t FileMgr::close( void* vp, const std::string& caller )
531 {
532 
533  // return codes:
534  // < 0 : error condition
535  // 0 : actual close of one file
536  // > 0 : shared file, removed from list, no actual close, returns
537  // number of shared files still open.
538 
539  ON_VERBOSE
540  verbose() << "close(" << vp << ")" << endmsg;
541 
542  close_t r = -1;
543 
544  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
545  [&]( fileMap::const_reference i ) { return i.second->fptr() == vp; } );
546 
547  if ( itr == m_files.end() ) {
548  error() << "unknown file ptr \"" << vp << "\" when calling close()" << endmsg;
549  return r;
550  }
551 
552  IoTech tech = itr->second->tech();
553 
554  FileHdlr fh;
555 
556  if ( getHandler( tech, fh ).isFailure() ) {
557  return r;
558  }
559  if ( !fh.b_closeP_fcn ) {
560  error() << "no close(" << tech << ",void*) function registered" << endmsg;
561  return -1;
562  }
563 
564  FileAttr* fa = itr->second;
565 
566  // find how many times this file is open
567  pair<fileMap::const_iterator, fileMap::const_iterator> fitr = m_files.equal_range( fa->name() );
568 
569  int i =
570  std::count_if( fitr.first, fitr.second, [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
571 
572  ON_VERBOSE
573  verbose() << " ref count: " << i << endmsg;
574 
575  if ( i > 1 && fa->isShared() ) {
576  // file open multiple times in shared access. don't do the actual close
577  ON_DEBUG
578  debug() << "closing file " << fa->name() << " opened " << i << " times with fptr " << vp << endmsg;
579  m_files.erase( itr );
580 
581  r = i - 1;
582 
583  } else if ( i == 1 || ( i > 1 && !fa->isShared() ) ) {
584  ON_DEBUG
585  debug() << "closing: " << *fa << endmsg;
586 
587  try {
588  r = fh.b_closeP_fcn( vp );
589  } catch ( const std::bad_function_call& err ) {
590  error() << "when calling close handler for " << tech << " on file " << fa->name() << " caught " << err.what()
591  << endmsg;
592  execAction( fa, caller, CLOSE_ERR ).ignore();
593  return -1;
594  } catch ( ... ) {
595  error() << "when calling close handler for " << tech << " on file " << fa->name()
596  << " caught an unknown exception." << endmsg;
597  execAction( fa, caller, CLOSE_ERR ).ignore();
598  return -1;
599  }
600 
601  if ( r < 0 ) {
602  warning() << "close of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
603  << "\" failed" << endmsg;
604 
605  return r;
606  }
607 
608  m_files.erase( itr );
609 
610  } else {
611  // this should never happen!
612  error() << "ref count: " << i << " < 0 when closing " << fa << ". This should never happen" << endmsg;
613  return -1;
614  }
615 
616  fa->fd( -1 );
617  fa->flags( INVALID );
618  fa->isOpen( false );
619  fa->fptr( 0 );
620  m_oldFiles.push_back( fa );
621 
622  // exec all callbacks
623  if ( execAction( fa, caller, CLOSE ).isFailure() ) {
624  warning() << "at least one close callback action failed" << endmsg;
625  }
626 
627  return r;
628 }
629 
630 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
631 
632 reopen_t FileMgr::reopen( Fd fd, const IoFlags& flags, const std::string& caller )
633 {
634 
635  ON_VERBOSE
636  verbose() << "reopen(" << fd << "," << flags << "," << caller << ")" << endmsg;
637 
638  reopen_t r = -1;
639 
640  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
641  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
642 
643  if ( itr == m_files.end() ) {
644  error() << "unregistered FD \"" << fd << "\" when calling reopen()" << endmsg;
645  return r;
646  }
647 
648  FileAttr* fa = itr->second;
649  IoTech tech = fa->tech();
650 
651  FileHdlr fh;
652 
653  if ( getHandler( tech, fh ).isFailure() ) {
654  return r;
655  }
656 
657  fa->flags( flags );
658 
659  if ( !fh.b_reopen_fcn ) {
660  error() << "no reopen(" << tech << ",Fd) function registered" << endmsg;
661  return -1;
662  }
663 
664  // FIXME: what does it mean to call reopen on a shared file?
665 
666  try {
667  r = fh.b_reopen_fcn( fd, flags );
668  } catch ( const std::bad_function_call& err ) {
669  error() << "when calling reopen handler for " << tech << " on file descriptor " << fd << " with flags " << flags
670  << " caught " << err.what() << endmsg;
671  return -1;
672  } catch ( ... ) {
673  error() << "when calling reopen handler for " << tech << " on file descriptor " << fd << " with flags " << flags
674  << " caught an unknown exception." << endmsg;
675  return -1;
676  }
677 
678  if ( r < 0 ) {
679  warning() << "reopen of file with FD \"" << fd << "\", name: \"" << fa->name() << "\", tech: \"" << tech
680  << "\", flags: \"" << flags << "\" failed" << endmsg;
681 
682  execAction( fa, caller, Io::REOPEN_ERR ).ignore();
683 
684  return r;
685  }
686 
687  fa->isOpen( true );
688  fa->flags( flags );
689 
690  // exec all callbacks
691  if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
692  warning() << "at least one reopen callback action failed" << endmsg;
693  }
694 
695  return r;
696 }
697 
698 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
699 
700 reopen_t FileMgr::reopen( void* vp, const IoFlags& flags, const std::string& caller )
701 {
702  ON_VERBOSE
703  verbose() << "reopen(" << vp << "," << flags << "," << caller << ")" << endmsg;
704 
705  reopen_t r = -1;
706 
707  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
708  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
709  if ( itr == m_files.end() ) {
710  error() << "unregistered file ptr \"" << vp << "\" when calling reopen()" << endmsg;
711  return r;
712  }
713 
714  FileAttr* fa = itr->second;
715  FileHdlr fh;
716  IoTech tech = fa->tech();
717 
718  if ( getHandler( tech, fh ).isFailure() ) {
719  return r;
720  }
721 
722  if ( !fh.b_reopenP_fcn ) {
723  error() << "no reopen(" << tech << ",void*) function registered" << endmsg;
724  return -1;
725  }
726 
727  try {
728  r = fh.b_reopenP_fcn( vp, flags );
729  } catch ( const std::bad_function_call& err ) {
730  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
731  << " caught " << err.what() << endmsg;
732  return -1;
733  } catch ( ... ) {
734  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
735  << " caught an unknown exception." << endmsg;
736  return -1;
737  }
738 
739  if ( r < 0 ) {
740  warning() << "reopen of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
741  << "\", flags: \"" << flags << "\" failed" << endmsg;
742 
743  execAction( fa, caller, Io::REOPEN_ERR ).ignore();
744 
745  return r;
746  }
747 
748  fa->isOpen( true );
749  fa->flags( flags );
750 
751  // exec all callbacks
752  if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
753  warning() << "at least one reopen callback action failed" << endmsg;
754  }
755 
756  return r;
757 }
758 
759 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
760 
762 {
763 
764  fa.clear();
765 
766  auto fitr = m_files.equal_range( fname );
767  std::transform( fitr.first, fitr.second, std::back_inserter( fa ), select2nd );
768 
769  std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( fa ),
770  [&]( const FileAttr* f ) { return f->name() == fname; } );
771 
772  return fa.size();
773 }
774 
775 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
776 
777 StatusCode FileMgr::getFileAttr( const Fd fd, const FileAttr*& fa ) const
778 {
779 
780  auto i = std::find_if( std::begin( m_files ), std::end( m_files ),
781  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
782  if ( i != std::end( m_files ) ) {
783  fa = i->second;
784  return StatusCode::SUCCESS;
785  }
786 
787  auto j = std::find_if( std::begin( m_oldFiles ), std::end( m_oldFiles ),
788  [&]( const FileAttr* f ) { return f->fd() == fd; } );
789  if ( j != std::end( m_oldFiles ) ) {
790  fa = *j;
791  return StatusCode::SUCCESS;
792  }
793 
794  return StatusCode::FAILURE;
795 }
796 
797 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
798 
799 StatusCode FileMgr::getFileAttr( void* vp, const FileAttr*& fa ) const
800 {
801 
802  auto i = std::find_if( std::begin( m_files ), std::end( m_files ),
803  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
804  if ( i != std::end( m_files ) ) {
805  fa = i->second;
806  return StatusCode::SUCCESS;
807  }
808 
809  auto j = std::find_if( std::begin( m_oldFiles ), std::end( m_oldFiles ),
810  [&]( const FileAttr* f ) { return f->fptr() == vp; } );
811  if ( j != std::end( m_oldFiles ) ) {
812  fa = *j;
813  return StatusCode::SUCCESS;
814  }
815 
816  return StatusCode::FAILURE;
817 }
818 
819 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
820 
821 int FileMgr::getFiles( std::vector<std::string>& files, bool op ) const
822 {
823 
824  files.clear();
825  auto not_in_files = [&]( const std::string& i ) {
826  return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& j ) { return j == i; } );
827  };
828  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name, not_in_files );
829  if ( !op ) {
830  transform_copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
831  not_in_files );
832  }
833  return files.size();
834 }
835 
836 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
837 
838 int FileMgr::getFiles( vector<const Io::FileAttr*>& files, bool op ) const
839 {
840 
841  files.clear();
842  std::transform( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd );
843  if ( !op ) {
844  std::copy( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ) );
845  }
846  return files.size();
847 }
848 
849 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
850 
851 int FileMgr::getFiles( const IoTech& tech, vector<string>& files, bool op ) const
852 {
853 
854  if ( tech == UNKNOWN ) return getFiles( files, op );
855 
856  files.clear();
857  transform_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
858  [&]( fileMap::const_reference f ) {
859  return f.second->tech() == tech &&
860  std::none_of( std::begin( files ), std::end( files ),
861  [&]( const std::string& j ) { return j == f.first; } );
862  } );
863 
864  if ( !op ) {
865  transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
866  [&]( const FileAttr* f ) {
867  return f->tech() == tech && std::none_of( std::begin( files ), std::end( files ),
868  [&]( const std::string& j ) { return j == f->name(); } );
869  } );
870  }
871  return files.size();
872 }
873 
874 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
875 
876 int FileMgr::getFiles( const IoTech& tech, vector<const Io::FileAttr*>& files, bool op ) const
877 {
878 
879  if ( tech == UNKNOWN ) return getFiles( files, op );
880 
881  auto matches_tech = [&]( const FileAttr* f ) { return f->tech() == tech; };
882 
883  files.clear();
884  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd, matches_tech );
885  if ( !op ) {
886  std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), matches_tech );
887  }
888 
889  return files.size();
890 }
891 
892 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
893 
894 int FileMgr::getFiles( const IoTech& tech, const IoFlags& flags, vector<string>& files, bool op ) const
895 {
896 
897  files.clear();
898 
899  auto not_in_files = [&]( const std::string& n ) {
900  return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& f ) { return f == n; } );
901  };
902  auto matches_tech_and_flags = [&]( const FileAttr* f ) {
903  return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
904  };
905 
906  transform_if(
907  std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
908  [&]( fileMap::const_reference f ) { return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
909  if ( !op ) {
910  transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
911  [&]( const FileAttr* f ) { return matches_tech_and_flags( f ) && not_in_files( f->name() ); } );
912  }
913 
914  return files.size();
915 }
916 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
917 
918 int FileMgr::getFiles( const IoTech& tech, const IoFlags& flags, vector<const Io::FileAttr*>& files, bool op ) const
919 {
920 
921  files.clear();
922 
923  auto matches_tech_and_flags = [&]( const FileAttr* f ) {
924  return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
925  };
926 
927  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd,
928  matches_tech_and_flags );
929  if ( !op ) {
930  std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ),
931  matches_tech_and_flags );
932  }
933 
934  return files.size();
935 }
936 
937 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
938 
939 // get all descriptors known
940 // return number found
941 
942 int FileMgr::getFd( vector<Fd>& fd ) const
943 {
944 
945  std::transform( std::begin( m_descriptors ), std::end( m_descriptors ), std::back_inserter( fd ), select1st );
946  return m_descriptors.size();
947 }
948 
949 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
950 
951 // get all descriptors given tech
952 // return number found
953 
954 int FileMgr::getFd( const IoTech& tech, vector<Fd>& fd ) const
955 {
956 
957  if ( tech == UNKNOWN ) return getFd( fd );
958 
959  fd.clear();
960  transform_if( std::begin( m_descriptors ), std::end( m_descriptors ), std::back_inserter( fd ), select1st,
961  [&]( const std::pair<Fd, FileAttr*>& d ) { return d.second->tech() == tech; } );
962 
963  return fd.size();
964 }
965 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
966 
967 // get all descriptors of given tech and flags
968 // return number found
969 
970 int FileMgr::getFd( const IoTech& tech, const IoFlags& flags, vector<Fd>& fd ) const
971 {
972 
973  fd.clear();
974  transform_if( m_descriptors.begin(), m_descriptors.end(), std::back_inserter( fd ), select1st,
975  [&]( const std::pair<Fd, FileAttr*>& d ) {
976  return ( d.second->tech() == tech || tech == UNKNOWN ) && ( d.second->flags() == flags );
977  } );
978  return fd.size();
979 }
980 
981 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
982 
983 const std::string& FileMgr::fname( const Io::Fd& fd ) const
984 {
985 
986  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
987  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
988  return ( itr != std::end( m_files ) ) ? itr->second->name() : s_empty;
989 }
990 
991 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
992 
993 const std::string& FileMgr::fname( void* vp ) const
994 {
995 
996  auto itr = std::find_if( m_files.begin(), m_files.end(),
997  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
998  return itr != m_files.end() ? itr->second->name() : s_empty;
999 }
1000 
1001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1002 
1003 Io::Fd FileMgr::fd( const std::string& fname ) const
1004 {
1005 
1006  auto fitr = m_files.equal_range( fname );
1007  auto itr = std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) { return f.second->fd() != -1; } );
1008  return itr != fitr.second ? itr->second->fd() : -1;
1009 }
1010 
1011 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1012 
1013 Io::Fd FileMgr::fd( void* fptr ) const
1014 {
1015 
1016  auto itr = std::find_if( m_files.begin(), m_files.end(),
1017  [&]( fileMap::const_reference f ) { return f.second->fptr() == fptr; } );
1018  return itr != m_files.end() ? itr->second->fd() : -1;
1019 }
1020 
1021 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1022 
1023 void* FileMgr::fptr( const std::string& fname ) const
1024 {
1025  auto fitr = m_files.equal_range( fname );
1026  auto itr =
1027  std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) -> bool { return f.second->fptr(); } );
1028  return itr != fitr.second ? itr->second->fptr() : nullptr;
1029 }
1030 
1031 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1032 
1033 void* FileMgr::fptr( const Io::Fd& fd ) const
1034 {
1035 
1036  auto itr = std::find_if( m_files.begin(), m_files.end(),
1037  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
1038  return itr != m_files.end() ? itr->second->fptr() : nullptr;
1039 }
1040 
1041 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1042 
1044 {
1045 
1046  info() << "listing registered files [" << ( m_files.size() + m_oldFiles.size() ) << "]:" << endl;
1047 
1048  for ( auto& itr : m_files ) info() << itr.second << endl;
1049  for ( auto& it2 : m_oldFiles ) info() << *it2 << endl;
1050 
1051  info() << endmsg;
1052 }
1053 
1054 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1055 
1057 {
1058 
1059  err = m_lastErrS;
1060  return m_lastErr;
1061 }
1062 
1063 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1064 
1065 StatusCode FileMgr::getHandler( const Io::IoTech& tech, Io::FileHdlr& hdlr ) const
1066 {
1067 
1068  auto itr = m_handlers.find( tech );
1069  if ( itr == m_handlers.end() ) {
1070  error() << "no handler for tech " << tech << " registered" << endmsg;
1071  return StatusCode::FAILURE;
1072  }
1073  hdlr = itr->second;
1074  return StatusCode::SUCCESS;
1075 }
1076 
1077 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1078 
1080 {
1081 
1082  auto fitr = m_files.equal_range( fname );
1083  if ( fitr.first == fitr.second ) {
1084  error() << "no file \"" << fname << "\" registered. Cannot determine tech" << endmsg;
1085  return StatusCode::FAILURE;
1086  }
1087 
1088  auto itr = fitr.first;
1089  IoTech tech = itr->second->tech();
1090 
1091  ++itr;
1092  while ( itr != fitr.second ) {
1093  if ( itr->second->tech() != tech ) {
1094  error() << "multiple technologies registered for file \"" << fname << "\". Cannot determine handler" << endmsg;
1095  return StatusCode::FAILURE;
1096  }
1097  ++itr;
1098  }
1099 
1100  return getHandler( tech, hdlr );
1101 }
1102 
1103 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1104 
1106 {
1107 
1108  info() << "Listing registered handlers:" << endl;
1109 
1110  for ( const auto& itr : m_handlers ) info() << " " << itr.first << endl;
1111  info() << endmsg;
1112 }
1113 
1114 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1115 
1117 {
1118 
1119  return regAction( bf, a, Io::UNKNOWN, d );
1120 }
1121 
1122 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1123 
1125 {
1126 
1127  ON_DEBUG
1128  debug() << "registering " << a << " action " << System::typeinfoName( bf.target_type() ) << " for tech " << t
1129  << endmsg;
1130 
1131  m_actions[t][a].emplace_back( bf, ( !d.empty() ) ? d : System::typeinfoName( bf.target_type() ) );
1132  return StatusCode::SUCCESS;
1133 }
1134 
1135 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1136 
1138 {
1139 
1140  info() << "listing registered actions" << endl;
1141 
1142  for ( const auto& iit : m_actions ) {
1143  Io::IoTech t = iit.first;
1144  const actionMap& m = iit.second;
1145 
1146  if ( !m.empty() ) {
1147  info() << " --- Tech: ";
1148  if ( t == Io::UNKNOWN ) {
1149  info() << "ALL ---" << endl;
1150  } else {
1151  info() << t << " ---" << endl;
1152  }
1153  for ( const auto& iia : m ) {
1154  for ( const auto& it2 : iia.second ) {
1155  info() << " " << iia.first << " " << it2.second << endl;
1156  }
1157  }
1158  }
1159  }
1160  info() << endmsg;
1161 }
1162 
1163 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1164 
1166 {
1167 
1168  Io::IoTech tech = fa->tech();
1169 
1170  StatusCode s1, s2;
1171 
1172  auto itr = m_actions.find( Io::UNKNOWN );
1173 
1174  if ( itr != m_actions.end() && !itr->second.empty() ) {
1175  s1 = execActs( fa, caller, a, itr->second );
1176  }
1177 
1178  itr = m_actions.find( tech );
1179  if ( itr != m_actions.end() && !itr->second.empty() ) {
1180  s2 = execActs( fa, caller, a, itr->second );
1181  }
1182 
1183  return ( s1.isFailure() || s2.isFailure() ) ? StatusCode::FAILURE : StatusCode::SUCCESS;
1184 }
1185 
1186 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1187 
1189  const actionMap& m ) const
1190 {
1191 
1192  auto mitr = m.find( a );
1193 
1194  if ( mitr == m.end() || mitr->second.empty() ) {
1195  return StatusCode::SUCCESS;
1196  }
1197 
1198  ON_DEBUG
1199  debug() << "executing " << mitr->second.size() << " " << a << " actions on " << *fa << " from " << caller << endmsg;
1200 
1201  bool fail( false );
1202 
1203  auto it2 = m_supMap.find( fa->name() );
1204  if ( it2 != m_supMap.end() ) {
1205  if ( get_bit( it2->second, a ) || get_bit( it2->second, Io::INVALID_ACTION ) ) {
1206  ON_DEBUG
1207  debug() << " --> suppressing callback action for " << a << endmsg;
1208  return StatusCode::SUCCESS;
1209  }
1210  }
1211 
1212  for ( const auto& itr : mitr->second ) {
1213 
1214  ON_DEBUG
1215  debug() << "executing " << itr.second << endmsg;
1216 
1217  if ( ( ( ( itr.first ) )( fa, caller ) ).isFailure() ) {
1218  warning() << "execution of " << itr.second << " on " << *fa << " failed during " << a << " action" << endmsg;
1219  fail = true;
1220  }
1221  }
1222 
1223  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
1224 }
1225 
1226 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1227 
1228 bool FileMgr::accessMatch( const Io::IoFlags& fold, const Io::IoFlags& fnew, bool /*strict*/ ) const
1229 {
1230 
1231  ON_VERBOSE
1232  verbose() << "accessMatch old: " << fold << " new: " << fnew << endmsg;
1233 
1234  return ( ( ( fold == Io::READ ) && ( fnew == Io::READ ) ) ||
1235  ( ( fold & Io::WRITE ) != 0 && ( fnew & Io::WRITE ) != 0 ) ||
1236  ( ( fold & Io::RDWR ) != 0 && ( fnew & Io::RDWR ) != 0 ) );
1237 }
1238 
1239 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1240 
1241 void FileMgr::suppressAction( const std::string& f ) { return suppressAction( f, Io::INVALID_ACTION ); }
1242 
1243 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1244 
1246 {
1247 
1248  auto it2 = m_supMap.find( f );
1249  if ( it2 == m_supMap.end() ) {
1250  int b( 0 );
1251  set_bit( b, a );
1252  m_supMap[f] = b;
1253  } else {
1254  set_bit( it2->second, a );
1255  }
1256 }
1257 
1258 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1259 
1261 {
1262 
1263  if ( m_supMap.empty() ) return;
1264 
1265  info() << "listing suppressed file actions" << endl;
1266 
1267  for ( auto it2 = m_supMap.begin(); it2 != m_supMap.end(); ++it2 ) {
1268  info() << " " << it2->first;
1269  if ( get_bit( it2->second, Io::INVALID_ACTION ) ) {
1270  info() << " ALL" << endl;
1271  } else {
1272  for ( int i = 0; i < Io::INVALID_ACTION; ++i ) {
1273  if ( get_bit( it2->second, i ) ) {
1274  info() << " " << (Io::Action)i;
1275  }
1276  }
1277  info() << endl;
1278  }
1279  }
1280 
1281  info() << endmsg;
1282 }
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:205
IoTech
Definition: IFileMgr.h:157
void listHandlers() const override
Definition: FileMgr.cpp:1105
StatusCode initialize() override
Definition: Service.cpp:64
int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const override
Definition: FileMgr.cpp:761
void listFiles() const override
Definition: FileMgr.cpp:1043
T empty(T...args)
Definition: IFileMgr.h:19
T copy_if(T...args)
T open(T...args)
StatusCode finalize() override
Definition: Service.cpp:174
StatusCode hasHandler(const IoTech &) const override
Definition: FileMgr.cpp:255
int reopen_t
Definition: IFileMgr.h:251
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
int Fd
Definition: IFileMgr.h:171
Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &fd, void *&ptr, const std::string &desc="", const bool shared=false) override
Definition: FileMgr.cpp:264
bfcn_reopen_t b_reopen_fcn
Definition: IFileMgr.h:266
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1241
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:821
void * fptr() const
Definition: IFileMgr.h:194
T endl(T...args)
int open_t
Definition: IFileMgr.h:249
STL namespace.
bool isOpen() const
Definition: IFileMgr.h:195
StatusCode deregHandler(const IoTech &) override
Definition: FileMgr.cpp:240
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1165
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:188
STL class.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
Definition: FileMgr.cpp:1228
virtual void listActions() const
Definition: FileMgr.cpp:1137
STL class.
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1003
Action
Definition: IFileMgr.h:284
const std::string & name() const
Definition: IFileMgr.h:189
STL class.
bool isShared() const
Definition: IFileMgr.h:196
void handle(const Incident &) override
Definition: FileMgr.cpp:201
StatusCode getHandler(const IoTech &, FileHdlr &) const override
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
constexpr double m
Definition: SystemOfUnits.h:94
bfcn_close_t b_close_fcn
Definition: IFileMgr.h:264
T close(T...args)
Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller) override
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1188
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:265
Io::close_t close(const Fd, const std::string &caller) override
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:267
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:211
T clear(T...args)
T move(T...args)
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1116
T count_if(T...args)
T target_type(T...args)
T insert(T...args)
T find_if(T...args)
T size(T...args)
bfcn_open_t b_open_fcn
Definition: IFileMgr.h:263
STL class.
STL class.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
virtual void listSuppression() const
Definition: FileMgr.cpp:1260
IoTech tech() const
Definition: IFileMgr.h:191
T begin(T...args)
bool match(const IoFlags &fa, bool strict=true) const
Definition: IFileMgr.h:61
T back_inserter(T...args)
T none_of(T...args)
Base class for all Incidents (computing events).
Definition: Incident.h:17
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:983
T transform(T...args)
#define ON_DEBUG
Definition: FileMgr.cpp:11
int getFd(std::vector< Fd > &) const override
~FileMgr() override
Definition: FileMgr.cpp:77
IoFlags flags() const
Definition: IFileMgr.h:192
StatusCode finalize() override
Definition: FileMgr.cpp:143
#define ON_VERBOSE
Definition: FileMgr.cpp:12
IoTech tech
Definition: IFileMgr.h:261
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
int close_t
Definition: IFileMgr.h:250
StatusCode initialize() override
Definition: FileMgr.cpp:86
int getLastError(std::string &) const override
Definition: FileMgr.cpp:1056
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:1023