AnimatLab  2
Test
AnimatSim::Behavior::ThreadedModule Class Reference

A Threaded neural module base class. More...

#include <ThreadedModule.h>

+ Inheritance diagram for AnimatSim::Behavior::ThreadedModule:
+ Collaboration diagram for AnimatSim::Behavior::ThreadedModule:

Public Member Functions

 ThreadedModule (void)
 Default constructor. More...
 
virtual ~ThreadedModule (void)
 Destructor. More...
 
virtual float * GetDataPointer (const std::string &strDataType)
 Returns a float pointer to a data item of interest in this object. More...
 
virtual void PauseThread (bool bVal)
 
virtual bool PauseThread ()
 
virtual void QueryProperties (CStdPtrArray< TypeProperty > &aryProperties)
 Queries this object for a list of properties that can be changed using SetData. More...
 
virtual void SetupThread ()
 This method is called after all connections to whatever control board have been made. It calls each parts SetupIO method. For example, We connect to a Firmata microcontroller like an Arduino, and then do a setup that could take some time. We should not attempt to setup any of the pins until after the board itself has been setup. After that we need to loop through and setup all the parts. More...
 
virtual void ShutdownThread ()
 This method is called just before the IO thread is closed down. It gives the IO objects a chance to do any required cleanup. More...
 
virtual void StepThread ()
 This method is called from within the IO thread. It calls StepIO for each part. More...
 
virtual float StepThreadDuration ()
 Gets the time duration required to perform one step of the thread for all parts in this control. More...
 
virtual bool ThreadPaused ()
 
- Public Member Functions inherited from AnimatSim::Behavior::NeuralModule
 NeuralModule ()
 Default constructor. More...
 
virtual ~NeuralModule ()
 Destructor. More...
 
virtual void AddExternalSynapse (AnimatSim::Link *lpSynapse)
 
virtual void AddExternalSynapse (std::string strXml, bool bDoNotInit)
 Adds a synapse using an xml packet. More...
 
virtual void AttachSourceAdapter (Adapter *lpAdapter)
 Attaches a source adapter. More...
 
virtual void AttachTargetAdapter (Adapter *lpAdapter)
 Attaches a target adapter. More...
 
virtual IStdClassFactoryClassFactory ()
 Gets the class factory. More...
 
virtual void ClassFactory (IStdClassFactory *lpFactory)
 
virtual int FindExternalSynapseListPos (std::string strID, bool bThrowError=true)
 Searches for a synapse with the specified ID and returns its position in the list. More...
 
OrganismGetOrganism ()
 Gets the organism. More...
 
SimulatorGetSimulator ()
 Gets the simulator. More...
 
virtual void Initialize ()
 Initializes this object. More...
 
virtual std::string ModuleName ()=0
 Gets the module name. More...
 
virtual bool NeedToStep (bool bIncrement)
 Tells whether this NeuralModule needs to call StepSimulation. More...
 
virtual void RemoveExternalSynapse (std::string strID, bool bThrowError=true)
 Removes the synapse by the GUID ID. More...
 
virtual void RemoveSourceAdapter (Adapter *lpAdapter)
 Removes a source adapter. More...
 
virtual void RemoveTargetAdapter (Adapter *lpAdapter)
 Removes a target adapter. More...
 
virtual void ResetSimulation ()
 Resets the simulation back to time 0. More...
 
virtual void ResetStepCounter ()
 
