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.

259 lines
4.9 KiB

  1. // Channel.cpp : Implementation of CChannel
  2. #include "stdafx.h"
  3. #include "Channel.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CChannel
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CChannels
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CChannelLineup
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CChannelLineups
  12. STDMETHODIMP CChannel::get_Name(BSTR *pbstrName)
  13. {
  14. ENTER_API
  15. {
  16. ValidateOut(pbstrName);
  17. return m_pdb->DescriptionPropSet::_get_Name((IChannel *)this, pbstrName);
  18. }
  19. LEAVE_API
  20. }
  21. STDMETHODIMP CChannel::put_Name(BSTR bstrName)
  22. {
  23. ENTER_API
  24. {
  25. ValidateOut(bstrName);
  26. return m_pdb->DescriptionPropSet::_put_Name((IChannel *) this, _variant_t(bstrName));
  27. }
  28. LEAVE_API
  29. }
  30. STDMETHODIMP CChannel::get_Service(IService **ppservice)
  31. {
  32. ENTER_API
  33. {
  34. ValidateOutPtr<IService>(ppservice, NULL);
  35. HRESULT hr;
  36. if (m_pservice == NULL)
  37. {
  38. hr = _get_ItemRelatedBy(m_pdb->ChannelPropSet::ServiceMetaPropertyType(),
  39. (IService **) &m_pservice);
  40. if (hr == S_FALSE || FAILED(hr))
  41. return hr;
  42. }
  43. m_pservice.CopyTo(ppservice);
  44. return S_OK;
  45. }
  46. LEAVE_API
  47. }
  48. STDMETHODIMP CChannel::putref_Service(IService *pservice)
  49. {
  50. ENTER_API
  51. {
  52. ValidateInPtr_NULL_OK<IService>(pservice);
  53. m_pservice = pservice;
  54. if (m_pservice == NULL)
  55. {
  56. //TODO: Remove the item relationship.
  57. return S_OK;
  58. }
  59. return put_ItemRelatedBy(m_pdb->ChannelPropSet::ServiceMetaPropertyType(),
  60. (IService *) m_pservice);
  61. }
  62. LEAVE_API
  63. }
  64. STDMETHODIMP CChannel::get_ChannelLineups(IChannelLineups **ppchanlineups)
  65. {
  66. ENTER_API
  67. {
  68. ValidateOutPtr<IChannelLineups>(ppchanlineups, NULL);
  69. HRESULT hr;
  70. CObjectType *pobjtype;
  71. hr = m_pdb->get_ChannelLineupObjectType(&pobjtype);
  72. if (FAILED(hr))
  73. return hr;
  74. CComPtr<IObjects> pobjsT;
  75. hr = m_pdb->get_ObjectsWithType(pobjtype, &pobjsT);
  76. if (FAILED(hr))
  77. return hr;
  78. CComPtr<IObjects> pobjs;
  79. hr = pobjsT->get_ItemsInverseRelatedToBy((IChannel *) this,
  80. m_pdb->ChannelsPropSet::ChannelMetaPropertyType(), &pobjs);
  81. if (FAILED(hr))
  82. return hr;
  83. return pobjs->QueryInterface(__uuidof(IChannelLineups), (void **)ppchanlineups);
  84. }
  85. LEAVE_API
  86. }
  87. STDMETHODIMP CChannels::AddAt(IChannel *pchan, long i)
  88. {
  89. ENTER_API
  90. {
  91. ValidateInPtr<IChannel>(pchan);
  92. CComQIPtr<IObjects> pobjs(GetControllingUnknown());
  93. return pobjs->AddAt(pchan, i);
  94. }
  95. LEAVE_API
  96. }
  97. STDMETHODIMP CChannels::get_AddNewAt(IService *pservice, BSTR bstrName, long i, IChannel **ppchan)
  98. {
  99. ENTER_API
  100. {
  101. ValidateInPtr_NULL_OK<IService>(pservice);
  102. ValidateIn(bstrName);
  103. ValidateOutPtr<IChannel>(ppchan, NULL);
  104. HRESULT hr;
  105. CComPtr<IChannel> pchan;
  106. hr = _get_AddNewAt(i, &pchan);
  107. if (FAILED(hr))
  108. return hr;
  109. hr = pchan->put_Name(bstrName);
  110. if (FAILED(hr))
  111. return hr;
  112. if (pservice != NULL)
  113. {
  114. hr = pchan->putref_Service(pservice);
  115. if (FAILED(hr))
  116. return hr;
  117. }
  118. *ppchan = pchan.Detach();
  119. return S_OK;
  120. }
  121. LEAVE_API
  122. }
  123. STDMETHODIMP CChannels::get_ItemWithName(BSTR bstrName, IChannel **ppchan)
  124. {
  125. ENTER_API
  126. {
  127. ValidateIn(bstrName);
  128. ValidateOutPtr<IChannel>(ppchan, NULL);
  129. // UNDONE: Test
  130. CComPtr<IMetaPropertyType> pproptype= m_pdb->DescriptionPropSet::NameMetaPropertyType();
  131. CComPtr<IMetaProperty> pprop;
  132. HRESULT hr;
  133. hr = pproptype->get_New(0, _variant_t(bstrName), &pprop);
  134. if (FAILED(hr))
  135. return hr;
  136. CComPtr<IMetaPropertyCondition> ppropcond;
  137. hr = pprop->get_Cond(_bstr_t(_T("=")), &ppropcond);
  138. if (FAILED(hr))
  139. return hr;
  140. CComQIPtr<IObjects> pobjsThis(GetControllingUnknown());
  141. CComPtr<IObjects> pobjs;
  142. hr = pobjsThis->get_ItemsWithMetaPropertyCond(ppropcond, &pobjs);
  143. if (FAILED(hr))
  144. return hr;
  145. CComPtr<IUnknown> pobj;
  146. hr = pobjs->get_Item(_variant_t(0L), &pobj);
  147. if (FAILED(hr))
  148. return hr;
  149. hr = pobj->QueryInterface(__uuidof(IChannel), (void **) ppchan);
  150. return hr;
  151. }
  152. LEAVE_API
  153. }
  154. STDMETHODIMP CChannelLineup::get_Name(BSTR *pbstrName)
  155. {
  156. ENTER_API
  157. {
  158. ValidateOut(pbstrName);
  159. return m_pdb->DescriptionPropSet::_get_Name((IChannelLineup *)this, pbstrName);
  160. }
  161. LEAVE_API
  162. }
  163. STDMETHODIMP CChannelLineup::put_Name(BSTR bstrName)
  164. {
  165. ENTER_API
  166. {
  167. ValidateIn(bstrName);
  168. return m_pdb->DescriptionPropSet::_put_Name((IChannelLineup *)this, bstrName);
  169. }
  170. LEAVE_API
  171. }
  172. STDMETHODIMP CChannelLineup::get_Channels(IChannels **ppchans)
  173. {
  174. ENTER_API
  175. {
  176. ValidateOutPtr<IChannels>(ppchans, NULL);
  177. if (m_pchans == NULL)
  178. {
  179. HRESULT hr;
  180. CObjectType *pobjtype;
  181. hr = m_pdb->get_ChannelObjectType(&pobjtype);
  182. if (FAILED(hr))
  183. return hr;
  184. CComPtr<IObjects> pobjs;
  185. hr = pobjtype->get_NewCollection(&pobjs);
  186. if (FAILED(hr))
  187. return hr;
  188. CComQIPtr<CObjects> pobjsT(pobjs);
  189. CComQIPtr<CMetaPropertyType> pproptype(m_pdb->ChannelsPropSet::ChannelMetaPropertyType());
  190. long idRel = pproptype->GetID();
  191. pobjsT->InitRelation(GetControllingUnknown(), idRel, FALSE);
  192. pobjs->QueryInterface(__uuidof(IChannels), (void **)&m_pchans);
  193. }
  194. (*ppchans = m_pchans)->AddRef();
  195. return S_OK;
  196. }
  197. LEAVE_API
  198. }