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.

233 lines
4.5 KiB

  1. // ScheduleEntry.cpp : Implementation of CScheduleEntry
  2. #include "stdafx.h"
  3. #include "ScheduleEntry.h"
  4. #include "Property.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CScheduleEntry
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CScheduleEntries
  9. STDMETHODIMP CScheduleEntries::get_ItemWithServiceAtTime(IService *pservice, DATE dt, IScheduleEntry **ppschedentry)
  10. {
  11. ENTER_API
  12. {
  13. HRESULT hr;
  14. ValidateInPtr<IService>(pservice);
  15. ValidateOutPtr<IScheduleEntry>(ppschedentry, NULL);
  16. CComPtr<IScheduleEntries> pschedentries;
  17. hr = get_ItemsWithService(pservice, &pschedentries);
  18. if (FAILED(hr))
  19. return hr;
  20. long cItems;
  21. hr = pschedentries->get_Count(&cItems);
  22. if (FAILED(hr))
  23. return hr;
  24. if (cItems == 0)
  25. return E_INVALIDARG;
  26. CComQIPtr<IObjects> pobjs(pschedentries);
  27. CComPtr<IObjects> pobjs2;
  28. hr = pobjs->get_ItemsInTimeRange(dt, dt, &pobjs2);
  29. if (FAILED(hr))
  30. return hr;
  31. hr = pobjs2->get_Count(&cItems);
  32. if (FAILED(hr))
  33. return hr;
  34. if (cItems == 0)
  35. return E_INVALIDARG;
  36. CComPtr<IUnknown> punk;
  37. hr = pobjs2->get_Item(_variant_t(0L), &punk);
  38. if (FAILED(hr))
  39. return hr;
  40. return punk->QueryInterface(__uuidof(IScheduleEntry), (void **) ppschedentry);
  41. }
  42. LEAVE_API
  43. }
  44. STDMETHODIMP CScheduleEntries::get_ItemsWithService(IService *pservice, IScheduleEntries **ppschedentries)
  45. {
  46. ENTER_API
  47. {
  48. ValidateInPtr<IService>(pservice);
  49. ValidateOutPtr<IScheduleEntries>(ppschedentries, NULL);
  50. CComQIPtr<CObjects> pobjs(GetControllingUnknown());
  51. CComPtr<IObjects> pobjsT;
  52. HRESULT hr;
  53. hr = pobjs->get_ItemsInverseRelatedToBy(pservice,
  54. m_pdb->ScheduleEntryPropSet::ServiceMetaPropertyType(), &pobjsT);
  55. if (FAILED(hr))
  56. return hr;
  57. return pobjsT->QueryInterface(__uuidof(IScheduleEntries), (void **) ppschedentries);
  58. }
  59. LEAVE_API
  60. }
  61. STDMETHODIMP CScheduleEntries::get_AddNew(DATE dtStart, DATE dtEnd, IService *pservice, IProgram *pprog, IScheduleEntry **ppschedentry)
  62. {
  63. ENTER_API
  64. {
  65. ValidateInPtr<IService>(pservice);
  66. ValidateOutPtr<IScheduleEntry>(ppschedentry, NULL);
  67. HRESULT hr;
  68. hr = _get_AddNew(ppschedentry);
  69. if (FAILED(hr))
  70. return hr;
  71. (*ppschedentry)->putref_Service(pservice);
  72. (*ppschedentry)->putref_Program(pprog);
  73. (*ppschedentry)->put_StartTime(dtStart);
  74. (*ppschedentry)->put_EndTime(dtEnd);
  75. return hr;
  76. }
  77. LEAVE_API
  78. }
  79. STDMETHODIMP CScheduleEntry::get_Service(IService **ppservice)
  80. {
  81. ENTER_API
  82. {
  83. ValidateOutPtr<IService>(ppservice, NULL);
  84. HRESULT hr;
  85. if (m_pservice == NULL)
  86. {
  87. hr = _get_ItemRelatedBy(m_pdb->ScheduleEntryPropSet::ServiceMetaPropertyType(), (IService **) &m_pservice);
  88. if (hr == S_FALSE || FAILED(hr))
  89. return hr;
  90. }
  91. m_pservice.CopyTo(ppservice);
  92. return S_OK;
  93. }
  94. LEAVE_API
  95. }
  96. STDMETHODIMP CScheduleEntry::putref_Service(IService *pservice)
  97. {
  98. ENTER_API
  99. {
  100. ValidateInPtr<IService>(pservice);
  101. m_pservice = pservice;
  102. return _put_ItemRelatedBy(m_pdb->ScheduleEntryPropSet::ServiceMetaPropertyType(),
  103. (IService *) m_pservice);
  104. }
  105. LEAVE_API
  106. }
  107. STDMETHODIMP CScheduleEntry::get_Program(IProgram **ppprog)
  108. {
  109. ENTER_API
  110. {
  111. ValidateOutPtr<IProgram>(ppprog, NULL);
  112. HRESULT hr;
  113. if (m_pprog == NULL)
  114. {
  115. hr = _get_ItemRelatedBy(m_pdb->ScheduleEntryPropSet::ProgramMetaPropertyType(),
  116. (IProgram **) &m_pprog);
  117. if (FAILED(hr))
  118. return hr;
  119. }
  120. m_pprog.CopyTo(ppprog);
  121. return S_OK;
  122. }
  123. LEAVE_API
  124. }
  125. STDMETHODIMP CScheduleEntry::putref_Program(IProgram *pprog)
  126. {
  127. ENTER_API
  128. {
  129. ValidateInPtr<IProgram>(pprog);
  130. m_pprog = pprog;
  131. return _put_ItemRelatedBy(m_pdb->ScheduleEntryPropSet::ProgramMetaPropertyType(),
  132. (IProgram *) m_pprog);
  133. }
  134. LEAVE_API
  135. }
  136. STDMETHODIMP CScheduleEntry::get_StartTime(DATE *pdtStart)
  137. {
  138. ENTER_API
  139. {
  140. ValidateOut<DATE>(pdtStart);
  141. return m_pdb->_get_Start((IScheduleEntry *) this, pdtStart);
  142. }
  143. LEAVE_API
  144. }
  145. STDMETHODIMP CScheduleEntry::put_StartTime(DATE dtStart)
  146. {
  147. ENTER_API
  148. {
  149. return m_pdb->_put_Start((IScheduleEntry *) this, dtStart);
  150. }
  151. LEAVE_API
  152. }
  153. STDMETHODIMP CScheduleEntry::get_EndTime(DATE *pdtEnd)
  154. {
  155. ENTER_API
  156. {
  157. ValidateOut<DATE>(pdtEnd);
  158. return m_pdb->_get_End((IScheduleEntry *) this, pdtEnd);
  159. }
  160. LEAVE_API
  161. }
  162. STDMETHODIMP CScheduleEntry::put_EndTime(DATE dtEnd)
  163. {
  164. ENTER_API
  165. {
  166. return m_pdb->_put_End((IScheduleEntry *) this, dtEnd);
  167. }
  168. LEAVE_API
  169. }
  170. STDMETHODIMP CScheduleEntry::get_Length(long *plSecs)
  171. {
  172. ENTER_API
  173. {
  174. ValidateOut<long>(plSecs, 0);
  175. // UNDONE: Test
  176. DATE dtStart;
  177. DATE dtEnd;
  178. HRESULT hr;
  179. hr = get_StartTime(&dtStart);
  180. if (FAILED(hr))
  181. return hr;
  182. hr = get_EndTime(&dtEnd);
  183. if (FAILED(hr))
  184. return hr;
  185. *plSecs = (long) ((dtEnd - dtStart)*86400.0); // 86400 = 24*60*60
  186. return S_OK;
  187. }
  188. LEAVE_API
  189. }