OpenWalnut  1.5.0dev
WModule.cpp
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 #include <algorithm>
26 #include <memory>
27 #include <set>
28 #include <sstream>
29 #include <string>
30 
31 #include <boost/uuid/uuid.hpp>
32 #include <boost/uuid/uuid_generators.hpp>
33 #include <boost/uuid/uuid_io.hpp>
34 
35 #include "../common/WCondition.h"
36 #include "../common/WConditionOneShot.h"
37 #include "../common/WConditionSet.h"
38 #include "../common/WException.h"
39 #include "../common/WLogger.h"
40 #include "../common/WPathHelper.h"
41 #include "../common/WPredicateHelper.h"
42 #include "../common/WProgressCombiner.h"
43 #include "../common/exceptions/WNameNotUnique.h"
44 #include "../common/exceptions/WSignalSubscriptionFailed.h"
45 #include "../common/exceptions/WSignalUnknown.h"
46 #include "WModule.h"
47 #include "WModuleConnectorSignals.h"
48 #include "WModuleContainer.h"
49 #include "WModuleFactory.h"
50 #include "WModuleInputConnector.h"
51 #include "WModuleInputData.h"
52 #include "WModuleMetaInformation.h"
53 #include "WModuleOutputConnector.h"
54 #include "WModuleOutputData.h"
55 #include "exceptions/WModuleConnectorInitFailed.h"
56 #include "exceptions/WModuleConnectorNotFound.h"
57 #include "exceptions/WModuleRequirementNotMet.h"
58 #include "exceptions/WModuleUninitialized.h"
59 
62  WPrototyped(),
63  m_initialized( new WCondition(), false ),
64  m_isAssociated( new WCondition(), false ),
65  m_isUsable( new WCondition(), false ),
66  m_isReady( new WConditionOneShot(), false ),
67  m_isReadyOrCrashed( new WConditionSet(), false ),
68  m_isRunning( new WCondition(), false ),
69  m_isLoadFinished( new WConditionOneShot(), false ),
70  m_restoreMode( false ),
71  m_readyProgress( std::shared_ptr< WProgress >( new WProgress( "Initializing Module" ) ) ),
72  m_moduleState(),
73  m_localPath( WPathHelper::getSharePath() )
74 {
75  // initialize members
76  m_properties = std::shared_ptr< WProperties >( new WProperties( "Properties", "Module's properties" ) );
77  m_infoProperties = std::shared_ptr< WProperties >( new WProperties( "Informational Properties", "Module's information properties" ) );
78  m_infoProperties->setPurpose( PV_PURPOSE_INFORMATION );
79 
80  m_runtimeName = m_properties->addProperty( "Name", "The name of the module defined by the user. This is, by default, the module name but "
81  "can be changed by the user to provide some kind of simple identification upon many modules.",
82  std::string( "" ), false );
83 
84  m_active = m_properties->addProperty( "active", "Determines whether the module should be activated.", true, true );
85  m_active->getCondition()->subscribeSignal( boost::bind( &WModule::activate, this ) );
86 
87  // the isReadyOrCrashed condition set needs to be set up here
88  WConditionSet* cs = static_cast< WConditionSet* >( m_isReadyOrCrashed.getCondition().get() ); // NOLINT
89  cs->setResetable( true, false );
90  cs->add( m_isReady.getCondition() );
91  cs->add( m_isCrashed.getCondition() );
92 
93  m_container = std::shared_ptr< WModuleContainer >();
94  m_progress = std::shared_ptr< WProgressCombiner >( new WProgressCombiner() );
95 
96  // add a progress indicator which finishes on "ready()"
97  m_progress->addSubProgress( m_readyProgress );
98 
99  // our internal state consist out of two conditions: data changed and the exit flag from WThreadedRunner.
101 }
102 
104 {
105  // cleanup
106 }
107 
108 void WModule::addConnector( std::shared_ptr< WModuleInputConnector > con )
109 {
110  size_t c = std::count_if( m_inputConnectors.begin(), m_inputConnectors.end(),
111  WPredicateHelper::Name< std::shared_ptr< WModuleInputConnector > >( con->getName() )
112  );
113  // well ... we want it to be unique in both:
114  c += std::count_if( m_outputConnectors.begin(), m_outputConnectors.end(),
115  WPredicateHelper::Name< std::shared_ptr< WModuleOutputConnector > >( con->getName() )
116  );
117 
118  // if there already is one ... exception
119  if( c )
120  {
121  throw WNameNotUnique( std::string( "Could not add the connector " + con->getCanonicalName() + " since names must be unique." ) );
122  }
123 
124  m_inputConnectors.push_back( con );
125 }
126 
127 void WModule::addConnector( std::shared_ptr< WModuleOutputConnector > con )
128 {
129  size_t c = std::count_if( m_inputConnectors.begin(), m_inputConnectors.end(),
130  WPredicateHelper::Name< std::shared_ptr< WModuleInputConnector > >( con->getName() )
131  );
132  // well ... we want it to be unique in both:
133  c += std::count_if( m_outputConnectors.begin(), m_outputConnectors.end(),
134  WPredicateHelper::Name< std::shared_ptr< WModuleOutputConnector > >( con->getName() )
135  );
136 
137  // if there already is one ... exception
138  if( c )
139  {
140  throw WNameNotUnique( std::string( "Could not add the connector " + con->getCanonicalName() + " since names must be unique." ) );
141  }
142 
143  m_outputConnectors.push_back( con );
144 }
145 
147 {
148  // remove connections and their signals
149  for( InputConnectorList::iterator listIter = m_inputConnectors.begin();
150  listIter != m_inputConnectors.end(); ++listIter )
151  {
152  ( *listIter )->disconnectAll();
153  }
154  for( OutputConnectorList::iterator listIter = m_outputConnectors.begin();
155  listIter != m_outputConnectors.end(); ++listIter )
156  {
157  ( *listIter )->disconnectAll();
158  }
159 }
160 
161 WCombinerTypes::WDisconnectList WModule::getPossibleDisconnections()
162 {
163  WCombinerTypes::WDisconnectList discons;
164 
165  // iterate inputs
166  for( InputConnectorList::iterator listIter = m_inputConnectors.begin(); listIter != m_inputConnectors.end(); ++listIter )
167  {
168  // get all connections of the current connector:
169  WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
170  ( *listIter )->getPossibleDisconnections() );
171 
172  if( g.second.size() )
173  {
174  discons.push_back( g );
175  }
176  }
177 
178  // iterate outputs
179  for( OutputConnectorList::iterator listIter = m_outputConnectors.begin(); listIter != m_outputConnectors.end(); ++listIter )
180  {
181  // get all connections of the current connector:
182  WCombinerTypes::WDisconnectGroup g = WCombinerTypes::WDisconnectGroup( ( *listIter )->getName(),
183  ( *listIter )->getPossibleDisconnections() );
184 
185  if( g.second.size() )
186  {
187  discons.push_back( g );
188  }
189  }
190 
191  return discons;
192 }
193 
195 {
196  m_initialized( false );
198 
199  // remove connections and their signals, this is flat removal. The module container can do deep removal
200  disconnect();
201 
202  // clean up list
203  // this should delete the connector since nobody else *should* have another shared_ptr to them
204  m_inputConnectors.clear();
205  m_outputConnectors.clear();
206 }
207 
209 {
210 }
211 
213 {
214 }
215 
217 {
218 }
219 
221 {
222 }
223 
224 std::string WModule::deprecated() const
225 {
226  return "";
227 }
228 
230 {
231  return m_meta;
232 }
233 
235 {
236  // doing it twice is not allowed
237  if( isInitialized()() )
238  {
239  throw WModuleConnectorInitFailed( std::string( "Could not initialize connectors for Module " ) + getName() +
240  std::string( ". Reason: already initialized." ) );
241  }
242 
243  // set the module name as default runtime name
244  m_runtimeName->set( getName() );
245 
246  // initialize module meta information
247  m_meta = WModuleMetaInformation::SPtr( new WModuleMetaInformation( shared_from_this() ) );
248 
249  // initialize connectors and properties
250  requirements();
251  connectors();
252  properties();
253 
254  // now, the module is initialized but not necessarily usable (if not associated with a container)
255  m_initialized( true );
257 
258  // also set thread name
259  setThreadName( getName() );
260 }
261 
263 {
264  // currently just removes connectors
266 }
267 
268 std::shared_ptr< WModuleContainer > WModule::getAssociatedContainer() const
269 {
270  return m_container;
271 }
272 
273 void WModule::setAssociatedContainer( std::shared_ptr< WModuleContainer > container )
274 {
275  m_container = container;
276 
277  // true if the pointer is set
278  m_isAssociated( m_container != std::shared_ptr< WModuleContainer >() );
280 }
281 
282 MODULE_TYPE WModule::getType() const
283 {
284  return MODULE_ARBITRARY;
285 }
286 
288 {
289  return m_inputConnectors;
290 }
291 
293 {
294  return m_outputConnectors;
295 }
296 
297 std::shared_ptr< WModuleInputConnector > WModule::findInputConnector( std::string name )
298 {
299  // simply search
300  for( InputConnectorList::const_iterator listIter = m_inputConnectors.begin();
301  listIter != m_inputConnectors.end(); ++listIter )
302  {
303  // try the canonical name
304  if( ( name == ( *listIter )->getCanonicalName() ) || ( name == ( *listIter )->getName() ) )
305  {
306  return ( *listIter );
307  }
308  }
309 
310  return std::shared_ptr< WModuleInputConnector >();
311 }
312 
313 std::shared_ptr< WModuleInputConnector > WModule::getInputConnector( std::string name )
314 {
315  std::shared_ptr< WModuleInputConnector > p = findInputConnector( name );
316 
317  if( !p )
318  {
319  throw WModuleConnectorNotFound( std::string( "The connector \"" ) + name +
320  std::string( "\" does not exist in the module \"" ) + getName() + std::string( "\"." ) );
321  }
322 
323  return p;
324 }
325 
326 std::shared_ptr< WModuleOutputConnector > WModule::findOutputConnector( std::string name )
327 {
328  // simply search
329  for( OutputConnectorList::const_iterator listIter = m_outputConnectors.begin();
330  listIter != m_outputConnectors.end(); ++listIter )
331  {
332  // try the canonical name
333  if( ( name == ( *listIter )->getCanonicalName() ) || ( name == ( *listIter )->getName() ) )
334  {
335  return ( *listIter );
336  }
337  }
338 
339  return std::shared_ptr< WModuleOutputConnector >();
340 }
341 
342 std::shared_ptr< WModuleOutputConnector > WModule::getOutputConnector( std::string name )
343 {
344  std::shared_ptr< WModuleOutputConnector > p = findOutputConnector( name );
345 
346  if( !p )
347  {
348  throw WModuleConnectorNotFound( std::string( "The connector \"" ) + name +
349  std::string( "\" does not exist in the module \"" ) + getName() +
350  std::string( "\"." ) );
351  }
352 
353  return p;
354 }
355 
356 std::shared_ptr< WModuleConnector > WModule::findConnector( std::string name )
357 {
358  // simply search both
359  std::shared_ptr< WModuleConnector > p = findInputConnector( name );
360  if( p ) // found?
361  {
362  return p;
363  }
364 
365  // search in output list
366  return findOutputConnector( name );
367 }
368 
369 std::shared_ptr< WModuleConnector > WModule::getConnector( std::string name )
370 {
371  std::shared_ptr< WModuleConnector > p = findConnector( name );
372 
373  if( !p )
374  {
375  throw WModuleConnectorNotFound( std::string( "The connector \"" ) + name +
376  std::string( "\" does not exist in the module \"" ) + getName() +
377  std::string( "\"." ) );
378  }
379 
380  return p;
381 }
382 
383 boost::signals2::connection WModule::subscribeSignal( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier )
384 {
385  switch( signal )
386  {
387  case WM_READY:
388  return signal_ready.connect( notifier );
389  default:
390  std::ostringstream s;
391  s << "Could not subscribe to unknown signal.";
392  throw WSignalSubscriptionFailed( s.str() );
393  break;
394  }
395 }
396 
397 boost::signals2::connection WModule::subscribeSignal( MODULE_SIGNAL signal, t_ModuleErrorSignalHandlerType notifier )
398 {
399  switch( signal )
400  {
401  case WM_ERROR:
402  return signal_error.connect( notifier );
403  default:
404  std::ostringstream s;
405  s << "Could not subscribe to unknown signal.";
406  throw WSignalSubscriptionFailed( s.str() );
407  break;
408  }
409 }
410 
411 const t_GenericSignalHandlerType WModule::getSignalHandler( MODULE_CONNECTOR_SIGNAL signal )
412 {
413  switch( signal )
414  {
415  case CONNECTION_ESTABLISHED:
416  return boost::bind( &WModule::notifyConnectionEstablished, this, boost::placeholders::_1, boost::placeholders::_2 );
417  case CONNECTION_CLOSED:
418  return boost::bind( &WModule::notifyConnectionClosed, this, boost::placeholders::_1, boost::placeholders::_2 );
419  case DATA_CHANGED:
420  return boost::bind( &WModule::notifyDataChange, this, boost::placeholders::_1, boost::placeholders::_2 );
421  default:
422  std::ostringstream s;
423  s << "Could not subscribe to unknown signal. You need to implement this signal type explicitly in your module.";
424  throw WSignalUnknown( s.str() );
425  break;
426  }
427 }
428 
430 {
431  return m_initialized;
432 }
433 
435 {
436  return m_isAssociated;
437 }
438 
440 {
441  return m_isUsable;
442  //return isInitialized() && isAssociated();
443 }
444 
446 {
447  return m_isReady;
448 }
449 
451 {
452  return m_isReadyOrCrashed;
453 }
454 
456 {
457  return m_isRunning;
458 }
459 
460 void WModule::notifyConnectionEstablished( std::shared_ptr< WModuleConnector > /*here*/,
461  std::shared_ptr< WModuleConnector > /*there*/ )
462 {
463  // By default this callback does nothing. Overwrite it in your module.
464 }
465 
466 void WModule::notifyConnectionClosed( std::shared_ptr< WModuleConnector > /*here*/,
467  std::shared_ptr< WModuleConnector > /*there*/ )
468 {
469  // By default this callback does nothing. Overwrite it in your module.
470 }
471 
472 void WModule::notifyDataChange( std::shared_ptr< WModuleConnector > /*input*/,
473  std::shared_ptr< WModuleConnector > /*output*/ )
474 {
475  // By default this callback does nothing. Overwrite it in your module.
476 }
477 
478 std::shared_ptr< WProperties > WModule::getProperties() const
479 {
480  return m_properties;
481 }
482 
483 std::shared_ptr< WProperties > WModule::getInformationProperties() const
484 {
485  return m_infoProperties;
486 }
487 
488 std::shared_ptr< WProgressCombiner > WModule::getRootProgressCombiner()
489 {
490  return m_progress;
491 }
492 
493 const char** WModule::getXPMIcon() const
494 {
495  // return empty 1x1 icon by default.
496  static const char * o_xpm[] =
497  {
498  "1 1 1 1",
499  " c None",
500  " "
501  };
502  return o_xpm;
503 }
504 
506 {
507  m_isReady( true );
508  m_readyProgress->finish();
509  signal_ready( shared_from_this() );
510 }
511 
513 {
514  // simply iterate all requirements and return the first found that is not fulfilled
515  for( Requirements::const_iterator i = m_requirements.begin(); i != m_requirements.end(); ++i )
516  {
517  if( !( *i )->isComplied() )
518  {
519  return *i;
520  }
521  }
522 
523  return NULL;
524 }
525 
527 {
528  WLogger::getLogger()->addLogMessage( "Starting module main method.", "Module (" + getName() + ")", LL_INFO );
529 
530  // check requirements
531  const WRequirement* failedReq = checkRequirements();
532  if( failedReq )
533  {
534  throw WModuleRequirementNotMet( failedReq );
535  }
536 
537  // call main thread function
538  m_isRunning( true );
539  moduleMain();
540 
541  // NOTE: if there is any exception in the module thread, WThreadedRunner calls onThreadException for us. We can then disconnect the
542  // module and call our own error notification mechanism.
543 
544  // remove all pending connections. This is important as connections that still exists after module deletion can cause segfaults when they get
545  // disconnected in the connector destructor.
546  disconnect();
547  m_isRunning( false );
548 }
549 
551 {
552  // use our own error callback which includes the exact module pointer which caused the problem
553  signal_error( shared_from_this(), e );
554 
555  // ensure the module is properly disconnected
556  disconnect();
557 
558  // module is not running anymore.
559  m_isRunning( false );
560 
561  // let WThreadedRunner do the remaining tasks.
562  handleDeadlyException( e, "Module (" + getName() +")" );
563 }
564 
566 {
567  return wlog::info( getName() );
568 }
569 
571 {
572  return wlog::error( getName() );
573 }
574 
576 {
577  return wlog::debug( getName() );
578 }
579 
581 {
582  return wlog::warn( getName() );
583 }
584 
585 void WModule::setLocalPath( boost::filesystem::path path )
586 {
587  m_localPath = path;
588 }
589 
590 boost::filesystem::path WModule::getLocalPath() const
591 {
592  return m_localPath;
593 }
594 
595 void WModule::setLibPath( boost::filesystem::path path )
596 {
597  m_libPath = path;
598 }
599 
600 boost::filesystem::path WModule::getLibPath() const
601 {
602  return m_libPath;
603 }
604 
605 void WModule::setPackageName( std::string name )
606 {
607  m_packageName = name;
608 }
609 
610 std::string WModule::getPackageName() const
611 {
612  return m_packageName;
613 }
614 
616 {
617  return !deprecated().empty();
618 }
619 
621 {
622  return deprecated();
623 }
624 
626 {
627  if( m_restoreMode )
628  {
629  // this returns if the flag was set in the past since it uses a OneShot Condition.
631  // after load has finished, the module is not in restore mode anymore
632  m_restoreMode = false;
633  }
634 }
635 
637 {
638  return m_restoreMode;
639 }
640 
641 void WModule::setRestoreNeeded( bool restore )
642 {
643  m_restoreMode = restore;
644 }
645 
647 {
648  m_isLoadFinished.set( true );
649 }
650 
651 const std::string& WModule::getUUID() const
652 {
653  return m_uuid;
654 }
655 
656 void WModule::setUUID( std::string uuid )
657 {
658  m_uuid = uuid;
659 
660  // create one if none was specified
661  if( m_uuid.empty() )
662  {
663  // simple random uuid generator
664  boost::uuids::random_generator gen;
665  m_uuid = boost::uuids::to_string( gen() );
666  }
667 }
668 
670 {
671  return WModuleFactory::findByUUID( uuid );
672 }
673 
674 WPropString WModule::getRuntimeName() const
675 {
676  return m_runtimeName;
677 }
678 
Implements a WCondition, but can be fired only ONCE.
Class allowing multiple conditions to be used for one waiting cycle.
Definition: WConditionSet.h:44
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
Basic exception handler.
Definition: WException.h:39
virtual void wait() const
Wait for the flag to change its value.
Definition: WFlag.h:279
std::shared_ptr< WCondition > getCondition()
Returns the condition that is used by this flag.
Definition: WFlag.h:319
virtual bool set(const T &value, bool suppressNotification=false)
Sets the new value for this flag.
Definition: WFlag.h:291
void addLogMessage(std::string message, std::string source="", LogLevel level=LL_DEBUG)
Appends a log message to the logging queue.
Definition: WLogger.cpp:84
static WLogger * getLogger()
Returns pointer to the currently running logger instance.
Definition: WLogger.cpp:64
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.
static WModule::SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
A class abstracting module meta information.
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 >.
Thrown whenever a module should be run but its requirements are not completely met.
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 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
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::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
Indicates that a given name is not unique in a group of names.
Singleton class helping to find files and paths.
Definition: WPathHelper.h:39
This class tests against the getName() method of the instances of type T.
Base class for all kinds of progress combinations.
Class managing progress inside of modules.
Definition: WProgress.h:42
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
Interface class for the concept "Prototype".
Definition: WPrototyped.h:38
virtual const std::string getName() const =0
Gets the name of this prototype.
Base class for all possible kinds of requirements.
Definition: WRequirement.h:38
General purpose exception and therefore base class for all kernel related exceptions.
General purpose exception and therefore base class for all kernel related exceptions.
Base class for all classes needing to be executed in a separate thread.
void setThreadName(std::string name)
Set the name of the thread.
void handleDeadlyException(const WException &e, std::string sender="WThreadedRunner")
Handle the specified exception which was not caught in the thread, which basically means the thread h...
WBoolFlag m_isCrashed
True whenever an exception is thrown during threadMain.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Resource class for streamed logging.
Definition: WLogger.h:180
WStreamedLogger debug(const std::string &source)
Logging a debug message.
Definition: WLogger.h:331
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309
WStreamedLogger info(const std::string &source)
Logging an information message.
Definition: WLogger.h:320
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298