comparison trunk/src/Support/Module.cc @ 401:b71ec2cbe55b

- Module tree
author tomwalters
date Sun, 17 Oct 2010 02:42:12 +0000
parents 7a573750b186
children 69466da9745e
comparison
equal deleted inserted replaced
400:dd13c9834ceb 401:b71ec2cbe55b
42 }; 42 };
43 43
44 Module::~Module() { 44 Module::~Module() {
45 }; 45 };
46 46
47 bool Module::Initialize(const SignalBank &input) { 47 bool Module::Initialize(const SignalBank &input,
48 // LOG_INFO_NN(_T("-> %s "), module_identifier_.c_str()); 48 Parameters *global_parameters) {
49 global_parameters_ = global_parameters;
49 // Validate the input 50 // Validate the input
50 if (!input.Validate()) { 51 if (!input.Validate()) {
51 LOG_ERROR(_T("Input SignalBank not valid")); 52 LOG_ERROR(_T("Input SignalBank not valid"));
52 return false; 53 return false;
53 } 54 }
55 LOG_ERROR(_T("Initialization failed in module %s"), 56 LOG_ERROR(_T("Initialization failed in module %s"),
56 module_identifier_.c_str()); 57 module_identifier_.c_str());
57 return false; 58 return false;
58 } 59 }
59 // If the module has an output bank, then we can set up the targets 60 // If the module has an output bank, then we can set up the targets
60 // of this module.. 61 // of this module.
61 if (output_.initialized()) { 62 if (output_.initialized()) {
62 // Check that the output SignalBank has been set up correctly 63 // Check that the output SignalBank has been set up correctly
63 if (!output_.Validate()) { 64 if (!output_.Validate()) {
64 LOG_ERROR(_T("Output SignalBank not valid in module %s"), 65 LOG_ERROR(_T("Output SignalBank not valid in module %s"),
65 module_identifier_.c_str()); 66 module_identifier_.c_str());
71 // set up to accept an input SignalBank of the correct form, but 72 // set up to accept an input SignalBank of the correct form, but
72 // this is not checked. 73 // this is not checked.
73 set<Module*>::const_iterator it; 74 set<Module*>::const_iterator it;
74 for (it = targets_.begin(); it != targets_.end(); ++it) { 75 for (it = targets_.begin(); it != targets_.end(); ++it) {
75 if (!(*it)->initialized()) 76 if (!(*it)->initialized())
76 if (!(*it)->Initialize(output_)) 77 if (!(*it)->Initialize(output_, global_parameters_))
77 return false; 78 return false;
78 } 79 }
79 } else {
80 // LOG_INFO(_T("|"));
81 } 80 }
82 initialized_ = true; 81 initialized_ = true;
83 return true; 82 return true;
84 } 83 }
85 84
99 bool Module::initialized() const { 98 bool Module::initialized() const {
100 return initialized_; 99 return initialized_;
101 } 100 }
102 101
103 bool Module::AddTarget(Module* target_module) { 102 bool Module::AddTarget(Module* target_module) {
103 bool result = false;
104 if (target_module) { 104 if (target_module) {
105 pair<set<Module*>::iterator, bool> ret; 105 pair<set<Module*>::iterator, bool> ret;
106 ret = targets_.insert(target_module); 106 ret = targets_.insert(target_module);
107 return ret.second; 107 result = ret.second;
108 if (result) {
109 if(initialized_) {
110 if(output_.initialized()) {
111 if (!target_module->initialized()) {
112 target_module->Initialize(output_, global_parameters_);
113 }
114 }
115 }
116 }
108 } 117 }
109 return false; 118 return result;
110 } 119 }
111 120
112 bool Module::RemoveTarget(Module* target_module) { 121 bool Module::RemoveTarget(Module* target_module) {
113 if (targets_.erase(target_module) != 0) 122 if (targets_.erase(target_module) != 0)
114 return true; 123 return true;