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.

318 lines
6.1 KiB

  1. // Service.cpp : Implementation of CService
  2. #include "stdafx.h"
  3. #include "Service.h"
  4. #include "channel.h"
  5. #include "Property.h"
  6. #include "ScheduleEntry.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CService
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CServices
  11. STDMETHODIMP CServices::get_ChannelLineups(IChannelLineups **ppchanlineups)
  12. {
  13. ENTER_API
  14. {
  15. ValidateOutPtr<IChannelLineups>(ppchanlineups, NULL);
  16. if (m_pchanlineups == NULL)
  17. {
  18. HRESULT hr;
  19. CObjectType *pobjtype;
  20. hr = m_pdb->get_ChannelLineupObjectType(&pobjtype);
  21. if (FAILED(hr))
  22. return hr;
  23. CComPtr<IObjects> pobjs;
  24. hr = m_pdb->get_ObjectsWithType(pobjtype, &pobjs);
  25. if (FAILED(hr))
  26. return hr;
  27. hr = pobjs->QueryInterface(__uuidof(IChannelLineups), (void **)&m_pchanlineups);
  28. if (FAILED(hr))
  29. return hr;
  30. }
  31. (*ppchanlineups = m_pchanlineups)->AddRef();
  32. return S_OK;
  33. }
  34. LEAVE_API
  35. }
  36. STDMETHODIMP CServices::get_AddNew(IUnknown *punkTuneRequest, BSTR bstrProviderName, BSTR bstrProviderDescription, BSTR bstrProviderNetworkName, DATE dtStart, DATE dtEnd, IService **ppservice)
  37. {
  38. ENTER_API
  39. {
  40. ValidateInPtr_NULL_OK<IUnknown>(punkTuneRequest);
  41. ValidateIn(bstrProviderName);
  42. ValidateIn(bstrProviderDescription);
  43. ValidateIn(bstrProviderNetworkName);
  44. ValidateOutPtr<IService>(ppservice, NULL);
  45. CComQIPtr<IObjects> pobjs(GetControllingUnknown());
  46. CComPtr<IUnknown> pobj;
  47. HRESULT hr = pobjs->get_AddNew(&pobj);
  48. if (FAILED(hr))
  49. return hr;
  50. hr = pobj->QueryInterface(IID_IService, (void **) ppservice);
  51. if (FAILED(hr))
  52. return hr;
  53. (*ppservice)->putref_TuneRequest(punkTuneRequest);
  54. (*ppservice)->put_ProviderName(bstrProviderName);
  55. (*ppservice)->put_ProviderDescription(bstrProviderDescription);
  56. (*ppservice)->put_ProviderNetworkName(bstrProviderNetworkName);
  57. (*ppservice)->put_StartTime(dtStart);
  58. (*ppservice)->put_EndTime(dtEnd);
  59. return hr;
  60. }
  61. LEAVE_API
  62. }
  63. STDMETHODIMP CServices::get_ItemWithProviderName(BSTR bstrProviderName, IService **ppservice)
  64. {
  65. ENTER_API
  66. {
  67. ValidateIn(bstrProviderName);
  68. ValidateOutPtr<IService>(ppservice, NULL);
  69. // UNDONE: Test
  70. CComPtr<IMetaPropertyType> pproptype= m_pdb->ProviderPropSet::NameMetaPropertyType();
  71. CComPtr<IMetaProperty> pprop;
  72. HRESULT hr;
  73. hr = pproptype->get_New(0, _variant_t(bstrProviderName), &pprop);
  74. if (FAILED(hr))
  75. return hr;
  76. CComPtr<IMetaPropertyCondition> ppropcond;
  77. hr = pprop->get_Cond(_bstr_t(_T("=")), &ppropcond);
  78. if (FAILED(hr))
  79. return hr;
  80. CComQIPtr<IObjects> pobjsThis(GetControllingUnknown());
  81. CComPtr<IObjects> pobjs;
  82. hr = pobjsThis->get_ItemsWithMetaPropertyCond(ppropcond, &pobjs);
  83. if (FAILED(hr))
  84. return hr;
  85. CComPtr<IUnknown> pobj;
  86. hr = pobjs->get_Item(_variant_t(0L), &pobj);
  87. if (FAILED(hr))
  88. return hr;
  89. hr = pobj->QueryInterface(__uuidof(IService), (void **) ppservice);
  90. return hr;
  91. }
  92. LEAVE_API
  93. }
  94. STDMETHODIMP CService::get_TuneRequest(IUnknown **ppunk)
  95. {
  96. ENTER_API
  97. {
  98. ValidateOutPtr<IUnknown>(ppunk, NULL);
  99. HRESULT hr;
  100. if (m_punkTuneRequest == NULL)
  101. {
  102. _variant_t var;
  103. hr = m_pdb->_get_TuneRequest((IService *) this, &var);
  104. if (FAILED(hr))
  105. return hr;
  106. switch (var.vt)
  107. {
  108. case VT_UNKNOWN:
  109. break;
  110. case VT_EMPTY:
  111. return S_FALSE;
  112. default:
  113. return E_FAIL;
  114. }
  115. m_punkTuneRequest = var.punkVal;
  116. }
  117. m_punkTuneRequest.CopyTo(ppunk);
  118. return S_OK;
  119. }
  120. LEAVE_API
  121. }
  122. STDMETHODIMP CService::putref_TuneRequest(IUnknown *punk)
  123. {
  124. ENTER_API
  125. {
  126. ValidateInPtr_NULL_OK<IUnknown>(punk);
  127. m_punkTuneRequest = punk;
  128. VARIANT var;
  129. if (punk != NULL)
  130. {
  131. var.vt = VT_UNKNOWN | VT_BYREF;
  132. var.ppunkVal = &punk;
  133. }
  134. else
  135. {
  136. var.vt = VT_EMPTY;
  137. var.lVal = 0;
  138. }
  139. return m_pdb->_put_TuneRequest((IService *) this, var);
  140. }
  141. LEAVE_API
  142. }
  143. STDMETHODIMP CService::get_StartTime(DATE *pdtStart)
  144. {
  145. ENTER_API
  146. {
  147. ValidateOut<DATE>(pdtStart, 0);
  148. return m_pdb->_get_Start((IService *) this, pdtStart);
  149. }
  150. LEAVE_API
  151. }
  152. STDMETHODIMP CService::put_StartTime(DATE dtStart)
  153. {
  154. ENTER_API
  155. {
  156. return m_pdb->_put_Start((IService *) this, _variant_t(dtStart));
  157. }
  158. LEAVE_API
  159. }
  160. STDMETHODIMP CService::get_EndTime(DATE *pdtEnd)
  161. {
  162. ENTER_API
  163. {
  164. ValidateOut<DATE>(pdtEnd, 0);
  165. return m_pdb->_get_End((IService *) this, pdtEnd);
  166. }
  167. LEAVE_API
  168. }
  169. STDMETHODIMP CService::put_EndTime(DATE dtEnd)
  170. {
  171. ENTER_API
  172. {
  173. return m_pdb->_put_End((IService *) this, dtEnd);
  174. }
  175. LEAVE_API
  176. }
  177. STDMETHODIMP CService::get_ProviderName(BSTR *pbstrName)
  178. {
  179. ENTER_API
  180. {
  181. ValidateOut(pbstrName);
  182. return m_pdb->ProviderPropSet::_get_Name((IService *) this, pbstrName);
  183. }
  184. LEAVE_API
  185. }
  186. STDMETHODIMP CService::put_ProviderName(BSTR bstrName)
  187. {
  188. ENTER_API
  189. {
  190. ValidateIn(bstrName);
  191. return m_pdb->ProviderPropSet::_put_Name((IService *) this, bstrName);
  192. }
  193. LEAVE_API
  194. }
  195. STDMETHODIMP CService::get_ProviderNetworkName(BSTR *pbstrName)
  196. {
  197. ENTER_API
  198. {
  199. ValidateOut(pbstrName);
  200. return m_pdb->ProviderPropSet::_get_NetworkName((IService *) this, pbstrName);
  201. }
  202. LEAVE_API
  203. }
  204. STDMETHODIMP CService::put_ProviderNetworkName(BSTR bstrName)
  205. {
  206. ENTER_API
  207. {
  208. ValidateIn(bstrName);
  209. return m_pdb->ProviderPropSet::_put_NetworkName((IService *) this, bstrName);
  210. }
  211. LEAVE_API
  212. }
  213. STDMETHODIMP CService::get_ProviderDescription(BSTR *pbstrDescr)
  214. {
  215. ENTER_API
  216. {
  217. ValidateOut(pbstrDescr);
  218. return m_pdb->ProviderPropSet::_get_Description((IService *) this, pbstrDescr);
  219. }
  220. LEAVE_API
  221. }
  222. STDMETHODIMP CService::put_ProviderDescription(BSTR bstrDescr)
  223. {
  224. ENTER_API
  225. {
  226. ValidateIn(bstrDescr);
  227. return m_pdb->ProviderPropSet::_put_Description((IService *) this, bstrDescr);
  228. }
  229. LEAVE_API
  230. }
  231. STDMETHODIMP CService::get_ScheduleEntries(IScheduleEntries **ppschedentries)
  232. {
  233. ENTER_API
  234. {
  235. ValidateOutPtr<IScheduleEntries>(ppschedentries, NULL);
  236. CObjectType *pobjtype;
  237. HRESULT hr;
  238. hr = m_pdb->get_ScheduleEntryObjectType(&pobjtype);
  239. if (FAILED(hr))
  240. return hr;
  241. CComPtr<IObjects> pobjsT;
  242. hr = m_pdb->get_ObjectsWithType(pobjtype, &pobjsT);
  243. if (FAILED(hr))
  244. return hr;
  245. CComPtr<IObjects> pobjs;
  246. hr = pobjsT->get_ItemsInverseRelatedToBy((IService *) this,
  247. m_pdb->ScheduleEntryPropSet::ServiceMetaPropertyType(), &pobjs);
  248. if (FAILED(hr))
  249. return hr;
  250. return pobjs->QueryInterface(__uuidof(IScheduleEntries), (void **) ppschedentries);
  251. }
  252. LEAVE_API
  253. }