Task #3118
closedDesign and implement the abstraction for schedule
100%
Description
This is a draft abstraction for schedule. It consists of two classes.
Schedule¶
A schedule contains two sets of RepetitiveIntervals: a white list and a black list.
The accessible time intervals of a schedule are those covered by one RepetitiveInterval in the white list but not by any RepetitiveInterval in the black list.
Schedule implements WireEncodable and WireDecodable concept to facilitate storage.
RepetitiveInterval¶
The element object in Schedule. A RepetitiveInterval is a time interval with the repeated pattern.
RepetitiveInterval has six properties: startDate, endDate, intervalStartTime, intervalEndTime, repeatUnit, and nRepeats.
startDate and endDate are expressed as date, e.g., "20150822T000000";
intervalStartTime and intervalEndTime are expressed as a particular hour in a day, i.e., an interval from 0 to 23;
repeatUnit is either day, month, or year;
nRepeat x repeatUnit is the interval between two repetitions.
One can interpret a RepetitiveInterval as:
"starting from startDate, repeat an interval from intervalStartTime to intervalEndTime for every (nRepeat x repeatUnit) until endDate.
Note that:
- nRepeat = 0 means no repetition
- endDate could be infinite
- repeatUnit = day and nRepeat = 7 is equivalent to repetition per week.
An example of RepetitiveInterval would look like:
- startDate: 20150822T000000
- endDate: 20160822T000000
- intervalStartTime: 16
- intervalEndTime: 18
- repeatUnit: day
- nRepeat: 7
RepetitiveInterval also implements WireEncodable and WireDecodable concept to facilitate storage.
Interval¶
A simple class which contains a start time and an end time.
It is used to as the return value of some member methods of Schedule.
Class Interface¶
class Schedule
{
public:
///@brief Construct an schedule
Schedule();
Schedule(const Block& block);
public:
template<encoding::Tag TAG>
size_t
wireEncode(EncodingImpl<TAG>& encoder) const;
Block
wireEncode() const;
void
wireDecode(const Block& block);
///@brief Add an RepetitiveInterval @p repetitiveInterval into white list
Schedule&
addWhiteInterval(RepetitiveInterval repetitiveInterval);
///@brief Add the RepetitiveInterval into black list
Schedule&
addBlackInterval(RepetitiveInterval repetitiveInterval);
///@brief Get the Interval that covers the @p ts
Interval
getCoveringInterval(const TimePoint& ts) const;
private:
std::set<RepetitiveInterval> m_whiteIntervalList;
std::set<RepetitiveInterval> m_blackIntervalList;
Block m_wire;
};
class RepetitiveInterval
{
public:
enum class RepeatUnit{
NONE = 0,
DAY = 1,
MONTH = 2,
YEAR = 3
};
public:
RepetitiveInterval();
RepetitiveInterval(Block& block);
RepetitiveInterval(const TimePoint& startDate,
const TimePoint& endDate,
Hour intervalStartTime,
Hour intervalEndTime,
size_t nRepeats = 0,
RepeatUnit unit = RepetitiveInterval::NONE);
template<encoding::Tag TAG>
size_t
wireEncode(EncodingImpl<TAG>& encoder) const;
Block
wireEncode();
void
wireDecode(const Block& block);
///@brief Check if the time point @p ts is covered by the RepetitiveInterval
bool
covers(const TimePoint& tp) const;
///@brief Get the covering interval for time point @p ts
Interval
getCoveringInterval(const TimePoint& tp) const;
///@brief To store in std::set
bool
operator <(const RepetitiveInterval& interval) const;
private:
bool
hasIntervalOnDate(const TimePoint& tp) const;
TimePoint m_startDate;
TimePoint m_endDate;
Hour m_intervalStartTime;
Hour m_intervalEndTime;
size_t m_nRepeats = 0;
RepeatUnit m_unit;
Block m_wire;
};
class Interval
{
public:
Interval();
Interval(const TimePoint& startTime,
const TimePoint& endTime
bool isPositive);
bool
covers(TimePoint tp);
Interval
operator &&(const Interval& interval) const;
Interval
operator ||(const Interval& interval) const;
operator bool() const;
operator !() const;
private:
TimePoint m_startTime;
TimePoint m_endTime;
bool isPositive;
};
Updated by Yingdi Yu over 8 years ago
- Subject changed from Draft abstraction for schedule to Design and implement the abstraction for schedule
- Assignee set to Zhiyi Zhang
Updated by Anonymous over 8 years ago
I see you pushed this code to GitHub. Is it ready for me to port to Java, etc.?
https://github.com/named-data/ndn-group-encrypt/commit/cea58d57c00edd4b510950b1db1a6a555200b517
Updated by Zhiyi Zhang over 8 years ago
Jeff Thompson wrote:
I see you pushed this code to GitHub. Is it ready for me to port to Java, etc.?
https://github.com/named-data/ndn-group-encrypt/commit/cea58d57c00edd4b510950b1db1a6a555200b517
As for this, I think you can talk with Yingdi. I am not sure if there will be any improvements to this part in the future. And one thing is that some bugs were removed but the changes have not been merged yet.
Updated by Zhiyi Zhang over 8 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
Updated by Anonymous over 8 years ago
Is the TLV definition for Schedule documented somewhere with the TLV type codes (like EncryptedContent is in task #2750)?