SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModuleInterface.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 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 /// @todo Documentation Dataflow/Network/ModuleInterface.h
29 
30 #ifndef DATAFLOW_NETWORK_MODULE_INTERFACE_H
31 #define DATAFLOW_NETWORK_MODULE_INTERFACE_H
32 
37 #include <Core/Logging/LoggerFwd.h>
38 #include <Dataflow/Network/share.h>
39 
40 namespace SCIRun {
41 namespace Dataflow {
42 namespace Networks {
43 
45  {
46  public:
47  virtual ~ModuleInfoProvider() {}
48 
49  /// @todo: kind of ridiculous interface/duplication. Should pull out a subinterface for "PortView" and just return one of those for input/output
50  virtual bool hasOutputPort(const PortId& id) const = 0;
51  virtual OutputPortHandle getOutputPort(const PortId& id) const = 0;
52  virtual std::vector<OutputPortHandle> findOutputPortsWithName(const std::string& name) const = 0;
53  virtual size_t num_output_ports() const = 0;
54  virtual std::vector<OutputPortHandle> outputPorts() const = 0;
55 
56  virtual bool hasInputPort(const PortId& id) const = 0;
57  virtual InputPortHandle getInputPort(const PortId& id) const = 0;
58  virtual std::vector<InputPortHandle> findInputPortsWithName(const std::string& name) const = 0;
59  virtual size_t num_input_ports() const = 0;
60  virtual std::vector<InputPortHandle> inputPorts() const = 0;
61 
62  virtual std::string get_module_name() const = 0;
63  virtual ModuleId get_id() const = 0;
64  virtual bool has_ui() const = 0;
65  virtual const ModuleLookupInfo& get_info() const = 0;
66  virtual bool hasDynamicPorts() const = 0;
67  };
68 
70  {
71  public:
73  virtual void setUiVisible(bool visible) = 0;
74  };
75 
76  SCISHARE std::string to_string(const ModuleInfoProvider&);
77 
78  typedef boost::function<void(bool)> UiToggleFunc;
79 
80  /// @todo: interface is getting bloated, segregate it.
82  {
83  public:
84  virtual ~ModuleInterface();
85 
86  virtual ModuleStateHandle get_state() = 0;
87 
88  virtual void do_execute() = 0;
89 
91  {
94  Completed
95  };
96 
97  virtual ExecutionState executionState() const = 0;
98  virtual void setExecutionState(ExecutionState state) = 0;
99 
100  /// @todo for deserialization
101  virtual void set_id(const std::string& id) = 0;
102  virtual void set_state(ModuleStateHandle state) = 0;
103 
104  virtual SCIRun::Core::Datatypes::DatatypeHandleOption get_input_handle(const PortId& id) = 0;
105  virtual std::vector<SCIRun::Core::Datatypes::DatatypeHandleOption> get_dynamic_input_handles(const PortId& id) = 0;
106  virtual void send_output_handle(const PortId& id, SCIRun::Core::Datatypes::DatatypeHandle data) = 0;
107 
108  virtual void setLogger(SCIRun::Core::Logging::LoggerHandle log) = 0;
109  virtual SCIRun::Core::Logging::LoggerHandle getLogger() const = 0;
110 
111  /// @todo functions
112  virtual SCIRun::Core::Algorithms::AlgorithmStatusReporter::UpdaterFunc getUpdaterFunc() const = 0;
113  virtual void setUpdaterFunc(SCIRun::Core::Algorithms::AlgorithmStatusReporter::UpdaterFunc func) = 0;
114  virtual void setUiToggleFunc(UiToggleFunc func) = 0;
115 
116  /// @todo: name too clunky.
117  /// Called before the module is to be destroyed. More importantly, called
118  /// before the UI widget is to be destroyed.
119  virtual void preDestruction() {}
120 
121  /// @todo:
122  // need to hook up input ports for new data coming in, and output ports for cached state.
123  virtual bool needToExecute() const = 0;
124 
125  virtual void setStateDefaults() = 0;
126 
127  virtual Core::Algorithms::AlgorithmHandle getAlgorithm() const = 0;
128 
129  virtual void portAddedSlot(const Networks::ModuleId& mid, const Networks::PortId& pid) {}
130  virtual void portRemovedSlot(const Networks::ModuleId& mid, const Networks::PortId& pid) {}
131  virtual void addPortConnection(const boost::signals2::connection& con) = 0;
132  };
133 
140 
141  #define MODULE_ERROR_WITH_TYPE(type, message) { error(message); BOOST_THROW_EXCEPTION(type() << SCIRun::Core::ErrorMessage(message)); }
142 }}}
143 
144 #endif
ExecutionState
Definition: ModuleInterface.h:90
boost::optional< DatatypeHandle > DatatypeHandleOption
Definition: DatatypeFwd.h:47
boost::shared_ptr< LegacyLoggerInterface > LoggerHandle
Definition: LoggerFwd.h:42
virtual void preDestruction()
Definition: ModuleInterface.h:119
Definition: ModuleInterface.h:44
Definition: ModuleDescription.h:99
Definition: ModuleInterface.h:134
Definition: ModuleInterface.h:81
boost::function< void(double)> UpdaterFunc
Definition: AlgorithmBase.h:155
boost::shared_ptr< ModuleStateInterface > ModuleStateHandle
Definition: NetworkFwd.h:75
#define SCISHARE
Definition: share.h:39
boost::shared_ptr< OutputPortInterface > OutputPortHandle
Definition: NetworkFwd.h:80
Definition: ModuleInterface.h:138
boost::shared_ptr< InputPortInterface > InputPortHandle
Definition: NetworkFwd.h:79
SCISHARE std::string to_string(const ModuleInfoProvider &)
Definition: Module.cc:48
virtual void portAddedSlot(const Networks::ModuleId &mid, const Networks::PortId &pid)
Definition: ModuleInterface.h:129
Definition: ExecutableObject.h:45
Definition: Exception.h:46
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: ModuleDescription.h:77
dictionary data
Definition: eabLatVolData.py:11
virtual void portRemovedSlot(const Networks::ModuleId &mid, const Networks::PortId &pid)
Definition: ModuleInterface.h:130
virtual ~ModuleInfoProvider()
Definition: ModuleInterface.h:47
virtual ~ModuleDisplayInterface()
Definition: ModuleInterface.h:72
boost::shared_ptr< AlgorithmBase > AlgorithmHandle
Definition: AlgorithmFwd.h:39
boost::function< void(bool)> UiToggleFunc
Definition: ModuleInterface.h:78
Definition: ModuleDescription.h:45
boost::shared_ptr< Datatype > DatatypeHandle
Definition: DatatypeFwd.h:44