/** \file
 *
 *  Contains the AsyncComponent class definition.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef ASYNCCOMPONENT_H_
#define ASYNCCOMPONENT_H_

#include "LcmMessagingComponent.h"

/** Abstract Base class for software components that run independently
 * from the computation cycle. Use with care!
 *
 *  \ingroup component
 *
 */
class AsyncComponent: public LcmMessagingComponent
{

public:

    bool isIdlePriority()
    {
        return idlePriority_;
    }

protected:

    /// Protected constructor for components that run in periodic asynchronous threads
    AsyncComponent( const Str& name, const Module* module, const Timespan period, bool idlePriority = false )
        : LcmMessagingComponent( name, COMPONENT_ASYNC, module ),
          idlePriority_( idlePriority )
    {
        setState( BLOCK_PERIODIC );
        setPeriod( period );
    }

    /// Protected constructor for components that run in continuous asynchronous threads
    AsyncComponent( const Str& name, const Module* module, bool idlePriority = false )
        : LcmMessagingComponent( name, COMPONENT_ASYNC, module ),
          idlePriority_( idlePriority )
    {
        setState( BLOCK_CONTINUOUS );
    }

    bool idlePriority_;

};

#endif /* ASYNCCOMPONENT_H_ */
