Leaked source code of windows server 2003
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.

233 lines
4.4 KiB

  1. #include "precomp.h"
  2. #include "wbloader.h"
  3. #include "nmwbobj.h"
  4. WBLoader *g_pWBLoader = NULL;
  5. HANDLE g_hWorkThread = NULL;
  6. BOOL g_fShutdownByT120 = FALSE;
  7. DWORD __stdcall WBWorkThreadProc(LPVOID lpv);
  8. TCHAR g_PassedFileName [MAX_PATH * 2];
  9. T120Error CALLBACK CreateAppletLoaderInterface
  10. (
  11. IAppletLoader **ppOutIntf
  12. )
  13. {
  14. if (NULL != ppOutIntf)
  15. {
  16. if (NULL == g_pWBLoader)
  17. {
  18. DBG_SAVE_FILE_LINE
  19. *ppOutIntf = (IAppletLoader *) new WBLoader();
  20. return ((NULL != *ppOutIntf) ? T120_NO_ERROR : T120_ALLOCATION_FAILURE);
  21. }
  22. return T120_ALREADY_INITIALIZED;
  23. }
  24. return T120_INVALID_PARAMETER;
  25. }
  26. //
  27. // FT Applet Loader
  28. //
  29. WBLoader::WBLoader(void)
  30. :
  31. CRefCount(MAKE_STAMP_ID('W','B','L','D'))
  32. {
  33. ASSERT(NULL == g_pWBLoader);
  34. g_pWBLoader = this;
  35. }
  36. WBLoader::~WBLoader(void)
  37. {
  38. ASSERT(this == g_pWBLoader);
  39. g_pWBLoader = NULL;
  40. }
  41. //
  42. // Create the work thread and wait for its being started.
  43. //
  44. APPLDR_RESULT WBLoader::AppletStartup
  45. (
  46. BOOL fNoUI
  47. )
  48. {
  49. APPLDR_RESULT eRet = APPLDR_FAIL;
  50. if (0 == g_dwWorkThreadID)
  51. {
  52. HANDLE hSync = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  53. if (NULL != hSync)
  54. {
  55. g_hWorkThread = ::CreateThread(NULL, 0, WBWorkThreadProc, hSync, 0, &g_dwWorkThreadID);
  56. if (NULL != g_hWorkThread)
  57. {
  58. ::WaitForSingleObject(hSync, 5000); // 5 seconds
  59. // ASSERT(g_pNMWBOBJ);
  60. eRet = APPLDR_NO_ERROR;
  61. }
  62. ::CloseHandle(hSync);
  63. }
  64. }
  65. return eRet;
  66. }
  67. //
  68. APPLDR_RESULT WBLoader::AppletCleanup
  69. (
  70. DWORD dwTimeout
  71. )
  72. {
  73. if (g_pMain)
  74. {
  75. //
  76. // Last change to save
  77. //
  78. int rc = g_pMain->QuerySaveRequired(TRUE);
  79. if (rc == IDYES)
  80. {
  81. rc = (int)g_pMain->OnSave(FALSE);
  82. }
  83. if (rc == IDCANCEL)
  84. {
  85. return APPLDR_CANCEL_EXIT;
  86. }
  87. }
  88. g_fShutdownByT120 = TRUE;
  89. ::T120_AppletStatus(APPLET_ID_WB, APPLET_CLOSING);
  90. // notify the work thread to exit
  91. ::PostThreadMessage(g_dwWorkThreadID, WM_QUIT, 0, 0);
  92. // wait for the worker thread's going down
  93. ::WaitForSingleObject(g_hWorkThread, dwTimeout);
  94. return APPLDR_NO_ERROR;
  95. }
  96. APPLDR_RESULT WBLoader::AppletQuery(APPLET_QUERY_ID eQueryId)
  97. {
  98. // Do nothing now
  99. return APPLDR_NO_ERROR;
  100. }
  101. APPLDR_RESULT WBLoader::OnNM2xNodeJoin(void)
  102. {
  103. // Do nothing now
  104. return APPLDR_NO_ERROR;
  105. }
  106. APPLDR_RESULT WBLoader::AppletInvoke
  107. (
  108. BOOL fRemote,
  109. T120ConfID nConfID,
  110. LPSTR pszCmdLine
  111. )
  112. {
  113. ::ZeroMemory(&g_PassedFileName, sizeof(g_PassedFileName));
  114. if(pszCmdLine)
  115. {
  116. lstrcpy(g_PassedFileName, pszCmdLine);
  117. if(g_pMain)
  118. {
  119. PostMessage(g_pMain->m_hwnd, WM_USER_LOAD_FILE, 0, 0);
  120. }
  121. }
  122. TRACE_MSG((">>>>AppletInvoke g_pMain = %x",g_pMain));
  123. if(g_pMain)
  124. {
  125. PostMessage(g_pMain->m_hwnd, WM_USER_BRING_TO_FRONT_WINDOW, 0, 0);
  126. }
  127. return APPLDR_NO_ERROR;
  128. }
  129. void WBLoader::ReleaseInterface(void)
  130. {
  131. Release();
  132. }
  133. DWORD __stdcall WBWorkThreadProc(LPVOID lpv)
  134. {
  135. HRESULT hr = S_OK;
  136. ::SetEvent((HANDLE) lpv);
  137. DBG_SAVE_FILE_LINE
  138. g_pNMWBOBJ = new CNMWbObj();
  139. if (NULL == g_pNMWBOBJ || NULL == g_pMain)
  140. {
  141. ERROR_OUT(("WB_Startup: cannot create CNMWbObj"));
  142. hr = E_OUTOFMEMORY;
  143. }
  144. if(*g_PassedFileName)
  145. {
  146. PostMessage(g_pMain->m_hwnd, WM_USER_LOAD_FILE, 0, 0);
  147. }
  148. ::T120_AppletStatus(APPLET_ID_WB, APPLET_WORK_THREAD_STARTED);
  149. TRACE_MSG((">>>>WBWorkThreadProc APPLET_WORK_THREAD_STARTED"));
  150. if(g_pMain)
  151. {
  152. PostMessage(g_pMain->m_hwnd, WM_USER_BRING_TO_FRONT_WINDOW, 0, 0);
  153. }
  154. //
  155. // MESSAGE LOOP
  156. //
  157. if (S_OK == hr)
  158. {
  159. MSG msg;
  160. while (::GetMessage(&msg, NULL, NULL, NULL))
  161. {
  162. if (!g_pMain->FilterMessage(&msg))
  163. {
  164. ::TranslateMessage(&msg);
  165. ::DispatchMessage(&msg);
  166. }
  167. }
  168. }
  169. if(g_pNMWBOBJ)
  170. {
  171. delete g_pNMWBOBJ;
  172. g_pNMWBOBJ = NULL;
  173. }
  174. ::T120_AppletStatus(APPLET_ID_WB, APPLET_WORK_THREAD_EXITED);
  175. g_dwWorkThreadID = 0;
  176. TRACE_MSG((">>>>WBWorkThreadProc APPLET_WORK_THREAD_EXITED"));
  177. if (! g_fShutdownByT120)
  178. {
  179. FreeLibraryAndExitThread(g_hInstance, 0);
  180. }
  181. return 0;
  182. }
  183.