1 /******************************************************************************
3 * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "i2-icinga.h"
22 using namespace icinga;
24 static AttributeDescription timePeriodAttributes[] = {
25 { "cached_state", Attribute_Transient },
26 { "cached_next_change", Attribute_Transient }
29 REGISTER_TYPE(TimePeriod, timePeriodAttributes);
31 String TimePeriod::GetAlias(void) const
33 String value = Get("alias");
41 bool TimePeriod::Exists(const String& name)
43 return (DynamicObject::GetObject("TimePeriod", name));
46 TimePeriod::Ptr TimePeriod::GetByName(const String& name)
48 DynamicObject::Ptr configObject = DynamicObject::GetObject("TimePeriod", name);
51 throw_exception(invalid_argument("TimePeriod '" + name + "' does not exist."));
53 return dynamic_pointer_cast<TimePeriod>(configObject);
56 bool TimePeriod::IsActive(void) {
57 if (GetNextChange() > Utility::GetTime()) {
59 args.push_back(static_cast<TimePeriod::Ptr>(GetSelf()));
60 return InvokeMethodSync<bool>("is_active", args);
62 return Get("cached_state");
66 double TimePeriod::GetNextChange(void) {
67 double next_change = Get("cached_next_change");
69 if (next_change < Utility::GetTime()) {
71 args.push_back(static_cast<TimePeriod::Ptr>(GetSelf()));
72 next_change = InvokeMethodSync<bool>("is_active", args);
73 // TODO: figure out next_change by calling method
75 Set("cached_next_change", next_change);