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

#ifndef LCMMESSAGINGCOMPONENT_H_
#define LCMMESSAGINGCOMPONENT_H_


#include "MessagingComponent.h"
#include "data/LcmMsgWriter.h"
#include "utils/FastMap.h"

/**
 * Abstract Base class for messaging software components publishing data via LCM.
 *
 *  \ingroup component
 */
class LcmMessagingComponent: public MessagingComponent
{
public:

    virtual ~LcmMessagingComponent();

    /// Creates and populates the LCM channels
    virtual void activateMessaging( void );

    /// Destroys the LCM channels
    virtual void deactivateMessaging( void );

    /// Sets the LCM channel fot ALL of the component's writer
    virtual void setChannelName( const Str& channleName );

    /// Routes the DataElement to the correct LCM channel for assignment
    virtual bool setMessage( const Str& channel, const DataElement& dataElement );

    /// Publishes the component's LCM messages
    virtual bool publish( void );

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

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

    /// Retrieves an LcmMsgWriter matching the channel name key.
    /// Creates a new <channel name, LcmMsgWriter> pair with the designated channel name
    /// if not found.
    LcmMsgWriter* getLcmMsg( const Str& channelName );

    /// Holds the component's LCM channels
    FastMap< const Str, LcmMsgWriter* > lcmMsgMap_;

};

#endif /* LCMMESSAGINGCOMPONENT_H_ */
