//
//  Copyright © 2002 - 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:   SecondaryHandling.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:      
//

#if !defined(AFX_SECONDARYHANDLING_H__A128D720_EB8F_4987_B732_CEAEDE933E7C__INCLUDED_)
#define AFX_SECONDARYHANDLING_H__A128D720_EB8F_4987_B732_CEAEDE933E7C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "..\Utils\NetUtils\Critical.h"
#include "..\Utils\NetUtils\BaseThread.h"
#include "..\Utils\NetUtils\PLCSensorData.h"

class CLogger;                                                              // Forward definition.

class CSecondaryHandling : protected CBaseThread
{
public:

                                CSecondaryHandling              (   const CLogger          *pLogger );
    virtual                    ~CSecondaryHandling              (   void );

    void                        ThreadProcessing                (   const bool             &rbEnable );

private:

    ///////////////
    //

    enum ETHREADMESSAGES                                                    // Recognised thread messages.
    {
        messageCriticalParameterUpdate = threadMessageTerminate + 1,        // Sensor has notified of a critial system parameter update.
    };

    ///////////////
    // Attributes.

    const unsigned long         m_ulMaxBufferSize;
    const CLogger              *m_pLogger;

    bool                        m_bProcessingEnable;
    unsigned long               m_ulNextRecordToRead;

    CCritical                   m_FlagsCriticalSection;

    CPLCReadSensorData         *m_pSensorData;
    BYTE                       *m_pby7kRecord;

    HANDLE                      m_hTerminateEvent;

    ///////////////
    // Services.

    bool                        InitializeThreadObjects         (   void );

    bool                        TerminateThreadObjects          (   void );

    void                        ProcessEvents                   (   const HANDLE           *phEvents,
                                                                    const DWORD            &rdwHandleIndex );

    bool                        ProcessQueuedSensorData         (   void );

    bool                        DispatchToSubscribingClients    (   const BYTE             *pbyData,
                                                                    const unsigned long    &rulSize,
                                                                    const unsigned long    &rulTimestamp,
                                                                    const int              &riSensorIndex );

    bool                        HandleProcessing                (   const BYTE             *pbyData,
                                                                    const unsigned long    &rulSize,
                                                                    const unsigned long    &rulTimestamp,
                                                                    const int              &riSensorIndex );

    // Overrides for CBaseThread's virtual members.

    BOOL                        ProcessMessage                  (   MSG                    *psMsg );
    void                        WatchCycle                      (   void );

                                CSecondaryHandling              (   void );                                         // Not implemented thus private.
                                CSecondaryHandling              (   const CSecondaryHandling   &rRhs );             // Not implemented thus private.
    CSecondaryHandling &        operator =                      (   const CSecondaryHandling   &rRhs );             // Not implemented thus private.

};

#endif // !defined(AFX_SECONDARYHANDLING_H__A128D720_EB8F_4987_B732_CEAEDE933E7C__INCLUDED_)
