CLAM-Development  1.4.0
Public Types | Public Member Functions | Protected Member Functions
CLAM::PortMonitor< TheDataType, ThePortType > Class Template Reference

A processing that allows other (GUI) thread to monitor a port in a thread safe way. More...

#include <PortMonitor.hxx>

List of all members.

Public Types

typedef TheDataType DataType
typedef ThePortType PortType
- Public Types inherited from CLAM::Processing
enum  ExecState { Unconfigured = 0, Ready, Running }
 Processing Object possible execution states. More...
typedef NullProcessingConfig Config

Public Member Functions

 PortMonitor (const Config &cfg=Config())
virtual ~PortMonitor ()
bool Do ()
 Supervised mode execution method (using ports)
const char * GetClassName () const
 Override it in every subclass and retur the name of that class.
const DataTypeFreezeAndGetData ()
void UnfreezeData ()
void AttachStartSlot (SigSlot::Slotv0 &slot)
void AttachStopSlot (SigSlot::Slotv0 &slot)
void AttachSlotNewData (SigSlot::Slotv0 &slot)
template<>
bool Do ()
 Supervised mode execution method (using ports)
template<>
 PortMonitor (const Config &cfg)
template<>
bool Do ()
 Supervised mode execution method (using ports)
template<>
 PortMonitor (const Config &cfg)
- Public Member Functions inherited from CLAM::Processing
bool Configure (const ProcessingConfig &config)
 Configuration change method.
void Start (void)
 Method to turn the object into running state.
void Stop (void)
 Method to put the object out of running state When in execution mode, this method must be called before any further call to Configure() methods.
 Processing ()
virtual ~Processing ()
virtual bool CanProcessInplace ()
 Override this method if your processing cannot process inplace.
bool CanConsumeAndProduce ()
 Check that Supervised Do() can be safely called.
void ConsumeAndProduce ()
 Acknoledges data tokens in published ports as read/writen by calling Produce() for all registered OutPorts and Consume() to all registered InPorts.
virtual const ProcessingConfigGetConfig () const
 Configuration getter.
