OpenWalnut  1.5.0dev
WModule.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMODULE_H
26 #define WMODULE_H
27 
28 #include <memory>
29 #include <string>
30 #include <typeinfo>
31 #include <vector>
32 
33 #include <boost/filesystem.hpp>
34 #include <boost/function.hpp>
35 #include <boost/signals2/signal.hpp>
36 #include <boost/thread.hpp>
37 
38 #include "../common/WConditionSet.h"
39 #include "../common/WLogger.h"
40 #include "../common/WProgress.h"
41 #include "../common/WProgressCombiner.h"
42 #include "../common/WProperties.h"
43 #include "../common/WPrototyped.h"
44 #include "../common/WRequirement.h"
45 #include "../common/WThreadedRunner.h"
46 #include "../dataHandler/WDataSet.h"
47 #include "../dataHandler/WDataSetSingle.h"
48 #include "../dataHandler/WValueSet.h"
49 #include "WModuleCombinerTypes.h"
50 #include "WModuleConnectorSignals.h"
51 #include "WModuleMetaInformation.h"
52 #include "WModuleSignals.h"
53 #include "WModuleTypes.h"
54 
55 class WModuleConnector;
56 class WModuleContainer;
57 class WModuleFactory;
58 class WModuleLoader;
61 template < typename T > class WModuleInputData;
62 template < typename T > class WModuleInputForwardData;
63 template < typename T > class WModuleOutputData;
64 
65 /**
66  * Class representing a single module of OpenWalnut.
67  * \ingroup kernel
68  */
69 class WModule: public WThreadedRunner,
70  public WPrototyped,
71  public std::enable_shared_from_this< WModule >
72 {
73 friend class WModuleConnector; //!< requires access to notify members
74 template< typename T > friend class WModuleInputData; //!< requires access for convenience functions to automatically add a created connector
75 template< typename T > friend class WModuleInputForwardData; //!< requires access for convenience functions to automatically add a created connector
76 template< typename T > friend class WModuleOutputData; //!< requires access for convenience functions to automatically add a created connector
77 template< typename T > friend class WModuleOutputForwardData; //!< requires access for convenience functions to automatically add a created connector
78 friend class WModuleFactory; //!< for proper creation of module instances, the factory needs access to protected functions.(esp. initialize)
79 friend class WModuleContainer; //!< for proper management of m_container WModuleContainer needs access.
80 friend class WModuleLoader; //!< needs to set several protected values like local path and library names.
81 
82 public:
83  /**
84  * Constructs a new WModule instance
85  */
86  WModule();
87 
88  /**
89  * Destructor.
90  */
91  virtual ~WModule();
92 
93  /**
94  * The type for the list of input connectors.
95  */
96  typedef std::vector< std::shared_ptr< WModuleInputConnector > > InputConnectorList;
97 
98  /**
99  * The type for the list of output connectors.
100  */
101  typedef std::vector< std::shared_ptr< WModuleOutputConnector > > OutputConnectorList;
102 
103  /**
104  * Shared pointer to a WModule.
105  */
106  typedef std::shared_ptr< WModule > SPtr;
107 
108  /**
109  * Shared pointer to a const WModule.
110  */
111  typedef std::shared_ptr< const WModule > ConstSPtr;
112 
113  /**
114  * Gives back input connectors.
115  *
116  * \return the input connectors.
117  */
118  const InputConnectorList& getInputConnectors() const;
119 
120  /**
121  * Finds the named connector for the module.
122  *
123  * \param name the name. This can be a canonical name or the connector name.
124  *
125  * \return the connector.
126  * \throw WModuleConnectorNotFound thrown whenever the module does not provide the specified connector.
127  */
128  std::shared_ptr< WModuleInputConnector > getInputConnector( std::string name );
129 
130  /**
131  * Finds the named connector for the module. This is similar to getInputConnector but it does not throw an exception if the connector could
132  * not be found.
133  *
134  * \param name the name. This can be a canonical name or the connector name.
135  *
136  * \return the connector or NULL if not found
137  */
138  std::shared_ptr< WModuleInputConnector > findInputConnector( std::string name );
139 
140  /**
141  * Gives back output connectors.
142  *
143  * \return the output connectors.
144  */
146 
147  /**
148  * Finds the named connector for the module.
149  *
150  * \param name the name. This can be a canonical name or the connector name.
151  *
152  * \return the connector.
153  * \throw WModuleConnectorNotFound thrown whenever the module does not provide the specified connector.
154  */
155  std::shared_ptr< WModuleOutputConnector > getOutputConnector( std::string name );
156 
157  /**
158  * Finds the named connector for the module. This is similar to getOutputConnector but it does not throw an exception if the connector could
159  * not be found.
160  *
161  * \param name the name. This can be a canonical name or the connector name.
162  *
163  * \return the connector or NULL if not found.
164  */
165  std::shared_ptr< WModuleOutputConnector > findOutputConnector( std::string name );
166 
167  /**
168  * Finds the named connector for the module. This searches for inputs and outputs.
169  *
170  * \param name the name. This can be a canonical name or the connector name.
171  *
172  * \return the connector.
173  * \throw WModuleConnectorNotFound thrown whenever the module does not provide the specified connector.
174  */
175  std::shared_ptr< WModuleConnector > getConnector( std::string name );
176 
177  /**
178  * Finds the named connector for the module. This searches for inputs and outputs. This is similar to getConnector but it does not throw an
179  * exception if the connector could not be found.
180  *
181  * \param name the name. This can be a canonical name or the connector name.
182  *
183  * \return the connector or NULL if not found.
184  */
185  std::shared_ptr< WModuleConnector > findConnector( std::string name );
186 
187  /**
188  * Return a pointer to the properties object of the module.
189  *
190  * \return the properties.
191  */
192  std::shared_ptr< WProperties > getProperties() const;
193 
194  /**
195  * Return a pointer to the information properties object of the module. The module intends these properties to not be modified.
196  *
197  * \return the properties.
198  */
199  std::shared_ptr< WProperties > getInformationProperties() const;
200 
201  /**
202  * Determines whether the module instance is properly initialized.
203  *
204  * \return true if properly initialized.
205  */
206  const WBoolFlag& isInitialized() const;
207 
208  /**
209  * Checks whether the module instance is ready to be used. This is the case if isInitialized && isAssociated.
210  *
211  * \return isInitialized && isAssociated
212  */
213  const WBoolFlag& isUseable() const;
214 
215  /**
216  * Checks whether this module is associated with an container.
217  *
218  * \return true if associated.
219  */
220  const WBoolFlag& isAssociated() const;
221 
222  /**
223  * Checks whether this module is ready.
224  *
225  * \return true if ready.
226  */
227  const WBoolFlag& isReady() const;
228 
229  /**
230  * This is the logical or of isReady and isCrashed. You should use this condition if you need to wait for a module to get ready. If it
231  * crashed before ready() got called, you most probably would wait endlessly.
232  *
233  * \return isReady || isCrashed.
234  */
235  const WBoolFlag& isReadyOrCrashed() const;
236 
237  /**
238  * Returns a flag denoting whether the thread currently is running or nor. It is also useful to get a callback whenever a module stops.
239  *
240  * \return the flag
241  */
242  const WBoolFlag& isRunning() const;
243 
244  /**
245  * This method waits for the module to be restored completely. Use this instead of m_isLoadFinished->wait() as this is not properly defined
246  * when adding modules without using the project file loader.
247  *
248  * \note you have to use this after your \ref ready call (or it will cause a freeze)
249  */
250  void waitRestored();
251 
252  /**
253  * Check whether this module is in restore mode. This means that some loader is currently handling the module. You are allowed to ignore this
254  * flag. But be aware that the loader can set connections and properties even if you do not expect this.
255  *
256  * \return true if the module is currently being restored.
257  */
258  bool isRestoreNeeded() const;
259 
260  /**
261  * Change the restore mode. \see isRestoreNeeded for details.
262  *
263  * \note loaders need to set this flag before the module is associated with a container.
264  *
265  * \param restore the mode.
266  */
267  void setRestoreNeeded( bool restore = true );
268 
269  /**
270  * Called by loaders to tell the module that loading has been completed.
271  */
272  void reportRestoreComplete();
273 
274  /**
275  * The container this module is associated with.
276  *
277  * \return the container.
278  */
279  std::shared_ptr< WModuleContainer > getAssociatedContainer() const;
280 
281  /**
282  * Due to the prototype design pattern used to build modules, this method returns a new instance of this module. NOTE: it
283  * should never be initialized or modified in some other way.
284  *
285  * \return the prototype used to create every module in OpenWalnut.
286  */
287  virtual std::shared_ptr< WModule > factory() const = 0;
288 
289  // Tell the compiler that we really want to use the base's subscribeSignal.
291 
292  /**
293  * Connects a specified notify function with a signal this module instance is offering.
294  *
295  * \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
296  *
297  * \param signal the signal to connect to.
298  * \param notifier the notifier function to bind.
299  *
300  * \return connection descriptor.
301  */
302  virtual boost::signals2::connection subscribeSignal( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier );
303 
304  /**
305  * Connects a specified notify function with a signal this module instance is offering. Please note that there also is a
306  * WThreadedRunner::subscribeSignal which allows error callbacks. The difference to this one is that the WThreadedRunner's version does not
307  * provide the sender information (shared_ptr).
308  *
309  * \exception WModuleSignalSubscriptionFailed thrown if the signal can't be connected.
310  *
311  * \param signal the signal to connect to.
312  * \param notifier the notifier function to bind.
313  *
314  * \return connection descriptor.
315  */
316  virtual boost::signals2::connection subscribeSignal( MODULE_SIGNAL signal, t_ModuleErrorSignalHandlerType notifier );
317 
318  /**
319  * Gets the modules base progress. This is actually a progress combiner, which bundles all progresses.
320  *
321  * \return the progress combiner for this module.
322  */
323  virtual std::shared_ptr< WProgressCombiner > getRootProgressCombiner();
324 
325  /**
326  * Get the icon for this module in XPM format.
327  * \return The icon.
328  */
329  virtual const char** getXPMIcon() const;
330 
331  /**
332  * Gets the type of the module. This is useful for FAST differentiation between several modules like standard modules and data
333  * modules which play a special role in OpenWalnut/Kernel.
334  *
335  * \return the Type. If you do not overwrite this method, it will return MODULE_ARBITRARY.
336  */
337  virtual MODULE_TYPE getType() const;
338 
339  /**
340  * Completely disconnects all connected connectors of this module. This is useful to isolate a module (for deletion, removal from a container
341  * and so on.)
342  */
343  void disconnect();
344 
345  /**
346  * Gives a list of all WDisconnectCombiners possible. Please note that while the list exists, connections might change.
347  *
348  * \return the list of possible disconnect operations
349  */
350  WCombinerTypes::WDisconnectList getPossibleDisconnections();
351 
352  /**
353  * Returns the local path of the module. Whenever you try to load local resources, use this path. It is especially useful for shader loading.
354  *
355  * \return the local module path.
356  */
357  boost::filesystem::path getLocalPath() const;
358 
359  /**
360  * Returns the absolute path to the library containing this module.
361  *
362  * \return the path.
363  */
364  boost::filesystem::path getLibPath() const;
365 
366  /**
367  * Returns the name of the package the module belongs to, The package name basically is the name of the
368  * library containing this and maybe other modules. Your build system manages this. The package name is used to identify the resources for
369  * the modules in the library (a.k.a package).
370  *
371  * \return the name
372  */
373  std::string getPackageName() const;
374 
375  /**
376  * Checks whether the module was marked as deprecated.
377  *
378  * \return true if deprecated
379  */
380  bool isDeprecated() const;
381 
382  /**
383  * Queries the deprecation message of a module if specified. If not specified, an empty string is returned. Check \ref isDeprecated first.
384  *
385  * \return deprecation message
386  */
387  std::string getDeprecationMessage() const;
388 
389  /**
390  * The meta information of this module. This contains several information like name, description, icons, help links and so on. It, at least,
391  * contains the name.
392  *
393  * \return the meta info object for this module.
394  */
396 
397  /**
398  * Get the UUID of the module instance. Use this when you need to guarantee a unique instance name, even across multiple OW sessions. The
399  * UUID gets set by the initialize method once and can never be changed.
400  *
401  * \return the UUID as string.
402  */
403  const std::string& getUUID() const;
404 
405  /**
406  * Find a module instance by UUID.
407  *
408  * \param uuid the uuid to search for.
409  *
410  * \return the module, or NULL if not found
411  */
412  static SPtr findByUUID( std::string uuid );
413 
414  /**
415  * Returns the name the user has given this module.
416  *
417  * \return the runtime name.
418  */
419  WPropString getRuntimeName() const;
420 
421  /**
422  * This method checks whether all the requirements of the module are complied. Can be used if the instance is a prototype.
423  *
424  * \return the requirement that has failed.
425  */
426  const WRequirement* checkRequirements() const;
427 
428 protected:
429  /**
430  * Entry point after loading the module. Runs in separate thread.
431  */
432  virtual void moduleMain() = 0;
433 
434  /**
435  * Thread entry point. Calls moduleMain and sends error notification if needed.
436  */
437  void threadMain();
438 
439  /**
440  * This method is called if an exception was caught, which came from the custom thread code. This method is virtual and allows you to
441  * overwrite the default behaviour. If you overwrite this method, you should call \ref WThreadedRunner::handleDeadlyException or
442  * WThreadedRunner::onThreadException if you are finished with your customized code.
443  *
444  * \param e the exception that was caught.
445  */
446  virtual void onThreadException( const WException& e );
447 
448  /**
449  * Sets the container this module is associated with.
450  *
451  * \param container the container to associate with.
452  */
453  void setAssociatedContainer( std::shared_ptr< WModuleContainer > container );
454 
455  // **************************************************************************************************************************
456  //
457  // Connector Management
458  //
459  // **************************************************************************************************************************
460 
461  /**
462  * Initialize connectors in this function. This function must not be called multiple times for one module instance.
463  * The module container manages calling those functions -> so just implement it.
464  */
465  virtual void connectors();
466 
467  /**
468  * Initialize properties in this function. This function must not be called multiple times for one module instance.
469  * The module container manages calling those functions -> so just implement it. Once initialized the number and type
470  * of all properties should be set.
471  */
472  virtual void properties();
473 
474  /**
475  * Initialize requirements in this function. This function must not be called multiple times for one module instance.
476  * The module should always implement this. Using this method, a module can tell the kernel what it needs to run properly. For example, it
477  * can require a running graphics engine or, in the case of module containers, other modules.
478  */
479  virtual void requirements();
480 
481  /**
482  * This function allows module programmers to mark their modules deprecated in a user-friendly way. If you implement this function, you need
483  * to specify an text which should mention an alternative module.
484  *
485  * \note do not add sentences like "this module is deprecated" or similar, since the GUI the user is using already shows this message. The
486  * message should say WHY it is deprecated and what alternative module is available.
487  * \return deprecation message
488  */
489  virtual std::string deprecated() const;
490 
491  /**
492  * Manages initialization. Gets called by module container and ensures all properties, requirements, and connectors are properly set up.
493  *
494  * \throw WModuleConnectorInitFailed if called multiple times.
495  */
496  void initialize();
497 
498  /**
499  * Called whenever the module should shutdown.
500  */
501  virtual void cleanup();
502 
503  /**
504  * Adds the specified connector to the list of inputs.
505  *
506  * \param con the connector.
507  */
508  void addConnector( std::shared_ptr<WModuleInputConnector> con );
509 
510  /**
511  * Adds the specified connector to the list of outputs.
512  *
513  * \param con the connector.
514  */
515  void addConnector( std::shared_ptr<WModuleOutputConnector> con );
516 
517  /**
518  * Removes all connectors properly. It disconnects the connectors and cleans the connectors list.
519  */
520  void removeConnectors();
521 
522  /**
523  * Callback for m_active. Overwrite this in your modules to handle m_active changes separately.
524  */
525  virtual void activate();
526 
527  // **************************************************************************************************************************
528  //
529  // Signal handlers that HAVE to be in every module. By default they do nothing. You should overwrite them to get notified
530  // with the corresponding signal
531  //
532  // **************************************************************************************************************************
533 
534  /**
535  * Gives the signal handler function responsible for a given signal. Modules defining own signal handlers should overwrite
536  * this function. This function is protected since boost::functions are callable, which is what is not wanted here. Just
537  * signals should call them.
538  *
539  * \param signal the signal to get the handler for.
540  *
541  * \return the signal handler for "signal".
542  */
543  virtual const t_GenericSignalHandlerType getSignalHandler( MODULE_CONNECTOR_SIGNAL signal );
544 
545  /**
546  * Gets called whenever a connector gets connected to the specified input.
547  *
548  * \param here the connector of THIS module that got connected to "there"
549  * \param there the connector that has been connected with the connector "here" of this module.
550  */
551  virtual void notifyConnectionEstablished( std::shared_ptr<WModuleConnector> here,
552  std::shared_ptr<WModuleConnector> there );
553  /**
554  * Gets called whenever a connection between a remote and local connector gets closed.
555  *
556  * \param here the connector of THIS module getting disconnected.
557  * \param there the connector of the other module getting disconnected.
558  */
559  virtual void notifyConnectionClosed( std::shared_ptr<WModuleConnector> here, std::shared_ptr<WModuleConnector> there );
560 
561  /**
562  * Gets called when the data on one input connector changed.
563  *
564  * \param input the input connector receiving the change.
565  * \param output the output connector sending the change notification.
566  */
567  virtual void notifyDataChange( std::shared_ptr<WModuleConnector> input,
568  std::shared_ptr<WModuleConnector> output );
569 
570  /**
571  * Call this whenever your module is ready and can react on property changes.
572  */
573  void ready();
574 
575  /**
576  * Logger instance for comfortable info logging. Simply use logInfo() << "my info".
577  *
578  * \return the logger stream.
579  */
581 
582  /**
583  * Logger instance for comfortable debug logging. Simply use logDebug() << "my debug".
584  *
585  * \return the logger stream.
586  */
588 
589  /**
590  * Logger instance for comfortable warning- logs. Simply use logWarning() << "my warning".
591  *
592  * \return the logger stream.
593  */
595 
596  /**
597  * Logger instance for comfortable error logging. Simply use logError() << "my error".
598  *
599  * \return the logger stream.
600  */
602 
603  // **************************************************************************************************************************
604  //
605  // Loading Management
606  //
607  // **************************************************************************************************************************
608 
609  /**
610  * Sets the local module path. This gets called by the module loader.
611  *
612  * \param path the local path.
613  */
614  void setLocalPath( boost::filesystem::path path );
615 
616  /**
617  * Set the path to the library which contains this module. This is usually set by \ref WModuleLoader.
618  *
619  * \param path the path to the library. Needs to be absolute.
620  */
621  void setLibPath( boost::filesystem::path path );
622 
623  /**
624  * Set the package name. This basically is the library name of the lib containing this module. The package name is used to identify resources
625  * and other things which belong to a library (a.k.a. package).
626  *
627  * \param name the name to set
628  */
629  void setPackageName( std::string name );
630 
631  // **************************************************************************************************************************
632  //
633  // Members
634  //
635  // **************************************************************************************************************************
636 
637  /**
638  * The property object for the module.
639  */
640  std::shared_ptr< WProperties > m_properties;
641 
642  /**
643  * The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION". It is useful to define some property
644  * to only be of informational nature. The GUI does not modify them. As it is a WProperties instance, you can use it the same way as
645  * m_properties.
646  */
647  std::shared_ptr< WProperties > m_infoProperties;
648 
649  /**
650  * Progress indicator used as parent for all progress' of this module.
651  */
652  std::shared_ptr< WProgressCombiner > m_progress;
653 
654  /**
655  * True if everything is initialized and ready to be used.
656  */
658 
659  /**
660  * True if container got associated with this flag.
661  */
663 
664  /**
665  * True if associated && initialized.
666  */
668 
669  /**
670  * True if ready() was called.
671  */
673 
674  /**
675  * It is true whenever m_isReady or WThreadedRunner::m_isCrashed is true. This is mostly useful for functions
676  * which need to wait for a module to get ready.
677  */
679 
680  /**
681  * True if the module currently is running.
682  */
684 
685  /**
686  * Flag to denote whether the module container and the project loader have finished their work. \see isLoadFinished.
687  */
689 
690  /**
691  * Flag denoting the current restore mode. \see setRestoreNeeded
692  */
694 
695  /**
696  * Progress indicator for the "ready" state.
697  */
698  std::shared_ptr< WProgress > m_readyProgress;
699 
700  /**
701  * The internal state of the module. This is, by default, simply the exit flag from WThreadedRunner.
702  */
704 
705  /**
706  * The container this module belongs to.
707  */
708  std::shared_ptr< WModuleContainer > m_container;
709 
710  /**
711  * Set of input connectors associated with this module.
712  */
714 
715  /**
716  * Set of output connectors associated with this module.
717  */
719 
720  /**
721  * True whenever the module should be active
722  */
723  WPropBool m_active;
724 
725  /**
726  * This property holds a user specified name for the current module instance.
727  */
728  WPropString m_runtimeName;
729 
730  /**
731  * The path where the module binary resides in. This path should be used whenever the module needs to load resources. It gets set by the
732  * module loader. Use this to load shaders and so on.
733  */
734  boost::filesystem::path m_localPath;
735 
736  /**
737  * The absolute path to the library containing this module.
738  */
739  boost::filesystem::path m_libPath;
740 
741  /**
742  * The name of the lib/the package containing this module.
743  */
744  std::string m_packageName;
745 
746  /**
747  * The type of the requirement list.
748  */
749  typedef std::vector< WRequirement* > Requirements;
750 
751  /**
752  * The list of requirements.
753  */
755 
756 private:
757  /**
758  * Lock for m_inputConnectors.
759  */
760  // std::shared_mutex m_inputConnectorsLock;
761 
762  /**
763  * Lock for m_outputConnectors.
764  */
765  // std::shared_mutex m_outputConnectorsLock;
766 
767  /**
768  * Module meta information. Set by the factory creating the module instance.
769  */
771 
772  /**
773  * Signal fired whenever a module main thread is ready.
774  */
775  t_ModuleGenericSignalType signal_ready;
776 
777  /**
778  * Signal fired whenever a module main thread throws an exception/error.
779  */
780  t_ModuleErrorSignalType signal_error;
781 
782  /**
783  * The unique ID of the module instance.
784  */
785  std::string m_uuid;
786 
787  /**
788  * Set a uuid. If the specified string is empty, a new one gets created.
789  *
790  * \param uuid the uuid to set.
791  */
792  void setUUID( std::string uuid );
793 };
794 
795 /**
796  * Simply a list of modules. The type is used by the following macros and typedefs
797  */
798 typedef std::vector< std::shared_ptr< WModule > > WModuleList;
799 
800 /**
801  * The signature used for the module loading entry point
802  */
803 typedef void ( *W_LOADABLE_MODULE_SIGNATURE )( WModuleList& );
804 
805 /**
806  * The signature used for the loaded toolbox as arbitrary registration function.
807  */
808 typedef void ( *W_LOADABLE_REGISTERARBITRARY_SIGNATURE )( const boost::filesystem::path& );
809 
810 /**
811  * The following macro is used by modules so the factory can acquire a prototype instance from a shared library using the symbol.
812  * You can write this symbol for your own if you need to add multiple modules to the list. This one is for convenience.
813  *
814  * \note we need the module instance to be created using a shared_ptr as WModule is derived from enable_shared_from_this. Removing the shared
815  * pointer causes segmentation faults during load.
816  */
817 #define W_LOADABLE_MODULE( MODULECLASS ) \
818 extern "C" void WLoadModule( WModuleList& m ) { m.push_back( std::shared_ptr< WModule >( new MODULECLASS ) ); } // NOLINT
819 
820 /**
821  * The corresponding symbol name.
822  */
823 #define W_LOADABLE_MODULE_SYMBOL "WLoadModule"
824 
825 /**
826  * THe register function's symbol name.
827  */
828 #define W_LOADABLE_REGISTERARBITRARY_SYMBOL "WRegisterArbitrary"
829 
830 /**
831  * \defgroup modules Modules
832  *
833  * \brief
834  * This group contains modules of OpenWalnut.
835  * The term modules can be understood as "plugin" or "algorithm" in this context.
836  */
837 #endif // WMODULE_H
838 
Class allowing multiple conditions to be used for one waiting cycle.
Definition: WConditionSet.h:44
Basic exception handler.
Definition: WException.h:39
Base class for modelling connections between kernel modules.
Class able to contain other modules.
Class able to create a new copy of an arbitrary module.
Class implementing input connection functionality between modules.
Class offering an instantiate-able data connection between modules.
This is a simple class which forwards input data to input data connectors.
Loads module prototypes from shared objects in a given directory and injects it into the module facto...
Definition: WModuleLoader.h:43
std::shared_ptr< WModuleMetaInformation > SPtr
Convenience typedef for a std::shared_ptr< WModuleMetaInformation >.
std::shared_ptr< const WModuleMetaInformation > ConstSPtr
Convenience typedef for a std::shared_ptr< const WModuleMetaInformation >.
Class implementing output connection functionality between modules.
Class offering an instantiate-able data connection between modules.
This is a simple class which forwards output data to output data connectors.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
void disconnect()
Completely disconnects all connected connectors of this module.
Definition: WModule.cpp:146
std::shared_ptr< WModuleOutputConnector > getOutputConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:342
virtual boost::signals2::connection subscribeSignal(THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
Connects a specified notify function with a signal this thread instance is offering.
virtual void cleanup()
Called whenever the module should shutdown.
Definition: WModule.cpp:262
virtual void requirements()
Initialize requirements in this function.
Definition: WModule.cpp:216
WCombinerTypes::WDisconnectList getPossibleDisconnections()
Gives a list of all WDisconnectCombiners possible.
Definition: WModule.cpp:161
boost::filesystem::path m_localPath
The path where the module binary resides in.
Definition: WModule.h:734
void reportRestoreComplete()
Called by loaders to tell the module that loading has been completed.
Definition: WModule.cpp:646
void setPackageName(std::string name)
Set the package name.
Definition: WModule.cpp:605
virtual void onThreadException(const WException &e)
This method is called if an exception was caught, which came from the custom thread code.
Definition: WModule.cpp:550
const WBoolFlag & isUseable() const
Checks whether the module instance is ready to be used.
Definition: WModule.cpp:439
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
Definition: WModule.cpp:493
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
void setAssociatedContainer(std::shared_ptr< WModuleContainer > container)
Sets the container this module is associated with.
Definition: WModule.cpp:273
const WBoolFlag & isInitialized() const
Determines whether the module instance is properly initialized.
Definition: WModule.cpp:429
Requirements m_requirements
The list of requirements.
Definition: WModule.h:754
const OutputConnectorList & getOutputConnectors() const
Gives back output connectors.
Definition: WModule.cpp:292
std::string getDeprecationMessage() const
Queries the deprecation message of a module if specified.
Definition: WModule.cpp:620
void initialize()
Manages initialization.
Definition: WModule.cpp:234
std::shared_ptr< WProperties > getProperties() const
Return a pointer to the properties object of the module.
Definition: WModule.cpp:478
std::string getPackageName() const
Returns the name of the package the module belongs to, The package name basically is the name of the ...
Definition: WModule.cpp:610
bool isDeprecated() const
Checks whether the module was marked as deprecated.
Definition: WModule.cpp:615
virtual std::shared_ptr< WModule > factory() const =0
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual MODULE_TYPE getType() const
Gets the type of the module.
Definition: WModule.cpp:282
t_ModuleErrorSignalType signal_error
Signal fired whenever a module main thread throws an exception/error.
Definition: WModule.h:780
WBoolFlag m_isAssociated
True if container got associated with this flag.
Definition: WModule.h:662
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
Definition: WModule.cpp:575
std::shared_ptr< WModuleContainer > m_container
The container this module belongs to.
Definition: WModule.h:708
void removeConnectors()
Removes all connectors properly.
Definition: WModule.cpp:194
void setLocalPath(boost::filesystem::path path)
Sets the local module path.
Definition: WModule.cpp:585
virtual const t_GenericSignalHandlerType getSignalHandler(MODULE_CONNECTOR_SIGNAL signal)
Gives the signal handler function responsible for a given signal.
Definition: WModule.cpp:411
bool m_restoreMode
Flag denoting the current restore mode.
Definition: WModule.h:693
WModuleMetaInformation::SPtr m_meta
Lock for m_inputConnectors.
Definition: WModule.h:770
WPropString getRuntimeName() const
Returns the name the user has given this module.
Definition: WModule.cpp:674
WBoolFlag m_isReady
True if ready() was called.
Definition: WModule.h:672
OutputConnectorList m_outputConnectors
Set of output connectors associated with this module.
Definition: WModule.h:718
void threadMain()
Thread entry point.
Definition: WModule.cpp:526
void setLibPath(boost::filesystem::path path)
Set the path to the library which contains this module.
Definition: WModule.cpp:595
virtual ~WModule()
Destructor.
Definition: WModule.cpp:103
static SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
Definition: WModule.cpp:669
std::shared_ptr< const WModule > ConstSPtr
Shared pointer to a const WModule.
Definition: WModule.h:111
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
Definition: WModule.cpp:108
InputConnectorList m_inputConnectors
Set of input connectors associated with this module.
Definition: WModule.h:713
const WRequirement * checkRequirements() const
This method checks whether all the requirements of the module are complied.
Definition: WModule.cpp:512
virtual WModuleMetaInformation::ConstSPtr getMetaInformation() const
The meta information of this module.
Definition: WModule.cpp:229
const WBoolFlag & isRunning() const
Returns a flag denoting whether the thread currently is running or nor.
Definition: WModule.cpp:455
wlog::WStreamedLogger warnLog() const
Logger instance for comfortable warning- logs.
Definition: WModule.cpp:580
std::shared_ptr< WModuleContainer > getAssociatedContainer() const
The container this module is associated with.
Definition: WModule.cpp:268
std::shared_ptr< WModuleConnector > getConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:369
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
virtual std::shared_ptr< WProgressCombiner > getRootProgressCombiner()
Gets the modules base progress.
Definition: WModule.cpp:488
std::shared_ptr< WModuleInputConnector > getInputConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:313
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WModule.h:647
const WBoolFlag & isReady() const
Checks whether this module is ready.
Definition: WModule.cpp:445
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
virtual std::string deprecated() const
This function allows module programmers to mark their modules deprecated in a user-friendly way.
Definition: WModule.cpp:224
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
Definition: WModule.cpp:570
virtual void activate()
Callback for m_active.
Definition: WModule.cpp:220
WPropBool m_active
True whenever the module should be active.
Definition: WModule.h:723
WPropString m_runtimeName
This property holds a user specified name for the current module instance.
Definition: WModule.h:728
std::vector< std::shared_ptr< WModuleOutputConnector > > OutputConnectorList
The type for the list of output connectors.
Definition: WModule.h:101
WBoolFlag m_isRunning
True if the module currently is running.
Definition: WModule.h:683
std::shared_ptr< WProperties > getInformationProperties() const
Return a pointer to the information properties object of the module.
Definition: WModule.cpp:483
WBoolFlag m_initialized
True if everything is initialized and ready to be used.
Definition: WModule.h:657
std::string m_uuid
The unique ID of the module instance.
Definition: WModule.h:785
const InputConnectorList & getInputConnectors() const
Gives back input connectors.
Definition: WModule.cpp:287
boost::filesystem::path getLocalPath() const
Returns the local path of the module.
Definition: WModule.cpp:590
WBoolFlag m_isReadyOrCrashed
It is true whenever m_isReady or WThreadedRunner::m_isCrashed is true.
Definition: WModule.h:678
boost::filesystem::path getLibPath() const
Returns the absolute path to the library containing this module.
Definition: WModule.cpp:600
std::vector< std::shared_ptr< WModuleInputConnector > > InputConnectorList
The type for the list of input connectors.
Definition: WModule.h:96
t_ModuleGenericSignalType signal_ready
Signal fired whenever a module main thread is ready.
Definition: WModule.h:775
std::vector< WRequirement * > Requirements
The type of the requirement list.
Definition: WModule.h:749
std::shared_ptr< WProgress > m_readyProgress
Progress indicator for the "ready" state.
Definition: WModule.h:698
void setUUID(std::string uuid)
Set a uuid.
Definition: WModule.cpp:656
std::shared_ptr< WModuleOutputConnector > findOutputConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:326
virtual void notifyDataChange(std::shared_ptr< WModuleConnector > input, std::shared_ptr< WModuleConnector > output)
Gets called when the data on one input connector changed.
Definition: WModule.cpp:472
void setRestoreNeeded(bool restore=true)
Change the restore mode.
Definition: WModule.cpp:641
const std::string & getUUID() const
Get the UUID of the module instance.
Definition: WModule.cpp:651
const WBoolFlag & isAssociated() const
Checks whether this module is associated with an container.
Definition: WModule.cpp:434
const WBoolFlag & isReadyOrCrashed() const
This is the logical or of isReady and isCrashed.
Definition: WModule.cpp:450
std::shared_ptr< WModuleConnector > findConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:356
std::shared_ptr< WModuleInputConnector > findInputConnector(std::string name)
Finds the named connector for the module.
Definition: WModule.cpp:297
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
Definition: WModule.h:652
virtual void moduleMain()=0
Entry point after loading the module.
WBoolFlag m_isUsable
True if associated && initialized.
Definition: WModule.h:667
virtual void notifyConnectionClosed(std::shared_ptr< WModuleConnector > here, std::shared_ptr< WModuleConnector > there)
Gets called whenever a connection between a remote and local connector gets closed.
Definition: WModule.cpp:466
WBoolFlag m_isLoadFinished
Flag to denote whether the module container and the project loader have finished their work.
Definition: WModule.h:688
WModule()
Constructs a new WModule instance.
Definition: WModule.cpp:60
virtual void notifyConnectionEstablished(std::shared_ptr< WModuleConnector > here, std::shared_ptr< WModuleConnector > there)
Gets called whenever a connector gets connected to the specified input.
Definition: WModule.cpp:460
bool isRestoreNeeded() const
Check whether this module is in restore mode.
Definition: WModule.cpp:636
std::string m_packageName
The name of the lib/the package containing this module.
Definition: WModule.h:744
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
Definition: WModule.cpp:565
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
boost::filesystem::path m_libPath
The absolute path to the library containing this module.
Definition: WModule.h:739
void waitRestored()
This method waits for the module to be restored completely.
Definition: WModule.cpp:625
Interface class for the concept "Prototype".
Definition: WPrototyped.h:38
Base class for all possible kinds of requirements.
Definition: WRequirement.h:38
Base class for all classes needing to be executed in a separate thread.
virtual boost::signals2::connection subscribeSignal(THREAD_SIGNAL signal, t_ThreadErrorSignalHandlerType notifier)
Connects a specified notify function with a signal this thread instance is offering.
std::shared_ptr< WThreadedRunner > SPtr
Abbreviation to a shared_ptr to this type.
Resource class for streamed logging.
Definition: WLogger.h:180