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.

709 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. status.cpp
  5. Abstract:
  6. This module implements the status interface/object.
  7. Author:
  8. Wesley Witt (wesw) 20-May-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "faxcom.h"
  13. #include "status.h"
  14. CFaxStatus::CFaxStatus()
  15. {
  16. m_pFaxPort = NULL;
  17. m_Tsid = NULL;
  18. m_Description = NULL;
  19. m_RecipientName = NULL;
  20. m_SenderName = NULL;
  21. m_RoutingString = NULL;
  22. m_Address = NULL;
  23. m_DocName = NULL;
  24. m_DeviceName = NULL;
  25. m_Csid = NULL;
  26. m_CallerId = NULL;
  27. m_Receive = FALSE;
  28. m_Send = FALSE;
  29. m_PageCount = 0;
  30. m_DocSize = 0;
  31. m_DeviceId = 0;
  32. m_CurrentPage = 0;
  33. ZeroMemory( &m_StartTime, sizeof(m_StartTime) );
  34. ZeroMemory( &m_SubmittedTime, sizeof(m_SubmittedTime) );
  35. ZeroMemory( &m_ElapsedTime, sizeof(m_ElapsedTime) );
  36. }
  37. CFaxStatus::~CFaxStatus()
  38. {
  39. if (m_pFaxPort) {
  40. m_pFaxPort->Release();
  41. }
  42. FreeMemory();
  43. }
  44. void CFaxStatus::FreeMemory()
  45. {
  46. if (m_Tsid) {
  47. SysFreeString( m_Tsid );
  48. }
  49. if (m_Description) {
  50. SysFreeString( m_Description );
  51. }
  52. if (m_RecipientName) {
  53. SysFreeString( m_RecipientName );
  54. }
  55. if (m_SenderName) {
  56. SysFreeString( m_SenderName );
  57. }
  58. if (m_RoutingString) {
  59. SysFreeString( m_RoutingString );
  60. }
  61. if (m_Address) {
  62. SysFreeString( m_Address );
  63. }
  64. if (m_DocName) {
  65. SysFreeString( m_DocName );
  66. }
  67. if (m_DeviceName) {
  68. SysFreeString( m_DeviceName );
  69. }
  70. if (m_Csid) {
  71. SysFreeString( m_Csid );
  72. }
  73. if (m_CallerId) {
  74. SysFreeString( m_CallerId );
  75. }
  76. m_Tsid = NULL;
  77. m_Description = NULL;
  78. m_RecipientName = NULL;
  79. m_SenderName = NULL;
  80. m_RoutingString = NULL;
  81. m_Address = NULL;
  82. m_DocName = NULL;
  83. m_DeviceName = NULL;
  84. m_Csid = NULL;
  85. m_CallerId = NULL;
  86. m_Receive = FALSE;
  87. m_Send = FALSE;
  88. m_PageCount = 0;
  89. m_DocSize = 0;
  90. m_DeviceId = 0;
  91. m_CurrentPage = 0;
  92. ZeroMemory( &m_StartTime, sizeof(m_StartTime) );
  93. ZeroMemory( &m_SubmittedTime, sizeof(m_SubmittedTime) );
  94. ZeroMemory( &m_ElapsedTime, sizeof(m_ElapsedTime) );
  95. }
  96. BOOL CFaxStatus::Init(CFaxPort *pFaxPort)
  97. {
  98. HRESULT hr;
  99. m_pFaxPort = pFaxPort;
  100. hr = m_pFaxPort->AddRef();
  101. if (FAILED(hr)) {
  102. m_pFaxPort = NULL;
  103. return FALSE;
  104. }
  105. hr = Refresh();
  106. if (FAILED(hr)) {
  107. return FALSE;
  108. }
  109. return TRUE;
  110. }
  111. STDMETHODIMP CFaxStatus::Refresh()
  112. {
  113. PFAX_DEVICE_STATUSW FaxStatus = NULL;
  114. DWORD Size = 0;
  115. DWORDLONG ElapsedTime;
  116. DWORDLONG CurrentFileTime;
  117. SYSTEMTIME CurrentTime;
  118. HRESULT hr = S_OK;
  119. if (!FaxGetDeviceStatusW( m_pFaxPort->GetPortHandle(), &FaxStatus )) {
  120. return Fax_HRESULT_FROM_WIN32(GetLastError());
  121. }
  122. FreeMemory();
  123. m_PageCount = FaxStatus->TotalPages;
  124. m_DocSize = FaxStatus->Size;
  125. m_DeviceId = m_pFaxPort->GetDeviceId();
  126. m_CurrentPage = FaxStatus->CurrentPage;
  127. m_Receive = FaxStatus->JobType == JT_RECEIVE ? TRUE : FALSE;
  128. m_Send = FaxStatus->JobType == JT_SEND ? TRUE : FALSE;
  129. if (FaxStatus->Tsid) {
  130. m_Tsid = SysAllocString( FaxStatus->Tsid );
  131. if (!m_Tsid) {
  132. hr = E_OUTOFMEMORY;
  133. goto error;
  134. }
  135. }
  136. if (FaxStatus->StatusString) {
  137. m_Description = SysAllocString( FaxStatus->StatusString );
  138. if (!m_Description) {
  139. hr = E_OUTOFMEMORY;
  140. goto error;
  141. }
  142. }
  143. if (FaxStatus->RecipientName) {
  144. m_RecipientName = SysAllocString( FaxStatus->RecipientName );
  145. if (!m_RecipientName) {
  146. hr = E_OUTOFMEMORY;
  147. goto error;
  148. }
  149. }
  150. if (FaxStatus->SenderName) {
  151. m_SenderName = SysAllocString( FaxStatus->SenderName );
  152. if (!m_SenderName) {
  153. hr = E_OUTOFMEMORY;
  154. goto error;
  155. }
  156. }
  157. if (FaxStatus->RoutingString) {
  158. m_RoutingString = SysAllocString( FaxStatus->RoutingString );
  159. if (!m_RoutingString) {
  160. hr = E_OUTOFMEMORY;
  161. goto error;
  162. }
  163. }
  164. if (FaxStatus->PhoneNumber) {
  165. m_Address = SysAllocString( FaxStatus->PhoneNumber );
  166. if (!m_Address) {
  167. hr = E_OUTOFMEMORY;
  168. goto error;
  169. }
  170. }
  171. if (FaxStatus->DocumentName) {
  172. m_DocName = SysAllocString( FaxStatus->DocumentName );
  173. if (!m_DocName) {
  174. hr = E_OUTOFMEMORY;
  175. goto error;
  176. }
  177. }
  178. if (FaxStatus->DeviceName) {
  179. m_DeviceName = SysAllocString( FaxStatus->DeviceName );
  180. if (!m_DeviceName) {
  181. hr = E_OUTOFMEMORY;
  182. goto error;
  183. }
  184. }
  185. if (FaxStatus->Csid) {
  186. m_Csid = SysAllocString( FaxStatus->Csid );
  187. if (!m_Csid) {
  188. hr = E_OUTOFMEMORY;
  189. goto error;
  190. }
  191. }
  192. if (FaxStatus->CallerId) {
  193. m_CallerId = SysAllocString( FaxStatus->CallerId );
  194. if (!m_CallerId) {
  195. hr = E_OUTOFMEMORY;
  196. goto error;
  197. }
  198. }
  199. m_Description = GetDeviceStatus(FaxStatus->Status);
  200. if (!m_Description) {
  201. hr = E_OUTOFMEMORY;
  202. goto error;
  203. }
  204. if (!FileTimeToSystemTime( &FaxStatus->StartTime, &m_StartTime ))
  205. {
  206. //
  207. // Failed to convert File Time to System Time
  208. //
  209. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  210. goto error;
  211. }
  212. if (!FileTimeToSystemTime( &FaxStatus->SubmittedTime, &m_SubmittedTime ))
  213. {
  214. //
  215. // Failed to convert File Time to System Time
  216. //
  217. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  218. goto error;
  219. }
  220. GetSystemTime( &CurrentTime );
  221. if (!SystemTimeToFileTime( &CurrentTime, (FILETIME*)&ElapsedTime ))
  222. {
  223. //
  224. // Failed to convert System Time to File Time
  225. //
  226. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  227. goto error;
  228. }
  229. if (!SystemTimeToFileTime( &m_StartTime, (FILETIME*)&CurrentFileTime ))
  230. {
  231. //
  232. // Failed to convert System Time to File Time
  233. //
  234. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  235. goto error;
  236. }
  237. ElapsedTime = ElapsedTime - CurrentFileTime;
  238. if (!FileTimeToSystemTime( (FILETIME*)&ElapsedTime, &m_ElapsedTime ))
  239. {
  240. //
  241. // Failed to convert File Time to System Time
  242. //
  243. hr = Fax_HRESULT_FROM_WIN32(GetLastError());
  244. goto error;
  245. }
  246. hr = ERROR_SUCCESS;
  247. error:
  248. if (FAILED(hr))
  249. {
  250. //
  251. // Make the object consistent
  252. //
  253. FreeMemory();
  254. }
  255. FaxFreeBuffer( FaxStatus );
  256. return hr;
  257. }
  258. STDMETHODIMP CFaxStatus::InterfaceSupportsErrorInfo(REFIID riid)
  259. {
  260. static const IID* arr[] = { &IID_IFaxStatus };
  261. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++) {
  262. if (InlineIsEqualGUID(*arr[i],riid)) {
  263. return S_OK;
  264. }
  265. }
  266. return S_FALSE;
  267. }
  268. STDMETHODIMP CFaxStatus::get_CallerId(BSTR * pVal)
  269. {
  270. if (!pVal) {
  271. return E_POINTER;
  272. }
  273. BSTR Copy = SysAllocString(m_CallerId);
  274. if (!Copy && m_CallerId) {
  275. return E_OUTOFMEMORY;
  276. }
  277. __try {
  278. *pVal = Copy;
  279. return S_OK;
  280. } __except (EXCEPTION_EXECUTE_HANDLER) {
  281. SysFreeString(Copy);
  282. }
  283. return E_UNEXPECTED;
  284. }
  285. STDMETHODIMP CFaxStatus::get_Csid(BSTR * pVal)
  286. {
  287. if (!pVal) {
  288. return E_POINTER;
  289. }
  290. BSTR Copy = SysAllocString(m_Csid);
  291. if (!Copy && m_Csid) {
  292. return E_OUTOFMEMORY;
  293. }
  294. __try {
  295. *pVal = Copy;
  296. return S_OK;
  297. } __except (EXCEPTION_EXECUTE_HANDLER) {
  298. SysFreeString(Copy);
  299. }
  300. return E_UNEXPECTED;
  301. }
  302. STDMETHODIMP CFaxStatus::get_CurrentPage(long * pVal)
  303. {
  304. if (!pVal){
  305. return E_POINTER;
  306. }
  307. __try {
  308. *pVal = m_CurrentPage;
  309. return S_OK;
  310. } __except (EXCEPTION_EXECUTE_HANDLER) {
  311. }
  312. return E_UNEXPECTED;
  313. }
  314. STDMETHODIMP CFaxStatus::get_DeviceId(long * pVal)
  315. {
  316. if (!pVal){
  317. return E_POINTER;
  318. }
  319. __try {
  320. *pVal = m_DeviceId;
  321. return S_OK;
  322. } __except (EXCEPTION_EXECUTE_HANDLER) {
  323. }
  324. return E_UNEXPECTED;
  325. }
  326. STDMETHODIMP CFaxStatus::get_DeviceName(BSTR * pVal)
  327. {
  328. if (!pVal) {
  329. return E_POINTER;
  330. }
  331. BSTR Copy = SysAllocString(m_DeviceName);
  332. if (!Copy && m_DeviceName) {
  333. return E_OUTOFMEMORY;
  334. }
  335. __try {
  336. *pVal = Copy;
  337. return S_OK;
  338. } __except (EXCEPTION_EXECUTE_HANDLER) {
  339. SysFreeString(Copy);
  340. }
  341. return E_UNEXPECTED;
  342. }
  343. STDMETHODIMP CFaxStatus::get_DocumentName(BSTR * pVal)
  344. {
  345. if (!pVal) {
  346. return E_POINTER;
  347. }
  348. BSTR Copy = SysAllocString(m_DocName);
  349. if (!Copy && m_DocName) {
  350. return E_OUTOFMEMORY;
  351. }
  352. __try {
  353. *pVal = Copy;
  354. return S_OK;
  355. } __except (EXCEPTION_EXECUTE_HANDLER) {
  356. SysFreeString(Copy);
  357. }
  358. return E_UNEXPECTED;
  359. }
  360. STDMETHODIMP CFaxStatus::get_Send(BOOL * pVal)
  361. {
  362. *pVal = m_Send;
  363. return S_OK;
  364. }
  365. STDMETHODIMP CFaxStatus::get_Receive(BOOL * pVal)
  366. {
  367. if (!pVal){
  368. return E_POINTER;
  369. }
  370. __try {
  371. *pVal = m_Receive;
  372. return S_OK;
  373. } __except (EXCEPTION_EXECUTE_HANDLER) {
  374. }
  375. return E_UNEXPECTED;
  376. }
  377. STDMETHODIMP CFaxStatus::get_Address(BSTR * pVal)
  378. {
  379. if (!pVal) {
  380. return E_POINTER;
  381. }
  382. BSTR Copy = SysAllocString(m_Address);
  383. if (!Copy && m_Address) {
  384. return E_OUTOFMEMORY;
  385. }
  386. __try {
  387. *pVal = Copy;
  388. return S_OK;
  389. } __except (EXCEPTION_EXECUTE_HANDLER) {
  390. SysFreeString(Copy);
  391. }
  392. return E_UNEXPECTED;}
  393. STDMETHODIMP CFaxStatus::get_RoutingString(BSTR * pVal)
  394. {
  395. if (!pVal) {
  396. return E_POINTER;
  397. }
  398. BSTR Copy = SysAllocString(m_RoutingString);
  399. if (!Copy && m_RoutingString) {
  400. return E_OUTOFMEMORY;
  401. }
  402. __try {
  403. *pVal = Copy;
  404. return S_OK;
  405. } __except (EXCEPTION_EXECUTE_HANDLER) {
  406. SysFreeString(Copy);
  407. }
  408. return E_UNEXPECTED;
  409. }
  410. STDMETHODIMP CFaxStatus::get_SenderName(BSTR * pVal)
  411. {
  412. if (!pVal) {
  413. return E_POINTER;
  414. }
  415. BSTR Copy = SysAllocString(m_SenderName);
  416. if (!Copy && m_SenderName) {
  417. return E_OUTOFMEMORY;
  418. }
  419. __try {
  420. *pVal = Copy;
  421. return S_OK;
  422. } __except (EXCEPTION_EXECUTE_HANDLER) {
  423. SysFreeString(Copy);
  424. }
  425. return E_UNEXPECTED;
  426. }
  427. STDMETHODIMP CFaxStatus::get_RecipientName(BSTR * pVal)
  428. {
  429. if (!pVal) {
  430. return E_POINTER;
  431. }
  432. BSTR Copy = SysAllocString(m_RecipientName);
  433. if (!Copy && m_RecipientName) {
  434. return E_OUTOFMEMORY;
  435. }
  436. __try {
  437. *pVal = Copy;
  438. return S_OK;
  439. } __except (EXCEPTION_EXECUTE_HANDLER) {
  440. SysFreeString(Copy);
  441. }
  442. return E_UNEXPECTED;
  443. }
  444. STDMETHODIMP CFaxStatus::get_DocumentSize(long * pVal)
  445. {
  446. if (!pVal){
  447. return E_POINTER;
  448. }
  449. __try {
  450. *pVal = m_DocSize;
  451. return S_OK;
  452. } __except (EXCEPTION_EXECUTE_HANDLER) {
  453. }
  454. return E_UNEXPECTED;
  455. }
  456. STDMETHODIMP CFaxStatus::get_Description(BSTR * pVal)
  457. {
  458. if (!pVal) {
  459. return E_POINTER;
  460. }
  461. BSTR Copy = SysAllocString(m_Description);
  462. if (!Copy && m_Description) {
  463. return E_OUTOFMEMORY;
  464. }
  465. __try {
  466. *pVal = Copy;
  467. return S_OK;
  468. } __except (EXCEPTION_EXECUTE_HANDLER) {
  469. SysFreeString(Copy);
  470. }
  471. return E_UNEXPECTED;
  472. }
  473. STDMETHODIMP CFaxStatus::get_PageCount(long * pVal)
  474. {
  475. if (!pVal){
  476. return E_POINTER;
  477. }
  478. __try {
  479. *pVal = m_PageCount;
  480. return S_OK;
  481. } __except (EXCEPTION_EXECUTE_HANDLER) {
  482. }
  483. return E_UNEXPECTED;
  484. }
  485. STDMETHODIMP CFaxStatus::get_Tsid(BSTR * pVal)
  486. {
  487. if (!pVal) {
  488. return E_POINTER;
  489. }
  490. BSTR Copy = SysAllocString(m_Tsid);
  491. if (!Copy && m_Tsid) {
  492. return E_OUTOFMEMORY;
  493. }
  494. __try {
  495. *pVal = Copy ;
  496. return S_OK;
  497. } __except (EXCEPTION_EXECUTE_HANDLER) {
  498. SysFreeString(Copy);
  499. }
  500. return E_UNEXPECTED;
  501. }
  502. STDMETHODIMP CFaxStatus::get_StartTime(DATE * pVal)
  503. {
  504. if (!SystemTimeToVariantTime( &m_StartTime, pVal )) {
  505. return E_FAIL;
  506. }
  507. return S_OK;
  508. }
  509. STDMETHODIMP CFaxStatus::get_SubmittedTime(DATE * pVal)
  510. {
  511. if (!SystemTimeToVariantTime( &m_SubmittedTime, pVal )) {
  512. return E_FAIL;
  513. }
  514. return S_OK;
  515. }
  516. STDMETHODIMP CFaxStatus::get_ElapsedTime(DATE * pVal)
  517. {
  518. if (!SystemTimeToVariantTime( &m_ElapsedTime, pVal )) {
  519. return E_FAIL;
  520. }
  521. return S_OK;
  522. }