HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
event_handler.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 
30 
31 #include <iostream>
32 
33 namespace hal
34 {
36  class Netlist;
37  class Net;
38  class Gate;
39  class Module;
40  class Grouping;
41 
46  {
47  public:
48  enum class event
49  {
50  id_changed,
62  };
63  };
64 
65  template<>
66  std::map<NetlistEvent::event, std::string> EnumStrings<NetlistEvent::event>::data;
67 
71  class GateEvent
72  {
73  public:
74  enum class event
75  {
76  created,
77  removed,
78  name_changed,
81  };
82  };
83 
84  template<>
85  std::map<GateEvent::event, std::string> EnumStrings<GateEvent::event>::data;
86 
90  class NetEvent
91  {
92  public:
93  enum class event
94  {
95  created,
96  removed,
97  name_changed,
98  src_added,
99  src_removed,
100  dst_added,
101  dst_removed
102  };
103  };
104 
105  template<>
106  std::map<NetEvent::event, std::string> EnumStrings<NetEvent::event>::data;
107 
112  {
113  public:
114  enum class event
115  {
116  created,
117  removed,
118  name_changed,
119  type_changed,
125  gate_assigned,
128  gate_removed,
129  pin_changed,
130  };
131  };
132 
133  template<>
134  std::map<ModuleEvent::event, std::string> EnumStrings<ModuleEvent::event>::data;
135 
140  {
141  public:
142  enum class event
143  {
144  created,
145  removed,
146  name_changed,
147  color_changed,
148  gate_assigned,
149  gate_removed,
150  net_assigned,
151  net_removed,
154  };
155  };
156 
157  template<>
158  std::map<GroupingEvent::event, std::string> EnumStrings<GroupingEvent::event>::data;
159 
165  {
166  private:
167  CallbackHook<void(NetlistEvent::event, Netlist*, u32)> m_netlist_callback;
168  CallbackHook<void(ModuleEvent::event, Module*, u32)> m_module_callback;
169  CallbackHook<void(GateEvent::event, Gate*, u32)> m_gate_callback;
170  CallbackHook<void(NetEvent::event, Net*, u32)> m_net_callback;
171  CallbackHook<void(GroupingEvent::event, Grouping*, u32)> m_grouping_callback;
172  bool netlist_event_enabled;
173  bool module_event_enabled;
174  bool gate_event_enabled;
175  bool net_event_enabled;
176  bool grouping_event_enabled;
177 
178  public:
179  EventHandler();
180 
187  NETLIST_API void event_enable_all(bool flag);
188 
196  NETLIST_API void notify(NetlistEvent::event ev, Netlist* netlist, u32 associated_data = 0xFFFFFFFF);
197 
205  NETLIST_API void notify(ModuleEvent::event ev, Module* module, u32 associated_data = 0xFFFFFFFF);
206 
214  NETLIST_API void notify(GateEvent::event ev, Gate* gate, u32 associated_data = 0xFFFFFFFF);
215 
223  NETLIST_API void notify(NetEvent::event ev, Net* net, u32 associated_data = 0xFFFFFFFF);
224 
232  NETLIST_API void notify(GroupingEvent::event ev, Grouping* grouping, u32 associated_data = 0xFFFFFFFF);
233 
240  NETLIST_API void register_callback(const std::string& name, std::function<void(NetlistEvent::event e, Netlist* netlist, u32 associated_data)> function);
241 
248  NETLIST_API void register_callback(const std::string& name, std::function<void(ModuleEvent::event e, Module* module, u32 associated_data)> function);
249 
256  NETLIST_API void register_callback(const std::string& name, std::function<void(GateEvent::event e, Gate*, u32 associated_data)> function);
257 
264  NETLIST_API void register_callback(const std::string& name, std::function<void(NetEvent::event e, Net*, u32 associated_data)> function);
265 
272  NETLIST_API void register_callback(const std::string& name, std::function<void(GroupingEvent::event e, Grouping* grouping, u32 associated_data)> function);
273 
279  NETLIST_API void unregister_callback(const std::string& name);
280 
281  }; // class event_handler
282 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
void register_callback(const std::string &name, std::function< void(NetlistEvent::event e, Netlist *netlist, u32 associated_data)> function)
void unregister_callback(const std::string &name)
void notify(NetlistEvent::event ev, Netlist *netlist, u32 associated_data=0xFFFFFFFF)
void event_enable_all(bool flag)
@ boolean_function_changed
no associated_data
@ location_changed
no associated_data
@ removed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
Definition: gate.h:58
@ net_assigned
associated_data = id of inserted net
@ module_removed
associated_data = id of removed module
@ color_changed
no associated_data
@ gate_assigned
associated_data = id of inserted gate
@ module_assigned
associated_data = id of inserted module
@ gate_removed
associated_data = id of removed gate
@ removed
no associated_data
@ net_removed
associated_data = id of removed net
@ name_changed
no associated_data
@ created
no associated_data
@ gates_remove_end
associated_data = number of removed gates
@ gate_assigned
associated_data = id of inserted gate
@ gate_removed
associated_data = id of removed gate
@ pin_changed
associated_data = [4LSB: type of action] [28HSB: id of pin group or pin]
@ submodule_removed
associated_data = id of removed module
@ gates_assign_begin
associated_data = number of gates to assign
@ type_changed
no associated_data
@ gates_assign_end
associated_data = number of assigned gates
@ gates_remove_begin
associated_data = number of gates to remove
@ submodule_added
associated_data = id of added module
@ removed
no associated_data
@ parent_changed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
@ src_added
associated_data = id of src gate
@ dst_removed
associated_data = id of dst gate
@ src_removed
associated_data = id of src gate
@ dst_added
associated_data = id of dst gate
@ removed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
Definition: net.h:58
@ marked_global_gnd
associated_data = id of gate
@ unmarked_global_output
associated_data = id of net
@ id_changed
associated_data = old id
@ device_name_changed
no associated_data
@ unmarked_global_gnd
associated_data = id of gate
@ input_filename_changed
no associated_data
@ unmarked_global_vcc
associated_data = id of gate
@ marked_global_vcc
associated_data = id of gate
@ unmarked_global_input
associated_data = id of net
@ design_name_changed
no associated_data
@ marked_global_output
associated_data = id of net
@ marked_global_input
associated_data = id of net
uint32_t u32
Definition: defines.h:41
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
Net * net
std::string name