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

#ifndef MESSAGINGCOMPONENT_H_
#define MESSAGINGCOMPONENT_H_

#include "Component.h"

/** Abstract Base class for messaging software components.
 *
 *  \ingroup component
 *
 */
class MessagingComponent: public Component
{

public:

    virtual ~MessagingComponent();

    /// Overloads the coponent's excution loop to include messaging
    virtual void execute( void );

    /// Checks for broadcast requests and activates/deactivates messaging accordingly
    virtual bool broadcastRequested( void );

    /// Virtual function, implementation should contain the actions required for activating messaging
    virtual void activateMessaging( void )
    {
        return;
    };

    /// Virtual function, implementation should contain the actions required for
    /// deactivating messaging
    virtual void deactivateMessaging( void )
    {
        return;
    };

    /// Virtual function, implementation should contain all actions required for
    /// publishing the component's messages
    virtual bool publish( void )
    {
        return false;
    }

    /// True when enabled
    const bool broadcastEnabled( void ) const
    {
        return broadcastEnabled_;
    }

    /// Overides Component to instantiate MessagingDataWriters
    DataWriter* newDataWriter( const DataURI& dataURI,
                               Logger::TimePrecisionType timePrecision = Logger::TIME_PRECISION_MILLIS );

    /// Overides Component to instantiate MessagingDataWriters with desgniated channel name
    DataWriter* newDataWriter( const Str& channel,
                               const DataURI& dataURI,
                               Logger::TimePrecisionType timePrecision = Logger::TIME_PRECISION_MILLIS );

protected:
    /// Protected constructor for messaging components
    MessagingComponent( const Str& name, ComponentType componentType, const Module* module );

    /// Protected constructor for messaging components
    MessagingComponent( const Str& name, ComponentType componentType, const Module* module, const DataURI& enableBroadcast );

    /// Enables broadcasting when true
    virtual void enableBroadcast( bool enable )
    {
        broadcastEnabled_ = enable;
    }

    /// Holds the component's enableBroadcast writer
    /// The component uses this writer's isDataRequested interface to enable/disable
    /// messaging broadcast
    DataWriter* enableBroadcastWriter_;

    /// True when broadcasting is enabled
    bool broadcastEnabled_;

};

#endif /* MESSAGINGCOMPONENT_H_ */
