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.

649 lines
12 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 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. }
  134. }
  135. if (FaxStatus->StatusString) {
  136. m_Description = SysAllocString( FaxStatus->StatusString );
  137. if (!m_Description) {
  138. hr = E_OUTOFMEMORY;
  139. }
  140. }
  141. if (FaxStatus->RecipientName) {
  142. m_RecipientName = SysAllocString( FaxStatus->RecipientName );
  143. if (!m_RecipientName) {
  144. hr = E_OUTOFMEMORY;
  145. }
  146. }
  147. if (FaxStatus->SenderName) {
  148. m_SenderName = SysAllocString( FaxStatus->SenderName );
  149. if (!m_SenderName) {
  150. hr = E_OUTOFMEMORY;
  151. }
  152. }
  153. if (FaxStatus->RoutingString) {
  154. m_RoutingString = SysAllocString( FaxStatus->RoutingString );
  155. if (!m_RoutingString) {
  156. hr = E_OUTOFMEMORY;
  157. }
  158. }
  159. if (FaxStatus->PhoneNumber) {
  160. m_Address = SysAllocString( FaxStatus->PhoneNumber );
  161. if (!m_Address) {
  162. hr = E_OUTOFMEMORY;
  163. }
  164. }
  165. if (FaxStatus->DocumentName) {
  166. m_DocName = SysAllocString( FaxStatus->DocumentName );
  167. if (!m_DocName) {
  168. hr = E_OUTOFMEMORY;
  169. }
  170. }
  171. if (FaxStatus->DeviceName) {
  172. m_DeviceName = SysAllocString( FaxStatus->DeviceName );
  173. if (!m_DeviceName) {
  174. hr = E_OUTOFMEMORY;
  175. }
  176. }
  177. if (FaxStatus->Csid) {
  178. m_Csid = SysAllocString( FaxStatus->Csid );
  179. if (!m_Csid) {
  180. hr = E_OUTOFMEMORY;
  181. }
  182. }
  183. if (FaxStatus->CallerId) {
  184. m_CallerId = SysAllocString( FaxStatus->CallerId );
  185. if (!m_CallerId) {
  186. hr = E_OUTOFMEMORY;
  187. }
  188. }
  189. m_Description = GetDeviceStatus(FaxStatus->Status);
  190. if (!m_Description) {
  191. hr = E_OUTOFMEMORY;
  192. }
  193. FileTimeToSystemTime( &FaxStatus->StartTime, &m_StartTime );
  194. FileTimeToSystemTime( &FaxStatus->SubmittedTime, &m_SubmittedTime );
  195. GetSystemTime( &CurrentTime );
  196. SystemTimeToFileTime( &CurrentTime, (FILETIME*)&ElapsedTime );
  197. SystemTimeToFileTime( &m_StartTime, (FILETIME*)&CurrentFileTime );
  198. ElapsedTime = ElapsedTime - CurrentFileTime;
  199. FileTimeToSystemTime( (FILETIME*)&ElapsedTime, &m_ElapsedTime );
  200. FaxFreeBuffer( FaxStatus );
  201. return hr;
  202. }
  203. STDMETHODIMP CFaxStatus::InterfaceSupportsErrorInfo(REFIID riid)
  204. {
  205. static const IID* arr[] = { &IID_IFaxStatus };
  206. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++) {
  207. if (InlineIsEqualGUID(*arr[i],riid)) {
  208. return S_OK;
  209. }
  210. }
  211. return S_FALSE;
  212. }
  213. STDMETHODIMP CFaxStatus::get_CallerId(BSTR * pVal)
  214. {
  215. if (!pVal) {
  216. return E_POINTER;
  217. }
  218. BSTR Copy = SysAllocString(m_CallerId);
  219. if (!Copy && m_CallerId) {
  220. return E_OUTOFMEMORY;
  221. }
  222. __try {
  223. *pVal = Copy;
  224. return S_OK;
  225. } __except (EXCEPTION_EXECUTE_HANDLER) {
  226. SysFreeString(Copy);
  227. }
  228. return E_UNEXPECTED;
  229. }
  230. STDMETHODIMP CFaxStatus::get_Csid(BSTR * pVal)
  231. {
  232. if (!pVal) {
  233. return E_POINTER;
  234. }
  235. BSTR Copy = SysAllocString(m_Csid);
  236. if (!Copy && m_Csid) {
  237. return E_OUTOFMEMORY;
  238. }
  239. __try {
  240. *pVal = Copy;
  241. return S_OK;
  242. } __except (EXCEPTION_EXECUTE_HANDLER) {
  243. SysFreeString(Copy);
  244. }
  245. return E_UNEXPECTED;
  246. }
  247. STDMETHODIMP CFaxStatus::get_CurrentPage(long * pVal)
  248. {
  249. if (!pVal){
  250. return E_POINTER;
  251. }
  252. __try {
  253. *pVal = m_CurrentPage;
  254. return S_OK;
  255. } __except (EXCEPTION_EXECUTE_HANDLER) {
  256. }
  257. return E_UNEXPECTED;
  258. }
  259. STDMETHODIMP CFaxStatus::get_DeviceId(long * pVal)
  260. {
  261. if (!pVal){
  262. return E_POINTER;
  263. }
  264. __try {
  265. *pVal = m_DeviceId;
  266. return S_OK;
  267. } __except (EXCEPTION_EXECUTE_HANDLER) {
  268. }
  269. return E_UNEXPECTED;
  270. }
  271. STDMETHODIMP CFaxStatus::get_DeviceName(BSTR * pVal)
  272. {
  273. if (!pVal) {
  274. return E_POINTER;
  275. }
  276. BSTR Copy = SysAllocString(m_DeviceName);
  277. if (!Copy && m_DeviceName) {
  278. return E_OUTOFMEMORY;
  279. }
  280. __try {
  281. *pVal = Copy;
  282. return S_OK;
  283. } __except (EXCEPTION_EXECUTE_HANDLER) {
  284. SysFreeString(Copy);
  285. }
  286. return E_UNEXPECTED;
  287. }
  288. STDMETHODIMP CFaxStatus::get_DocumentName(BSTR * pVal)
  289. {
  290. if (!pVal) {
  291. return E_POINTER;
  292. }
  293. BSTR Copy = SysAllocString(m_DocName);
  294. if (!Copy && m_DocName) {
  295. return E_OUTOFMEMORY;
  296. }
  297. __try {
  298. *pVal = Copy;
  299. return S_OK;
  300. } __except (EXCEPTION_EXECUTE_HANDLER) {
  301. SysFreeString(Copy);
  302. }
  303. return E_UNEXPECTED;
  304. }
  305. STDMETHODIMP CFaxStatus::get_Send(BOOL * pVal)
  306. {
  307. *pVal = m_Send;
  308. return S_OK;
  309. }
  310. STDMETHODIMP CFaxStatus::get_Receive(BOOL * pVal)
  311. {
  312. if (!pVal){
  313. return E_POINTER;
  314. }
  315. __try {
  316. *pVal = m_Receive;
  317. return S_OK;
  318. } __except (EXCEPTION_EXECUTE_HANDLER) {
  319. }
  320. return E_UNEXPECTED;
  321. }
  322. STDMETHODIMP CFaxStatus::get_Address(BSTR * pVal)
  323. {
  324. if (!pVal) {
  325. return E_POINTER;
  326. }
  327. BSTR Copy = SysAllocString(m_Address);
  328. if (!Copy && m_Address) {
  329. return E_OUTOFMEMORY;
  330. }
  331. __try {
  332. *pVal = Copy;
  333. return S_OK;
  334. } __except (EXCEPTION_EXECUTE_HANDLER) {
  335. SysFreeString(Copy);
  336. }
  337. return E_UNEXPECTED;}
  338. STDMETHODIMP CFaxStatus::get_RoutingString(BSTR * pVal)
  339. {
  340. if (!pVal) {
  341. return E_POINTER;
  342. }
  343. BSTR Copy = SysAllocString(m_RoutingString);
  344. if (!Copy && m_RoutingString) {
  345. return E_OUTOFMEMORY;
  346. }
  347. __try {
  348. *pVal = Copy;
  349. return S_OK;
  350. } __except (EXCEPTION_EXECUTE_HANDLER) {
  351. SysFreeString(Copy);
  352. }
  353. return E_UNEXPECTED;
  354. }
  355. STDMETHODIMP CFaxStatus::get_SenderName(BSTR * pVal)
  356. {
  357. if (!pVal) {
  358. return E_POINTER;
  359. }
  360. BSTR Copy = SysAllocString(m_SenderName);
  361. if (!Copy && m_SenderName) {
  362. return E_OUTOFMEMORY;
  363. }
  364. __try {
  365. *pVal = Copy;
  366. return S_OK;
  367. } __except (EXCEPTION_EXECUTE_HANDLER) {
  368. SysFreeString(Copy);
  369. }
  370. return E_UNEXPECTED;
  371. }
  372. STDMETHODIMP CFaxStatus::get_RecipientName(BSTR * pVal)
  373. {
  374. if (!pVal) {
  375. return E_POINTER;
  376. }
  377. BSTR Copy = SysAllocString(m_RecipientName);
  378. if (!Copy && m_RecipientName) {
  379. return E_OUTOFMEMORY;
  380. }
  381. __try {
  382. *pVal = Copy;
  383. return S_OK;
  384. } __except (EXCEPTION_EXECUTE_HANDLER) {
  385. SysFreeString(Copy);
  386. }
  387. return E_UNEXPECTED;
  388. }
  389. STDMETHODIMP CFaxStatus::get_DocumentSize(long * pVal)
  390. {
  391. if (!pVal){
  392. return E_POINTER;
  393. }
  394. __try {
  395. *pVal = m_DocSize;
  396. return S_OK;
  397. } __except (EXCEPTION_EXECUTE_HANDLER) {
  398. }
  399. return E_UNEXPECTED;
  400. }
  401. STDMETHODIMP CFaxStatus::get_Description(BSTR * pVal)
  402. {
  403. if (!pVal) {
  404. return E_POINTER;
  405. }
  406. BSTR Copy = SysAllocString(m_Description);
  407. if (!Copy && m_Description) {
  408. return E_OUTOFMEMORY;
  409. }
  410. __try {
  411. *pVal = Copy;
  412. return S_OK;
  413. } __except (EXCEPTION_EXECUTE_HANDLER) {
  414. SysFreeString(Copy);
  415. }
  416. return E_UNEXPECTED;
  417. }
  418. STDMETHODIMP CFaxStatus::get_PageCount(long * pVal)
  419. {
  420. if (!pVal){
  421. return E_POINTER;
  422. }
  423. __try {
  424. *pVal = m_PageCount;
  425. return S_OK;
  426. } __except (EXCEPTION_EXECUTE_HANDLER) {
  427. }
  428. return E_UNEXPECTED;
  429. }
  430. STDMETHODIMP CFaxStatus::get_Tsid(BSTR * pVal)
  431. {
  432. if (!pVal) {
  433. return E_POINTER;
  434. }
  435. BSTR Copy = SysAllocString(m_Tsid);
  436. if (!Copy && m_Tsid) {
  437. return E_OUTOFMEMORY;
  438. }
  439. __try {
  440. *pVal = Copy ;
  441. return S_OK;
  442. } __except (EXCEPTION_EXECUTE_HANDLER) {
  443. SysFreeString(Copy);
  444. }
  445. return E_UNEXPECTED;
  446. }
  447. STDMETHODIMP CFaxStatus::get_StartTime(DATE * pVal)
  448. {
  449. if (!SystemTimeToVariantTime( &m_StartTime, pVal )) {
  450. return E_FAIL;
  451. }
  452. return S_OK;
  453. }
  454. STDMETHODIMP CFaxStatus::get_SubmittedTime(DATE * pVal)
  455. {
  456. if (!SystemTimeToVariantTime( &m_SubmittedTime, pVal )) {
  457. return E_FAIL;
  458. }
  459. return S_OK;
  460. }
  461. STDMETHODIMP CFaxStatus::get_ElapsedTime(DATE * pVal)
  462. {
  463. if (!SystemTimeToVariantTime( &m_ElapsedTime, pVal )) {
  464. return E_FAIL;
  465. }
  466. return S_OK;
  467. }