virtual void SetSystemPointers (Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
 Sets the system pointers. More...
 
virtual void StepAdapters ()
 Step adapters. More...
 
virtual void StepSimulation ()
 Step the simulation for this object. More...
 
virtual float TimeStep ()
 Gets the time step for this moudle in time units. More...
 
virtual void TimeStep (float fltVal)
 Sets the Time step for this moudle in time units. More...
 
virtual short TimeStepInterval ()
 Gets the time step interval. More...
 
virtual void TimeStepInterval (short iVal)
 Sets ime step interval. More...
 
virtual void VerifySystemPointers ()
 Verify that system pointers have been set correctly. More...
 
- Public Member Functions inherited from AnimatSim::AnimatBase
 AnimatBase ()
 Constructs an AnimatBase object. More...
 
virtual ~AnimatBase ()
 Destroys the AnimatBase object.. More...
 
virtual bool AddItem (const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
 Adds a new object to this parent. More...
 
virtual void AfterResetSimulation ()
 Called after a simulation reset for some objects. More...
 
virtual long CalculateSnapshotByteSize ()
 Calculates the snapshot byte size. More...
 
virtual void Copy (CStdSerialize *lpSource)
 
virtual void Enabled (bool bVal)
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual bool Enabled ()
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual NeuralModuleGetNeuralModule ()
 Gets the neural module. More...
 
virtual NodeGetNode ()
 Gets the node. More...
 
virtual StructureGetStructure ()
 Gets the structure for this node. More...
 
virtual bool HasProperty (const std::string &strName)
 Queries this object if it has a property with the given name. More...
 
virtual std::string ID ()
 Gets the unique GUID ID of this object. More...
 
virtual void ID (std::string strValue)
 Sets the unique GUID ID of the object. More...
 
virtual void Kill (bool bState=true)
 Kills. More...
 
virtual void Load (StdUtils::CStdXml &oXml)
 Loads the item using an XML data packet. More...
 
virtual void LoadKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Loads a key frame snapshot. More...
 
virtual std::string Name ()
 Gets the name of this object. More...
 
virtual void Name (std::string strValue)
 Sets the name of the object. Blank is acceptable. More...
 
virtual AnimatPropertyType PropertyType (const std::string &strName)
 
virtual void ReInitialize ()
 Re-initialize this object. More...
 
virtual bool RemoveItem (const std::string &strItemType, const std::string &strID, bool bThrowError=true)
 Removes a child item from this parent. More...
 
virtual void Reset ()
 Resets this object. More...
 
virtual void RigidBodyAdded (std::string strID)
 
virtual void RigidBodyRemoved (std::string strID)
 
virtual void SaveKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Saves a key frame snapshot. More...
 
virtual bool Selected ()
 Tells if this items is selected or not. More...
 
virtual void Selected (bool bValue, bool bSelectMultiple)
 Selects this object. More...
 
virtual bool SetData (const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual bool SetData (const std::string &strDataType, const float fltValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual bool SetData (const std::string &strDataType, const long lValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual void SetSystemPointers (Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
 Sets the system pointers. More...
 
virtual void SimPausing ()
 Called just before the simulation pauses. More...
 
virtual void SimStarting ()
 Called just before the simulation starts. More...
 
virtual void SimStopping ()
 Called just before the simulation stops. More...
 
virtual void TimeStepModified ()
 Notification method that the time step modified has been modified. Objects should recalculate any slice times as needed. More...
 
virtual std::string Type ()
 returns the string type name of this object. More...
 
virtual void Type (std::string strValue)
 Sets the class type for this object. More...
 
virtual void VisualSelectionModeChanged (int iNewMode)
 Visual selection mode changed. More...
 

Static Public Member Functions

static ThreadedModuleCastToDerived (AnimatBase *lpBase)
 
- Static Public Member Functions inherited from AnimatSim::Behavior::NeuralModule
static NeuralModuleCastToDerived (AnimatBase *lpBase)
 

Protected Member Functions

virtual void CloseThread ()
 
virtual void ExitPause ()
 This method is waits until the m_bIOPaused flag is set back to false. More...
 
virtual void ExitThread ()
 
virtual void ProcessThread ()
 
virtual void StartPause ()
 This method is waits until the m_bIOPaused flag is set to true. More...
 
virtual void StartThread ()
 
virtual void WaitForThreadNotifyReady ()
 
virtual void WaitTillPaused ()
 This method is waits until the m_bIOPaused flag is set to true. More...
 
virtual void WaitWhilePaused ()
 This method is waits until the m_bPauseIO flag is set back to false. More...
 
- Protected Member Functions inherited from AnimatSim::Behavior::NeuralModule
virtual int FindAdapterListIndex (CStdArray< Adapter * > aryAdapters, std::string strID, bool bThrowError=true)
 
virtual AnimatSim::LinkLoadExternalSynapse (CStdXml &oXml)
 Loads an external synapse. More...
 
virtual void LoadExternalSynapses (CStdXml &oXml)
 Loads external synapses. More...
 

Protected Attributes

bool m_bPauseThread
 Set to true to pause the thread processing. Set back to false to resume it.
 
bool m_bSetupComplete
 Set to true once the thread is setup correctly.
 
bool m_bSetupStarted
 Set to true once the thread begins its setup.
 
bool m_bStopThread
 Flags the thread processing loop to exit.
 
bool m_bThreadPaused
 Is set to true once the thread loop is paused.
 
bool m_bThreadProcessing
 True while the io thread processing loop is going on.
 
bool m_bWaitingForThreadNotify
 Used to signal to the IO thread that we are waiting for their return signal.
 
float m_fltStepThreadDuration
 The time it takes to perform a step of the IO for all parts in this control.
 
boost::thread m_Thread
 Thread responsible for doing IO processing.
 
boost::interprocess::interprocess_condition m_WaitForSetupCond
 Condition used to determine when the IO is setup.
 
boost::interprocess::interprocess_mutex m_WaitForSetupMutex
 Mutex responsible for waiting until the IO is finished setting up.
 
- Protected Attributes inherited from AnimatSim::Behavior::NeuralModule
CStdPtrArray< AnimatSim::Linkm_aryExternalSynapses
 An array of external synapses connected to nodes within this module.
 
CStdArray< Adapter * > m_arySourceAdapters
 An array of source adapters for this module.
 
CStdArray< Adapter * > m_aryTargetAdapters
 An array of target adapters for this module.
 
float m_fltTimeStep
 The DT time step for this neural module in seconds.
 
short m_iTargetAdapterCount
 Number of target adapters.
 
short m_iTimeStepCount
 Count variable that keeps track of how many slices have occured since the last StepSimulation.
 
short m_iTimeStepInterval
 
IStdClassFactorym_lpClassFactory
 The pointer to the class factory for this module.
 
Organism * m_lpOrganism
 The pointer to the organism.
 
std::string m_strNeuralNetworkFile
 The string neural network file name.
 
std::string m_strProjectPath
 Full pathname of the string project file for this module.
 
- Protected Attributes inherited from AnimatSim::AnimatBase
bool m_bEnabled
 Tells if this item is enabled or not. If it is not enabled then it is not run.
 
bool m_bSelected
 Tells whether the object is selected or not.
 
AnimatSim::Behavior::NeuralModulem_lpModule
 The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NULL.
 
Nodem_lpNode
 The pointer to this items parent Node. If this is not relevant for this object then this is NULL.
 
Simulatorm_lpSim
 The pointer to a Simulation.
 
AnimatSim::Environment::Structurem_lpStructure
 The pointer to this items parent Structure. If this is not relevant for this object then this is NULL.
 
std::string m_strID
 The unique Id for this object.
 
std::string m_strName
 The name for this object.
 
std::string m_strType
 The type for this object. Examples are Box, Plane, Neuron, etc..
 

Detailed Description

A Threaded neural module base class.

To do.

Author
dcofer
Date
10/1/2014

Definition at line 21 of file ThreadedModule.h.

Constructor & Destructor Documentation

AnimatSim::Behavior::ThreadedModule::ThreadedModule ( void  )

Default constructor.

Author
dcofer
Date
9/8/2014

Definition at line 54 of file ThreadedModule.cpp.

References m_bPauseThread, m_bSetupComplete, m_bSetupStarted, m_bStopThread, m_bThreadPaused, m_bThreadProcessing, m_bWaitingForThreadNotify, and m_fltStepThreadDuration.

AnimatSim::Behavior::ThreadedModule::~ThreadedModule ( void  )
virtual

Destructor.

Author
dcofer
Date
9/8/2014

Definition at line 73 of file ThreadedModule.cpp.

References ShutdownThread(), and StdUtils::Std_TraceMsg().

+ Here is the call graph for this function:

Member Function Documentation

void AnimatSim::Behavior::ThreadedModule::ExitPause ( )
protectedvirtual

This method is waits until the m_bIOPaused flag is set back to false.

Author
dcofer
Date
5/12/2014

Definition at line 321 of file ThreadedModule.cpp.

References AnimatSim::Simulator::InSimulation(), AnimatSim::AnimatBase::m_bEnabled, m_bPauseThread, m_bThreadPaused, AnimatSim::AnimatBase::m_lpSim, and AnimatSim::Simulator::Paused().

+ Here is the call graph for this function:

float * AnimatSim::Behavior::ThreadedModule::GetDataPointer ( const std::string &  strDataType)
virtual

Returns a float pointer to a data item of interest in this object.

This is a generic method used to get a pointer to data variable of interest. It is used by a variety of systems in the simulation. The most prominent are the data charting and stimulus classes. Within this method we associate a variable with a string name. By passing in the name of the data type we are interested in we can recieve back a float pointer to that data type. We can use that to read or set the data item in other classes. For example, the data charting system gets the pointer and then each time it needs to log a data point it reads the value into an array.

Author
dcofer
Date
2/22/2011
Parameters
strDataTypename of the data item for which we are looking.
Returns
float pointer of the data item. If not found then it throws an exception.
Exceptions
IfDataType is not found.

Reimplemented from AnimatSim::Behavior::NeuralModule.

Definition at line 105 of file ThreadedModule.cpp.

References AnimatSim::Behavior::NeuralModule::GetDataPointer(), m_fltStepThreadDuration, and StdUtils::Std_CheckString().

+ Here is the call graph for this function:

void AnimatSim::Behavior::ThreadedModule::QueryProperties ( CStdPtrArray< TypeProperty > &  aryProperties)
virtual

Queries this object for a list of properties that can be changed using SetData.

The method provides a list of the properties that can be set using the SetData method. It gives the property name and the type of data that should be passed to it. Valid date types are Boolean, Float, Integer, and Xml.

Author
dcofer
Date
2/22/2011
Parameters
aryNamesArray list of the property names.
strTypesArray list of the type that is associated with the cooresponding name in the list.
Returns
Nothing.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 117 of file ThreadedModule.cpp.

References AnimatSim::AnimatBase::QueryProperties().

+ Here is the call graph for this function:

void AnimatSim::Behavior::ThreadedModule::SetupThread ( )
virtual

This method is called after all connections to whatever control board have been made. It calls each parts SetupIO method. For example, We connect to a Firmata microcontroller like an Arduino, and then do a setup that could take some time. We should not attempt to setup any of the pins until after the board itself has been setup. After that we need to loop through and setup all the parts.

Author
dcofer
Date
5/1/2014

Definition at line 246 of file ThreadedModule.cpp.

References m_bWaitingForThreadNotify.

void AnimatSim::Behavior::ThreadedModule::ShutdownThread ( )
virtual

This method is called just before the IO thread is closed down. It gives the IO objects a chance to do any required cleanup.

Author
dcofer
Date
5/12/2014

Definition at line 340 of file ThreadedModule.cpp.

References m_bThreadProcessing, StartPause(), and WaitTillPaused().

Referenced by AnimatCarlSim::CsNeuralModule::ResetSimulation(), AnimatCarlSim::CsNeuralModule::SimStopping(), and ~ThreadedModule().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::ThreadedModule::StartPause ( )
protectedvirtual

This method is waits until the m_bIOPaused flag is set to true.

Author
dcofer
Date
5/12/2014

Definition at line 303 of file ThreadedModule.cpp.

References AnimatSim::Simulator::InSimulation(), AnimatSim::AnimatBase::m_bEnabled, m_bPauseThread, m_bThreadPaused, AnimatSim::AnimatBase::m_lpSim, and AnimatSim::Simulator::Paused().

Referenced by ShutdownThread().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::ThreadedModule::StepThread ( )
virtual

This method is called from within the IO thread. It calls StepIO for each part.

Author
dcofer
Date
5/2/2014

Reimplemented in AnimatCarlSim::CsNeuralModule.

Definition at line 264 of file ThreadedModule.cpp.

float AnimatSim::Behavior::ThreadedModule::StepThreadDuration ( )
virtual

Gets the time duration required to perform one step of the thread for all parts in this control.

Author
dcofer
Date
5/7/2014
Returns
Step duration.

Definition at line 101 of file ThreadedModule.cpp.

References m_fltStepThreadDuration.

void AnimatSim::Behavior::ThreadedModule::WaitTillPaused ( )
protectedvirtual

This method is waits until the m_bIOPaused flag is set to true.

Author
dcofer
Date
9/20/2014

Definition at line 290 of file ThreadedModule.cpp.

References m_bThreadPaused.

Referenced by ShutdownThread().

+ Here is the caller graph for this function:

void AnimatSim::Behavior::ThreadedModule::WaitWhilePaused ( )
protectedvirtual

This method is waits until the m_bPauseIO flag is set back to false.

Author
dcofer
Date
5/12/2014

Definition at line 275 of file ThreadedModule.cpp.

References m_bPauseThread, and m_bThreadPaused.


The documentation for this class was generated from the following files: