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.

1895 lines
34 KiB

  1. #include "stdafx.h"
  2. #include "termevnt.h"
  3. HRESULT CASRTerminalEvent::FireEvent(
  4. CTAPI * pTapi,
  5. ITCallInfo *pCall,
  6. ITTerminal * pTerminal,
  7. HRESULT hrErrorCode
  8. )
  9. {
  10. STATICLOG((TL_TRACE, "FireEvent - enter" ));
  11. CCall *pCCall = NULL;
  12. pCCall = dynamic_cast<CComObject<CCall>*>(pCall);
  13. if (NULL == pCCall)
  14. {
  15. STATICLOG((TL_ERROR, "FireEvent - bad call pointer" ));
  16. return E_FAIL;
  17. }
  18. if( pCCall->DontExpose())
  19. {
  20. STATICLOG((TL_INFO, "FireEvent - Don't expose this call %p", pCCall));
  21. return S_OK;
  22. }
  23. if (NULL == pTapi)
  24. {
  25. STATICLOG((TL_ERROR, "FireEvent - tapi object is NULL" ));
  26. return E_POINTER;
  27. }
  28. //
  29. // create the event object
  30. //
  31. HRESULT hr = E_FAIL;
  32. CComObject<CASRTerminalEvent> *p;
  33. hr = CComObject<CASRTerminalEvent>::CreateInstance( &p );
  34. if (FAILED(hr))
  35. {
  36. STATICLOG((TL_ERROR, "FireEvent - could not createinstance" ));
  37. return E_OUTOFMEMORY;
  38. }
  39. //
  40. // save event information to the event object
  41. //
  42. hr = p->put_Call(pCall);
  43. if (FAILED(hr))
  44. {
  45. STATICLOG((TL_ERROR, "FireEvent - put_Call failed" ));
  46. delete p;
  47. return hr;
  48. }
  49. hr = p->put_Terminal(pTerminal);
  50. if (FAILED(hr))
  51. {
  52. STATICLOG((TL_ERROR, "FireEvent - put_Terminal failed" ));
  53. delete p;
  54. return hr;
  55. }
  56. hr = p->put_ErrorCode(hrErrorCode);
  57. if (FAILED(hr))
  58. {
  59. STATICLOG((TL_ERROR, "FireEvent - put_ErrorCode failed" ));
  60. delete p;
  61. return hr;
  62. }
  63. //
  64. // get the dispatch interface
  65. //
  66. IDispatch *pDisp = NULL;
  67. hr = p->_InternalQueryInterface( IID_IDispatch, (void **)&pDisp );
  68. if (FAILED(hr))
  69. {
  70. delete p;
  71. STATICLOG((TL_ERROR, "FireEvent - could not get IDispatch %lx", hr));
  72. return hr;
  73. }
  74. //
  75. // fire the event
  76. //
  77. pTapi->Event(
  78. TE_ASRTERMINAL,
  79. pDisp
  80. );
  81. //
  82. // release our reference
  83. //
  84. pDisp->Release();
  85. STATICLOG((TL_TRACE, "FireEvent - exit - returing SUCCESS" ));
  86. return S_OK;
  87. }
  88. CASRTerminalEvent::CASRTerminalEvent()
  89. :m_pCallInfo(NULL),
  90. m_pTerminal(NULL),
  91. m_hr(S_OK)
  92. {
  93. LOG((TL_TRACE, "CASRTerminalEvent[%p] - enter", this));
  94. LOG((TL_TRACE, "CASRTerminalEvent - finish"));
  95. }
  96. CASRTerminalEvent::~CASRTerminalEvent()
  97. {
  98. LOG((TL_INFO, "~CASRTerminalEvent[%p] - enter", this));
  99. //
  100. // remember to release all the references we may hold
  101. //
  102. if (NULL != m_pCallInfo)
  103. {
  104. LOG((TL_INFO, "~CASRTerminalEvent - releasing m_pCallInfo %p", m_pCallInfo));
  105. m_pCallInfo->Release();
  106. m_pCallInfo = NULL;
  107. }
  108. if ( NULL != m_pTerminal)
  109. {
  110. LOG((TL_INFO, "~CASRTerminalEvent - releasing m_pTerminal %p", m_pTerminal));
  111. m_pTerminal->Release();
  112. m_pTerminal = NULL;
  113. }
  114. LOG((TL_TRACE, "~CASRTerminalEvent - finish"));
  115. }
  116. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::get_Call(
  117. OUT ITCallInfo **ppCallInfo
  118. )
  119. {
  120. LOG((TL_TRACE, "get_Call[%p] - enter", this));
  121. //
  122. // check arguments
  123. //
  124. if (TAPIIsBadWritePtr(ppCallInfo, sizeof(ITCallInfo *)))
  125. {
  126. LOG((TL_ERROR, "get_Call - bad pointer passed in"));
  127. return E_POINTER;
  128. }
  129. //
  130. // no garbage out
  131. //
  132. *ppCallInfo = NULL;
  133. //
  134. // return call info if we have it
  135. //
  136. if (NULL != m_pCallInfo)
  137. {
  138. *ppCallInfo = m_pCallInfo;
  139. (*ppCallInfo)->AddRef();
  140. }
  141. LOG((TL_TRACE, "get_Call - finish"));
  142. return S_OK;
  143. }
  144. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::get_Terminal(
  145. OUT ITTerminal **ppTerminal
  146. )
  147. {
  148. LOG((TL_TRACE, "get_Terminal[%p] - enter", this));
  149. //
  150. // check arguments
  151. //
  152. if (TAPIIsBadWritePtr(ppTerminal, sizeof(ITTerminal*)))
  153. {
  154. LOG((TL_ERROR, "get_Terminal - bad pointer passed in"));
  155. return E_POINTER;
  156. }
  157. //
  158. // no garbage out
  159. //
  160. *ppTerminal = NULL;
  161. //
  162. // return terminal if we have it
  163. //
  164. if (NULL != m_pTerminal)
  165. {
  166. *ppTerminal = m_pTerminal;
  167. (*ppTerminal)->AddRef();
  168. }
  169. LOG((TL_TRACE, "get_Terminal - finish"));
  170. return S_OK;
  171. }
  172. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::get_Error(
  173. OUT HRESULT *phrErrorCode
  174. )
  175. {
  176. LOG((TL_TRACE, "get_Error[%p] - enter", this));
  177. //
  178. // check arguments
  179. //
  180. if (TAPIIsBadWritePtr(phrErrorCode, sizeof(HRESULT)))
  181. {
  182. LOG((TL_ERROR, "get_Error - bad pointer passed in"));
  183. return E_POINTER;
  184. }
  185. //
  186. // return error code
  187. //
  188. *phrErrorCode = m_hr;
  189. LOG((TL_TRACE, "get_Error - finish. hr = [%lx]", m_hr));
  190. return S_OK;
  191. }
  192. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::put_Terminal(
  193. IN ITTerminal *pTerminal
  194. )
  195. {
  196. LOG((TL_TRACE, "put_Terminal[%p] - enter", this));
  197. //
  198. // check the argument
  199. //
  200. if ((NULL != pTerminal) && IsBadReadPtr(pTerminal, sizeof(ITTerminal)))
  201. {
  202. LOG((TL_ERROR, "put_Terminal - bad pointer passed in"));
  203. //
  204. // if we get here, we have a bug. debug to see what happened.
  205. //
  206. _ASSERTE(FALSE);
  207. return E_POINTER;
  208. }
  209. //
  210. // keep the pointer
  211. //
  212. m_pTerminal = pTerminal;
  213. //
  214. // keep a reference if not null
  215. //
  216. if (NULL != m_pTerminal)
  217. {
  218. m_pTerminal->AddRef();
  219. }
  220. LOG((TL_TRACE, "put_Terminal - finished"));
  221. return S_OK;
  222. }
  223. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::put_Call(
  224. IN ITCallInfo *pCallInfo
  225. )
  226. {
  227. LOG((TL_TRACE, "put_Call[%p] - enter", this));
  228. //
  229. // check the argument
  230. //
  231. if ((NULL != pCallInfo) && IsBadReadPtr(pCallInfo, sizeof(ITCallInfo)))
  232. {
  233. LOG((TL_ERROR, "put_Call - bad pointer passed in"));
  234. //
  235. // if we get here, we have a bug. debug to see what happened.
  236. //
  237. _ASSERTE(FALSE);
  238. return E_POINTER;
  239. }
  240. //
  241. // keep the pointer
  242. //
  243. m_pCallInfo = pCallInfo;
  244. //
  245. // keep a reference if not null
  246. //
  247. if (NULL != m_pCallInfo)
  248. {
  249. m_pCallInfo->AddRef();
  250. }
  251. LOG((TL_TRACE, "put_Call - finished"));
  252. return S_OK;
  253. }
  254. HRESULT STDMETHODCALLTYPE CASRTerminalEvent::put_ErrorCode(
  255. IN HRESULT hrErrorCode
  256. )
  257. {
  258. LOG((TL_TRACE, "put_ErrorCode[%p] - enter. hr = [%lx]", this, hrErrorCode));
  259. //
  260. // keep the value
  261. //
  262. m_hr = hrErrorCode;
  263. LOG((TL_TRACE, "put_ErrorCode - finished"));
  264. return S_OK;
  265. }
  266. HRESULT CFileTerminalEvent::FireEvent(
  267. CAddress *pCAddress,
  268. CTAPI * pTapi,
  269. ITCallInfo *pCall,
  270. TERMINAL_MEDIA_STATE tmsTerminalState,
  271. FT_STATE_EVENT_CAUSE ftecEventCause,
  272. ITTerminal * pTerminal,
  273. ITFileTrack * pFileTrack,
  274. HRESULT hrErrorCode
  275. )
  276. {
  277. STATICLOG((TL_TRACE, "FireEvent - enter" ));
  278. STATICLOG((TL_INFO, " File Terminal State -------------> %d", tmsTerminalState));
  279. STATICLOG((TL_INFO, " File Terminal Event Cause -------> %d", ftecEventCause));
  280. STATICLOG((TL_INFO, " File Terminal -------------------> %p", pTerminal));
  281. CCall *pCCall = NULL;
  282. pCCall = dynamic_cast<CComObject<CCall>*>(pCall);
  283. if (NULL == pCCall)
  284. {
  285. STATICLOG((TL_ERROR, "FireEvent - bad call pointer" ));
  286. return E_FAIL;
  287. }
  288. if( pCCall->DontExpose())
  289. {
  290. STATICLOG((TL_INFO, "FireEvent - Don't expose this call %p", pCCall));
  291. return S_OK;
  292. }
  293. if (NULL == pTapi)
  294. {
  295. STATICLOG((TL_ERROR, "FireEvent - tapi object is NULL" ));
  296. return E_POINTER;
  297. }
  298. //
  299. // Check the event filter mask
  300. // This are MSP events and are not filtered by
  301. // TapiSrv
  302. //
  303. DWORD dwEventFilterMask = 0;
  304. dwEventFilterMask = pCAddress->GetSubEventsMask( TE_FILETERMINAL );
  305. if( !( dwEventFilterMask & GET_SUBEVENT_FLAG(tmsTerminalState)))
  306. {
  307. STATICLOG((TL_WARN, "FireEvent - filtering out this event [%lx]", tmsTerminalState));
  308. return S_OK;
  309. }
  310. //
  311. // create the event object
  312. //
  313. HRESULT hr = E_FAIL;
  314. CComObject<CFileTerminalEvent> *p;
  315. hr = CComObject<CFileTerminalEvent>::CreateInstance( &p );
  316. if (FAILED(hr))
  317. {
  318. STATICLOG((TL_ERROR, "FireEvent - could not createinstance" ));
  319. return E_OUTOFMEMORY;
  320. }
  321. //
  322. // save event information to the event object
  323. //
  324. hr = p->put_Call(pCall);
  325. if (FAILED(hr))
  326. {
  327. STATICLOG((TL_ERROR, "FireEvent - put_Call failed" ));
  328. delete p;
  329. return hr;
  330. }
  331. hr = p->put_Terminal(pTerminal);
  332. if (FAILED(hr))
  333. {
  334. STATICLOG((TL_ERROR, "FireEvent - put_Terminal failed" ));
  335. delete p;
  336. return hr;
  337. }
  338. hr = p->put_Track(pFileTrack);
  339. if (FAILED(hr))
  340. {
  341. STATICLOG((TL_ERROR, "FireEvent - put_Track failed" ));
  342. delete p;
  343. return hr;
  344. }
  345. hr = p->put_State(tmsTerminalState);
  346. if (FAILED(hr))
  347. {
  348. STATICLOG((TL_ERROR, "FireEvent - put_State failed" ));
  349. delete p;
  350. return hr;
  351. }
  352. hr = p->put_Cause(ftecEventCause);
  353. if (FAILED(hr))
  354. {
  355. STATICLOG((TL_ERROR, "FireEvent - put_Cause failed" ));
  356. delete p;
  357. return hr;
  358. }
  359. hr = p->put_ErrorCode(hrErrorCode);
  360. if (FAILED(hr))
  361. {
  362. STATICLOG((TL_ERROR, "FireEvent - put_ErrorCode failed" ));
  363. delete p;
  364. return hr;
  365. }
  366. //
  367. // get the dispatch interface
  368. //
  369. IDispatch *pDisp = NULL;
  370. hr = p->_InternalQueryInterface( IID_IDispatch, (void **)&pDisp );
  371. if (FAILED(hr))
  372. {
  373. delete p;
  374. STATICLOG((TL_ERROR, "FireEvent - could not get IDispatch %lx", hr));
  375. return hr;
  376. }
  377. //
  378. // fire the event
  379. //
  380. pTapi->Event(
  381. TE_FILETERMINAL,
  382. pDisp
  383. );
  384. //
  385. // release our reference
  386. //
  387. pDisp->Release();
  388. STATICLOG((TL_TRACE, "FireEvent - exit - returing SUCCESS" ));
  389. return S_OK;
  390. }
  391. CFileTerminalEvent::CFileTerminalEvent()
  392. :m_pCallInfo(NULL),
  393. m_pParentFileTerminal(NULL),
  394. m_pFileTrack(NULL),
  395. m_tmsTerminalState(TMS_IDLE),
  396. m_ftecEventCause(FTEC_NORMAL),
  397. m_hr(S_OK)
  398. {
  399. LOG((TL_TRACE, "CFileTerminalEvent[%p] - enter", this));
  400. LOG((TL_TRACE, "CFileTerminalEvent - finish"));
  401. }
  402. CFileTerminalEvent::~CFileTerminalEvent()
  403. {
  404. LOG((TL_TRACE, "~CFileTerminalEvent[%p] - enter", this));
  405. //
  406. // remember to release all the references we may hold
  407. //
  408. if (NULL != m_pCallInfo)
  409. {
  410. LOG((TL_INFO, "~CFileTerminalEvent - releasing m_pCallInfo %p", m_pCallInfo));
  411. m_pCallInfo->Release();
  412. m_pCallInfo = NULL;
  413. }
  414. if ( NULL != m_pParentFileTerminal)
  415. {
  416. LOG((TL_INFO, "~CFileTerminalEvent - releasing m_pParentFileTerminal %p", m_pParentFileTerminal));
  417. m_pParentFileTerminal->Release();
  418. m_pParentFileTerminal = NULL;
  419. }
  420. if (NULL != m_pFileTrack)
  421. {
  422. LOG((TL_INFO, "~CFileTerminalEvent - releasing m_pFileTrack %p", m_pFileTrack));
  423. m_pFileTrack->Release();
  424. m_pFileTrack = NULL;
  425. }
  426. LOG((TL_TRACE, "~CFileTerminalEvent - finish"));
  427. }
  428. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_Call(
  429. OUT ITCallInfo **ppCallInfo
  430. )
  431. {
  432. LOG((TL_TRACE, "get_Call[%p] - enter", this));
  433. //
  434. // check arguments
  435. //
  436. if (TAPIIsBadWritePtr(ppCallInfo, sizeof(ITCallInfo *)))
  437. {
  438. LOG((TL_ERROR, "get_Call - bad pointer passed in"));
  439. return E_POINTER;
  440. }
  441. //
  442. // no garbage out
  443. //
  444. *ppCallInfo = NULL;
  445. //
  446. // return call info if we have it
  447. //
  448. if (NULL != m_pCallInfo)
  449. {
  450. *ppCallInfo = m_pCallInfo;
  451. (*ppCallInfo)->AddRef();
  452. }
  453. LOG((TL_TRACE, "get_Call - finish"));
  454. return S_OK;
  455. }
  456. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_State(
  457. OUT TERMINAL_MEDIA_STATE *pFileTerminallState
  458. )
  459. {
  460. LOG((TL_TRACE, "get_State[%p] - enter", this));
  461. //
  462. // check arguments
  463. //
  464. if (TAPIIsBadWritePtr(pFileTerminallState, sizeof(TERMINAL_MEDIA_STATE)))
  465. {
  466. LOG((TL_ERROR, "get_State - bad pointer passed in"));
  467. return E_POINTER;
  468. }
  469. //
  470. // return state
  471. //
  472. *pFileTerminallState = m_tmsTerminalState;
  473. LOG((TL_TRACE, "get_State - finish. state = [%lx]", m_tmsTerminalState));
  474. return S_OK;
  475. }
  476. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_Cause(
  477. OUT FT_STATE_EVENT_CAUSE *pCause
  478. )
  479. {
  480. LOG((TL_TRACE, "get_Cause[%p] - enter", this));
  481. //
  482. // check arguments
  483. //
  484. if (TAPIIsBadWritePtr(pCause, sizeof(FT_STATE_EVENT_CAUSE)))
  485. {
  486. LOG((TL_ERROR, "get_Cause - bad pointer passed in"));
  487. return E_POINTER;
  488. }
  489. //
  490. // return cause
  491. //
  492. *pCause = m_ftecEventCause;
  493. LOG((TL_TRACE, "get_Cause - finish. cause = [%lx]", m_ftecEventCause));
  494. return S_OK;
  495. }
  496. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_Terminal(
  497. OUT ITTerminal **ppTerminal
  498. )
  499. {
  500. LOG((TL_TRACE, "get_Terminal[%p] - enter", this));
  501. //
  502. // check arguments
  503. //
  504. if (TAPIIsBadWritePtr(ppTerminal, sizeof(ITTerminal*)))
  505. {
  506. LOG((TL_ERROR, "get_Terminal - bad pointer passed in"));
  507. return E_POINTER;
  508. }
  509. //
  510. // no garbage out
  511. //
  512. *ppTerminal = NULL;
  513. //
  514. // return terminal if we have it
  515. //
  516. if (NULL != m_pParentFileTerminal)
  517. {
  518. *ppTerminal = m_pParentFileTerminal;
  519. (*ppTerminal)->AddRef();
  520. }
  521. LOG((TL_TRACE, "get_Terminal - finish"));
  522. return S_OK;
  523. }
  524. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_Track(
  525. OUT ITFileTrack **ppFileTrack
  526. )
  527. {
  528. LOG((TL_TRACE, "get_Track[%p] - enter", this));
  529. //
  530. // check arguments
  531. //
  532. if (TAPIIsBadWritePtr(ppFileTrack, sizeof(ITFileTrack*)))
  533. {
  534. LOG((TL_ERROR, "get_Track - bad pointer passed in"));
  535. return E_POINTER;
  536. }
  537. //
  538. // no garbage out
  539. //
  540. *ppFileTrack = NULL;
  541. //
  542. // return track terminal if we have it
  543. //
  544. if (NULL != m_pFileTrack)
  545. {
  546. *ppFileTrack = m_pFileTrack;
  547. (*ppFileTrack)->AddRef();
  548. }
  549. LOG((TL_TRACE, "get_Track - finish"));
  550. return S_OK;
  551. }
  552. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::get_Error(
  553. OUT HRESULT *phrErrorCode
  554. )
  555. {
  556. LOG((TL_TRACE, "get_Error[%p] - enter", this));
  557. //
  558. // check arguments
  559. //
  560. if (TAPIIsBadWritePtr(phrErrorCode, sizeof(HRESULT)))
  561. {
  562. LOG((TL_ERROR, "get_Error - bad pointer passed in"));
  563. return E_POINTER;
  564. }
  565. //
  566. // return error code
  567. //
  568. *phrErrorCode = m_hr;
  569. LOG((TL_TRACE, "get_Error - finish. hr = [%lx]", m_hr));
  570. return S_OK;
  571. }
  572. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_Terminal(
  573. IN ITTerminal *pTerminal
  574. )
  575. {
  576. LOG((TL_TRACE, "put_Terminal[%p] - enter", this));
  577. //
  578. // check the argument
  579. //
  580. if ((NULL != pTerminal) && IsBadReadPtr(pTerminal, sizeof(ITTerminal)))
  581. {
  582. LOG((TL_ERROR, "put_Terminal - bad pointer passed in"));
  583. //
  584. // if we get here, we have a bug. debug to see what happened.
  585. //
  586. _ASSERTE(FALSE);
  587. return E_POINTER;
  588. }
  589. //
  590. // keep the pointer
  591. //
  592. m_pParentFileTerminal = pTerminal;
  593. //
  594. // keep a reference if not null
  595. //
  596. if (NULL != m_pParentFileTerminal)
  597. {
  598. m_pParentFileTerminal->AddRef();
  599. }
  600. LOG((TL_TRACE, "put_Terminal - finished"));
  601. return S_OK;
  602. }
  603. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_Track(
  604. IN ITFileTrack *pFileTrack
  605. )
  606. {
  607. LOG((TL_TRACE, "put_Track[%p] - enter", this));
  608. //
  609. // check the argument
  610. //
  611. if ((NULL != pFileTrack) && IsBadReadPtr(pFileTrack, sizeof(ITFileTrack)))
  612. {
  613. LOG((TL_ERROR, "put_Track - bad pointer passed in"));
  614. //
  615. // if we get here, we have a bug. debug to see what happened.
  616. //
  617. _ASSERTE(FALSE);
  618. return E_POINTER;
  619. }
  620. //
  621. // keep the pointer
  622. //
  623. m_pFileTrack = pFileTrack;
  624. //
  625. // keep a reference if not null
  626. //
  627. if (NULL != m_pFileTrack)
  628. {
  629. m_pFileTrack->AddRef();
  630. }
  631. LOG((TL_TRACE, "put_Track - finished"));
  632. return S_OK;
  633. }
  634. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_Call(
  635. IN ITCallInfo *pCallInfo
  636. )
  637. {
  638. LOG((TL_TRACE, "put_Call[%p] - enter", this));
  639. //
  640. // check the argument
  641. //
  642. if ((NULL != pCallInfo) && IsBadReadPtr(pCallInfo, sizeof(ITCallInfo)))
  643. {
  644. LOG((TL_ERROR, "put_Call - bad pointer passed in"));
  645. //
  646. // if we get here, we have a bug. debug to see what happened.
  647. //
  648. _ASSERTE(FALSE);
  649. return E_POINTER;
  650. }
  651. //
  652. // keep the pointer
  653. //
  654. m_pCallInfo = pCallInfo;
  655. //
  656. // keep a reference if not null
  657. //
  658. if (NULL != m_pCallInfo)
  659. {
  660. m_pCallInfo->AddRef();
  661. }
  662. LOG((TL_TRACE, "put_Call - finished"));
  663. return S_OK;
  664. }
  665. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_State(
  666. IN TERMINAL_MEDIA_STATE tmsTerminalState
  667. )
  668. {
  669. LOG((TL_TRACE, "put_State[%p] - enter. State = [%x]", this, tmsTerminalState));
  670. //
  671. // keep the value
  672. //
  673. m_tmsTerminalState = tmsTerminalState;
  674. LOG((TL_TRACE, "put_State - finished"));
  675. return S_OK;
  676. }
  677. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_Cause(
  678. IN FT_STATE_EVENT_CAUSE Cause
  679. )
  680. {
  681. LOG((TL_TRACE, "put_Cause[%p] - enter. Cause = [%x]", this, Cause));
  682. //
  683. // keep the value
  684. //
  685. m_ftecEventCause = Cause;
  686. LOG((TL_TRACE, "put_Cause - finished"));
  687. return S_OK;
  688. }
  689. HRESULT STDMETHODCALLTYPE CFileTerminalEvent::put_ErrorCode(
  690. IN HRESULT hrErrorCode
  691. )
  692. {
  693. LOG((TL_TRACE, "put_ErrorCode[%p] - enter. hr = [%lx]", this, hrErrorCode));
  694. //
  695. // keep the value
  696. //
  697. m_hr = hrErrorCode;
  698. LOG((TL_TRACE, "put_ErrorCode - finished"));
  699. return S_OK;
  700. }
  701. HRESULT CToneTerminalEvent::FireEvent(
  702. CTAPI * pTapi,
  703. ITCallInfo *pCall,
  704. ITTerminal * pTerminal,
  705. HRESULT hrErrorCode
  706. )
  707. {
  708. STATICLOG((TL_TRACE, "FireEvent - enter" ));
  709. CCall *pCCall = NULL;
  710. pCCall = dynamic_cast<CComObject<CCall>*>(pCall);
  711. if (NULL == pCCall)
  712. {
  713. STATICLOG((TL_ERROR, "FireEvent - bad call pointer" ));
  714. return E_FAIL;
  715. }
  716. if( pCCall->DontExpose())
  717. {
  718. STATICLOG((TL_INFO, "FireEvent - Don't expose this call %p", pCCall));
  719. return S_OK;
  720. }
  721. if (NULL == pTapi)
  722. {
  723. STATICLOG((TL_ERROR, "FireEvent - tapi object is NULL" ));
  724. return E_POINTER;
  725. }
  726. //
  727. // create the event object
  728. //
  729. HRESULT hr = E_FAIL;
  730. CComObject<CToneTerminalEvent> *p;
  731. hr = CComObject<CToneTerminalEvent>::CreateInstance( &p );
  732. if (FAILED(hr))
  733. {
  734. STATICLOG((TL_ERROR, "FireEvent - could not createinstance" ));
  735. return E_OUTOFMEMORY;
  736. }
  737. //
  738. // save event information to the event object
  739. //
  740. hr = p->put_Call(pCall);
  741. if (FAILED(hr))
  742. {
  743. STATICLOG((TL_ERROR, "FireEvent - put_Call failed" ));
  744. delete p;
  745. return hr;
  746. }
  747. hr = p->put_Terminal(pTerminal);
  748. if (FAILED(hr))
  749. {
  750. STATICLOG((TL_ERROR, "FireEvent - put_Terminal failed" ));
  751. delete p;
  752. return hr;
  753. }
  754. hr = p->put_ErrorCode(hrErrorCode);
  755. if (FAILED(hr))
  756. {
  757. STATICLOG((TL_ERROR, "FireEvent - put_ErrorCode failed" ));
  758. delete p;
  759. return hr;
  760. }
  761. //
  762. // get the dispatch interface
  763. //
  764. IDispatch *pDisp = NULL;
  765. hr = p->_InternalQueryInterface( IID_IDispatch, (void **)&pDisp );
  766. if (FAILED(hr))
  767. {
  768. delete p;
  769. STATICLOG((TL_ERROR, "FireEvent - could not get IDispatch %lx", hr));
  770. return hr;
  771. }
  772. //
  773. // fire the event
  774. //
  775. pTapi->Event(
  776. TE_TONETERMINAL,
  777. pDisp
  778. );
  779. //
  780. // release our reference
  781. //
  782. pDisp->Release();
  783. STATICLOG((TL_TRACE, "FireEvent - exit - returing SUCCESS" ));
  784. return S_OK;
  785. }
  786. CToneTerminalEvent::CToneTerminalEvent()
  787. :m_pCallInfo(NULL),
  788. m_pTerminal(NULL),
  789. m_hr(S_OK)
  790. {
  791. LOG((TL_TRACE, "CToneTerminalEvent[%p] - enter", this));
  792. LOG((TL_TRACE, "CToneTerminalEvent - finish"));
  793. }
  794. CToneTerminalEvent::~CToneTerminalEvent()
  795. {
  796. LOG((TL_TRACE, "~CToneTerminalEvent[%p] - enter", this));
  797. //
  798. // remember to release all the references we may hold
  799. //
  800. if (NULL != m_pCallInfo)
  801. {
  802. LOG((TL_INFO, "~CToneTerminalEvent - releasing m_pCallInfo %p", m_pCallInfo));
  803. m_pCallInfo->Release();
  804. m_pCallInfo = NULL;
  805. }
  806. if ( NULL != m_pTerminal)
  807. {
  808. LOG((TL_INFO, "~CToneTerminalEvent - releasing m_pTerminal %p", m_pTerminal));
  809. m_pTerminal->Release();
  810. m_pTerminal = NULL;
  811. }
  812. LOG((TL_TRACE, "~CToneTerminalEvent - finish"));
  813. }
  814. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::get_Call(
  815. OUT ITCallInfo **ppCallInfo
  816. )
  817. {
  818. LOG((TL_TRACE, "get_Call[%p] - enter", this));
  819. //
  820. // check arguments
  821. //
  822. if (TAPIIsBadWritePtr(ppCallInfo, sizeof(ITCallInfo *)))
  823. {
  824. LOG((TL_ERROR, "get_Call - bad pointer passed in"));
  825. return E_POINTER;
  826. }
  827. //
  828. // no garbage out
  829. //
  830. *ppCallInfo = NULL;
  831. //
  832. // return call info if we have it
  833. //
  834. if (NULL != m_pCallInfo)
  835. {
  836. *ppCallInfo = m_pCallInfo;
  837. (*ppCallInfo)->AddRef();
  838. }
  839. LOG((TL_TRACE, "get_Call - finish"));
  840. return S_OK;
  841. }
  842. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::get_Terminal(
  843. OUT ITTerminal **ppTerminal
  844. )
  845. {
  846. LOG((TL_TRACE, "get_Terminal[%p] - enter", this));
  847. //
  848. // check arguments
  849. //
  850. if (TAPIIsBadWritePtr(ppTerminal, sizeof(ITTerminal*)))
  851. {
  852. LOG((TL_ERROR, "get_Terminal - bad pointer passed in"));
  853. return E_POINTER;
  854. }
  855. //
  856. // no garbage out
  857. //
  858. *ppTerminal = NULL;
  859. //
  860. // return terminal if we have it
  861. //
  862. if (NULL != m_pTerminal)
  863. {
  864. *ppTerminal = m_pTerminal;
  865. (*ppTerminal)->AddRef();
  866. }
  867. LOG((TL_TRACE, "get_Terminal - finish"));
  868. return S_OK;
  869. }
  870. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::get_Error(
  871. OUT HRESULT *phrErrorCode
  872. )
  873. {
  874. LOG((TL_TRACE, "get_Error[%p] - enter", this));
  875. //
  876. // check arguments
  877. //
  878. if (TAPIIsBadWritePtr(phrErrorCode, sizeof(HRESULT)))
  879. {
  880. LOG((TL_ERROR, "get_Error - bad pointer passed in"));
  881. return E_POINTER;
  882. }
  883. //
  884. // return error code
  885. //
  886. *phrErrorCode = m_hr;
  887. LOG((TL_TRACE, "get_Error - finish. hr = [%lx]", m_hr));
  888. return S_OK;
  889. }
  890. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::put_Terminal(
  891. IN ITTerminal *pTerminal
  892. )
  893. {
  894. LOG((TL_TRACE, "put_Terminal[%p] - enter", this));
  895. //
  896. // check the argument
  897. //
  898. if ((NULL != pTerminal) && IsBadReadPtr(pTerminal, sizeof(ITTerminal)))
  899. {
  900. LOG((TL_ERROR, "put_Terminal - bad pointer passed in"));
  901. //
  902. // if we get here, we have a bug. debug to see what happened.
  903. //
  904. _ASSERTE(FALSE);
  905. return E_POINTER;
  906. }
  907. //
  908. // keep the pointer
  909. //
  910. m_pTerminal = pTerminal;
  911. //
  912. // keep a reference if not null
  913. //
  914. if (NULL != m_pTerminal)
  915. {
  916. m_pTerminal->AddRef();
  917. }
  918. LOG((TL_TRACE, "put_Terminal - finished"));
  919. return S_OK;
  920. }
  921. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::put_Call(
  922. IN ITCallInfo *pCallInfo
  923. )
  924. {
  925. LOG((TL_TRACE, "put_Call[%p] - enter", this));
  926. //
  927. // check the argument
  928. //
  929. if ((NULL != pCallInfo) && IsBadReadPtr(pCallInfo, sizeof(ITCallInfo)))
  930. {
  931. LOG((TL_ERROR, "put_Call - bad pointer passed in"));
  932. //
  933. // if we get here, we have a bug. debug to see what happened.
  934. //
  935. _ASSERTE(FALSE);
  936. return E_POINTER;
  937. }
  938. //
  939. // keep the pointer
  940. //
  941. m_pCallInfo = pCallInfo;
  942. //
  943. // keep a reference if not null
  944. //
  945. if (NULL != m_pCallInfo)
  946. {
  947. m_pCallInfo->AddRef();
  948. }
  949. LOG((TL_TRACE, "put_Call - finished"));
  950. return S_OK;
  951. }
  952. HRESULT STDMETHODCALLTYPE CToneTerminalEvent::put_ErrorCode(
  953. IN HRESULT hrErrorCode
  954. )
  955. {
  956. LOG((TL_TRACE, "put_ErrorCode[%p] - enter. hr = [%lx]", this, hrErrorCode));
  957. //
  958. // keep the value
  959. //
  960. m_hr = hrErrorCode;
  961. LOG((TL_TRACE, "put_ErrorCode - finished"));
  962. return S_OK;
  963. }
  964. HRESULT CTTSTerminalEvent::FireEvent(
  965. CTAPI * pTapi,
  966. ITCallInfo *pCall,
  967. ITTerminal * pTerminal,
  968. HRESULT hrErrorCode
  969. )
  970. {
  971. STATICLOG((TL_TRACE, "FireEvent - enter" ));
  972. CCall *pCCall = NULL;
  973. pCCall = dynamic_cast<CComObject<CCall>*>(pCall);
  974. if (NULL == pCCall)
  975. {
  976. STATICLOG((TL_ERROR, "FireEvent - bad call pointer" ));
  977. return E_FAIL;
  978. }
  979. if( pCCall->DontExpose())
  980. {
  981. STATICLOG((TL_INFO, "FireEvent - Don't expose this call %p", pCCall));
  982. return S_OK;
  983. }
  984. if (NULL == pTapi)
  985. {
  986. STATICLOG((TL_ERROR, "FireEvent - tapi object is NULL" ));
  987. return E_POINTER;
  988. }
  989. //
  990. // create the event object
  991. //
  992. HRESULT hr = E_FAIL;
  993. CComObject<CTTSTerminalEvent> *p;
  994. hr = CComObject<CTTSTerminalEvent>::CreateInstance( &p );
  995. if (FAILED(hr))
  996. {
  997. STATICLOG((TL_ERROR, "FireEvent - could not createinstance" ));
  998. return E_OUTOFMEMORY;
  999. }
  1000. //
  1001. // save event information to the event object
  1002. //
  1003. hr = p->put_Call(pCall);
  1004. if (FAILED(hr))
  1005. {
  1006. STATICLOG((TL_ERROR, "FireEvent - put_Call failed" ));
  1007. delete p;
  1008. return hr;
  1009. }
  1010. hr = p->put_Terminal(pTerminal);
  1011. if (FAILED(hr))
  1012. {
  1013. STATICLOG((TL_ERROR, "FireEvent - put_Terminal failed" ));
  1014. delete p;
  1015. return hr;
  1016. }
  1017. hr = p->put_ErrorCode(hrErrorCode);
  1018. if (FAILED(hr))
  1019. {
  1020. STATICLOG((TL_ERROR, "FireEvent - put_ErrorCode failed" ));
  1021. delete p;
  1022. return hr;
  1023. }
  1024. //
  1025. // get the dispatch interface
  1026. //
  1027. IDispatch *pDisp = NULL;
  1028. hr = p->_InternalQueryInterface( IID_IDispatch, (void **)&pDisp );
  1029. if (FAILED(hr))
  1030. {
  1031. delete p;
  1032. STATICLOG((TL_ERROR, "FireEvent - could not get IDispatch %lx", hr));
  1033. return hr;
  1034. }
  1035. //
  1036. // fire the event
  1037. //
  1038. pTapi->Event(
  1039. TE_TTSTERMINAL,
  1040. pDisp
  1041. );
  1042. //
  1043. // release our reference
  1044. //
  1045. pDisp->Release();
  1046. STATICLOG((TL_TRACE, "FireEvent - exit - returing SUCCESS" ));
  1047. return S_OK;
  1048. }
  1049. CTTSTerminalEvent::CTTSTerminalEvent()
  1050. :m_pCallInfo(NULL),
  1051. m_pTerminal(NULL),
  1052. m_hr(S_OK)
  1053. {
  1054. LOG((TL_TRACE, "CTTSTerminalEvent[%p] - enter", this));
  1055. LOG((TL_TRACE, "CTTSTerminalEvent - finish"));
  1056. }
  1057. CTTSTerminalEvent::~CTTSTerminalEvent()
  1058. {
  1059. LOG((TL_TRACE, "~CTTSTerminalEvent[%p] - enter", this));
  1060. //
  1061. // remember to release all the references we may hold
  1062. //
  1063. if (NULL != m_pCallInfo)
  1064. {
  1065. LOG((TL_INFO, "~CTTSTerminalEvent - releasing m_pCallInfo %p", m_pCallInfo));
  1066. m_pCallInfo->Release();
  1067. m_pCallInfo = NULL;
  1068. }
  1069. if ( NULL != m_pTerminal)
  1070. {
  1071. LOG((TL_INFO, "~CTTSTerminalEvent - releasing m_pTerminal %p", m_pTerminal));
  1072. m_pTerminal->Release();
  1073. m_pTerminal = NULL;
  1074. }
  1075. LOG((TL_TRACE, "~CTTSTerminalEvent - finish"));
  1076. }
  1077. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::get_Call(
  1078. OUT ITCallInfo **ppCallInfo
  1079. )
  1080. {
  1081. LOG((TL_TRACE, "get_Call[%p] - enter", this));
  1082. //
  1083. // check arguments
  1084. //
  1085. if (TAPIIsBadWritePtr(ppCallInfo, sizeof(ITCallInfo *)))
  1086. {
  1087. LOG((TL_ERROR, "get_Call - bad pointer passed in"));
  1088. return E_POINTER;
  1089. }
  1090. //
  1091. // no garbage out
  1092. //
  1093. *ppCallInfo = NULL;
  1094. //
  1095. // return call info if we have it
  1096. //
  1097. if (NULL != m_pCallInfo)
  1098. {
  1099. *ppCallInfo = m_pCallInfo;
  1100. (*ppCallInfo)->AddRef();
  1101. }
  1102. LOG((TL_TRACE, "get_Call - finish"));
  1103. return S_OK;
  1104. }
  1105. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::get_Terminal(
  1106. OUT ITTerminal **ppTerminal
  1107. )
  1108. {
  1109. LOG((TL_TRACE, "get_Terminal[%p] - enter", this));
  1110. //
  1111. // check arguments
  1112. //
  1113. if (TAPIIsBadWritePtr(ppTerminal, sizeof(ITTerminal*)))
  1114. {
  1115. LOG((TL_ERROR, "get_Terminal - bad pointer passed in"));
  1116. return E_POINTER;
  1117. }
  1118. //
  1119. // no garbage out
  1120. //
  1121. *ppTerminal = NULL;
  1122. //
  1123. // return terminal if we have it
  1124. //
  1125. if (NULL != m_pTerminal)
  1126. {
  1127. *ppTerminal = m_pTerminal;
  1128. (*ppTerminal)->AddRef();
  1129. }
  1130. LOG((TL_TRACE, "get_Terminal - finish"));
  1131. return S_OK;
  1132. }
  1133. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::get_Error(
  1134. OUT HRESULT *phrErrorCode
  1135. )
  1136. {
  1137. LOG((TL_TRACE, "get_Error[%p] - enter", this));
  1138. //
  1139. // check arguments
  1140. //
  1141. if (TAPIIsBadWritePtr(phrErrorCode, sizeof(HRESULT)))
  1142. {
  1143. LOG((TL_ERROR, "get_Error - bad pointer passed in"));
  1144. return E_POINTER;
  1145. }
  1146. //
  1147. // return error code
  1148. //
  1149. *phrErrorCode = m_hr;
  1150. LOG((TL_TRACE, "get_Error - finish. hr = [%lx]", m_hr));
  1151. return S_OK;
  1152. }
  1153. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::put_Terminal(
  1154. IN ITTerminal *pTerminal
  1155. )
  1156. {
  1157. LOG((TL_TRACE, "put_Terminal[%p] - enter", this));
  1158. //
  1159. // check the argument
  1160. //
  1161. if ((NULL != pTerminal) && IsBadReadPtr(pTerminal, sizeof(ITTerminal)))
  1162. {
  1163. LOG((TL_ERROR, "put_Terminal - bad pointer passed in"));
  1164. //
  1165. // if we get here, we have a bug. debug to see what happened.
  1166. //
  1167. _ASSERTE(FALSE);
  1168. return E_POINTER;
  1169. }
  1170. //
  1171. // keep the pointer
  1172. //
  1173. m_pTerminal = pTerminal;
  1174. //
  1175. // keep a reference if not null
  1176. //
  1177. if (NULL != m_pTerminal)
  1178. {
  1179. m_pTerminal->AddRef();
  1180. }
  1181. LOG((TL_TRACE, "put_Terminal - finished"));
  1182. return S_OK;
  1183. }
  1184. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::put_Call(
  1185. IN ITCallInfo *pCallInfo
  1186. )
  1187. {
  1188. LOG((TL_TRACE, "put_Call[%p] - enter", this));
  1189. //
  1190. // check the argument
  1191. //
  1192. if ((NULL != pCallInfo) && IsBadReadPtr(pCallInfo, sizeof(ITCallInfo)))
  1193. {
  1194. LOG((TL_ERROR, "put_Call - bad pointer passed in"));
  1195. //
  1196. // if we get here, we have a bug. debug to see what happened.
  1197. //
  1198. _ASSERTE(FALSE);
  1199. return E_POINTER;
  1200. }
  1201. //
  1202. // keep the pointer
  1203. //
  1204. m_pCallInfo = pCallInfo;
  1205. //
  1206. // keep a reference if not null
  1207. //
  1208. if (NULL != m_pCallInfo)
  1209. {
  1210. m_pCallInfo->AddRef();
  1211. }
  1212. LOG((TL_TRACE, "put_Call - finished"));
  1213. return S_OK;
  1214. }
  1215. HRESULT STDMETHODCALLTYPE CTTSTerminalEvent::put_ErrorCode(
  1216. IN HRESULT hrErrorCode
  1217. )
  1218. {
  1219. LOG((TL_TRACE, "put_ErrorCode[%p] - enter. hr = [%lx]", this, hrErrorCode));
  1220. //
  1221. // keep the value
  1222. //
  1223. m_hr = hrErrorCode;
  1224. LOG((TL_TRACE, "put_ErrorCode - finished"));
  1225. return S_OK;
  1226. }