AppGlobalF.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. //---------------------------------------------------------------------------
  4. #include <vcl.h>
  5. #include <assert.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <memory.h>
  10. #include <Systobj.h>
  11. #include <winsock.h>
  12. #include <time.h>
  13. #include <Buttons.hpp>
  14. #include <Classes.hpp>
  15. #include <ComCtrls.hpp>
  16. #include <Controls.hpp>
  17. #include <Chart.hpp>
  18. #include <DB.hpp>
  19. #include <DBClient.hpp>
  20. #include <DBGrids.hpp>
  21. #include <DBXpress.hpp>
  22. #include <Dialogs.hpp>
  23. #include <ExtCtrls.hpp>
  24. #include <FMTBcd.hpp>
  25. #include <Forms.hpp>
  26. #include <Graphics.hpp>
  27. #include <Grids.hpp>
  28. #include <jpeg.hpp>
  29. #include <Mask.hpp>
  30. #include <Menus.hpp>
  31. #include <Messages.hpp>
  32. #include <OleCtrls.hpp>
  33. #include <Outline.hpp>
  34. #include <Provider.hpp>
  35. #include <SqlExpr.hpp>
  36. #include <StdCtrls.hpp>
  37. #include <System.hpp>
  38. #include <SysUtils.hpp>
  39. #include <Types.hpp>
  40. #include <Windows.hpp>
  41. #include <inifiles.hpp>
  42. //---------------------------------------------------------------------------
  43. #include "AppGlobalF.h"
  44. //---------------------------------------------------------------------------
  45. #pragma package(smart_init)
  46. //---------------------------------------------------------------------------
  47. /*
  48. ******************************************************************************
  49. * Global variables
  50. ******************************************************************************
  51. */
  52. APP_CONFIG g_AppCfg;
  53. LOG_INFO g_LogCfg;
  54. TITSLog *ITSLog = NULL;
  55. TITSLog *FDbLog = NULL;
  56. bool LOGIN_CHECK = false;
  57. bool LOAD_DB = false;
  58. /**
  59. * TODO: 20220816: 종료처리를 위해 플래그 추가
  60. **/
  61. bool APP_EXIT = false;
  62. SYSTEM_INFORMATION *g_SysInfo;
  63. //---------------------------------------------------------------------------
  64. bool APP_LoadConfigInfo()
  65. {
  66. String sCfgFile;
  67. TIniFile *pIniFile = NULL;
  68. sCfgFile = g_sCfgDir + g_sAppName + ".ini";
  69. g_AppCfg.sConfigFile = sCfgFile;
  70. DATABASE_INFO *pDb;
  71. try
  72. {
  73. String sTmp;
  74. pIniFile = new TIniFile(sCfgFile);
  75. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "VMS Communication Server");
  76. g_AppCfg.sSystemId = pIniFile->ReadString("APPLICATION", "SYSTEMID", "VMS01");
  77. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "30101");
  78. g_AppCfg.nProcessId = g_AppCfg.sProcessId.ToIntDef(0);
  79. g_AppCfg.nProcessPort = pIniFile->ReadInteger("APPLICATION", "PROCESSPORT", 5301);;
  80. g_AppCfg.bSendCenterComm = false;
  81. g_AppCfg.DownloadBitmap = (bool)pIniFile->ReadInteger("APPLICATION", "DOWNLOADBITMAP", 0);
  82. LOGIN_CHECK = (bool)pIniFile->ReadInteger("APPLICATION", "LOGINCHECK", 1);
  83. LOAD_DB = pIniFile->ReadString("APPLICATION", "LOADDB", "1").ToIntDef(1) == 1 ? true : false;
  84. g_sFtpDir = pIniFile->ReadString("APPLICATION", "FTPHOMEDIR", g_sFtpDir);
  85. if (g_sFtpDir.SubString(g_sFtpDir.Length(), 1) != "\\")
  86. g_sFtpDir += "\\";
  87. g_AppCfg.sManagerApp= pIniFile->ReadString("APPLICATION", "MANAGERAPP", "");
  88. if (g_AppCfg.sManagerApp != "")
  89. {
  90. if (!FileExists(g_AppCfg.sManagerApp))
  91. {
  92. g_AppCfg.sManagerApp = "";
  93. }
  94. }
  95. g_AppCfg.nTrafficCycleTime = pIniFile->ReadInteger("APPLICATION", "TrafficCycleTime", 300);
  96. if (g_AppCfg.nTrafficCycleTime < 60) g_AppCfg.nTrafficCycleTime = 60;
  97. g_AppCfg.nTrafficBasisTime = pIniFile->ReadInteger("APPLICATION", "TrafficBasisTime", 60);
  98. g_AppCfg.nSaveFormType = pIniFile->ReadInteger("APPLICATION", "SaveFormType", 0);
  99. if (g_AppCfg.nSaveFormType < 0 || g_AppCfg.nSaveFormType > 2) g_AppCfg.nSaveFormType = 0;
  100. g_AppCfg.nDefaultFillColor = pIniFile->ReadInteger("APPLICATION", "DefaultFillColor", 0);
  101. g_AppCfg.MaxMemory = pIniFile->ReadInteger("RESOURCE", "MAXMEMORY", 512);
  102. g_AppCfg.MaxHandle = pIniFile->ReadInteger("RESOURCE", "MAXHANDLE", 0);
  103. g_AppCfg.MaxThread = pIniFile->ReadInteger("RESOURCE", "MAXTHREAD", 4096);
  104. g_AppCfg.MaxGdi = pIniFile->ReadInteger("RESOURCE", "MAXGDI", 0);
  105. g_AppCfg.RcRestart = (bool)pIniFile->ReadInteger("RESOURCE", "RESTART", 0);
  106. g_AppCfg.comm.nCenterPort = pIniFile->ReadInteger("COMMUNICATION", "CENTERPORT", 6000);
  107. g_AppCfg.comm.nListenPort = pIniFile->ReadInteger("COMMUNICATION", "LISTENPORT", 6020);
  108. g_AppCfg.comm.sLocalDomain = pIniFile->ReadString ("COMMUNICATION", "LOCALDOMAIN", "VMS_SERVER");
  109. g_AppCfg.comm.nClientPort = pIniFile->ReadInteger("COMMUNICATION", "CLIENTPORT", 355);
  110. g_AppCfg.comm.sLoginUser = pIniFile->ReadString ("COMMUNICATION", "LOGINUSER", "ysvms");
  111. g_AppCfg.comm.sLoginPswd = pIniFile->ReadString ("COMMUNICATION", "LOGINPSWD", "ysvms");
  112. g_AppCfg.comm.nConnectWait = pIniFile->ReadInteger("COMMUNICATION", "CONNECTWAIT", 60);
  113. g_AppCfg.comm.nCmdTimeOut = pIniFile->ReadInteger("COMMUNICATION", "CMDTIMEOUT", 5);
  114. g_AppCfg.comm.nWatchDogTime = pIniFile->ReadInteger("COMMUNICATION", "WATCHDOGTIME", 30);
  115. g_AppCfg.comm.nPollingTime = pIniFile->ReadInteger("COMMUNICATION", "POLLINGTIME", 20);
  116. if (g_AppCfg.comm.nPollingTime < 10) g_AppCfg.comm.nPollingTime = 10;
  117. if (g_AppCfg.comm.nPollingTime > 90) g_AppCfg.comm.nPollingTime = 90;
  118. g_AppCfg.nCenterCommLogLevel = pIniFile->ReadInteger("COMMUNICATION", "CenterCommLogLevel", 0);
  119. if (g_AppCfg.comm.nConnectWait < 30) g_AppCfg.comm.nConnectWait = 30;
  120. if (g_AppCfg.comm.nConnectWait > 60) g_AppCfg.comm.nConnectWait = 60;
  121. if (g_AppCfg.comm.nCmdTimeOut < 5) g_AppCfg.comm.nCmdTimeOut = 5;
  122. if (g_AppCfg.comm.nWatchDogTime < 30) g_AppCfg.comm.nWatchDogTime = 30;
  123. g_AppCfg.comm.nWatchDogTime += 5; // 5초정도를 더 추가해 준다(딜레이발생할 경우)
  124. pDb = &g_AppCfg.db;
  125. pDb->sProvider = pIniFile->ReadString("DATABASE", "PROVIDER", "");
  126. pDb->sServerName = pIniFile->ReadString("DATABASE", "SERVERNAME", "");
  127. pDb->sCatalog = pIniFile->ReadString("DATABASE", "CATALOG", "");
  128. pDb->sUserName = pIniFile->ReadString("DATABASE", "USERNAME", "");
  129. pDb->sPassword = pIniFile->ReadString("DATABASE", "PASSWORD", "");
  130. pDb->MakeConnString();
  131. try
  132. {
  133. g_AppCfg.nMaxLogLines = pIniFile->ReadInteger("LOG", "LOGLINE", 200);
  134. if (g_AppCfg.nMaxLogLines > 1000) g_AppCfg.nMaxLogLines = 1000;
  135. if (g_AppCfg.nMaxLogLines < 0) g_AppCfg.nMaxLogLines = 100;
  136. g_AppCfg.sLogDay = pIniFile->ReadString ("LOG", "LOGDAY", "");
  137. g_LogCfg.Info = (bool)pIniFile->ReadInteger("LOG", "INFO", 1);
  138. g_LogCfg.Data = (bool)pIniFile->ReadInteger("LOG", "DATA", 0);
  139. g_LogCfg.Error = (bool)pIniFile->ReadInteger("LOG", "ERROR", 1);
  140. g_LogCfg.Warning = (bool)pIniFile->ReadInteger("LOG", "WARNING", 1);
  141. g_LogCfg.Debug = (bool)pIniFile->ReadInteger("LOG", "DEBUG", 0);
  142. g_LogCfg.Detail = (bool)pIniFile->ReadInteger("LOG", "DETAIL", 0);
  143. g_LogCfg.Detail = 0;
  144. } catch(Exception &e) {}
  145. g_AppCfg.bThrExit = false;
  146. }
  147. __finally
  148. {
  149. if (pIniFile) delete pIniFile;
  150. pIniFile = NULL;
  151. }
  152. return true;
  153. }
  154. //---------------------------------------------------------------------------
  155. int ITSUtil_Trace(const char *lpszFormat, ...)
  156. {
  157. static HWND m_TraceHandle = 0;
  158. int nBuf;
  159. char szBuffer[4097];
  160. va_list args;
  161. DWORD dwError = GetLastError();
  162. if (m_TraceHandle == 0)
  163. {
  164. //m_TraceHandle = ::FindWindow(L"TFormTrace", NULL);
  165. //m_TraceHandle = FindWindow(NULL, (LPCTSTR)"Trace");
  166. m_TraceHandle = FindWindow(NULL, "TracePlus");
  167. }
  168. if (!m_TraceHandle)
  169. return -1;
  170. memset(szBuffer, 0x00, sizeof(szBuffer));
  171. va_start(args, lpszFormat);
  172. nBuf = vsprintf(szBuffer, lpszFormat, args);
  173. va_end(args);
  174. if (nBuf < 0) return -1;
  175. //wsprintf(szBuffer + strlen(szBuffer), "|14|%s|%d|%d|%d|%d|%s|%s", process, level, mode, color, m.line, m.func, m.file);
  176. //sprintf(szBuffer + strlen(szBuffer), "|14|%s|%d|%d|%d|%d|%s|%s", lpszFileName, 0, 3, 0, nLineNo, " ", lpszFileName);
  177. nBuf = strlen(szBuffer);
  178. COPYDATASTRUCT cds;
  179. cds.dwData = 0;
  180. cds.cbData = nBuf + 1;
  181. cds.lpData = (void *)szBuffer;
  182. int iLength = ::SendMessage(m_TraceHandle, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
  183. if(iLength == 0)
  184. {
  185. m_TraceHandle = 0;
  186. dwError = GetLastError();
  187. }
  188. return 0;
  189. }
  190. //---------------------------------------------------------------------------