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.

10596 lines
273 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. phone.cpp
  5. Abstract:
  6. Implementation of phone object for TAPI 3.1
  7. Notes:
  8. optional-notes
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #define TIMER_KEEP_ALIVE 0x0FFFFFFF
  13. /////////////////////////////////////////////////////////////////////////////
  14. // IDispatch implementation
  15. //
  16. typedef IDispatchImpl<ITPhoneVtbl<CPhone>,
  17. &IID_ITPhone,
  18. &LIBID_TAPI3Lib>
  19. PhoneType;
  20. typedef IDispatchImpl<ITAutomatedPhoneControlVtbl<CPhone>,
  21. &IID_ITAutomatedPhoneControl,
  22. &LIBID_TAPI3Lib>
  23. AutomatedPhoneControlType;
  24. extern HRESULT mapTAPIErrorCode(long lErrorCode);
  25. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  26. //
  27. // CPhone::GetIDsOfNames
  28. //
  29. // Overidden IDispatch method
  30. //
  31. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  32. STDMETHODIMP CPhone::GetIDsOfNames(REFIID riid,
  33. LPOLESTR* rgszNames,
  34. UINT cNames,
  35. LCID lcid,
  36. DISPID* rgdispid
  37. )
  38. {
  39. HRESULT hr = DISP_E_UNKNOWNNAME;
  40. // See if the requsted method belongs to the default interface
  41. hr = PhoneType::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  42. if (SUCCEEDED(hr))
  43. {
  44. LOG((TL_INFO, "GetIDsOfNames - found %S on ITPhone", *rgszNames));
  45. rgdispid[0] |= IDISPPHONE;
  46. return hr;
  47. }
  48. // If not, then try the ITAutomatedPhoneControl interface
  49. hr = AutomatedPhoneControlType::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid);
  50. if (SUCCEEDED(hr))
  51. {
  52. LOG((TL_INFO, "GetIDsOfNames - found %S on ITAutomatedPhoneControl", *rgszNames));
  53. rgdispid[0] |= IDISPAPC;
  54. return hr;
  55. }
  56. LOG((TL_INFO, "GetIDsOfNames - Didn't find %S on our iterfaces", *rgszNames));
  57. return hr;
  58. }
  59. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  60. //
  61. // CPhone::Invoke
  62. //
  63. // Overide if IDispatch method
  64. //
  65. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  66. STDMETHODIMP CPhone::Invoke(DISPID dispidMember,
  67. REFIID riid,
  68. LCID lcid,
  69. WORD wFlags,
  70. DISPPARAMS* pdispparams,
  71. VARIANT* pvarResult,
  72. EXCEPINFO* pexcepinfo,
  73. UINT* puArgErr
  74. )
  75. {
  76. HRESULT hr = DISP_E_MEMBERNOTFOUND;
  77. DWORD dwInterface = (dispidMember & INTERFACEMASK);
  78. LOG((TL_TRACE, "Invoke - dispidMember %X", dispidMember));
  79. // Call invoke for the required interface
  80. switch (dwInterface)
  81. {
  82. case IDISPPHONE:
  83. {
  84. hr = PhoneType::Invoke(dispidMember,
  85. riid,
  86. lcid,
  87. wFlags,
  88. pdispparams,
  89. pvarResult,
  90. pexcepinfo,
  91. puArgErr
  92. );
  93. break;
  94. }
  95. case IDISPAPC:
  96. {
  97. hr = AutomatedPhoneControlType::Invoke(dispidMember,
  98. riid,
  99. lcid,
  100. wFlags,
  101. pdispparams,
  102. pvarResult,
  103. pexcepinfo,
  104. puArgErr
  105. );
  106. break;
  107. }
  108. } // end switch (dwInterface)
  109. LOG((TL_TRACE, hr, "Invoke - exit" ));
  110. return hr;
  111. }
  112. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  113. //
  114. // CPhone::InternalAddRef
  115. //
  116. // Overidden IDispatch method
  117. //
  118. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  119. STDMETHODIMP_(ULONG) CPhone::InternalAddRef()
  120. {
  121. DWORD dwR;
  122. dwR = InterlockedIncrement(&m_dwRef);
  123. LOG((TL_INFO, "InternalAddRef - dwR %d",dwR ));
  124. #if DBG
  125. LogDebugAddRef(m_dwRef);
  126. #endif
  127. return dwR;
  128. }
  129. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  130. //
  131. // CPhone::InternalRelease
  132. //
  133. // Overidden IDispatch method
  134. //
  135. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  136. STDMETHODIMP_(ULONG) CPhone::InternalRelease()
  137. {
  138. DWORD dwR;
  139. PtrList::iterator iter, end;
  140. T3LINE * pt3Line;
  141. LOG((TL_INFO, "InternalRelease - m_dwRef %d",m_dwRef ));
  142. Lock();
  143. gpPhoneHashTable->Lock();
  144. dwR = InterlockedDecrement(&m_dwRef);
  145. // if ref count is 0 (means we entered function with 1) then we final release
  146. if (0 == dwR)
  147. {
  148. // remove from the hash table, so any more messages
  149. // from tapisrv are ignored
  150. //
  151. if (m_hPhone)
  152. {
  153. if(FAILED(gpPhoneHashTable->Remove( (ULONG_PTR)(m_hPhone) ) ))
  154. {
  155. LOG((TL_INFO, "InternalRelease - pLineHashTable->Remove failed" ));
  156. }
  157. }
  158. gpPhoneHashTable->Unlock();
  159. dwR = m_dwRef = 0;
  160. Unlock();
  161. LOG((TL_INFO, "InternalRelease - final OK dwR %d",dwR ));
  162. }
  163. else
  164. {
  165. gpPhoneHashTable->Unlock();
  166. Unlock();
  167. LOG((TL_INFO, "InternalRelease - not final dwR %d",dwR ));
  168. }
  169. #if DBG
  170. LogDebugRelease( dwR );
  171. #endif
  172. return dwR;
  173. }
  174. //////////////////////////////////////////////////////////////////////////////
  175. //////////////////////////////////////////////////////////////////////////////
  176. //
  177. // ITPhone methods
  178. //
  179. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  180. //
  181. // Open
  182. //
  183. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  184. STDMETHODIMP
  185. CPhone::Open(
  186. PHONE_PRIVILEGE Privilege
  187. )
  188. {
  189. DWORD dwPrivilege;
  190. T3PHONE t3Phone;
  191. HRESULT hr;
  192. LOG((TL_TRACE, "Open - enter" ));
  193. Lock();
  194. //
  195. // We cannot be opened multiple time simultaneously
  196. // return TAPI_E_INUSE if someone else has us open
  197. //
  198. if (m_hPhone)
  199. {
  200. LOG((TL_TRACE, "Open - phone in use" ));
  201. Unlock();
  202. return TAPI_E_INUSE;
  203. }
  204. switch(Privilege)
  205. {
  206. case PP_OWNER:
  207. dwPrivilege = PHONEPRIVILEGE_OWNER;
  208. break;
  209. case PP_MONITOR:
  210. dwPrivilege = PHONEPRIVILEGE_MONITOR;
  211. break;
  212. default:
  213. {
  214. LOG((TL_TRACE, "Open - invalid privilege" ));
  215. Unlock();
  216. return TAPI_E_INVALPRIVILEGE;
  217. }
  218. break;
  219. }
  220. t3Phone.hPhone = NULL;
  221. t3Phone.pPhone = this;
  222. hr = PhoneOpen(m_hPhoneApp, m_dwDeviceID, &t3Phone, m_dwAPIVersion, dwPrivilege);
  223. if ( SUCCEEDED(hr) )
  224. {
  225. hr = PhoneSetStatusMessages(&t3Phone,
  226. PHONESTATE_CAPSCHANGE |
  227. PHONESTATE_HANDSETHOOKSWITCH |
  228. PHONESTATE_HEADSETHOOKSWITCH |
  229. PHONESTATE_LAMP |
  230. PHONESTATE_RINGMODE |
  231. PHONESTATE_RINGVOLUME |
  232. PHONESTATE_SPEAKERHOOKSWITCH |
  233. PHONESTATE_DISPLAY,
  234. PHONEBUTTONMODE_CALL |
  235. PHONEBUTTONMODE_DISPLAY |
  236. PHONEBUTTONMODE_DUMMY |
  237. PHONEBUTTONMODE_FEATURE |
  238. PHONEBUTTONMODE_KEYPAD |
  239. PHONEBUTTONMODE_LOCAL,
  240. PHONEBUTTONSTATE_UP |
  241. PHONEBUTTONSTATE_DOWN |
  242. PHONEBUTTONSTATE_UNKNOWN |
  243. PHONEBUTTONSTATE_UNAVAIL);
  244. if ( SUCCEEDED(hr) )
  245. {
  246. m_hPhone = t3Phone.hPhone;
  247. m_dwPrivilege = dwPrivilege;
  248. }
  249. else
  250. {
  251. PhoneClose(t3Phone.hPhone);
  252. }
  253. }
  254. //
  255. // Defaults for phone automation settings
  256. //
  257. m_fPhoneHandlingEnabled = FALSE;
  258. m_dwAutoEndOfNumberTimeout = APC_DEFAULT_AEONT;
  259. m_fAutoDialtone = TRUE;
  260. m_fAutoStopTonesOnOnHook = TRUE;
  261. m_fAutoStopRingOnOffHook = TRUE;
  262. m_fAutoKeypadTones = TRUE;
  263. m_dwAutoKeypadTonesMinimumDuration = APC_DEFAULT_AKTMD;
  264. m_fAutoVolumeControl = TRUE;
  265. m_dwAutoVolumeControlStep = APC_DEFAULT_VCS;
  266. m_dwAutoVolumeControlRepeatDelay = APC_DEFAULT_VCRD;
  267. m_dwAutoVolumeControlRepeatPeriod = APC_DEFAULT_VCRP;
  268. Unlock();
  269. if ( FAILED(hr) )
  270. {
  271. LOG((TL_TRACE, "Open - PhoneOpen returned failure - "
  272. "exit 0x%08x", hr ));
  273. return hr;
  274. }
  275. LOG((TL_TRACE, "Open - exit S_OK"));
  276. return S_OK;
  277. }
  278. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  279. //
  280. // Close
  281. //
  282. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  283. STDMETHODIMP
  284. CPhone::Close()
  285. {
  286. HRESULT hr;
  287. LOG((TL_TRACE, "Close - enter" ));
  288. Lock();
  289. if ( m_hPhone == NULL )
  290. {
  291. LOG((TL_WARN, "Close - phone not open - return S_OK"));
  292. Unlock();
  293. return S_OK;
  294. }
  295. if (m_dwPrivilege == PHONEPRIVILEGE_OWNER)
  296. {
  297. //
  298. // Turn off automatic phone handling
  299. //
  300. m_fPhoneHandlingEnabled = FALSE;
  301. //
  302. // Stop any ringers or tones
  303. //
  304. if (m_fRinger == TRUE)
  305. {
  306. StopRinger();
  307. }
  308. if (m_Tone != PT_SILENCE)
  309. {
  310. StopTone();
  311. }
  312. CloseWaveDevice();
  313. //
  314. // Unselect any calls
  315. //
  316. if (m_pCall != NULL)
  317. {
  318. InternalUnselectCall(m_pCall);
  319. }
  320. }
  321. //
  322. // Finally, actually close the phone
  323. //
  324. hr = PhoneClose(m_hPhone);
  325. m_hPhone = NULL;
  326. Unlock();
  327. LOG((TL_TRACE, "Close - exit - return %lx", hr));
  328. return hr;
  329. }
  330. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  331. //
  332. // get_Addresses
  333. //
  334. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  335. STDMETHODIMP
  336. CPhone::get_Addresses(
  337. VARIANT *pAddresses
  338. )
  339. {
  340. IEnumAddress * pEnum;
  341. ITAddress * pAddress;
  342. AddressArray aAddresses;
  343. HRESULT hr;
  344. IDispatch * pDisp;
  345. LOG((TL_TRACE, "get_Addresses - enter" ));
  346. if ( TAPIIsBadWritePtr( pAddresses, sizeof (VARIANT) ) )
  347. {
  348. LOG((TL_ERROR, "get_Addresses - bad pointer"));
  349. return E_POINTER;
  350. }
  351. Lock();
  352. //
  353. // get the addresses from tapi
  354. //
  355. hr = m_pTAPI->EnumerateAddresses( &pEnum );
  356. if ( FAILED(hr) )
  357. {
  358. LOG((TL_ERROR, "get_Addresses - could not enumerate addresses from tapi - return %lx", hr));
  359. Unlock();
  360. return hr;
  361. }
  362. //
  363. // choose only addresses that this phone is on
  364. //
  365. while ( S_OK == pEnum->Next( 1, &pAddress, NULL ) )
  366. {
  367. if (IsPhoneOnAddress( pAddress ))
  368. {
  369. if ( !aAddresses.Add( pAddress ) )
  370. {
  371. LOG((TL_ERROR, "get_Addresses - could add address to array"));
  372. }
  373. }
  374. pAddress->Release();
  375. }
  376. pEnum->Release();
  377. Unlock();
  378. //
  379. // create the collection
  380. //
  381. CComObject< CTapiCollection< ITAddress > > * p;
  382. hr = CComObject< CTapiCollection< ITAddress > >::CreateInstance( &p );
  383. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  384. {
  385. LOG((TL_ERROR, "get_Addresses - could not create collection" ));
  386. return E_OUTOFMEMORY;
  387. }
  388. //
  389. // get the IDispatch interface
  390. //
  391. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  392. if ( FAILED(hr) )
  393. {
  394. LOG((TL_ERROR, "get_Addresses - could not get IDispatch interface" ));
  395. delete p;
  396. return hr;
  397. }
  398. hr = p->Initialize( aAddresses );
  399. aAddresses.Shutdown();
  400. if ( FAILED(hr) )
  401. {
  402. LOG((TL_ERROR, "get_Addresses - could not initialize collection" ));
  403. pDisp->Release();
  404. return hr;
  405. }
  406. //
  407. // put it in the variant
  408. //
  409. VariantInit(pAddresses);
  410. pAddresses->vt = VT_DISPATCH;
  411. pAddresses->pdispVal = pDisp;
  412. LOG((TL_TRACE, "get_Addresses - exit - return %lx", hr));
  413. return hr;
  414. }
  415. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  416. //
  417. // EnumerateAddresses
  418. //
  419. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  420. STDMETHODIMP
  421. CPhone::EnumerateAddresses(
  422. IEnumAddress ** ppEnumAddress
  423. )
  424. {
  425. IEnumAddress * pEnumAddress;
  426. ITAddress * pAddress;
  427. AddressArray aAddresses;
  428. HRESULT hr;
  429. LOG((TL_TRACE, "EnumerateAddresses - enter" ));
  430. if ( TAPIIsBadWritePtr( ppEnumAddress, sizeof (IEnumAddress *) ) )
  431. {
  432. LOG((TL_ERROR, "EnumerateAddresses - bad pointer"));
  433. return E_POINTER;
  434. }
  435. Lock();
  436. //
  437. // get the addresses from tapi
  438. //
  439. hr = m_pTAPI->EnumerateAddresses( &pEnumAddress );
  440. if ( FAILED(hr) )
  441. {
  442. LOG((TL_ERROR, "EnumerateAddresses - could not enumerate addresses from tapi - return %lx", hr));
  443. Unlock();
  444. return hr;
  445. }
  446. //
  447. // choose only addresses that this phone is on
  448. //
  449. while ( S_OK == pEnumAddress->Next( 1, &pAddress, NULL ) )
  450. {
  451. if (IsPhoneOnAddress( pAddress ))
  452. {
  453. if ( !aAddresses.Add( pAddress ) )
  454. {
  455. LOG((TL_ERROR, "EnumerateAddresses - could add address to array"));
  456. }
  457. }
  458. pAddress->Release();
  459. }
  460. pEnumAddress->Release();
  461. Unlock();
  462. //
  463. // create the enum
  464. //
  465. CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> > * pEnum;
  466. hr = CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> >::CreateInstance( &pEnum );
  467. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  468. {
  469. LOG((TL_ERROR, "EnumerateAddresses - could not create enum - return %lx", hr));
  470. return hr;
  471. }
  472. //
  473. // initialize
  474. //
  475. hr = pEnum->Initialize( aAddresses );
  476. aAddresses.Shutdown();
  477. if ( FAILED(hr) )
  478. {
  479. pEnum->Release();
  480. LOG((TL_ERROR, "EnumerateAddresses - could not initialize enum - return %lx", hr));
  481. return hr;
  482. }
  483. *ppEnumAddress = pEnum;
  484. LOG((TL_TRACE, "EnumerateAddresses - exit - return %lx", hr));
  485. return hr;
  486. }
  487. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  488. //
  489. // get_PreferredAddresses
  490. //
  491. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  492. STDMETHODIMP
  493. CPhone::get_PreferredAddresses(
  494. VARIANT *pAddresses
  495. )
  496. {
  497. IEnumAddress * pEnum;
  498. ITAddress * pAddress;
  499. AddressArray aAddresses;
  500. HRESULT hr;
  501. IDispatch * pDisp;
  502. LOG((TL_TRACE, "get_PreferredAddresses - enter" ));
  503. if ( TAPIIsBadWritePtr( pAddresses, sizeof (VARIANT) ) )
  504. {
  505. LOG((TL_ERROR, "get_PreferredAddresses - bad pointer"));
  506. return E_POINTER;
  507. }
  508. Lock();
  509. //
  510. // get the addresses from tapi
  511. //
  512. hr = m_pTAPI->EnumerateAddresses( &pEnum );
  513. if ( FAILED(hr) )
  514. {
  515. LOG((TL_ERROR, "get_PreferredAddresses - could not enumerate addresses from tapi - return %lx", hr));
  516. Unlock();
  517. return hr;
  518. }
  519. //
  520. // choose only addresses that this phone is on
  521. //
  522. while ( S_OK == pEnum->Next( 1, &pAddress, NULL ) )
  523. {
  524. if (IsPhoneOnPreferredAddress( pAddress ))
  525. {
  526. if ( !aAddresses.Add( pAddress ) )
  527. {
  528. LOG((TL_ERROR, "get_PreferredAddresses - could add address to array"));
  529. }
  530. }
  531. pAddress->Release();
  532. }
  533. pEnum->Release();
  534. Unlock();
  535. //
  536. // create the collection
  537. //
  538. CComObject< CTapiCollection< ITAddress > > * p;
  539. hr = CComObject< CTapiCollection< ITAddress > >::CreateInstance( &p );
  540. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  541. {
  542. LOG((TL_ERROR, "get_PreferredAddresses - could not create collection" ));
  543. return E_OUTOFMEMORY;
  544. }
  545. //
  546. // get the IDispatch interface
  547. //
  548. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  549. if ( FAILED(hr) )
  550. {
  551. LOG((TL_ERROR, "get_PreferredAddresses - could not get IDispatch interface" ));
  552. delete p;
  553. return hr;
  554. }
  555. hr = p->Initialize( aAddresses );
  556. aAddresses.Shutdown();
  557. if ( FAILED(hr) )
  558. {
  559. LOG((TL_ERROR, "get_PreferredAddresses - could not initialize collection" ));
  560. pDisp->Release();
  561. return hr;
  562. }
  563. //
  564. // put it in the variant
  565. //
  566. VariantInit(pAddresses);
  567. pAddresses->vt = VT_DISPATCH;
  568. pAddresses->pdispVal = pDisp;
  569. LOG((TL_TRACE, "get_PreferredAddresses - exit - return %lx", hr));
  570. return hr;
  571. }
  572. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  573. //
  574. // EnumeratePreferredAddresses
  575. //
  576. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  577. STDMETHODIMP
  578. CPhone::EnumeratePreferredAddresses(
  579. IEnumAddress ** ppEnumAddress
  580. )
  581. {
  582. IEnumAddress * pEnumAddress;
  583. ITAddress * pAddress;
  584. AddressArray aAddresses;
  585. HRESULT hr;
  586. LOG((TL_TRACE, "EnumeratePreferredAddresses - enter" ));
  587. if ( TAPIIsBadWritePtr( ppEnumAddress, sizeof (IEnumAddress *) ) )
  588. {
  589. LOG((TL_ERROR, "EnumeratePreferredAddresses - bad pointer"));
  590. return E_POINTER;
  591. }
  592. Lock();
  593. //
  594. // get the addresses from tapi
  595. //
  596. hr = m_pTAPI->EnumerateAddresses( &pEnumAddress );
  597. if ( FAILED(hr) )
  598. {
  599. LOG((TL_ERROR, "EnumeratePreferredAddresses - could not enumerate addresses from tapi - return %lx", hr));
  600. Unlock();
  601. return hr;
  602. }
  603. //
  604. // choose only addresses that this phone is on
  605. //
  606. while ( S_OK == pEnumAddress->Next( 1, &pAddress, NULL ) )
  607. {
  608. if (IsPhoneOnPreferredAddress( pAddress ))
  609. {
  610. if ( !aAddresses.Add( pAddress ) )
  611. {
  612. LOG((TL_ERROR, "EnumeratePreferredAddresses - could add address to array"));
  613. }
  614. }
  615. pAddress->Release();
  616. }
  617. pEnumAddress->Release();
  618. Unlock();
  619. //
  620. // create the enum
  621. //
  622. CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> > * pEnum;
  623. hr = CComObject< CTapiEnum<IEnumAddress, ITAddress, &IID_IEnumAddress> >::CreateInstance( &pEnum );
  624. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  625. {
  626. LOG((TL_ERROR, "EnumeratePreferredAddresses - could not create enum - return %lx", hr));
  627. return hr;
  628. }
  629. //
  630. // initialize
  631. //
  632. hr = pEnum->Initialize( aAddresses );
  633. aAddresses.Shutdown();
  634. if ( FAILED(hr) )
  635. {
  636. pEnum->Release();
  637. LOG((TL_ERROR, "EnumeratePreferredAddresses - could not initialize enum - return %lx", hr));
  638. return hr;
  639. }
  640. *ppEnumAddress = pEnum;
  641. LOG((TL_TRACE, "EnumeratePreferredAddresses - exit - return %lx", hr));
  642. return hr;
  643. }
  644. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  645. //
  646. // get_PhoneCapsLong
  647. //
  648. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  649. STDMETHODIMP
  650. CPhone::get_PhoneCapsLong(
  651. PHONECAPS_LONG pclCap,
  652. long * plCapability
  653. )
  654. {
  655. HRESULT hr = S_OK;
  656. if ( TAPIIsBadWritePtr( plCapability, sizeof(long) ) )
  657. {
  658. LOG((TL_ERROR, "get_PhoneCapsLong - bad pointer"));
  659. return E_POINTER;
  660. }
  661. LOG((TL_TRACE, "get_PhoneCapsLong - enter" ));
  662. Lock();
  663. //
  664. // Update the cache
  665. //
  666. hr = UpdatePhoneCaps();
  667. if ( FAILED(hr) )
  668. {
  669. LOG((TL_ERROR, "get_PhoneCapsLong - could not get phonecaps"));
  670. Unlock();
  671. return hr;
  672. }
  673. switch (pclCap)
  674. {
  675. case PCL_HOOKSWITCHES:
  676. *plCapability = m_pPhoneCaps->dwHookSwitchDevs;
  677. break;
  678. case PCL_HANDSETHOOKSWITCHMODES:
  679. *plCapability = m_pPhoneCaps->dwHandsetHookSwitchModes;
  680. break;
  681. case PCL_HEADSETHOOKSWITCHMODES:
  682. *plCapability = m_pPhoneCaps->dwHeadsetHookSwitchModes;
  683. break;
  684. case PCL_SPEAKERPHONEHOOKSWITCHMODES:
  685. *plCapability = m_pPhoneCaps->dwSpeakerHookSwitchModes;
  686. break;
  687. case PCL_DISPLAYNUMROWS:
  688. *plCapability = m_pPhoneCaps->dwDisplayNumRows;
  689. break;
  690. case PCL_DISPLAYNUMCOLUMNS:
  691. *plCapability = m_pPhoneCaps->dwDisplayNumColumns;
  692. break;
  693. case PCL_NUMRINGMODES:
  694. *plCapability = m_pPhoneCaps->dwNumRingModes;
  695. break;
  696. case PCL_NUMBUTTONLAMPS:
  697. *plCapability = m_pPhoneCaps->dwNumButtonLamps;
  698. break;
  699. case PCL_GENERICPHONE:
  700. if( m_dwAPIVersion >= TAPI_VERSION2_0 )
  701. {
  702. *plCapability = (m_pPhoneCaps->dwPhoneFeatures & PHONEFEATURE_GENERICPHONE) ? 1:0;
  703. }
  704. else
  705. {
  706. *plCapability = 0;
  707. }
  708. break;
  709. default:
  710. LOG((TL_ERROR, "get_PhoneCapsLong - bad pclCap"));
  711. Unlock();
  712. return E_INVALIDARG;
  713. }
  714. Unlock();
  715. LOG((TL_TRACE, "get_PhoneCapsLong - exit - return %lx", hr));
  716. return hr;
  717. }
  718. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  719. //
  720. // get_PhoneCapsString
  721. //
  722. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  723. STDMETHODIMP
  724. CPhone::get_PhoneCapsString(
  725. PHONECAPS_STRING pcsCap,
  726. BSTR * ppCapability
  727. )
  728. {
  729. HRESULT hr;
  730. if ( TAPIIsBadWritePtr( ppCapability, sizeof(BSTR) ) )
  731. {
  732. LOG((TL_ERROR, "get_PhoneCapsString - bad pointer"));
  733. return E_POINTER;
  734. }
  735. LOG((TL_TRACE, "get_PhoneCapsString - enter" ));
  736. Lock();
  737. //
  738. // Update the cache
  739. //
  740. hr = UpdatePhoneCaps();
  741. if ( FAILED(hr) )
  742. {
  743. LOG((TL_ERROR, "get_PhoneCapsString - could not get phonecaps - %lx", hr));
  744. Unlock();
  745. return hr;
  746. }
  747. DWORD dwSize;
  748. DWORD dwOffset;
  749. //
  750. // Get the size and offset of the string in the phone caps
  751. //
  752. switch (pcsCap)
  753. {
  754. case PCS_PHONENAME:
  755. dwSize = m_pPhoneCaps->dwPhoneNameSize;
  756. dwOffset = m_pPhoneCaps->dwPhoneNameOffset;
  757. break;
  758. case PCS_PHONEINFO:
  759. dwSize = m_pPhoneCaps->dwPhoneInfoSize;
  760. dwOffset = m_pPhoneCaps->dwPhoneInfoOffset;
  761. break;
  762. case PCS_PROVIDERINFO:
  763. dwSize = m_pPhoneCaps->dwProviderInfoSize;
  764. dwOffset = m_pPhoneCaps->dwProviderInfoOffset;
  765. break;
  766. default:
  767. LOG((TL_ERROR, "get_PhoneCapsString - bad pcsCap"));
  768. Unlock();
  769. return E_INVALIDARG;
  770. }
  771. //
  772. // Allocate the BSTR
  773. //
  774. if ( dwSize != 0 )
  775. {
  776. *ppCapability = SysAllocString( (LPWSTR)(((LPBYTE)(m_pPhoneCaps)) + dwOffset) );
  777. if ( NULL == *ppCapability )
  778. {
  779. LOG((TL_ERROR, "get_PhoneCapsString - SysAllocString failed - E_OUTOFMEMORY"));
  780. Unlock();
  781. return E_OUTOFMEMORY;
  782. }
  783. }
  784. Unlock();
  785. LOG((TL_TRACE, "get_PhoneCapsString - exit - return S_OK"));
  786. return S_OK;
  787. }
  788. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  789. //
  790. // get_Terminals
  791. //
  792. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  793. STDMETHODIMP
  794. CPhone::get_Terminals(
  795. ITAddress * pAddress,
  796. VARIANT * pTerminals
  797. )
  798. {
  799. IEnumTerminal * pEnumTerminal;
  800. ITTerminal * pTerminal;
  801. ITStaticAudioTerminal * pStaticAudioTerminal;
  802. TerminalArray aTerminals;
  803. HRESULT hr;
  804. IDispatch * pDisp;
  805. ITTerminalSupport * pTerminalSupport;
  806. LONG lMediaType;
  807. TERMINAL_DIRECTION nDir;
  808. LOG((TL_TRACE, "get_Terminals - enter" ));
  809. if ( IsBadReadPtr( pAddress, sizeof (ITAddress) ) )
  810. {
  811. LOG((TL_ERROR, "get_Terminals - bad pointer"));
  812. return E_POINTER;
  813. }
  814. if ( TAPIIsBadWritePtr( pTerminals, sizeof (VARIANT) ) )
  815. {
  816. LOG((TL_ERROR, "get_Terminals - bad pointer"));
  817. return E_POINTER;
  818. }
  819. Lock();
  820. //
  821. // Get the ITTerminalSupport interface
  822. //
  823. hr = pAddress->QueryInterface(IID_ITTerminalSupport, (void **) &pTerminalSupport);
  824. if ( SUCCEEDED(hr) )
  825. {
  826. //
  827. // Get all the terminals on this address
  828. //
  829. hr = pTerminalSupport->EnumerateStaticTerminals( &pEnumTerminal );
  830. if ( SUCCEEDED(hr) )
  831. {
  832. while ( S_OK == pEnumTerminal->Next( 1, &pTerminal, NULL ) )
  833. {
  834. hr = pTerminal->get_MediaType(&lMediaType);
  835. if ( SUCCEEDED(hr) )
  836. {
  837. hr = pTerminal->get_Direction(&nDir);
  838. if ( SUCCEEDED(hr) )
  839. {
  840. //
  841. // we only care about audio terminals
  842. //
  843. if (lMediaType == TAPIMEDIATYPE_AUDIO)
  844. {
  845. //
  846. // we only care about terminals which implement ITStaticAudioTerminal
  847. // because we need to get the wave ID
  848. //
  849. hr = pTerminal->QueryInterface(IID_ITStaticAudioTerminal,
  850. (void **) &pStaticAudioTerminal);
  851. if ( SUCCEEDED(hr) )
  852. {
  853. LONG lWaveId;
  854. hr = pStaticAudioTerminal->get_WaveId(&lWaveId);
  855. if ( SUCCEEDED(hr) )
  856. {
  857. LOG((TL_INFO, "get_Terminals - got terminal wave id %d", lWaveId));
  858. if (IsPhoneUsingWaveID( lWaveId, nDir ))
  859. {
  860. if ( !aTerminals.Add( pTerminal ) )
  861. {
  862. LOG((TL_ERROR, "get_Terminals - could add terminal to array"));
  863. }
  864. }
  865. }
  866. pStaticAudioTerminal->Release();
  867. }
  868. }
  869. }
  870. else
  871. {
  872. LOG((TL_WARN, "get_Terminals - could not get terminal direction - %lx", hr));
  873. }
  874. }
  875. else
  876. {
  877. LOG((TL_WARN, "get_Terminals - could not get terminal media type - %lx", hr));
  878. }
  879. pTerminal->Release();
  880. }
  881. pEnumTerminal->Release();
  882. }
  883. pTerminalSupport->Release();
  884. }
  885. Unlock();
  886. //
  887. // create the collection
  888. //
  889. CComObject< CTapiCollection< ITTerminal > > * p;
  890. hr = CComObject< CTapiCollection< ITTerminal > >::CreateInstance( &p );
  891. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  892. {
  893. LOG((TL_ERROR, "get_Terminals - could not create collection" ));
  894. return E_OUTOFMEMORY;
  895. }
  896. //
  897. // get the IDispatch interface
  898. //
  899. hr = p->_InternalQueryInterface( IID_IDispatch, (void **) &pDisp );
  900. if ( FAILED(hr) )
  901. {
  902. LOG((TL_ERROR, "get_Terminals - could not get IDispatch interface" ));
  903. delete p;
  904. return hr;
  905. }
  906. //
  907. // initialize
  908. //
  909. hr = p->Initialize( aTerminals );
  910. aTerminals.Shutdown();
  911. if ( FAILED(hr) )
  912. {
  913. LOG((TL_ERROR, "get_Terminals - could not initialize collection" ));
  914. pDisp->Release();
  915. return hr;
  916. }
  917. //
  918. // put it in the variant
  919. //
  920. VariantInit(pTerminals);
  921. pTerminals->vt = VT_DISPATCH;
  922. pTerminals->pdispVal = pDisp;
  923. LOG((TL_TRACE, "get_Terminals - exit - return %lx", hr));
  924. return hr;
  925. }
  926. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  927. //
  928. // EnumerateTerminals
  929. //
  930. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  931. STDMETHODIMP
  932. CPhone::EnumerateTerminals(
  933. ITAddress * pAddress,
  934. IEnumTerminal ** ppEnumTerminal
  935. )
  936. {
  937. IEnumTerminal * pEnumTerminal;
  938. ITTerminal * pTerminal;
  939. ITStaticAudioTerminal * pStaticAudioTerminal;
  940. TerminalArray aTerminals;
  941. HRESULT hr;
  942. ITTerminalSupport * pTerminalSupport;
  943. LONG lMediaType;
  944. TERMINAL_DIRECTION nDir;
  945. LOG((TL_TRACE, "EnumerateTerminals - enter" ));
  946. if ( IsBadReadPtr( pAddress, sizeof (ITAddress) ) )
  947. {
  948. LOG((TL_ERROR, "get_Terminals - bad pointer"));
  949. return E_POINTER;
  950. }
  951. if ( TAPIIsBadWritePtr( ppEnumTerminal, sizeof (IEnumTerminal *) ) )
  952. {
  953. LOG((TL_ERROR, "EnumerateTerminals - bad pointer"));
  954. return E_POINTER;
  955. }
  956. Lock();
  957. //
  958. // Get the ITTerminalSupport interface
  959. //
  960. hr = pAddress->QueryInterface(IID_ITTerminalSupport, (void **) &pTerminalSupport);
  961. if ( SUCCEEDED(hr) )
  962. {
  963. //
  964. // Get all the terminals on this address
  965. //
  966. hr = pTerminalSupport->EnumerateStaticTerminals( &pEnumTerminal );
  967. if ( SUCCEEDED(hr) )
  968. {
  969. while ( S_OK == pEnumTerminal->Next( 1, &pTerminal, NULL ) )
  970. {
  971. hr = pTerminal->get_MediaType(&lMediaType);
  972. if ( SUCCEEDED(hr) )
  973. {
  974. hr = pTerminal->get_Direction(&nDir);
  975. if ( SUCCEEDED(hr) )
  976. {
  977. //
  978. // we only care about audio terminals
  979. //
  980. if (lMediaType == TAPIMEDIATYPE_AUDIO)
  981. {
  982. //
  983. // we only care about terminals which implement ITStaticAudioTerminal
  984. // because we need to get the wave ID
  985. //
  986. hr = pTerminal->QueryInterface(IID_ITStaticAudioTerminal,
  987. (void **) &pStaticAudioTerminal);
  988. if ( SUCCEEDED(hr) )
  989. {
  990. LONG lWaveId;
  991. hr = pStaticAudioTerminal->get_WaveId(&lWaveId);
  992. if ( SUCCEEDED(hr) )
  993. {
  994. LOG((TL_INFO, "get_Terminals - got terminal wave id %d", lWaveId));
  995. if (IsPhoneUsingWaveID( lWaveId, nDir ))
  996. {
  997. if ( !aTerminals.Add( pTerminal ) )
  998. {
  999. LOG((TL_ERROR, "get_Terminals - could add terminal to array"));
  1000. }
  1001. }
  1002. }
  1003. pStaticAudioTerminal->Release();
  1004. }
  1005. }
  1006. }
  1007. else
  1008. {
  1009. LOG((TL_WARN, "get_Terminals - could not get terminal direction - %lx", hr));
  1010. }
  1011. }
  1012. else
  1013. {
  1014. LOG((TL_WARN, "get_Terminals - could not get terminal media type - %lx", hr));
  1015. }
  1016. pTerminal->Release();
  1017. }
  1018. pEnumTerminal->Release();
  1019. }
  1020. pTerminalSupport->Release();
  1021. }
  1022. Unlock();
  1023. //
  1024. // create the enum
  1025. //
  1026. CComObject< CTapiEnum<IEnumTerminal, ITTerminal, &IID_IEnumTerminal> > * pEnum;
  1027. hr = CComObject< CTapiEnum<IEnumTerminal, ITTerminal, &IID_IEnumTerminal> >::CreateInstance( &pEnum );
  1028. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  1029. {
  1030. LOG((TL_ERROR, "EnumerateTerminals - could not create enum - return %lx", hr));
  1031. return hr;
  1032. }
  1033. //
  1034. // initialize
  1035. //
  1036. hr = pEnum->Initialize( aTerminals );
  1037. aTerminals.Shutdown();
  1038. if ( FAILED(hr) )
  1039. {
  1040. pEnum->Release();
  1041. LOG((TL_ERROR, "EnumerateTerminals - could not initialize enum - return %lx", hr));
  1042. return hr;
  1043. }
  1044. *ppEnumTerminal = pEnum;
  1045. LOG((TL_TRACE, "EnumerateTerminals - exit - return %lx", hr ));
  1046. return hr;
  1047. }
  1048. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1049. //
  1050. // get_ButtonMode
  1051. //
  1052. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1053. STDMETHODIMP
  1054. CPhone::get_ButtonMode(
  1055. long lButtonID,
  1056. PHONE_BUTTON_MODE * pButtonMode
  1057. )
  1058. {
  1059. HRESULT hr = S_OK;
  1060. DWORD dwNumButtons;
  1061. LPPHONEBUTTONINFO pButtonInfo;
  1062. LOG((TL_TRACE, "get_ButtonMode - enter" ));
  1063. if ( TAPIIsBadWritePtr( pButtonMode, sizeof(PHONE_BUTTON_MODE) ) )
  1064. {
  1065. LOG((TL_ERROR, "get_ButtonMode - bad pointer"));
  1066. return E_POINTER;
  1067. }
  1068. Lock();
  1069. if ( m_hPhone == NULL )
  1070. {
  1071. LOG((TL_ERROR, "get_ButtonMode - phone not open"));
  1072. Unlock();
  1073. return TAPI_E_PHONENOTOPEN;
  1074. }
  1075. //
  1076. // Get the ButtonInfo buffer
  1077. //
  1078. hr = PhoneGetButtonInfo(
  1079. m_hPhone,
  1080. lButtonID,
  1081. &pButtonInfo
  1082. );
  1083. Unlock();
  1084. if ( SUCCEEDED(hr) )
  1085. {
  1086. switch ( pButtonInfo->dwButtonMode )
  1087. {
  1088. case PHONEBUTTONMODE_CALL:
  1089. *pButtonMode = PBM_CALL;
  1090. break;
  1091. case PHONEBUTTONMODE_DISPLAY:
  1092. *pButtonMode = PBM_DISPLAY;
  1093. break;
  1094. case PHONEBUTTONMODE_DUMMY:
  1095. *pButtonMode = PBM_DUMMY;
  1096. break;
  1097. case PHONEBUTTONMODE_FEATURE:
  1098. *pButtonMode = PBM_FEATURE;
  1099. break;
  1100. case PHONEBUTTONMODE_KEYPAD:
  1101. *pButtonMode = PBM_KEYPAD;
  1102. break;
  1103. case PHONEBUTTONMODE_LOCAL:
  1104. *pButtonMode = PBM_LOCAL;
  1105. break;
  1106. default:
  1107. LOG((TL_ERROR, "get_ButtonMode - bad button mode"));
  1108. hr = E_FAIL;
  1109. }
  1110. //
  1111. // Free the ButtonInfo buffer
  1112. //
  1113. ClientFree( pButtonInfo );
  1114. }
  1115. LOG((TL_TRACE, "get_ButtonMode - exit - return %lx", hr));
  1116. return hr;
  1117. }
  1118. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1119. //
  1120. // put_ButtonMode
  1121. //
  1122. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1123. STDMETHODIMP
  1124. CPhone::put_ButtonMode(
  1125. long lButtonID,
  1126. PHONE_BUTTON_MODE ButtonMode
  1127. )
  1128. {
  1129. HRESULT hr;
  1130. LOG((TL_TRACE, "put_ButtonMode - enter" ));
  1131. Lock();
  1132. //
  1133. // Make sure the phone is open with owner privilege.
  1134. //
  1135. if ( m_hPhone == NULL )
  1136. {
  1137. LOG((TL_ERROR, "put_ButtonMode - phone is not open - "
  1138. "exit TAPI_E_PHONENOTOPEN"));
  1139. Unlock();
  1140. return TAPI_E_PHONENOTOPEN;
  1141. }
  1142. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  1143. {
  1144. LOG((TL_ERROR, "put_ButtonMode - wrong phone privilege - "
  1145. "exit TAPI_E_NOTOWNER"));
  1146. Unlock();
  1147. return TAPI_E_NOTOWNER;
  1148. }
  1149. //
  1150. // get info for this button
  1151. //
  1152. PHONEBUTTONINFO *pButtonInfo = NULL;
  1153. hr = PhoneGetButtonInfo(m_hPhone, lButtonID, &pButtonInfo);
  1154. if ( FAILED(hr) )
  1155. {
  1156. LOG((TL_ERROR, "put_ButtonMode - failed to get button info"));
  1157. Unlock();
  1158. return hr;
  1159. }
  1160. //
  1161. // make sure the memory we got back is writeable
  1162. //
  1163. if (TAPIIsBadWritePtr(pButtonInfo, sizeof(PHONEBUTTONINFO)))
  1164. {
  1165. LOG((TL_ERROR, "put_ButtonMode - PhoneGetButtonInfo returned a bad memory block"));
  1166. Unlock();
  1167. return E_UNEXPECTED;
  1168. }
  1169. //
  1170. // set the appropriate button mode in the structure that we have. leave everything else unchanged
  1171. //
  1172. switch (ButtonMode)
  1173. {
  1174. case PBM_DUMMY:
  1175. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_DUMMY;
  1176. break;
  1177. case PBM_CALL:
  1178. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_CALL;
  1179. break;
  1180. case PBM_FEATURE:
  1181. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_FEATURE;
  1182. break;
  1183. case PBM_KEYPAD:
  1184. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_KEYPAD;
  1185. break;
  1186. case PBM_LOCAL:
  1187. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_LOCAL;
  1188. break;
  1189. case PBM_DISPLAY:
  1190. pButtonInfo->dwButtonMode = PHONEBUTTONMODE_DISPLAY;
  1191. break;
  1192. default:
  1193. LOG((TL_ERROR, "put_ButtonMode - bad ButtonMode"));
  1194. Unlock();
  1195. ClientFree(pButtonInfo);
  1196. pButtonInfo = NULL;
  1197. return E_INVALIDARG;
  1198. }
  1199. //
  1200. // set the new button mode
  1201. //
  1202. hr = PhoneSetButtonInfo(m_hPhone, lButtonID, pButtonInfo);
  1203. Unlock();
  1204. //
  1205. // free memory returned to us by PhoneGetButtonInfo
  1206. //
  1207. ClientFree(pButtonInfo);
  1208. pButtonInfo = NULL;
  1209. LOG((TL_TRACE, "put_ButtonMode - put_ButtonMode - return %lx", hr ));
  1210. return hr;
  1211. }
  1212. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1213. //
  1214. // put_ButtonText
  1215. //
  1216. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1217. STDMETHODIMP
  1218. CPhone::put_ButtonText(
  1219. long lButtonID,
  1220. BSTR bstrButtonText
  1221. )
  1222. {
  1223. HRESULT hr;
  1224. LOG((TL_TRACE, "put_ButtonText - enter" ));
  1225. if ( IsBadStringPtrW(bstrButtonText, -1) )
  1226. {
  1227. LOG((TL_ERROR, "put_ButtonText - invalid parameter",
  1228. "exit E_POINTER"));
  1229. return E_POINTER;
  1230. }
  1231. Lock();
  1232. //
  1233. // Make sure the phone is open with owner privilege.
  1234. //
  1235. if ( m_hPhone == NULL )
  1236. {
  1237. LOG((TL_ERROR, "put_ButtonText - phone is not open - "
  1238. "exit TAPI_E_PHONENOTOPEN"));
  1239. Unlock();
  1240. return TAPI_E_PHONENOTOPEN;
  1241. }
  1242. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  1243. {
  1244. LOG((TL_ERROR, "put_ButtonText - wrong phone privilege - "
  1245. "exit TAPI_E_NOTOWNER"));
  1246. Unlock();
  1247. return TAPI_E_NOTOWNER;
  1248. }
  1249. //
  1250. // get info for this button
  1251. //
  1252. PHONEBUTTONINFO *pButtonInfo = NULL;
  1253. hr = PhoneGetButtonInfo(m_hPhone, lButtonID, &pButtonInfo);
  1254. if ( FAILED(hr) )
  1255. {
  1256. LOG((TL_ERROR, "put_ButtonText - failed to get button info"));
  1257. Unlock();
  1258. return hr;
  1259. }
  1260. //
  1261. // make sure the memory we got back is writeable
  1262. //
  1263. if ( TAPIIsBadWritePtr(pButtonInfo, sizeof(PHONEBUTTONINFO)) )
  1264. {
  1265. LOG((TL_ERROR, "put_ButtonText - PhoneGetButtonInfo returned a bad memory block"));
  1266. Unlock();
  1267. return E_UNEXPECTED;
  1268. }
  1269. DWORD dwButtonTextLength = SysStringByteLen(bstrButtonText);
  1270. //
  1271. // add the string to the structure we have. if the new string fits in
  1272. // place of the old string, put it in there. otherwise, allocate a bigger
  1273. // structure and append the new string at the end
  1274. //
  1275. if ( dwButtonTextLength <= pButtonInfo->dwButtonTextSize )
  1276. {
  1277. CopyMemory((BYTE*)pButtonInfo + pButtonInfo->dwButtonTextOffset,
  1278. bstrButtonText,
  1279. dwButtonTextLength);
  1280. pButtonInfo->dwButtonTextSize = dwButtonTextLength;
  1281. }
  1282. else
  1283. {
  1284. //
  1285. // create the new structure that will have everything the old one does + the new string
  1286. //
  1287. DWORD dwBiggerStructureSize = pButtonInfo->dwTotalSize + dwButtonTextLength;
  1288. //
  1289. // allocate the new, bigger structure
  1290. //
  1291. PHONEBUTTONINFO *pBiggerButtonInfo = (PHONEBUTTONINFO *)ClientAlloc(dwBiggerStructureSize);
  1292. if ( NULL == pBiggerButtonInfo )
  1293. {
  1294. LOG((TL_ERROR, "put_ButtonText - failed to allocate memory for the new structure"));
  1295. ClientFree(pButtonInfo);
  1296. Unlock();
  1297. return E_OUTOFMEMORY;
  1298. }
  1299. //
  1300. // copy the old data into the bigger structure
  1301. //
  1302. CopyMemory(pBiggerButtonInfo, pButtonInfo, pButtonInfo->dwTotalSize);
  1303. //
  1304. // append the new structure with the new string (the new text starts after the old data)
  1305. //
  1306. //
  1307. // set the offset and size for the text in the new structure
  1308. //
  1309. pBiggerButtonInfo->dwButtonTextOffset = pButtonInfo->dwTotalSize;
  1310. pBiggerButtonInfo->dwButtonTextSize = dwButtonTextLength;
  1311. //
  1312. // copy the text to the end of the new structure
  1313. //
  1314. CopyMemory((BYTE*)pBiggerButtonInfo + pBiggerButtonInfo->dwButtonTextOffset,
  1315. bstrButtonText,
  1316. dwButtonTextLength);
  1317. //
  1318. // set the size of the new structure
  1319. //
  1320. pBiggerButtonInfo->dwTotalSize = dwBiggerStructureSize;
  1321. //
  1322. // free memory allocated by the old structure
  1323. //
  1324. ClientFree(pButtonInfo);
  1325. //
  1326. // pButtonInfo will now point to the new structure
  1327. //
  1328. pButtonInfo = pBiggerButtonInfo;
  1329. pBiggerButtonInfo = NULL;
  1330. }
  1331. //
  1332. // set the new button text
  1333. //
  1334. hr = PhoneSetButtonInfo(m_hPhone, lButtonID, pButtonInfo);
  1335. Unlock();
  1336. //
  1337. // free memory returned to us by PhoneGetButtonInfo
  1338. //
  1339. ClientFree(pButtonInfo);
  1340. pButtonInfo = NULL;
  1341. LOG((TL_TRACE, "put_ButtonText - exit - return %lx", hr ));
  1342. return hr;
  1343. }
  1344. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1345. //
  1346. // get_PhoneCapsBuffer
  1347. //
  1348. // returns the requested buffer from phone capapabilities array --
  1349. // the scriptable version
  1350. //
  1351. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1352. STDMETHODIMP
  1353. CPhone::get_PhoneCapsBuffer(
  1354. IN PHONECAPS_BUFFER pcbCaps,
  1355. OUT VARIANT *pVarBuffer
  1356. )
  1357. {
  1358. LOG((TL_TRACE, "get_PhoneCapsBuffer[%p] - enter", this ));
  1359. //
  1360. // check arguments
  1361. //
  1362. if ( TAPIIsBadWritePtr( pVarBuffer, sizeof(VARIANT) ) )
  1363. {
  1364. LOG((TL_ERROR, "get_PhoneCapsBuffer - bad pointer"));
  1365. return E_POINTER;
  1366. }
  1367. //
  1368. // get the buffer
  1369. //
  1370. DWORD dwBufferSize = 0;
  1371. BYTE *pBuffer = NULL;
  1372. HRESULT hr = GetPhoneCapsBuffer(pcbCaps, &dwBufferSize, &pBuffer);
  1373. if (FAILED(hr))
  1374. {
  1375. LOG((TL_ERROR, "get_PhoneCapsBuffer - failed to get phone caps buffer"));
  1376. return hr;
  1377. }
  1378. VariantInit(pVarBuffer);
  1379. //
  1380. // fill the variant with the data buffer
  1381. //
  1382. hr = FillVariantFromBuffer(dwBufferSize, pBuffer, pVarBuffer);
  1383. //
  1384. // no longer need the buffer -- we hope that now have all the data in the variant
  1385. //
  1386. CoTaskMemFree(pBuffer);
  1387. if (FAILED(hr))
  1388. {
  1389. LOG((TL_ERROR, "get_PhoneCapsBuffer - failed to copy phone caps buffer to a variant"));
  1390. return hr;
  1391. }
  1392. LOG((TL_TRACE, "get_PhoneCapsBuffer - exit - return S_OK"));
  1393. return S_OK;
  1394. }
  1395. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1396. //
  1397. // GetPhoneCapsBuffer
  1398. //
  1399. // returns the requested buffer from phone capapabilities array
  1400. //
  1401. // on success, the caller must call CoTaskMemFree to free the buffer that is
  1402. // returned by this method
  1403. //
  1404. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1405. STDMETHODIMP
  1406. CPhone::GetPhoneCapsBuffer(
  1407. IN PHONECAPS_BUFFER pcbCaps,
  1408. OUT DWORD *pdwSize,
  1409. OUT BYTE **ppPhoneCapsBuffer
  1410. )
  1411. {
  1412. LOG((TL_TRACE, "GetPhoneCapsBuffer - enter" ));
  1413. //
  1414. // check arguments
  1415. //
  1416. if ( TAPIIsBadWritePtr( ppPhoneCapsBuffer, sizeof(BYTE*) ) )
  1417. {
  1418. LOG((TL_ERROR, "GetPhoneCapsBuffer - bad pointer"));
  1419. return E_POINTER;
  1420. }
  1421. *ppPhoneCapsBuffer = NULL;
  1422. if ( TAPIIsBadWritePtr( pdwSize, sizeof(DWORD) ) )
  1423. {
  1424. LOG((TL_ERROR, "GetPhoneCapsBuffer - bad pointer"));
  1425. return E_POINTER;
  1426. }
  1427. *pdwSize = 0;
  1428. Lock();
  1429. //
  1430. // update phone capabilities cache
  1431. //
  1432. HRESULT hr = UpdatePhoneCaps();
  1433. if ( FAILED(hr) )
  1434. {
  1435. LOG((TL_ERROR, "GetPhoneCapsBuffer - could not get phonecaps"));
  1436. Unlock();
  1437. return hr;
  1438. }
  1439. switch (pcbCaps)
  1440. {
  1441. case PCB_DEVSPECIFICBUFFER:
  1442. {
  1443. //
  1444. // allocate the buffer for device-specific caps
  1445. //
  1446. *pdwSize = m_pPhoneCaps->dwDevSpecificSize;
  1447. *ppPhoneCapsBuffer = static_cast<BYTE*>(CoTaskMemAlloc(*pdwSize));
  1448. if (NULL == *ppPhoneCapsBuffer)
  1449. {
  1450. LOG((TL_ERROR, "GetPhoneCapsBuffer - could not allocate memory for the output buffer"));
  1451. Unlock();
  1452. return E_OUTOFMEMORY;
  1453. }
  1454. //
  1455. // copy data to the buffer to be returned to the caller
  1456. //
  1457. CopyMemory( *ppPhoneCapsBuffer,
  1458. (BYTE*)m_pPhoneCaps + m_pPhoneCaps->dwDevSpecificOffset,
  1459. *pdwSize);
  1460. break;
  1461. }
  1462. default:
  1463. Unlock();
  1464. LOG((TL_ERROR, "GetPhoneCapsBuffer - unknown capability type %x", pcbCaps));
  1465. return E_INVALIDARG;
  1466. break;
  1467. }
  1468. Unlock();
  1469. LOG((TL_TRACE, "GetPhoneCapsBuffer - exit - return S_OK"));
  1470. return S_OK;
  1471. }
  1472. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1473. //
  1474. // get_Display
  1475. //
  1476. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1477. STDMETHODIMP
  1478. CPhone::get_Display(
  1479. BSTR *pbstrDisplay
  1480. )
  1481. {
  1482. HRESULT hr;
  1483. LONG lResult;
  1484. LPVARSTRING pVarString = NULL;
  1485. LOG((TL_TRACE, "get_Display - enter" ));
  1486. //
  1487. // check arguments
  1488. //
  1489. if ( TAPIIsBadWritePtr( pbstrDisplay, sizeof(BSTR) ) )
  1490. {
  1491. LOG((TL_ERROR, "get_Display - bad pointer"));
  1492. return E_POINTER;
  1493. }
  1494. Lock();
  1495. if ( m_hPhone == NULL )
  1496. {
  1497. LOG((TL_ERROR, "get_Display - phone not open"));
  1498. Unlock();
  1499. return TAPI_E_PHONENOTOPEN;
  1500. }
  1501. hr = PhoneGetDisplay(m_hPhone, &pVarString);
  1502. Unlock();
  1503. if (FAILED(hr))
  1504. {
  1505. LOG((TL_ERROR, "get_Display - failed to get display. hr = %lx", hr));
  1506. if (NULL != pVarString)
  1507. {
  1508. ClientFree(pVarString);
  1509. }
  1510. return hr;
  1511. }
  1512. //
  1513. // succeeded. extract display information and place it in the the output bstr
  1514. //
  1515. hr = S_OK;
  1516. switch (pVarString->dwStringFormat)
  1517. {
  1518. case STRINGFORMAT_ASCII:
  1519. {
  1520. int nWCHARSNeeded = MultiByteToWideChar(CP_ACP,
  1521. 0,
  1522. (char*)((BYTE*)pVarString + pVarString->dwStringOffset),
  1523. pVarString->dwStringSize,
  1524. NULL,
  1525. 0);
  1526. if (0 == nWCHARSNeeded)
  1527. {
  1528. LOG((TL_ERROR, "get_Display - failed to get the size of the buffer needed for the display. LastError = %lx", GetLastError()));
  1529. hr = E_FAIL;
  1530. break;
  1531. }
  1532. //
  1533. // allocate the buffer required for conversion
  1534. //
  1535. LPWSTR lpWideCharStr = (LPWSTR)ClientAlloc(sizeof(WCHAR) * nWCHARSNeeded);
  1536. if (NULL == lpWideCharStr)
  1537. {
  1538. LOG((TL_ERROR, "get_Display - failed to allocate memory for lpWideCharStr" ));
  1539. hr = E_OUTOFMEMORY;
  1540. break;
  1541. }
  1542. //
  1543. // perform conversion
  1544. //
  1545. int nResult = MultiByteToWideChar(CP_ACP,
  1546. 0,
  1547. (char*)((BYTE*)pVarString + pVarString->dwStringOffset),
  1548. pVarString->dwStringSize,
  1549. lpWideCharStr,
  1550. nWCHARSNeeded);
  1551. if (0 == nResult)
  1552. {
  1553. LOG((TL_ERROR, "get_Display - failed to convert string to wchar. last error %lx", GetLastError()));
  1554. ClientFree(lpWideCharStr);
  1555. hr = E_FAIL;
  1556. break;
  1557. }
  1558. //
  1559. // allocate bstr and initialize it with the converted string
  1560. //
  1561. *pbstrDisplay = SysAllocString(lpWideCharStr);
  1562. //
  1563. // no longer need the wchar string -- we hope the data is in bstr
  1564. //
  1565. ClientFree(lpWideCharStr);
  1566. if (NULL == *pbstrDisplay)
  1567. {
  1568. LOG((TL_ERROR, "get_Display - failed to allocate memory for bstr"));
  1569. hr = E_OUTOFMEMORY;
  1570. break;
  1571. }
  1572. }
  1573. break;
  1574. case STRINGFORMAT_BINARY:
  1575. //
  1576. // allocate bstr and copy data as is
  1577. //
  1578. *pbstrDisplay = SysAllocStringByteLen(NULL, pVarString->dwStringSize);
  1579. if (NULL == *pbstrDisplay)
  1580. {
  1581. LOG((TL_ERROR, "get_Display - failed to allocate memory for bstr"));
  1582. hr = E_OUTOFMEMORY;
  1583. break;
  1584. }
  1585. CopyMemory(*pbstrDisplay, ((BYTE*)pVarString + pVarString->dwStringOffset), pVarString->dwStringSize);
  1586. break;
  1587. case STRINGFORMAT_DBCS:
  1588. LOG((TL_ERROR, "get_Display - unsupported string format"));
  1589. hr = E_FAIL;
  1590. break;
  1591. case STRINGFORMAT_UNICODE:
  1592. {
  1593. WCHAR *pwcDisplay = (WCHAR*)((BYTE*)pVarString + pVarString->dwStringOffset);
  1594. *pbstrDisplay = SysAllocString(pwcDisplay);
  1595. if (NULL == *pbstrDisplay)
  1596. {
  1597. LOG((TL_ERROR, "get_Display - failed to allocate memory for bstr"));
  1598. hr = E_OUTOFMEMORY;
  1599. break;
  1600. }
  1601. }
  1602. break;
  1603. default:
  1604. ClientFree(pVarString);
  1605. pVarString = NULL;
  1606. LOG((TL_ERROR, "get_Display - tapisrv returned unrecognized string type %lx", pVarString->dwStringFormat));
  1607. hr = E_FAIL;
  1608. break;
  1609. }
  1610. ClientFree(pVarString);
  1611. pVarString = NULL;
  1612. LOG((TL_TRACE, "get_Display - exit - return %lx", hr));
  1613. return hr;
  1614. }
  1615. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1616. //
  1617. // SetDisplay
  1618. //
  1619. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1620. STDMETHODIMP
  1621. CPhone::SetDisplay(
  1622. long lRow,
  1623. long lColumn,
  1624. BSTR bstrDisplay
  1625. )
  1626. {
  1627. HRESULT hr;
  1628. LOG((TL_TRACE, "SetDisplay - enter" ));
  1629. if (bstrDisplay == NULL)
  1630. {
  1631. LOG((TL_ERROR, "SetDisplay - invalid parameter",
  1632. "exit E_POINTER"));
  1633. return E_POINTER;
  1634. }
  1635. Lock();
  1636. if ( m_hPhone == NULL )
  1637. {
  1638. LOG((TL_ERROR, "SetDisplay - phone not open"));
  1639. Unlock();
  1640. return TAPI_E_PHONENOTOPEN;
  1641. }
  1642. //
  1643. // pass the text to tapisrv
  1644. //
  1645. hr = PhoneSetDisplay(
  1646. m_hPhone,
  1647. lRow,
  1648. lColumn,
  1649. (char*)bstrDisplay,
  1650. SysStringByteLen(bstrDisplay));
  1651. Unlock();
  1652. LOG((TL_TRACE, "SetDisplay - exit - return %lx", hr));
  1653. return hr;
  1654. }
  1655. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1656. //
  1657. // get_ButtonFunction
  1658. //
  1659. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1660. STDMETHODIMP
  1661. CPhone::get_ButtonFunction(
  1662. long lButtonID,
  1663. PHONE_BUTTON_FUNCTION * pButtonFunction
  1664. )
  1665. {
  1666. HRESULT hr = S_OK;
  1667. DWORD dwNumButtons;
  1668. LPPHONEBUTTONINFO pButtonInfo;
  1669. LOG((TL_TRACE, "get_ButtonFunction - enter" ));
  1670. if ( TAPIIsBadWritePtr( pButtonFunction, sizeof(PHONE_BUTTON_FUNCTION) ) )
  1671. {
  1672. LOG((TL_ERROR, "get_ButtonFunction - bad pointer"));
  1673. return E_POINTER;
  1674. }
  1675. Lock();
  1676. if ( m_hPhone == NULL )
  1677. {
  1678. LOG((TL_ERROR, "get_ButtonFunction - phone not open"));
  1679. Unlock();
  1680. return TAPI_E_PHONENOTOPEN;
  1681. }
  1682. //
  1683. // get the ButtonInfo buffer
  1684. //
  1685. hr = PhoneGetButtonInfo(
  1686. m_hPhone,
  1687. lButtonID,
  1688. &pButtonInfo
  1689. );
  1690. if ( SUCCEEDED(hr) )
  1691. {
  1692. switch ( pButtonInfo->dwButtonFunction )
  1693. {
  1694. case PHONEBUTTONFUNCTION_ABBREVDIAL:
  1695. *pButtonFunction = PBF_ABBREVDIAL;
  1696. break;
  1697. case PHONEBUTTONFUNCTION_BUSY:
  1698. *pButtonFunction = PBF_BUSY;
  1699. break;
  1700. case PHONEBUTTONFUNCTION_BRIDGEDAPP:
  1701. *pButtonFunction = PBF_BRIDGEDAPP;
  1702. break;
  1703. case PHONEBUTTONFUNCTION_CALLAPP:
  1704. *pButtonFunction = PBF_CALLAPP;
  1705. break;
  1706. case PHONEBUTTONFUNCTION_CALLID:
  1707. *pButtonFunction = PBF_CALLID;
  1708. break;
  1709. case PHONEBUTTONFUNCTION_CAMPON:
  1710. *pButtonFunction = PBF_CAMPON;
  1711. break;
  1712. case PHONEBUTTONFUNCTION_COVER:
  1713. *pButtonFunction = PBF_COVER;
  1714. break;
  1715. case PHONEBUTTONFUNCTION_CONFERENCE:
  1716. *pButtonFunction = PBF_CONFERENCE;
  1717. break;
  1718. case PHONEBUTTONFUNCTION_CONNECT:
  1719. *pButtonFunction = PBF_CONNECT;
  1720. break;
  1721. case PHONEBUTTONFUNCTION_DATAOFF:
  1722. *pButtonFunction = PBF_DATAOFF;
  1723. break;
  1724. case PHONEBUTTONFUNCTION_DATAON:
  1725. *pButtonFunction = PBF_DATAON;
  1726. break;
  1727. case PHONEBUTTONFUNCTION_DATETIME:
  1728. *pButtonFunction = PBF_DATETIME;
  1729. break;
  1730. case PHONEBUTTONFUNCTION_DIRECTORY:
  1731. *pButtonFunction = PBF_DIRECTORY;
  1732. break;
  1733. case PHONEBUTTONFUNCTION_DISCONNECT:
  1734. *pButtonFunction = PBF_DISCONNECT;
  1735. break;
  1736. case PHONEBUTTONFUNCTION_DONOTDISTURB:
  1737. *pButtonFunction = PBF_DONOTDISTURB;
  1738. break;
  1739. case PHONEBUTTONFUNCTION_DROP:
  1740. *pButtonFunction = PBF_DROP;
  1741. break;
  1742. case PHONEBUTTONFUNCTION_FLASH:
  1743. *pButtonFunction = PBF_FLASH;
  1744. break;
  1745. case PHONEBUTTONFUNCTION_FORWARD:
  1746. *pButtonFunction = PBF_FORWARD;
  1747. break;
  1748. case PHONEBUTTONFUNCTION_HOLD:
  1749. *pButtonFunction = PBF_HOLD;
  1750. break;
  1751. case PHONEBUTTONFUNCTION_INTERCOM:
  1752. *pButtonFunction = PBF_INTERCOM;
  1753. break;
  1754. case PHONEBUTTONFUNCTION_LASTNUM:
  1755. *pButtonFunction = PBF_LASTNUM;
  1756. break;
  1757. case PHONEBUTTONFUNCTION_MSGINDICATOR:
  1758. *pButtonFunction = PBF_MSGINDICATOR;
  1759. break;
  1760. case PHONEBUTTONFUNCTION_MSGWAITOFF:
  1761. *pButtonFunction = PBF_MSGWAITOFF;
  1762. break;
  1763. case PHONEBUTTONFUNCTION_MSGWAITON:
  1764. *pButtonFunction = PBF_MSGWAITON;
  1765. break;
  1766. case PHONEBUTTONFUNCTION_MUTE:
  1767. *pButtonFunction = PBF_MUTE;
  1768. break;
  1769. case PHONEBUTTONFUNCTION_NIGHTSRV:
  1770. *pButtonFunction = PBF_NIGHTSRV;
  1771. break;
  1772. case PHONEBUTTONFUNCTION_NONE:
  1773. *pButtonFunction = PBF_NONE;
  1774. break;
  1775. case PHONEBUTTONFUNCTION_PARK:
  1776. *pButtonFunction = PBF_PARK;
  1777. break;
  1778. case PHONEBUTTONFUNCTION_PICKUP:
  1779. *pButtonFunction = PBF_PICKUP;
  1780. break;
  1781. case PHONEBUTTONFUNCTION_QUEUECALL:
  1782. *pButtonFunction = PBF_QUEUECALL;
  1783. break;
  1784. case PHONEBUTTONFUNCTION_RECALL:
  1785. *pButtonFunction = PBF_RECALL;
  1786. break;
  1787. case PHONEBUTTONFUNCTION_REDIRECT:
  1788. *pButtonFunction = PBF_REDIRECT;
  1789. break;
  1790. case PHONEBUTTONFUNCTION_REJECT:
  1791. *pButtonFunction = PBF_REJECT;
  1792. break;
  1793. case PHONEBUTTONFUNCTION_REPDIAL:
  1794. *pButtonFunction = PBF_REPDIAL;
  1795. break;
  1796. case PHONEBUTTONFUNCTION_RINGAGAIN:
  1797. *pButtonFunction = PBF_RINGAGAIN;
  1798. break;
  1799. case PHONEBUTTONFUNCTION_SAVEREPEAT:
  1800. *pButtonFunction = PBF_SAVEREPEAT;
  1801. break;
  1802. case PHONEBUTTONFUNCTION_SELECTRING:
  1803. *pButtonFunction = PBF_SELECTRING;
  1804. break;
  1805. case PHONEBUTTONFUNCTION_SETREPDIAL:
  1806. *pButtonFunction = PBF_SETREPDIAL;
  1807. break;
  1808. case PHONEBUTTONFUNCTION_SENDCALLS:
  1809. *pButtonFunction = PBF_SENDCALLS;
  1810. break;
  1811. case PHONEBUTTONFUNCTION_SPEAKEROFF:
  1812. *pButtonFunction = PBF_SPEAKEROFF;
  1813. break;
  1814. case PHONEBUTTONFUNCTION_SPEAKERON:
  1815. *pButtonFunction = PBF_SPEAKERON;
  1816. break;
  1817. case PHONEBUTTONFUNCTION_STATIONSPEED:
  1818. *pButtonFunction = PBF_STATIONSPEED;
  1819. break;
  1820. case PHONEBUTTONFUNCTION_SYSTEMSPEED:
  1821. *pButtonFunction = PBF_SYSTEMSPEED;
  1822. break;
  1823. case PHONEBUTTONFUNCTION_TRANSFER:
  1824. *pButtonFunction = PBF_TRANSFER;
  1825. break;
  1826. case PHONEBUTTONFUNCTION_UNKNOWN:
  1827. *pButtonFunction = PBF_UNKNOWN;
  1828. break;
  1829. case PHONEBUTTONFUNCTION_VOLUMEDOWN:
  1830. *pButtonFunction = PBF_VOLUMEDOWN;
  1831. break;
  1832. case PHONEBUTTONFUNCTION_VOLUMEUP:
  1833. *pButtonFunction = PBF_VOLUMEUP;
  1834. break;
  1835. case PHONEBUTTONFUNCTION_SEND:
  1836. *pButtonFunction = PBF_SEND;
  1837. break;
  1838. default:
  1839. LOG((TL_ERROR, "get_ButtonFunction - bad button function"));
  1840. hr = E_FAIL;
  1841. }
  1842. //
  1843. // Free the ButtonInfo buffer
  1844. //
  1845. ClientFree( pButtonInfo );
  1846. }
  1847. Unlock();
  1848. LOG((TL_TRACE, "get_ButtonFunction - exit - return %lx", hr));
  1849. return hr;
  1850. }
  1851. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1852. //
  1853. // put_ButtonFunction
  1854. //
  1855. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1856. STDMETHODIMP
  1857. CPhone::put_ButtonFunction(
  1858. IN long lButtonID,
  1859. IN PHONE_BUTTON_FUNCTION ButtonFunction
  1860. )
  1861. {
  1862. HRESULT hr;
  1863. LOG((TL_TRACE, "put_ButtonFunction - enter" ));
  1864. Lock();
  1865. //
  1866. // Make sure the phone is open with owner privilege.
  1867. //
  1868. if ( m_hPhone == NULL )
  1869. {
  1870. LOG((TL_ERROR, "put_ButtonFunction - phone is not open - "
  1871. "exit TAPI_E_PHONENOTOPEN"));
  1872. Unlock();
  1873. return TAPI_E_PHONENOTOPEN;
  1874. }
  1875. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  1876. {
  1877. LOG((TL_ERROR, "put_ButtonFunction - wrong phone privilege - "
  1878. "exit TAPI_E_NOTOWNER"));
  1879. Unlock();
  1880. return TAPI_E_NOTOWNER;
  1881. }
  1882. //
  1883. // get info for this button
  1884. //
  1885. PHONEBUTTONINFO *pButtonInfo = NULL;
  1886. hr = PhoneGetButtonInfo(m_hPhone, lButtonID, &pButtonInfo);
  1887. if ( FAILED(hr) )
  1888. {
  1889. LOG((TL_ERROR, "put_ButtonFunction - failed to get button info - %lx", hr));
  1890. Unlock();
  1891. return hr;
  1892. }
  1893. //
  1894. // make sure the memory we got back is writeable
  1895. //
  1896. if (TAPIIsBadWritePtr(pButtonInfo, sizeof(PHONEBUTTONINFO)))
  1897. {
  1898. LOG((TL_ERROR, "put_ButtonFunction - PhoneGetButtonInfo returned a bad memory block"));
  1899. Unlock();
  1900. return E_UNEXPECTED;
  1901. }
  1902. //
  1903. // translate PHONE_BUTTON_FUNCTION to a DWORD value understood by tapisrv
  1904. //
  1905. DWORD dwButtonFunction = 0;
  1906. switch ( ButtonFunction )
  1907. {
  1908. case PBF_ABBREVDIAL:
  1909. dwButtonFunction = PHONEBUTTONFUNCTION_ABBREVDIAL;
  1910. break;
  1911. case PBF_BUSY:
  1912. dwButtonFunction = PHONEBUTTONFUNCTION_BUSY;
  1913. break;
  1914. case PBF_BRIDGEDAPP:
  1915. dwButtonFunction = PHONEBUTTONFUNCTION_BRIDGEDAPP;
  1916. break;
  1917. case PBF_CALLAPP:
  1918. dwButtonFunction = PHONEBUTTONFUNCTION_CALLAPP;
  1919. break;
  1920. case PBF_CALLID:
  1921. dwButtonFunction = PHONEBUTTONFUNCTION_CALLID;
  1922. break;
  1923. case PBF_CAMPON:
  1924. dwButtonFunction = PHONEBUTTONFUNCTION_CAMPON;
  1925. break;
  1926. case PBF_COVER:
  1927. dwButtonFunction = PHONEBUTTONFUNCTION_COVER;
  1928. break;
  1929. case PBF_CONFERENCE:
  1930. dwButtonFunction = PHONEBUTTONFUNCTION_CONFERENCE;
  1931. break;
  1932. case PBF_CONNECT:
  1933. dwButtonFunction = PHONEBUTTONFUNCTION_CONNECT;
  1934. break;
  1935. case PBF_DATAOFF:
  1936. dwButtonFunction = PHONEBUTTONFUNCTION_DATAOFF;
  1937. break;
  1938. case PBF_DATAON:
  1939. dwButtonFunction = PHONEBUTTONFUNCTION_DATAON;
  1940. break;
  1941. case PBF_DATETIME:
  1942. dwButtonFunction = PHONEBUTTONFUNCTION_DATETIME;
  1943. break;
  1944. case PBF_DIRECTORY:
  1945. dwButtonFunction = PHONEBUTTONFUNCTION_DIRECTORY;
  1946. break;
  1947. case PBF_DISCONNECT:
  1948. dwButtonFunction = PHONEBUTTONFUNCTION_DISCONNECT;
  1949. break;
  1950. case PBF_DONOTDISTURB:
  1951. dwButtonFunction = PHONEBUTTONFUNCTION_DONOTDISTURB;
  1952. break;
  1953. case PBF_DROP:
  1954. dwButtonFunction = PHONEBUTTONFUNCTION_DROP;
  1955. break;
  1956. case PBF_FLASH:
  1957. dwButtonFunction = PHONEBUTTONFUNCTION_FLASH;
  1958. break;
  1959. case PBF_FORWARD:
  1960. dwButtonFunction = PHONEBUTTONFUNCTION_FORWARD;
  1961. break;
  1962. case PBF_HOLD:
  1963. dwButtonFunction = PHONEBUTTONFUNCTION_HOLD;
  1964. break;
  1965. case PBF_INTERCOM:
  1966. dwButtonFunction = PHONEBUTTONFUNCTION_INTERCOM;
  1967. break;
  1968. case PBF_LASTNUM:
  1969. dwButtonFunction = PHONEBUTTONFUNCTION_LASTNUM;
  1970. break;
  1971. case PBF_MSGINDICATOR:
  1972. dwButtonFunction = PHONEBUTTONFUNCTION_MSGINDICATOR;
  1973. break;
  1974. case PBF_MSGWAITOFF:
  1975. dwButtonFunction = PHONEBUTTONFUNCTION_MSGWAITOFF;
  1976. break;
  1977. case PBF_MSGWAITON:
  1978. dwButtonFunction = PHONEBUTTONFUNCTION_MSGWAITON;
  1979. break;
  1980. case PBF_MUTE:
  1981. dwButtonFunction = PHONEBUTTONFUNCTION_MUTE;
  1982. break;
  1983. case PBF_NIGHTSRV:
  1984. dwButtonFunction = PHONEBUTTONFUNCTION_NIGHTSRV;
  1985. break;
  1986. case PBF_NONE:
  1987. dwButtonFunction = PHONEBUTTONFUNCTION_NONE;
  1988. break;
  1989. case PBF_PARK:
  1990. dwButtonFunction = PHONEBUTTONFUNCTION_PARK;
  1991. break;
  1992. case PBF_PICKUP:
  1993. dwButtonFunction = PHONEBUTTONFUNCTION_PICKUP;
  1994. break;
  1995. case PBF_QUEUECALL:
  1996. dwButtonFunction = PHONEBUTTONFUNCTION_QUEUECALL;
  1997. break;
  1998. case PBF_RECALL:
  1999. dwButtonFunction = PHONEBUTTONFUNCTION_RECALL;
  2000. break;
  2001. case PBF_REDIRECT:
  2002. dwButtonFunction = PHONEBUTTONFUNCTION_REDIRECT;
  2003. break;
  2004. case PBF_REJECT:
  2005. dwButtonFunction = PHONEBUTTONFUNCTION_REJECT;
  2006. break;
  2007. case PBF_REPDIAL:
  2008. dwButtonFunction = PHONEBUTTONFUNCTION_REPDIAL;
  2009. break;
  2010. case PBF_RINGAGAIN:
  2011. dwButtonFunction = PHONEBUTTONFUNCTION_RINGAGAIN;
  2012. break;
  2013. case PBF_SAVEREPEAT:
  2014. dwButtonFunction = PHONEBUTTONFUNCTION_SAVEREPEAT;
  2015. break;
  2016. case PBF_SELECTRING:
  2017. dwButtonFunction = PHONEBUTTONFUNCTION_SELECTRING;
  2018. break;
  2019. case PBF_SETREPDIAL:
  2020. dwButtonFunction = PHONEBUTTONFUNCTION_SETREPDIAL;
  2021. break;
  2022. case PBF_SENDCALLS:
  2023. dwButtonFunction = PHONEBUTTONFUNCTION_SENDCALLS;
  2024. break;
  2025. case PBF_SPEAKEROFF:
  2026. dwButtonFunction = PHONEBUTTONFUNCTION_SPEAKEROFF;
  2027. break;
  2028. case PBF_SPEAKERON:
  2029. dwButtonFunction = PHONEBUTTONFUNCTION_SPEAKERON;
  2030. break;
  2031. case PBF_STATIONSPEED:
  2032. dwButtonFunction = PHONEBUTTONFUNCTION_STATIONSPEED;
  2033. break;
  2034. case PBF_SYSTEMSPEED:
  2035. dwButtonFunction = PHONEBUTTONFUNCTION_SYSTEMSPEED;
  2036. break;
  2037. case PBF_TRANSFER:
  2038. dwButtonFunction = PHONEBUTTONFUNCTION_TRANSFER;
  2039. break;
  2040. case PBF_UNKNOWN:
  2041. dwButtonFunction = PHONEBUTTONFUNCTION_UNKNOWN;
  2042. break;
  2043. case PBF_VOLUMEDOWN:
  2044. dwButtonFunction = PHONEBUTTONFUNCTION_VOLUMEDOWN;
  2045. break;
  2046. case PBF_VOLUMEUP:
  2047. dwButtonFunction = PHONEBUTTONFUNCTION_VOLUMEUP;
  2048. break;
  2049. case PBF_SEND:
  2050. dwButtonFunction = PHONEBUTTONFUNCTION_SEND;
  2051. break;
  2052. default:
  2053. LOG((TL_ERROR, "put_ButtonFunction - bad ButtonFunction"));
  2054. Unlock();
  2055. ClientFree(pButtonInfo);
  2056. pButtonInfo = NULL;
  2057. return E_INVALIDARG;
  2058. }
  2059. //
  2060. // put the value into the structure to be passed to tapisrv
  2061. //
  2062. pButtonInfo->dwButtonFunction = dwButtonFunction;
  2063. //
  2064. // set the new button function
  2065. //
  2066. hr = PhoneSetButtonInfo(m_hPhone, lButtonID, pButtonInfo);
  2067. Unlock();
  2068. //
  2069. // free memory returned to us by PhoneGetButtonInfo
  2070. //
  2071. ClientFree(pButtonInfo);
  2072. pButtonInfo = NULL;
  2073. LOG((TL_TRACE, "put_ButtonFunction - exit - return %lx", hr ));
  2074. return hr;
  2075. }
  2076. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2077. //
  2078. // get_ButtonText
  2079. //
  2080. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2081. STDMETHODIMP
  2082. CPhone::get_ButtonText(
  2083. long lButtonID,
  2084. BSTR * ppButtonText
  2085. )
  2086. {
  2087. LPPHONEBUTTONINFO pButtonInfo;
  2088. HRESULT hr;
  2089. LOG((TL_TRACE, "get_ButtonText - enter" ));
  2090. if ( TAPIIsBadWritePtr( ppButtonText, sizeof(BSTR) ) )
  2091. {
  2092. LOG((TL_ERROR, "get_ButtonText - bad pointer"));
  2093. return E_POINTER;
  2094. }
  2095. Lock();
  2096. if ( m_hPhone == NULL )
  2097. {
  2098. LOG((TL_ERROR, "get_ButtonText - phone not open"));
  2099. Unlock();
  2100. return TAPI_E_PHONENOTOPEN;
  2101. }
  2102. //
  2103. // Get the ButtonInfo buffer
  2104. //
  2105. hr = PhoneGetButtonInfo(
  2106. m_hPhone,
  2107. lButtonID,
  2108. &pButtonInfo
  2109. );
  2110. if ( SUCCEEDED(hr) )
  2111. {
  2112. if ( pButtonInfo->dwButtonTextSize != 0 )
  2113. {
  2114. //
  2115. // Allocate the BSTR
  2116. //
  2117. *ppButtonText = SysAllocString( (LPWSTR)(((LPBYTE)(pButtonInfo)) + pButtonInfo->dwButtonTextOffset) );
  2118. if ( NULL == *ppButtonText )
  2119. {
  2120. LOG((TL_ERROR, "get_ButtonText - SysAllocString Failed"));
  2121. hr = E_OUTOFMEMORY;
  2122. }
  2123. }
  2124. else
  2125. {
  2126. LOG((TL_ERROR, "get_ButtonText - button has no text"));
  2127. hr = E_FAIL;
  2128. }
  2129. //
  2130. // Free the ButtonInfo buffer
  2131. //
  2132. ClientFree( pButtonInfo );
  2133. }
  2134. Unlock();
  2135. LOG((TL_TRACE, "get_ButtonText - exit - return %lx", hr));
  2136. return hr;
  2137. }
  2138. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2139. //
  2140. // get_ButtonState
  2141. //
  2142. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2143. STDMETHODIMP
  2144. CPhone::get_ButtonState(
  2145. long lButtonID,
  2146. PHONE_BUTTON_STATE * pButtonState
  2147. )
  2148. {
  2149. LPPHONEBUTTONINFO pButtonInfo;
  2150. HRESULT hr;
  2151. LOG((TL_TRACE, "get_ButtonState - enter" ));
  2152. if ( TAPIIsBadWritePtr( pButtonState, sizeof(PHONE_BUTTON_STATE) ) )
  2153. {
  2154. LOG((TL_ERROR, "get_ButtonState - bad pointer"));
  2155. return E_POINTER;
  2156. }
  2157. Lock();
  2158. if ( m_hPhone == NULL )
  2159. {
  2160. LOG((TL_ERROR, "get_ButtonState - phone not open"));
  2161. Unlock();
  2162. return TAPI_E_PHONENOTOPEN;
  2163. }
  2164. //
  2165. // Get the ButtonInfo buffer
  2166. //
  2167. hr = PhoneGetButtonInfo(
  2168. m_hPhone,
  2169. lButtonID,
  2170. &pButtonInfo
  2171. );
  2172. if (FAILED(hr))
  2173. {
  2174. LOG((TL_ERROR, "get_ButtonState - failed to get get button info"));
  2175. Unlock();
  2176. return hr;
  2177. }
  2178. switch (pButtonInfo->dwButtonState)
  2179. {
  2180. case PHONEBUTTONSTATE_UP:
  2181. *pButtonState = PBS_UP;
  2182. break;
  2183. case PHONEBUTTONSTATE_DOWN:
  2184. *pButtonState = PBS_DOWN;
  2185. break;
  2186. case PHONEBUTTONSTATE_UNKNOWN:
  2187. *pButtonState = PBS_UNKNOWN;
  2188. break;
  2189. case PHONEBUTTONSTATE_UNAVAIL:
  2190. *pButtonState = PBS_UNAVAIL;
  2191. break;
  2192. default:
  2193. LOG((TL_ERROR, "get_ButtonState - bad button state"));
  2194. hr = E_FAIL;
  2195. }
  2196. //
  2197. // Free the ButtonInfo buffer
  2198. //
  2199. ClientFree( pButtonInfo );
  2200. Unlock();
  2201. LOG((TL_TRACE, "get_ButtonState - exit - return %lx", hr));
  2202. return hr;
  2203. }
  2204. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2205. //
  2206. // get_LampMode
  2207. //
  2208. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2209. STDMETHODIMP
  2210. CPhone::get_LampMode(
  2211. long lLampID,
  2212. PHONE_LAMP_MODE* pLampMode
  2213. )
  2214. {
  2215. LOG((TL_TRACE, "get_LampMode - enter" ));
  2216. if ( TAPIIsBadWritePtr( pLampMode, sizeof(PHONE_LAMP_MODE) ) )
  2217. {
  2218. LOG((TL_ERROR, "get_LampMode - bad pointer"));
  2219. return E_POINTER;
  2220. }
  2221. Lock();
  2222. if ( m_hPhone == NULL )
  2223. {
  2224. LOG((TL_ERROR, "get_LampMode - phone not open"));
  2225. Unlock();
  2226. return TAPI_E_PHONENOTOPEN;
  2227. }
  2228. //
  2229. // get lamp mode from tapisrv
  2230. //
  2231. DWORD dwLampMode = 0;
  2232. HRESULT hr = PhoneGetLamp(m_hPhone, lLampID, &dwLampMode);
  2233. Unlock();
  2234. if (FAILED(hr))
  2235. {
  2236. LOG((TL_ERROR, "get_LampMode - failed to get lamp mode - %lx", hr));
  2237. return hr;
  2238. }
  2239. //
  2240. // map the value returned by tapisrv to tapi3.x value
  2241. //
  2242. switch (dwLampMode)
  2243. {
  2244. case PHONELAMPMODE_DUMMY:
  2245. *pLampMode = LM_DUMMY;
  2246. break;
  2247. case PHONELAMPMODE_BROKENFLUTTER:
  2248. *pLampMode = LM_BROKENFLUTTER;
  2249. break;
  2250. case PHONELAMPMODE_FLASH:
  2251. *pLampMode = LM_FLASH;
  2252. break;
  2253. case PHONELAMPMODE_FLUTTER:
  2254. *pLampMode = LM_FLUTTER;
  2255. break;
  2256. case PHONELAMPMODE_OFF:
  2257. *pLampMode = LM_OFF;
  2258. break;
  2259. case PHONELAMPMODE_STEADY:
  2260. *pLampMode = LM_STEADY;
  2261. break;
  2262. case PHONELAMPMODE_UNKNOWN:
  2263. *pLampMode = LM_UNKNOWN;
  2264. break;
  2265. case PHONELAMPMODE_WINK :
  2266. *pLampMode = LM_WINK;
  2267. break;
  2268. default:
  2269. LOG((TL_ERROR, "get_LampMode - bad lamp mode received from tapisrv"));
  2270. return E_FAIL;
  2271. }
  2272. LOG((TL_TRACE, "get_LampMode - exit - return S_OK"));
  2273. return S_OK;
  2274. }
  2275. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2276. //
  2277. // put_LampMode
  2278. //
  2279. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2280. STDMETHODIMP
  2281. CPhone::put_LampMode(
  2282. long lLampID,
  2283. PHONE_LAMP_MODE enLampMode
  2284. )
  2285. {
  2286. LOG((TL_TRACE, "put_LampMode - enter" ));
  2287. Lock();
  2288. //
  2289. // Make sure the phone is open with owner privilege.
  2290. //
  2291. if ( m_hPhone == NULL )
  2292. {
  2293. LOG((TL_ERROR, "put_LampMode - phone is not open - "
  2294. "exit TAPI_E_PHONENOTOPEN"));
  2295. Unlock();
  2296. return TAPI_E_PHONENOTOPEN;
  2297. }
  2298. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  2299. {
  2300. LOG((TL_ERROR, "put_LampMode - wrong phone privilege - "
  2301. "exit TAPI_E_NOTOWNER"));
  2302. Unlock();
  2303. return TAPI_E_NOTOWNER;
  2304. }
  2305. //
  2306. // map PHONE_LAMP_MODE to the dword value understood by tapisrv
  2307. //
  2308. DWORD dwLampMode = 0;
  2309. switch (enLampMode)
  2310. {
  2311. case LM_DUMMY:
  2312. dwLampMode = PHONELAMPMODE_DUMMY;
  2313. break;
  2314. case LM_BROKENFLUTTER:
  2315. dwLampMode = PHONELAMPMODE_BROKENFLUTTER;
  2316. break;
  2317. case LM_FLASH:
  2318. dwLampMode = PHONELAMPMODE_FLASH;
  2319. break;
  2320. case LM_FLUTTER:
  2321. dwLampMode = PHONELAMPMODE_FLUTTER;
  2322. break;
  2323. case LM_OFF:
  2324. dwLampMode = PHONELAMPMODE_OFF;
  2325. break;
  2326. case LM_STEADY:
  2327. dwLampMode = PHONELAMPMODE_STEADY;
  2328. break;
  2329. case LM_UNKNOWN:
  2330. dwLampMode = PHONELAMPMODE_UNKNOWN;
  2331. break;
  2332. case LM_WINK:
  2333. dwLampMode = PHONELAMPMODE_WINK;
  2334. break;
  2335. default:
  2336. LOG((TL_ERROR, "put_LampMode - unknown lamp mode"));
  2337. Unlock();
  2338. return E_INVALIDARG;
  2339. }
  2340. //
  2341. // make a call to tapisrv to set lamp mode
  2342. //
  2343. HRESULT hr = PhoneSetLamp(m_hPhone, lLampID, dwLampMode);
  2344. Unlock();
  2345. LOG((TL_TRACE, "put_LampMode - exit - return %lx", hr ));
  2346. return hr;
  2347. }
  2348. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2349. //
  2350. // get_HookSwitchState
  2351. //
  2352. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2353. STDMETHODIMP
  2354. CPhone::get_HookSwitchState(
  2355. PHONE_HOOK_SWITCH_DEVICE HookSwitchDevice,
  2356. PHONE_HOOK_SWITCH_STATE * pHookSwitchState
  2357. )
  2358. {
  2359. HRESULT hr;
  2360. LPPHONESTATUS pPhoneStatus;
  2361. DWORD dwHookSwitchMode;
  2362. LOG((TL_TRACE, "get_HookSwitchState - enter" ));
  2363. if ( 0 == HookSwitchDevice )
  2364. {
  2365. LOG((TL_ERROR, "get_HookSwitchState - invalid hookswitch"));
  2366. return E_INVALIDARG;
  2367. }
  2368. if ( TAPIIsBadWritePtr( pHookSwitchState, sizeof(PHONE_HOOK_SWITCH_STATE) ) )
  2369. {
  2370. LOG((TL_ERROR, "get_HookSwitchState - bad pointer"));
  2371. return E_POINTER;
  2372. }
  2373. Lock();
  2374. if ( m_hPhone == NULL )
  2375. {
  2376. LOG((TL_ERROR, "get_HookSwitchState - phone not open"));
  2377. Unlock();
  2378. return TAPI_E_PHONENOTOPEN;
  2379. }
  2380. //
  2381. // Update the phone caps cache
  2382. //
  2383. hr = UpdatePhoneCaps();
  2384. if ( FAILED(hr) )
  2385. {
  2386. LOG((TL_ERROR, "get_HookSwitchState - could not get phonecaps - %lx", hr));
  2387. Unlock();
  2388. return hr;
  2389. }
  2390. if ( !(m_pPhoneCaps->dwHookSwitchDevs & HookSwitchDevice) )
  2391. {
  2392. LOG((TL_ERROR, "get_HookSwitchState - invalid hookswitch"));
  2393. Unlock();
  2394. return TAPI_E_RESOURCEUNAVAIL;
  2395. }
  2396. //
  2397. // Get the PhoneStatus buffer
  2398. //
  2399. hr = PhoneGetStatusWithAlloc(m_hPhone, &pPhoneStatus);
  2400. if ( SUCCEEDED(hr) )
  2401. {
  2402. //
  2403. // get the proper hookswitch mode from the phone status struct
  2404. //
  2405. switch (HookSwitchDevice)
  2406. {
  2407. case PHSD_HANDSET:
  2408. dwHookSwitchMode = pPhoneStatus->dwHandsetHookSwitchMode;
  2409. break;
  2410. case PHSD_SPEAKERPHONE:
  2411. dwHookSwitchMode = pPhoneStatus->dwSpeakerHookSwitchMode;
  2412. break;
  2413. case PHSD_HEADSET:
  2414. dwHookSwitchMode = pPhoneStatus->dwHeadsetHookSwitchMode;
  2415. break;
  2416. default:
  2417. LOG((TL_ERROR, "get_HookSwitchState - bad HookSwitchDevice"));
  2418. hr = E_INVALIDARG;
  2419. }
  2420. }
  2421. if ( pPhoneStatus != NULL )
  2422. {
  2423. //
  2424. // Free the PhoneStatusBuffer
  2425. //
  2426. ClientFree( pPhoneStatus );
  2427. }
  2428. if ( SUCCEEDED(hr) )
  2429. {
  2430. //
  2431. // translate the hookswitch mode to a tapi3 value
  2432. //
  2433. switch (dwHookSwitchMode)
  2434. {
  2435. case PHONEHOOKSWITCHMODE_ONHOOK:
  2436. *pHookSwitchState = PHSS_ONHOOK;
  2437. break;
  2438. case PHONEHOOKSWITCHMODE_MIC:
  2439. *pHookSwitchState = PHSS_OFFHOOK_MIC_ONLY;
  2440. break;
  2441. case PHONEHOOKSWITCHMODE_SPEAKER:
  2442. *pHookSwitchState = PHSS_OFFHOOK_SPEAKER_ONLY;
  2443. break;
  2444. case PHONEHOOKSWITCHMODE_MICSPEAKER:
  2445. *pHookSwitchState = PHSS_OFFHOOK;
  2446. break;
  2447. default:
  2448. LOG((TL_ERROR, "get_HookSwitchState - bad dwHookSwitchMode"));
  2449. hr = E_FAIL;
  2450. }
  2451. }
  2452. Unlock();
  2453. LOG((TL_TRACE, "get_HookSwitchState - exit - return %lx", hr));
  2454. return hr;
  2455. }
  2456. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2457. //
  2458. // put_HookSwitchState
  2459. //
  2460. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2461. STDMETHODIMP
  2462. CPhone::put_HookSwitchState(
  2463. PHONE_HOOK_SWITCH_DEVICE HookSwitchDevice,
  2464. PHONE_HOOK_SWITCH_STATE HookSwitchState
  2465. )
  2466. {
  2467. DWORD dwHookSwitchMode;
  2468. HRESULT hr;
  2469. LOG((TL_TRACE, "put_HookSwitchState - enter" ));
  2470. if ( 0 == HookSwitchDevice )
  2471. {
  2472. LOG((TL_ERROR, "put_HookSwitchState - invalid hookswitch"));
  2473. return E_INVALIDARG;
  2474. }
  2475. Lock();
  2476. //
  2477. // Make sure the phone is open with owner privilege.
  2478. //
  2479. if ( m_hPhone == NULL )
  2480. {
  2481. LOG((TL_ERROR, "put_HookSwitchState - phone is not open - "
  2482. "exit TAPI_E_PHONENOTOPEN"));
  2483. Unlock();
  2484. return TAPI_E_PHONENOTOPEN;
  2485. }
  2486. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  2487. {
  2488. LOG((TL_ERROR, "put_HookSwitchState - wrong phone privilege - "
  2489. "exit TAPI_E_NOTOWNER"));
  2490. Unlock();
  2491. return TAPI_E_NOTOWNER;
  2492. }
  2493. //
  2494. // Update the phone caps cache
  2495. //
  2496. hr = UpdatePhoneCaps();
  2497. if ( FAILED(hr) )
  2498. {
  2499. LOG((TL_ERROR, "put_HookSwitchState - could not get phonecaps - %lx", hr));
  2500. Unlock();
  2501. return hr;
  2502. }
  2503. if ( !(m_pPhoneCaps->dwHookSwitchDevs & HookSwitchDevice) )
  2504. {
  2505. LOG((TL_ERROR, "put_HookSwitchState - invalid hookswitch"));
  2506. Unlock();
  2507. return TAPI_E_RESOURCEUNAVAIL;
  2508. }
  2509. //
  2510. // Translate the hookswithstate from tapi3 to tapi2 values
  2511. //
  2512. switch (HookSwitchState)
  2513. {
  2514. case PHSS_ONHOOK:
  2515. dwHookSwitchMode = PHONEHOOKSWITCHMODE_ONHOOK;
  2516. break;
  2517. case PHSS_OFFHOOK_MIC_ONLY:
  2518. dwHookSwitchMode = PHONEHOOKSWITCHMODE_MIC;
  2519. break;
  2520. case PHSS_OFFHOOK_SPEAKER_ONLY:
  2521. dwHookSwitchMode = PHONEHOOKSWITCHMODE_SPEAKER;
  2522. break;
  2523. case PHSS_OFFHOOK:
  2524. dwHookSwitchMode = PHONEHOOKSWITCHMODE_MICSPEAKER;
  2525. break;
  2526. default:
  2527. LOG((TL_ERROR, "put_HookSwitchState - bad HookSwitchMode"));
  2528. Unlock();
  2529. return E_INVALIDARG;
  2530. }
  2531. //
  2532. // Set the proper hookswitch
  2533. //
  2534. switch (HookSwitchDevice)
  2535. {
  2536. case PHSD_HANDSET:
  2537. hr = PhoneSetHookSwitch(m_hPhone, PHONEHOOKSWITCHDEV_HANDSET, dwHookSwitchMode);
  2538. break;
  2539. case PHSD_SPEAKERPHONE:
  2540. hr = PhoneSetHookSwitch(m_hPhone, PHONEHOOKSWITCHDEV_SPEAKER, dwHookSwitchMode);
  2541. break;
  2542. case PHSD_HEADSET:
  2543. hr = PhoneSetHookSwitch(m_hPhone, PHONEHOOKSWITCHDEV_HEADSET, dwHookSwitchMode);
  2544. break;
  2545. default:
  2546. LOG((TL_ERROR, "put_HookSwitchState - bad HookSwitchDevice"));
  2547. hr = E_INVALIDARG;
  2548. }
  2549. Unlock();
  2550. LOG((TL_TRACE, "put_HookSwitchState - exit - return %lx", hr));
  2551. return hr;
  2552. }
  2553. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2554. //
  2555. // put_RingMode
  2556. //
  2557. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2558. STDMETHODIMP
  2559. CPhone::put_RingMode(
  2560. long lRingMode
  2561. )
  2562. {
  2563. HRESULT hr;
  2564. DWORD dwDummy;
  2565. DWORD dwVolume;
  2566. LOG((TL_TRACE, "put_RingMode - enter" ));
  2567. Lock();
  2568. //
  2569. // Make sure the phone is open with owner privilege.
  2570. //
  2571. if ( m_hPhone == NULL )
  2572. {
  2573. LOG((TL_ERROR, "put_RingMode - phone is not open - "
  2574. "exit TAPI_E_PHONENOTOPEN"));
  2575. Unlock();
  2576. return TAPI_E_PHONENOTOPEN;
  2577. }
  2578. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  2579. {
  2580. LOG((TL_ERROR, "put_RingMode - wrong phone privilege - "
  2581. "exit TAPI_E_NOTOWNER"));
  2582. Unlock();
  2583. return TAPI_E_NOTOWNER;
  2584. }
  2585. hr = PhoneGetRing(m_hPhone, &dwDummy, &dwVolume);
  2586. if ( FAILED(hr) )
  2587. {
  2588. LOG((TL_ERROR, "put_RingMode - PhoneGetRing failed"));
  2589. Unlock();
  2590. return hr;
  2591. }
  2592. hr = PhoneSetRing(m_hPhone, lRingMode, dwVolume );
  2593. Unlock();
  2594. LOG((TL_TRACE, "put_RingMode - exit - return %lx", hr));
  2595. return hr;
  2596. }
  2597. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2598. //
  2599. // get_RingMode
  2600. //
  2601. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2602. STDMETHODIMP
  2603. CPhone::get_RingMode(
  2604. long * plRingMode
  2605. )
  2606. {
  2607. HRESULT hr;
  2608. DWORD dwDummy;
  2609. LOG((TL_TRACE, "get_RingMode - enter" ));
  2610. if ( TAPIIsBadWritePtr( plRingMode, sizeof(long) ) )
  2611. {
  2612. LOG((TL_ERROR, "get_RingMode - bad pointer"));
  2613. return E_POINTER;
  2614. }
  2615. Lock();
  2616. if ( m_hPhone == NULL )
  2617. {
  2618. LOG((TL_ERROR, "get_RingMode - phone not open"));
  2619. Unlock();
  2620. return TAPI_E_PHONENOTOPEN;
  2621. }
  2622. hr = PhoneGetRing(m_hPhone, (LPDWORD)plRingMode, &dwDummy);
  2623. Unlock();
  2624. LOG((TL_TRACE, "get_RingMode - exit - return %lx", hr));
  2625. return hr;
  2626. }
  2627. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2628. //
  2629. // put_RingVolume
  2630. //
  2631. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2632. STDMETHODIMP
  2633. CPhone::put_RingVolume(
  2634. long lRingVolume
  2635. )
  2636. {
  2637. HRESULT hr;
  2638. DWORD dwDummy;
  2639. DWORD dwMode;
  2640. LOG((TL_TRACE, "put_RingVolume - enter" ));
  2641. Lock();
  2642. //
  2643. // Make sure the phone is open with owner privilege.
  2644. //
  2645. if ( m_hPhone == NULL )
  2646. {
  2647. LOG((TL_ERROR, "put_RingVolume - phone is not open - "
  2648. "exit TAPI_E_PHONENOTOPEN"));
  2649. Unlock();
  2650. return TAPI_E_PHONENOTOPEN;
  2651. }
  2652. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  2653. {
  2654. LOG((TL_ERROR, "put_RingVolume - wrong phone privilege - "
  2655. "exit TAPI_E_NOTOWNER"));
  2656. Unlock();
  2657. return TAPI_E_NOTOWNER;
  2658. }
  2659. hr = PhoneGetRing(m_hPhone, &dwMode, &dwDummy);
  2660. if ( FAILED(hr) )
  2661. {
  2662. LOG((TL_ERROR, "put_RingVolume - PhoneGetRing failed"));
  2663. Unlock();
  2664. return hr;
  2665. }
  2666. hr = PhoneSetRing(m_hPhone, dwMode, lRingVolume );
  2667. Unlock();
  2668. LOG((TL_TRACE, "put_RingVolume - exit" ));
  2669. return hr;
  2670. }
  2671. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2672. //
  2673. // get_RingVolume
  2674. //
  2675. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2676. STDMETHODIMP
  2677. CPhone::get_RingVolume(
  2678. long * plRingVolume
  2679. )
  2680. {
  2681. HRESULT hr;
  2682. DWORD dwDummy;
  2683. LOG((TL_TRACE, "get_RingVolume - enter" ));
  2684. if ( TAPIIsBadWritePtr( plRingVolume, sizeof(long) ) )
  2685. {
  2686. LOG((TL_ERROR, "get_RingVolume - bad pointer"));
  2687. return E_POINTER;
  2688. }
  2689. Lock();
  2690. if ( m_hPhone == NULL )
  2691. {
  2692. LOG((TL_ERROR, "get_RingVolume - phone not open"));
  2693. Unlock();
  2694. return TAPI_E_PHONENOTOPEN;
  2695. }
  2696. hr = PhoneGetRing(m_hPhone, &dwDummy, (LPDWORD)plRingVolume );
  2697. Unlock();
  2698. LOG((TL_TRACE, "get_RingVolume - exit - return %lx", hr));
  2699. return hr;
  2700. }
  2701. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2702. //
  2703. // get_Privilege
  2704. //
  2705. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2706. STDMETHODIMP
  2707. CPhone::get_Privilege(
  2708. PHONE_PRIVILEGE * pPrivilege
  2709. )
  2710. {
  2711. HRESULT hr = S_OK;
  2712. LOG((TL_TRACE, "get_Privilege - enter" ));
  2713. if ( TAPIIsBadWritePtr( pPrivilege, sizeof(PHONE_PRIVILEGE) ) )
  2714. {
  2715. LOG((TL_ERROR, "get_Privilege - bad pointer"));
  2716. return E_POINTER;
  2717. }
  2718. Lock();
  2719. if ( m_hPhone == NULL )
  2720. {
  2721. LOG((TL_ERROR, "get_Privilege - phone not open"));
  2722. Unlock();
  2723. return TAPI_E_PHONENOTOPEN;
  2724. }
  2725. switch(m_dwPrivilege)
  2726. {
  2727. case PHONEPRIVILEGE_OWNER:
  2728. *pPrivilege = PP_OWNER;
  2729. break;
  2730. case PHONEPRIVILEGE_MONITOR:
  2731. *pPrivilege = PP_MONITOR;
  2732. break;
  2733. default:
  2734. _ASSERTE(FALSE);
  2735. hr = E_UNEXPECTED;
  2736. break;
  2737. }
  2738. Unlock();
  2739. LOG((TL_TRACE, "get_Privilege - exit - return %lx", hr));
  2740. return hr;
  2741. }
  2742. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2743. //
  2744. // Initialize
  2745. //
  2746. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2747. HRESULT
  2748. CPhone::Initialize(
  2749. ITTAPI * pTAPI,
  2750. HPHONEAPP hPhoneApp,
  2751. DWORD dwAPIVersion,
  2752. DWORD dwDeviceID
  2753. )
  2754. {
  2755. LPVARSTRING pVarString = NULL;
  2756. LONG lResult;
  2757. T3PHONE t3Phone;
  2758. HRESULT hr;
  2759. LOG((TL_TRACE, "Initialize - enter" ));
  2760. LOG((TL_INFO, " hPhoneApp --------->%lx", hPhoneApp ));
  2761. LOG((TL_INFO, " dwAPIVersion ------>%lx", dwAPIVersion ));
  2762. LOG((TL_INFO, " dwDeviceID -------->%lx", dwDeviceID ));
  2763. Lock();
  2764. //
  2765. // save relevant info
  2766. //
  2767. m_pTAPI = NULL;
  2768. m_dwDeviceID = dwDeviceID;
  2769. m_hPhoneApp = hPhoneApp;
  2770. m_dwAPIVersion = dwAPIVersion;
  2771. m_pPhoneCaps = NULL;
  2772. m_hPhone = NULL;
  2773. m_pdwLineDeviceIDs = NULL;
  2774. m_dwNumLineDeviceIDs = 0;
  2775. try
  2776. {
  2777. InitializeCriticalSection( &m_csAutomatedPhoneState );
  2778. }
  2779. catch(...)
  2780. {
  2781. LOG((TL_ERROR, "Initialize - out of memory" ));
  2782. Unlock();
  2783. return E_OUTOFMEMORY;
  2784. }
  2785. try
  2786. {
  2787. InitializeCriticalSection( &m_csToneTimer );
  2788. }
  2789. catch(...)
  2790. {
  2791. LOG((TL_ERROR, "Initialize - out of memory" ));
  2792. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2793. Unlock();
  2794. return E_OUTOFMEMORY;
  2795. }
  2796. try
  2797. {
  2798. InitializeCriticalSection( &m_csRingTimer );
  2799. }
  2800. catch(...)
  2801. {
  2802. LOG((TL_ERROR, "Initialize - out of memory" ));
  2803. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2804. DeleteCriticalSection( &m_csToneTimer );
  2805. Unlock();
  2806. return E_OUTOFMEMORY;
  2807. }
  2808. //
  2809. // allocate a buffer for the numbers gathered
  2810. //
  2811. m_wszNumbersGathered = (LPWSTR)ClientAlloc( (APC_MAX_NUMBERS_GATHERED + 1) * sizeof( WCHAR ) );
  2812. if (m_wszNumbersGathered == NULL)
  2813. {
  2814. LOG((TL_ERROR, "Initialize - out of memory" ));
  2815. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2816. DeleteCriticalSection( &m_csToneTimer );
  2817. DeleteCriticalSection( &m_csRingTimer );
  2818. Unlock();
  2819. return E_OUTOFMEMORY;
  2820. }
  2821. //
  2822. // get line device ids associated with this phone
  2823. // we need to open the phone device to do this
  2824. //
  2825. t3Phone.hPhone = NULL;
  2826. t3Phone.pPhone = this;
  2827. hr = PhoneOpen(m_hPhoneApp, m_dwDeviceID, &t3Phone, m_dwAPIVersion, PHONEPRIVILEGE_MONITOR);
  2828. if ( SUCCEEDED(hr) )
  2829. {
  2830. hr = PhoneGetID(
  2831. t3Phone.hPhone,
  2832. &pVarString,
  2833. L"tapi/line"
  2834. );
  2835. PhoneClose(t3Phone.hPhone);
  2836. if ( SUCCEEDED(hr) )
  2837. {
  2838. m_pdwLineDeviceIDs = (DWORD *)ClientAlloc( pVarString->dwUsedSize );
  2839. if (m_pdwLineDeviceIDs == NULL)
  2840. {
  2841. LOG((TL_ERROR, "Initialize - out of memory" ));
  2842. ClientFree( pVarString );
  2843. ClientFree( m_wszNumbersGathered );
  2844. m_wszNumbersGathered = NULL;
  2845. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2846. DeleteCriticalSection( &m_csToneTimer );
  2847. DeleteCriticalSection( &m_csRingTimer );
  2848. Unlock();
  2849. return E_OUTOFMEMORY;
  2850. }
  2851. CopyMemory(
  2852. m_pdwLineDeviceIDs,
  2853. ((LPBYTE)pVarString)+pVarString->dwStringOffset,
  2854. pVarString->dwStringSize
  2855. );
  2856. m_dwNumLineDeviceIDs = pVarString->dwStringSize / sizeof(DWORD);
  2857. LOG((TL_INFO, " dwNumLineDeviceIDs -->%lx", m_dwNumLineDeviceIDs ));
  2858. }
  2859. if ( NULL != pVarString )
  2860. {
  2861. ClientFree( pVarString );
  2862. }
  2863. }
  2864. else
  2865. {
  2866. LOG((TL_ERROR, "Initialize - PhoneOpen failed %lx", hr ));
  2867. ClientFree( m_wszNumbersGathered );
  2868. m_wszNumbersGathered = NULL;
  2869. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2870. DeleteCriticalSection( &m_csToneTimer );
  2871. DeleteCriticalSection( &m_csRingTimer );
  2872. Unlock();
  2873. return hr;
  2874. }
  2875. m_hTimerQueue = CreateTimerQueue();
  2876. if (m_hTimerQueue == NULL)
  2877. {
  2878. LOG((TL_ERROR, "Initialize - CreateTimerQueue failed %lx", hr ));
  2879. ClientFree( m_wszNumbersGathered );
  2880. m_wszNumbersGathered = NULL;
  2881. if (m_pdwLineDeviceIDs != NULL)
  2882. {
  2883. ClientFree( m_pdwLineDeviceIDs );
  2884. m_pdwLineDeviceIDs = NULL;
  2885. }
  2886. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2887. DeleteCriticalSection( &m_csToneTimer );
  2888. DeleteCriticalSection( &m_csRingTimer );
  2889. Unlock();
  2890. return E_OUTOFMEMORY;
  2891. }
  2892. m_hTimerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  2893. if (m_hTimerEvent == NULL)
  2894. {
  2895. LOG((TL_ERROR, "Initialize - CreateEvent failed %lx", hr ));
  2896. ClientFree( m_wszNumbersGathered );
  2897. m_wszNumbersGathered = NULL;
  2898. if (m_pdwLineDeviceIDs != NULL)
  2899. {
  2900. ClientFree( m_pdwLineDeviceIDs );
  2901. m_pdwLineDeviceIDs = NULL;
  2902. }
  2903. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2904. DeleteCriticalSection( &m_csToneTimer );
  2905. DeleteCriticalSection( &m_csRingTimer );
  2906. DeleteTimerQueue( m_hTimerQueue );
  2907. m_hTimerQueue = NULL;
  2908. Unlock();
  2909. return E_OUTOFMEMORY;
  2910. }
  2911. AddRef();
  2912. //
  2913. // Save a pointer to TAPI
  2914. //
  2915. m_pTAPI = pTAPI;
  2916. m_pTAPI->AddRef();
  2917. m_fInitialized = TRUE;
  2918. Unlock();
  2919. LOG((TL_TRACE, S_OK, "Initialize - exit"));
  2920. return S_OK;
  2921. }
  2922. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2923. //
  2924. // FinalRelease
  2925. // Clean up anything in the phone object.
  2926. //
  2927. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2928. void CPhone::FinalRelease()
  2929. {
  2930. LOG((TL_TRACE, "FinalRelease enter, this %p", this ));
  2931. Lock();
  2932. if (m_fInitialized == TRUE)
  2933. {
  2934. //
  2935. // Deallocate the phone caps cache
  2936. //
  2937. InvalidatePhoneCaps();
  2938. //
  2939. // Close the phone if it is open
  2940. //
  2941. if ( m_hPhone != NULL )
  2942. {
  2943. if (m_dwPrivilege == PHONEPRIVILEGE_OWNER)
  2944. {
  2945. if (m_fRinger == TRUE)
  2946. {
  2947. StopRinger();
  2948. }
  2949. if (m_Tone != PT_SILENCE)
  2950. {
  2951. StopTone();
  2952. }
  2953. CloseWaveDevice();
  2954. }
  2955. PhoneClose(m_hPhone);
  2956. }
  2957. //
  2958. // Delete timers
  2959. //
  2960. if (m_hTimerQueue != NULL)
  2961. {
  2962. DeleteTimerQueue(m_hTimerQueue);
  2963. m_hTimerQueue = NULL;
  2964. }
  2965. if (m_hTimerEvent != NULL)
  2966. {
  2967. CloseHandle( m_hTimerEvent );
  2968. m_hTimerEvent = NULL;
  2969. }
  2970. //
  2971. // Deallocate memory
  2972. //
  2973. if (m_wszNumbersGathered != NULL)
  2974. {
  2975. ClientFree( m_wszNumbersGathered );
  2976. m_wszNumbersGathered = NULL;
  2977. }
  2978. if (m_pdwLineDeviceIDs != NULL)
  2979. {
  2980. ClientFree( m_pdwLineDeviceIDs );
  2981. m_pdwLineDeviceIDs = NULL;
  2982. }
  2983. DeleteCriticalSection( &m_csAutomatedPhoneState );
  2984. DeleteCriticalSection( &m_csToneTimer );
  2985. DeleteCriticalSection( &m_csRingTimer );
  2986. if ( m_pCall != NULL )
  2987. {
  2988. m_pCall->Release();
  2989. m_pCall = NULL;
  2990. }
  2991. //
  2992. // Release our refernece to the Tapi object
  2993. //
  2994. if (m_pTAPI != NULL)
  2995. {
  2996. m_pTAPI->Release();
  2997. m_pTAPI = NULL;
  2998. }
  2999. }
  3000. Unlock();
  3001. LOG((TL_TRACE, "FinalRelease - exit, this %p", this ));
  3002. }
  3003. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3004. //
  3005. // SetPhoneCapsBuffer
  3006. //
  3007. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3008. void
  3009. CPhone::SetPhoneCapBuffer( LPVOID pBuf )
  3010. {
  3011. Lock();
  3012. //
  3013. // This allow the phone caps cache to notify us that our phone
  3014. // caps buffer has changed (or more likely it will pass us NULL
  3015. // to say out buffer has been destroyed)
  3016. //
  3017. m_pPhoneCaps = (LPPHONECAPS)pBuf;
  3018. Unlock();
  3019. }
  3020. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3021. //
  3022. // UpdatePhoneCaps
  3023. //
  3024. // must be called in lock
  3025. //
  3026. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3027. HRESULT
  3028. CPhone::UpdatePhoneCaps()
  3029. {
  3030. HRESULT hr = S_OK;
  3031. //
  3032. // Only do something if we don't have a current phone caps buffer
  3033. //
  3034. if ( NULL == m_pPhoneCaps )
  3035. {
  3036. LPPHONECAPS pTemp;
  3037. CTAPI * pCTapi;
  3038. pCTapi = GetTapi();
  3039. if( NULL == pCTapi )
  3040. {
  3041. LOG((TL_ERROR, "UpdatePhoneCaps - dynamic cast operation failed"));
  3042. _ASSERTE(FALSE);
  3043. hr = E_UNEXPECTED;
  3044. }
  3045. else
  3046. {
  3047. //
  3048. // Get a new buffer from the cache
  3049. //
  3050. hr = pCTapi->GetBuffer( BUFFERTYPE_PHONECAP,
  3051. (UINT_PTR)this,
  3052. (LPVOID*)&m_pPhoneCaps
  3053. );
  3054. }
  3055. if ( FAILED(hr) )
  3056. {
  3057. LOG((TL_ERROR, "UpdatePhoneCaps - GetBuffer failed - %lx", hr));
  3058. m_pPhoneCaps = NULL;
  3059. return hr;
  3060. }
  3061. pTemp = m_pPhoneCaps;
  3062. //
  3063. // Get the phone caps from tapi2
  3064. //
  3065. hr = PhoneGetDevCaps(
  3066. m_hPhoneApp,
  3067. m_dwDeviceID,
  3068. m_dwAPIVersion,
  3069. &m_pPhoneCaps
  3070. );
  3071. if ( FAILED(hr) )
  3072. {
  3073. LOG((TL_ERROR, "UpdatePhoneCaps - PhoneGetDevCaps failed - %lx", hr));
  3074. //
  3075. // Invalidate our buffer which is no good
  3076. //
  3077. InvalidatePhoneCaps();
  3078. return hr;
  3079. }
  3080. //
  3081. // PhoneGetDevsCaps may have reallocated our buffer. If so, tell the tapiobject
  3082. // cache mechanism what our new buffer is.
  3083. //
  3084. if ( m_pPhoneCaps != pTemp )
  3085. {
  3086. pCTapi->SetBuffer( BUFFERTYPE_PHONECAP, (UINT_PTR)this, (LPVOID)m_pPhoneCaps );
  3087. }
  3088. }
  3089. return S_OK;
  3090. }
  3091. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3092. //
  3093. // InvalidatePhoneCaps
  3094. //
  3095. // must be called in lock
  3096. //
  3097. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3098. HRESULT
  3099. CPhone::InvalidatePhoneCaps()
  3100. {
  3101. HRESULT hr = S_OK;
  3102. if ( NULL != m_pPhoneCaps )
  3103. {
  3104. CTAPI * pCTapi;
  3105. pCTapi = GetTapi();
  3106. if( NULL == pCTapi )
  3107. {
  3108. LOG((TL_ERROR, "InvalidatePhoneCaps - dynamic cast operation failed"));
  3109. _ASSERTE(FALSE);
  3110. hr = E_UNEXPECTED;
  3111. }
  3112. else
  3113. {
  3114. pCTapi->InvalidateBuffer( BUFFERTYPE_PHONECAP, (UINT_PTR)this );
  3115. }
  3116. m_pPhoneCaps = NULL;
  3117. }
  3118. return hr;
  3119. }
  3120. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3121. //
  3122. // IsPhoneOnAddress
  3123. //
  3124. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3125. BOOL
  3126. CPhone::IsPhoneOnAddress(ITAddress *pAddress)
  3127. {
  3128. BOOL bResult = FALSE;
  3129. HRESULT hr;
  3130. ITTerminalSupport * pTerminalSupport;
  3131. ITMediaSupport * pMediaSupport;
  3132. LONG lMediaType;
  3133. Lock();
  3134. //
  3135. // Update phone caps cache
  3136. //
  3137. hr = UpdatePhoneCaps();
  3138. if ( FAILED(hr) )
  3139. {
  3140. Unlock();
  3141. LOG((TL_ERROR, "IsPhoneOnAddress - UpdatePhoneCaps failed %lx", hr ));
  3142. return FALSE;
  3143. }
  3144. if ( (m_dwAPIVersion >= TAPI_VERSION2_0) && (m_pPhoneCaps->dwPhoneFeatures & PHONEFEATURE_GENERICPHONE) )
  3145. {
  3146. //
  3147. // We are a generic phone, therefore we
  3148. // are on any address that has a MSP and audio media types.
  3149. //
  3150. //
  3151. // get the terminal support interface
  3152. //
  3153. hr = pAddress->QueryInterface(
  3154. IID_ITTerminalSupport,
  3155. (void **)&pTerminalSupport
  3156. );
  3157. if ( FAILED(hr) )
  3158. {
  3159. Unlock();
  3160. LOG((TL_ERROR, "IsPhoneOnAddress - QueryInterface IID_ITTerminalSupport failed %lx", hr ));
  3161. return FALSE;
  3162. }
  3163. pTerminalSupport->Release();
  3164. //
  3165. // get the media support interface
  3166. //
  3167. hr = pAddress->QueryInterface(
  3168. IID_ITMediaSupport,
  3169. (void **)&pMediaSupport
  3170. );
  3171. if ( FAILED(hr) )
  3172. {
  3173. Unlock();
  3174. LOG((TL_ERROR, "IsPhoneOnAddress - QueryInterface IID_ITMediaSupport failed %lx", hr ));
  3175. return FALSE;
  3176. }
  3177. //
  3178. // get the mediatype
  3179. //
  3180. hr = pMediaSupport->get_MediaTypes(&lMediaType);
  3181. pMediaSupport->Release();
  3182. if ( FAILED(hr) )
  3183. {
  3184. Unlock();
  3185. LOG((TL_ERROR, "IsPhoneOnAddress - get_MediaTypes failed %lx", hr ));
  3186. return FALSE;
  3187. }
  3188. //
  3189. // make sure address supports audio
  3190. //
  3191. if (lMediaType & (LINEMEDIAMODE_INTERACTIVEVOICE | LINEMEDIAMODE_AUTOMATEDVOICE))
  3192. {
  3193. bResult = TRUE;
  3194. }
  3195. }
  3196. //
  3197. // If we haven't already decided that we support this address
  3198. // check to see if this a preferred address.
  3199. //
  3200. if ( bResult == FALSE )
  3201. {
  3202. bResult = IsPhoneOnPreferredAddress(pAddress);
  3203. }
  3204. Unlock();
  3205. return bResult;
  3206. }
  3207. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3208. //
  3209. // IsPhoneOnPreferredAddress
  3210. //
  3211. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3212. BOOL
  3213. CPhone::IsPhoneOnPreferredAddress(ITAddress *pAddress)
  3214. {
  3215. BOOL bResult = FALSE;
  3216. HRESULT hr;
  3217. CAddress * pCAddress;
  3218. Lock();
  3219. if ( m_dwNumLineDeviceIDs > 0 )
  3220. {
  3221. //
  3222. // Check out list of line device IDs to see if we are
  3223. // preferred on this address
  3224. //
  3225. pCAddress = dynamic_cast<CAddress *>(pAddress);
  3226. if (NULL == pCAddress)
  3227. {
  3228. Unlock();
  3229. LOG((TL_ERROR, "IsPhoneOnPreferredAddress - dynamic cast failed" ));
  3230. return FALSE;
  3231. }
  3232. for (int i = 0; i < m_dwNumLineDeviceIDs; i++ )
  3233. {
  3234. if ( m_pdwLineDeviceIDs[i] == pCAddress->GetDeviceID() )
  3235. {
  3236. //
  3237. // Yes, we matched this device ID to one in our list
  3238. //
  3239. bResult = TRUE;
  3240. break;
  3241. }
  3242. }
  3243. }
  3244. Unlock();
  3245. return bResult;
  3246. }
  3247. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3248. //
  3249. // IsPhoneUsingWaveID
  3250. //
  3251. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3252. BOOL CPhone::IsPhoneUsingWaveID(DWORD dwWaveID, TERMINAL_DIRECTION nDir)
  3253. {
  3254. T3PHONE t3Phone;
  3255. BOOL bResult = FALSE;
  3256. HRESULT hr;
  3257. LPVARSTRING pVarString = NULL;
  3258. DWORD dwPhoneWaveID;
  3259. //
  3260. // get wave device ids associated with this phone
  3261. // we need to open the phone device to do this
  3262. // Must use monitor privilege, because owner privilege open will
  3263. // fail if anyone happens to have the phone open as owner.
  3264. //
  3265. t3Phone.hPhone = NULL;
  3266. t3Phone.pPhone = this;
  3267. Lock();
  3268. hr = PhoneOpen(m_hPhoneApp, m_dwDeviceID, &t3Phone, m_dwAPIVersion, PHONEPRIVILEGE_MONITOR);
  3269. if ( SUCCEEDED(hr) )
  3270. {
  3271. switch(nDir)
  3272. {
  3273. case TD_CAPTURE:
  3274. {
  3275. hr = PhoneGetID(
  3276. t3Phone.hPhone,
  3277. &pVarString,
  3278. L"wave/in"
  3279. );
  3280. if ( SUCCEEDED(hr) )
  3281. {
  3282. if (pVarString->dwStringSize == sizeof(DWORD))
  3283. {
  3284. CopyMemory(
  3285. &dwPhoneWaveID,
  3286. ((LPBYTE)pVarString)+pVarString->dwStringOffset,
  3287. pVarString->dwStringSize
  3288. );
  3289. if ( dwWaveID == dwPhoneWaveID )
  3290. {
  3291. LOG((TL_INFO, "IsPhoneUsingWaveID - matched phone wave capture id %d", dwPhoneWaveID ));
  3292. bResult = TRUE;
  3293. }
  3294. }
  3295. }
  3296. break;
  3297. }
  3298. case TD_RENDER:
  3299. {
  3300. hr = PhoneGetID(
  3301. t3Phone.hPhone,
  3302. &pVarString,
  3303. L"wave/out"
  3304. );
  3305. if ( SUCCEEDED(hr) )
  3306. {
  3307. if (pVarString->dwStringSize == sizeof(DWORD))
  3308. {
  3309. CopyMemory(
  3310. &dwPhoneWaveID,
  3311. ((LPBYTE)pVarString)+pVarString->dwStringOffset,
  3312. pVarString->dwStringSize
  3313. );
  3314. if ( dwWaveID == dwPhoneWaveID )
  3315. {
  3316. LOG((TL_INFO, "IsPhoneUsingWaveID - matched phone wave render id %d", dwPhoneWaveID ));
  3317. bResult = TRUE;
  3318. }
  3319. }
  3320. }
  3321. break;
  3322. }
  3323. }
  3324. if ( NULL != pVarString )
  3325. {
  3326. ClientFree( pVarString );
  3327. }
  3328. PhoneClose(t3Phone.hPhone);
  3329. }
  3330. else
  3331. {
  3332. LOG((TL_ERROR, "IsPhoneUsingWaveID - PhoneOpen failed %lx", hr ));
  3333. }
  3334. Unlock();
  3335. return bResult;
  3336. }
  3337. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3338. //
  3339. // GetTapi
  3340. //
  3341. // private method to get the tapi object
  3342. //
  3343. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3344. CTAPI *
  3345. CPhone::GetTapi()
  3346. {
  3347. CTAPI * p = NULL;
  3348. Lock();
  3349. if( m_pTAPI != NULL )
  3350. {
  3351. p = dynamic_cast<CTAPI *>(m_pTAPI);
  3352. }
  3353. Unlock();
  3354. return p;
  3355. }
  3356. //
  3357. // handle dev specific message
  3358. //
  3359. void HandlePhoneDevSpecificMessage( PASYNCEVENTMSG pParams )
  3360. {
  3361. LOG((TL_INFO, "HandlePhoneDevSpecificMessage - enter"));
  3362. //
  3363. // find the phone corresponding to this event
  3364. //
  3365. CPhone *pPhone = NULL;
  3366. if (!FindPhoneObject((HPHONE)pParams->hDevice, &pPhone))
  3367. {
  3368. LOG((TL_WARN, "HandlePhoneDevSpecificMessage - FindPhoneObject failed to find matching phone."));
  3369. return;
  3370. }
  3371. //
  3372. // fire event
  3373. //
  3374. CPhoneDevSpecificEvent::FireEvent(
  3375. pPhone,
  3376. pParams->Param1,
  3377. pParams->Param2,
  3378. pParams->Param3
  3379. );
  3380. //
  3381. // undo findphoneobject's addref
  3382. //
  3383. pPhone->Release();
  3384. pPhone = NULL;
  3385. LOG((TL_INFO, "HandlePhoneDevSpecificMessage - exit. "));
  3386. }
  3387. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3388. //
  3389. // HandlePhoneButtonMessage
  3390. //
  3391. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3392. HRESULT HandlePhoneButtonMessage( PASYNCEVENTMSG pParams )
  3393. {
  3394. LOG((TL_TRACE, "HandlePhoneButtonMessage - enter"));
  3395. CPhone * pCPhone;
  3396. if (!FindPhoneObject((HPHONE)pParams->hDevice, &pCPhone))
  3397. {
  3398. LOG((TL_TRACE, "HandlePhoneButtonMessage - bad phone handle"));
  3399. return E_FAIL;
  3400. }
  3401. switch ( pParams->Param3 )
  3402. {
  3403. case PHONEBUTTONSTATE_DOWN:
  3404. //
  3405. // Automation event hook
  3406. //
  3407. pCPhone->Automation_ButtonDown( pParams->Param1 );
  3408. CPhoneEvent::FireEvent(
  3409. pCPhone,
  3410. PE_BUTTON,
  3411. PBS_DOWN,
  3412. (PHONE_HOOK_SWITCH_STATE)0,
  3413. (PHONE_HOOK_SWITCH_DEVICE)0,
  3414. 0,
  3415. pParams->Param1,
  3416. NULL,
  3417. NULL
  3418. );
  3419. break;
  3420. case PHONEBUTTONSTATE_UNAVAIL:
  3421. CPhoneEvent::FireEvent(
  3422. pCPhone,
  3423. PE_BUTTON,
  3424. PBS_UNAVAIL,
  3425. (PHONE_HOOK_SWITCH_STATE)0,
  3426. (PHONE_HOOK_SWITCH_DEVICE)0,
  3427. 0,
  3428. pParams->Param1,
  3429. NULL,
  3430. NULL
  3431. );
  3432. break;
  3433. case PHONEBUTTONSTATE_UNKNOWN:
  3434. CPhoneEvent::FireEvent(
  3435. pCPhone,
  3436. PE_BUTTON,
  3437. PBS_UNKNOWN,
  3438. (PHONE_HOOK_SWITCH_STATE)0,
  3439. (PHONE_HOOK_SWITCH_DEVICE)0,
  3440. 0,
  3441. pParams->Param1,
  3442. NULL,
  3443. NULL
  3444. );
  3445. break;
  3446. case PHONEBUTTONSTATE_UP:
  3447. //
  3448. // Automation event hook
  3449. //
  3450. pCPhone->Automation_ButtonUp( pParams->Param1 );
  3451. CPhoneEvent::FireEvent(
  3452. pCPhone,
  3453. PE_BUTTON,
  3454. PBS_UP,
  3455. (PHONE_HOOK_SWITCH_STATE)0,
  3456. (PHONE_HOOK_SWITCH_DEVICE)0,
  3457. 0,
  3458. pParams->Param1,
  3459. NULL,
  3460. NULL
  3461. );
  3462. break;
  3463. }
  3464. pCPhone->Release();
  3465. LOG((TL_TRACE, "HandlePhoneButtonMessage - exit"));
  3466. return S_OK;
  3467. }
  3468. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3469. //
  3470. // HandlePhoneStateMessage
  3471. //
  3472. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3473. HRESULT HandlePhoneStateMessage( PASYNCEVENTMSG pParams )
  3474. {
  3475. LOG((TL_TRACE, "HandlePhoneStateMessage - enter"));
  3476. CPhone * pCPhone;
  3477. PHONE_HOOK_SWITCH_STATE HookSwitchState;
  3478. if (!FindPhoneObject((HPHONE)pParams->hDevice, &pCPhone))
  3479. {
  3480. LOG((TL_TRACE, "HandlePhoneStateMessage - bad phone handle"));
  3481. return E_FAIL;
  3482. }
  3483. switch( pParams->Param1 ) // PhoneState
  3484. {
  3485. case PHONESTATE_CAPSCHANGE:
  3486. pCPhone->Lock();
  3487. //
  3488. // Phone caps have changed, so invalidate out cache
  3489. //
  3490. pCPhone->InvalidatePhoneCaps();
  3491. pCPhone->Unlock();
  3492. CPhoneEvent::FireEvent(
  3493. pCPhone,
  3494. PE_CAPSCHANGE,
  3495. (PHONE_BUTTON_STATE)0,
  3496. (PHONE_HOOK_SWITCH_STATE)0,
  3497. (PHONE_HOOK_SWITCH_DEVICE)0,
  3498. 0,
  3499. 0,
  3500. NULL,
  3501. NULL
  3502. );
  3503. break;
  3504. case PHONESTATE_HANDSETHOOKSWITCH:
  3505. if ( pParams->Param2 == PHONEHOOKSWITCHMODE_ONHOOK )
  3506. {
  3507. //
  3508. // Automation event hook
  3509. //
  3510. pCPhone->Automation_OnHook( PHSD_HANDSET );
  3511. }
  3512. else
  3513. {
  3514. //
  3515. // Automation event hook
  3516. //
  3517. pCPhone->Automation_OffHook( PHSD_HANDSET );
  3518. }
  3519. switch (pParams->Param2)
  3520. {
  3521. case PHONEHOOKSWITCHMODE_ONHOOK:
  3522. HookSwitchState = PHSS_ONHOOK;
  3523. break;
  3524. case PHONEHOOKSWITCHMODE_MIC:
  3525. HookSwitchState = PHSS_OFFHOOK_MIC_ONLY;
  3526. break;
  3527. case PHONEHOOKSWITCHMODE_SPEAKER:
  3528. HookSwitchState = PHSS_OFFHOOK_SPEAKER_ONLY;
  3529. break;
  3530. case PHONEHOOKSWITCHMODE_MICSPEAKER:
  3531. HookSwitchState = PHSS_OFFHOOK;
  3532. break;
  3533. default:
  3534. LOG((TL_ERROR, "HandlePhoneStateMessage - bad HookSwitchMode"));
  3535. pCPhone->Release();
  3536. return E_FAIL;
  3537. }
  3538. CPhoneEvent::FireEvent(
  3539. pCPhone,
  3540. PE_HOOKSWITCH,
  3541. (PHONE_BUTTON_STATE)0,
  3542. HookSwitchState,
  3543. PHSD_HANDSET,
  3544. 0,
  3545. 0,
  3546. NULL,
  3547. NULL
  3548. );
  3549. break;
  3550. case PHONESTATE_HEADSETHOOKSWITCH:
  3551. if ( pParams->Param2 == PHONEHOOKSWITCHMODE_ONHOOK )
  3552. {
  3553. //
  3554. // Automation event hook
  3555. //
  3556. pCPhone->Automation_OnHook( PHSD_HEADSET );
  3557. }
  3558. else
  3559. {
  3560. //
  3561. // Automation event hook
  3562. //
  3563. pCPhone->Automation_OffHook( PHSD_HEADSET );
  3564. }
  3565. switch (pParams->Param2)
  3566. {
  3567. case PHONEHOOKSWITCHMODE_ONHOOK:
  3568. HookSwitchState = PHSS_ONHOOK;
  3569. break;
  3570. case PHONEHOOKSWITCHMODE_MIC:
  3571. HookSwitchState = PHSS_OFFHOOK_MIC_ONLY;
  3572. break;
  3573. case PHONEHOOKSWITCHMODE_SPEAKER:
  3574. HookSwitchState = PHSS_OFFHOOK_SPEAKER_ONLY;
  3575. break;
  3576. case PHONEHOOKSWITCHMODE_MICSPEAKER:
  3577. HookSwitchState = PHSS_OFFHOOK;
  3578. break;
  3579. default:
  3580. LOG((TL_ERROR, "HandlePhoneStateMessage - bad HookSwitchMode"));
  3581. pCPhone->Release();
  3582. return E_FAIL;
  3583. }
  3584. CPhoneEvent::FireEvent(
  3585. pCPhone,
  3586. PE_HOOKSWITCH,
  3587. (PHONE_BUTTON_STATE)0,
  3588. HookSwitchState,
  3589. PHSD_HEADSET,
  3590. 0,
  3591. 0,
  3592. NULL,
  3593. NULL
  3594. );
  3595. break;
  3596. case PHONESTATE_LAMP:
  3597. CPhoneEvent::FireEvent(
  3598. pCPhone,
  3599. PE_LAMPMODE,
  3600. (PHONE_BUTTON_STATE)0,
  3601. (PHONE_HOOK_SWITCH_STATE)0,
  3602. (PHONE_HOOK_SWITCH_DEVICE)0,
  3603. 0,
  3604. pParams->Param2,
  3605. NULL,
  3606. NULL
  3607. );
  3608. break;
  3609. case PHONESTATE_RINGMODE:
  3610. CPhoneEvent::FireEvent(
  3611. pCPhone,
  3612. PE_RINGMODE,
  3613. (PHONE_BUTTON_STATE)0,
  3614. (PHONE_HOOK_SWITCH_STATE)0,
  3615. (PHONE_HOOK_SWITCH_DEVICE)0,
  3616. pParams->Param2,
  3617. 0,
  3618. NULL,
  3619. NULL
  3620. );
  3621. break;
  3622. case PHONESTATE_RINGVOLUME:
  3623. CPhoneEvent::FireEvent(
  3624. pCPhone,
  3625. PE_RINGVOLUME,
  3626. (PHONE_BUTTON_STATE)0,
  3627. (PHONE_HOOK_SWITCH_STATE)0,
  3628. (PHONE_HOOK_SWITCH_DEVICE)0,
  3629. 0,
  3630. 0,
  3631. NULL,
  3632. NULL
  3633. );
  3634. break;
  3635. case PHONESTATE_SPEAKERHOOKSWITCH:
  3636. if ( pParams->Param2 == PHONEHOOKSWITCHMODE_ONHOOK )
  3637. {
  3638. //
  3639. // Automation event hook
  3640. //
  3641. pCPhone->Automation_OnHook( PHSD_SPEAKERPHONE );
  3642. }
  3643. else
  3644. {
  3645. //
  3646. // Automation event hook
  3647. //
  3648. pCPhone->Automation_OffHook( PHSD_SPEAKERPHONE );
  3649. }
  3650. switch (pParams->Param2)
  3651. {
  3652. case PHONEHOOKSWITCHMODE_ONHOOK:
  3653. HookSwitchState = PHSS_ONHOOK;
  3654. break;
  3655. case PHONEHOOKSWITCHMODE_MIC:
  3656. HookSwitchState = PHSS_OFFHOOK_MIC_ONLY;
  3657. break;
  3658. case PHONEHOOKSWITCHMODE_SPEAKER:
  3659. HookSwitchState = PHSS_OFFHOOK_SPEAKER_ONLY;
  3660. break;
  3661. case PHONEHOOKSWITCHMODE_MICSPEAKER:
  3662. HookSwitchState = PHSS_OFFHOOK;
  3663. break;
  3664. default:
  3665. LOG((TL_ERROR, "HandlePhoneStateMessage - bad HookSwitchMode"));
  3666. pCPhone->Release();
  3667. return E_FAIL;
  3668. }
  3669. CPhoneEvent::FireEvent(
  3670. pCPhone,
  3671. PE_HOOKSWITCH,
  3672. (PHONE_BUTTON_STATE)0,
  3673. HookSwitchState,
  3674. PHSD_SPEAKERPHONE,
  3675. 0,
  3676. 0,
  3677. NULL,
  3678. NULL
  3679. );
  3680. break;
  3681. case PHONESTATE_DISPLAY:
  3682. CPhoneEvent::FireEvent(
  3683. pCPhone,
  3684. PE_DISPLAY,
  3685. (PHONE_BUTTON_STATE)0,
  3686. (PHONE_HOOK_SWITCH_STATE)0,
  3687. (PHONE_HOOK_SWITCH_DEVICE)0,
  3688. 0,
  3689. 0,
  3690. NULL,
  3691. NULL
  3692. );
  3693. break;
  3694. default:
  3695. LOG((TL_INFO, "HandlePhoneStateMessage - PHONE_STATE %lx event not handled", pParams->Param1));
  3696. }
  3697. pCPhone->Release();
  3698. LOG((TL_TRACE, "HandlePhoneStateMessage - exit"));
  3699. return S_OK;
  3700. }
  3701. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3702. //
  3703. // HandlePhoneCloseMessage
  3704. //
  3705. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3706. HRESULT HandlePhoneCloseMessage( PASYNCEVENTMSG pParams )
  3707. {
  3708. LOG((TL_TRACE, "HandlePhoneCloseMessage - enter"));
  3709. CPhone * pCPhone;
  3710. if (!FindPhoneObject((HPHONE)pParams->hDevice, &pCPhone))
  3711. {
  3712. LOG((TL_TRACE, "HandlePhoneCloseMessage - bad phone handle"));
  3713. return E_FAIL;
  3714. }
  3715. pCPhone->ForceClose();
  3716. pCPhone->Release();
  3717. LOG((TL_TRACE, "HandlePhoneCloseMessage - exit"));
  3718. return S_OK;
  3719. }
  3720. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3721. //
  3722. // ForceClose
  3723. //
  3724. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3725. void CPhone::ForceClose()
  3726. {
  3727. Lock();
  3728. //
  3729. // If phone isn't open then get out of here
  3730. //
  3731. if ( m_hPhone == NULL )
  3732. {
  3733. Unlock();
  3734. return;
  3735. }
  3736. Unlock();
  3737. //
  3738. // Close the phone
  3739. //
  3740. Close();
  3741. //
  3742. // Fire a PE_CLOSE event
  3743. //
  3744. CPhoneEvent::FireEvent(
  3745. this,
  3746. PE_CLOSE,
  3747. (PHONE_BUTTON_STATE)0,
  3748. (PHONE_HOOK_SWITCH_STATE)0,
  3749. (PHONE_HOOK_SWITCH_DEVICE)0,
  3750. 0,
  3751. 0,
  3752. NULL,
  3753. NULL
  3754. );
  3755. }
  3756. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3757. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3758. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3759. //
  3760. // ITAutomatedPhoneControl implementation
  3761. //
  3762. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3763. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3764. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3765. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3766. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3767. //
  3768. // Automation_CallState
  3769. //
  3770. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3771. void CPhone::Automation_CallState( ITCallInfo * pCall, CALL_STATE cs, CALL_STATE_EVENT_CAUSE cause )
  3772. {
  3773. LOG((TL_TRACE, "Automation_CallState - enter"));
  3774. EnterCriticalSection(&m_csAutomatedPhoneState);
  3775. LOG((TL_INFO, "Automation_CallState - phone[%p]",
  3776. this));
  3777. LOG((TL_INFO, "Automation_CallState - selected call [%p]",
  3778. m_pCall));
  3779. LOG((TL_INFO, "Automation_CallState - current phone state [%d]",
  3780. m_AutomatedPhoneState));
  3781. LOG((TL_INFO, "Automation_CallState - phone control enabled [%s]",
  3782. m_fPhoneHandlingEnabled ? "TRUE" : "FALSE"));
  3783. LOG((TL_INFO, "Automation_CallState - new call state [%d]",
  3784. cs));
  3785. if (m_fPhoneHandlingEnabled)
  3786. {
  3787. if ( pCall == m_pCall )
  3788. {
  3789. switch( cs )
  3790. {
  3791. case CS_IDLE:
  3792. LOG((TL_INFO, "Automation_CallState - CS_IDLE"));
  3793. break;
  3794. case CS_INPROGRESS:
  3795. LOG((TL_INFO, "Automation_CallState - CS_INPROGRESS"));
  3796. switch(m_AutomatedPhoneState)
  3797. {
  3798. case APS_ONHOOK_IDLE:
  3799. case APS_ONHOOK_RINGING_IN:
  3800. {
  3801. StartRinger( 0, 0 );
  3802. m_AutomatedPhoneState = APS_ONHOOK_RINGING_OUT;
  3803. }
  3804. break;
  3805. case APS_OFFHOOK_DIALTONE:
  3806. case APS_OFFHOOK_WARNING:
  3807. case APS_OFFHOOK_DIALING:
  3808. case APS_OFFHOOK_DEAD_LINE:
  3809. case APS_OFFHOOK_CALL_INIT:
  3810. case APS_OFFHOOK_BUSY_TONE:
  3811. {
  3812. StartTone( PT_RINGBACK, 0);
  3813. m_AutomatedPhoneState = APS_OFFHOOK_RINGING_OUT;
  3814. }
  3815. break;
  3816. }
  3817. break;
  3818. case CS_CONNECTED:
  3819. LOG((TL_INFO, "Automation_CallState - CS_CONNECTED"));
  3820. switch(m_AutomatedPhoneState)
  3821. {
  3822. case APS_OFFHOOK_CALL_INIT:
  3823. {
  3824. m_AutomatedPhoneState = APS_OFFHOOK_CONNECTED;
  3825. }
  3826. break;
  3827. case APS_OFFHOOK_RINGING_OUT:
  3828. {
  3829. // stop ringback
  3830. StopTone();
  3831. m_AutomatedPhoneState = APS_OFFHOOK_CONNECTED;
  3832. }
  3833. break;
  3834. case APS_ONHOOK_RINGING_OUT:
  3835. {
  3836. m_AutomatedPhoneState = APS_ONHOOK_CONNECTED;
  3837. }
  3838. break;
  3839. case APS_ONHOOK_IDLE:
  3840. {
  3841. StartRinger( 0, 0 );
  3842. m_AutomatedPhoneState = APS_ONHOOK_CONNECTED;
  3843. }
  3844. break;
  3845. case APS_ONHOOK_RINGING_IN:
  3846. {
  3847. m_AutomatedPhoneState = APS_ONHOOK_CONNECTED;
  3848. }
  3849. break;
  3850. case APS_OFFHOOK_DIALTONE:
  3851. case APS_OFFHOOK_WARNING:
  3852. case APS_OFFHOOK_DIALING:
  3853. case APS_OFFHOOK_DEAD_LINE:
  3854. case APS_OFFHOOK_BUSY_TONE:
  3855. {
  3856. // An app shouldn't do this to us, but stop the
  3857. // tone and move to the connected state
  3858. StopTone();
  3859. m_AutomatedPhoneState = APS_OFFHOOK_CONNECTED;
  3860. }
  3861. }
  3862. break;
  3863. case CS_DISCONNECTED:
  3864. LOG((TL_INFO, "Automation_CallState - CS_DISCONNECTED"));
  3865. switch(m_AutomatedPhoneState)
  3866. {
  3867. case APS_ONHOOK_RINGING_IN:
  3868. case APS_ONHOOK_RINGING_OUT:
  3869. case APS_ONHOOK_CONNECTED:
  3870. {
  3871. //
  3872. // Stop the ringer
  3873. //
  3874. if (m_fRinger == TRUE)
  3875. {
  3876. StopRinger();
  3877. }
  3878. // unselect the call
  3879. InternalUnselectCall( pCall );
  3880. m_AutomatedPhoneState = APS_ONHOOK_IDLE;
  3881. }
  3882. break;
  3883. case APS_ONHOOK_IDLE:
  3884. {
  3885. // unselect the call
  3886. InternalUnselectCall( pCall );
  3887. }
  3888. break;
  3889. case APS_OFFHOOK_DIALTONE:
  3890. case APS_OFFHOOK_DIALING:
  3891. case APS_OFFHOOK_RINGING_OUT:
  3892. case APS_OFFHOOK_CALL_INIT:
  3893. case APS_OFFHOOK_CONNECTED:
  3894. {
  3895. switch( cause )
  3896. {
  3897. case CEC_DISCONNECT_BUSY:
  3898. {
  3899. // start busy tone
  3900. StartTone( PT_BUSY, 0 );
  3901. m_AutomatedPhoneState = APS_OFFHOOK_BUSY_TONE;
  3902. }
  3903. break;
  3904. case CEC_DISCONNECT_NORMAL:
  3905. {
  3906. // stop any playing tone
  3907. StopTone();
  3908. m_AutomatedPhoneState = APS_OFFHOOK_DEAD_LINE;
  3909. }
  3910. break;
  3911. default:
  3912. {
  3913. // start error tone
  3914. StartTone( PT_ERRORTONE, 0 );
  3915. m_AutomatedPhoneState = APS_OFFHOOK_WARNING;
  3916. }
  3917. }
  3918. // unselect the call
  3919. InternalUnselectCall( pCall );
  3920. }
  3921. break;
  3922. }
  3923. break;
  3924. case CS_OFFERING:
  3925. LOG((TL_INFO, "Automation_CallState - CS_OFFERING"));
  3926. switch(m_AutomatedPhoneState)
  3927. {
  3928. case APS_ONHOOK_IDLE:
  3929. case APS_ONHOOK_RINGING_OUT:
  3930. {
  3931. StartRinger( 0, 0 );
  3932. m_AutomatedPhoneState = APS_ONHOOK_RINGING_IN;
  3933. }
  3934. break;
  3935. case APS_OFFHOOK_DIALTONE:
  3936. case APS_OFFHOOK_WARNING:
  3937. case APS_OFFHOOK_DIALING:
  3938. case APS_OFFHOOK_DEAD_LINE:
  3939. case APS_OFFHOOK_CALL_INIT:
  3940. case APS_OFFHOOK_BUSY_TONE:
  3941. {
  3942. StopTone();
  3943. ITBasicCallControl * pCallBCC;
  3944. ITCallInfo * pCall;
  3945. HRESULT hr;
  3946. pCall = m_pCall;
  3947. pCall->AddRef();
  3948. hr = pCall->QueryInterface( IID_ITBasicCallControl,
  3949. (void **) & pCallBCC );
  3950. if ( SUCCEEDED(hr) )
  3951. {
  3952. LeaveCriticalSection(&m_csAutomatedPhoneState);
  3953. hr = pCallBCC->Answer();
  3954. pCallBCC->Release();
  3955. if ( FAILED(hr) )
  3956. {
  3957. LOG((TL_ERROR, "Automation_CallState - Answer failed %08x", hr ));
  3958. }
  3959. else
  3960. {
  3961. CPhoneEvent::FireEvent(
  3962. this,
  3963. PE_ANSWER,
  3964. (PHONE_BUTTON_STATE)0,
  3965. (PHONE_HOOK_SWITCH_STATE)0,
  3966. (PHONE_HOOK_SWITCH_DEVICE)0,
  3967. 0,
  3968. 0,
  3969. NULL,
  3970. pCall
  3971. );
  3972. }
  3973. pCall->Release();
  3974. EnterCriticalSection(&m_csAutomatedPhoneState);
  3975. }
  3976. m_AutomatedPhoneState = APS_OFFHOOK_CALL_INIT;
  3977. }
  3978. break;
  3979. }
  3980. break;
  3981. case CS_HOLD:
  3982. LOG((TL_INFO, "Automation_CallState - CS_HOLD"));
  3983. break;
  3984. case CS_QUEUED:
  3985. LOG((TL_INFO, "Automation_CallState - CS_QUEUED"));
  3986. break;
  3987. }
  3988. }
  3989. } //m_fPhoneHandlingEnabled
  3990. LOG((TL_INFO, "Automation_CallState - new phone state [%d]",
  3991. m_AutomatedPhoneState));
  3992. LeaveCriticalSection(&m_csAutomatedPhoneState);
  3993. LOG((TL_TRACE, "Automation_CallState - exit"));
  3994. }
  3995. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  3996. //
  3997. // Automation_EndOfNumberTimeout
  3998. //
  3999. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4000. void CPhone::Automation_EndOfNumberTimeout()
  4001. {
  4002. LOG((TL_TRACE, "Automation_EndOfNumberTimeout - enter"));
  4003. EnterCriticalSection(&m_csAutomatedPhoneState);
  4004. if (m_fPhoneHandlingEnabled && m_dwAutoEndOfNumberTimeout)
  4005. {
  4006. if (m_hAutoEndOfNumberTimer) // make sure the timer hasn't been cancelled
  4007. // while waiting for the critical section
  4008. {
  4009. switch (m_AutomatedPhoneState)
  4010. {
  4011. case APS_OFFHOOK_DIALING:
  4012. {
  4013. //
  4014. // We need to fire and event with the number we have
  4015. // collected
  4016. //
  4017. CPhoneEvent::FireEvent(
  4018. this,
  4019. PE_NUMBERGATHERED,
  4020. (PHONE_BUTTON_STATE)0,
  4021. (PHONE_HOOK_SWITCH_STATE)0,
  4022. (PHONE_HOOK_SWITCH_DEVICE)0,
  4023. 0,
  4024. 0,
  4025. m_wszNumbersGathered,
  4026. NULL
  4027. );
  4028. m_AutomatedPhoneState = APS_OFFHOOK_CALL_INIT;
  4029. }
  4030. break;
  4031. }
  4032. }
  4033. } //m_fPhoneHandlingEnabled
  4034. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4035. LOG((TL_TRACE, "Automation_EndOfNumberTimeout - exit"));
  4036. }
  4037. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4038. //
  4039. // Automation_ButtonDown
  4040. //
  4041. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4042. void CPhone::Automation_ButtonDown( DWORD dwButtonId )
  4043. {
  4044. PHONE_BUTTON_MODE ButtonMode;
  4045. WCHAR wszNumber[11]; // enough to hold a big number in case dwButtonId is bad
  4046. HRESULT hr;
  4047. BOOL fResult;
  4048. LOG((TL_TRACE, "Automation_ButtonDown - enter"));
  4049. EnterCriticalSection(&m_csAutomatedPhoneState);
  4050. if (m_fPhoneHandlingEnabled)
  4051. {
  4052. hr = get_ButtonMode((LONG)dwButtonId, &ButtonMode);
  4053. if ( SUCCEEDED(hr) )
  4054. {
  4055. if (ButtonMode == PBM_KEYPAD)
  4056. {
  4057. switch (m_AutomatedPhoneState)
  4058. {
  4059. case APS_OFFHOOK_DIALTONE:
  4060. {
  4061. if (m_fAutoDialtone)
  4062. {
  4063. // Stop the dial tone
  4064. StopTone();
  4065. }
  4066. CPhoneEvent::FireEvent(
  4067. this,
  4068. PE_DIALING,
  4069. (PHONE_BUTTON_STATE)0,
  4070. (PHONE_HOOK_SWITCH_STATE)0,
  4071. (PHONE_HOOK_SWITCH_DEVICE)0,
  4072. 0,
  4073. 0,
  4074. NULL,
  4075. NULL
  4076. );
  4077. m_AutomatedPhoneState = APS_OFFHOOK_DIALING;
  4078. }
  4079. // Fall Thru
  4080. case APS_OFFHOOK_DIALING:
  4081. {
  4082. // Kill auto end of number timer
  4083. if (m_hAutoEndOfNumberTimer)
  4084. {
  4085. DeleteTimerQueueTimer(m_hTimerQueue,
  4086. m_hAutoEndOfNumberTimer,
  4087. m_hTimerEvent // non-blocking
  4088. );
  4089. m_hAutoEndOfNumberTimer = NULL;
  4090. }
  4091. if ( dwButtonId <= 10 ) // digit key
  4092. {
  4093. //
  4094. // We have a dialed digit. Append it to the phone
  4095. // number we have so far.
  4096. //
  4097. if ( dwButtonId == 10) // star
  4098. {
  4099. wsprintfW(wszNumber, L"*");
  4100. }
  4101. else // regular digit
  4102. {
  4103. wsprintfW(wszNumber, L"%d", dwButtonId);
  4104. }
  4105. if ( (lstrlenW(m_wszNumbersGathered) + lstrlenW(wszNumber)) < APC_MAX_NUMBERS_GATHERED )
  4106. {
  4107. lstrcatW(m_wszNumbersGathered, wszNumber);
  4108. }
  4109. LOG((TL_INFO, "Automation_ButtonDown - '%s'", wszNumber));
  4110. }
  4111. else if ( dwButtonId == 11 ) // pound key
  4112. {
  4113. LOG((TL_INFO, "Automation_ButtonDown - '#'"));
  4114. // Kill auto end of number timer
  4115. if (m_hAutoEndOfNumberTimer)
  4116. {
  4117. DeleteTimerQueueTimer(m_hTimerQueue,
  4118. m_hAutoEndOfNumberTimer,
  4119. m_hTimerEvent // non-blocking
  4120. );
  4121. m_hAutoEndOfNumberTimer = NULL;
  4122. }
  4123. //
  4124. // We have dialed a #. Send a number gathered event
  4125. //
  4126. CPhoneEvent::FireEvent(
  4127. this,
  4128. PE_NUMBERGATHERED,
  4129. (PHONE_BUTTON_STATE)0,
  4130. (PHONE_HOOK_SWITCH_STATE)0,
  4131. (PHONE_HOOK_SWITCH_DEVICE)0,
  4132. 0,
  4133. 0,
  4134. m_wszNumbersGathered,
  4135. NULL
  4136. );
  4137. m_AutomatedPhoneState = APS_OFFHOOK_CALL_INIT;
  4138. }
  4139. }
  4140. // Fall Thru
  4141. case APS_OFFHOOK_WARNING:
  4142. case APS_OFFHOOK_DEAD_LINE:
  4143. case APS_OFFHOOK_CALL_INIT:
  4144. case APS_OFFHOOK_CONNECTED:
  4145. case APS_OFFHOOK_BUSY_TONE:
  4146. case APS_OFFHOOK_RINGING_OUT:
  4147. {
  4148. if (m_fAutoKeypadTones)
  4149. {
  4150. // Kill DTMF timer
  4151. if (m_hDTMFTimer)
  4152. {
  4153. DeleteTimerQueueTimer(m_hTimerQueue,
  4154. m_hDTMFTimer,
  4155. INVALID_HANDLE_VALUE // blocking
  4156. );
  4157. m_hDTMFTimer = NULL;
  4158. }
  4159. // Stop the old DTMF tone
  4160. if (m_DTMF != PT_SILENCE)
  4161. {
  4162. m_WavePlayer.StopTone( (long) m_DTMF);
  4163. }
  4164. // Play the DTMF tone
  4165. m_WavePlayer.StartTone( (long) dwButtonId );
  4166. m_DTMF = (PHONE_TONE) dwButtonId;
  4167. m_dwDTMFStart = GetTickCount();
  4168. }
  4169. }
  4170. break;
  4171. }
  4172. }
  4173. else if ( ButtonMode == PBM_FEATURE )
  4174. {
  4175. PHONE_BUTTON_FUNCTION ButtonFunction;
  4176. hr = get_ButtonFunction((LONG)dwButtonId, &ButtonFunction);
  4177. if ( SUCCEEDED(hr) )
  4178. {
  4179. switch (ButtonFunction)
  4180. {
  4181. case PBF_VOLUMEUP:
  4182. {
  4183. DWORD dwVolume;
  4184. LOG((TL_INFO, "Automation_ButtonDown - VOLUMEUP"));
  4185. if (m_fAutoVolumeControl)
  4186. {
  4187. // Kill volume timer
  4188. if (m_hVolumeTimer)
  4189. {
  4190. DeleteTimerQueueTimer(m_hTimerQueue,
  4191. m_hVolumeTimer,
  4192. INVALID_HANDLE_VALUE // blocking
  4193. );
  4194. m_hVolumeTimer = NULL;
  4195. }
  4196. hr = m_WavePlayer.GetVolume( &dwVolume );
  4197. if ( SUCCEEDED(hr) )
  4198. {
  4199. dwVolume += m_dwAutoVolumeControlStep;
  4200. if (dwVolume > 0xFFFF) dwVolume = 0xFFFF;
  4201. hr = m_WavePlayer.SetVolume( dwVolume );
  4202. if ( SUCCEEDED(hr) )
  4203. {
  4204. LOG((TL_INFO, "Automation_ButtonDown - Volume: %d", dwVolume));
  4205. m_fVolumeUp = TRUE;
  4206. fResult = CreateTimerQueueTimer(&m_hVolumeTimer,
  4207. m_hTimerQueue,
  4208. &CPhone::VolumeTimerCallback,
  4209. (PVOID)this,
  4210. max(m_dwAutoVolumeControlRepeatDelay,m_dwAutoVolumeControlRepeatPeriod),
  4211. m_dwAutoVolumeControlRepeatPeriod,
  4212. WT_EXECUTEINIOTHREAD
  4213. );
  4214. if (fResult == FALSE)
  4215. {
  4216. // CreateTimerQueueTimer failed, not much to do but log the error
  4217. LOG((TL_ERROR, "Automation_ButtonDown - CreateTimerQueueTimer failed - %lx", GetLastError()));
  4218. }
  4219. }
  4220. }
  4221. }
  4222. }
  4223. break;
  4224. case PBF_VOLUMEDOWN:
  4225. {
  4226. DWORD dwVolume;
  4227. LOG((TL_INFO, "Automation_ButtonDown - VOLUMEDOWN"));
  4228. if (m_fAutoVolumeControl)
  4229. {
  4230. // Kill volume timer
  4231. if (m_hVolumeTimer)
  4232. {
  4233. DeleteTimerQueueTimer(m_hTimerQueue,
  4234. m_hVolumeTimer,
  4235. INVALID_HANDLE_VALUE // blocking
  4236. );
  4237. m_hVolumeTimer = NULL;
  4238. }
  4239. hr = m_WavePlayer.GetVolume( &dwVolume );
  4240. if ( SUCCEEDED(hr) )
  4241. {
  4242. dwVolume -= m_dwAutoVolumeControlStep;
  4243. if (dwVolume > 0xFFFF) dwVolume = 0x0000;
  4244. hr = m_WavePlayer.SetVolume( dwVolume );
  4245. if ( SUCCEEDED(hr) )
  4246. {
  4247. LOG((TL_INFO, "Automation_ButtonDown - Volume: %d", dwVolume));
  4248. m_fVolumeUp = FALSE;
  4249. fResult = CreateTimerQueueTimer(&m_hVolumeTimer,
  4250. m_hTimerQueue,
  4251. &CPhone::VolumeTimerCallback,
  4252. (PVOID)this,
  4253. max(m_dwAutoVolumeControlRepeatDelay,m_dwAutoVolumeControlRepeatPeriod),
  4254. m_dwAutoVolumeControlRepeatPeriod,
  4255. WT_EXECUTEINIOTHREAD
  4256. );
  4257. if (fResult == FALSE)
  4258. {
  4259. // CreateTimerQueueTimer failed, not much to do but log the error
  4260. LOG((TL_ERROR, "Automation_ButtonDown - CreateTimerQueueTimer failed - %lx", GetLastError()));
  4261. }
  4262. }
  4263. }
  4264. }
  4265. }
  4266. break;
  4267. case PBF_SEND:
  4268. {
  4269. LOG((TL_INFO, "Automation_ButtonDown - PBF_SEND"));
  4270. switch (m_AutomatedPhoneState)
  4271. {
  4272. case APS_OFFHOOK_DIALING:
  4273. {
  4274. // Kill auto end of number timer
  4275. if (m_hAutoEndOfNumberTimer)
  4276. {
  4277. DeleteTimerQueueTimer(m_hTimerQueue,
  4278. m_hAutoEndOfNumberTimer,
  4279. m_hTimerEvent // non-blocking
  4280. );
  4281. m_hAutoEndOfNumberTimer = NULL;
  4282. }
  4283. //
  4284. // We have pressed send. Send a number gathered event.
  4285. //
  4286. CPhoneEvent::FireEvent(
  4287. this,
  4288. PE_NUMBERGATHERED,
  4289. (PHONE_BUTTON_STATE)0,
  4290. (PHONE_HOOK_SWITCH_STATE)0,
  4291. (PHONE_HOOK_SWITCH_DEVICE)0,
  4292. 0,
  4293. 0,
  4294. m_wszNumbersGathered,
  4295. NULL
  4296. );
  4297. m_AutomatedPhoneState = APS_OFFHOOK_CALL_INIT;
  4298. }
  4299. break;
  4300. } // switch (m_AutomatedPhoneState)
  4301. }
  4302. break;
  4303. } // switch (ButtonFunction)
  4304. }
  4305. }
  4306. }
  4307. } //m_fPhoneHandlingEnabled
  4308. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4309. LOG((TL_TRACE, "Automation_ButtonDown - exit"));
  4310. }
  4311. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4312. //
  4313. //
  4314. //
  4315. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4316. void CPhone::Automation_ButtonUp( DWORD dwButtonId )
  4317. {
  4318. PHONE_BUTTON_MODE ButtonMode;
  4319. HRESULT hr;
  4320. BOOL fResult;
  4321. LOG((TL_TRACE, "Automation_ButtonUp - enter"));
  4322. EnterCriticalSection(&m_csAutomatedPhoneState);
  4323. if (m_fPhoneHandlingEnabled)
  4324. {
  4325. hr = get_ButtonMode((LONG)dwButtonId, &ButtonMode);
  4326. if ( SUCCEEDED(hr) )
  4327. {
  4328. if ( ButtonMode == PBM_KEYPAD )
  4329. {
  4330. switch (m_AutomatedPhoneState)
  4331. {
  4332. case APS_OFFHOOK_DIALING:
  4333. {
  4334. if ( dwButtonId <= 10 ) // digit key
  4335. {
  4336. if (m_dwAutoEndOfNumberTimeout)
  4337. {
  4338. fResult = CreateTimerQueueTimer(&m_hAutoEndOfNumberTimer,
  4339. m_hTimerQueue,
  4340. &CPhone::AutoEndOfNumberTimerCallback,
  4341. (PVOID)this,
  4342. m_dwAutoEndOfNumberTimeout,
  4343. 0,
  4344. WT_EXECUTEINIOTHREAD
  4345. );
  4346. if (fResult == FALSE)
  4347. {
  4348. // CreateTimerQueueTimer failed, not much to do but log the error
  4349. LOG((TL_ERROR, "Automation_ButtonUp - CreateTimerQueueTimer failed - %lx", GetLastError()));
  4350. }
  4351. }
  4352. }
  4353. }
  4354. // Fall Thru
  4355. case APS_OFFHOOK_CONNECTED:
  4356. case APS_OFFHOOK_CALL_INIT:
  4357. case APS_OFFHOOK_DEAD_LINE:
  4358. case APS_OFFHOOK_DIALTONE:
  4359. case APS_OFFHOOK_WARNING:
  4360. case APS_OFFHOOK_BUSY_TONE:
  4361. case APS_OFFHOOK_RINGING_OUT:
  4362. {
  4363. if (m_fAutoKeypadTones)
  4364. {
  4365. if ((PHONE_TONE)dwButtonId == m_DTMF)
  4366. {
  4367. DWORD dwElapsed = GetTickCount() - m_dwDTMFStart;
  4368. if ( dwElapsed > m_dwAutoKeypadTonesMinimumDuration )
  4369. {
  4370. // Stop the DTMF tone
  4371. m_WavePlayer.StopTone( (long) m_DTMF);
  4372. m_DTMF = PT_SILENCE;
  4373. }
  4374. else
  4375. {
  4376. // Limit the DTMF tone
  4377. fResult = CreateTimerQueueTimer(&m_hDTMFTimer,
  4378. m_hTimerQueue,
  4379. &CPhone::DTMFTimerCallback,
  4380. (PVOID)this,
  4381. m_dwAutoKeypadTonesMinimumDuration - dwElapsed,
  4382. 0,
  4383. WT_EXECUTEINIOTHREAD
  4384. );
  4385. if (fResult == FALSE)
  4386. {
  4387. // CreateTimerQueueTimer failed, not much to do but log the error
  4388. LOG((TL_ERROR, "Automation_ButtonUp - CreateTimerQueueTimer failed - %lx", GetLastError()));
  4389. }
  4390. }
  4391. }
  4392. }
  4393. }
  4394. break;
  4395. }
  4396. }
  4397. else if ( ButtonMode == PBM_FEATURE )
  4398. {
  4399. PHONE_BUTTON_FUNCTION ButtonFunction;
  4400. hr = get_ButtonFunction((LONG)dwButtonId, &ButtonFunction);
  4401. if ( SUCCEEDED(hr) )
  4402. {
  4403. switch (ButtonFunction)
  4404. {
  4405. case PBF_VOLUMEUP:
  4406. {
  4407. DWORD dwVolume;
  4408. LOG((TL_INFO, "Automation_ButtonUp - VOLUMEUP"));
  4409. if (m_fAutoVolumeControl)
  4410. {
  4411. // Kill volume timer
  4412. if (m_hVolumeTimer)
  4413. {
  4414. DeleteTimerQueueTimer(m_hTimerQueue,
  4415. m_hVolumeTimer,
  4416. INVALID_HANDLE_VALUE // blocking
  4417. );
  4418. m_hVolumeTimer = NULL;
  4419. }
  4420. }
  4421. }
  4422. break;
  4423. case PBF_VOLUMEDOWN:
  4424. {
  4425. DWORD dwVolume;
  4426. LOG((TL_INFO, "Automation_ButtonUp - VOLUMEDOWN"));
  4427. if (m_fAutoVolumeControl)
  4428. {
  4429. // Kill volume timer
  4430. if (m_hVolumeTimer)
  4431. {
  4432. DeleteTimerQueueTimer(m_hTimerQueue,
  4433. m_hVolumeTimer,
  4434. INVALID_HANDLE_VALUE // blocking
  4435. );
  4436. m_hVolumeTimer = NULL;
  4437. }
  4438. }
  4439. }
  4440. break;
  4441. }
  4442. }
  4443. }
  4444. }
  4445. } //m_fPhoneHandlingEnabled
  4446. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4447. LOG((TL_TRACE, "Automation_ButtonUp - exit"));
  4448. }
  4449. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4450. //
  4451. //
  4452. //
  4453. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4454. void CPhone::Automation_OnHook( PHONE_HOOK_SWITCH_DEVICE phsd )
  4455. {
  4456. LOG((TL_TRACE, "Automation_OnHook - enter"));
  4457. EnterCriticalSection(&m_csAutomatedPhoneState);
  4458. if (m_fPhoneHandlingEnabled)
  4459. {
  4460. if (m_dwOffHookCount > 0) m_dwOffHookCount--;
  4461. if (m_dwOffHookCount == 0)
  4462. {
  4463. switch (m_AutomatedPhoneState)
  4464. {
  4465. case APS_ONHOOK_IDLE:
  4466. case APS_ONHOOK_RINGING_IN:
  4467. case APS_ONHOOK_CONNECTED:
  4468. case APS_ONHOOK_RINGING_OUT:
  4469. {
  4470. //
  4471. // Something is wrong!! Most likely this phone was offhook on startup, but told
  4472. // us it was onhook. Lets clean up the best we can
  4473. //
  4474. LOG((TL_WARN, "Automation_OnHook - Phone is already in onhook state!" ));
  4475. if (m_fAutoStopTonesOnOnHook)
  4476. {
  4477. // Kill DTMF timer
  4478. if (m_hDTMFTimer)
  4479. {
  4480. DeleteTimerQueueTimer(m_hTimerQueue,
  4481. m_hDTMFTimer,
  4482. INVALID_HANDLE_VALUE // blocking
  4483. );
  4484. m_hDTMFTimer = NULL;
  4485. }
  4486. // Stop any DTMF that may be playing
  4487. if (m_DTMF != PT_SILENCE)
  4488. {
  4489. // Stop the DTMF tone
  4490. m_WavePlayer.StopTone( (long) m_DTMF );
  4491. m_DTMF = PT_SILENCE;
  4492. }
  4493. // Stop any tone that may be playing
  4494. StopTone();
  4495. }
  4496. m_AutomatedPhoneState = APS_ONHOOK_IDLE;
  4497. }
  4498. break;
  4499. case APS_OFFHOOK_DIALTONE:
  4500. case APS_OFFHOOK_WARNING:
  4501. case APS_OFFHOOK_DEAD_LINE:
  4502. case APS_OFFHOOK_DIALING:
  4503. case APS_OFFHOOK_CONNECTED:
  4504. case APS_OFFHOOK_CALL_INIT:
  4505. case APS_OFFHOOK_BUSY_TONE:
  4506. case APS_OFFHOOK_RINGING_OUT:
  4507. {
  4508. if (m_fAutoStopTonesOnOnHook)
  4509. {
  4510. // Kill DTMF timer
  4511. if (m_hDTMFTimer)
  4512. {
  4513. DeleteTimerQueueTimer(m_hTimerQueue,
  4514. m_hDTMFTimer,
  4515. INVALID_HANDLE_VALUE // blocking
  4516. );
  4517. m_hDTMFTimer = NULL;
  4518. }
  4519. // Stop any DTMF that may be playing
  4520. if (m_DTMF != PT_SILENCE)
  4521. {
  4522. // Stop the DTMF tone
  4523. m_WavePlayer.StopTone( (long) m_DTMF );
  4524. m_DTMF = PT_SILENCE;
  4525. }
  4526. // Stop any tone that may be playing
  4527. StopTone();
  4528. }
  4529. // Kill automated end of number timer
  4530. if (m_hAutoEndOfNumberTimer)
  4531. {
  4532. DeleteTimerQueueTimer(m_hTimerQueue,
  4533. m_hAutoEndOfNumberTimer,
  4534. m_hTimerEvent // non-blocking
  4535. );
  4536. m_hAutoEndOfNumberTimer = NULL;
  4537. }
  4538. if (m_pCall)
  4539. {
  4540. CALL_STATE cs;
  4541. HRESULT hr;
  4542. hr = m_pCall->get_CallState( &cs );
  4543. if ( SUCCEEDED(hr) )
  4544. {
  4545. if ( cs != CS_DISCONNECTED )
  4546. {
  4547. ITBasicCallControl * pCallBCC;
  4548. ITCallInfo * pCall;
  4549. pCall = m_pCall;
  4550. pCall->AddRef();
  4551. hr = pCall->QueryInterface( IID_ITBasicCallControl,
  4552. (void **) & pCallBCC );
  4553. if ( SUCCEEDED(hr) )
  4554. {
  4555. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4556. hr = pCallBCC->Disconnect( DC_NORMAL );
  4557. pCallBCC->Release();
  4558. if ( FAILED(hr) )
  4559. {
  4560. LOG((TL_ERROR, "Automation_OnHook - Disconnect failed %08x", hr ));
  4561. }
  4562. else
  4563. {
  4564. CPhoneEvent::FireEvent(
  4565. this,
  4566. PE_DISCONNECT,
  4567. (PHONE_BUTTON_STATE)0,
  4568. (PHONE_HOOK_SWITCH_STATE)0,
  4569. (PHONE_HOOK_SWITCH_DEVICE)0,
  4570. 0,
  4571. 0,
  4572. NULL,
  4573. pCall
  4574. );
  4575. }
  4576. pCall->Release();
  4577. EnterCriticalSection(&m_csAutomatedPhoneState);
  4578. }
  4579. }
  4580. else
  4581. {
  4582. // If we are already disconnected we can unselect the call, otherwise
  4583. // the CS_DISCONNECT event will do it for us.
  4584. InternalUnselectCall( m_pCall );
  4585. }
  4586. }
  4587. }
  4588. m_AutomatedPhoneState = APS_ONHOOK_IDLE;
  4589. }
  4590. break;
  4591. }
  4592. }
  4593. } //m_fPhoneHandlingEnabled
  4594. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4595. LOG((TL_TRACE, "Automation_OnHook - exit"));
  4596. }
  4597. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4598. //
  4599. //
  4600. //
  4601. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4602. void CPhone::Automation_OffHook( PHONE_HOOK_SWITCH_DEVICE phsd )
  4603. {
  4604. LOG((TL_TRACE, "Automation_OffHook - enter"));
  4605. EnterCriticalSection(&m_csAutomatedPhoneState);
  4606. if (m_fPhoneHandlingEnabled)
  4607. {
  4608. m_dwOffHookCount++;
  4609. // We just went offhook
  4610. if (m_dwOffHookCount == 1)
  4611. {
  4612. switch (m_AutomatedPhoneState)
  4613. {
  4614. case APS_ONHOOK_IDLE:
  4615. {
  4616. if (m_fAutoStopRingOnOffHook)
  4617. {
  4618. // Stop incoming ring
  4619. StopRinger();
  4620. }
  4621. if (m_fAutoDialtone)
  4622. {
  4623. // Start the dialtone
  4624. StartTone( PT_NORMALDIALTONE, 0 );
  4625. }
  4626. // Clear the numbers gathered
  4627. lstrcpyW(m_wszNumbersGathered, L"");
  4628. m_AutomatedPhoneState = APS_OFFHOOK_DIALTONE;
  4629. }
  4630. break;
  4631. case APS_ONHOOK_RINGING_IN:
  4632. {
  4633. if (m_fAutoStopRingOnOffHook)
  4634. {
  4635. // Stop incoming ring
  4636. StopRinger();
  4637. }
  4638. if (m_pCall)
  4639. {
  4640. CALL_STATE cs;
  4641. HRESULT hr;
  4642. hr = m_pCall->get_CallState( &cs );
  4643. if ( SUCCEEDED(hr) )
  4644. {
  4645. if ( cs == CS_OFFERING )
  4646. {
  4647. ITBasicCallControl * pCallBCC;
  4648. ITCallInfo * pCall;
  4649. pCall = m_pCall;
  4650. pCall->AddRef();
  4651. hr = pCall->QueryInterface( IID_ITBasicCallControl,
  4652. (void **) & pCallBCC );
  4653. if ( SUCCEEDED(hr) )
  4654. {
  4655. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4656. hr = pCallBCC->Answer();
  4657. pCallBCC->Release();
  4658. if ( FAILED(hr) )
  4659. {
  4660. LOG((TL_ERROR, "Automation_OffHook - Answer failed %08x", hr ));
  4661. }
  4662. else
  4663. {
  4664. CPhoneEvent::FireEvent(
  4665. this,
  4666. PE_ANSWER,
  4667. (PHONE_BUTTON_STATE)0,
  4668. (PHONE_HOOK_SWITCH_STATE)0,
  4669. (PHONE_HOOK_SWITCH_DEVICE)0,
  4670. 0,
  4671. 0,
  4672. NULL,
  4673. pCall
  4674. );
  4675. }
  4676. pCall->Release();
  4677. EnterCriticalSection(&m_csAutomatedPhoneState);
  4678. }
  4679. }
  4680. }
  4681. }
  4682. m_AutomatedPhoneState = APS_OFFHOOK_CALL_INIT;
  4683. }
  4684. break;
  4685. case APS_ONHOOK_RINGING_OUT:
  4686. {
  4687. if (m_fAutoStopRingOnOffHook)
  4688. {
  4689. // Stop incoming ring
  4690. StopRinger();
  4691. }
  4692. if (m_pCall)
  4693. {
  4694. CALL_STATE cs;
  4695. HRESULT hr;
  4696. hr = m_pCall->get_CallState( &cs );
  4697. if ( SUCCEEDED(hr) )
  4698. {
  4699. switch( cs )
  4700. {
  4701. case CS_INPROGRESS:
  4702. {
  4703. StartTone( PT_RINGBACK, 0 );
  4704. m_AutomatedPhoneState = APS_OFFHOOK_RINGING_OUT;
  4705. }
  4706. break;
  4707. case CS_CONNECTED:
  4708. {
  4709. m_AutomatedPhoneState = APS_OFFHOOK_CONNECTED;
  4710. }
  4711. break;
  4712. }
  4713. }
  4714. }
  4715. }
  4716. break;
  4717. case APS_ONHOOK_CONNECTED:
  4718. {
  4719. if (m_fAutoStopRingOnOffHook)
  4720. {
  4721. // Stop incoming ring
  4722. StopRinger();
  4723. }
  4724. m_AutomatedPhoneState = APS_OFFHOOK_CONNECTED;
  4725. }
  4726. break;
  4727. }
  4728. }
  4729. } //m_fPhoneHandlingEnabled
  4730. LeaveCriticalSection(&m_csAutomatedPhoneState);
  4731. LOG((TL_TRACE, "Automation_OffHook - exit"));
  4732. }
  4733. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4734. //
  4735. //
  4736. //
  4737. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4738. VOID CALLBACK CPhone::ToneTimerCallback(
  4739. PVOID lpParameter,
  4740. BOOLEAN TimerOrWaitFired
  4741. )
  4742. {
  4743. CPhone * pCPhone = (CPhone *)(lpParameter);
  4744. STATICLOG((TL_TRACE, "ToneTimerCallback - enter"));
  4745. BOOL Stopped = TRUE;
  4746. if (pCPhone != NULL)
  4747. {
  4748. if (TryEnterCriticalSection( &pCPhone->m_csToneTimer ))
  4749. {
  4750. if (pCPhone->m_WavePlayer.PlayingTone( (long) pCPhone->m_Tone ))
  4751. {
  4752. //
  4753. // Tone was on
  4754. //
  4755. pCPhone->m_WavePlayer.StopTone( (long) pCPhone->m_Tone );
  4756. if (pCPhone->m_dwTonePeriodOn > 0)
  4757. {
  4758. //
  4759. // Tone is periodic
  4760. //
  4761. if (pCPhone->m_dwToneDuration > 0)
  4762. {
  4763. //
  4764. // Tone is periodic with limited duration
  4765. //
  4766. if ( pCPhone->m_dwToneDuration > pCPhone->m_dwTonePeriodOn )
  4767. {
  4768. pCPhone->m_dwToneDuration -= pCPhone->m_dwTonePeriodOn;
  4769. if ( pCPhone->m_dwTonePeriodOff < pCPhone->m_dwToneDuration )
  4770. {
  4771. //
  4772. // Remaining duration is greater than the period
  4773. //
  4774. ChangeTimerQueueTimer(
  4775. pCPhone->m_hTimerQueue,
  4776. pCPhone->m_hToneTimer,
  4777. pCPhone->m_dwTonePeriodOff,
  4778. TIMER_KEEP_ALIVE
  4779. );
  4780. Stopped = FALSE;
  4781. }
  4782. else
  4783. {
  4784. //
  4785. // Remaining duration is less than the period
  4786. //
  4787. ChangeTimerQueueTimer(
  4788. pCPhone->m_hTimerQueue,
  4789. pCPhone->m_hToneTimer,
  4790. pCPhone->m_dwToneDuration,
  4791. 0
  4792. );
  4793. Stopped = FALSE;
  4794. }
  4795. }
  4796. }
  4797. else
  4798. {
  4799. //
  4800. // Tone is periodic with infinite duration
  4801. //
  4802. ChangeTimerQueueTimer(
  4803. pCPhone->m_hTimerQueue,
  4804. pCPhone->m_hToneTimer,
  4805. pCPhone->m_dwTonePeriodOff,
  4806. TIMER_KEEP_ALIVE
  4807. );
  4808. Stopped = FALSE;
  4809. }
  4810. }
  4811. }
  4812. else
  4813. {
  4814. //
  4815. // Tone was off
  4816. //
  4817. if (pCPhone->m_dwTonePeriodOff > 0)
  4818. {
  4819. //
  4820. // Tone is periodic
  4821. //
  4822. if (pCPhone->m_dwToneDuration > 0)
  4823. {
  4824. //
  4825. // Tone is periodic with limited duration
  4826. //
  4827. if ( pCPhone->m_dwToneDuration > pCPhone->m_dwTonePeriodOff )
  4828. {
  4829. pCPhone->m_dwToneDuration -= pCPhone->m_dwTonePeriodOff;
  4830. if ( pCPhone->m_dwTonePeriodOn < pCPhone->m_dwToneDuration )
  4831. {
  4832. //
  4833. // Remaining duration is greater than the period
  4834. //
  4835. pCPhone->m_WavePlayer.StartTone( (long) pCPhone->m_Tone );
  4836. ChangeTimerQueueTimer(
  4837. pCPhone->m_hTimerQueue,
  4838. pCPhone->m_hToneTimer,
  4839. pCPhone->m_dwTonePeriodOn,
  4840. TIMER_KEEP_ALIVE
  4841. );
  4842. Stopped = FALSE;
  4843. }
  4844. else
  4845. {
  4846. //
  4847. // Remaining duration is less than the period
  4848. //
  4849. pCPhone->m_WavePlayer.StartTone( (long) pCPhone->m_Tone );
  4850. ChangeTimerQueueTimer(
  4851. pCPhone->m_hTimerQueue,
  4852. pCPhone->m_hToneTimer,
  4853. pCPhone->m_dwToneDuration,
  4854. 0
  4855. );
  4856. Stopped = FALSE;
  4857. }
  4858. }
  4859. }
  4860. else
  4861. {
  4862. //
  4863. // Tone is periodic with infinite duration
  4864. //
  4865. pCPhone->m_WavePlayer.StartTone( (long) pCPhone->m_Tone );
  4866. ChangeTimerQueueTimer(
  4867. pCPhone->m_hTimerQueue,
  4868. pCPhone->m_hToneTimer,
  4869. pCPhone->m_dwTonePeriodOn,
  4870. TIMER_KEEP_ALIVE
  4871. );
  4872. Stopped = FALSE;
  4873. }
  4874. }
  4875. }
  4876. if (Stopped) pCPhone->m_Tone = PT_SILENCE;
  4877. LeaveCriticalSection( &pCPhone->m_csToneTimer );
  4878. }
  4879. }
  4880. STATICLOG((TL_TRACE, "ToneTimerCallback - exit"));
  4881. }
  4882. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4883. //
  4884. //
  4885. //
  4886. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4887. VOID CALLBACK CPhone::DTMFTimerCallback(
  4888. PVOID lpParameter,
  4889. BOOLEAN TimerOrWaitFired
  4890. )
  4891. {
  4892. CPhone * pCPhone = (CPhone *)(lpParameter);
  4893. STATICLOG((TL_TRACE, "DTMFTimerCallback - enter"));
  4894. if (pCPhone != NULL)
  4895. {
  4896. pCPhone->m_WavePlayer.StopTone( (long) pCPhone->m_DTMF );
  4897. pCPhone->m_DTMF = PT_SILENCE;
  4898. }
  4899. STATICLOG((TL_TRACE, "DTMFTimerCallback - exit"));
  4900. }
  4901. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4902. //
  4903. //
  4904. //
  4905. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4906. VOID CALLBACK CPhone::RingTimerCallback(
  4907. PVOID lpParameter,
  4908. BOOLEAN TimerOrWaitFired
  4909. )
  4910. {
  4911. HRESULT hr;
  4912. DWORD dwDummy;
  4913. DWORD dwVolume;
  4914. CPhone * pCPhone = (CPhone *)(lpParameter);
  4915. STATICLOG((TL_TRACE, "RingTimerCallback - enter"));
  4916. BOOL Stopped = TRUE;
  4917. if (pCPhone != NULL)
  4918. {
  4919. if ( TryEnterCriticalSection( &pCPhone->m_csRingTimer ))
  4920. {
  4921. if ( pCPhone->m_fUseWaveForRinger )
  4922. {
  4923. //
  4924. // Using wave player for ring
  4925. //
  4926. if ( pCPhone->m_dwRingDuration > 0 )
  4927. {
  4928. //
  4929. // Ring has a limited duration
  4930. //
  4931. if ( pCPhone->m_dwRingDuration > pCPhone->m_dwRingPeriod )
  4932. {
  4933. pCPhone->m_dwRingDuration -= pCPhone->m_dwRingPeriod;
  4934. if ( pCPhone->m_dwRingPeriod < pCPhone->m_dwRingDuration )
  4935. {
  4936. //
  4937. // Remaining duration is greater than period
  4938. //
  4939. hr = pCPhone->m_WavePlayer.StartRing();
  4940. Stopped = FALSE;
  4941. }
  4942. else
  4943. {
  4944. //
  4945. // Remaining duration is less than period
  4946. //
  4947. ChangeTimerQueueTimer(
  4948. pCPhone->m_hTimerQueue,
  4949. pCPhone->m_hRingTimer,
  4950. pCPhone->m_dwRingDuration,
  4951. 0
  4952. );
  4953. hr = pCPhone->m_WavePlayer.StartRing();
  4954. Stopped = FALSE;
  4955. }
  4956. }
  4957. }
  4958. else
  4959. {
  4960. //
  4961. // Ring has an infinite duration
  4962. //
  4963. hr = pCPhone->m_WavePlayer.StartRing();
  4964. Stopped = FALSE;
  4965. }
  4966. //
  4967. // Stop the ring if needed
  4968. //
  4969. if (Stopped)
  4970. {
  4971. hr = pCPhone->m_WavePlayer.StopRing();
  4972. }
  4973. }
  4974. else
  4975. {
  4976. //
  4977. // Using phone's ringer, duration must have elapsed because
  4978. // this is not periodic
  4979. //
  4980. hr = PhoneGetRing(pCPhone->m_hPhone, &dwDummy, &dwVolume);
  4981. if ( FAILED(hr) )
  4982. {
  4983. STATICLOG((TL_TRACE, "RingTimerCallback - PhoneGetRing failed - %lx", hr));
  4984. LeaveCriticalSection( &pCPhone->m_csRingTimer );
  4985. return;
  4986. }
  4987. hr = PhoneSetRing(pCPhone->m_hPhone, 0, dwVolume );
  4988. }
  4989. if (Stopped)
  4990. {
  4991. pCPhone->m_fRinger = FALSE;
  4992. }
  4993. LeaveCriticalSection( &pCPhone->m_csRingTimer );
  4994. }
  4995. }
  4996. STATICLOG((TL_TRACE, "RingTimerCallback - exit"));
  4997. }
  4998. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  4999. //
  5000. //
  5001. //
  5002. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5003. VOID CALLBACK CPhone::VolumeTimerCallback(
  5004. PVOID lpParameter,
  5005. BOOLEAN TimerOrWaitFired
  5006. )
  5007. {
  5008. HRESULT hr;
  5009. DWORD dwVolume;
  5010. CPhone * pCPhone = (CPhone *)(lpParameter);
  5011. STATICLOG((TL_TRACE, "VolumeTimerCallback - enter"));
  5012. if (pCPhone != NULL)
  5013. {
  5014. hr = pCPhone->m_WavePlayer.GetVolume( &dwVolume );
  5015. if ( SUCCEEDED(hr) )
  5016. {
  5017. if (pCPhone->m_fVolumeUp)
  5018. {
  5019. dwVolume += pCPhone->m_dwAutoVolumeControlStep;
  5020. if (dwVolume > 0xFFFF)
  5021. {
  5022. dwVolume = 0xFFFF;
  5023. }
  5024. }
  5025. else
  5026. {
  5027. dwVolume -= pCPhone->m_dwAutoVolumeControlStep;
  5028. if (dwVolume > 0xFFFF)
  5029. {
  5030. dwVolume = 0x0000;
  5031. }
  5032. }
  5033. hr = pCPhone->m_WavePlayer.SetVolume( dwVolume );
  5034. if ( SUCCEEDED(hr) )
  5035. {
  5036. STATICLOG((TL_INFO, "VolumeTimerCallback - Volume: %lx", dwVolume));
  5037. }
  5038. else
  5039. {
  5040. STATICLOG((TL_INFO, "VolumeTimerCallback - SetVolume failed - %lx", hr));
  5041. }
  5042. }
  5043. else
  5044. {
  5045. STATICLOG((TL_INFO, "VolumeTimerCallback - GetVolume failed - %lx", hr));
  5046. }
  5047. }
  5048. STATICLOG((TL_TRACE, "VolumeTimerCallback - exit"));
  5049. }
  5050. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5051. //
  5052. //
  5053. //
  5054. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5055. VOID CALLBACK CPhone::AutoEndOfNumberTimerCallback(
  5056. PVOID lpParameter,
  5057. BOOLEAN TimerOrWaitFired
  5058. )
  5059. {
  5060. HRESULT hr;
  5061. CPhone * pCPhone = (CPhone *)(lpParameter);
  5062. STATICLOG((TL_TRACE, "AutoEndOfNumberTimerCallback - enter"));
  5063. if (pCPhone != NULL)
  5064. {
  5065. pCPhone->Automation_EndOfNumberTimeout();
  5066. }
  5067. STATICLOG((TL_TRACE, "AutoEndOfNumberTimerCallback - exit"));
  5068. }
  5069. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5070. //
  5071. // GetPhoneWaveRenderID
  5072. //
  5073. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5074. HRESULT CPhone::GetPhoneWaveRenderID(DWORD * pdwWaveID)
  5075. {
  5076. T3PHONE t3Phone;
  5077. HRESULT hr;
  5078. LPVARSTRING pVarString = NULL;
  5079. DWORD dwPhoneWaveID;
  5080. //
  5081. // get wave device ids associated with this phone
  5082. // we need to open the phone device to do this
  5083. // Must use monitor privilege, because owner privilege open will
  5084. // fail if anyone happens to have the phone open as owner.
  5085. //
  5086. t3Phone.hPhone = NULL;
  5087. t3Phone.pPhone = this;
  5088. Lock();
  5089. hr = PhoneOpen(m_hPhoneApp,
  5090. m_dwDeviceID,
  5091. &t3Phone,
  5092. m_dwAPIVersion,
  5093. PHONEPRIVILEGE_MONITOR
  5094. );
  5095. if ( SUCCEEDED(hr) )
  5096. {
  5097. hr = PhoneGetID(
  5098. t3Phone.hPhone,
  5099. &pVarString,
  5100. L"wave/out"
  5101. );
  5102. if ( SUCCEEDED(hr) )
  5103. {
  5104. if (pVarString->dwStringSize == sizeof(DWORD))
  5105. {
  5106. CopyMemory(
  5107. pdwWaveID,
  5108. ((LPBYTE)pVarString)+pVarString->dwStringOffset,
  5109. pVarString->dwStringSize
  5110. );
  5111. LOG((TL_INFO, "GetPhoneWaveRenderID - got phone wave "
  5112. "render id %d", *pdwWaveID ));
  5113. }
  5114. }
  5115. else
  5116. {
  5117. LOG((TL_ERROR, "GetPhoneRenderWaveID - PhoneGetID failed %08x", hr ));
  5118. }
  5119. if ( NULL != pVarString )
  5120. {
  5121. ClientFree( pVarString );
  5122. }
  5123. PhoneClose(t3Phone.hPhone);
  5124. }
  5125. else
  5126. {
  5127. LOG((TL_ERROR, "GetPhoneRenderWaveID - PhoneOpen failed %08x", hr ));
  5128. }
  5129. Unlock();
  5130. return hr;
  5131. }
  5132. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5133. //
  5134. //
  5135. //
  5136. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5137. void CPhone::OpenWaveDevice(
  5138. )
  5139. {
  5140. HRESULT hr;
  5141. LOG((TL_TRACE, "OpenWaveDevice - enter" ));
  5142. if (!m_WavePlayer.IsInitialized())
  5143. {
  5144. hr = m_WavePlayer.Initialize();
  5145. if ( FAILED(hr) )
  5146. {
  5147. LOG((TL_ERROR, "OpenWaveDevice - Initialize failed %08x", hr ));
  5148. return;
  5149. }
  5150. }
  5151. if (!m_WavePlayer.IsInUse())
  5152. {
  5153. if (m_fUseWaveForRinger)
  5154. {
  5155. hr = m_WavePlayer.OpenWaveDeviceForRing( WAVE_MAPPER );
  5156. if ( FAILED(hr) )
  5157. {
  5158. LOG((TL_ERROR, "OpenWaveDevice - OpenWaveDeviceForRing failed %08x", hr ));
  5159. }
  5160. }
  5161. long lWaveId;
  5162. hr = GetPhoneWaveRenderID( (DWORD *) & lWaveId );
  5163. if ( FAILED(hr) )
  5164. {
  5165. LOG((TL_ERROR, "OpenWaveDevice - GetPhoneWaveRenderID failed %08x", hr ));
  5166. return;
  5167. }
  5168. hr = m_WavePlayer.OpenWaveDeviceForTone( lWaveId );
  5169. if ( FAILED(hr) )
  5170. {
  5171. LOG((TL_ERROR, "OpenWaveDevice - OpenWaveDeviceForTone failed %08x", hr ));
  5172. }
  5173. hr = m_WavePlayer.OpenMixerDevice( lWaveId );
  5174. if ( FAILED(hr) )
  5175. {
  5176. LOG((TL_ERROR, "OpenWaveDevice - OpenMixerDevice failed %08x", hr ));
  5177. }
  5178. }
  5179. LOG((TL_TRACE, "OpenWaveDevice - exit" ));
  5180. }
  5181. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5182. //
  5183. //
  5184. //
  5185. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5186. void CPhone::CloseWaveDevice(
  5187. )
  5188. {
  5189. LOG((TL_TRACE, "CloseWaveDevice - enter" ));
  5190. if (m_WavePlayer.IsInUse())
  5191. {
  5192. if (m_fUseWaveForRinger)
  5193. {
  5194. m_WavePlayer.CloseWaveDeviceForRing();
  5195. }
  5196. m_WavePlayer.CloseWaveDeviceForTone();
  5197. m_WavePlayer.CloseMixerDevice();
  5198. }
  5199. LOG((TL_TRACE, "CloseWaveDevice - exit" ));
  5200. }
  5201. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5202. //
  5203. // ITAutomatedPhoneControlQI
  5204. // Don't give out the ITAutomatedPhoneControl interface
  5205. // if the application does not have the phone open.
  5206. // Also, open the wave devices if owner.
  5207. //
  5208. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5209. HRESULT
  5210. WINAPI
  5211. CPhone::ITAutomatedPhoneControlQI(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
  5212. {
  5213. STATICLOG((TL_TRACE,"AutomatedPhoneControlQI - enter"));
  5214. *ppv = NULL;
  5215. CPhone * pPhone = ((CPhone *)pv);
  5216. pPhone->Lock();
  5217. if (pPhone->m_hPhone == NULL)
  5218. {
  5219. STATICLOG((TL_WARN,"The application does not have this phone open"));
  5220. STATICLOG((TL_WARN,"so it cannot access the AutomatedPhoneControl interface"));
  5221. pPhone->Unlock();
  5222. return TAPI_E_PHONENOTOPEN;
  5223. }
  5224. if (pPhone->m_dwPrivilege != PHONEPRIVILEGE_OWNER)
  5225. {
  5226. STATICLOG((TL_WARN,"The application does not have owner privilege"));
  5227. STATICLOG((TL_WARN,"so it cannot access the AutomatedPhoneControl interface"));
  5228. pPhone->Unlock();
  5229. return TAPI_E_NOTOWNER;
  5230. }
  5231. HRESULT hr = pPhone->UpdatePhoneCaps();
  5232. if ( FAILED(hr) )
  5233. {
  5234. STATICLOG((TL_ERROR,"UpdatePhoneCaps failed 0x%lx", hr));
  5235. pPhone->Unlock();
  5236. return hr;
  5237. }
  5238. if ( ( pPhone->GetAPIVersion() < TAPI_VERSION2_0 ) ||
  5239. !(pPhone->m_pPhoneCaps->dwPhoneFeatures & PHONEFEATURE_GENERICPHONE) )
  5240. {
  5241. STATICLOG((TL_TRACE,"The phone does not have PCL_GENERICPHONE capability"));
  5242. STATICLOG((TL_TRACE,"so it cannot access the AutomatedPhoneControl interface"));
  5243. pPhone->Unlock();
  5244. return E_NOINTERFACE;
  5245. }
  5246. if ( pPhone->m_pPhoneCaps->dwNumRingModes == 0)
  5247. {
  5248. //
  5249. // The hardware doesn't have a ringer, so use the wave
  5250. // device as a ringer
  5251. //
  5252. pPhone->m_fUseWaveForRinger = TRUE;
  5253. }
  5254. else
  5255. {
  5256. //
  5257. // Use the hardware ringer
  5258. //
  5259. pPhone->m_fUseWaveForRinger = FALSE;
  5260. }
  5261. pPhone->OpenWaveDevice();
  5262. pPhone->Unlock();
  5263. //
  5264. // S_FALSE tells atl to continue querying for the interface
  5265. //
  5266. STATICLOG((TL_TRACE, "AutomatedPhoneControlQI - exit"));
  5267. return S_FALSE;
  5268. }
  5269. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5270. //
  5271. //
  5272. //
  5273. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5274. STDMETHODIMP
  5275. CPhone::StartTone(
  5276. IN PHONE_TONE Tone,
  5277. IN long lDuration
  5278. )
  5279. {
  5280. HRESULT hr;
  5281. BOOL fResult;
  5282. LOG((TL_TRACE, "StartTone - enter"));
  5283. //
  5284. // Check arguments.
  5285. //
  5286. if ( ( Tone < PT_KEYPADZERO) || ( Tone > PT_SILENCE ) )
  5287. {
  5288. LOG((TL_ERROR, "StartTone - "
  5289. "invalid tone type - exit E_INVALIDARG"));
  5290. return E_INVALIDARG;
  5291. }
  5292. if ( lDuration < 0 )
  5293. {
  5294. LOG((TL_ERROR, "StartTone - "
  5295. "negative argument - exit E_INVALIDARG"));
  5296. return E_INVALIDARG;
  5297. }
  5298. Lock();
  5299. //
  5300. // Make sure the phone is open with owner privilege.
  5301. //
  5302. if ( m_hPhone == NULL )
  5303. {
  5304. LOG((TL_ERROR, "StartTone - phone is not open - "
  5305. "exit TAPI_E_PHONENOTOPEN"));
  5306. Unlock();
  5307. return TAPI_E_PHONENOTOPEN;
  5308. }
  5309. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5310. {
  5311. LOG((TL_ERROR, "StartTone - wrong phone privilege - "
  5312. "exit TAPI_E_NOTOWNER"));
  5313. Unlock();
  5314. return TAPI_E_NOTOWNER;
  5315. }
  5316. //
  5317. // Kill the tone timer
  5318. //
  5319. if (m_hToneTimer)
  5320. {
  5321. EnterCriticalSection( &m_csToneTimer );
  5322. DeleteTimerQueueTimer(m_hTimerQueue,
  5323. m_hToneTimer,
  5324. INVALID_HANDLE_VALUE // blocking
  5325. );
  5326. m_hToneTimer = NULL;
  5327. LeaveCriticalSection( &m_csToneTimer );
  5328. }
  5329. //
  5330. // Stop the old tone if there was one
  5331. //
  5332. if (m_Tone != PT_SILENCE)
  5333. {
  5334. m_WavePlayer.StopTone( (long) m_Tone );
  5335. m_Tone = PT_SILENCE;
  5336. }
  5337. //
  5338. // Start the new tone if needed
  5339. //
  5340. if ( Tone != PT_SILENCE )
  5341. {
  5342. //
  5343. // Set duration and period
  5344. //
  5345. m_dwToneDuration = lDuration;
  5346. switch ( Tone )
  5347. {
  5348. case PT_BUSY:
  5349. m_dwTonePeriodOn = 500;
  5350. m_dwTonePeriodOff = 500;
  5351. break;
  5352. case PT_RINGBACK:
  5353. m_dwTonePeriodOn = 2000;
  5354. m_dwTonePeriodOff = 4000;
  5355. break;
  5356. case PT_ERRORTONE:
  5357. m_dwTonePeriodOn = 100;
  5358. m_dwTonePeriodOff = 100;
  5359. break;
  5360. default: // not periodic
  5361. m_dwTonePeriodOn = 0;
  5362. m_dwTonePeriodOff = 0;
  5363. break;
  5364. }
  5365. hr = m_WavePlayer.StartTone( (long) Tone );
  5366. if ( SUCCEEDED(hr) )
  5367. {
  5368. if ( (m_dwTonePeriodOn > 0) &&
  5369. ((m_dwTonePeriodOn < m_dwToneDuration) || (m_dwToneDuration == 0)) )
  5370. {
  5371. //
  5372. // Tone is periodic and duration is greater than the period
  5373. //
  5374. fResult = CreateTimerQueueTimer(&m_hToneTimer,
  5375. m_hTimerQueue,
  5376. &CPhone::ToneTimerCallback,
  5377. (PVOID)this,
  5378. m_dwTonePeriodOn,
  5379. TIMER_KEEP_ALIVE,
  5380. WT_EXECUTEINIOTHREAD
  5381. );
  5382. if (fResult == FALSE)
  5383. {
  5384. // CreateTimerQueueTimer failed, lets stop the tone and bail out
  5385. LOG((TL_ERROR, "StartTone - CreateTimerQueueTimer failed - %lx", GetLastError()));
  5386. hr = HRESULT_FROM_WIN32(GetLastError());
  5387. m_WavePlayer.StopTone( (long) Tone );
  5388. }
  5389. }
  5390. else if (m_dwToneDuration > 0)
  5391. {
  5392. //
  5393. // Tone is not periodic, or duration is less than the period
  5394. //
  5395. fResult = CreateTimerQueueTimer(&m_hToneTimer,
  5396. m_hTimerQueue,
  5397. &CPhone::ToneTimerCallback,
  5398. (PVOID)this,
  5399. m_dwToneDuration,
  5400. 0,
  5401. WT_EXECUTEINIOTHREAD
  5402. );
  5403. if (fResult == FALSE)
  5404. {
  5405. // CreateTimerQueueTimer failed, lets stop the tone and bail out
  5406. LOG((TL_ERROR, "StartTone - CreateTimerQueueTimer failed - %lx", GetLastError()));
  5407. hr = HRESULT_FROM_WIN32(GetLastError());
  5408. m_WavePlayer.StopTone( (long) Tone );
  5409. }
  5410. }
  5411. }
  5412. if ( FAILED(hr) )
  5413. {
  5414. LOG((TL_ERROR, "StartTone - exit 0x%08x", hr));
  5415. Unlock();
  5416. return hr;
  5417. }
  5418. m_Tone = Tone;
  5419. }
  5420. Unlock();
  5421. LOG((TL_TRACE, "StartTone - exit S_OK"));
  5422. return S_OK;
  5423. }
  5424. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5425. //
  5426. //
  5427. //
  5428. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5429. STDMETHODIMP
  5430. CPhone::StopTone()
  5431. {
  5432. HRESULT hr = S_OK;
  5433. LOG((TL_TRACE, "StopTone - enter"));
  5434. Lock();
  5435. //
  5436. // Make sure the phone is open with owner privilege.
  5437. //
  5438. if ( m_hPhone == NULL )
  5439. {
  5440. LOG((TL_ERROR, "StopTone - phone is not open - "
  5441. "exit TAPI_E_PHONENOTOPEN"));
  5442. Unlock();
  5443. return TAPI_E_PHONENOTOPEN;
  5444. }
  5445. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5446. {
  5447. LOG((TL_ERROR, "StopTone - wrong phone privilege - "
  5448. "exit TAPI_E_NOTOWNER"));
  5449. Unlock();
  5450. return TAPI_E_NOTOWNER;
  5451. }
  5452. //
  5453. // Kill the tone timer
  5454. //
  5455. if (m_hToneTimer)
  5456. {
  5457. EnterCriticalSection( &m_csToneTimer );
  5458. DeleteTimerQueueTimer(m_hTimerQueue,
  5459. m_hToneTimer,
  5460. INVALID_HANDLE_VALUE // blocking
  5461. );
  5462. m_hToneTimer = NULL;
  5463. LeaveCriticalSection( &m_csToneTimer );
  5464. }
  5465. //
  5466. // Stop the old tone if there was one
  5467. //
  5468. if (m_Tone != PT_SILENCE)
  5469. {
  5470. hr = m_WavePlayer.StopTone( (long) m_Tone );
  5471. m_Tone = PT_SILENCE;
  5472. }
  5473. Unlock();
  5474. LOG((TL_ERROR, "StopTone - exit - return %lx", hr));
  5475. return hr;
  5476. }
  5477. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5478. //
  5479. //
  5480. //
  5481. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5482. STDMETHODIMP
  5483. CPhone::get_Tone(
  5484. OUT PHONE_TONE * pTone
  5485. )
  5486. {
  5487. LOG((TL_TRACE, "get_Tone - "
  5488. "enter"));
  5489. if ( TAPIIsBadWritePtr( pTone, sizeof( PHONE_TONE ) ) )
  5490. {
  5491. LOG((TL_ERROR, "get_Tone - "
  5492. "bad parameter - exit E_POINTER"));
  5493. return E_POINTER;
  5494. }
  5495. Lock();
  5496. //
  5497. // Make sure the phone is open
  5498. //
  5499. if ( m_hPhone == NULL )
  5500. {
  5501. LOG((TL_ERROR, "get_Tone - phone is not open - "
  5502. "exit TAPI_E_PHONENOTOPEN"));
  5503. Unlock();
  5504. return TAPI_E_PHONENOTOPEN;
  5505. }
  5506. *pTone = m_Tone;
  5507. Unlock();
  5508. LOG((TL_TRACE, "get_Tone - "
  5509. "exit S_OK"));
  5510. return S_OK;
  5511. }
  5512. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5513. //
  5514. //
  5515. //
  5516. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5517. STDMETHODIMP
  5518. CPhone::StartRinger(
  5519. IN long lRingMode,
  5520. IN long lDuration
  5521. )
  5522. {
  5523. HRESULT hr;
  5524. DWORD dwDummy;
  5525. DWORD dwVolume;
  5526. BOOL fResult;
  5527. LOG((TL_TRACE, "StartRinger - enter"));
  5528. if ( lDuration < 0 )
  5529. {
  5530. LOG((TL_ERROR, "StartRinger - "
  5531. "negative argument - exit E_INVALIDARG"));
  5532. return E_INVALIDARG;
  5533. }
  5534. Lock();
  5535. //
  5536. // Make sure the phone is open with owner privilege.
  5537. //
  5538. if ( m_hPhone == NULL )
  5539. {
  5540. LOG((TL_ERROR, "StartRinger - phone is not open - "
  5541. "exit TAPI_E_PHONENOTOPEN"));
  5542. Unlock();
  5543. return TAPI_E_PHONENOTOPEN;
  5544. }
  5545. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5546. {
  5547. LOG((TL_ERROR, "StartRinger - wrong phone privilege - "
  5548. "exit TAPI_E_NOTOWNER"));
  5549. Unlock();
  5550. return TAPI_E_NOTOWNER;
  5551. }
  5552. //
  5553. // Kill ring timer
  5554. //
  5555. if (m_hRingTimer)
  5556. {
  5557. EnterCriticalSection( &m_csRingTimer );
  5558. DeleteTimerQueueTimer(m_hTimerQueue,
  5559. m_hRingTimer,
  5560. INVALID_HANDLE_VALUE // blocking
  5561. );
  5562. m_hRingTimer = NULL;
  5563. LeaveCriticalSection( &m_csRingTimer );
  5564. }
  5565. //
  5566. // Start ring and set duration and period
  5567. //
  5568. m_dwRingDuration = lDuration;
  5569. if (lRingMode == 0)
  5570. {
  5571. if (m_fUseWaveForRinger)
  5572. {
  5573. m_dwRingPeriod = 4000;
  5574. hr = m_WavePlayer.StartRing();
  5575. }
  5576. else
  5577. {
  5578. m_dwRingPeriod = 0;
  5579. hr = put_RingMode(1);
  5580. }
  5581. }
  5582. else
  5583. {
  5584. m_dwRingPeriod = 0;
  5585. hr = put_RingMode(lRingMode);
  5586. }
  5587. if ( FAILED(hr) )
  5588. {
  5589. LOG((TL_ERROR, "StartRinger - exit 0x%08x", hr));
  5590. Unlock();
  5591. return hr;
  5592. }
  5593. if ( (m_dwRingPeriod > 0) &&
  5594. ((m_dwRingPeriod < m_dwRingDuration) || (m_dwRingDuration == 0)) )
  5595. {
  5596. //
  5597. // Ring is periodic (wave generated) and duration is greater than the period
  5598. //
  5599. fResult = CreateTimerQueueTimer(&m_hRingTimer,
  5600. m_hTimerQueue,
  5601. &CPhone::RingTimerCallback,
  5602. (PVOID)this,
  5603. m_dwRingPeriod,
  5604. m_dwRingPeriod,
  5605. WT_EXECUTEINIOTHREAD
  5606. );
  5607. if (fResult == FALSE)
  5608. {
  5609. // CreateTimerQueueTimer failed, lets stop the ring and bail out
  5610. LOG((TL_ERROR, "StartRinger - CreateTimerQueueTimer failed - %lx", GetLastError()));
  5611. hr = HRESULT_FROM_WIN32(GetLastError());
  5612. }
  5613. }
  5614. else if (m_dwRingDuration > 0)
  5615. {
  5616. //
  5617. // Ring is not periodic (ringer generated), or duration is less than period
  5618. //
  5619. fResult = CreateTimerQueueTimer(&m_hRingTimer,
  5620. m_hTimerQueue,
  5621. &CPhone::RingTimerCallback,
  5622. (PVOID)this,
  5623. m_dwRingDuration,
  5624. 0,
  5625. WT_EXECUTEINIOTHREAD
  5626. );
  5627. if (fResult == FALSE)
  5628. {
  5629. // CreateTimerQueueTimer failed, lets stop the ring and bail out
  5630. LOG((TL_ERROR, "StartRinger - CreateTimerQueueTimer failed - %lx", GetLastError()));
  5631. hr = HRESULT_FROM_WIN32(GetLastError());
  5632. }
  5633. }
  5634. if ( FAILED(hr) )
  5635. {
  5636. if (m_fUseWaveForRinger)
  5637. {
  5638. m_WavePlayer.StopRing();
  5639. }
  5640. else
  5641. {
  5642. put_RingMode(0);
  5643. }
  5644. LOG((TL_ERROR, "StartRinger - exit 0x%08x", hr));
  5645. Unlock();
  5646. return hr;
  5647. }
  5648. m_fRinger = TRUE;
  5649. Unlock();
  5650. LOG((TL_TRACE, "StartRinger - exit S_OK"));
  5651. return S_OK;
  5652. }
  5653. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5654. //
  5655. //
  5656. //
  5657. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5658. STDMETHODIMP
  5659. CPhone::StopRinger()
  5660. {
  5661. HRESULT hr;
  5662. DWORD dwDummy;
  5663. DWORD dwVolume;
  5664. LOG((TL_TRACE, "StopRinger - enter"));
  5665. Lock();
  5666. //
  5667. // Make sure the phone is open with owner privilege.
  5668. //
  5669. if ( m_hPhone == NULL )
  5670. {
  5671. LOG((TL_ERROR, "StopRinger - phone is not open - "
  5672. "exit TAPI_E_PHONENOTOPEN"));
  5673. Unlock();
  5674. return TAPI_E_PHONENOTOPEN;
  5675. }
  5676. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5677. {
  5678. LOG((TL_ERROR, "StopRinger - wrong phone privilege - "
  5679. "exit TAPI_E_NOTOWNER"));
  5680. Unlock();
  5681. return TAPI_E_NOTOWNER;
  5682. }
  5683. //
  5684. // Kill ring timer
  5685. //
  5686. if (m_hRingTimer)
  5687. {
  5688. EnterCriticalSection( &m_csRingTimer );
  5689. DeleteTimerQueueTimer(m_hTimerQueue,
  5690. m_hRingTimer,
  5691. INVALID_HANDLE_VALUE // blocking
  5692. );
  5693. m_hRingTimer = NULL;
  5694. LeaveCriticalSection( &m_csRingTimer );
  5695. }
  5696. if (m_fUseWaveForRinger)
  5697. {
  5698. hr = m_WavePlayer.StopRing();
  5699. }
  5700. else
  5701. {
  5702. hr = put_RingMode( 0 );
  5703. }
  5704. if ( FAILED(hr) )
  5705. {
  5706. LOG((TL_ERROR, "StopRinger - exit 0x%08x", hr));
  5707. Unlock();
  5708. return hr;
  5709. }
  5710. m_fRinger = FALSE;
  5711. Unlock();
  5712. LOG((TL_TRACE, "StopRinger - exit S_OK"));
  5713. return S_OK;
  5714. }
  5715. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5716. //
  5717. //
  5718. //
  5719. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5720. STDMETHODIMP
  5721. CPhone::get_Ringer(
  5722. OUT VARIANT_BOOL * pfRinging
  5723. )
  5724. {
  5725. LOG((TL_TRACE, "get_Ringer - "
  5726. "enter"));
  5727. if ( TAPIIsBadWritePtr( pfRinging, sizeof( VARIANT_BOOL ) ) )
  5728. {
  5729. LOG((TL_ERROR, "get_Ringer - "
  5730. "bad parameter - exit E_POINTER"));
  5731. return E_POINTER;
  5732. }
  5733. Lock();
  5734. //
  5735. // Make sure the phone is open
  5736. //
  5737. if ( m_hPhone == NULL )
  5738. {
  5739. LOG((TL_ERROR, "get_Ringer - phone not open"));
  5740. Unlock();
  5741. return TAPI_E_PHONENOTOPEN;
  5742. }
  5743. //
  5744. // Translate from BOOL to VARIANT_BOOL.
  5745. //
  5746. *pfRinging = m_fRinger ? VARIANT_TRUE : VARIANT_FALSE;
  5747. Unlock();
  5748. LOG((TL_TRACE, "get_Ringer - "
  5749. "exit S_OK"));
  5750. return S_OK;
  5751. }
  5752. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5753. //
  5754. //
  5755. //
  5756. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5757. STDMETHODIMP
  5758. CPhone::put_PhoneHandlingEnabled(
  5759. IN VARIANT_BOOL fEnabled
  5760. )
  5761. {
  5762. LOG((TL_TRACE, "put_PhoneHandlingEnabled - "
  5763. "enter"));
  5764. //
  5765. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  5766. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  5767. //
  5768. Lock();
  5769. //
  5770. // Make sure the phone is open with owner privilege.
  5771. //
  5772. if ( m_hPhone == NULL )
  5773. {
  5774. LOG((TL_ERROR, "put_PhoneHandlingEnabled - phone is not open - "
  5775. "exit TAPI_E_PHONENOTOPEN"));
  5776. Unlock();
  5777. return TAPI_E_PHONENOTOPEN;
  5778. }
  5779. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5780. {
  5781. LOG((TL_ERROR, "put_PhoneHandlingEnabled - wrong phone privilege - "
  5782. "exit TAPI_E_NOTOWNER"));
  5783. Unlock();
  5784. return TAPI_E_NOTOWNER;
  5785. }
  5786. //
  5787. // Make sure there is no call selected on the phone
  5788. //
  5789. if ( m_pCall != NULL )
  5790. {
  5791. LOG((TL_ERROR, "put_PhoneHandlingEnabled - a call is "
  5792. "selected - exit TAPI_E_INUSE"));
  5793. Unlock();
  5794. return TAPI_E_INUSE;
  5795. }
  5796. EnterCriticalSection(&m_csAutomatedPhoneState);
  5797. m_fPhoneHandlingEnabled = fEnabled ? TRUE : FALSE;
  5798. if (m_fPhoneHandlingEnabled)
  5799. {
  5800. HRESULT hr;
  5801. DWORD dwHookSwitchDevs;
  5802. m_dwOffHookCount = 0;
  5803. hr = PhoneGetHookSwitch(m_hPhone, &dwHookSwitchDevs);
  5804. if ( SUCCEEDED(hr) )
  5805. {
  5806. if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_HANDSET) m_dwOffHookCount++;
  5807. if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER) m_dwOffHookCount++;
  5808. if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_HEADSET) m_dwOffHookCount++;
  5809. if (m_dwOffHookCount > 0)
  5810. {
  5811. // phone is off hook
  5812. m_AutomatedPhoneState = APS_OFFHOOK_DEAD_LINE;
  5813. }
  5814. else
  5815. {
  5816. // phone is on hook
  5817. m_AutomatedPhoneState = APS_ONHOOK_IDLE;
  5818. }
  5819. }
  5820. else
  5821. {
  5822. LOG((TL_ERROR, "put_PhoneHandlingEnabled - PhoneGetHookSwitch failed - %lx", hr));
  5823. }
  5824. }
  5825. LeaveCriticalSection(&m_csAutomatedPhoneState);
  5826. Unlock();
  5827. LOG((TL_TRACE, "put_PhoneHandlingEnabled - "
  5828. "exit S_OK"));
  5829. return S_OK;
  5830. }
  5831. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5832. //
  5833. //
  5834. //
  5835. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5836. STDMETHODIMP
  5837. CPhone::get_PhoneHandlingEnabled(
  5838. OUT VARIANT_BOOL * pfEnabled
  5839. )
  5840. {
  5841. LOG((TL_TRACE, "get_PhoneHandlingEnabled - "
  5842. "enter"));
  5843. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  5844. {
  5845. LOG((TL_ERROR, "get_PhoneHandlingEnabled - "
  5846. "bad parameter - exit E_POINTER"));
  5847. return E_POINTER;
  5848. }
  5849. //
  5850. // Translate from BOOL to VARIANT_BOOL.
  5851. //
  5852. Lock();
  5853. //
  5854. // Make sure the phone is open
  5855. //
  5856. if ( m_hPhone == NULL )
  5857. {
  5858. LOG((TL_ERROR, "get_PhoneHandlingEnabled - phone is not open - "
  5859. "exit TAPI_E_PHONENOTOPEN"));
  5860. Unlock();
  5861. return TAPI_E_PHONENOTOPEN;
  5862. }
  5863. EnterCriticalSection(&m_csAutomatedPhoneState);
  5864. *pfEnabled = m_fPhoneHandlingEnabled ? VARIANT_TRUE : VARIANT_FALSE;
  5865. LeaveCriticalSection(&m_csAutomatedPhoneState);
  5866. Unlock();
  5867. LOG((TL_TRACE, "get_PhoneHandlingEnabled - "
  5868. "exit S_OK"));
  5869. return S_OK;
  5870. }
  5871. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5872. //
  5873. //
  5874. //
  5875. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5876. STDMETHODIMP
  5877. CPhone::put_AutoEndOfNumberTimeout(
  5878. IN long lTimeout
  5879. )
  5880. {
  5881. LOG((TL_TRACE, "put_AutoEndOfNumberTimeout - "
  5882. "enter"));
  5883. if ( lTimeout < 0 )
  5884. {
  5885. LOG((TL_ERROR, "put_AutoEndOfNumberTimeout - "
  5886. "negative argument - exit E_INVALIDARG"));
  5887. return E_INVALIDARG;
  5888. }
  5889. Lock();
  5890. //
  5891. // Make sure the phone is open with owner privilege
  5892. //
  5893. if ( m_hPhone == NULL )
  5894. {
  5895. LOG((TL_ERROR, "put_AutoEndOfNumberTimeout - phone is not open - "
  5896. "exit TAPI_E_PHONENOTOPEN"));
  5897. Unlock();
  5898. return TAPI_E_PHONENOTOPEN;
  5899. }
  5900. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5901. {
  5902. LOG((TL_ERROR, "put_AutoEndOfNumberTimeout - wrong phone privilege - "
  5903. "exit TAPI_E_NOTOWNER"));
  5904. Unlock();
  5905. return TAPI_E_NOTOWNER;
  5906. }
  5907. EnterCriticalSection(&m_csAutomatedPhoneState);
  5908. m_dwAutoEndOfNumberTimeout = lTimeout;
  5909. LeaveCriticalSection(&m_csAutomatedPhoneState);
  5910. Unlock();
  5911. LOG((TL_TRACE, "put_AutoEndOfNumberTimeout - "
  5912. "exit S_OK"));
  5913. return S_OK;
  5914. }
  5915. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5916. //
  5917. //
  5918. //
  5919. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5920. STDMETHODIMP
  5921. CPhone::get_AutoEndOfNumberTimeout(
  5922. OUT long * plTimeout
  5923. )
  5924. {
  5925. LOG((TL_TRACE, "get_AutoEndOfNumberTimeout - "
  5926. "enter"));
  5927. if ( TAPIIsBadWritePtr( plTimeout, sizeof( long ) ) )
  5928. {
  5929. LOG((TL_ERROR, "get_AutoEndOfNumberTimeout - "
  5930. "bad parameter - exit E_POINTER"));
  5931. return E_POINTER;
  5932. }
  5933. Lock();
  5934. //
  5935. // Make sure the phone is open
  5936. //
  5937. if ( m_hPhone == NULL )
  5938. {
  5939. LOG((TL_ERROR, "get_AutoEndOfNumberTimeout - phone is not open - "
  5940. "exit TAPI_E_PHONENOTOPEN"));
  5941. Unlock();
  5942. return TAPI_E_PHONENOTOPEN;
  5943. }
  5944. EnterCriticalSection(&m_csAutomatedPhoneState);
  5945. *plTimeout = m_dwAutoEndOfNumberTimeout;
  5946. LeaveCriticalSection(&m_csAutomatedPhoneState);
  5947. Unlock();
  5948. LOG((TL_TRACE, "get_AutoEndOfNumberTimeout - "
  5949. "exit S_OK"));
  5950. return S_OK;
  5951. }
  5952. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5953. //
  5954. //
  5955. //
  5956. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5957. STDMETHODIMP
  5958. CPhone::put_AutoDialtone(
  5959. IN VARIANT_BOOL fEnabled
  5960. )
  5961. {
  5962. LOG((TL_TRACE, "put_AutoDialtone - "
  5963. "enter"));
  5964. //
  5965. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  5966. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  5967. //
  5968. Lock();
  5969. //
  5970. // Make sure the phone is open with owner privilege
  5971. //
  5972. if ( m_hPhone == NULL )
  5973. {
  5974. LOG((TL_ERROR, "put_AutoDialtone - phone is not open - "
  5975. "exit TAPI_E_PHONENOTOPEN"));
  5976. Unlock();
  5977. return TAPI_E_PHONENOTOPEN;
  5978. }
  5979. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  5980. {
  5981. LOG((TL_ERROR, "put_AutoDialtone - wrong phone privilege - "
  5982. "exit TAPI_E_NOTOWNER"));
  5983. Unlock();
  5984. return TAPI_E_NOTOWNER;
  5985. }
  5986. EnterCriticalSection(&m_csAutomatedPhoneState);
  5987. m_fAutoDialtone = fEnabled ? TRUE : FALSE;
  5988. LeaveCriticalSection(&m_csAutomatedPhoneState);
  5989. Unlock();
  5990. LOG((TL_TRACE, "put_AutoDialtone - "
  5991. "exit S_OK"));
  5992. return S_OK;
  5993. }
  5994. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5995. //
  5996. //
  5997. //
  5998. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  5999. STDMETHODIMP
  6000. CPhone::get_AutoDialtone(
  6001. OUT VARIANT_BOOL * pfEnabled
  6002. )
  6003. {
  6004. LOG((TL_TRACE, "get_AutoDialtone - "
  6005. "enter"));
  6006. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  6007. {
  6008. LOG((TL_ERROR, "get_AutoDialtone - "
  6009. "bad parameter - exit E_POINTER"));
  6010. return E_POINTER;
  6011. }
  6012. //
  6013. // Translate from BOOL to VARIANT_BOOL.
  6014. //
  6015. Lock();
  6016. //
  6017. // Make sure the phone is open
  6018. //
  6019. if ( m_hPhone == NULL )
  6020. {
  6021. LOG((TL_ERROR, "get_AutoDialtone - phone is not open - "
  6022. "exit TAPI_E_PHONENOTOPEN"));
  6023. Unlock();
  6024. return TAPI_E_PHONENOTOPEN;
  6025. }
  6026. EnterCriticalSection(&m_csAutomatedPhoneState);
  6027. *pfEnabled = m_fAutoDialtone ? VARIANT_TRUE : VARIANT_FALSE;
  6028. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6029. Unlock();
  6030. LOG((TL_TRACE, "get_AutoDialtone - "
  6031. "exit S_OK"));
  6032. return S_OK;
  6033. }
  6034. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6035. //
  6036. //
  6037. //
  6038. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6039. STDMETHODIMP
  6040. CPhone::put_AutoStopTonesOnOnHook(
  6041. IN VARIANT_BOOL fEnabled
  6042. )
  6043. {
  6044. LOG((TL_TRACE, "put_AutoStopTonesOnOnHook - "
  6045. "enter"));
  6046. //
  6047. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  6048. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  6049. //
  6050. Lock();
  6051. //
  6052. // Make sure the phone is open with owner privilege
  6053. //
  6054. if ( m_hPhone == NULL )
  6055. {
  6056. LOG((TL_ERROR, "put_AutoStopTonesOnOnHook - phone is not open - "
  6057. "exit TAPI_E_PHONENOTOPEN"));
  6058. Unlock();
  6059. return TAPI_E_PHONENOTOPEN;
  6060. }
  6061. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6062. {
  6063. LOG((TL_ERROR, "put_AutoStopTonesOnOnHook - wrong phone privilege - "
  6064. "exit TAPI_E_NOTOWNER"));
  6065. Unlock();
  6066. return TAPI_E_NOTOWNER;
  6067. }
  6068. EnterCriticalSection(&m_csAutomatedPhoneState);
  6069. m_fAutoStopTonesOnOnHook = fEnabled ? TRUE : FALSE;
  6070. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6071. Unlock();
  6072. LOG((TL_TRACE, "put_AutoStopTonesOnOnHook - "
  6073. "exit S_OK"));
  6074. return S_OK;
  6075. }
  6076. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6077. //
  6078. //
  6079. //
  6080. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6081. STDMETHODIMP
  6082. CPhone::get_AutoStopTonesOnOnHook(
  6083. OUT VARIANT_BOOL * pfEnabled
  6084. )
  6085. {
  6086. LOG((TL_TRACE, "get_AutoStopTonesOnOnHook - "
  6087. "enter"));
  6088. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  6089. {
  6090. LOG((TL_ERROR, "get_AutoStopTonesOnOnHook - "
  6091. "bad parameter - exit E_POINTER"));
  6092. return E_POINTER;
  6093. }
  6094. //
  6095. // Translate from BOOL to VARIANT_BOOL.
  6096. //
  6097. Lock();
  6098. //
  6099. // Make sure the phone is open
  6100. //
  6101. if ( m_hPhone == NULL )
  6102. {
  6103. LOG((TL_ERROR, "get_AutoDialtone - phone is not open - "
  6104. "exit TAPI_E_PHONENOTOPEN"));
  6105. Unlock();
  6106. return TAPI_E_PHONENOTOPEN;
  6107. }
  6108. EnterCriticalSection(&m_csAutomatedPhoneState);
  6109. *pfEnabled = m_fAutoStopTonesOnOnHook ? VARIANT_TRUE : VARIANT_FALSE;
  6110. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6111. Unlock();
  6112. LOG((TL_TRACE, "get_AutoStopTonesOnOnHook - "
  6113. "exit S_OK"));
  6114. return S_OK;
  6115. }
  6116. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6117. //
  6118. //
  6119. //
  6120. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6121. STDMETHODIMP
  6122. CPhone::put_AutoStopRingOnOffHook(
  6123. IN VARIANT_BOOL fEnabled
  6124. )
  6125. {
  6126. LOG((TL_TRACE, "put_AutoStopRingOnOffHook - "
  6127. "enter"));
  6128. //
  6129. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  6130. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  6131. //
  6132. Lock();
  6133. //
  6134. // Make sure the phone is open with owner privilege
  6135. //
  6136. if ( m_hPhone == NULL )
  6137. {
  6138. LOG((TL_ERROR, "put_AutoStopRingOnOffHook - phone is not open - "
  6139. "exit TAPI_E_PHONENOTOPEN"));
  6140. Unlock();
  6141. return TAPI_E_PHONENOTOPEN;
  6142. }
  6143. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6144. {
  6145. LOG((TL_ERROR, "put_AutoStopRingOnOffHook - wrong phone privilege - "
  6146. "exit TAPI_E_NOTOWNER"));
  6147. Unlock();
  6148. return TAPI_E_NOTOWNER;
  6149. }
  6150. EnterCriticalSection(&m_csAutomatedPhoneState);
  6151. m_fAutoStopRingOnOffHook = fEnabled ? TRUE : FALSE;
  6152. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6153. Unlock();
  6154. LOG((TL_TRACE, "put_AutoStopRingOnOffHook - "
  6155. "exit S_OK"));
  6156. return S_OK;
  6157. }
  6158. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6159. //
  6160. //
  6161. //
  6162. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6163. STDMETHODIMP
  6164. CPhone::get_AutoStopRingOnOffHook(
  6165. OUT VARIANT_BOOL * pfEnabled
  6166. )
  6167. {
  6168. LOG((TL_TRACE, "get_AutoStopRingOnOffHook - "
  6169. "enter"));
  6170. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  6171. {
  6172. LOG((TL_ERROR, "get_AutoStopRingOnOffHook - "
  6173. "bad parameter - exit E_POINTER"));
  6174. return E_POINTER;
  6175. }
  6176. //
  6177. // Translate from BOOL to VARIANT_BOOL.
  6178. //
  6179. Lock();
  6180. //
  6181. // Make sure the phone is open
  6182. //
  6183. if ( m_hPhone == NULL )
  6184. {
  6185. LOG((TL_ERROR, "get_AutoStopRingOnOffHook - phone is not open - "
  6186. "exit TAPI_E_PHONENOTOPEN"));
  6187. Unlock();
  6188. return TAPI_E_PHONENOTOPEN;
  6189. }
  6190. EnterCriticalSection(&m_csAutomatedPhoneState);
  6191. *pfEnabled = m_fAutoStopRingOnOffHook ? VARIANT_TRUE : VARIANT_FALSE;
  6192. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6193. Unlock();
  6194. LOG((TL_TRACE, "get_AutoStopRingOnOffHook - "
  6195. "exit S_OK"));
  6196. return S_OK;
  6197. }
  6198. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6199. //
  6200. //
  6201. //
  6202. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6203. STDMETHODIMP
  6204. CPhone::put_AutoKeypadTones(
  6205. IN VARIANT_BOOL fEnabled
  6206. )
  6207. {
  6208. LOG((TL_TRACE, "put_AutoKeypadTones - "
  6209. "enter"));
  6210. //
  6211. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  6212. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  6213. //
  6214. Lock();
  6215. //
  6216. // Make sure the phone is open with owner privilege
  6217. //
  6218. if ( m_hPhone == NULL )
  6219. {
  6220. LOG((TL_ERROR, "put_AutoKeypadTones - phone is not open - "
  6221. "exit TAPI_E_PHONENOTOPEN"));
  6222. Unlock();
  6223. return TAPI_E_PHONENOTOPEN;
  6224. }
  6225. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6226. {
  6227. LOG((TL_ERROR, "put_AutoKeypadTones - wrong phone privilege - "
  6228. "exit TAPI_E_NOTOWNER"));
  6229. Unlock();
  6230. return TAPI_E_NOTOWNER;
  6231. }
  6232. EnterCriticalSection(&m_csAutomatedPhoneState);
  6233. m_fAutoKeypadTones = fEnabled ? TRUE : FALSE;
  6234. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6235. Unlock();
  6236. LOG((TL_TRACE, "put_AutoKeypadTones - "
  6237. "exit S_OK"));
  6238. return S_OK;
  6239. }
  6240. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6241. //
  6242. //
  6243. //
  6244. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6245. STDMETHODIMP
  6246. CPhone::get_AutoKeypadTones (
  6247. OUT VARIANT_BOOL * pfEnabled
  6248. )
  6249. {
  6250. LOG((TL_TRACE, "get_AutoKeypadTones - "
  6251. "enter"));
  6252. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  6253. {
  6254. LOG((TL_ERROR, "get_AutoKeypadTones - "
  6255. "bad parameter - exit E_POINTER"));
  6256. return E_POINTER;
  6257. }
  6258. //
  6259. // Translate from BOOL to VARIANT_BOOL.
  6260. //
  6261. Lock();
  6262. //
  6263. // Make sure the phone is open
  6264. //
  6265. if ( m_hPhone == NULL )
  6266. {
  6267. LOG((TL_ERROR, "get_AutoKeypadTones - phone is not open - "
  6268. "exit TAPI_E_PHONENOTOPEN"));
  6269. Unlock();
  6270. return TAPI_E_PHONENOTOPEN;
  6271. }
  6272. EnterCriticalSection(&m_csAutomatedPhoneState);
  6273. *pfEnabled = m_fAutoKeypadTones ? VARIANT_TRUE : VARIANT_FALSE;
  6274. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6275. Unlock();
  6276. LOG((TL_TRACE, "get_AutoKeypadTones - "
  6277. "exit S_OK"));
  6278. return S_OK;
  6279. }
  6280. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6281. //
  6282. //
  6283. //
  6284. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6285. STDMETHODIMP
  6286. CPhone::put_AutoKeypadTonesMinimumDuration(
  6287. IN long lDuration
  6288. )
  6289. {
  6290. LOG((TL_TRACE, "put_AutoKeypadTonesMinimumDuration - "
  6291. "enter"));
  6292. if ( lDuration < 0 )
  6293. {
  6294. LOG((TL_ERROR, "put_AutoKeypadTonesMinimumDuration - "
  6295. "negative argument - exit E_INVALIDARG"));
  6296. return E_INVALIDARG;
  6297. }
  6298. Lock();
  6299. //
  6300. // Make sure the phone is open with owner privilege
  6301. //
  6302. if ( m_hPhone == NULL )
  6303. {
  6304. LOG((TL_ERROR, "put_AutoKeypadTonesMinimumDuration - phone is not open - "
  6305. "exit TAPI_E_PHONENOTOPEN"));
  6306. Unlock();
  6307. return TAPI_E_PHONENOTOPEN;
  6308. }
  6309. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6310. {
  6311. LOG((TL_ERROR, "put_AutoKeypadTonesMinimumDuration - wrong phone privilege - "
  6312. "exit TAPI_E_NOTOWNER"));
  6313. Unlock();
  6314. return TAPI_E_NOTOWNER;
  6315. }
  6316. EnterCriticalSection(&m_csAutomatedPhoneState);
  6317. m_dwAutoKeypadTonesMinimumDuration = lDuration;
  6318. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6319. Unlock();
  6320. LOG((TL_TRACE, "put_AutoKeypadTonesMinimumDuration - "
  6321. "exit S_OK"));
  6322. return S_OK;
  6323. }
  6324. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6325. //
  6326. //
  6327. //
  6328. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6329. STDMETHODIMP
  6330. CPhone::get_AutoKeypadTonesMinimumDuration(
  6331. OUT long * plDuration
  6332. )
  6333. {
  6334. LOG((TL_TRACE, "get_AutoKeypadTonesMinimumDuration - "
  6335. "enter"));
  6336. if ( TAPIIsBadWritePtr( plDuration, sizeof(long) ) )
  6337. {
  6338. LOG((TL_ERROR, "get_AutoKeypadTonesMinimumDuration - "
  6339. "bad parameter - exit E_POINTER"));
  6340. return E_POINTER;
  6341. }
  6342. Lock();
  6343. //
  6344. // Make sure the phone is open
  6345. //
  6346. if ( m_hPhone == NULL )
  6347. {
  6348. LOG((TL_ERROR, "get_AutoKeypadTonesMinimumDuration - phone is not open - "
  6349. "exit TAPI_E_PHONENOTOPEN"));
  6350. Unlock();
  6351. return TAPI_E_PHONENOTOPEN;
  6352. }
  6353. EnterCriticalSection(&m_csAutomatedPhoneState);
  6354. *plDuration = m_dwAutoKeypadTonesMinimumDuration;
  6355. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6356. Unlock();
  6357. LOG((TL_TRACE, "get_AutoKeypadTonesMinimumDuration - "
  6358. "exit S_OK"));
  6359. return S_OK;
  6360. }
  6361. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6362. //
  6363. //
  6364. //
  6365. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6366. STDMETHODIMP
  6367. CPhone::put_AutoVolumeControl(
  6368. IN VARIANT_BOOL fEnabled
  6369. )
  6370. {
  6371. LOG((TL_TRACE, "put_AutoVolumeControl - "
  6372. "enter"));
  6373. //
  6374. // Translate from VARIANT_BOOL to BOOL. If someone mistakenly
  6375. // passes in TRUE instead of VARIANT_TRUE, we are still ok.
  6376. //
  6377. Lock();
  6378. //
  6379. // Make sure the phone is open with owner privilege
  6380. //
  6381. if ( m_hPhone == NULL )
  6382. {
  6383. LOG((TL_ERROR, "put_AutoVolumeControl - phone is not open - "
  6384. "exit TAPI_E_PHONENOTOPEN"));
  6385. Unlock();
  6386. return TAPI_E_PHONENOTOPEN;
  6387. }
  6388. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6389. {
  6390. LOG((TL_ERROR, "put_AutoVolumeControl - wrong phone privilege - "
  6391. "exit TAPI_E_NOTOWNER"));
  6392. Unlock();
  6393. return TAPI_E_NOTOWNER;
  6394. }
  6395. EnterCriticalSection(&m_csAutomatedPhoneState);
  6396. m_fAutoVolumeControl = fEnabled ? TRUE : FALSE;
  6397. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6398. Unlock();
  6399. LOG((TL_TRACE, "put_AutoVolumeControl - "
  6400. "exit S_OK"));
  6401. return S_OK;
  6402. }
  6403. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6404. //
  6405. //
  6406. //
  6407. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6408. STDMETHODIMP
  6409. CPhone::get_AutoVolumeControl (
  6410. OUT VARIANT_BOOL * pfEnabled
  6411. )
  6412. {
  6413. LOG((TL_TRACE, "get_AutoVolumeControl - "
  6414. "enter"));
  6415. if ( TAPIIsBadWritePtr( pfEnabled, sizeof( VARIANT_BOOL ) ) )
  6416. {
  6417. LOG((TL_ERROR, "get_AutoVolumeControl - "
  6418. "bad parameter - exit E_POINTER"));
  6419. return E_POINTER;
  6420. }
  6421. //
  6422. // Translate from BOOL to VARIANT_BOOL.
  6423. //
  6424. Lock();
  6425. //
  6426. // Make sure the phone is open
  6427. //
  6428. if ( m_hPhone == NULL )
  6429. {
  6430. LOG((TL_ERROR, "get_AutoVolumeControl - phone is not open - "
  6431. "exit TAPI_E_PHONENOTOPEN"));
  6432. Unlock();
  6433. return TAPI_E_PHONENOTOPEN;
  6434. }
  6435. EnterCriticalSection(&m_csAutomatedPhoneState);
  6436. *pfEnabled = m_fAutoVolumeControl ? VARIANT_TRUE : VARIANT_FALSE;
  6437. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6438. Unlock();
  6439. LOG((TL_TRACE, "get_AutoVolumeControl - "
  6440. "exit S_OK"));
  6441. return S_OK;
  6442. }
  6443. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6444. //
  6445. //
  6446. //
  6447. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6448. STDMETHODIMP
  6449. CPhone::put_AutoVolumeControlStep(
  6450. IN long lStepSize
  6451. )
  6452. {
  6453. LOG((TL_TRACE, "put_AutoVolumeControlStep - "
  6454. "enter"));
  6455. if ( (lStepSize < 0) || (lStepSize > 0xFFFF) )
  6456. {
  6457. LOG((TL_ERROR, "put_AutoVolumeControlStep - "
  6458. "invalid argument - exit E_INVALIDARG"));
  6459. return E_INVALIDARG;
  6460. }
  6461. Lock();
  6462. //
  6463. // Make sure the phone is open with owner privilege
  6464. //
  6465. if ( m_hPhone == NULL )
  6466. {
  6467. LOG((TL_ERROR, "put_AutoVolumeControlStep - phone is not open - "
  6468. "exit TAPI_E_PHONENOTOPEN"));
  6469. Unlock();
  6470. return TAPI_E_PHONENOTOPEN;
  6471. }
  6472. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6473. {
  6474. LOG((TL_ERROR, "put_AutoVolumeControlStep - wrong phone privilege - "
  6475. "exit TAPI_E_NOTOWNER"));
  6476. Unlock();
  6477. return TAPI_E_NOTOWNER;
  6478. }
  6479. EnterCriticalSection(&m_csAutomatedPhoneState);
  6480. m_dwAutoVolumeControlStep = lStepSize;
  6481. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6482. Unlock();
  6483. LOG((TL_TRACE, "put_AutoVolumeControlStep - "
  6484. "exit S_OK"));
  6485. return S_OK;
  6486. }
  6487. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6488. //
  6489. //
  6490. //
  6491. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6492. STDMETHODIMP
  6493. CPhone::get_AutoVolumeControlStep(
  6494. OUT long * plStepSize
  6495. )
  6496. {
  6497. LOG((TL_TRACE, "get_AutoVolumeControlStep - "
  6498. "enter"));
  6499. if ( TAPIIsBadWritePtr( plStepSize, sizeof(long) ) )
  6500. {
  6501. LOG((TL_ERROR, "get_AutoVolumeControlStep - "
  6502. "bad parameter - exit E_POINTER"));
  6503. return E_POINTER;
  6504. }
  6505. Lock();
  6506. //
  6507. // Make sure the phone is open
  6508. //
  6509. if ( m_hPhone == NULL )
  6510. {
  6511. LOG((TL_ERROR, "get_AutoVolumeControlStep - phone is not open - "
  6512. "exit TAPI_E_PHONENOTOPEN"));
  6513. Unlock();
  6514. return TAPI_E_PHONENOTOPEN;
  6515. }
  6516. EnterCriticalSection(&m_csAutomatedPhoneState);
  6517. *plStepSize = m_dwAutoVolumeControlStep;
  6518. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6519. Unlock();
  6520. LOG((TL_TRACE, "get_AutoVolumeControlStep - "
  6521. "exit S_OK"));
  6522. return S_OK;
  6523. }
  6524. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6525. //
  6526. //
  6527. //
  6528. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6529. STDMETHODIMP
  6530. CPhone::put_AutoVolumeControlRepeatDelay(
  6531. IN long lDelay
  6532. )
  6533. {
  6534. LOG((TL_TRACE, "put_AutoVolumeControlRepeatDelay - "
  6535. "enter"));
  6536. if ( lDelay < 0 )
  6537. {
  6538. LOG((TL_ERROR, "put_AutoVolumeControlRepeatDelay - "
  6539. "invalid argument - exit E_INVALIDARG"));
  6540. return E_INVALIDARG;
  6541. }
  6542. Lock();
  6543. //
  6544. // Make sure the phone is open with owner privilege
  6545. //
  6546. if ( m_hPhone == NULL )
  6547. {
  6548. LOG((TL_ERROR, "put_AutoVolumeControlRepeatDelay - phone is not open - "
  6549. "exit TAPI_E_PHONENOTOPEN"));
  6550. Unlock();
  6551. return TAPI_E_PHONENOTOPEN;
  6552. }
  6553. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6554. {
  6555. LOG((TL_ERROR, "put_AutoVolumeControlRepeatDelay - wrong phone privilege - "
  6556. "exit TAPI_E_NOTOWNER"));
  6557. Unlock();
  6558. return TAPI_E_NOTOWNER;
  6559. }
  6560. EnterCriticalSection(&m_csAutomatedPhoneState);
  6561. m_dwAutoVolumeControlRepeatDelay = lDelay;
  6562. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6563. Unlock();
  6564. LOG((TL_TRACE, "put_AutoVolumeControlRepeatDelay - "
  6565. "exit S_OK"));
  6566. return S_OK;
  6567. }
  6568. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6569. //
  6570. //
  6571. //
  6572. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6573. STDMETHODIMP
  6574. CPhone::get_AutoVolumeControlRepeatDelay(
  6575. OUT long * plDelay
  6576. )
  6577. {
  6578. LOG((TL_TRACE, "get_AutoVolumeControlRepeatDelay - "
  6579. "enter"));
  6580. if ( TAPIIsBadWritePtr( plDelay, sizeof(long) ) )
  6581. {
  6582. LOG((TL_ERROR, "get_AutoVolumeControlRepeatDelay - "
  6583. "bad parameter - exit E_POINTER"));
  6584. return E_POINTER;
  6585. }
  6586. Lock();
  6587. //
  6588. // Make sure the phone is open
  6589. //
  6590. if ( m_hPhone == NULL )
  6591. {
  6592. LOG((TL_ERROR, "get_AutoVolumeControlRepeatDelay - phone is not open - "
  6593. "exit TAPI_E_PHONENOTOPEN"));
  6594. Unlock();
  6595. return TAPI_E_PHONENOTOPEN;
  6596. }
  6597. EnterCriticalSection(&m_csAutomatedPhoneState);
  6598. *plDelay = m_dwAutoVolumeControlRepeatDelay;
  6599. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6600. Unlock();
  6601. LOG((TL_TRACE, "get_AutoVolumeControlRepeatDelay - "
  6602. "exit S_OK"));
  6603. return S_OK;
  6604. }
  6605. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6606. //
  6607. //
  6608. //
  6609. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6610. STDMETHODIMP
  6611. CPhone::put_AutoVolumeControlRepeatPeriod(
  6612. IN long lPeriod
  6613. )
  6614. {
  6615. LOG((TL_TRACE, "put_AutoVolumeControlRepeatPeriod - "
  6616. "enter"));
  6617. if ( lPeriod < 0 )
  6618. {
  6619. LOG((TL_ERROR, "put_AutoVolumeControlRepeatPeriod - "
  6620. "invalid argument - exit E_INVALIDARG"));
  6621. return E_INVALIDARG;
  6622. }
  6623. Lock();
  6624. //
  6625. // Make sure the phone is open with owner privilege
  6626. //
  6627. if ( m_hPhone == NULL )
  6628. {
  6629. LOG((TL_ERROR, "put_AutoVolumeControlRepeatPeriod - phone is not open - "
  6630. "exit TAPI_E_PHONENOTOPEN"));
  6631. Unlock();
  6632. return TAPI_E_PHONENOTOPEN;
  6633. }
  6634. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6635. {
  6636. LOG((TL_ERROR, "put_AutoVolumeControlRepeatPeriod - wrong phone privilege - "
  6637. "exit TAPI_E_NOTOWNER"));
  6638. Unlock();
  6639. return TAPI_E_NOTOWNER;
  6640. }
  6641. EnterCriticalSection(&m_csAutomatedPhoneState);
  6642. m_dwAutoVolumeControlRepeatPeriod = lPeriod;
  6643. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6644. Unlock();
  6645. LOG((TL_TRACE, "put_AutoVolumeControlRepeatPeriod - "
  6646. "exit S_OK"));
  6647. return S_OK;
  6648. }
  6649. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6650. //
  6651. //
  6652. //
  6653. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6654. STDMETHODIMP
  6655. CPhone::get_AutoVolumeControlRepeatPeriod(
  6656. OUT long * plPeriod
  6657. )
  6658. {
  6659. LOG((TL_TRACE, "get_AutoVolumeControlRepeatPeriod - "
  6660. "enter"));
  6661. if ( TAPIIsBadWritePtr( plPeriod, sizeof(long) ) )
  6662. {
  6663. LOG((TL_ERROR, "get_AutoVolumeControlRepeatPeriod - "
  6664. "bad parameter - exit E_POINTER"));
  6665. return E_POINTER;
  6666. }
  6667. Lock();
  6668. //
  6669. // Make sure the phone is open
  6670. //
  6671. if ( m_hPhone == NULL )
  6672. {
  6673. LOG((TL_ERROR, "get_AutoVolumeControlRepeatPeriod - phone is not open - "
  6674. "exit TAPI_E_PHONENOTOPEN"));
  6675. Unlock();
  6676. return TAPI_E_PHONENOTOPEN;
  6677. }
  6678. EnterCriticalSection(&m_csAutomatedPhoneState);
  6679. *plPeriod = m_dwAutoVolumeControlRepeatPeriod;
  6680. LeaveCriticalSection(&m_csAutomatedPhoneState);
  6681. Unlock();
  6682. LOG((TL_TRACE, "get_AutoVolumeControlRepeatPeriod - "
  6683. "exit S_OK"));
  6684. return S_OK;
  6685. }
  6686. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6687. //
  6688. // UnselectAllPreviouslySelectedTerminals
  6689. //
  6690. // pCallBCC2 -- the call on which we started to select terminals
  6691. // pTerminal -- the last terminal we tried to select; it failed
  6692. // pEnum -- the enumerator that gave us the terminals we tried to select
  6693. //
  6694. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6695. void
  6696. CPhone::UnselectAllPreviouslySelectedTerminals(
  6697. IN ITBasicCallControl2 * pCall,
  6698. IN ITTerminal * pTerminalThatFailed,
  6699. IN IEnumTerminal * pEnum
  6700. )
  6701. {
  6702. HRESULT hr;
  6703. LOG((TL_TRACE, "UnselectAllPreviouslySelectedTerminals - "
  6704. "enter"));
  6705. //
  6706. // Reset the enumerator. If this fails, stop -- we don't want to risk
  6707. // unselecting terminals that were selected independently of SelectCall().
  6708. //
  6709. hr = pEnum->Reset();
  6710. if ( FAILED(hr) )
  6711. {
  6712. LOG((TL_WARN,
  6713. "UnselectAllPreviouslySelectedTerminals - "
  6714. "failed to reset enumerator %p - "
  6715. "hr = 0x%08x. Not unselecting terminals.", pEnum, hr ));
  6716. return;
  6717. }
  6718. ITTerminal * pTerminal;
  6719. BOOL fDone = FALSE;
  6720. while ( S_OK == pEnum->Next( 1, & pTerminal, NULL ) )
  6721. {
  6722. if ( pTerminal == pTerminalThatFailed )
  6723. {
  6724. fDone = TRUE;
  6725. }
  6726. else
  6727. {
  6728. //
  6729. // Try to unselect the terminal. If it fails to unselect, there's
  6730. // nothing more we can do... just continue trying to unselect the
  6731. // rest of the terminals.
  6732. //
  6733. hr = pCall->UnselectTerminalOnCall( pTerminal );
  6734. if ( FAILED(hr) )
  6735. {
  6736. LOG((TL_WARN,
  6737. "UnselectAllPreviouslySelectedTerminals - "
  6738. "cannot unselect terminal %p on ITBCC2 %p - "
  6739. "hr = 0x%08x. Continuing...", pTerminal, pCall, hr ));
  6740. }
  6741. }
  6742. pTerminal->Release();
  6743. if ( fDone == TRUE )
  6744. {
  6745. break;
  6746. }
  6747. }
  6748. LOG((TL_TRACE, "UnselectAllPreviouslySelectedTerminals - "
  6749. "normal exit"));
  6750. }
  6751. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6752. //
  6753. //
  6754. //
  6755. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6756. HRESULT
  6757. CPhone::SelectDefaultTerminalsOnCall(
  6758. IN ITCallInfo * pCall
  6759. )
  6760. {
  6761. LOG((TL_TRACE, "SelectDefaultTerminalsOnCall - enter" ));
  6762. //
  6763. // Get the address for the call
  6764. //
  6765. HRESULT hr;
  6766. ITAddress * pAddress;
  6767. hr = pCall->get_Address( & pAddress );
  6768. if ( FAILED(hr) )
  6769. {
  6770. LOG((TL_ERROR, "SelectDefaultTerminalsOnCall - "
  6771. "cannot get call's "
  6772. "address - exit 0x%08x", hr ));
  6773. return hr;
  6774. }
  6775. //
  6776. // Find the default terminals for this phone.
  6777. //
  6778. IEnumTerminal * pEnum;
  6779. hr = EnumerateTerminals( pAddress, & pEnum );
  6780. pAddress->Release();
  6781. if ( FAILED(hr) )
  6782. {
  6783. LOG((TL_ERROR, "SelectDefaultTerminalsOnCall - "
  6784. "cannot enum phone's "
  6785. "terminals - exit 0x%08x", hr ));
  6786. return hr;
  6787. }
  6788. //
  6789. // Get the terminal selection interface on the call.
  6790. //
  6791. ITBasicCallControl2 * pCallBCC2;
  6792. hr = pCall->QueryInterface( IID_ITBasicCallControl2,
  6793. (void **) & pCallBCC2 );
  6794. if ( FAILED(hr) )
  6795. {
  6796. LOG((TL_ERROR, "SelectDefaultTerminalsOnCall - "
  6797. "cannot get call's "
  6798. "ITBasicCallControl2 interface - "
  6799. "exit 0x%08x", hr ));
  6800. pEnum->Release();
  6801. return hr;
  6802. }
  6803. //
  6804. // Select each of the default terminals on the call.
  6805. //
  6806. ITTerminal * pTerminal;
  6807. while ( S_OK == pEnum->Next( 1, & pTerminal, NULL ) )
  6808. {
  6809. //
  6810. // Select each terminal on the call.
  6811. // If one selection fails, unselect all the terminals
  6812. // that were successfully selected.
  6813. //
  6814. hr = pCallBCC2->SelectTerminalOnCall( pTerminal );
  6815. if ( FAILED(hr) )
  6816. {
  6817. LOG((TL_ERROR, "SelectDefaultTerminalsOnCall - "
  6818. "cannot select "
  6819. "terminal %p on ITBCC2 %p - "
  6820. "unselecting other terminals",
  6821. pTerminal, pCallBCC2 ));
  6822. UnselectAllPreviouslySelectedTerminals(pCallBCC2,
  6823. pTerminal,
  6824. pEnum);
  6825. LOG((TL_ERROR, "SelectDefaultTerminalsOnCall - "
  6826. "exit 0x%08x", hr ));
  6827. pTerminal->Release();
  6828. pEnum->Release();
  6829. pCallBCC2->Release();
  6830. return hr;
  6831. }
  6832. pTerminal->Release();
  6833. }
  6834. pEnum->Release();
  6835. pCallBCC2->Release();
  6836. LOG((TL_TRACE, "SelectDefaultTerminalsOnCall - exit S_OK" ));
  6837. return S_OK;
  6838. }
  6839. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6840. //
  6841. //
  6842. //
  6843. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6844. HRESULT
  6845. CPhone::UnselectDefaultTerminalsOnCall(
  6846. IN ITCallInfo * pCall
  6847. )
  6848. {
  6849. LOG((TL_TRACE, "UnselectDefaultTerminalsOnCall - enter" ));
  6850. //
  6851. // Get the address for the call
  6852. //
  6853. HRESULT hr;
  6854. ITAddress * pAddress;
  6855. hr = pCall->get_Address( & pAddress );
  6856. if ( FAILED(hr) )
  6857. {
  6858. LOG((TL_ERROR, "UnselectDefaultTerminalsOnCall - "
  6859. "cannot get call's "
  6860. "address - exit 0x%08x", hr ));
  6861. return hr;
  6862. }
  6863. //
  6864. // Find the default terminals for this phone.
  6865. //
  6866. IEnumTerminal * pEnum;
  6867. hr = EnumerateTerminals( pAddress, & pEnum );
  6868. pAddress->Release();
  6869. if ( FAILED(hr) )
  6870. {
  6871. LOG((TL_ERROR, "UnselectDefaultTerminalsOnCall - "
  6872. "cannot enum phone's "
  6873. "terminals - exit 0x%08x", hr ));
  6874. return hr;
  6875. }
  6876. //
  6877. // Get the terminal selection interface on the call.
  6878. //
  6879. ITBasicCallControl2 * pCallBCC2;
  6880. hr = pCall->QueryInterface( IID_ITBasicCallControl2,
  6881. (void **) & pCallBCC2 );
  6882. if ( FAILED(hr) )
  6883. {
  6884. LOG((TL_ERROR, "UnselectDefaultTerminalsOnCall - "
  6885. "cannot get call's "
  6886. "ITBasicCallControl2 interface - "
  6887. "exit 0x%08x", hr ));
  6888. pEnum->Release();
  6889. return hr;
  6890. }
  6891. //
  6892. // Unselect each of the default terminals on the call.
  6893. //
  6894. ITTerminal * pTerminal;
  6895. while ( S_OK == pEnum->Next( 1, & pTerminal, NULL ) )
  6896. {
  6897. //
  6898. // Unselect each terminal on the call.
  6899. // If one unselection fails, keep on going
  6900. //
  6901. hr = pCallBCC2->UnselectTerminalOnCall( pTerminal );
  6902. if ( FAILED(hr) )
  6903. {
  6904. LOG((TL_ERROR, "UnselectDefaultTerminalsOnCall - "
  6905. "cannot unselect "
  6906. "terminal %p on ITBCC2 %p",
  6907. pTerminal, pCallBCC2 ));
  6908. }
  6909. pTerminal->Release();
  6910. }
  6911. pEnum->Release();
  6912. pCallBCC2->Release();
  6913. LOG((TL_TRACE, "UnselectDefaultTerminalsOnCall - exit S_OK" ));
  6914. return S_OK;
  6915. }
  6916. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6917. //
  6918. //
  6919. //
  6920. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  6921. STDMETHODIMP
  6922. CPhone::SelectCall(
  6923. IN ITCallInfo * pCall,
  6924. IN VARIANT_BOOL fSelectDefaultTerminals
  6925. )
  6926. {
  6927. HRESULT hr;
  6928. CALL_STATE cs;
  6929. CALL_PRIVILEGE priv;
  6930. LOG((TL_TRACE, "SelectCall - enter"));
  6931. //
  6932. // check argument
  6933. //
  6934. if ( IsBadReadPtr( pCall, sizeof( ITCallInfo ) ) )
  6935. {
  6936. LOG((TL_ERROR, "SelectCall - exit E_POINTER"));
  6937. return E_POINTER;
  6938. }
  6939. //
  6940. // Check if the app has owner privilege on this call.
  6941. //
  6942. hr = pCall->get_Privilege( & priv );
  6943. if ( FAILED(hr) )
  6944. {
  6945. LOG((TL_ERROR, "SelectCall - cannot get call privilege - "
  6946. "exit 0x%08x", hr ));
  6947. return hr;
  6948. }
  6949. if ( priv != CP_OWNER )
  6950. {
  6951. LOG((TL_ERROR, "SelectCall - wrong call privilege - "
  6952. "exit TAPI_E_NOTOWNER"));
  6953. return TAPI_E_NOTOWNER;
  6954. }
  6955. //
  6956. // check to make sure the call state isn't disconnected
  6957. //
  6958. hr = pCall->get_CallState( & cs );
  6959. if ( FAILED(hr) )
  6960. {
  6961. LOG((TL_ERROR, "SelectCall - cannot get call state - "
  6962. "exit 0x%08x", hr ));
  6963. return hr;
  6964. }
  6965. if ( cs == CS_DISCONNECTED )
  6966. {
  6967. LOG((TL_ERROR, "SelectCall - call is disconnected - "
  6968. "exit TAPI_E_INVALCALLSTATE"));
  6969. return TAPI_E_INVALCALLSTATE;
  6970. }
  6971. //
  6972. // check if another call already selected
  6973. //
  6974. Lock();
  6975. if ( m_pCall != NULL )
  6976. {
  6977. LOG((TL_ERROR, "SelectCall - another call already "
  6978. "selected - exit TAPI_E_INUSE"));
  6979. Unlock();
  6980. return TAPI_E_INUSE;
  6981. }
  6982. //
  6983. // Make sure the phone is open with owner privilege.
  6984. //
  6985. if ( m_hPhone == NULL )
  6986. {
  6987. LOG((TL_ERROR, "SelectCall - phone is not open - "
  6988. "exit TAPI_E_PHONENOTOPEN"));
  6989. Unlock();
  6990. return TAPI_E_PHONENOTOPEN;
  6991. }
  6992. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  6993. {
  6994. LOG((TL_ERROR, "SelectCall - wrong phone privilege - "
  6995. "exit TAPI_E_NOTOWNER"));
  6996. Unlock();
  6997. return TAPI_E_NOTOWNER;
  6998. }
  6999. m_fDefaultTerminalsSelected = FALSE;
  7000. //
  7001. // Perform default terminal selection if the invoker wants it.
  7002. //
  7003. if ( fSelectDefaultTerminals != VARIANT_FALSE )
  7004. {
  7005. hr = SelectDefaultTerminalsOnCall( pCall );
  7006. if ( FAILED(hr) )
  7007. {
  7008. LOG((TL_ERROR, "SelectCall - failed to select "
  7009. "terminals - exit 0x%08x", hr ));
  7010. Unlock();
  7011. return hr;
  7012. }
  7013. //
  7014. // Set this flag so that we know to unselect the terminals from the call when
  7015. // the call is unselected
  7016. //
  7017. m_fDefaultTerminalsSelected = TRUE;
  7018. }
  7019. m_pCall = pCall;
  7020. m_pCall->AddRef();
  7021. Unlock();
  7022. //
  7023. // Now that the call is selected, get the callstate
  7024. // so we can call Automation_CallState
  7025. //
  7026. hr = pCall->get_CallState( & cs );
  7027. if ( FAILED(hr) )
  7028. {
  7029. LOG((TL_ERROR, "SelectCall - cannot get call state - "
  7030. "exit 0x%08x", hr ));
  7031. return hr;
  7032. }
  7033. Automation_CallState( pCall, cs, CEC_NONE );
  7034. LOG((TL_TRACE, "SelectCall - exit"));
  7035. return S_OK;
  7036. }
  7037. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7038. //
  7039. //
  7040. //
  7041. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7042. HRESULT
  7043. CPhone::InternalUnselectCall(
  7044. IN ITCallInfo * pCall
  7045. )
  7046. {
  7047. HRESULT hr;
  7048. LOG((TL_TRACE, "InternalUnselectCall - enter"));
  7049. Lock();
  7050. if ( pCall != m_pCall )
  7051. {
  7052. LOG((TL_ERROR, "InternalUnselectCall - call was not selected; "
  7053. "exit TAPI_E_CALLNOTSELECTED"));
  7054. Unlock();
  7055. return TAPI_E_CALLNOTSELECTED;
  7056. }
  7057. //
  7058. // Make sure the phone is open with owner privilege
  7059. //
  7060. if ( m_hPhone == NULL )
  7061. {
  7062. LOG((TL_ERROR, "InternalUnselectCall - phone is not open - "
  7063. "exit TAPI_E_PHONENOTOPEN"));
  7064. Unlock();
  7065. return TAPI_E_PHONENOTOPEN;
  7066. }
  7067. if ( m_dwPrivilege != PHONEPRIVILEGE_OWNER )
  7068. {
  7069. LOG((TL_ERROR, "InternalUnselectCall - wrong phone privilege - "
  7070. "exit TAPI_E_NOTOWNER"));
  7071. Unlock();
  7072. return TAPI_E_NOTOWNER;
  7073. }
  7074. //
  7075. // If we selected the default terminals on the call when the call was selected on this phone,
  7076. // then we need to unselect the default terminals from the call.
  7077. //
  7078. if ( m_fDefaultTerminalsSelected == TRUE )
  7079. {
  7080. hr = UnselectDefaultTerminalsOnCall( pCall );
  7081. if ( FAILED(hr) )
  7082. {
  7083. LOG((TL_ERROR, "InternalUnselectCall - UnselectDefaultTerminalsOnCall %p failed - %lx", pCall, hr ));
  7084. // If we fail here then maybe the app already unselected the terminals. In any case
  7085. // just continue...
  7086. }
  7087. m_fDefaultTerminalsSelected = FALSE;
  7088. }
  7089. //
  7090. // Release our reference to the call.
  7091. //
  7092. m_pCall->Release();
  7093. m_pCall = NULL;
  7094. LOG((TL_TRACE, "InternalUnselectCall - exit S_OK"));
  7095. Unlock();
  7096. return S_OK;
  7097. }
  7098. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7099. //
  7100. //
  7101. //
  7102. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7103. STDMETHODIMP
  7104. CPhone::UnselectCall(
  7105. IN ITCallInfo * pCall
  7106. )
  7107. {
  7108. HRESULT hr;
  7109. LOG((TL_TRACE, "UnselectCall - enter"));
  7110. //
  7111. // Check arguments.
  7112. //
  7113. if (IsBadReadPtr(pCall, sizeof( ITCallInfo ) ) )
  7114. {
  7115. LOG((TL_ERROR, "UnselectCall - "
  7116. "returning E_POINTER"));
  7117. return E_POINTER;
  7118. }
  7119. hr = InternalUnselectCall( pCall );
  7120. if ( FAILED(hr) )
  7121. {
  7122. LOG((TL_ERROR, "UnselectCall - "
  7123. "InternalUnselectCall failed 0x%lx", hr));
  7124. return hr;
  7125. }
  7126. EnterCriticalSection(&m_csAutomatedPhoneState);
  7127. if (m_fPhoneHandlingEnabled)
  7128. {
  7129. switch(m_AutomatedPhoneState)
  7130. {
  7131. case APS_ONHOOK_RINGING_IN:
  7132. case APS_ONHOOK_RINGING_OUT:
  7133. case APS_ONHOOK_CONNECTED:
  7134. {
  7135. //
  7136. // Stop the ringer
  7137. //
  7138. if (m_fRinger == TRUE)
  7139. {
  7140. StopRinger();
  7141. }
  7142. m_AutomatedPhoneState = APS_ONHOOK_IDLE;
  7143. }
  7144. break;
  7145. case APS_OFFHOOK_RINGING_OUT:
  7146. case APS_OFFHOOK_CALL_INIT:
  7147. case APS_OFFHOOK_CONNECTED:
  7148. {
  7149. //
  7150. // Stop any playing tone
  7151. //
  7152. if (m_Tone != PT_SILENCE)
  7153. {
  7154. StopTone();
  7155. }
  7156. m_AutomatedPhoneState = APS_OFFHOOK_DEAD_LINE;
  7157. }
  7158. break;
  7159. }
  7160. } //m_fPhoneHandlingEnabled
  7161. LeaveCriticalSection(&m_csAutomatedPhoneState);
  7162. LOG((TL_TRACE, "UnselectCall - exit S_OK"));
  7163. return S_OK;
  7164. }
  7165. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7166. //
  7167. //
  7168. //
  7169. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7170. STDMETHODIMP
  7171. CPhone::EnumerateSelectedCalls(
  7172. OUT IEnumCall ** ppCallEnum
  7173. )
  7174. {
  7175. HRESULT hr = S_OK;
  7176. LOG((TL_TRACE, "EnumerateSelectedCalls enter" ));
  7177. LOG((TL_TRACE, " ppCallEnum----->%p", ppCallEnum ));
  7178. //
  7179. // Check arguments.
  7180. //
  7181. if (TAPIIsBadWritePtr(ppCallEnum, sizeof( IEnumCall * ) ) )
  7182. {
  7183. LOG((TL_ERROR, "EnumerateSelectedCalls - "
  7184. "returning E_POINTER"));
  7185. return E_POINTER;
  7186. }
  7187. //
  7188. // Create and initialize the enumerator.
  7189. //
  7190. CComObject< CTapiEnum< IEnumCall, ITCallInfo, &IID_IEnumCall > > * p;
  7191. hr = CComObject< CTapiEnum< IEnumCall, ITCallInfo, &IID_IEnumCall > >
  7192. ::CreateInstance( &p );
  7193. if ( hr != S_OK ) // CreateInstance deletes object on S_FALSE
  7194. {
  7195. LOG((TL_ERROR, "EnumerateSelectedCalls - "
  7196. "could not create enum - "
  7197. "exit 0x%08x", hr ));
  7198. return hr;
  7199. }
  7200. // Initialize adds a reference to p
  7201. hr = p->Initialize( );
  7202. if ( FAILED(hr) )
  7203. {
  7204. delete p;
  7205. LOG((TL_ERROR, "EnumerateSelectedCalls - "
  7206. "could not init enum - "
  7207. "exit 0x%08x", hr ));
  7208. return hr;
  7209. }
  7210. //
  7211. // Add our single call to the enumerator, if we have one.
  7212. //
  7213. Lock();
  7214. //
  7215. // Make sure the phone is open
  7216. //
  7217. if ( m_hPhone == NULL )
  7218. {
  7219. LOG((TL_ERROR, "EnumerateSelectedCalls - phone is not open - "
  7220. "exit TAPI_E_PHONENOTOPEN"));
  7221. Unlock();
  7222. p->Release();
  7223. return TAPI_E_PHONENOTOPEN;
  7224. }
  7225. if ( m_pCall != NULL )
  7226. {
  7227. hr = p->Add( m_pCall );
  7228. }
  7229. else
  7230. {
  7231. hr = S_OK;
  7232. }
  7233. Unlock();
  7234. //
  7235. // Return the enum if we succeeded, else throw it away.
  7236. //
  7237. if ( SUCCEEDED(hr) )
  7238. {
  7239. *ppCallEnum = p;
  7240. LOG((TL_TRACE, "EnumerateSelectedCalls exit - "
  7241. "hr = 0x%08x", hr ));
  7242. }
  7243. else
  7244. {
  7245. p->Release();
  7246. LOG((TL_ERROR, "EnumerateSelectedCalls - "
  7247. "could not add call to enum - "
  7248. "exit 0x%08x", hr ));
  7249. }
  7250. return hr;
  7251. }
  7252. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7253. //
  7254. //
  7255. //
  7256. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  7257. STDMETHODIMP
  7258. CPhone::get_SelectedCalls(
  7259. OUT VARIANT * pVariant
  7260. )
  7261. {
  7262. HRESULT hr = S_OK;
  7263. LOG((TL_TRACE, "get_SelectedCalls enter" ));
  7264. LOG((TL_TRACE, " pVariant----->%p", pVariant ));
  7265. //
  7266. // Check arguments.
  7267. //
  7268. if ( TAPIIsBadWritePtr(pVariant, sizeof( pVariant ) ) )
  7269. {
  7270. LOG((TL_ERROR, "get_SelectedCalls - "
  7271. "returning E_POINTER"));
  7272. return E_POINTER;
  7273. }
  7274. //
  7275. // Create an array containing no calls or our single call. This
  7276. // type of array does not keep any COM refcounts. We will pass this
  7277. // array into the collection object initialization, and then we will
  7278. // shut down the array.
  7279. //
  7280. CTArray<ITCallInfo *> aCalls;
  7281. BOOL fResult;
  7282. Lock();
  7283. //
  7284. // Make sure the phone is open
  7285. //
  7286. if ( m_hPhone == NULL )
  7287. {
  7288. LOG((TL_ERROR, "get_SelectedCalls - phone is not open - "
  7289. "exit TAPI_E_PHONENOTOPEN"));
  7290. Unlock();
  7291. aCalls.Shutdown();
  7292. return TAPI_E_PHONENOTOPEN;
  7293. }
  7294. if ( m_pCall != NULL )
  7295. {
  7296. fResult = aCalls.Add( m_pCall );
  7297. }
  7298. else
  7299. {
  7300. fResult = TRUE;
  7301. }
  7302. Unlock();
  7303. if ( fResult == FALSE )
  7304. {
  7305. LOG((TL_ERROR, "get_SelectedCalls - "
  7306. "could not add call to array; "
  7307. "exit E_OUTOFMEMORY" ));
  7308. return E_OUTOFMEMORY;
  7309. }
  7310. //
  7311. // Create and initialize the Collection.
  7312. //
  7313. CComObject< CTapiCollection< ITCallInfo > > * p;
  7314. hr = CComObject< CTapiCollection< ITCallInfo > >
  7315. ::CreateInstance( &p );
  7316. if ( hr != S_OK ) // CreateInstance deleted object on S_FALSE
  7317. {
  7318. LOG((TL_ERROR, "get_SelectedCalls - "
  7319. "could not create Collection - "
  7320. "exit 0x%08x", hr ));
  7321. aCalls.Shutdown();
  7322. return hr;
  7323. }
  7324. //
  7325. // Get the collection object's IDispatch interface.
  7326. //
  7327. IDispatch * pDisp;
  7328. hr = p->_InternalQueryInterface( IID_IDispatch,
  7329. (void **) & pDisp );
  7330. if ( FAILED(hr) )
  7331. {
  7332. LOG((TL_ERROR, "get_SelectedCalls - "
  7333. "could not get IDispatch interface" ));
  7334. delete p;
  7335. return hr;
  7336. }
  7337. hr = p->Initialize( aCalls );
  7338. aCalls.Shutdown();
  7339. if ( FAILED(hr) )
  7340. {
  7341. LOG((TL_ERROR, "get_SelectedCalls - "
  7342. "could not init Collection - "
  7343. "exit 0x%08x", hr ));
  7344. pDisp->Release();
  7345. return hr;
  7346. }
  7347. //
  7348. // Put the collection object's IDispatch pointer into the variant.
  7349. //
  7350. VariantInit(pVariant);
  7351. pVariant->vt = VT_DISPATCH;
  7352. pVariant->pdispVal = pDisp;
  7353. LOG((TL_TRACE, "get_SelectedCalls exit - "
  7354. "hr = 0x%08x", hr ));
  7355. return hr;
  7356. }
  7357. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7358. // Class : CPhone
  7359. // Interface : ITPhone
  7360. // Method : DeviceSpecific
  7361. //
  7362. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7363. HRESULT CPhone::DeviceSpecific(
  7364. IN BYTE *pbDataArray,
  7365. IN DWORD dwSize
  7366. )
  7367. {
  7368. LOG((TL_TRACE, "DeviceSpecific - enter"));
  7369. //
  7370. // check if arguments are any good
  7371. //
  7372. if ( NULL == pbDataArray )
  7373. {
  7374. LOG((TL_ERROR, "DeviceSpecific - pbDataArray is NULL. E_INVALIDARG"));
  7375. return E_INVALIDARG;
  7376. }
  7377. if ( 0 == dwSize )
  7378. {
  7379. LOG((TL_ERROR, "DeviceSpecific - dwSize is 0. E_INVALIDARG"));
  7380. return E_INVALIDARG;
  7381. }
  7382. //
  7383. // check if the buffer is valid
  7384. //
  7385. if ( IsBadReadPtr(pbDataArray, dwSize) )
  7386. {
  7387. LOG((TL_ERROR, "DeviceSpecific - bad array passed in [%p] of size %ld", pbDataArray, dwSize));
  7388. return E_POINTER;
  7389. }
  7390. //
  7391. // starting to access data members. lock.
  7392. //
  7393. Lock();
  7394. //
  7395. // see if the phone is open
  7396. //
  7397. if ( m_hPhone == NULL )
  7398. {
  7399. LOG((TL_ERROR,
  7400. "DeviceSpecific - phone not open. TAPI_E_PHONENOTOPEN"));
  7401. Unlock();
  7402. return TAPI_E_PHONENOTOPEN;
  7403. }
  7404. //
  7405. // keep the phone handle
  7406. //
  7407. HPHONE hPhone = m_hPhone;
  7408. Unlock();
  7409. //
  7410. // make the tapisrv call. if hPhone becomes invalid, the call will simply
  7411. // fail. this is ok.
  7412. //
  7413. HRESULT hr = phoneDevSpecific(hPhone, pbDataArray, dwSize);
  7414. LOG((TL_TRACE, "DeviceSpecific - exit. hr = %lx", hr));
  7415. return hr;
  7416. }
  7417. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7418. // Class : CPhone
  7419. // Interface : ITPhone
  7420. // Method : DeviceSpecificVariant
  7421. //
  7422. // this is the scriptable version of DeviceSpecific
  7423. //
  7424. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7425. HRESULT CPhone::DeviceSpecificVariant(
  7426. IN VARIANT varDevSpecificByteArray
  7427. )
  7428. {
  7429. LOG((TL_TRACE, "DeviceSpecificVariant - enter"));
  7430. //
  7431. // extract buffer from the variant
  7432. //
  7433. DWORD dwByteArraySize = 0;
  7434. BYTE *pBuffer = NULL;
  7435. HRESULT hr = E_FAIL;
  7436. hr = MakeBufferFromVariant(varDevSpecificByteArray, &dwByteArraySize, &pBuffer);
  7437. if (FAILED(hr))
  7438. {
  7439. LOG((TL_TRACE, "DeviceSpecificVariant - MakeBufferFromVariant failed. hr = %lx", hr));
  7440. return hr;
  7441. }
  7442. //
  7443. // call the non-scriptable version and pass it the nonscriptable implementation
  7444. //
  7445. hr = DeviceSpecific(pBuffer, dwByteArraySize);
  7446. //
  7447. // success or failure, free the buffer allocated by MakeBufferFromVariant
  7448. //
  7449. ClientFree(pBuffer);
  7450. pBuffer = NULL;
  7451. //
  7452. // log rc and exit
  7453. //
  7454. LOG((TL_TRACE, "DeviceSpecificVariant - exit. hr = %lx", hr));
  7455. return hr;
  7456. }
  7457. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7458. // Class : CPhone
  7459. // Interface : ITPhone
  7460. // Method : NegotiateExtVersion
  7461. //
  7462. //
  7463. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7464. HRESULT CPhone::NegotiateExtVersion (
  7465. IN long lLowVersion,
  7466. IN long lHighVersion,
  7467. OUT long *plExtVersion
  7468. )
  7469. {
  7470. LOG((TL_TRACE, "NegotiateExtVersion - enter"));
  7471. //
  7472. // make sure the out parameter is writable
  7473. //
  7474. if (IsBadWritePtr(plExtVersion, sizeof(long)) )
  7475. {
  7476. LOG((TL_ERROR, "NegotiateExtVersion - output arg [%p] not writeable", plExtVersion));
  7477. return E_POINTER;
  7478. }
  7479. Lock();
  7480. //
  7481. // make a call to tapisrv
  7482. //
  7483. DWORD dwNegotiatedVersion = 0;
  7484. LONG lResult = phoneNegotiateExtVersion(m_hPhoneApp,
  7485. m_dwDeviceID,
  7486. m_dwAPIVersion,
  7487. lLowVersion,
  7488. lHighVersion,
  7489. &dwNegotiatedVersion );
  7490. Unlock();
  7491. HRESULT hr = mapTAPIErrorCode(lResult);
  7492. //
  7493. // return the value on success
  7494. //
  7495. if ( SUCCEEDED(hr) )
  7496. {
  7497. LOG((TL_TRACE, "NegotiateExtVersion - negotiated version %ld", dwNegotiatedVersion));
  7498. *plExtVersion = dwNegotiatedVersion;
  7499. }
  7500. LOG((TL_TRACE, "NegotiateExtVersion - exit. hr = %lx", hr));
  7501. return hr;
  7502. }
  7503. //////////////////////////////////////////////////////////////////////////////
  7504. //////////////////////////////////////////////////////////////////////////////
  7505. //
  7506. // ITPhoneEvent methods
  7507. //
  7508. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7509. //
  7510. // FireEvent
  7511. //
  7512. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7513. HRESULT
  7514. CPhoneEvent::FireEvent(
  7515. CPhone * pCPhone,
  7516. PHONE_EVENT Event,
  7517. PHONE_BUTTON_STATE ButtonState,
  7518. PHONE_HOOK_SWITCH_STATE HookSwitchState,
  7519. PHONE_HOOK_SWITCH_DEVICE HookSwitchDevice,
  7520. DWORD dwRingMode,
  7521. DWORD dwButtonLampId,
  7522. PWSTR pNumber,
  7523. ITCallInfo * pCallInfo
  7524. )
  7525. {
  7526. HRESULT hr = S_OK;
  7527. CComObject<CPhoneEvent> * p;
  7528. IDispatch * pDisp;
  7529. STATICLOG((TL_TRACE, "FireEvent enter" ));
  7530. //
  7531. // We have to filter Phoneevents because
  7532. // Tapisrv doesn't. Tapi3 receive always phone events
  7533. // and use them to keep alive the Phone object
  7534. //
  7535. CTAPI* pTapi = pCPhone->GetTapi();
  7536. if( pTapi == NULL )
  7537. {
  7538. STATICLOG((TL_ERROR, "Tapi object is invalid - %lx", E_UNEXPECTED));
  7539. return E_UNEXPECTED;
  7540. }
  7541. long nFilterMask = 0;
  7542. pTapi->get_EventFilter( &nFilterMask );
  7543. if( (nFilterMask & TE_PHONEEVENT) == 0 )
  7544. {
  7545. //
  7546. // The user didn't set the mask for TE_PHONEEVENT
  7547. // so we don't fire the event to the application
  7548. //
  7549. STATICLOG((TL_INFO, "The user didn't set the mask for TE_PHONEEVENT."
  7550. " Don't fire the event to app - %lx", S_OK));
  7551. return S_OK;
  7552. }
  7553. //
  7554. // create event
  7555. //
  7556. hr = CComObject<CPhoneEvent>::CreateInstance( &p );
  7557. if ( S_OK != hr ) // CreateInstance deletes object on S_FALSE
  7558. {
  7559. STATICLOG((TL_ERROR, "Could not create PhoneEvent object - %lx", hr));
  7560. return hr;
  7561. }
  7562. //
  7563. // get idisp interface
  7564. //
  7565. hr = p->QueryInterface(
  7566. IID_IDispatch,
  7567. (void **)&pDisp
  7568. );
  7569. if ( FAILED(hr) )
  7570. {
  7571. STATICLOG((TL_ERROR, "Could not get disp interface of PhoneEvent object - %lx", hr));
  7572. delete p;
  7573. return hr;
  7574. }
  7575. //
  7576. // initialize
  7577. //
  7578. if (pNumber != NULL)
  7579. {
  7580. p->m_pNumber = SysAllocString( pNumber );
  7581. if (p->m_pNumber == NULL)
  7582. {
  7583. STATICLOG((TL_ERROR, "Out of memory allocating phone number"));
  7584. pDisp->Release();
  7585. return E_OUTOFMEMORY;
  7586. }
  7587. }
  7588. else
  7589. {
  7590. p->m_pNumber = NULL;
  7591. }
  7592. p->m_Event = Event;
  7593. p->m_pPhone = dynamic_cast<ITPhone *>(pCPhone);
  7594. p->m_pPhone->AddRef();
  7595. p->m_ButtonState = ButtonState;
  7596. p->m_HookSwitchState = HookSwitchState;
  7597. p->m_HookSwitchDevice = HookSwitchDevice;
  7598. p->m_dwRingMode = dwRingMode;
  7599. p->m_dwButtonLampId = dwButtonLampId;
  7600. p->m_pCallInfo = pCallInfo;
  7601. if (p->m_pCallInfo != NULL)
  7602. {
  7603. p->m_pCallInfo->AddRef();
  7604. }
  7605. #if DBG
  7606. p->m_pDebug = (PWSTR) ClientAlloc( 1 );
  7607. #endif
  7608. //
  7609. // get callback
  7610. //
  7611. //
  7612. // fire event
  7613. //
  7614. (pCPhone->GetTapi())->Event(
  7615. TE_PHONEEVENT,
  7616. pDisp
  7617. );
  7618. //
  7619. // release stuff
  7620. //
  7621. pDisp->Release();
  7622. STATICLOG((TL_TRACE, "FireEvent exit - return S_OK" ));
  7623. return S_OK;
  7624. }
  7625. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7626. //
  7627. // finalrelease
  7628. //
  7629. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7630. void
  7631. CPhoneEvent::FinalRelease()
  7632. {
  7633. LOG((TL_INFO, "CPhoneEvent - FinalRelease"));
  7634. m_pPhone->Release();
  7635. m_pPhone = NULL;
  7636. if (m_pCallInfo != NULL)
  7637. {
  7638. m_pCallInfo->Release();
  7639. m_pCallInfo = NULL;
  7640. }
  7641. if (m_pNumber != NULL)
  7642. {
  7643. SysFreeString(m_pNumber);
  7644. m_pNumber = NULL;
  7645. }
  7646. #if DBG
  7647. ClientFree( m_pDebug );
  7648. m_pDebug = NULL;
  7649. #endif
  7650. }
  7651. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7652. //
  7653. // get_Phone
  7654. //
  7655. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7656. STDMETHODIMP
  7657. CPhoneEvent::get_Phone(
  7658. ITPhone ** ppPhone
  7659. )
  7660. {
  7661. if (TAPIIsBadWritePtr(ppPhone , sizeof(ITPhone *) ) )
  7662. {
  7663. LOG((TL_ERROR, "get_Phone - bad pointer"));
  7664. return E_POINTER;
  7665. }
  7666. *ppPhone = m_pPhone;
  7667. (*ppPhone)->AddRef();
  7668. return S_OK;
  7669. }
  7670. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7671. //
  7672. // get_Event
  7673. //
  7674. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7675. STDMETHODIMP
  7676. CPhoneEvent::get_Event(
  7677. PHONE_EVENT * pEvent
  7678. )
  7679. {
  7680. if (TAPIIsBadWritePtr(pEvent , sizeof(PHONE_EVENT) ) )
  7681. {
  7682. LOG((TL_ERROR, "get_Event - bad pointer"));
  7683. return E_POINTER;
  7684. }
  7685. *pEvent = m_Event;
  7686. return S_OK;
  7687. }
  7688. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7689. //
  7690. // get_ButtonState
  7691. //
  7692. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7693. STDMETHODIMP
  7694. CPhoneEvent::get_ButtonState(
  7695. PHONE_BUTTON_STATE * pState
  7696. )
  7697. {
  7698. if (TAPIIsBadWritePtr(pState , sizeof(PHONE_BUTTON_STATE) ) )
  7699. {
  7700. LOG((TL_ERROR, "get_ButtonState - bad pointer"));
  7701. return E_POINTER;
  7702. }
  7703. if (m_Event != PE_BUTTON)
  7704. {
  7705. LOG((TL_ERROR, "get_ButtonState - wrong event"));
  7706. return TAPI_E_WRONGEVENT;
  7707. }
  7708. *pState = m_ButtonState;
  7709. return S_OK;
  7710. }
  7711. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7712. //
  7713. // get_HookSwitchState
  7714. //
  7715. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7716. STDMETHODIMP
  7717. CPhoneEvent::get_HookSwitchState(
  7718. PHONE_HOOK_SWITCH_STATE * pState
  7719. )
  7720. {
  7721. if (TAPIIsBadWritePtr(pState , sizeof(PHONE_HOOK_SWITCH_STATE) ) )
  7722. {
  7723. LOG((TL_ERROR, "get_HookSwitchState - bad pointer"));
  7724. return E_POINTER;
  7725. }
  7726. if (m_Event != PE_HOOKSWITCH)
  7727. {
  7728. LOG((TL_ERROR, "get_HookSwitchState - wrong event"));
  7729. return TAPI_E_WRONGEVENT;
  7730. }
  7731. *pState = m_HookSwitchState;
  7732. return S_OK;
  7733. }
  7734. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7735. //
  7736. // get_HookSwitchDevice
  7737. //
  7738. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7739. STDMETHODIMP
  7740. CPhoneEvent::get_HookSwitchDevice(
  7741. PHONE_HOOK_SWITCH_DEVICE * pDevice
  7742. )
  7743. {
  7744. if (TAPIIsBadWritePtr(pDevice , sizeof(PHONE_HOOK_SWITCH_DEVICE) ) )
  7745. {
  7746. LOG((TL_ERROR, "get_HookSwitchDevice - bad pointer"));
  7747. return E_POINTER;
  7748. }
  7749. if (m_Event != PE_HOOKSWITCH)
  7750. {
  7751. LOG((TL_ERROR, "get_HookSwitchDevice - wrong event"));
  7752. return TAPI_E_WRONGEVENT;
  7753. }
  7754. *pDevice = m_HookSwitchDevice;
  7755. return S_OK;
  7756. }
  7757. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7758. //
  7759. // get_RingMode
  7760. //
  7761. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7762. STDMETHODIMP
  7763. CPhoneEvent::get_RingMode(
  7764. long * plRingMode
  7765. )
  7766. {
  7767. if (TAPIIsBadWritePtr(plRingMode , sizeof(long) ) )
  7768. {
  7769. LOG((TL_ERROR, "get_RingMode - bad pointer"));
  7770. return E_POINTER;
  7771. }
  7772. if (m_Event != PE_RINGMODE)
  7773. {
  7774. LOG((TL_ERROR, "get_RingMode - wrong event"));
  7775. return TAPI_E_WRONGEVENT;
  7776. }
  7777. *plRingMode = m_dwRingMode;
  7778. return S_OK;
  7779. }
  7780. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7781. //
  7782. // get_ButtonLampId
  7783. //
  7784. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7785. STDMETHODIMP
  7786. CPhoneEvent::get_ButtonLampId(
  7787. long *plButtonLampId
  7788. )
  7789. {
  7790. if (TAPIIsBadWritePtr(plButtonLampId , sizeof(long) ) )
  7791. {
  7792. LOG((TL_ERROR, "get_ButtonLampId - bad pointer"));
  7793. return E_POINTER;
  7794. }
  7795. if ((m_Event != PE_LAMPMODE) && (m_Event != PE_BUTTON))
  7796. {
  7797. LOG((TL_ERROR, "get_ButtonLampId - wrong event"));
  7798. return TAPI_E_WRONGEVENT;
  7799. }
  7800. *plButtonLampId = m_dwButtonLampId;
  7801. return S_OK;
  7802. }
  7803. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7804. //
  7805. // get_NumberGathered
  7806. //
  7807. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7808. STDMETHODIMP
  7809. CPhoneEvent::get_NumberGathered(
  7810. BSTR * ppNumber
  7811. )
  7812. {
  7813. if (TAPIIsBadWritePtr(ppNumber , sizeof(BSTR) ) )
  7814. {
  7815. LOG((TL_ERROR, "get_NumberGathered - bad pointer"));
  7816. return E_POINTER;
  7817. }
  7818. if (m_Event != PE_NUMBERGATHERED)
  7819. {
  7820. LOG((TL_ERROR, "get_NumberGathered - wrong event"));
  7821. return TAPI_E_WRONGEVENT;
  7822. }
  7823. *ppNumber = SysAllocString(m_pNumber);
  7824. if (*ppNumber == NULL)
  7825. {
  7826. LOG((TL_ERROR, "get_NumberGathered - out of memory"));
  7827. return E_OUTOFMEMORY;
  7828. }
  7829. return S_OK;
  7830. }
  7831. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7832. //
  7833. // get_Call
  7834. //
  7835. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7836. STDMETHODIMP
  7837. CPhoneEvent::get_Call(
  7838. ITCallInfo ** ppCallInfo
  7839. )
  7840. {
  7841. if (TAPIIsBadWritePtr(ppCallInfo , sizeof(ITCallInfo *) ) )
  7842. {
  7843. LOG((TL_ERROR, "get_Call - bad pointer"));
  7844. return E_POINTER;
  7845. }
  7846. if ((m_Event != PE_ANSWER) &&
  7847. (m_Event != PE_DISCONNECT))
  7848. {
  7849. LOG((TL_ERROR, "get_Call - wrong event"));
  7850. return TAPI_E_WRONGEVENT;
  7851. }
  7852. if ( m_pCallInfo == NULL )
  7853. {
  7854. LOG((TL_ERROR, "get_Call - NULL call pointer"));
  7855. return E_UNEXPECTED;
  7856. }
  7857. *ppCallInfo = m_pCallInfo;
  7858. (*ppCallInfo)->AddRef();
  7859. return S_OK;
  7860. }
  7861. ///////////////////////////////////////////////////////////////////////////////
  7862. //
  7863. // CPhoneDevSpecificEvent
  7864. //
  7865. // static
  7866. HRESULT CPhoneDevSpecificEvent::FireEvent( CPhone * pCPhone,
  7867. long l1,
  7868. long l2,
  7869. long l3
  7870. )
  7871. {
  7872. STATICLOG((TL_INFO, "CPhoneDevSpecificEvent::FireEvent - enter"));
  7873. //
  7874. // try to create the event
  7875. //
  7876. CComObject<CPhoneDevSpecificEvent> *pEventObject = NULL;
  7877. HRESULT hr = CComObject<CPhoneDevSpecificEvent>::CreateInstance(&pEventObject);
  7878. if ( FAILED(hr) )
  7879. {
  7880. STATICLOG((TL_ERROR,
  7881. "CPhoneDevSpecificEvent::FireEvent - failed to create CPhoneDevSpecificEvent. hr = %lx",
  7882. hr));
  7883. return hr;
  7884. }
  7885. //
  7886. // initialize the event with the data we received
  7887. //
  7888. //
  7889. // get ITPhone from CPhone we received
  7890. //
  7891. hr = pCPhone->_InternalQueryInterface(IID_ITPhone, (void**)(&(pEventObject->m_pPhone)) );
  7892. if (FAILED(hr))
  7893. {
  7894. STATICLOG((TL_ERROR,
  7895. "CPhoneDevSpecificEvent::FireEvent - failed to get ITPhone interface from phone. hr = %lx",
  7896. hr));
  7897. delete pEventObject;
  7898. return hr;
  7899. }
  7900. //
  7901. // keep the actual data
  7902. //
  7903. pEventObject->m_l1 = l1;
  7904. pEventObject->m_l2 = l2;
  7905. pEventObject->m_l3 = l3;
  7906. #if DBG
  7907. pEventObject->m_pDebug = (PWSTR) ClientAlloc( 1 );
  7908. #endif
  7909. //
  7910. // get event's idispatch interface
  7911. //
  7912. IDispatch *pDispatch = NULL;
  7913. hr = pEventObject->QueryInterface( IID_IDispatch,
  7914. (void **)&pDispatch );
  7915. if ( FAILED(hr) )
  7916. {
  7917. STATICLOG((TL_ERROR,
  7918. "CPhoneDevSpecificEvent::FireEvent - Could not get disp interface of AddressEvent object %lx",
  7919. hr));
  7920. //
  7921. // undo the QI we have performed earlier
  7922. //
  7923. pEventObject->m_pPhone->Release();
  7924. pEventObject->m_pPhone = NULL;
  7925. //
  7926. // delete the event object
  7927. //
  7928. delete pEventObject;
  7929. return hr;
  7930. }
  7931. //
  7932. // from this point on, we will be using events pDispatch
  7933. //
  7934. pEventObject = NULL;
  7935. //
  7936. // get callback
  7937. //
  7938. //
  7939. // fire event to tapi
  7940. //
  7941. hr = (pCPhone->GetTapi())->Event( TE_PHONEDEVSPECIFIC, pDispatch);
  7942. //
  7943. // succeeded or not, we no longer need a reference to the event object
  7944. //
  7945. pDispatch->Release();
  7946. pDispatch = NULL;
  7947. STATICLOG((TL_INFO, "CPhoneDevSpecificEvent::FireEvent - exit. hr = %lx", hr));
  7948. return hr;
  7949. }
  7950. CPhoneDevSpecificEvent::CPhoneDevSpecificEvent()
  7951. :m_pPhone(NULL)
  7952. {
  7953. LOG((TL_INFO, "CPhoneDevSpecificEvent - enter"));
  7954. #if DBG
  7955. m_pDebug = NULL;
  7956. #endif
  7957. LOG((TL_INFO, "CPhoneDevSpecificEvent - exit"));
  7958. }
  7959. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7960. //
  7961. // finalrelease
  7962. //
  7963. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7964. void CPhoneDevSpecificEvent::FinalRelease()
  7965. {
  7966. LOG((TL_INFO, "FinalRelease - enter"));
  7967. if (NULL != m_pPhone)
  7968. {
  7969. m_pPhone->Release();
  7970. m_pPhone = NULL;
  7971. }
  7972. else
  7973. {
  7974. //
  7975. // we must have a phone -- if not, there is a bug in our code
  7976. //
  7977. _ASSERTE(FALSE);
  7978. }
  7979. #if DBG
  7980. ClientFree( m_pDebug );
  7981. #endif
  7982. LOG((TL_INFO, "FinalRelease - exit"));
  7983. }
  7984. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7985. //
  7986. // get_Phone
  7987. //
  7988. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7989. STDMETHODIMP
  7990. CPhoneDevSpecificEvent::get_Phone(
  7991. ITPhone ** ppPhone
  7992. )
  7993. {
  7994. LOG((TL_TRACE, "get_Phone - enter"));
  7995. //
  7996. // good out pointer?
  7997. //
  7998. if (TAPIIsBadWritePtr(ppPhone , sizeof(ITPhone *) ) )
  7999. {
  8000. LOG((TL_ERROR, "get_Phone - bad pointer at [%p]", ppPhone));
  8001. return E_POINTER;
  8002. }
  8003. //
  8004. // return addreff'd address
  8005. //
  8006. *ppPhone = m_pPhone;
  8007. (*ppPhone)->AddRef();
  8008. LOG((TL_TRACE, "get_Phone- enter. phone[%p]", (*ppPhone) ));
  8009. return S_OK;
  8010. }
  8011. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8012. //
  8013. // get_lParam1
  8014. //
  8015. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8016. STDMETHODIMP CPhoneDevSpecificEvent::get_lParam1( long *pl1 )
  8017. {
  8018. LOG((TL_TRACE, "get_lParam1 - enter"));
  8019. //
  8020. // good out pointer?
  8021. //
  8022. if (TAPIIsBadWritePtr(pl1, sizeof(long) ) )
  8023. {
  8024. LOG((TL_ERROR, "get_lParam1 - bad pointer at %p", pl1));
  8025. return E_POINTER;
  8026. }
  8027. //
  8028. // log and return the value
  8029. //
  8030. *pl1 = m_l1;
  8031. LOG((TL_TRACE, "get_lParam1 - exit. p1[%ld]", *pl1));
  8032. return S_OK;
  8033. }
  8034. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8035. //
  8036. // get_lParam2
  8037. //
  8038. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8039. STDMETHODIMP CPhoneDevSpecificEvent::get_lParam2( long *pl2 )
  8040. {
  8041. LOG((TL_TRACE, "get_lParam2 - enter"));
  8042. //
  8043. // good out pointer?
  8044. //
  8045. if (TAPIIsBadWritePtr(pl2, sizeof(long) ) )
  8046. {
  8047. LOG((TL_ERROR, "get_lParam2 - bad pointer at %p", pl2));
  8048. return E_POINTER;
  8049. }
  8050. //
  8051. // log and return the value
  8052. //
  8053. *pl2 = m_l2;
  8054. LOG((TL_TRACE, "get_lParam2 - exit. p2[%ld]", *pl2));
  8055. return S_OK;
  8056. }
  8057. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8058. //
  8059. // get_lParam3
  8060. //
  8061. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8062. STDMETHODIMP CPhoneDevSpecificEvent::get_lParam3( long *pl3 )
  8063. {
  8064. LOG((TL_TRACE, "get_lParam3 - enter"));
  8065. //
  8066. // good out pointer?
  8067. //
  8068. if ( TAPIIsBadWritePtr(pl3, sizeof(long)) )
  8069. {
  8070. LOG((TL_ERROR, "get_lParam3 - bad pointer at %p", pl3));
  8071. return E_POINTER;
  8072. }
  8073. //
  8074. // log and return the value
  8075. //
  8076. *pl3 = m_l3;
  8077. LOG((TL_TRACE, "get_lParam3 - exit. p3[%ld]", *pl3));
  8078. return S_OK;
  8079. }