Skip to content

Commit 15b79ee

Browse files
committed
Module.h
1 parent f72c5ac commit 15b79ee

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

src/Dataflow/Network/Module.cc

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,15 @@ namespace SCIRun
148148
private:
149149
Module* module_;
150150
public:
151-
ModuleImpl(Module* module, bool hasUi, ModuleStateFactoryHandle stateFactory)
151+
ModuleImpl(Module* module,
152+
const ModuleLookupInfo& info,
153+
bool hasUi,
154+
ModuleStateFactoryHandle stateFactory)
152155
: module_(module),
156+
info_(info),
157+
id_(info.module_name_, DefaultModuleFactories::idGenerator_->makeId(info.module_name_)),
153158
has_ui_(hasUi),
154-
state_(stateFactory ? stateFactory->make_state(module->info_.module_name_) : new NullModuleState),
159+
state_(stateFactory ? stateFactory->make_state(info_.module_name_) : new NullModuleState),
155160
metadata_(state_),
156161
executionState_(boost::make_shared<detail::ModuleExecutionStateImpl>())
157162
{
@@ -161,6 +166,8 @@ namespace SCIRun
161166

162167
boost::atomic<bool> inputsChanged_ { false };
163168

169+
const ModuleLookupInfo info_;
170+
ModuleId id_;
164171
bool has_ui_;
165172
AlgorithmHandle algo_;
166173

@@ -200,25 +207,22 @@ Module::Module(const ModuleLookupInfo& info,
200207
bool hasUi,
201208
AlgorithmFactoryHandle algoFactory,
202209
ModuleStateFactoryHandle stateFactory,
203-
ReexecuteStrategyFactoryHandle reexFactory,
204-
const std::string& version)
205-
: info_(info),
206-
id_(info.module_name_, DefaultModuleFactories::idGenerator_->makeId(info.module_name_))
210+
ReexecuteStrategyFactoryHandle reexFactory)
207211
{
208-
impl_ = boost::make_shared<ModuleImpl>(this, hasUi, stateFactory);
212+
impl_ = boost::make_shared<ModuleImpl>(this, info, hasUi, stateFactory);
209213

210214
setLogger(DefaultModuleFactories::defaultLogger_);
211215
setUpdaterFunc([](double x) {});
212216

213217
auto& log = Log::get();
214218

215-
log << DEBUG_LOG << "Module created: " << info_.module_name_ << " with id: " << id_;
219+
log << DEBUG_LOG << "Module created: " << info.module_name_ << " with id: " << impl_->id_;
216220

217221
if (algoFactory)
218222
{
219223
impl_->algo_ = algoFactory->create(get_module_name(), this);
220224
if (impl_->algo_)
221-
log << DEBUG_LOG << "Module algorithm initialized: " << info_.module_name_;
225+
log << DEBUG_LOG << "Module algorithm initialized: " << info.module_name_;
222226
}
223227
log.flush();
224228

@@ -235,7 +239,7 @@ void Module::set_id(const std::string& id)
235239
ModuleId newId(id);
236240
if (!DefaultModuleFactories::idGenerator_->takeId(newId.name_, newId.idNumber_))
237241
THROW_INVALID_ARGUMENT("Duplicate module IDs, invalid network file.");
238-
id_ = newId;
242+
impl_->id_ = newId;
239243
}
240244

241245
Module::~Module()
@@ -251,6 +255,31 @@ bool Module::has_ui() const
251255
return impl_->has_ui_;
252256
}
253257

258+
const ModuleLookupInfo& Module::get_info() const
259+
{
260+
return impl_->info_;
261+
}
262+
263+
std::string Module::get_module_name() const
264+
{
265+
return get_info().module_name_;
266+
}
267+
268+
std::string Module::get_categoryname() const
269+
{
270+
return get_info().category_name_;
271+
}
272+
273+
std::string Module::get_packagename() const
274+
{
275+
return get_info().package_name_;
276+
}
277+
278+
ModuleId Module::get_id() const
279+
{
280+
return impl_->id_;
281+
}
282+
254283
bool Module::executionDisabled() const
255284
{
256285
return impl_->executionDisabled_;
@@ -263,7 +292,7 @@ void Module::setExecutionDisabled(bool disable)
263292

264293
void Module::error(const std::string& msg) const
265294
{
266-
impl_->errorSignal_(id_);
295+
impl_->errorSignal_(get_id());
267296
getLogger()->error(msg);
268297
}
269298

@@ -334,7 +363,7 @@ void Module::copyStateToMetadata()
334363

335364
bool Module::executeWithSignals() NOEXCEPT
336365
{
337-
auto starting = "STARTING MODULE: " + id_.id_;
366+
auto starting = "STARTING MODULE: " + get_id().id_;
338367
#ifdef BUILD_HEADLESS //TODO: better headless logging
339368
static Mutex executeLogLock("headlessExecution");
340369
if (!Log::get().verbose())
@@ -343,7 +372,7 @@ bool Module::executeWithSignals() NOEXCEPT
343372
std::cout << starting << std::endl;
344373
}
345374
#endif
346-
impl_->executeBegins_(id_);
375+
impl_->executeBegins_(get_id());
347376
boost::timer executionTimer;
348377
{
349378
auto isoString = boost::posix_time::to_simple_string(boost::posix_time::microsec_clock::universal_time());
@@ -420,7 +449,8 @@ bool Module::executeWithSignals() NOEXCEPT
420449
}
421450

422451
std::ostringstream finished;
423-
finished << "MODULE " << id_.id_ << " FINISHED " << (returnCode ? "successfully " : "with errors ") << "in " << executionTime << " seconds.";
452+
finished << "MODULE " << get_id().id_ << " FINISHED " <<
453+
(returnCode ? "successfully " : "with errors ") << "in " << executionTime << " seconds.";
424454
status(finished.str());
425455
#ifdef BUILD_HEADLESS //TODO: better headless logging
426456
if (!Log::get().verbose())
@@ -442,7 +472,7 @@ bool Module::executeWithSignals() NOEXCEPT
442472
impl_->inputsChanged_ = false;
443473
}
444474

