Skip to content

Commit 7444ed2

Browse files
committed
Closes #1597
1 parent 15b79ee commit 7444ed2

17 files changed

+135
-85
lines changed

src/Dataflow/Network/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ SET(Dataflow_Network_HEADERS
7171
NetworkSettings.h
7272
NullModuleState.h
7373
Port.h
74+
PortNames.h
7475
PortInterface.h
7576
PortManager.h
7677
share.h

src/Dataflow/Network/Module.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ size_t Module::num_output_ports() const
339339
//TODO requirements for state metadata reporting
340340
std::string Module::stateMetaInfo() const
341341
{
342-
if (!get_state())
342+
if (!cstate())
343343
return "Null state map.";
344-
auto keys = get_state()->getKeys();
344+
auto keys = cstate()->getKeys();
345345
size_t i = 0;
346346
std::ostringstream ostr;
347347
ostr << "\n\t{";
348348
for (const auto& key : keys)
349349
{
350-
ostr << "[" << key.name() << ", " << get_state()->getValue(key).value() << "]";
350+
ostr << "[" << key.name() << ", " << cstate()->getValue(key).value() << "]";
351351
i++;
352352
if (i < keys.size())
353353
ostr << ",\n\t";
@@ -481,7 +481,7 @@ ModuleStateHandle Module::get_state()
481481
return impl_->state_;
482482
}
483483

484-
const ModuleStateHandle Module::get_state() const
484+
const ModuleStateHandle Module::cstate() const
485485
{
486486
return impl_->state_;
487487
}
@@ -842,6 +842,8 @@ ModuleExecutionState& Module::executionState()
842842
return *impl_->executionState_;
843843
}
844844

845+
/// @todo:
846+
// need to hook up output ports for cached state.
845847
bool Module::needToExecute() const
846848
{
847849
static Mutex needToExecuteLock("needToExecute");
@@ -1053,7 +1055,7 @@ std::string ModuleLevelUniqueIDGenerator::generateModuleLevelUniqueID(const Modu
10531055
}
10541056

10551057
toHash << "}__State{";
1056-
auto state = module.get_state();
1058+
auto state = module.cstate();
10571059
for (const auto& key : state->getKeys())
10581060
{
10591061
toHash << key << "->" << state->getValue(key).value() << "_";

src/Dataflow/Network/Module.h

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,50 +46,13 @@
4646
#include <Dataflow/Network/ModuleDescription.h>
4747
#include <Dataflow/Network/PortManager.h>
4848
#include <Dataflow/Network/DefaultModuleFactories.h>
49+
#include <Dataflow/Network/PortNames.h>
4950
#include <Dataflow/Network/share.h>
5051

5152
namespace SCIRun {
5253
namespace Dataflow {
5354
namespace Networks {
5455

55-
56-
template <class Type, size_t N>
57-
struct PortNameBase
58-
{
59-
explicit PortNameBase(const PortId& id) : id_(id) {}
60-
61-
operator PortId() const
62-
{
63-
return toId();
64-
}
65-
66-
PortId toId() const
67-
{
68-
if (id_.name.empty())
69-
BOOST_THROW_EXCEPTION(DataPortException() << SCIRun::Core::ErrorMessage("Port name not initialized!"));
70-
return id_;
71-
}
72-
operator std::string() const
73-
{
74-
return toId().name;
75-
}
76-
77-
PortId id_;
78-
};
79-
80-
template <class Type, size_t N>
81-
struct StaticPortName : PortNameBase<Type,N>
82-
{
83-
explicit StaticPortName(const PortId& id = PortId(0, "[not defined yet]")) : PortNameBase<Type,N>(id) {}
84-
};
85-
86-
template <class Type, size_t N>
87-
struct DynamicPortName : PortNameBase<Type,N>
88-
{
89-
explicit DynamicPortName(const PortId& id = PortId(0, "[not defined yet]")) : PortNameBase<Type,N>(id) {}
90-
};
91-
92-
9356
class SCISHARE Module : public ModuleInterface,
9457
public Core::Logging::LegacyLoggerInterface,
9558
public StateChangeObserver,
@@ -105,7 +68,7 @@ namespace Networks {
10568

10669
/*** User-interface ****/
10770
ModuleStateHandle get_state() override final;
108-
const ModuleStateHandle get_state() const override final;
71+
const ModuleStateHandle cstate() const override final;
10972
void enqueueExecuteAgain(bool upstream) override final;
11073
void error(const std::string& msg) const override final;
11174
void warning(const std::string& msg) const override final { getLogger()->warning(msg); }

src/Dataflow/Network/ModuleInterface.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,64 +46,64 @@ namespace SCIRun {
4646
namespace Dataflow {
4747
namespace Networks {
4848

49-
/// @todo: interface is getting bloated, segregate it.
50-
class SCISHARE ModuleInterface : public ModuleInfoProvider, public ModuleDisplayInterface,
51-
public ExecutableObject, public Core::Algorithms::AlgorithmCollaborator
49+
// Methods a module writer needs to know/use/override
50+
class SCISHARE ModuleUserInterface
5251
{
5352
public:
54-
virtual ~ModuleInterface();
55-
56-
virtual ModuleStateHandle get_state() = 0;
57-
virtual const ModuleStateHandle get_state() const = 0;
53+
virtual ~ModuleUserInterface() {}
5854

55+
// These two functions must be implemented:
5956
virtual void execute() = 0;
57+
virtual void setStateDefaults() = 0;
58+
59+
// These two functions must be understood and used correctly:
60+
virtual ModuleStateHandle get_state() = 0;
61+
virtual bool needToExecute() const = 0;
62+
};
6063

64+
// Methods for internal developer use/testing
65+
class SCISHARE ModuleInternalsInterface
66+
{
67+
public:
68+
virtual ~ModuleInternalsInterface() {}
69+
virtual const ModuleStateHandle cstate() const = 0;
6170
typedef boost::signals2::signal<void(bool)> ExecutionSelfRequestSignalType;
6271
virtual boost::signals2::connection connectExecuteSelfRequest(const ExecutionSelfRequestSignalType::slot_type& subscriber) = 0;
63-
6472
virtual ModuleExecutionState& executionState() = 0;
65-
6673
/// @todo for deserialization
6774
virtual void set_id(const std::string& id) = 0;
6875
virtual void set_state(ModuleStateHandle state) = 0;
69-
7076
virtual SCIRun::Core::Datatypes::DatatypeHandleOption get_input_handle(const PortId& id) = 0;
7177
virtual std::vector<SCIRun::Core::Datatypes::DatatypeHandleOption> get_dynamic_input_handles(const PortId& id) = 0;
7278
virtual void send_output_handle(const PortId& id, SCIRun::Core::Datatypes::DatatypeHandle data) = 0;
73-
7479
virtual void setLogger(SCIRun::Core::Logging::LoggerHandle log) = 0;
75-
virtual SCIRun::Core::Logging::LoggerHandle getLogger() const override = 0;
76-
77-
/// @todo functions
78-
virtual SCIRun::Core::Algorithms::AlgorithmStatusReporter::UpdaterFunc getUpdaterFunc() const override = 0;
7980
virtual void setUpdaterFunc(SCIRun::Core::Algorithms::AlgorithmStatusReporter::UpdaterFunc func) = 0;
8081
virtual void setUiToggleFunc(UiToggleFunc func) = 0;
81-
82-
/// @todo:
83-
// need to hook up output ports for cached state.
84-
virtual bool needToExecute() const = 0;
85-
8682
virtual ModuleReexecutionStrategyHandle getReexecutionStrategy() const = 0;
8783
virtual void setReexecutionStrategy(ModuleReexecutionStrategyHandle caching) = 0;
88-
89-
virtual void setStateDefaults() = 0;
90-
9184
virtual Core::Algorithms::AlgorithmHandle getAlgorithm() const = 0;
92-
9385
virtual void portAddedSlot(const Networks::ModuleId& mid, const Networks::PortId& pid) {}
9486
virtual void portRemovedSlot(const Networks::ModuleId& mid, const Networks::PortId& pid) {}
9587
virtual void addPortConnection(const boost::signals2::connection& con) = 0;
96-
9788
virtual void enqueueExecuteAgain(bool upstream) = 0;
98-
9989
virtual const MetadataMap& metadata() const = 0;
100-
10190
virtual bool isStoppable() const = 0;
102-
10391
virtual bool executionDisabled() const = 0;
10492
virtual void setExecutionDisabled(bool disable) = 0;
10593
};
10694

95+
class SCISHARE ModuleInterface :
96+
public ModuleUserInterface,
97+
public ModuleInternalsInterface,
98+
public ModuleInfoProvider,
99+
public ModuleDisplayInterface,
100+
public ExecutableObject,
101+
public Core::Algorithms::AlgorithmCollaborator
102+
{
103+
public:
104+
virtual ~ModuleInterface();
105+
};
106+
107107
}}}
108108

109109
#endif

src/Dataflow/Network/PortNames.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
License for the specific language governing rights and limitations under
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#ifndef DATAFLOW_NETWORK_PORTNAMES_H
30+
#define DATAFLOW_NETWORK_PORTNAMES_H
31+
32+
#include <boost/noncopyable.hpp>
33+
#include <boost/static_assert.hpp>
34+
#include <Dataflow/Network/NetworkFwd.h>
35+
#include <Dataflow/Network/ModuleInterface.h>
36+
#include <Dataflow/Network/ModuleStateInterface.h>
37+
#include <Dataflow/Network/ModuleDescription.h>
38+
#include <Dataflow/Network/PortManager.h>
39+
#include <Dataflow/Network/share.h>
40+
41+
namespace SCIRun {
42+
namespace Dataflow {
43+
namespace Networks {
44+
45+
template <class Type, size_t N>
46+
struct PortNameBase
47+
{
48+
explicit PortNameBase(const PortId& id) : id_(id) {}
49+
50+
operator PortId() const
51+
{
52+
return toId();
53+
}
54+
55+
PortId toId() const
56+
{
57+
if (id_.name.empty())
58+
BOOST_THROW_EXCEPTION(DataPortException() << SCIRun::Core::ErrorMessage("Port name not initialized!"));
59+
return id_;
60+
}
61+
operator std::string() const
62+
{
63+
return toId().name;
64+
}
65+
66+
PortId id_;
67+
};
68+
69+
template <class Type, size_t N>
70+
struct StaticPortName : PortNameBase<Type,N>
71+
{
72+
explicit StaticPortName(const PortId& id = PortId(0, "[not defined yet]")) : PortNameBase<Type,N>(id) {}
73+
};
74+
75+
template <class Type, size_t N>
76+
struct DynamicPortName : PortNameBase<Type,N>
77+
{
78+
explicit DynamicPortName(const PortId& id = PortId(0, "[not defined yet]")) : PortNameBase<Type,N>(id) {}
79+
};
80+
81+
}}}
82+
83+
#endif

src/Dataflow/Network/Tests/MockModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace SCIRun {
4747
MOCK_METHOD0(execute, void());
4848
MOCK_METHOD0(executeWithSignals, bool());
4949
MOCK_METHOD0(get_state, ModuleStateHandle());
50-
MOCK_CONST_METHOD0(get_state, const ModuleStateHandle());
50+
MOCK_CONST_METHOD0(cstate, const ModuleStateHandle());
5151
MOCK_METHOD1(set_state, void(ModuleStateHandle));
5252
MOCK_METHOD2(send_output_handle, void(const PortId&, SCIRun::Core::Datatypes::DatatypeHandle));
5353
MOCK_METHOD1(get_input_handle, SCIRun::Core::Datatypes::DatatypeHandleOption(const PortId&));

src/Modules/DataIO/ReadMatrixClassic.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ReadMatrix::execute()
8383

8484
bool ReadMatrix::useCustomImporter(const std::string& filename) const
8585
{
86-
auto filetypename = get_state()->getValue(Variables::FileTypeName).toString();
86+
auto filetypename = cstate()->getValue(Variables::FileTypeName).toString();
8787
return !(filetypename.empty() || filetypename == "SCIRun Matrix File" || filetypename == "SCIRun Matrix File (*.mat)");
8888
}
8989

src/Modules/DataIO/WriteField.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void WriteField::execute()
117117

118118
bool WriteField::useCustomExporter(const std::string& filename) const
119119
{
120-
auto ft = get_state()->getValue(Variables::FileTypeName).toString();
120+
auto ft = cstate()->getValue(Variables::FileTypeName).toString();
121121
LOG_DEBUG("WriteField with filetype " << ft);
122122
auto ret = boost::filesystem::extension(filename) != ".fld";
123123

src/Modules/DataIO/WriteMatrix.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void WriteMatrix::execute()
104104

105105
bool WriteMatrix::useCustomExporter(const std::string& filename) const
106106
{
107-
auto ft = get_state()->getValue(Variables::FileTypeName).toString();
107+
auto ft = cstate()->getValue(Variables::FileTypeName).toString();
108108
LOG_DEBUG("WriteMatrix with filetype " << ft);
109109

110110
filetype_ = (ft == "SCIRun Matrix ASCII") ? "ASCII" : "Binary";

src/Modules/Legacy/Fields/ConvertFieldBasis.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ConvertFieldBasis::execute()
9595
}
9696
}
9797

98-
void ConvertFieldBasis::pushInputFieldInfo(FieldHandle input) const
98+
void ConvertFieldBasis::pushInputFieldInfo(FieldHandle input)
9999
{
100100
auto state = get_state();
101101
std::string name = input->properties().get_name();

0 commit comments

Comments
 (0)