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.

615 lines
12 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #ifndef __SDP_TIME__
  5. #define __SDP_TIME__
  6. #include "sdpcommo.h"
  7. #include "sdpgen.h"
  8. #include "sdpfld.h"
  9. #include "sdpval.h"
  10. #include "sdpstp.h"
  11. #include "sdpsadj.h"
  12. // no Reset method to set the member values to 0 again (as its not really required and it saves
  13. // one call per instance)
  14. class _DllDecl SDP_TIME_PERIOD : public SDP_SINGLE_FIELD
  15. {
  16. public:
  17. inline SDP_TIME_PERIOD();
  18. inline BOOL IsCompact() const;
  19. inline void IsCompact(
  20. IN BOOL IsCompactFlag
  21. );
  22. inline CHAR GetUnit() const;
  23. inline void SetUnit(
  24. IN CHAR Unit
  25. );
  26. inline LONG GetCompactValue() const;
  27. inline void SetCompactValue(
  28. IN LONG CompactValue
  29. );
  30. inline LONG GetPeriodValue() const;
  31. inline void SetPeriodValue(
  32. IN LONG PeriodValue
  33. );
  34. inline void Get(
  35. OUT BOOL &IsCompactFlag,
  36. OUT CHAR &Unit,
  37. OUT LONG &CompactValue,
  38. OUT LONG &PeriodValue
  39. ) const;
  40. inline void Set(
  41. IN BOOL IsCompactFlag,
  42. IN CHAR Unit,
  43. IN LONG CompactValue,
  44. IN LONG PeriodValue
  45. );
  46. protected:
  47. BOOL m_IsCompact;
  48. CHAR m_Unit;
  49. LONG m_CompactValue;
  50. LONG m_PeriodValue;
  51. CHAR m_SdpTimePeriodBuffer[25];
  52. virtual BOOL InternalParseToken(
  53. IN CHAR *Token
  54. );
  55. virtual BOOL PrintData(
  56. OUT ostrstream &OutputStream
  57. );
  58. };
  59. inline
  60. SDP_TIME_PERIOD::SDP_TIME_PERIOD(
  61. )
  62. : SDP_SINGLE_FIELD(sizeof(m_SdpTimePeriodBuffer), m_SdpTimePeriodBuffer)
  63. {
  64. }
  65. inline BOOL
  66. SDP_TIME_PERIOD::IsCompact(
  67. ) const
  68. {
  69. return m_IsCompact;
  70. }
  71. inline void
  72. SDP_TIME_PERIOD::IsCompact(
  73. IN BOOL IsCompactFlag
  74. )
  75. {
  76. m_IsCompact = IsCompactFlag;
  77. }
  78. inline CHAR
  79. SDP_TIME_PERIOD::GetUnit(
  80. ) const
  81. {
  82. return m_Unit;
  83. }
  84. inline void
  85. SDP_TIME_PERIOD::SetUnit(
  86. IN CHAR Unit
  87. )
  88. {
  89. m_Unit = Unit;
  90. }
  91. inline LONG
  92. SDP_TIME_PERIOD::GetCompactValue(
  93. ) const
  94. {
  95. return m_CompactValue;
  96. }
  97. inline void
  98. SDP_TIME_PERIOD::SetCompactValue(
  99. IN LONG CompactValue
  100. )
  101. {
  102. m_CompactValue = CompactValue;
  103. }
  104. inline LONG
  105. SDP_TIME_PERIOD::GetPeriodValue(
  106. ) const
  107. {
  108. return m_PeriodValue;
  109. }
  110. inline void
  111. SDP_TIME_PERIOD::SetPeriodValue(
  112. IN LONG PeriodValue
  113. )
  114. {
  115. m_PeriodValue = PeriodValue;
  116. }
  117. inline void
  118. SDP_TIME_PERIOD::Get(
  119. OUT BOOL &IsCompactFlag,
  120. OUT CHAR &Unit,
  121. OUT LONG &CompactValue,
  122. OUT LONG &PeriodValue
  123. ) const
  124. {
  125. IsCompactFlag = IsCompact();
  126. Unit = GetUnit();
  127. CompactValue = GetCompactValue();
  128. PeriodValue = GetPeriodValue();
  129. }
  130. inline void
  131. SDP_TIME_PERIOD::Set(
  132. IN BOOL IsCompactFlag,
  133. IN CHAR Unit,
  134. IN LONG CompactValue,
  135. IN LONG PeriodValue
  136. )
  137. {
  138. IsCompact(IsCompactFlag);
  139. SetUnit(Unit);
  140. SetCompactValue(CompactValue);
  141. SetPeriodValue(PeriodValue);
  142. IsValid(TRUE);
  143. IsModified(TRUE);
  144. }
  145. class _DllDecl SDP_TIME_PERIOD_LIST :
  146. public SDP_FIELD_LIST,
  147. public SDP_TIME_PERIOD_SAFEARRAY
  148. {
  149. public:
  150. inline SDP_TIME_PERIOD_LIST();
  151. virtual SDP_FIELD *CreateElement();
  152. };
  153. inline
  154. SDP_TIME_PERIOD_LIST::SDP_TIME_PERIOD_LIST(
  155. )
  156. : SDP_FIELD_LIST(CHAR_BLANK),
  157. SDP_TIME_PERIOD_SAFEARRAY(*this)
  158. {
  159. }
  160. class _DllDecl SDP_REPEAT : public SDP_VALUE
  161. {
  162. public:
  163. SDP_REPEAT();
  164. inline SDP_TIME_PERIOD &GetInterval();
  165. inline SDP_TIME_PERIOD &GetDuration();
  166. inline SDP_TIME_PERIOD_LIST &GetOffsets();
  167. protected:
  168. SDP_TIME_PERIOD m_Interval;
  169. SDP_TIME_PERIOD m_Duration;
  170. SDP_TIME_PERIOD_LIST m_Offsets; // array of SDP_TIME_PERIOD
  171. virtual BOOL InternalParseLine(
  172. IN OUT CHAR *&Line
  173. );
  174. virtual BOOL GetField(
  175. OUT SDP_FIELD *&Field,
  176. OUT BOOL &AddToArray
  177. );
  178. virtual void InternalReset();
  179. };
  180. inline SDP_TIME_PERIOD &
  181. SDP_REPEAT::GetInterval(
  182. )
  183. {
  184. return m_Interval;
  185. }
  186. inline SDP_TIME_PERIOD &
  187. SDP_REPEAT::GetDuration(
  188. )
  189. {
  190. return m_Duration;
  191. }
  192. inline SDP_TIME_PERIOD_LIST &
  193. SDP_REPEAT::GetOffsets(
  194. )
  195. {
  196. return m_Offsets;
  197. }
  198. class _DllDecl SDP_REPEAT_LIST : public SDP_VALUE_LIST
  199. {
  200. protected:
  201. virtual SDP_VALUE *CreateElement();
  202. };
  203. class _DllDecl SDP_ADJUSTMENT :
  204. public SDP_VALUE,
  205. public SDP_ADJUSTMENT_SAFEARRAY
  206. {
  207. public:
  208. SDP_ADJUSTMENT();
  209. inline SDP_ULONG_LIST &GetAdjustmentTimes();
  210. inline SDP_TIME_PERIOD_LIST &GetOffsets();
  211. protected:
  212. SDP_ULONG_LIST m_AdjustmentTimes; // array of SDP_ULONG
  213. SDP_TIME_PERIOD_LIST m_Offsets; // array of SDP_TIME_PERIOD
  214. CHAR m_PrintBuffer[400];
  215. DWORD m_PrintLength;
  216. virtual void InternalReset();
  217. BOOL PrintData(
  218. OUT ostrstream &OutputStream
  219. );
  220. virtual BOOL GetField(
  221. OUT SDP_FIELD *&Field,
  222. OUT BOOL &AddToArray
  223. );
  224. virtual BOOL CalcIsModified() const;
  225. virtual DWORD CalcCharacterStringSize();
  226. virtual BOOL CopyValue(
  227. OUT ostrstream &OutputStream
  228. );
  229. BOOL PrintElement(
  230. IN DWORD Index,
  231. OUT ostrstream &OutputStream
  232. );
  233. };
  234. inline SDP_ULONG_LIST &
  235. SDP_ADJUSTMENT::GetAdjustmentTimes(
  236. )
  237. {
  238. return m_AdjustmentTimes;
  239. }
  240. inline SDP_TIME_PERIOD_LIST &
  241. SDP_ADJUSTMENT::GetOffsets(
  242. )
  243. {
  244. return m_Offsets;
  245. }
  246. class _DllDecl SDP_TIME : public SDP_VALUE
  247. {
  248. public:
  249. SDP_TIME();
  250. inline HRESULT SetTimes(
  251. IN ULONG StartTime,
  252. IN ULONG StopTime
  253. );
  254. inline HRESULT SetStartTime(
  255. IN ULONG StartTime
  256. );
  257. inline HRESULT SetStopTime(
  258. IN ULONG StopTime
  259. );
  260. inline HRESULT GetStartTime(
  261. OUT ULONG &StartTime
  262. );
  263. inline HRESULT GetStopTime(
  264. OUT ULONG &StopTime
  265. );
  266. inline SDP_REPEAT_LIST &GetRepeatList();
  267. protected:
  268. virtual BOOL CalcIsModified() const;
  269. virtual DWORD CalcCharacterStringSize();
  270. virtual BOOL CopyValue(
  271. OUT ostrstream &OutputStream
  272. );
  273. virtual BOOL GetField(
  274. OUT SDP_FIELD *&Field,
  275. OUT BOOL &AddToArray
  276. );
  277. virtual void InternalReset();
  278. private:
  279. SDP_ULONG m_StartTime;
  280. SDP_ULONG m_StopTime;
  281. SDP_REPEAT_LIST m_RepeatList;
  282. inline HRESULT FillArrays();
  283. };
  284. inline HRESULT
  285. SDP_TIME::FillArrays(
  286. )
  287. {
  288. // check if the field and separator char arrays have been filled properly
  289. if ( (2 != m_FieldArray.GetSize()) || (2 != m_SeparatorCharArray.GetSize()) )
  290. {
  291. // clear the field and separator arrays
  292. m_FieldArray.RemoveAll();
  293. m_SeparatorCharArray.RemoveAll();
  294. try
  295. {
  296. // insert the fields and the separator characters into respective arrays
  297. m_FieldArray.SetAtGrow(0, &m_StartTime);
  298. m_SeparatorCharArray.SetAtGrow(0, CHAR_BLANK);
  299. m_FieldArray.SetAtGrow(1, &m_StopTime);
  300. m_SeparatorCharArray.SetAtGrow(1, CHAR_NEWLINE);
  301. }
  302. catch(...)
  303. {
  304. m_FieldArray.RemoveAll();
  305. m_SeparatorCharArray.RemoveAll();
  306. return E_OUTOFMEMORY;
  307. }
  308. }
  309. ASSERT(&m_StartTime == m_FieldArray[0]);
  310. ASSERT(&m_StopTime == m_FieldArray[1]);
  311. return S_OK;
  312. }
  313. inline HRESULT
  314. SDP_TIME::SetTimes(
  315. IN ULONG StartTime,
  316. IN ULONG StopTime
  317. )
  318. {
  319. HRESULT hr;
  320. // validate the start/stop times (either stop time == 0 or starttime <= stop time)
  321. if ( !( (0 == StopTime) || (StartTime <= StopTime) ) )
  322. {
  323. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  324. }
  325. m_StartTime.SetValueAndFlag(StartTime);
  326. m_StopTime.SetValueAndFlag(StopTime);
  327. hr = FillArrays();
  328. return hr;
  329. }
  330. inline HRESULT
  331. SDP_TIME::SetStartTime(
  332. IN ULONG StartTime
  333. )
  334. {
  335. HRESULT hr;
  336. hr = FillArrays();
  337. if ( FAILED(hr) )
  338. {
  339. return hr;
  340. }
  341. // set the value and the valid, modified flag
  342. m_StartTime.SetValueAndFlag(StartTime);
  343. // if the stop time is invalid, there is nothing to compare against
  344. if ( !m_StopTime.IsValid() )
  345. {
  346. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  347. }
  348. // check if the new start time is <= the current stop time,
  349. // special case for an unbounded start/stop time (value 0)
  350. if ( !((0 == m_StopTime.GetValue()) ||
  351. (0 == StartTime) ||
  352. (StartTime <= m_StopTime.GetValue())) )
  353. {
  354. // unbound the stop time
  355. m_StopTime.SetValueAndFlag(0);
  356. }
  357. return S_OK;
  358. }
  359. inline HRESULT
  360. SDP_TIME::SetStopTime(
  361. IN ULONG StopTime
  362. )
  363. {
  364. HRESULT hr;
  365. hr = FillArrays();
  366. if ( FAILED(hr) )
  367. {
  368. return hr;
  369. }
  370. // set the value and the valid, modified flag
  371. m_StopTime.SetValueAndFlag(StopTime);
  372. // if the start time is invalid, there is nothing to compare against
  373. if ( !m_StartTime.IsValid() )
  374. {
  375. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  376. }
  377. // check if the current start time is <= the new stop time,
  378. // special case for an unbounded start/stop time (value 0)
  379. if ( !((0 == m_StartTime.GetValue()) ||
  380. (0 == StopTime) ||
  381. (m_StartTime.GetValue() <= StopTime)) )
  382. {
  383. // unbound the start time
  384. m_StartTime.SetValueAndFlag(0);
  385. }
  386. return S_OK;
  387. }
  388. inline HRESULT
  389. SDP_TIME::GetStartTime(
  390. OUT ULONG &StartTime
  391. )
  392. {
  393. // check if the value being asked for is valid
  394. if ( !m_StartTime.IsValid() )
  395. {
  396. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  397. }
  398. StartTime = m_StartTime.GetValue();
  399. return S_OK;
  400. }
  401. inline HRESULT
  402. SDP_TIME::GetStopTime(
  403. OUT ULONG &StopTime
  404. )
  405. {
  406. // check if the value being asked for is valid
  407. if ( !m_StopTime.IsValid() )
  408. {
  409. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  410. }
  411. StopTime = m_StopTime.GetValue();
  412. return S_OK;
  413. }
  414. inline SDP_REPEAT_LIST &
  415. SDP_TIME::GetRepeatList(
  416. )
  417. {
  418. return m_RepeatList;
  419. }
  420. class _DllDecl SDP_TIME_LIST : public SDP_VALUE_LIST
  421. {
  422. public:
  423. virtual void Reset();
  424. inline SDP_ADJUSTMENT &GetAdjustment();
  425. virtual BOOL IsModified() const;
  426. virtual DWORD GetCharacterStringSize();
  427. virtual BOOL PrintValue(
  428. OUT ostrstream &OutputStream
  429. );
  430. protected:
  431. SDP_ADJUSTMENT m_Adjustment;
  432. virtual SDP_VALUE *CreateElement();
  433. };
  434. inline SDP_ADJUSTMENT &
  435. SDP_TIME_LIST::GetAdjustment(
  436. )
  437. {
  438. return m_Adjustment;
  439. }
  440. #endif // __SDP_TIME__