MiddleWares_YiHe 郑州颐和医院随访系统中间件

SystemLauncher.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "StdAfx.h"
  2. #include "SystemLauncher.h"
  3. #include "DeviceMgr.h"
  4. #include "NetworkVs.h"
  5. #include "Config.h"
  6. #include "../Public/DaemonClient/DaemonClient.h"
  7. CSystemLauncher::CSystemLauncher(void)
  8. {
  9. }
  10. /*****************************************************************
  11. **【函数名称】 __openTts
  12. **【函数功能】 打开TTS
  13. **【参数】
  14. **【返回值】
  15. ****************************************************************/
  16. void CSystemLauncher::__openTts( void )
  17. {
  18. TTS_TYPE TtsType = CConfig::ttsType();
  19. if(TtsType != TTS_NONE)
  20. {
  21. CHAR szErrCode[BUFFER_LENGTH];
  22. if(ITtsInterface::getInstance().init(TtsType, CConfig::ttsPath(), szErrCode))
  23. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, _T("{Core}: TTS打开成功"));
  24. else
  25. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_WARNING, _T("{Core}: TTS打开失败, Reason = %s"), szErrCode);
  26. }
  27. }
  28. /*****************************************************************
  29. **【函数名称】 __closeTts
  30. **【函数功能】 关闭TTS
  31. **【参数】
  32. **【返回值】
  33. ****************************************************************/
  34. void CSystemLauncher::__closeTts( void )
  35. {
  36. if(CConfig::ttsType() != TTS_NONE)
  37. ITtsInterface::getInstance().close();
  38. }
  39. /*****************************************************************
  40. **【函数名称】 stage1Start
  41. **【函数功能】 第一阶段启动
  42. **【参数】
  43. **【返回值】
  44. ****************************************************************/
  45. bool CSystemLauncher::stage1Start( void )
  46. {
  47. // 连接配置数据库
  48. if(!IOtlConnection::getInstance()->Connect())
  49. {
  50. AfxMessageBox(STR_ERR_INIT_DB_CONN);
  51. return false;
  52. }
  53. // 加载配置
  54. if(!CConfig::load())
  55. {
  56. // 断开数据库连接
  57. IOtlConnection::getInstance()->Disconnect();
  58. AfxMessageBox(STR_ERR_INIT_CFG_LOAD);
  59. return false;
  60. }
  61. return true;
  62. }
  63. /*****************************************************************
  64. **【函数名称】 stage2Start
  65. **【函数功能】 第二阶段启动
  66. **【参数】
  67. **【返回值】
  68. ****************************************************************/
  69. bool CSystemLauncher::stage2Start( void )
  70. {
  71. __openTts();
  72. if(!CDeviceMgr::GetInstance().initDev())
  73. {
  74. // 断开数据库连接
  75. IOtlConnection::getInstance()->Disconnect();
  76. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_INIT_DEV_OPEN);
  77. return false;
  78. }
  79. if(!CNetworkVs::GetInstance().init())
  80. {
  81. CDeviceMgr::GetInstance().closeDev();
  82. // 断开数据库连接
  83. IOtlConnection::getInstance()->Disconnect();
  84. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("%s"), STR_ERR_INIT_NET_SETUP);
  85. return false;
  86. }
  87. CDaemonClient::GetInstance().doWork();
  88. return true;
  89. }
  90. /*****************************************************************
  91. **【函数名称】 stop
  92. **【函数功能】 停止
  93. **【参数】
  94. **【返回值】
  95. ****************************************************************/
  96. void CSystemLauncher::stop( void )
  97. {
  98. CNetworkVs::GetInstance().release();
  99. CDeviceMgr::GetInstance().closeDev();
  100. __closeTts();
  101. IOtlConnection::getInstance()->Disconnect();
  102. ILogger::getInstance().close();
  103. }