std::string GetExecStateString () const
bool IsConfigured () const
bool IsRunning () const
void RegisterOutPort (OutPortBase *out)
void RegisterInPort (InPortBase *in)
void RegisterOutControl (OutControlBase *out)
void RegisterInControl (InControlBase *in)
void SetParent (Processing *p)
void SetNetworkBackLink (Network *network)
virtual bool ModifiesPortsAndControlsAtConfiguration ()
 This method is used to determine if a given processing can change its interface of ports/controls after its construction (i.e.
bool HasInPort (const std::string &name)
bool HasOutPort (const std::string &name)
bool HasInControl (const std::string &name)
bool HasOutControl (const std::string &name)
InPortBaseGetInPort (const std::string &name)
OutPortBaseGetOutPort (const std::string &name)
InControlBaseGetInControl (const std::string &name)
OutControlBaseGetOutControl (const std::string &name)
InPortBaseGetInPort (unsigned index)
OutPortBaseGetOutPort (unsigned index)
InControlBaseGetInControl (unsigned index)
OutControlBaseGetOutControl (unsigned index)
unsigned GetNInPorts () const
unsigned GetNOutPorts () const
unsigned GetNInControls () const
unsigned GetNOutControls () const
const std::string & GetConfigErrorMessage () const
 Returns a string describing configuration errors if any.
virtual bool IsSyncSource () const
 Wether the processing is a sync source such as audio i/o device, or an audio callback hook (i.e.
virtual bool SupportsVariableAudioSize () const
 This method reports whether the processing supports dynamic buffer-size host.

Protected Member Functions

bool ConcreteStart ()
 Processing objects have to redefine this method when starting them implies some internal changes.
bool ConcreteStop ()
 Processing objects have to redefine this method when stoping them implies some internal changes.
- Protected Member Functions inherited from CLAM::Processing
virtual bool ConcreteConfigure (const ProcessingConfig &)
 Configuration method interface.
unsigned BackendBufferSize ()
 Given by the NetworkPlayer (backend) if exists.
unsigned BackendSampleRate ()
 Given by the NetworkPlayer (backend) if exists.
InControlRegistryGetInControls ()
 Accessor to published Controls manager.
OutControlRegistryGetOutControls ()
 Accessor to published Controls manager.
InPortRegistryGetInPorts ()
 Accessor to published Ports manager.
OutPortRegistryGetOutPorts ()
 Accessor to published Portss manager.
bool AddConfigErrorMessage (const std::string &msg)
 Use this method to append a configuration errors to the processing when implementing ConcreteConfigure.
bool AbleToExecute (void) const
 In debug-mode checks that the processing is configured and started.
template<typename ConcreteConfig >
void CopyAsConcreteConfig (ConcreteConfig &concrete, const ProcessingConfig &abstract) const
 Helper template to convert a reference to a ProcessingConfig to the concrete ProcessingConfig specified on the first parameter.
void SetExecState (ExecState state)

Additional Inherited Members

- Protected Attributes inherited from CLAM::Processing
ProcessingCompositempParent
 Pointer to the parent (composite) processing object, or 0.
Network_network
 The parent network if any.

Detailed Description

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
class CLAM::PortMonitor< TheDataType, ThePortType >

A processing that allows other (GUI) thread to monitor a port in a thread safe way.

Subclass specializations of this template in order to use it.

class SpectrumPortMonitor : public CLAM::PortMonitor<CLAM::Spectrum>
{
public:
const char * GetClassName() const {return "SpectrumPortMonitor";}
};

In order to get data from a GUI thread you should use a PortMonitor::DataLocker

// Supose 'monitor' being a SpectrumPortMonitor reference.
...
{
const Spectrum & spectrum = monitor.FreezeAndGetData();
// The monitor won't overwrite the current copy until Release.
// Do what ever with the object
visualize(spectrum);
monitor.UnfreezeData();
// After unfreezing, 'spectrum' is not safe to use.
// and the monitor will be allowed to swap copies
}

Definition at line 53 of file PortMonitor.hxx.


Member Typedef Documentation

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
typedef TheDataType CLAM::PortMonitor< TheDataType, ThePortType >::DataType

Definition at line 56 of file PortMonitor.hxx.

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
typedef ThePortType CLAM::PortMonitor< TheDataType, ThePortType >::PortType

Definition at line 57 of file PortMonitor.hxx.


Constructor & Destructor Documentation

template<typename PortDataType , typename PortType >
CLAM::PortMonitor< PortDataType, PortType >::PortMonitor ( const Config cfg = Config())
inline

Definition at line 103 of file PortMonitor.hxx.

References CLAM::Processing::Configure(), and CLAM::Hidden::initData().

template<typename PortDataType , typename PortType >
CLAM::PortMonitor< PortDataType, PortType >::~PortMonitor ( )
inlinevirtual

Definition at line 113 of file PortMonitor.hxx.

template<>
CLAM::PortMonitor< Audio, AudioInPort >::PortMonitor ( const Config cfg)

Definition at line 24 of file PortMonitor.cxx.

References CLAM::Processing::Configure().

template<>
CLAM::PortMonitor< Audio, AudioInPort >::PortMonitor ( const Config cfg)

Member Function Documentation

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
void CLAM::PortMonitor< TheDataType, ThePortType >::AttachSlotNewData ( SigSlot::Slotv0 slot)
inline

Definition at line 71 of file PortMonitor.hxx.

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
void CLAM::PortMonitor< TheDataType, ThePortType >::AttachStartSlot ( SigSlot::Slotv0 slot)
inline

Definition at line 69 of file PortMonitor.hxx.

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
void CLAM::PortMonitor< TheDataType, ThePortType >::AttachStopSlot ( SigSlot::Slotv0 slot)
inline

Definition at line 70 of file PortMonitor.hxx.

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
bool CLAM::PortMonitor< TheDataType, ThePortType >::ConcreteStart ( void  )
inlineprotectedvirtual

Processing objects have to redefine this method when starting them implies some internal changes.

ie: adquiring resources.

Returns:
Whether start changes have been successful

Reimplemented from CLAM::Processing.

Definition at line 74 of file PortMonitor.hxx.

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
bool CLAM::PortMonitor< TheDataType, ThePortType >::ConcreteStop ( )
inlineprotectedvirtual

Processing objects have to redefine this method when stoping them implies some internal changes.

ie: releasing resources.

Returns:
Whether stop changes have been successful

Reimplemented from CLAM::Processing.

Definition at line 75 of file PortMonitor.hxx.

template<>
bool CLAM::PortMonitor< Audio, AudioInPort >::Do ( )
virtual

Supervised mode execution method (using ports)

Returns:
A boolean telling whether it has been output

Implements CLAM::Processing.

Definition at line 8 of file PortMonitor.cxx.

References CLAM::Hidden::ScopedTryLock< TryMutexType >::Locked().

template<typename PortDataType , typename PortType >
bool CLAM::PortMonitor< PortDataType, PortType >::Do ( )
inlinevirtual

Supervised mode execution method (using ports)

Returns:
A boolean telling whether it has been output

Implements CLAM::Processing.

Definition at line 131 of file PortMonitor.hxx.

References CLAM::Hidden::ScopedTryLock< TryMutexType >::Locked().

template<>
bool CLAM::PortMonitor< Audio, AudioInPort >::Do ( )
virtual

Supervised mode execution method (using ports)

Returns:
A boolean telling whether it has been output

Implements CLAM::Processing.

template<typename PortDataType , typename PortType >
const PortMonitor< PortDataType, PortType >::DataType & CLAM::PortMonitor< PortDataType, PortType >::FreezeAndGetData ( )
inline

Definition at line 118 of file PortMonitor.hxx.

References CLAM::Hidden::LockOps< MutexType >::Lock().

template<typename TheDataType, typename ThePortType = InPort<TheDataType>>
const char* CLAM::PortMonitor< TheDataType, ThePortType >::GetClassName ( ) const
inlinevirtual
template<typename PortDataType , typename PortType >
void CLAM::PortMonitor< PortDataType, PortType >::UnfreezeData ( )
inline

Definition at line 125 of file PortMonitor.hxx.

References CLAM::Hidden::LockOps< MutexType >::Unlock().


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