Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
MON-11764-backport (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 authored and bouda1 committed Jun 2, 2022
1 parent 19b1e70 commit 805b8cf
Show file tree
Hide file tree
Showing 26 changed files with 363 additions and 1,158 deletions.
6 changes: 0 additions & 6 deletions inc/com/centreon/engine/configuration/applier/timeperiod.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ CCE_BEGIN()

namespace configuration {
// Forward declarations.
class daterange;
class state;
class timeperiod;
class timerange;

namespace applier {
class timeperiod {
Expand All @@ -53,10 +51,6 @@ class timeperiod {
private:
void _add_exclusions(std::set<std::string> const& exclusions,
com::centreon::engine::timeperiod* tp);
void _add_exceptions(std::vector<std::list<daterange> > const& exceptions,
com::centreon::engine::timeperiod* tp);
void _add_time_ranges(std::vector<std::list<timerange> > const& ranges,
com::centreon::engine::timeperiod* tp);
};
} // namespace applier
} // namespace configuration
Expand Down
95 changes: 0 additions & 95 deletions inc/com/centreon/engine/configuration/daterange.hh

This file was deleted.

23 changes: 14 additions & 9 deletions inc/com/centreon/engine/configuration/timeperiod.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <set>
#include <string>
#include <vector>
#include "com/centreon/engine/configuration/daterange.hh"
#include "com/centreon/engine/daterange.hh"
#include "com/centreon/engine/configuration/group.hh"
#include "com/centreon/engine/configuration/object.hh"
#include "com/centreon/engine/namespace.hh"
Expand All @@ -33,6 +33,9 @@
CCE_BEGIN()

namespace configuration {
namespace test {
class time_period_comparator;
}
class timeperiod : public object {
public:
typedef std::string key_type;
Expand All @@ -41,20 +44,22 @@ class timeperiod : public object {
timeperiod(timeperiod const& right);
~timeperiod() throw() override;
timeperiod& operator=(timeperiod const& right);
bool operator==(timeperiod const& right) const throw();
bool operator!=(timeperiod const& right) const throw();
bool operator<(timeperiod const& right) const throw();
bool operator==(timeperiod const& right) const;
bool operator!=(timeperiod const& right) const;
bool operator<(timeperiod const& right) const;
void check_validity() const override;
key_type const& key() const throw();
void merge(object const& obj) override;
bool parse(char const* key, char const* value) override;
bool parse(std::string const& line) override;

std::string const& alias() const throw();
std::vector<std::list<daterange> > const& exceptions() const throw();
exception_array const& exceptions() const throw();
set_string const& exclude() const throw();
std::string const& timeperiod_name() const throw();
std::vector<std::list<timerange> > const& timeranges() const throw();
days_array const& timeranges() const;

friend test::time_period_comparator;

private:
typedef bool (*setter_func)(timeperiod&, char const*);
Expand All @@ -63,7 +68,7 @@ class timeperiod : public object {
bool _add_other_date(std::string const& line);
bool _add_week_day(std::string const& key, std::string const& value);
static bool _build_timeranges(std::string const& line,
std::list<timerange>& timeranges);
timerange_list& timeranges);
static bool _build_time_t(std::string const& time_str, unsigned long& ret);
static bool _has_similar_daterange(std::list<daterange> const& lst,
daterange const& range) throw();
Expand All @@ -75,10 +80,10 @@ class timeperiod : public object {

std::string _alias;
static std::unordered_map<std::string, setter_func> const _setters;
std::vector<std::list<daterange> > _exceptions;
exception_array _exceptions;
group<set_string> _exclude;
std::string _timeperiod_name;
std::vector<std::list<timerange> > _timeranges;
days_array _timeranges;
};

typedef std::shared_ptr<timeperiod> timeperiod_ptr;
Expand Down
50 changes: 0 additions & 50 deletions inc/com/centreon/engine/configuration/timerange.hh

This file was deleted.

92 changes: 56 additions & 36 deletions inc/com/centreon/engine/daterange.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef CCE_OBJECTS_DATERANGE_HH
#define CCE_OBJECTS_DATERANGE_HH
#include <ostream>
#include "com/centreon/engine/common.hh"
#include "com/centreon/engine/timerange.hh"

struct timeperiod_struct;
Expand All @@ -28,14 +29,24 @@ CCE_BEGIN()
class daterange;
CCE_END()

typedef std::list<std::shared_ptr<com::centreon::engine::daterange>>
daterange_list;
using daterange_list = std::list<com::centreon::engine::daterange>;

using exception_array = std::array<daterange_list, DATERANGE_TYPES>;

CCE_BEGIN()

class daterange {
public:
daterange(int type,
enum type_range {
none = -1,
calendar_date = 0,
month_date = 1,
month_day = 2,
month_week_day = 3,
week_day = 4
};

daterange(type_range type,
int syear,
int smon,
int smday,
Expand All @@ -47,42 +58,48 @@ class daterange {
int ewday,
int ewday_offset,
int skip_interval);
daterange(type_range type);

int get_type() const;
void set_type(int type);
int get_syear() const;
void set_syear(int syear);
int get_smon() const;
void set_smon(int smon);
int get_smday() const;
void set_smday(int smday);
int get_swday() const;
void set_swday(int swday);
int get_swday_offset() const;
void set_swday_offset(int swday_offset);
int get_eyear() const;
void set_eyear(int eyear);
int get_emon() const;
void set_emon(int emon);
int get_emday() const;
void set_emday(int emday);
int get_ewday() const;
void set_ewday(int ewday);
int get_ewday_offset() const;
void set_ewday_offset(int ewday_offset);
int get_skip_interval() const;
void set_skip_interval(int skip_interval);

bool operator==(daterange const& obj) throw();
bool operator!=(daterange const& obj2) throw();

timerange_list times;
type_range get_type() const { return _type; }
void set_type(type_range type) { _type = type; }
int get_syear() const { return _syear; }
void set_syear(int syear) { _syear = syear; }
int get_smon() const { return _smon; }
void set_smon(int smon) { _smon = smon; }
int get_smday() const { return _smday; }
void set_smday(int smday) { _smday = smday; }
int get_swday() const { return _swday; }
void set_swday(int swday) { _swday = swday; }
int get_swday_offset() const { return _swday_offset; }
void set_swday_offset(int swday_offset) { _swday_offset = swday_offset; }
int get_eyear() const { return _eyear; }
void set_eyear(int eyear) { _eyear = eyear; }
int get_emon() const { return _emon; }
void set_emon(int emon) { _emon = emon; }
int get_emday() const { return _emday; }
void set_emday(int emday) { _emday = emday; }
int get_ewday() const { return _ewday; }
void set_ewday(int ewday) { _ewday = ewday; }
int get_ewday_offset() const { return _ewday_offset; }
void set_ewday_offset(int ewday_offset) { _ewday_offset = ewday_offset; }
int get_skip_interval() const { return _skip_interval; }
void set_skip_interval(int skip_interval) { _skip_interval = skip_interval; }
const timerange_list& get_timerange() const { return _timerange; }
void set_timerange(const timerange_list& timerange) {
_timerange = timerange;
}
void add_timerange(const timerange& toadd) { _timerange.push_back(toadd); }

bool operator==(daterange const& obj) const;
bool operator!=(daterange const& obj2) const;
bool operator<(daterange const& right) const;
bool is_date_data_equal(daterange const& obj) const;

static std::string const& get_month_name(unsigned int index);
static std::string const& get_weekday_name(unsigned int index);

private:
int _type;
type_range _type;
int _syear; // Start year.
int _smon; // Start month.
// Start day of month (may 3rd, last day in feb).
Expand All @@ -96,11 +113,14 @@ class daterange {
int _ewday;
int _ewday_offset;
int _skip_interval;
timerange_list _timerange;
};

CCE_END()

std::ostream& operator<<(std::ostream& os,
com::centreon::engine::daterange const& obj);

#endif // !CCE_OBJECTS_DATERANGE_HH
std::ostream& operator<<(std::ostream& os, exception_array const& obj);

CCE_END()

#endif // !CCE_OBJECTS_DATERANGE_HH
12 changes: 6 additions & 6 deletions inc/com/centreon/engine/timeperiod.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class timeperiod {
public:
timeperiod(std::string const& name, std::string const& alias);

std::string const& get_name() const;
std::string const& get_name() const { return _name; };
void set_name(std::string const& name);
std::string const get_alias() const;
std::string const get_alias() const { return _alias; };
void set_alias(std::string const& alias);
timeperiodexclusion const& get_exclusions() const;
timeperiodexclusion& get_exclusions();
timeperiodexclusion const& get_exclusions() const { return _exclusions; };
timeperiodexclusion& get_exclusions() { return _exclusions; };
void get_next_valid_time_per_timeperiod(time_t preferred_time,
time_t* invalid_time,
bool notif_timeperiod);
Expand All @@ -63,8 +63,8 @@ class timeperiod {
bool operator==(timeperiod const& obj) throw();
bool operator!=(timeperiod const& obj) throw();

std::array<timerange_list, 7> days;
std::array<daterange_list, DATERANGE_TYPES> exceptions;
days_array days;
exception_array exceptions;

static timeperiod_map timeperiods;

Expand Down
Loading

0 comments on commit 805b8cf

Please sign in to comment.