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