SCFLoader.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "stdafx.h"
  2. #include "SCFLoader.h"
  3. using namespace DIOS::Dev::Detail::MachineryECOM;
  4. #ifdef _WIN64
  5. #ifdef _DEBUG
  6. const string SCFFile = "SerialSCFX64D.dll";
  7. #else
  8. const string SCFFile = "SerialSCFX64.dll";
  9. #endif
  10. #else
  11. #ifdef _DEBUG
  12. const string SCFFile = "SerialSCFD.dll";
  13. #else
  14. const string SCFFile = "SerialSCF.dll";
  15. #endif
  16. #endif
  17. using namespace nsSCF;
  18. SCFLoader *SCFLoader::m_instance = nullptr;
  19. SCFLoader::SCFLoader() :m_DllFileHandle(0), m_SCFInstance(nullptr)
  20. {
  21. }
  22. SCFLoader::~SCFLoader()
  23. {
  24. //if (m_DllFileHandle)
  25. //{
  26. // typedef void(*ReleaseSCF)(SCF *p);
  27. // ReleaseSCF dpcfunc = (ReleaseSCF)GetProcAddress(m_DllFileHandle, "ReleseSCF");
  28. // if (dpcfunc)
  29. // {
  30. // dpcfunc(m_SCFInstance);
  31. // }
  32. //}
  33. }
  34. SCFLoader *SCFLoader::Instance()
  35. {
  36. if (m_instance == nullptr)
  37. {
  38. m_instance = new SCFLoader();
  39. //m_instance->Initialize();
  40. }
  41. return m_instance;
  42. }
  43. void SCFLoader::Initialize(nsSCF::SCF* pSCF)
  44. {
  45. //m_DllFileHandle = LoadLibrary(SCFFile.c_str());
  46. //if (!m_DllFileHandle)
  47. //{
  48. // if(gdriverLog) gdriverLog->Error("DIOSBoardController Initialize Load library %s Failed.ErrorNo:%d", SCFFile.c_str(), GetLastError());
  49. //}
  50. //typedef SCF* (*GetSCF)();
  51. //GetSCF getSCF;
  52. //getSCF = (GetSCF)GetProcAddress(m_DllFileHandle, "GetSCF");
  53. //m_SCFInstance = getSCF();
  54. m_SCFInstance = pSCF;
  55. if (!m_SCFInstance)
  56. {
  57. if(gdriverLog) gdriverLog->Error("Load library {$}::GetSCF Action Failed", SCFFile.c_str());
  58. }
  59. }
  60. SCF* SCFLoader::GetSCFInstance()
  61. {
  62. //if (!m_SCFInstance)
  63. //{
  64. // Initialize();
  65. //}
  66. return m_SCFInstance;
  67. }
  68. SCFPacket *SCFLoader::CreateSingletonSCFPacket(const std::string &name)
  69. {
  70. if (m_scfPackets.find(name) == m_scfPackets.end())
  71. {
  72. auto packet = (SCFPacket *)MallocSCFPacket();
  73. m_scfPackets[name] = packet;
  74. }
  75. return m_scfPackets[name];
  76. }
  77. void SCFLoader::ReleaseSCFPacket(const std::string &name)
  78. {
  79. if (m_scfPackets.find(name) != m_scfPackets.end())
  80. {
  81. ::ReleaseSCFPacket(m_scfPackets[name]);
  82. m_scfPackets.erase(name);
  83. }
  84. }