//
//  Copyright © 2003, 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:   SubsystemIndex.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    Defines CSubsystemIndex class to assist with defining the association between the 
//              sensor index and the 7k id doublet.
//
//  Notes:      
//

#if !defined(AFX_SUBSYSTEMINDEX_H__CF8A9184_0F1B_4162_8945_19578630198E__INCLUDED_)
#define AFX_SUBSYSTEMINDEX_H__CF8A9184_0F1B_4162_8945_19578630198E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "CallbackDefs.h"

class CSubsystemIndex
{
public:

    ///////////////
    // Services.

    // Construction and assignment.

                            CSubsystemIndex     (   PFN_SUBSYSTEMCALLBACK   pfnCallback             = NULL,
                                                    void                   *pvParam                 = NULL,
                                                    const int              &riSensorIndex           = 0,
                                                    const int              &riSystemIndex           = 0,
                                                    const unsigned long    &rulDeviceId             = 0UL,
                                                    const unsigned short   &runSystemEnumerator     = 0 );

    virtual                ~CSubsystemIndex     (   void );

                            CSubsystemIndex     (   const CSubsystemIndex  &rRhs );
    CSubsystemIndex &       operator =          (   const CSubsystemIndex  &rRhs );

    bool                    SetCallback         (   PFN_SUBSYSTEMCALLBACK   pfnCallback,
                                                    void                   *pvParam );

    bool                    SetDeviceIndicies   (   const int              &riSensorIndex,
                                                    const int              &riSystemIndex,
                                                    const unsigned long    &rulDeviceId,
                                                    const unsigned short   &runSystemEnumerator );

    void                    SystemIndex         (   const int              &riSystemIndex );

    bool                    Is7kSubsystem       (   const unsigned long    &rulDeviceId,
                                                    const unsigned short   &runSystemEnumerator )   const;  // Is specified subsystem by 7k identerfiers.

    bool                    operator ==         (   const int              &riSensorIndex )         const;  // For easy comparison by Sensor Index.

    bool                    operator <          (   const CSubsystemIndex  &rRhs )                  const;  // Is less than for STL sorting.

    void                    operator ()         (   const BYTE             *pbyData,                        // Pointer to 7k record.
                                                    const unsigned long    &rulBytes,                       // Bytes in stream.
                                                    const unsigned long    &rulTimeStamp );                 // Millisecond time stamp.

    // Methods for attribute retrieval.

    int                     SensorIndex         (   void ) const;                                           // Sensor index for which this subsystem refers.

    int                     SystemIndex         (   void ) const;                                           // id of interface descriptor to which the sensor maps.

    unsigned long           DeviceId            (   void ) const;                                           // 7k doublet id's... device id and system enumerator.

    unsigned short          SystemEnumerator    (   void ) const;

private:

    ///////////////
    // Attributes.

    int                     m_iSensorIndex;                                                                 // PLC's sensor index for this subsystem.
    int                     m_iSystemIndex;                                                                 // Interface id to which a given subsystem maps.

    unsigned long           m_ulDeviceId;                                                                   // 7k identification: device id,
    unsigned short          m_unSystemEnumerator;                                                           // system numerator and

    PFN_SUBSYSTEMCALLBACK   m_pfnCallback;                                                                  // Callback function pointer to the C7kSubsystem object.
    void                   *m_pvParam;                                                                      // 'this' pointer for above object.

};

#endif // !defined(AFX_SUBSYSTEMINDEX_H__CF8A9184_0F1B_4162_8945_19578630198E__INCLUDED_)
