InstanceSystem.cpp
Go to the documentation of this file.
1 #include "InstanceSystem.hpp"
2 #include "Instance.hpp"
3 #include "instance_ptr.hpp"
4 #include <iostream>
5 #include <cstring>
6 #include "../DebugView/TextDebugView.hpp"
7 #include "../DebugView/TreeDebugView.hpp"
9 
10 namespace iv
11 {
12 
14  System( sc ),
15  last_check_frame_id( 0 )
16 {
17 }
18 
20 {
21  unsigned frame_id = this->system_container()->frame_id();
22  if( this->last_check_frame_id != frame_id )
23  {
24  this->last_check_frame_id = frame_id;
25 
26  this->log( SRC_INFO, iv::Defs::Log::ConsistencyChecks_Frame, "ConsistencyChecks_Frame." );
28  {
29  for( Instance * instance : this->_instances )
30  {
31  //
32  if( !instance->Debug_RootClient() )
33  this->log( SRC_INFO, iv::Defs::Log::ConsistencyChecks_Frame, "Instance without root ClientMarker '",instance->instance_name(),"' found. It did not have Instance::instance_finalize called on itself." );
34 
35  //
36  for( ClientMarker const * client : instance->Debug_Clients() )
37  {
38  bool has_parent = client == instance->Debug_RootClient() || client->inheritance_child() || client->ownership_parent();
39  if( !has_parent )
40  this->log( SRC_INFO, iv::Defs::Log::ConsistencyChecks_Frame, "Orphaned ClientMarker ", client, " found. Instance root is ",instance->Debug_RootClient(),"." );
41  }
42  }
43  }
44  }
45 
46  return false;
47 }
48 
49 void InstanceSystem::DebugPrintInstance( TreeDebugView * tree, Instance * inst )
50 {
51  SS title;
52  title << inst;
53  if( inst->instance_name().size() )
54  title << " \"" << inst->instance_name() << "\"";
55  tree->Push( title<<SS::c_str() );
56 
57  inst->debug_print_clients( tree );
58 
59  for( Instance * child : inst->Debug_Children() )
60  {
61  if( child->getSystem< InstanceSystem >() == inst->getSystem< InstanceSystem >() )
62  this->DebugPrintInstance( tree, child );
63  else
64  tree->out() << "-> instance in different InstanceSystem" << std::endl;
65  }
66 
67  tree->Pop();
68 }
69 
71 {
72  TreeDebugView tree( view->context() );
73  std::unordered_set< Instance * > visited;
74  for( Instance * inst : this->Debug_Instances() )
75  if( !inst->Debug_Parent() )
76  this->DebugPrintInstance( &tree, inst );
78 }
79 
80 std::unordered_set< Instance * > const & InstanceSystem::Debug_Instances()
81 {
82  return this->_instances;
83 }
84 
86 {
87  return this->_debug_listeners;
88 }
89 
91 {
92  this->_instances.insert( inst );
93 }
94 
96 {
97  this->_instances.erase( inst );
98 }
99 
101 {
102  this->_debug_listeners.insert( listener );
103 }
104 
106 {
107  this->_debug_listeners.erase( listener );
108 }
109 
110 void InstanceSystem::ClientLog( ClientMarker const * cm, SrcInfo const & info, LogId id, std::string const & message )
111 {
112  this->_debug_listeners.foreach(
113  [ & ]( DebugInstanceListener * const & listener )
114  {
115  listener->ClientLog( cm, info, id, message );
116  }
117  );
118 }
119 
121 {
122  bool enabled = false;
123 
124  this->_debug_listeners.foreach(
125  [ & ]( DebugInstanceListener * const & listener )
126  {
127  enabled = enabled || listener->ClientLogEnabled( cm, id );
128  }
129  );
130 
131  return enabled;
132 }
133 
134 void InstanceSystem::SystemLog( System const * system, SrcInfo const & info, LogId id, std::string const & message )
135 {
136  this->_debug_listeners.foreach(
137  [ & ]( DebugInstanceListener * const & listener )
138  {
139  listener->SystemLog( system, info, id, message );
140  }
141  );
142 }
143 
145 {
146  bool enabled = false;
147 
148  this->_debug_listeners.foreach(
149  [ & ]( DebugInstanceListener * const & listener )
150  {
151  enabled = enabled || listener->SystemLogEnabled( system, id );
152  }
153  );
154 
155  return enabled;
156 }
157 
158 
159 }