filelogger.cpp \
filelogger.h \
i2-base.h \
+ initialize.h \
logger.cpp \
logger.h \
logger_fwd.h \
--- /dev/null
+/******************************************************************************
+ * 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 UTILITY_H
+#define UTILITY_H
+
+#include "base/i2-base.h"
+
+namespace icinga
+{
+
+typedef void (*InitializeFunc)(void);
+
+inline bool InitializeOnceHelper(InitializeFunc func)
+{
+ func();
+
+ return true;
+}
+
+#define INITIALIZE_ONCE(func) \
+ static bool l_InitializeOnce ## __LINE__(InitializeOnceHelper(func));
+
+}
+
+#endif /* UTILITY_H */
#include "icinga/icingaapplication.h"
#include "base/dynamictype.h"
#include "base/utility.h"
+#include "base/initialize.h"
#include <boost/foreach.hpp>
using namespace icinga;
Timer::Ptr DbConnection::m_ProgramStatusTimer;
+INITIALIZE_ONCE(&DbConnection::StaticInitialize);
+
DbConnection::DbConnection(const Dictionary::Ptr& serializedUpdate)
: DynamicObject(serializedUpdate)
{
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/utility.h"
+#include "base/initialize.h"
#include "base/logger_fwd.h"
#include <boost/foreach.hpp>
boost::signals2::signal<void (const DbObject::Ptr&)> DbObject::OnUnregistered;
boost::signals2::signal<void (const DbQuery&)> DbObject::OnQuery;
+INITIALIZE_ONCE(&DbObject::StaticInitialize);
+
DbObject::DbObject(const shared_ptr<DbType>& type, const String& name1, const String& name2)
: m_Name1(name1), m_Name2(name2), m_Type(type), m_LastConfigUpdate(0), m_LastStatusUpdate(0)
{ }
DbType::DbType(const String& name, const String& table, long tid, const DbType::ObjectFactory& factory)
: m_Name(name), m_Table(table), m_TypeID(tid), m_ObjectFactory(factory)
-{
- static boost::once_flag initializeOnce = BOOST_ONCE_INIT;
- boost::call_once(initializeOnce, &DbType::StaticInitialize);
-}
-
-void DbType::StaticInitialize(void)
-{
- DbConnection::StaticInitialize();
- DbObject::StaticInitialize();
-}
+{ }
String DbType::GetName(void) const
{
static TypeMap& GetTypes(void);
ObjectMap& GetObjects(void);
-
- static void StaticInitialize(void);
};
/**