Source code of Windows XP (NT5)
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.

229 lines
3.9 KiB

  1. #include "precomp.h"
  2. CHATLoader *g_pCHATLoader = NULL;
  3. CChatObj *g_pChatObj = NULL;
  4. DWORD g_dwWorkThreadID = 0;
  5. CNmChatCtl *g_pChatWindow = NULL;
  6. HANDLE g_hWorkThread = NULL;
  7. BOOL g_fShutdownByT120 = FALSE;
  8. DWORD __stdcall CHATWorkThreadProc(LPVOID lpv);
  9. T120Error CALLBACK CreateAppletLoaderInterface
  10. (
  11. IAppletLoader **ppOutIntf
  12. )
  13. {
  14. if (NULL != ppOutIntf)
  15. {
  16. if (NULL == g_pCHATLoader)
  17. {
  18. DBG_SAVE_FILE_LINE
  19. *ppOutIntf = (IAppletLoader *) new CHATLoader();
  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. // Chat Applet Loader
  28. //
  29. CHATLoader::CHATLoader(void)
  30. :
  31. CRefCount(MAKE_STAMP_ID('C','H','L','D'))
  32. {
  33. ASSERT(NULL == g_pCHATLoader);
  34. g_pCHATLoader = this;
  35. }
  36. CHATLoader::~CHATLoader(void)
  37. {
  38. g_pCHATLoader = NULL;
  39. }
  40. //
  41. // Create the work thread and wait for its being started.
  42. //
  43. APPLDR_RESULT CHATLoader::AppletStartup
  44. (
  45. BOOL fNoUI
  46. )
  47. {
  48. APPLDR_RESULT eRet = APPLDR_FAIL;
  49. if (0 == g_dwWorkThreadID)
  50. {
  51. HANDLE hSync = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  52. if (NULL != hSync)
  53. {
  54. g_hWorkThread = ::CreateThread(NULL, 0, CHATWorkThreadProc, hSync, 0, &g_dwWorkThreadID);
  55. if (NULL != g_hWorkThread)
  56. {
  57. ::WaitForSingleObject(hSync, 5000); // 5 seconds
  58. eRet = APPLDR_NO_ERROR;
  59. }
  60. ::CloseHandle(hSync);
  61. }
  62. }
  63. return eRet;
  64. }
  65. //
  66. APPLDR_RESULT CHATLoader::AppletCleanup
  67. (
  68. DWORD dwTimeout
  69. )
  70. {
  71. if(g_pChatWindow)
  72. {
  73. //
  74. // Last change to save
  75. //
  76. int rc = g_pChatWindow->QueryEndSession();
  77. if(rc == IDCANCEL)
  78. {
  79. return APPLDR_CANCEL_EXIT;
  80. }
  81. }
  82. g_fShutdownByT120 = TRUE;
  83. ::T120_AppletStatus(APPLET_ID_CHAT, APPLET_CLOSING);
  84. // notify the work thread to exit
  85. if(g_pChatWindow)
  86. {
  87. ::PostMessage(g_pChatWindow->GetHandle(), WM_CLOSE, 1, 0);
  88. }
  89. // wait for the worker thread's going down
  90. ::WaitForSingleObject(g_hWorkThread, dwTimeout);
  91. return APPLDR_NO_ERROR;
  92. }
  93. APPLDR_RESULT CHATLoader::AppletQuery(APPLET_QUERY_ID eQueryId)
  94. {
  95. // Do nothing here
  96. return APPLDR_NO_ERROR;
  97. }
  98. APPLDR_RESULT CHATLoader::OnNM2xNodeJoin(void)
  99. {
  100. // Invoke CHAT on NM2.x nodes
  101. if (NULL != g_pChatObj)
  102. {
  103. g_pChatObj->InvokeApplet();
  104. }
  105. return APPLDR_NO_ERROR;
  106. }
  107. APPLDR_RESULT CHATLoader::AppletInvoke
  108. (
  109. BOOL fRemote,
  110. T120ConfID nConfID,
  111. LPSTR pszCmdLine
  112. )
  113. {
  114. if(g_pChatWindow)
  115. {
  116. PostMessage(g_pChatWindow->GetHandle(), WM_USER_BRING_TO_FRONT_WINDOW, 0, 0);
  117. }
  118. return APPLDR_NO_ERROR;
  119. }
  120. void CHATLoader::ReleaseInterface(void)
  121. {
  122. Release();
  123. }
  124. DWORD __stdcall CHATWorkThreadProc(LPVOID lpv)
  125. {
  126. HRESULT hr = S_OK;
  127. DBG_SAVE_FILE_LINE
  128. g_pChatObj = new CChatObj();
  129. if (!g_pChatObj)
  130. {
  131. ERROR_OUT(("Can't create g_pChatObj"));
  132. return S_FALSE;
  133. }
  134. DBG_SAVE_FILE_LINE
  135. g_pChatWindow = new CNmChatCtl();
  136. if (!g_pChatWindow)
  137. {
  138. ERROR_OUT(("Can't create CNmChatCtl"));
  139. return S_FALSE;
  140. }
  141. ::SetEvent((HANDLE) lpv);
  142. ::T120_AppletStatus(APPLET_ID_CHAT, APPLET_WORK_THREAD_STARTED);
  143. PostMessage(g_pChatWindow->GetHandle(), WM_USER_BRING_TO_FRONT_WINDOW, 0, 0);
  144. //
  145. // MESSAGE LOOP
  146. //
  147. if (S_OK == hr)
  148. {
  149. MSG msg;
  150. while (::GetMessage(&msg, NULL, NULL, NULL))
  151. {
  152. if(!g_pChatWindow->FilterMessage(&msg))
  153. {
  154. ::TranslateMessage(&msg);
  155. ::DispatchMessage(&msg);
  156. }
  157. }
  158. }
  159. if(g_pChatWindow)
  160. {
  161. CGenWindow::DeleteStandardPalette();
  162. delete g_pChatWindow;
  163. g_pChatWindow = NULL;
  164. }
  165. if(g_pChatObj)
  166. {
  167. delete g_pChatObj;
  168. g_pChatObj = NULL;
  169. }
  170. ::T120_AppletStatus(APPLET_ID_CHAT, APPLET_WORK_THREAD_EXITED);
  171. g_dwWorkThreadID = 0;
  172. if (! g_fShutdownByT120)
  173. {
  174. ::FreeLibraryAndExitThread(g_hInstance, 0);
  175. }
  176. return 0;
  177. }