Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

590 lines
13 KiB

  1. /*++
  2. Copyright (c) 1998 - 1999 Microsoft Corporation
  3. Module Name:
  4. stream.cpp
  5. Abstract:
  6. implementation of the CStream objects
  7. these objects are used when a TSP has phone devices that have
  8. been made into terminals
  9. Author:
  10. mquinton - 9/15/98
  11. Notes:
  12. optional-notes
  13. Revision History:
  14. --*/
  15. #include "stdafx.h"
  16. #include "priviids.h"
  17. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  18. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  19. //
  20. // CStream implementation
  21. //
  22. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  23. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  24. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  25. //
  26. // CStream::get_MediaType
  27. //
  28. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  29. STDMETHODIMP
  30. CStream::get_MediaType(long * plMediaType)
  31. {
  32. LOG((TL_TRACE, "get_MediaType - enter"));
  33. if ( TAPIIsBadWritePtr( plMediaType, sizeof( long ) ) )
  34. {
  35. LOG((TL_ERROR, "get_MediaType - bad pointer"));
  36. return E_POINTER;
  37. }
  38. Lock();
  39. *plMediaType = m_lMediaType;
  40. Unlock();
  41. LOG((TL_TRACE, "get_MediaType - exit - return SUCCESS"));
  42. return S_OK;
  43. }
  44. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  45. //
  46. // CStream::get_Direction
  47. //
  48. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  49. STDMETHODIMP
  50. CStream::get_Direction(TERMINAL_DIRECTION * pTD)
  51. {
  52. LOG((TL_TRACE, "get_Direction - enter"));
  53. if ( TAPIIsBadWritePtr( pTD, sizeof( TERMINAL_DIRECTION ) ) )
  54. {
  55. LOG((TL_ERROR, "get_Direction - bad pointer"));
  56. return E_POINTER;
  57. }
  58. Lock();
  59. *pTD = m_Dir;
  60. Unlock();
  61. LOG((TL_TRACE, "get_Direction - exit - return S_OK"));
  62. return S_OK;
  63. }
  64. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  65. //
  66. // CStream::get_Name
  67. //
  68. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  69. STDMETHODIMP
  70. CStream::get_Name(BSTR * ppName)
  71. {
  72. LOG((TL_TRACE, "get_Name - enter"));
  73. if ( TAPIIsBadWritePtr( ppName, sizeof( BSTR ) ) )
  74. {
  75. LOG((TL_ERROR, "get_Name - bad pointer"));
  76. return E_POINTER;
  77. }
  78. Lock();
  79. *ppName = SysAllocString( m_pName );
  80. Unlock();
  81. if ( ( NULL == *ppName ) && ( NULL != m_pName ) )
  82. {
  83. LOG((TL_TRACE, "get_Name - SysAllocString Failed" ));
  84. return E_OUTOFMEMORY;
  85. }
  86. LOG((TL_TRACE, "get_Name - exit - return S_OK"));
  87. return S_OK;
  88. }
  89. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  90. //
  91. // CStream::StartStream
  92. //
  93. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  94. STDMETHODIMP
  95. CStream::StartStream(void)
  96. {
  97. HRESULT hr = E_NOTIMPL;
  98. LOG((TL_TRACE, "StartStream - enter"));
  99. LOG((TL_TRACE, "StartStream - exit - return %lx", hr));
  100. return hr;
  101. }
  102. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  103. //
  104. // CStream::PauseStream
  105. //
  106. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  107. STDMETHODIMP
  108. CStream::PauseStream(void)
  109. {
  110. HRESULT hr = E_NOTIMPL;
  111. LOG((TL_TRACE, "PauseStream - enter"));
  112. LOG((TL_TRACE, "PauseStream - exit - return %lx", hr));
  113. return hr;
  114. }
  115. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  116. //
  117. // CStream::StopStream
  118. //
  119. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  120. STDMETHODIMP
  121. CStream::StopStream(void)
  122. {
  123. HRESULT hr = E_NOTIMPL;
  124. LOG((TL_TRACE, "StopStream - enter"));
  125. LOG((TL_TRACE, "StopStream - exit - return %lx", hr));
  126. return hr;
  127. }
  128. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  129. //
  130. // CStream::SelectTerminal
  131. //
  132. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  133. STDMETHODIMP
  134. CStream::SelectTerminal(ITTerminal * pTerminal)
  135. {
  136. HRESULT hr = S_OK;
  137. ITTerminalPrivate * pTerminalPrivate;
  138. long lMediaType;
  139. TERMINAL_DIRECTION Dir;
  140. LOG((TL_TRACE, "SelectTerminal - enter"));
  141. if ( IsBadReadPtr( pTerminal, sizeof( ITTerminal ) ) )
  142. {
  143. LOG((TL_ERROR, "SelectTerminal - bad pTerminal"));
  144. return E_INVALIDARG;
  145. }
  146. hr = pTerminal->QueryInterface(
  147. IID_ITTerminalPrivate,
  148. (void**)&pTerminalPrivate
  149. );
  150. if ( !SUCCEEDED(hr) )
  151. {
  152. LOG((TL_ERROR, "SelectTerminal - Terminal not valid on this address"));
  153. return TAPI_E_INVALIDTERMINAL;
  154. }
  155. hr = pTerminal->get_MediaType( &lMediaType );
  156. if ( SUCCEEDED(hr) )
  157. {
  158. hr = pTerminal->get_Direction( &Dir );
  159. }
  160. if ( !SUCCEEDED(hr) )
  161. {
  162. LOG((TL_ERROR, "SelectTerminal - ITTerminal method failed - %lx", hr));
  163. pTerminalPrivate->Release();
  164. return hr;
  165. }
  166. Lock();
  167. if ( (lMediaType != m_lMediaType) ||
  168. (Dir != m_Dir) )
  169. {
  170. LOG((TL_ERROR, "SelectTerminal - terminal wrong mediatype or dir"));
  171. pTerminalPrivate->Release();
  172. Unlock();
  173. return TAPI_E_INVALIDTERMINAL;
  174. }
  175. AddTerminal( pTerminalPrivate );
  176. Unlock();
  177. pTerminalPrivate->Release();
  178. LOG((TL_TRACE, "SelectTerminal - exit - return %lx", hr));
  179. return hr;
  180. }
  181. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  182. //
  183. // CStream::UnselectTerminal
  184. //
  185. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  186. STDMETHODIMP
  187. CStream::UnselectTerminal(ITTerminal * pTerminal)
  188. {
  189. HRESULT hr = S_OK;
  190. ITTerminalPrivate * pTerminalPrivate;
  191. LOG((TL_TRACE, "UnselectTerminal - enter"));
  192. if ( IsBadReadPtr( pTerminal, sizeof( ITTerminal ) ) )
  193. {
  194. LOG((TL_ERROR, "UnselectTerminal - bad pTerminal"));
  195. return E_INVALIDARG;
  196. }
  197. hr = pTerminal->QueryInterface(
  198. IID_ITTerminalPrivate,
  199. (void**)&pTerminalPrivate
  200. );
  201. if ( !SUCCEEDED(hr) )
  202. {
  203. LOG((TL_TRACE, "UnselectTerminal - terminal not selected"));
  204. return TAPI_E_INVALIDTERMINAL;
  205. }
  206. hr = RemoveTerminal( pTerminal );
  207. pTerminalPrivate->Release();
  208. if ( !SUCCEEDED(hr) )
  209. {
  210. LOG((TL_TRACE, "UnselectTerminal - terminal not selected"));
  211. return TAPI_E_INVALIDTERMINAL;
  212. }
  213. LOG((TL_TRACE, "UnselectTerminal - exit - return %lx", hr));
  214. return hr;
  215. }
  216. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  217. //
  218. // CStream::EnumerateTerminals
  219. //
  220. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  221. STDMETHODIMP
  222. CStream::EnumerateTerminals(IEnumTerminal ** ppEnumTerminal)
  223. {
  224. HRESULT hr = S_OK;
  225. LOG((TL_TRACE, "EnumerateTerminals - enter"));
  226. if (TAPIIsBadWritePtr(ppEnumTerminal, sizeof( IEnumTerminal * ) ) )
  227. {
  228. LOG((TL_ERROR, "EnumerateTerminals - bad pointer"));
  229. return E_POINTER;
  230. }
  231. //
  232. // create the enumerator
  233. //
  234. CComObject< CTapiEnum< IEnumTerminal, ITTerminal, &IID_IEnumTerminal > > * p;
  235. hr = CComObject< CTapiEnum< IEnumTerminal, ITTerminal, &IID_IEnumTerminal > >
  236. ::CreateInstance( &p );
  237. if (S_OK != hr)
  238. {
  239. LOG((TL_ERROR, "EnumerateTerminals - could not create enum" ));
  240. return hr;
  241. }
  242. Lock();
  243. //
  244. // initialize it with our terminal array
  245. //
  246. p->Initialize( m_TerminalArray );
  247. Unlock();
  248. //
  249. // return it
  250. //
  251. *ppEnumTerminal = p;
  252. LOG((TL_TRACE, "EnumerateTerminals - exit - return %lx", hr));
  253. return hr;
  254. }
  255. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  256. //
  257. // CStream::get_Terminals
  258. //
  259. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  260. STDMETHODIMP
  261. CStream::get_Terminals(VARIANT * pTerminals)
  262. {
  263. HRESULT hr = S_OK;
  264. IDispatch * pDisp;
  265. LOG((TL_TRACE, "get_Terminals - enter"));
  266. if (TAPIIsBadWritePtr( pTerminals, sizeof(VARIANT) ) )
  267. {
  268. LOG((TL_ERROR, "get_Terminals - bad pointer"));
  269. return E_POINTER;
  270. }
  271. CComObject< CTapiCollection< ITTerminal > > * p;
  272. CComObject< CTapiCollection< ITTerminal > >::CreateInstance( &p );
  273. if (NULL == p)
  274. {
  275. LOG((TL_ERROR, "get_Terminals - could not create collection" ));
  276. return E_OUTOFMEMORY;
  277. }
  278. Lock();
  279. // initialize
  280. hr = p->Initialize( m_TerminalArray );
  281. Unlock();
  282. if (S_OK != hr)
  283. {
  284. LOG((TL_ERROR, "get_Terminals - could not initialize collection" ));
  285. delete p;
  286. return hr;
  287. }
  288. //
  289. // get the IDispatch interface
  290. //
  291. hr = p->_InternalQueryInterface(
  292. IID_IDispatch,
  293. (void **) &pDisp
  294. );
  295. if (S_OK != hr)
  296. {
  297. LOG((TL_ERROR, "get_Terminals - could not get IDispatch interface" ));
  298. delete p;
  299. return hr;
  300. }
  301. //
  302. // put it in the variant
  303. //
  304. VariantInit(pTerminals);
  305. pTerminals->vt = VT_DISPATCH;
  306. pTerminals->pdispVal = pDisp;
  307. LOG((TL_TRACE, "get_Terminals - exit - return %lx", hr));
  308. return hr;
  309. }
  310. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  311. //
  312. // CStream::InternalCreateStream
  313. //
  314. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  315. HRESULT
  316. CStream::InternalCreateStream(
  317. long lMediaType,
  318. TERMINAL_DIRECTION td,
  319. ITPhoneMSPCallPrivate * pCall,
  320. ITStream ** ppStream
  321. )
  322. {
  323. CComObject< CStream > * p;
  324. HRESULT hr = S_OK;
  325. PWSTR pPhoneDevice;
  326. PWSTR pStream;
  327. PWSTR pAudio;
  328. hr = CComObject< CStream >::CreateInstance( &p );
  329. if ( !SUCCEEDED(hr) )
  330. {
  331. STATICLOG((TL_ERROR, "InternalCreateStream failed - %lx", hr));
  332. return hr;
  333. }
  334. p->m_Dir = td;
  335. p->m_lMediaType = lMediaType;
  336. p->m_pCall = pCall;
  337. p->AddRef();
  338. pPhoneDevice = MyLoadString( IDS_PHONEDEVICE );
  339. pStream = MyLoadString( IDS_STREAM );
  340. pAudio = MyLoadString( (td == TD_CAPTURE) ? IDS_AUDIOOUT : IDS_AUDIOIN );
  341. if ( ( NULL == pPhoneDevice ) ||
  342. ( NULL == pStream ) ||
  343. ( NULL == pAudio ) )
  344. {
  345. STATICLOG((TL_ERROR, "Couldn't load string in InternalCreateStream"));
  346. p->Release();
  347. return E_OUTOFMEMORY;
  348. }
  349. p->m_pName = (BSTR) ClientAlloc( ( lstrlenW( pPhoneDevice ) + lstrlenW( pStream ) +
  350. lstrlenW( pAudio ) + 64 ) * sizeof (WCHAR) );
  351. if ( NULL == p->m_pName )
  352. {
  353. STATICLOG((TL_ERROR, "Alloc failed in InternalCreateStream"));
  354. p->Release();
  355. ClientFree( pPhoneDevice );
  356. ClientFree( pStream );
  357. ClientFree( pAudio );
  358. return E_OUTOFMEMORY;
  359. }
  360. wsprintfW(
  361. p->m_pName,
  362. L"%s %s %s",
  363. pPhoneDevice,
  364. pStream,
  365. pAudio
  366. );
  367. ClientFree( pPhoneDevice );
  368. ClientFree( pStream );
  369. ClientFree( pAudio );
  370. *ppStream = p;
  371. return S_OK;
  372. }
  373. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  374. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  375. void
  376. CStream::FinalRelease()
  377. {
  378. if ( NULL != m_pName )
  379. {
  380. ClientFree( m_pName );
  381. }
  382. m_TerminalArray.Shutdown();
  383. }
  384. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  385. //
  386. // CStream::AddTerminal
  387. //
  388. // saves terminal as selected
  389. //
  390. // called in lock
  391. //
  392. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  393. void
  394. CStream::AddTerminal( ITTerminalPrivate * pTerminal )
  395. {
  396. ITTerminal * pLocalTerminal;
  397. HRESULT hr;
  398. hr = pTerminal->QueryInterface(
  399. IID_ITTerminal,
  400. (void**)&pLocalTerminal
  401. );
  402. m_TerminalArray.Add( pLocalTerminal );
  403. pLocalTerminal->Release();
  404. m_pCall->SelectTerminal( pTerminal );
  405. }
  406. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  407. //
  408. // CStream::RemoveTerminal
  409. //
  410. // removes terminal from being selected
  411. //
  412. // called in lock
  413. //
  414. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  415. HRESULT
  416. CStream::RemoveTerminal( ITTerminal * pTerminal )
  417. {
  418. BOOL bRemoved;
  419. bRemoved = m_TerminalArray.Remove( pTerminal );
  420. if (bRemoved)
  421. {
  422. ITTerminalPrivate * pTerminalPrivate;
  423. HRESULT hr;
  424. hr = pTerminal->QueryInterface(
  425. IID_ITTerminalPrivate,
  426. (void**)&pTerminalPrivate
  427. );
  428. m_pCall->UnselectTerminal( pTerminalPrivate );
  429. pTerminalPrivate->Release();
  430. return S_OK;
  431. }
  432. return TAPI_E_INVALIDTERMINAL;
  433. }