diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index 3ae7e0519..d16f21da3 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -4,12 +4,16 @@ pkglib_LTLIBRARIES = \ livestatus.la livestatus_la_SOURCES = \ + andfilter.cpp \ + andfilter.h \ component.cpp \ component.h \ connection.cpp \ connection.h \ filter.cpp \ filter.h \ + orfilter.cpp \ + orfilter.h \ query.cpp \ query.h \ statustable.cpp \ diff --git a/components/livestatus/andfilter.cpp b/components/livestatus/andfilter.cpp new file mode 100644 index 000000000..4e56fb533 --- /dev/null +++ b/components/livestatus/andfilter.cpp @@ -0,0 +1,41 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "i2-livestatus.h" + +using namespace icinga; +using namespace livestatus; + +AndFilter::AndFilter(void) +{ } + +bool AndFilter::Apply(const Object::Ptr& object) +{ + BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) { + if (!filter->Apply(object)) + return false; + } + + return true; +} + +void AndFilter::AddSubFilter(const Filter::Ptr& filter) +{ + m_Filters.push_back(filter); +} \ No newline at end of file diff --git a/components/livestatus/andfilter.h b/components/livestatus/andfilter.h new file mode 100644 index 000000000..dac34afc8 --- /dev/null +++ b/components/livestatus/andfilter.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef ANDFILTER_H +#define ANDFILTER_H + +namespace livestatus +{ + +/** + * @ingroup livestatus + */ +class AndFilter : public Filter +{ +public: + typedef shared_ptr Ptr; + typedef weak_ptr WeakPtr; + + AndFilter(void); + + virtual bool Apply(const Object::Ptr& object); + + void AddSubFilter(const Filter::Ptr& filter); + +private: + vector m_Filters; +}; + +} + +#endif /* ANDFILTER_H */ diff --git a/components/livestatus/i2-livestatus.h b/components/livestatus/i2-livestatus.h index 765173feb..73ebd4663 100644 --- a/components/livestatus/i2-livestatus.h +++ b/components/livestatus/i2-livestatus.h @@ -35,6 +35,8 @@ using namespace icinga; #include "connection.h" #include "query.h" #include "filter.h" +#include "orfilter.h" +#include "andfilter.h" #include "table.h" #include "statustable.h" #include "contactgroupstable.h" diff --git a/components/livestatus/livestatus.vcxproj b/components/livestatus/livestatus.vcxproj index dc0a478d4..ff9c42e56 100644 --- a/components/livestatus/livestatus.vcxproj +++ b/components/livestatus/livestatus.vcxproj @@ -19,22 +19,26 @@ + + + + diff --git a/components/livestatus/livestatus.vcxproj.filters b/components/livestatus/livestatus.vcxproj.filters index a3f9f6b58..327e12117 100644 --- a/components/livestatus/livestatus.vcxproj.filters +++ b/components/livestatus/livestatus.vcxproj.filters @@ -36,6 +36,12 @@ Headerdateien + + Headerdateien + + + Headerdateien + @@ -62,5 +68,11 @@ Quelldateien + + Quelldateien + + + Quelldateien + \ No newline at end of file diff --git a/components/livestatus/orfilter.cpp b/components/livestatus/orfilter.cpp new file mode 100644 index 000000000..5989610d3 --- /dev/null +++ b/components/livestatus/orfilter.cpp @@ -0,0 +1,44 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "i2-livestatus.h" + +using namespace icinga; +using namespace livestatus; + +OrFilter::OrFilter(void) +{ } + +bool OrFilter::Apply(const Object::Ptr& object) +{ + if (m_Filters.empty()) + return true; + + BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) { + if (filter->Apply(object)) + return true; + } + + return false; +} + +void OrFilter::AddSubFilter(const Filter::Ptr& filter) +{ + m_Filters.push_back(filter); +} \ No newline at end of file diff --git a/components/livestatus/orfilter.h b/components/livestatus/orfilter.h new file mode 100644 index 000000000..0433354e1 --- /dev/null +++ b/components/livestatus/orfilter.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef ORFILTER_H +#define ORFILTER_H + +namespace livestatus +{ + +/** + * @ingroup livestatus + */ +class OrFilter : public Filter +{ +public: + typedef shared_ptr Ptr; + typedef weak_ptr WeakPtr; + + OrFilter(void); + + virtual bool Apply(const Object::Ptr& object); + + void AddSubFilter(const Filter::Ptr& filter); + +private: + vector m_Filters; +}; + +} + +#endif /* ORFILTER_H */