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.

85 lines
2.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: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgAdvantechDeviceEnumerator.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgAdvantechDeviceEnumerator.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgAdvantechDeviceEnumerator.h"
  16. CLgAdvantechDeviceEnumerator::CLgAdvantechDeviceEnumerator()
  17. {
  18. m_pDeviceList = NULL;
  19. m_nDeviceCount = 0;
  20. }
  21. CLgAdvantechDeviceEnumerator::~CLgAdvantechDeviceEnumerator()
  22. {
  23. Destroy();
  24. }
  25. BOOL CLgAdvantechDeviceEnumerator::Create()
  26. {
  27. // destroy old creature
  28. Destroy();
  29. // get device count
  30. SHORT NumOfDevices;
  31. if( DRV_DeviceGetNumOfList( &NumOfDevices ) != SUCCESS )
  32. {
  33. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgAdvantechDeviceEnumerator::Create", "DRV_DeviceGetNumOfList failed" );
  34. return FALSE;
  35. };
  36. // aloc memory for list
  37. DEVLIST *pDeviceList = (DEVLIST*)malloc( sizeof(DEVLIST) * NumOfDevices );
  38. if( !pDeviceList )
  39. {
  40. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgAdvantechDeviceEnumerator::Create", "Out of memory during device list allocation" );
  41. return FALSE;
  42. }
  43. // get devices info
  44. SHORT FilledNumOfDevices;
  45. if( DRV_DeviceGetList( pDeviceList, NumOfDevices, &FilledNumOfDevices ) != SUCCESS )
  46. {
  47. // free memory for device list
  48. free( pDeviceList );
  49. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, "CLgAdvantechDeviceEnumerator::Create", "DRV_DeviceGetList failed" );
  50. return FALSE;
  51. }
  52. m_pDeviceList = pDeviceList;
  53. m_nDeviceCount = NumOfDevices;
  54. return TRUE;
  55. }
  56. void CLgAdvantechDeviceEnumerator::Destroy()
  57. {
  58. if( m_pDeviceList )
  59. {
  60. free( m_pDeviceList );
  61. m_pDeviceList = NULL;
  62. }
  63. m_nDeviceCount = 0;
  64. }
  65. INT CLgAdvantechDeviceEnumerator::GetDeviceCount()
  66. {
  67. return m_nDeviceCount;
  68. }
  69. DEVLIST* CLgAdvantechDeviceEnumerator::GetDevice( INT nDevice )
  70. {
  71. return ( nDevice >= 0 && nDevice < m_nDeviceCount ) ? m_pDeviceList + nDevice : NULL;
  72. }