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