//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 05/12/2002 // PROJECT: // SUBSYSTEM: // FILE: LgHWVideoSwitchDevice.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of LgHWVideoSwitchDevice.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "LgHWVideoSwitchDevice.h" #include "LgHWVideoPinInput.h" #include "LgHWVideoPinOutput.h" #include "LgHWVideoSwitchJob.h" CLgHWVideoSwitchDevice::CLgHWVideoSwitchDevice() { // initialize request counter m_nRequestCount = 0; } CLgHWVideoSwitchDevice::~CLgHWVideoSwitchDevice() { Destroy(); } BOOL CLgHWVideoSwitchDevice::Create( INT nInput, INT nOutput ) { // initialize inputs for( INT i = 0; i < nInput; i++ ) { CLgHWVideoPinInput *pInput = new CLgHWVideoPinInput; if( !pInput ) return FALSE; // set pin index pInput->SetIndex( i ); // link input to itself CLgLink::Link( pInput ); } // initialize outputs for( i = 0; i < nOutput; i++ ) { CLgHWVideoPinOutput *pOutput = new CLgHWVideoPinOutput; if( !pOutput ) return FALSE; // set pin index pOutput->SetIndex( i ); // link output to itself CLgLink::Link( pOutput ); } return TRUE; } void CLgHWVideoSwitchDevice::Destroy() { // delete all pins while( CLgLink::GetCount() ) delete *CLgLink::GetAt(0); while( CLgLink::GetCount() ) delete *CLgLink::GetAt(0); } BOOL CLgHWVideoSwitchDevice::Link( CLgLink *pJob ) { if( !CLgLink::Link( pJob ) ) return FALSE; return CheckSwitchJobArray(); } // notification about switching void CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch( INT nInput, INT nOutput ) { CLgArray< CLgLink* >& arrOutput = *this; CLgArray< CLgLink* >& arrInput = *this; // validate input and output if( nInput < 0 || nInput >= arrInput.GetCount() || nOutput < 0 || nOutput >= arrOutput.GetCount() ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Parameters are incorrect (%d,%d)"), nInput, nOutput ); return; } // perform internal interconnection CLgHWVideoPinInput *pInputPin = *arrInput[nInput]; CLgHWVideoPinOutput *pOutputPin = *arrOutput[nOutput]; // unlink previous associations pInputPin->CLgSingleLink::Unlink(); pOutputPin->CLgSingleLink::Unlink(); // establish new association if( !pInputPin->CLgSingleLink::Link( pOutputPin ) ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Link failed") ); return; } CLgArray< CLgLink* >& arrJob = *this; // update jobs array for( INT i = 0; i < arrJob.GetCount(); i++ ) { CLgHWVideoSwitchJob *pJob = *arrJob[i]; if( !pJob ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Job is NULL") ); return; } CLgHWVideoPinInput *pInput = *pJob; CLgHWVideoPinOutput *pOutput = *pJob; if( !pInput || !pOutput ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput ); return; } // if job had been done if( pInput->GetIndex() == nInput && pOutput->GetIndex() == nOutput ) { delete pJob; break; } } // decrease number of issued requests m_nRequestCount--; // start next job CheckSwitchJobArray(); } BOOL CLgHWVideoSwitchDevice::CheckSwitchJobArray() { CLgArray< CLgLink* >& arrJob = *this; // if all jobs had been done or there is outstanding request if( m_nRequestCount || !arrJob.GetCount() ) return TRUE; // get next job CLgHWVideoSwitchJob *pJob = *arrJob[0]; if( !pJob ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::CheckSwitchJobArray"), _T("Job is NULL") ); return FALSE; } // get job pins CLgHWVideoPinInput *pInput = *pJob; CLgHWVideoPinOutput *pOutput = *pJob; if( !pInput || !pOutput ) { LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::CheckSwitchJobArray"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput ); return FALSE; } // start next job if( !HWVideoSwitchDeviceSwitch( pInput->GetIndex(), pOutput->GetIndex() ) ) return FALSE; // increase number of issued requests m_nRequestCount++; return TRUE; }