//-----------------------------------------------------------------------------
//  (c) 2004 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  GenApi
//	Author:  Fritz Dierks
//  $Header: /cvs/genicam/genicam/library/CPP/include/GenApi/Basler/BcamPort.h,v 1.3 2006/03/21 11:46:55 friedrich_dierks Exp $
//-----------------------------------------------------------------------------
/**
\file
\brief    Declaration of the CBcamPort class.
*/

#pragma once

#include <GenApi/Basler/Bcam/bcam.h>
#include <GenApi/Basler/Bcam/hidden.h>
#include <GenApi/Types.h>
#include <GenApi/PortImpl.h>
#include <GenApi/Log.h>

//! Adds the IPort interface to the CBcam class
class CBcamPort : 
	public Bcam::CBcam, 
	public GenApi::CPortImpl
{

public:
	//! Constructor
	CBcamPort();


	//-------------------------------------------------------------
	// IPort implementation
	//-------------------------------------------------------------

	//! Reads a chunk of bytes from the port
	virtual void Read(void *pBuffer, INT64 Address, INT64 Length);

	//! Writes a chunk of bytes to the port
	virtual void Write(const void *pBuffer, INT64 Address, INT64 Length);

	//-------------------------------------------------------------
	// INode implementation
	//-------------------------------------------------------------

	//!	Get	the	access mode	of the node
	virtual	GenApi::EAccessMode	GetAccessMode()	const;

	//-------------------------------------------------------------
	// CBcam overrides 
	//-------------------------------------------------------------

	//! Opens the driver
	void Open( CString DeviceName, HWND hWndNotify = NULL );

	//! Closes the driver and frees all resources (esp. OVERLAPPED structures from cancelled driver calls)
	void Close();

	//! Initialize camera
	void Initialize(); 

	HANDLE GetCompletionPort() const
	{
		return m_hCompletionPort;
	}

	// Raw access functions
protected:
	//! Writes a quadlet into a register
	void WriteRegister( INT64 Address, UINT32 Value );   

	//! Reads a quadlet from a register
	UINT32 ReadRegister( INT64 Address );

	void WriteBlock( INT64 Address, const void* Buffer, UINT32 Length );
	void ReadBlock( INT64 Address, PVOID Buffer, UINT32 Length );

	//! Set into GenICam mode
    void SetGenICamMode();
public:
    void OpenEventGrabber( unsigned short NumBuffer, HANDLE hNotifier );
    void CloseEventGrabber();
    UINT32 RetrieveEvent( void* pBuffer, unsigned BufferSize );
private:
#ifdef LOG4C
        //! Logger for messages concerning the AccessMode
        log4cpp::Category *m_pAccessLog;

        //! Logger for messages concerning the getting and setting values
        log4cpp::Category *m_pValueLog;

        //! Logger for messages concerning the range check
        log4cpp::Category *m_pRangeLog;

        //! Logger for messages concerning the port access
        log4cpp::Category *m_pPortLog;

        //! Logger for messages concerning the caching access
        log4cpp::Category *m_pCacheLog;

        //! Logger for messages concerning administrative access, e.g. GetNode()
        log4cpp::Category *m_pAdminLog;

        //! Logger for messages concerning miscellaneoud access which does not fit to the other categories
        log4cpp::Category *m_pMiscLog;
#endif

};