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.

333 lines
6.0 KiB

  1. #include "precomp.h"
  2. #include "FtHook.h"
  3. #include "NmManager.h"
  4. #include "NmConference.h"
  5. #include "iAppLdr.h"
  6. namespace CFt
  7. {
  8. static CFtEvents* s_pFtEventsObj = NULL;
  9. static IMbftControl* s_pMbftControl = NULL;
  10. static bool s_bInitialized = false;
  11. static CSimpleArray<IMbftEvents*>* s_pEventSinkArray = NULL;
  12. static CSimpleArray<T120NodeID>* s_pFtMemberList = NULL;
  13. static HINSTANCE s_hmsconfft = NULL;
  14. PFNCREATEMBFTOBJECT pfnFT_CreateInterface;
  15. HRESULT InitFt()
  16. {
  17. pfnFT_CreateInterface = NULL;
  18. s_pEventSinkArray = new CSimpleArray<IMbftEvents*>;
  19. s_pFtMemberList = new CSimpleArray<T120NodeID>;
  20. s_pFtEventsObj = new CFtEvents();
  21. return (s_pFtEventsObj ? S_OK : E_OUTOFMEMORY);
  22. }
  23. bool IsFtActive()
  24. {
  25. return s_bInitialized && s_pMbftControl;
  26. }
  27. HRESULT EnsureLoadFtApplet()
  28. {
  29. HRESULT hr = S_FALSE;
  30. if(T120_NO_ERROR == ::T120_LoadApplet(APPLET_ID_FT,
  31. FALSE,
  32. 0,
  33. _Module.InitControlMode(),
  34. NULL))
  35. {
  36. s_bInitialized = true;
  37. hr = S_OK;
  38. }
  39. return hr;
  40. }
  41. HRESULT ShowFtUI()
  42. {
  43. if(T120_NO_ERROR == ::T120_LoadApplet(APPLET_ID_FT,
  44. TRUE,
  45. 0,
  46. FALSE,
  47. NULL))
  48. {
  49. s_bInitialized = true;
  50. return S_OK;
  51. }
  52. return E_FAIL;
  53. }
  54. HRESULT StartNewConferenceSession()
  55. {
  56. HRESULT hr = E_FAIL;
  57. if(s_bInitialized && !s_pMbftControl)
  58. {
  59. if (S_OK == EnsureLoadFtApplet())
  60. {
  61. ASSERT (s_hmsconfft == NULL);
  62. ASSERT (pfnFT_CreateInterface == NULL);
  63. s_hmsconfft = NmLoadLibrary(_T("nmft.dll"),FALSE);
  64. if (s_hmsconfft)
  65. {
  66. pfnFT_CreateInterface = (PFNCREATEMBFTOBJECT) GetProcAddress(s_hmsconfft, _T("FT_CreateInterface"));
  67. if (pfnFT_CreateInterface)
  68. {
  69. hr = pfnFT_CreateInterface(&s_pMbftControl, s_pFtEventsObj);
  70. ASSERT (SUCCEEDED(hr));
  71. ASSERT (s_pMbftControl);
  72. }
  73. FreeLibrary(s_hmsconfft);
  74. }
  75. s_hmsconfft = NULL;
  76. pfnFT_CreateInterface = NULL;
  77. }
  78. }
  79. return hr;
  80. }
  81. void CloseFtApplet()
  82. {
  83. if(s_pEventSinkArray)
  84. {
  85. ASSERT(0 == s_pEventSinkArray->GetSize());
  86. delete s_pEventSinkArray;
  87. s_pEventSinkArray = NULL;
  88. }
  89. if(s_pFtMemberList)
  90. {
  91. delete s_pFtMemberList;
  92. s_pFtMemberList = NULL;
  93. }
  94. if(s_pFtEventsObj)
  95. {
  96. delete s_pFtEventsObj;
  97. s_pFtEventsObj = NULL;
  98. }
  99. if(s_bInitialized)
  100. {
  101. s_bInitialized = false;
  102. }
  103. }
  104. bool IsMemberInFtSession(T120NodeID gccID)
  105. {
  106. if(s_pFtMemberList)
  107. {
  108. return (-1 != s_pFtMemberList->Find(gccID));
  109. }
  110. return false;
  111. }
  112. HRESULT Advise(IMbftEvents* pSink)
  113. {
  114. HRESULT hr = EnsureLoadFtApplet();
  115. if(s_pEventSinkArray)
  116. {
  117. ASSERT(-1 == s_pEventSinkArray->Find(pSink));
  118. s_pEventSinkArray->Add(pSink);
  119. hr = S_OK;
  120. }
  121. return hr;
  122. }
  123. HRESULT UnAdvise(IMbftEvents* pSink)
  124. {
  125. HRESULT hr = E_UNEXPECTED;
  126. if(s_pEventSinkArray)
  127. {
  128. s_pEventSinkArray->Remove(pSink);
  129. hr = S_OK;
  130. }
  131. return hr;
  132. }
  133. HRESULT CancelFt(MBFTEVENTHANDLE hEvent, MBFTFILEHANDLE hFile)
  134. {
  135. if(s_pMbftControl)
  136. {
  137. s_pMbftControl->CancelFt(hEvent, hFile);
  138. return S_OK;
  139. }
  140. return E_FAIL;
  141. }
  142. HRESULT AcceptFileOffer(MBFT_FILE_OFFER *pOffer, LPCSTR pszRecvFileDir, LPCSTR pszFileName)
  143. {
  144. if(s_pMbftControl)
  145. {
  146. return s_pMbftControl->AcceptFileOffer(pOffer, pszRecvFileDir, pszFileName);
  147. }
  148. return E_FAIL;
  149. }
  150. HRESULT SendFile(LPCSTR pszFileName,
  151. T120NodeID gccID,
  152. MBFTEVENTHANDLE *phEvent,
  153. MBFTFILEHANDLE *phFile)
  154. {
  155. if(s_pMbftControl)
  156. {
  157. return s_pMbftControl->SendFile(pszFileName, gccID, phEvent, phFile);
  158. }
  159. return E_FAIL;
  160. }
  161. // IMbftEvent Interface
  162. STDMETHODIMP CFtEvents::OnInitializeComplete(void)
  163. {
  164. if(s_pEventSinkArray)
  165. {
  166. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  167. {
  168. (*s_pEventSinkArray)[i]->OnInitializeComplete();
  169. }
  170. }
  171. return S_OK;
  172. }
  173. STDMETHODIMP CFtEvents::OnPeerAdded(MBFT_PEER_INFO *pInfo)
  174. {
  175. if(s_pFtMemberList)
  176. {
  177. if(-1 == s_pFtMemberList->Find(pInfo->NodeID))
  178. {
  179. s_pFtMemberList->Add(pInfo->NodeID);
  180. }
  181. }
  182. if(s_pEventSinkArray)
  183. {
  184. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  185. {
  186. (*s_pEventSinkArray)[i]->OnPeerAdded(pInfo);
  187. }
  188. }
  189. return S_OK;
  190. }
  191. STDMETHODIMP CFtEvents::OnPeerRemoved(MBFT_PEER_INFO *pInfo)
  192. {
  193. if(s_pFtMemberList)
  194. {
  195. s_pFtMemberList->Remove(pInfo->NodeID);
  196. }
  197. if(s_pEventSinkArray)
  198. {
  199. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  200. {
  201. (*s_pEventSinkArray)[i]->OnPeerRemoved(pInfo);
  202. }
  203. }
  204. return S_OK;
  205. }
  206. STDMETHODIMP CFtEvents::OnFileOffer(MBFT_FILE_OFFER *pOffer)
  207. {
  208. if(s_pEventSinkArray)
  209. {
  210. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  211. {
  212. (*s_pEventSinkArray)[i]->OnFileOffer(pOffer);
  213. }
  214. }
  215. return S_OK;
  216. }
  217. STDMETHODIMP CFtEvents::OnFileProgress(MBFT_FILE_PROGRESS *pProgress)
  218. {
  219. if(s_pEventSinkArray)
  220. {
  221. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  222. {
  223. (*s_pEventSinkArray)[i]->OnFileProgress(pProgress);
  224. }
  225. }
  226. return S_OK;
  227. }
  228. STDMETHODIMP CFtEvents::OnFileEnd(MBFTFILEHANDLE hFile)
  229. {
  230. if(s_pEventSinkArray)
  231. {
  232. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  233. {
  234. (*s_pEventSinkArray)[i]->OnFileEnd(hFile);
  235. }
  236. }
  237. return S_OK;
  238. }
  239. STDMETHODIMP CFtEvents::OnFileError(MBFT_EVENT_ERROR *pEvent)
  240. {
  241. if(s_pEventSinkArray)
  242. {
  243. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  244. {
  245. (*s_pEventSinkArray)[i]->OnFileError(pEvent);
  246. }
  247. }
  248. return S_OK;
  249. }
  250. STDMETHODIMP CFtEvents::OnFileEventEnd(MBFTEVENTHANDLE hEvent)
  251. {
  252. if(s_pEventSinkArray)
  253. {
  254. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  255. {
  256. (*s_pEventSinkArray)[i]->OnFileEventEnd(hEvent);
  257. }
  258. }
  259. return S_OK;
  260. }
  261. STDMETHODIMP CFtEvents::OnSessionEnd(void)
  262. {
  263. if(s_pFtMemberList)
  264. {
  265. s_pFtMemberList->RemoveAll();
  266. }
  267. if(s_pEventSinkArray)
  268. {
  269. for(int i = 0; i < s_pEventSinkArray->GetSize(); ++i)
  270. {
  271. (*s_pEventSinkArray)[i]->OnSessionEnd();
  272. }
  273. }
  274. if(s_pMbftControl)
  275. {
  276. s_pMbftControl->ReleaseInterface();
  277. s_pMbftControl = NULL;
  278. }
  279. return S_OK;
  280. }
  281. }; // end namespace CFt