HAL
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 
43  {
44  public:
45  enum class event
46  {
47  id_changed,
59  };
60  };
61 
62  template<>
63  std::map<NetlistEvent::event, std::string> EnumStrings<NetlistEvent::event>::data;
64 
65  class GateEvent
66  {
67  public:
68  enum class event
69  {
70  created,
71  removed,
72  name_changed,
75  };
76  };
77 
78  template<>
79  std::map<GateEvent::event, std::string> EnumStrings<GateEvent::event>::data;
80 
81  class NetEvent
82  {
83  public:
84  enum class event
85  {
86  created,
87  removed,
88  name_changed,
89  src_added,
90  src_removed,
91  dst_added,
93  };
94  };
95 
96  template<>
97  std::map<NetEvent::event, std::string> EnumStrings<NetEvent::event>::data;
98 
100  {
101  public:
102  enum class event
103  {
104  created,
105  removed,
106  name_changed,
107  type_changed,
113  gate_assigned,
116  gate_removed,
117  pin_changed,
118  };
119  };
120 
121  template<>
122  std::map<ModuleEvent::event, std::string> EnumStrings<ModuleEvent::event>::data;
123 
125  {
126  public:
127  enum class event
128  {
129  created,
130  removed,
131  name_changed,
132  color_changed,
133  gate_assigned,
134  gate_removed,
135  net_assigned,
136  net_removed,
139  };
140  };
141 
142  template<>
143  std::map<GroupingEvent::event, std::string> EnumStrings<GroupingEvent::event>::data;
144 
146  {
147  private:
148  CallbackHook<void(NetlistEvent::event, Netlist*, u32)> m_netlist_callback;
149  CallbackHook<void(ModuleEvent::event, Module*, u32)> m_module_callback;
150  CallbackHook<void(GateEvent::event, Gate*, u32)> m_gate_callback;
151  CallbackHook<void(NetEvent::event, Net*, u32)> m_net_callback;
152  CallbackHook<void(GroupingEvent::event, Grouping*, u32)> m_grouping_callback;
153  bool netlist_event_enabled;
154  bool module_event_enabled;
155  bool gate_event_enabled;
156  bool net_event_enabled;
157  bool grouping_event_enabled;
158 
159  public:
160  EventHandler();
161 
168  NETLIST_API void event_enable_all(bool flag);
169 
177  NETLIST_API void notify(NetlistEvent::event ev, Netlist* netlist, u32 associated_data = 0xFFFFFFFF);
178 
186  NETLIST_API void notify(ModuleEvent::event ev, Module* module, u32 associated_data = 0xFFFFFFFF);
187 
195  NETLIST_API void notify(GateEvent::event ev, Gate* gate, u32 associated_data = 0xFFFFFFFF);
196 
204  NETLIST_API void notify(NetEvent::event ev, Net* net, u32 associated_data = 0xFFFFFFFF);
205 
213  NETLIST_API void notify(GroupingEvent::event ev, Grouping* grouping, u32 associated_data = 0xFFFFFFFF);
214 
221  NETLIST_API void register_callback(const std::string& name, std::function<void(NetlistEvent::event e, Netlist* netlist, u32 associated_data)> function);
222 
229  NETLIST_API void register_callback(const std::string& name, std::function<void(ModuleEvent::event e, Module* module, u32 associated_data)> function);
230 
237  NETLIST_API void register_callback(const std::string& name, std::function<void(GateEvent::event e, Gate*, u32 associated_data)> function);
238 
245  NETLIST_API void register_callback(const std::string& name, std::function<void(NetEvent::event e, Net*, u32 associated_data)> function);
246 
253  NETLIST_API void register_callback(const std::string& name, std::function<void(GroupingEvent::event e, Grouping* grouping, u32 associated_data)> function);
254 
260  NETLIST_API void unregister_callback(const std::string& name);
261 
262  }; // class event_handler
263 } // namespace hal
#define NETLIST_API
Definition: arch_linux.h:30
NETLIST_API void register_callback(const std::string &name, std::function< void(NetEvent::event e, Net *, u32 associated_data)> function)
NETLIST_API void unregister_callback(const std::string &name)
NETLIST_API void register_callback(const std::string &name, std::function< void(GateEvent::event e, Gate *, u32 associated_data)> function)
NETLIST_API void notify(NetlistEvent::event ev, Netlist *netlist, u32 associated_data=0xFFFFFFFF)
NETLIST_API void register_callback(const std::string &name, std::function< void(NetlistEvent::event e, Netlist *netlist, u32 associated_data)> function)
NETLIST_API void register_callback(const std::string &name, std::function< void(ModuleEvent::event e, Module *module, u32 associated_data)> function)
NETLIST_API void register_callback(const std::string &name, std::function< void(GroupingEvent::event e, Grouping *grouping, u32 associated_data)> function)
NETLIST_API 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
const Module * module(const Gate *g, const NodeBoxes &boxes)
quint32 u32
Net * net
std::string name