HAL  v4.5.0-124-g47ab54673
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
user_feedback.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
29 
30 #include <atomic>
31 #include <string>
32 
33 namespace hal
34 {
35  class UIPluginInterface;
36 
47  namespace user_feedback
48  {
60  void report_progress(int percent, const std::string& message);
61 
70  {
71  public:
72  LayoutLocker();
73  ~LayoutLocker();
74 
75  LayoutLocker(const LayoutLocker&) = delete;
76  LayoutLocker& operator=(const LayoutLocker&) = delete;
77 
78  private:
80  UIPluginInterface* m_ui_plugin;
81  };
82 
92  {
93  public:
99  explicit ProgressScope(const std::string& message);
100 
101  ~ProgressScope();
102 
103  ProgressScope(const ProgressScope&) = delete;
105 
106  private:
107  static std::atomic<u32> s_depth;
108  };
109 
120  {
121  public:
128  explicit ProgressPrinter(const std::string& message, u32 max_detail_size = 0);
129 
132 
135 
144  void report(float progress, const std::string& detail = "");
145 
151  void set_message(const std::string& message);
152 
154  void clear();
155 
157  void reset();
158 
159  private:
161  static int get_terminal_width();
162 
164  ProgressScope m_scope;
165 
167  std::string m_message;
168 
170  std::string m_last_detail;
171 
173  u32 m_printed_progress;
174 
176  u32 m_bar_width;
177 
179  u32 m_max_detail_size;
180 
182  int m_last_percentage;
183 
185  int m_terminal_width;
186  };
187  } // namespace user_feedback
188 } // namespace hal
LayoutLocker & operator=(const LayoutLocker &)=delete
LayoutLocker(const LayoutLocker &)=delete
ProgressPrinter & operator=(const ProgressPrinter &)=delete
void set_message(const std::string &message)
ProgressPrinter(const ProgressPrinter &)=delete
ProgressPrinter(const std::string &message, u32 max_detail_size=0)
void report(float progress, const std::string &detail="")
ProgressScope(const std::string &message)
ProgressScope & operator=(const ProgressScope &)=delete
ProgressScope(const ProgressScope &)=delete
uint32_t u32
Definition: defines.h:41
void report_progress(int percent, const std::string &message)
Definition: defines.h:45