Files
2024-09-23 12:00:04 -04:00

344 lines
9.7 KiB
C++

/*
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
*
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
* and international copyright treaties.
*
* Access to and use of the software is governed by the terms of the applicable OnixS Software
* Services Agreement (the Agreement) and Customer end user license agreements granting
* a non-assignable, non-transferable and non-exclusive license to use the software
* for it's own data processing purposes under the terms defined in the Agreement.
*
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
* of this source code or associated reference material to any other location for further reproduction
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
*
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
* the terms of the Agreement is a violation of copyright law.
*/
#pragma once
#include <string>
#include <vector>
#include <OnixS/FIXEngine/ABI.h>
#if !defined (MINMAX_ABUSER)
#define UNDEF_MINMAX_ABUSER
#define MINMAX_ABUSER
#endif
namespace OnixS {
namespace FIX {
namespace Scheduling {
/// Specifies an activity time frame for the session.
struct
ONIXS_FIXENGINE_API
SessionDuration {
enum Enum {
/// The session continues not more than 24 hours.
/// That is the session logon and logout are
/// performed within bounds of the single day.
Day,
/// The session logon/logout occurs only once per week.
Week
};
/// Transforms the string presentation into a valid constant.
static Enum parse(const std::string & value);
/// Builds the string presentation for a given constant.
static std::string toString(Enum value);
};
/// Defines the session sequence number reset policy.
struct
ONIXS_FIXENGINE_API
SequenceNumberResetPolicy {
enum Enum {
/// The session sequence number must never
/// be reset by scheduling services.
Never,
/// The session sequence number reset
/// is performed on daily basis.
Daily,
/// The session sequence number reset
/// is performed once per week.
Weekly
};
/// Transforms the string presentation into a valid constant.
static Enum parse(const std::string & value);
/// Builds the string presentation for a given constant.
static std::string toString(Enum value);
};
/// Specifies a day of the week.
struct
ONIXS_FIXENGINE_API
DayOfWeek {
enum Enum {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Total
};
/// Transforms the string presentation into a valid constant.
static Enum parse(const std::string & value);
/// Builds the string presentation for a given constant.
static std::string toString(Enum value);
};
// The alias of the number of hours.
typedef int Hours;
// The alias of the number of minutes.
typedef int Minutes;
// The alias of the number of seconds.
typedef int Seconds;
/// Represents the time of the day.
class ONIXS_FIXENGINE_API TimeOfDay
{
public:
/// The default initialization.
TimeOfDay();
/// Initializes an instance to a specified
/// number of hours, minutes, and seconds.
TimeOfDay(
Hours hours,
Minutes minutes,
Seconds = 0);
/// Initializes from another instance.
TimeOfDay(const TimeOfDay &);
/// Gets hours of the time of the day.
Hours hours() const;
/// Gets minutes of the time of the day.
Minutes minutes() const;
/// Gets the seconds component of the time of the day.
Seconds seconds() const;
/// Gets the total number of seconds since the midnight.
Seconds sinceMidnight() const;
/// Builds the string presentation.
std::string toString() const;
/// Checks whether the instance is equal to another one.
bool operator == (const TimeOfDay & other) const;
/// Checks whether the instance is unequal to another one.
bool operator != (const TimeOfDay & other) const;
// Reinitializes the instance from another one.
TimeOfDay & operator = (const TimeOfDay &);
/// Returns the current time of the day value.
static TimeOfDay now();
/// The 'Zero' point of the time of the day.
static TimeOfDay midnight();
/// An instance of the ill-formed time of the day.
static TimeOfDay bad();
/// Parses the time of day from its string presentation.
static TimeOfDay parse(const std::string &);
private:
Seconds seconds_;
TimeOfDay(Seconds);
};
inline
Seconds
TimeOfDay::sinceMidnight() const
{
return seconds_;
}
inline
bool
TimeOfDay::operator == (
const TimeOfDay & other) const
{
return seconds_ == other.seconds_;
}
inline
bool
TimeOfDay::operator != (
const TimeOfDay & other) const
{
return seconds_ != other.seconds_;
}
/// The collection of the time of day values indexed by the day of the week.
typedef TimeOfDay TimeOfDayOfWeek[DayOfWeek::Total];
/// Defines activity time frames for the session.
/// Also provides the ability to define the sequence number
/// reset policy for the session.
class ONIXS_FIXENGINE_API SessionSchedule
{
public:
/// Initializes the session schedule according to the given parameters.
///
/// If the session duration is a single day, then logon and logout
/// are performed each day from the first day of the week till the last
/// day of the week. If the session duration is defined as the entire week
/// then the session logon occurs on the first day of the week and
/// the corresponding logout is performed on the last day of the week.
///
/// The session sequence number reset policy must correspond to
/// the session duration time. In particular, if the session continues
/// for an entire week it's not possible to request the scheduler to reset
/// the session sequence number on daily basis.
///
/// @param firstDay Defines the first day of an activity week for the session.
///
/// @param lastDay Defines the last day of an activity week for the session.
///
/// @param logonTime Defines the time of the logon for the session for each
/// activity day if the session duration is a single day. If the session must
/// continue for an entire week, defines the time of the logon performed on
/// the first day of an activity week.
///
/// @param logoutTime Defines the time of the logout for the session for each
/// activity day if the session duration is a single day. If the session must
/// continue for an entire week, defines the time of the logout performed on the
/// last day of an activity week.
///
/// @param sessionDuration Defines whether the session continues
/// for an entire week or the activity time frame is limited for a single day.
///
/// @param seqNumberResetPolicy Defines the session sequence number reset policy.
SessionSchedule(
DayOfWeek::Enum firstDay,
DayOfWeek::Enum lastDay,
TimeOfDay logonTime,
TimeOfDay logoutTime,
SessionDuration::Enum sessionDuration,
SequenceNumberResetPolicy::Enum seqNumberResetPolicy);
/// Initializes a clone of the given instance.
SessionSchedule(const SessionSchedule & other);
/// The logon time for the session for the given day.
///
/// If the logon is not performed on the given day, it returns
/// the corresponding value equals to the TimeOfDay::bad() value.
TimeOfDay logonTime(DayOfWeek::Enum day) const;
/// Defines the logon time for the session for the given day.
void logonTime(DayOfWeek::Enum day, TimeOfDay time);
/// The logout time for the session for the given day.
///
/// If the logout is not performed on the given day, it returns
/// the corresponding value equals to the TimeOfDay::bad() value.
TimeOfDay logoutTime(DayOfWeek::Enum day) const;
/// Defines logout time for the session for given day.
void logoutTime(DayOfWeek::Enum day, TimeOfDay time);
/// Defines whether the session continues the entire week
/// or an activity time frame is limited for the single day.
SessionDuration::Enum sessionDuration() const;
/// Defines the session sequence number reset policy.
SequenceNumberResetPolicy::Enum sequenceNumberResetPolicy() const;
/// The day of the week on which the session message sequence numbers are reset.
DayOfWeek::Enum sequenceNumberWeeklyResetDay() const;
/// Reinitializes the instance from another one.
SessionSchedule & operator = (const SessionSchedule & other);
std::string toString() const;
private:
friend class SessionStateChanger;
TimeOfDayOfWeek logonTimes_;
TimeOfDayOfWeek logoutTimes_;
SessionDuration::Enum sessionDuration_;
SequenceNumberResetPolicy::Enum seqNumberResetPolicy_;
DayOfWeek::Enum startOfWeek_;
DayOfWeek::Enum endOfWeek_;
};
inline
TimeOfDay
SessionSchedule::logonTime(DayOfWeek::Enum day) const
{
return logonTimes_[day];
}
inline
void
SessionSchedule::logonTime(
DayOfWeek::Enum day, TimeOfDay logonTime)
{
logonTimes_[day] = logonTime;
}
inline
TimeOfDay
SessionSchedule::logoutTime(DayOfWeek::Enum day) const
{
return logoutTimes_[day];
}
inline
void
SessionSchedule::logoutTime(
DayOfWeek::Enum day, TimeOfDay logoutTime)
{
logoutTimes_[day] = logoutTime;
}
inline
SessionDuration::Enum
SessionSchedule::sessionDuration() const
{
return sessionDuration_;
}
inline
SequenceNumberResetPolicy::Enum
SessionSchedule::sequenceNumberResetPolicy() const
{
return seqNumberResetPolicy_;
}
inline
DayOfWeek::Enum
SessionSchedule::sequenceNumberWeeklyResetDay() const
{
return startOfWeek_;
}
}
}
}