]> granicus.if.org Git - icinga2/blob - lib/livestatus/timeperiodstable.cpp
Update copyright year
[icinga2] / lib / livestatus / timeperiodstable.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #include "livestatus/timeperiodstable.hpp"
21 #include "icinga/icingaapplication.hpp"
22 #include "icinga/timeperiod.hpp"
23 #include "base/dynamictype.hpp"
24 #include "base/objectlock.hpp"
25 #include "base/convert.hpp"
26 #include "base/utility.hpp"
27 #include <boost/foreach.hpp>
28 #include <boost/algorithm/string/replace.hpp>
29
30 using namespace icinga;
31
32 TimePeriodsTable::TimePeriodsTable(void)
33 {
34         AddColumns(this);
35 }
36
37 void TimePeriodsTable::AddColumns(Table *table, const String& prefix,
38     const Column::ObjectAccessor& objectAccessor)
39 {
40         table->AddColumn(prefix + "name", Column(&TimePeriodsTable::NameAccessor, objectAccessor));
41         table->AddColumn(prefix + "alias", Column(&TimePeriodsTable::AliasAccessor, objectAccessor));
42         table->AddColumn(prefix + "in", Column(&TimePeriodsTable::InAccessor, objectAccessor));
43 }
44
45 String TimePeriodsTable::GetName(void) const
46 {
47         return "timeperiod";
48 }
49
50 String TimePeriodsTable::GetPrefix(void) const
51 {
52         return "timeperiod";
53 }
54
55 void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
56 {
57         BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjectsByType<TimePeriod>()) {
58                 addRowFn(tp);
59         }
60 }
61
62 Value TimePeriodsTable::NameAccessor(const Value& row)
63 {
64         return static_cast<TimePeriod::Ptr>(row)->GetName();
65 }
66
67 Value TimePeriodsTable::AliasAccessor(const Value& row)
68 {
69         return static_cast<TimePeriod::Ptr>(row)->GetDisplayName();
70 }
71
72 Value TimePeriodsTable::InAccessor(const Value& row)
73 {
74         return (static_cast<TimePeriod::Ptr>(row)->IsInside(Utility::GetTime()) ? 1 : 0);
75 }
76
77