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.

214 lines
5.0 KiB

  1. #include "mbftpch.h"
  2. #include "ftldr.h"
  3. #include "ftui.h"
  4. // #include "SDKInternal.h"
  5. CFtLoader *g_pFtLoader = NULL;
  6. BOOL g_fNoUI = FALSE;
  7. extern void ReadSettingsFromRegistry(void);
  8. extern void LoadDefaultStrings(void);
  9. extern DWORD __stdcall FTWorkThreadProc(LPVOID lpv);
  10. extern HANDLE g_hWorkThread;
  11. extern BOOL g_fShutdownByT120;
  12. T120Error WINAPI CreateAppletLoaderInterface
  13. (
  14. IAppletLoader **ppOutIntf
  15. )
  16. {
  17. if (NULL != ppOutIntf)
  18. {
  19. *ppOutIntf = NULL;
  20. if (NULL == g_pFtLoader)
  21. {
  22. ::ReadSettingsFromRegistry();
  23. ::LoadDefaultStrings();
  24. if (g_fSendAllowed || g_fRecvAllowed)
  25. {
  26. DBG_SAVE_FILE_LINE
  27. *ppOutIntf = (IAppletLoader *) new CFtLoader();
  28. return ((NULL != *ppOutIntf) ? T120_NO_ERROR : T120_ALLOCATION_FAILURE);
  29. }
  30. return T120_POLICY_PROHIBIT;
  31. }
  32. return T120_ALREADY_INITIALIZED;
  33. }
  34. return T120_INVALID_PARAMETER;
  35. }
  36. //
  37. // FT Applet Loader
  38. //
  39. CFtLoader::CFtLoader(void)
  40. :
  41. CRefCount(MAKE_STAMP_ID('F','T','L','D'))
  42. {
  43. ASSERT(NULL == g_pFtLoader);
  44. g_pFtLoader = this;
  45. }
  46. CFtLoader::~CFtLoader(void)
  47. {
  48. ASSERT(this == g_pFtLoader);
  49. g_pFtLoader = NULL;
  50. }
  51. //
  52. // Create the work thread and wait for its being started.
  53. //
  54. APPLDR_RESULT CFtLoader::AppletStartup
  55. (
  56. BOOL fNoUI
  57. )
  58. {
  59. APPLDR_RESULT eRet = APPLDR_FAIL;
  60. if (0 == g_dwWorkThreadID)
  61. {
  62. g_fNoUI = fNoUI;
  63. ASSERT(NULL == g_pFileXferApplet);
  64. HANDLE hSync = ::CreateEvent(NULL, FALSE, FALSE, NULL);
  65. if (NULL != hSync)
  66. {
  67. g_hWorkThread = ::CreateThread(NULL, 0, FTWorkThreadProc, hSync, 0, &g_dwWorkThreadID);
  68. if (NULL != g_hWorkThread)
  69. {
  70. DWORD dwRet = ::WaitForSingleObject(hSync, FT_STARTUP_TIMEOUT);
  71. // ASSERT(NULL != g_pFileXferApplet);
  72. eRet = APPLDR_NO_ERROR;
  73. }
  74. ::CloseHandle(hSync);
  75. }
  76. }
  77. TCHAR szRecvFolder[MAX_PATH];
  78. ::GetRecvFolder(NULL, szRecvFolder);
  79. return eRet;
  80. }
  81. APPLDR_RESULT CFtLoader::AppletCleanup
  82. (
  83. DWORD dwTimeout
  84. )
  85. {
  86. ::EnterCriticalSection(&g_csWorkThread);
  87. if (NULL != g_pFileXferApplet)
  88. {
  89. if (! g_pFileXferApplet->QueryShutdown(TRUE))
  90. {
  91. ::LeaveCriticalSection(&g_csWorkThread);
  92. return APPLDR_CANCEL_EXIT;
  93. }
  94. }
  95. ::LeaveCriticalSection(&g_csWorkThread);
  96. //
  97. // shut down the worker thread now
  98. //
  99. g_fShutdownByT120 = TRUE;
  100. T120_AppletStatus(APPLET_ID_FT, APPLET_CLOSING);
  101. // shuting down the work thread
  102. ASSERT(::GetCurrentThreadId() != g_dwWorkThreadID);
  103. if (NULL != g_pFileXferApplet)
  104. { // Shutdown MBFTInterface ourself to make things simpler
  105. MSG msg;
  106. MBFTEngine *pEngine = g_pFileXferApplet->FindEngineWithIntf();
  107. if (pEngine)
  108. {
  109. DBG_SAVE_FILE_LINE
  110. InitUnInitNotifyMsg *pMsg = new InitUnInitNotifyMsg(EnumInvoluntaryUnInit);
  111. pEngine->GetInterfacePointer()->HandleInitUninitNotification(pMsg);
  112. delete pMsg;
  113. }
  114. }
  115. // shut down by T.120
  116. ::EnterCriticalSection(&g_csWorkThread);
  117. // remember the event such that the work thread can access it
  118. if (NULL != g_pFileXferApplet)
  119. {
  120. CAppletWindow *pWindow;
  121. CWindowList *pList = g_pFileXferApplet->GetWindowList();
  122. pList->Reset();
  123. while (NULL != (pWindow = pList->Iterate()))
  124. {
  125. BOOL fRet = ::PostMessage(pWindow->GetHwnd(), WM_CLOSE, 0, 0);
  126. ASSERT(fRet);
  127. }
  128. } // if applet ptr
  129. ::LeaveCriticalSection(&g_csWorkThread);
  130. // wait for the worker thread's going down
  131. DWORD dwRet = ::WaitForSingleObject(g_hWorkThread, dwTimeout);
  132. return APPLDR_NO_ERROR;
  133. }
  134. APPLDR_RESULT CFtLoader::AppletQuery(APPLET_QUERY_ID eQueryId)
  135. {
  136. ::EnterCriticalSection(&g_csWorkThread);
  137. if (NULL != g_pFileXferApplet)
  138. {
  139. switch (eQueryId)
  140. {
  141. case APPLET_QUERY_SHUTDOWN:
  142. // Don't really shuts down
  143. if (! g_pFileXferApplet->QueryShutdown(FALSE))
  144. {
  145. ::LeaveCriticalSection(&g_csWorkThread);
  146. return APPLDR_CANCEL_EXIT;
  147. }
  148. break;
  149. }
  150. }
  151. ::LeaveCriticalSection(&g_csWorkThread);
  152. return APPLDR_NO_ERROR;
  153. }
  154. APPLDR_RESULT CFtLoader::OnNM2xNodeJoin(void)
  155. {
  156. // Do nothing here
  157. return APPLDR_NO_ERROR;
  158. }
  159. APPLDR_RESULT CFtLoader::AppletInvoke
  160. (
  161. BOOL fLocal,
  162. T120ConfID nConfID,
  163. LPSTR pszCmdLine
  164. )
  165. {
  166. // fLocal == TRUE ==> local invoke
  167. if (fLocal && g_pFileXferApplet) // Only bring UI to front for local invoke
  168. {
  169. ::PostMessage(g_pFileXferApplet->GetHiddenWnd(), WM_BRING_TO_FRONT, 0, 0);
  170. }
  171. return APPLDR_NO_ERROR;
  172. }
  173. void CFtLoader::ReleaseInterface(void)
  174. {
  175. Release();
  176. }