Tomographer  v5.2
Tomographer C++ Framework Documentation
signal_status_report.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2016 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  * Copyright (c) 2017 Caltech, Institute for Quantum Information and Matter, Philippe Faist
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 
28 
29 #ifndef TOMOGRAPHER_TOOLS_SIGNAL_STATUS_REPORT
30 #define TOMOGRAPHER_TOOLS_SIGNAL_STATUS_REPORT
31 
32 
41 #include <tomographer/multiproc.h>
42 
43 
44 namespace Tomographer
45 {
46 namespace Tools
47 {
48 
52 template<typename TaskDispatcher, typename Logger>
53 struct TOMOGRAPHER_EXPORT SigHandlerTaskDispatcherStatusReporter
54  : public SignalHandler
55 {
56  typedef typename TaskDispatcher::FullStatusReportType FullStatusReportType;
57 
58  SigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks_, Logger & logger_)
59  : tasks(tasks_), logger(logger_)
60  {
61  logger.debug("Tomographer::Tools::SigHandlerTaskDispatcherStatusReporter",
62  "Setting up signal handler, with default callback") ;
63  tasks->setStatusReportHandler(intermediateProgressReport) ;
64  }
65 
66  template<typename CallbackFn>
67  SigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks_, Logger & logger_, CallbackFn && fn)
68  : tasks(tasks_), logger(logger_)
69  {
70  logger.debug("Tomographer::Tools::SigHandlerTaskDispatcherStatusReporter",
71  "Setting up signal handler, with custom callback") ;
72  tasks->setStatusReportHandler(std::forward<CallbackFn>(fn)) ;
73  }
74 
75  TaskDispatcher * tasks;
76  Logger & logger;
77 
78  virtual void handleSignal(int /*sig*/)
79  {
80  tasks->requestStatusReport();
81  }
82 
86  static void intermediateProgressReport(const FullStatusReportType& report)
87  {
88  std::cerr << "\n" << report.getHumanReport() << "\n";
89  };
90 
91 };
92 
93 template<typename TaskDispatcher, typename LoggerT>
95 makeSigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks, LoggerT & logger)
96 {
98 }
99 
100 
101 template<typename TaskDispatcher, typename LoggerT, typename CallbackFn>
103 makeSigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks, LoggerT & logger, CallbackFn && fn)
104 {
106  tasks,
107  logger,
108  std::forward<CallbackFn>(fn)
109  );
110 }
111 
112 
113 
114 } // namespace Tools
115 } // namespace Tomographer
116 
117 
118 #endif
Base namespace for the Tomographer project.
Definition: densellh.h:45
An abstract signal handler (C++ interface)
Some common definitions for multiprocessing interfaces.
A generic handler which requests a status report from an OMPTaskDispatcher.
static void intermediateProgressReport(const FullStatusReportType &report)
Format a nice intermediate progress report.
Basic common code for intercepting a signal and basic interfacing to C++.