//
//  Copyright © 2004, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   Sensor.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Defines an abstract base class for the generic sensor interface.
//
//  Notes:      
//

#if !defined(AFX_SENSOR_H__A0BFDE5D_1E84_4FB8_A6D5_152B24F8F368__INCLUDED_)
#define AFX_SENSOR_H__A0BFDE5D_1E84_4FB8_A6D5_152B24F8F368__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "..\..\ProcessInf.h"
#include "SensorStatus.h"

class EXPORT_DLL CSensor
{
public:

    ///////////////
    // Services.

    // Construction, destrunction and assignment.

                    CSensor             (   const int                  &riSensorIndex = -1 );

                    CSensor             (   const CSensor              &rRhs );

    virtual        ~CSensor             (   void );

    CSensor &       operator =          (   const CSensor              &rRhs );


    bool            IsStarted           (   void )  const;

    int             SensorIndex         (   void )  const;

    void            SensorIndex         (   const   int                &riSensorIndex );

    bool            ActivateOnStartup   (   void )  const;

    unsigned int    DataReadyMessage    (   void )  const;

    unsigned int    ReplyReadyMessage   (   void )  const;

    DWORD           NotifyThreadId      (   void )  const;

    // Operators to support STL containment (e.g. using std::find() and list<>.sort() etc).

    bool            operator ==         (   const int                  &riSensorIndex ) const;

    bool            operator <          (   const CSensor              &rRhs )          const;

    ///////////////
    // Attributes.

protected:

    ///////////////
    // Services.

    // Mandatory sensor interface methods that must be overridden (pure virtual).

    virtual bool    Startup             (   const int                  &riSensorIndex,
                                            const DWORD                &rdwThreadId,
                                            const unsigned int         &ruiDataReadyMessageId,
                                            const unsigned int         &ruiReplyReadyMessageId,
                                            const int                  &riActivateOnStartup )   = 0;

    virtual bool    Shutdown            (   void )                                              = 0;

    virtual bool    Load                (   BYTE                       *pbyData,
                                            unsigned long              *pulSize,
                                            unsigned long              *pulTimeStamp )          = 0;

    virtual bool    SendCommand         (   int                         iClientIndex,
                                            char                       *pszCommand )            = 0;

    virtual bool    RetrieveStatus      (   BYTE                       *pbyData,
                                            unsigned long              *pulSize,
                                            unsigned long              *pulTimeStamp,
                                            int                        *piClientIndex )         = 0;

    virtual bool    IsSensorHealthy     (   void )                                              = 0;

    virtual bool    Reset               (   void )                                              = 0;

    virtual bool    RouteMessage        (   const int                  &riClientIndex,
                                            const BYTE                 *pbyMessage,
                                            const unsigned long        &rulSize,
                                            const unsigned long        &rulTimeStamp )          = 0;

    // Optional non-implemented sensor interface methods.

    virtual bool    Identify            (   SENSORINFO                 *psSensorInfo );

    virtual bool    QueryHealth         (   void );

    // General helpers.

    static int      AddRef              (   void );
    static int      ReleaseRef          (   void );
    static int      RefCount            (   void );

    ///////////////
    // Attributes.

    const int                           m_iInvalidSensorIndex;
    const unsigned int                  m_uiInvalidMessageId;
    const DWORD                         m_dwInvalidThreadId;

    bool                                m_bStarted;

    CSensorStatus                       m_Status;

private:

    ///////////////
    // Attributes.

    static int                          m_iSensorRefCount;

    bool                                m_bActivateOnStartup;

    int                                 m_iSensorIndex;

    unsigned int                        m_uiDataReadyMessageId;
    unsigned int                        m_uiReplyReadyMessageId;

    DWORD                               m_dwThreadId;

};

#endif // !defined(AFX_SENSOR_H__A0BFDE5D_1E84_4FB8_A6D5_152B24F8F368__INCLUDED_)
