PetaVision  Alpha
PV::Subject Class Reference

#include <Subject.hpp>

Inheritance diagram for PV::Subject:
PV::BaseConnection PV::Checkpointer PV::HyPerCol PV::HyPerConn PV::IdentConn PV::PoolingConn PV::WTAConn PV::CloneConn PV::CopyConn PV::GapConn PV::MomentumConn PV::TransposeConn PV::RescaleConn PV::TransposePoolingConn PV::PlasticCloneConn PV::FeedbackConn

Public Member Functions

virtual void addObserver (Observer *observer)
 

Protected Member Functions

Response::Status notify (ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag)
 
Response::Status notify (ObserverTable const &table, std::shared_ptr< BaseMessage const > message, bool printFlag)
 
void notifyLoop (ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag, std::string const &description)
 
void notifyLoop (ObserverTable const &table, std::shared_ptr< BaseMessage const > message, bool printFlag, std::string const &description)
 

Detailed Description

The subject class of the observer pattern. A class that inherits from the Subject class can maintain a hierarchy of BaseObject-derived objects, and can send each object a BaseMessage-derived message, or vector of such messages, using the notify() method. See the documentation of the notify() method for the expected behavior of the objects in the hierarchy, and the meaning of the notify() method's return values.

The notifyLoop methods() call notify() in a loop until notify() returns a value other than PV_SUCCESS. If the return value is PV_COMPLETED, notify() returns to the caller. Otherwise it exits with a fatal error.

Definition at line 28 of file Subject.hpp.

Member Function Documentation

virtual void PV::Subject::addObserver ( Observer observer)
inlinevirtual

The virtual method for adding an Observer-derived object. Derived classes must override this method to add the object to their hierarchy.

Reimplemented in PV::Checkpointer, and PV::BaseConnection.

Definition at line 37 of file Subject.hpp.

Response::Status PV::Subject::notify ( ObserverTable const &  table,
std::vector< std::shared_ptr< BaseMessage const >>  messages,
bool  printFlag 
)
protected

This method calls the respond() method of each object in the given table, using the given vector of messages. If the table consists of objects A, B, and C; and the messages vector consists of messages X and Y, the order is A->X, A->Y, B->X, B->Y, C->X, C->Y.

The objects' respond() method returns one of the Response::Status types: SUCCESS, NO_ACTION, PARTIAL, or PV_POSTPONE.

SUCCESS: the object completed the task requested by the messages. NO_ACTION: the object has nothing to do in response to the message, or had already done it. PARTIAL: the object has not yet completed but is making progress. It is expected that there are a small number of descrete tasks, so that an object will not return PARTIAL a large number of times in response to the same message. POSTPONE: the object needs to act but cannot do so until an event outside its control occurs.

If all objects return NO_ACTION, then notify() returns NO_ACTION. If all objects return either SUCCESS or NO_ACTION and there is at least one SUCCESS, then notify() returns SUCCESS. If all objects return either POSTPONE or NO_ACTION and there is at least one POSTPONE, then notify() returns POSTPONE. Otherwise, notify() returns PARTIAL.

Generally each message in the messages vector is sent to each object in the table. However, if an object returns POSTPONE in response to a message, the loop skips to the next object, and does not sent any remaining messages to the postponing object.

The rationale behind these rules is so that if the objects in the table are themselves derived from the Subject class, the messages can be passed down the tree and the return values passed up it, and the return value at the top can be interpreted as being over all the components at the bottom, without the topmost object needing to know details of the composition of the objects below it.

If printFlag is true, the method prints information regarding postponement to standard output.

Definition at line 15 of file Subject.cpp.

Response::Status PV::Subject::notify ( ObserverTable const &  table,
std::shared_ptr< BaseMessage const >  message,
bool  printFlag 
)
inlineprotected

A convenience overload of the basic notify method where there is only one message to send to the objects. This overloading handles enclosing the message in a vector of length one.

Definition at line 91 of file Subject.hpp.

void PV::Subject::notifyLoop ( ObserverTable const &  table,
std::vector< std::shared_ptr< BaseMessage const >>  messages,
bool  printFlag,
std::string const &  description 
)
protected

This method calls the notify() method in a loop until the result is not PARTIAL. If it is either POSTPONE, it exits with a fatal error. The description argument is used in the error message to report which message vector failed. If the result is PV_SUCCESS, notifyLoop() returns to the calling function.

notifyLoop should only be used if the objects that might cause a postponement are themselves in the table of objects; otherwise the routine will hang.

Definition at line 57 of file Subject.cpp.

void PV::Subject::notifyLoop ( ObserverTable const &  table,
std::shared_ptr< BaseMessage const >  message,
bool  printFlag,
std::string const &  description 
)
inlineprotected

A convenience overload of the basic notifyLoop method where there is only one message to send to the objects. This overloading handles enclosing the message in a vector of length one.

Definition at line 114 of file Subject.hpp.


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