//
//  Copyright (c) 2001, Reson, Inc. All Rights Reserved.
//
//  Filename:   ConnectedClient.h
//
//  Project:    6046.
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:      

#if !defined(AFX_CONNECTEDCLIENT_H__9CF909FC_8F1B_49CE_9C60_CD28F0F7F275__INCLUDED_)
#define AFX_CONNECTEDCLIENT_H__9CF909FC_8F1B_49CE_9C60_CD28F0F7F275__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include ".\Include\SurveyEventTypes.h"
#include "Alarm.h"

#include <list>

typedef struct tagSUBSCRIPTION
{
    int             m_iSensorIndex;
    unsigned long   m_ulRecordType;

    tagSUBSCRIPTION(    const int           &riSensorIndex = -1,
                        const unsigned long &rulRecordType = 0UL )
    {
        m_iSensorIndex = riSensorIndex;
        m_ulRecordType = rulRecordType;
    }

    virtual ~tagSUBSCRIPTION( void )
    {
        m_iSensorIndex = -1;
        m_ulRecordType = 0UL;
    }

    bool operator == ( const tagSUBSCRIPTION &rRhs ) const
    {
        return ( ( m_iSensorIndex == rRhs.m_iSensorIndex ) && (  m_ulRecordType == rRhs.m_ulRecordType ) );
    }

    bool operator < ( const tagSUBSCRIPTION &rRhs ) const
    {
        bool bIsLess = false;

        if ( m_iSensorIndex < rRhs.m_iSensorIndex )
        {
            bIsLess = true;
        }
        else if ( m_iSensorIndex == rRhs.m_iSensorIndex )
        {
            bIsLess = ( m_ulRecordType < rRhs.m_ulRecordType );
        }

        return bIsLess;
    }
}
SUBSCRIPTION;

class CConnectedClient
{
public:

    ///////////////
    // Services.

                        CConnectedClient        (   const int               &riIndex  = -1 );
                        CConnectedClient        (   const CConnectedClient  &rRhs );

    virtual            ~CConnectedClient        (   void );

    CConnectedClient &  operator =              (   const CConnectedClient  &rRhs );

    bool                operator ==             (   const int               &riIndex ) const;
    bool                operator <              (   const CConnectedClient  &rRhs    ) const;

    bool                Subscribe               (   const int               &riSensorIndex,
                                                    const unsigned long     &rulRecordType );

    bool                Unsubscribe             (   const int               &riSensorIndex,
                                                    const unsigned long     &rulRecordType );

    bool                UnsubscribeAll          (   void );

    bool                IsSubscribedRecord      (   const int               &riSensorIndex,
                                                    const unsigned long     &rulRecordType );

    bool                Verbose                 (   void ) const;
    void                Verbose                 (   const bool              &rbVerbose );

    int                 SocketIndex             (   void ) const;

    bool                IsAlarmReportable       (   const EALARMID          &reAlarmId ) const;

    bool                AlarmMode               (   const EALARMID          &reAlarmId,
                                                    const int               &riAlarmAction );

private:

    ///////////////
    // Definitions.

    typedef std::list<SUBSCRIPTION>             SubscriptionList_t;
    typedef SubscriptionList_t::iterator        SubscriptionListIterator_t;

    typedef std::list<int>                      AlarmSuppressionList_t;
    typedef AlarmSuppressionList_t::iterator    AlarmSuppressionListIterator_t;

    ///////////////
    // Attributes.

    const int                                   m_iInvalidIndex;

    bool                                        m_bVerboseMode;
    int                                         m_iIndex;

    SubscriptionList_t                          m_SubscriptionList;
    mutable AlarmSuppressionList_t              m_AlarmSuppressionList;

};

#endif // !defined(AFX_CONNECTEDCLIENT_H__9CF909FC_8F1B_49CE_9C60_CD28F0F7F275__INCLUDED_)
