/** \file
 *
 *  Contains the BackseatDriver class declaration.
 *
 *  BackseatDriver.h should only be included by BackseatDriver.cpp
 *  Other classes should include BackseatDriverIF.h
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef BACKSEATDRIVER_H_
#define BACKSEATDRIVER_H_

#include "component/Behavior.h"
#include "supervisor/LcmSlateBridge.h"

class UniversalDataReader;

/**
 *  Contains the BackseatDriver Behavior
 *
 *  BackseatDriver.h should only be included by BackseatDriver.cpp
 *  Other classes should include BackseatDriverIF.h
 *
 *  \ingroup modules_guidance
 **/

class BackseatDriver : public Behavior
{
public:

    BackseatDriver( const Str& prefix, const Module* module );

    virtual ~BackseatDriver();

    /// Initialize function
    void initialize( void );

    /// Read in the parameters for satisfied or runIfUnsatisfied: return true if OK.
    void readParams( void );

    /// Perform the satisfied: return true if envelope "satisfied"
    bool calcSatisfied( void );

    /// Just do the run: ignore the results of the satisfied
    void run( void );

    /// Just do the satisfied: return true if envelope "satisfied"
    bool isSatisfied( void );

    /// Do the run, and return true if envelope "satisfied"
    bool runIfUnsatisfied( void );

    /// Uninit function
    void uninitialize( void );

    /// Mission Component factory interface
    static Behavior* CreateBehavior( const Str& prefix, const Module* module );

protected:

    /// Handle incomming LMC-Slate messages
    LcmSlateBridge lcmBridge_;

    // Slate setting inputs
    SettingReader* channelSettingReader_;
    SettingReader* sourceIdSettingReader_;
    SettingReader* powerBackseatSettingReader_;

    // Slate configuration inputs
    ConfigReader* lcmListenerTimeoutCfgReader_;

    // Other Slate inputs
    //DataReader* lcmUniversalBroadcastReader_;
    DataReader* powerBackseatCompReader_;
    DataReader* lcmHeartbeatReader_;

    // LCM outputs
    DataWriter* lcmHeartbeatWriter_;

    /// Max timespan to block while waiting for LCM msg
    Timespan lcmHandleTimeout_;

    /// Max timespan with no LCM updates
    Timespan timeoutCfg_;

    /// Marks the msg handeling start time
    Timestamp startTime_;

    /// Indicates whether or not behavior is requesting backseat power/data
    int powerBackseat_;

    /// Indicates behavior has been initialized
    bool initialized_;

    bool debug_;

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    BackseatDriver( const BackseatDriver& old ); // disallow copy constructor

    // Actually initialize backseat power and comms
    void initComms( void );

};

#endif /*BACKSEATDRIVER_H_*/
