1 /******************************************************************************
3 * Copyright (C) 2012-2014 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 "remote/zone.hpp"
21 #include "remote/apiclient.hpp"
22 #include "base/objectlock.hpp"
23 #include <boost/foreach.hpp>
25 using namespace icinga;
29 Zone::Ptr Zone::GetParent(void) const
31 return Zone::GetByName(GetParentRaw());
34 std::set<Endpoint::Ptr> Zone::GetEndpoints(void) const
36 std::set<Endpoint::Ptr> result;
38 Array::Ptr endpoints = GetEndpointsRaw();
41 ObjectLock olock(endpoints);
43 BOOST_FOREACH(const String& name, endpoints) {
44 Endpoint::Ptr endpoint = Endpoint::GetByName(name);
49 result.insert(endpoint);
56 bool Zone::CanAccessObject(const DynamicObject::Ptr& object)
58 Zone::Ptr object_zone;
60 if (dynamic_pointer_cast<Zone>(object))
61 object_zone = static_pointer_cast<Zone>(object);
63 object_zone = Zone::GetByName(object->GetZone());
66 object_zone = Zone::GetLocalZone();
68 return object_zone->IsChildOf(this);
71 bool Zone::IsChildOf(const Zone::Ptr& zone)
73 Zone::Ptr azone = this;
79 azone = azone->GetParent();
85 bool Zone::IsGlobal(void) const
90 Zone::Ptr Zone::GetLocalZone(void)
92 Endpoint::Ptr local = Endpoint::GetLocalEndpoint();
97 return local->GetZone();