Old fashion design for PC-104
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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 05/12/2002
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgHWVideoSwitchDevice.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgHWVideoSwitchDevice.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgHWVideoSwitchDevice.h"
  16. #include "LgHWVideoPinInput.h"
  17. #include "LgHWVideoPinOutput.h"
  18. #include "LgHWVideoSwitchJob.h"
  19. CLgHWVideoSwitchDevice::CLgHWVideoSwitchDevice()
  20. {
  21. // initialize request counter
  22. m_nRequestCount = 0;
  23. }
  24. CLgHWVideoSwitchDevice::~CLgHWVideoSwitchDevice()
  25. {
  26. Destroy();
  27. }
  28. BOOL CLgHWVideoSwitchDevice::Create( INT nInput, INT nOutput )
  29. {
  30. // initialize inputs
  31. for( INT i = 0; i < nInput; i++ )
  32. {
  33. CLgHWVideoPinInput *pInput = new CLgHWVideoPinInput;
  34. if( !pInput )
  35. return FALSE;
  36. // set pin index
  37. pInput->SetIndex( i );
  38. // link input to itself
  39. CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::Link( pInput );
  40. }
  41. // initialize outputs
  42. for( i = 0; i < nOutput; i++ )
  43. {
  44. CLgHWVideoPinOutput *pOutput = new CLgHWVideoPinOutput;
  45. if( !pOutput )
  46. return FALSE;
  47. // set pin index
  48. pOutput->SetIndex( i );
  49. // link output to itself
  50. CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::Link( pOutput );
  51. }
  52. return TRUE;
  53. }
  54. void CLgHWVideoSwitchDevice::Destroy()
  55. {
  56. // delete all pins
  57. while( CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::GetCount() )
  58. delete *CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinInput>::GetAt(0);
  59. while( CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::GetCount() )
  60. delete *CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoPinOutput>::GetAt(0);
  61. }
  62. BOOL CLgHWVideoSwitchDevice::Link( CLgLink<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice> *pJob )
  63. {
  64. if( !CLgLink<CLgHWVideoSwitchDevice,CLgHWVideoSwitchJob>::Link( pJob ) )
  65. return FALSE;
  66. return CheckSwitchJobArray();
  67. }
  68. // notification about switching
  69. void CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch( INT nInput, INT nOutput )
  70. {
  71. CLgArray< CLgLink<CLgHWVideoPinOutput,CLgHWVideoSwitchDevice>* >& arrOutput = *this;
  72. CLgArray< CLgLink<CLgHWVideoPinInput,CLgHWVideoSwitchDevice>* >& arrInput = *this;
  73. // validate input and output
  74. if( nInput < 0 || nInput >= arrInput.GetCount() || nOutput < 0 || nOutput >= arrOutput.GetCount() )
  75. {
  76. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Parameters are incorrect (%d,%d)"), nInput, nOutput );
  77. return;
  78. }
  79. // perform internal interconnection
  80. CLgHWVideoPinInput *pInputPin = *arrInput[nInput];
  81. CLgHWVideoPinOutput *pOutputPin = *arrOutput[nOutput];
  82. // unlink previous associations
  83. pInputPin->CLgSingleLink<CLgHWVideoSwitch,CLgHWVideoSwitch>::Unlink();
  84. pOutputPin->CLgSingleLink<CLgHWVideoSwitch,CLgHWVideoSwitch>::Unlink();
  85. // establish new association
  86. if( !pInputPin->CLgSingleLink<CLgHWVideoSwitch,CLgHWVideoSwitch>::Link( pOutputPin ) )
  87. {
  88. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Link failed") );
  89. return;
  90. }
  91. CLgArray< CLgLink<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice>* >& arrJob = *this;
  92. // update jobs array
  93. for( INT i = 0; i < arrJob.GetCount(); i++ )
  94. {
  95. CLgHWVideoSwitchJob *pJob = *arrJob[i];
  96. if( !pJob )
  97. {
  98. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Job is NULL") );
  99. return;
  100. }
  101. CLgHWVideoPinInput *pInput = *pJob;
  102. CLgHWVideoPinOutput *pOutput = *pJob;
  103. if( !pInput || !pOutput )
  104. {
  105. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::OnHWVideoSwitchDeviceSwitch"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput );
  106. return;
  107. }
  108. // if job had been done
  109. if( pInput->GetIndex() == nInput && pOutput->GetIndex() == nOutput )
  110. {
  111. delete pJob;
  112. break;
  113. }
  114. }
  115. // decrease number of issued requests
  116. m_nRequestCount--;
  117. // start next job
  118. CheckSwitchJobArray();
  119. }
  120. BOOL CLgHWVideoSwitchDevice::CheckSwitchJobArray()
  121. {
  122. CLgArray< CLgLink<CLgHWVideoSwitchJob,CLgHWVideoSwitchDevice>* >& arrJob = *this;
  123. // if all jobs had been done or there is outstanding request
  124. if( m_nRequestCount || !arrJob.GetCount() )
  125. return TRUE;
  126. // get next job
  127. CLgHWVideoSwitchJob *pJob = *arrJob[0];
  128. if( !pJob )
  129. {
  130. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::CheckSwitchJobArray"), _T("Job is NULL") );
  131. return FALSE;
  132. }
  133. // get job pins
  134. CLgHWVideoPinInput *pInput = *pJob;
  135. CLgHWVideoPinOutput *pOutput = *pJob;
  136. if( !pInput || !pOutput )
  137. {
  138. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitchDevice::CheckSwitchJobArray"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput );
  139. return FALSE;
  140. }
  141. // start next job
  142. if( !HWVideoSwitchDeviceSwitch( pInput->GetIndex(), pOutput->GetIndex() ) )
  143. return FALSE;
  144. // increase number of issued requests
  145. m_nRequestCount++;
  146. return TRUE;
  147. }