| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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