You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
5.2 KiB
179 lines
5.2 KiB
//----------------------------------------------------------------------------
|
|
// 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<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::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<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::Link( pOutput );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgHWVideoSwitchDevice::Destroy()
|
|
{
|
|
// delete all pins
|
|
while( CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::GetCount() )
|
|
delete *CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::GetAt(0);
|
|
|
|
while( CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::GetCount() )
|
|
delete *CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::GetAt(0);
|
|
}
|
|
|
|
BOOL CLgHWVideoSwitchDevice::Link( CLgLink<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice> *pJob )
|
|
{
|
|
if( !CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoSwitchJob>::Link( pJob ) )
|
|
return FALSE;
|
|
|
|
return CheckSwitchJobArray();
|
|
}
|
|
|
|
// notification about switching
|
|
void CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch( INT nInput, INT nOutput )
|
|
{
|
|
CLgArray< CLgLink<CLgHWVideoPinOutput,CLgHWVideoSwitchDevice>* >& arrOutput = *this;
|
|
CLgArray< CLgLink<CLgHWVideoPinInput,CLgHWVideoSwitchDevice>* >& 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<CLgHWVideoSwitch,CLgHWVideoSwitch>::Unlink();
|
|
pOutputPin->CLgSingleLink<CLgHWVideoSwitch,CLgHWVideoSwitch>::Unlink();
|
|
|
|
// establish new association
|
|
if( !pInputPin->CLgSingleLink<CLgHWVideoSwitch,CLgHWVideoSwitch>::Link( pOutputPin ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Link failed") );
|
|
return;
|
|
}
|
|
|
|
CLgArray< CLgLink<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice>* >& 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<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice>* >& 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;
|
|
}
|
|
|