445-
impl_->executeEnds_(executionTime, id_);
475+
impl_->executeEnds_(executionTime, get_id());
446476
return returnCode;
447477
}
448478

@@ -550,7 +580,7 @@ std::vector<DatatypeHandleOption> Module::get_dynamic_input_handles(const PortId
550580
// NOTE: don't use short-circuited boolean OR here, we need to call hasChanged each time since it updates the port's cache flag.
551581
bool startingVal = impl_->inputsChanged_;
552582
impl_->inputsChanged_ = std::accumulate(portsWithName.begin(), portsWithName.end(), startingVal, [](bool acc, InputPortHandle input) { return input->hasChanged() || acc; });
553-
LOG_DEBUG(id_ << ":: inputsChanged is now " << inputsChanged_);
583+
LOG_DEBUG(get_id() << ":: inputsChanged is now " << inputsChanged_);
554584
}
555585

556586
std::vector<DatatypeHandleOption> options;

src/Dataflow/Network/Module.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ namespace Networks {
100100
bool hasUi = true,
101101
Core::Algorithms::AlgorithmFactoryHandle algoFactory = DefaultModuleFactories::defaultAlgoFactory_,
102102
ModuleStateFactoryHandle stateFactory = DefaultModuleFactories::defaultStateFactory_,
103-
ReexecuteStrategyFactoryHandle reexFactory = DefaultModuleFactories::defaultReexFactory_,
104-
const std::string& version = "1.0");
103+
ReexecuteStrategyFactoryHandle reexFactory = DefaultModuleFactories::defaultReexFactory_);
105104
virtual ~Module() override;
106105

107106
/*** User-interface ****/
@@ -125,7 +124,7 @@ namespace Networks {
125124
virtual std::string helpPageUrl() const override;
126125
std::string newHelpPageUrl() const; // location in flux, but new v5 modules only have one of these
127126
//for serialization
128-
const ModuleLookupInfo& get_info() const override final { return info_; }
127+
const ModuleLookupInfo& get_info() const override final;
129128
void set_id(const std::string& id) override final;
130129
bool executeWithSignals() NOEXCEPT override final;
131130
bool has_ui() const override;
@@ -147,10 +146,10 @@ namespace Networks {
147146
bool isStoppable() const override final;
148147
bool oport_connected(const PortId& id) const;
149148
bool inputsChanged() const;
150-
std::string get_module_name() const override final { return info_.module_name_; }
151-
std::string get_categoryname() const { return info_.category_name_; }
152-
std::string get_packagename() const { return info_.package_name_; }
153-
ModuleId get_id() const override { return id_; }
149+
std::string get_module_name() const override final;
150+
std::string get_categoryname() const;
151+
std::string get_packagename() const;
152+
ModuleId get_id() const override;
154153
ModuleReexecutionStrategyHandle getReexecutionStrategy() const override final;
155154
void setReexecutionStrategy(ModuleReexecutionStrategyHandle caching) override final;
156155
Core::Algorithms::AlgorithmStatusReporter::UpdaterFunc getUpdaterFunc() const override final;
@@ -223,8 +222,6 @@ namespace Networks {
223222
template <class T>
224223
boost::shared_ptr<T> checkInput(Core::Datatypes::DatatypeHandleOption inputOpt, const PortId& id);
225224

226-
const ModuleLookupInfo info_;
227-
ModuleId id_;
228225
friend class ModuleImpl;
229226
boost::shared_ptr<class ModuleImpl> impl_;
230227
};

0 commit comments

Comments
 (0)