[icinga-checkins] icinga.org: icinga2/master: Removed dependency on boost/uuid.

git at icinga.org git at icinga.org
Fri May 3 11:26:35 CEST 2013


Module: icinga2
Branch: master
Commit: 10dff1d8c1b4273f7117b722c7b315e4b38a10c7
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=10dff1d8c1b4273f7117b722c7b315e4b38a10c7

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri May  3 11:26:18 2013 +0200

Removed dependency on boost/uuid.

---

 lib/base/utility.cpp                 |   33 +++++++++++++++++++++++++--------
 lib/base/utility.h                   |    2 +-
 lib/config/configcompilercontext.cpp |    2 +-
 lib/icinga/service-comment.cpp       |    2 +-
 lib/icinga/service-downtime.cpp      |    2 +-
 5 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp
index c7d3df5..80f730d 100644
--- a/lib/base/utility.cpp
+++ b/lib/base/utility.cpp
@@ -18,13 +18,11 @@
  ******************************************************************************/
 
 #include "base/utility.h"
+#include "base/convert.h"
 #include "base/application.h"
 #include "base/logger_fwd.h"
 #include "base/exception.h"
 #include <mmatch.h>
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/function.hpp>
 #include <boost/foreach.hpp>
@@ -276,14 +274,33 @@ Utility::LoadExtensionLibrary(const String& library)
 }
 
 /**
- * Generates a new UUID.
+ * Generates a new unique ID.
  *
- * @returns The new UUID in text form.
+ * @returns The new unique ID.
  */
-String Utility::NewUUID(void)
+String Utility::NewUniqueID(void)
 {
-	boost::uuids::uuid uuid = boost::uuids::random_generator()();
-	return boost::lexical_cast<String>(uuid);
+	static boost::mutex mutex;
+	static int next_id = 0;
+
+	/* I'd much rather use UUIDs but RHEL is way too cool to have
+	 * a semi-recent version of boost. Yay. */
+
+	String id;
+
+	char buf[128];
+	if (gethostname(buf, sizeof(buf)) == 0)
+		id = String(buf) + "-";
+
+	id += Convert::ToString((long)Utility::GetTime()) + "-";
+
+	{
+		boost::mutex::scoped_lock lock(mutex);
+		id += Convert::ToString(next_id);
+		next_id++;
+	}
+
+	return id;
 }
 
 /**
diff --git a/lib/base/utility.h b/lib/base/utility.h
index f3112bc..7288f61 100644
--- a/lib/base/utility.h
+++ b/lib/base/utility.h
@@ -53,7 +53,7 @@ public:
 
 	static void Sleep(double timeout);
 
-	static String NewUUID(void);
+	static String NewUniqueID(void);
 
 	static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback);
 
diff --git a/lib/config/configcompilercontext.cpp b/lib/config/configcompilercontext.cpp
index a412943..0a346f3 100644
--- a/lib/config/configcompilercontext.cpp
+++ b/lib/config/configcompilercontext.cpp
@@ -29,7 +29,7 @@ using namespace icinga;
 ConfigCompilerContext *ConfigCompilerContext::m_Context = NULL;
 
 ConfigCompilerContext::ConfigCompilerContext(void)
-	: m_Unit(Utility::NewUUID()), m_Flags(0)
+	: m_Unit(Utility::NewUniqueID()), m_Flags(0)
 { }
 
 void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item)
diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp
index e41bcca..23c80af 100644
--- a/lib/icinga/service-comment.cpp
+++ b/lib/icinga/service-comment.cpp
@@ -81,7 +81,7 @@ String Service::AddComment(CommentType entryType, const String& author,
 		m_Comments = comments;
 	}
 
-	String id = Utility::NewUUID();
+	String id = Utility::NewUniqueID();
 	comments->Set(id, comment);
 
 	Touch("comments");
diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp
index eed8990..654e3f4 100644
--- a/lib/icinga/service-downtime.cpp
+++ b/lib/icinga/service-downtime.cpp
@@ -96,7 +96,7 @@ String Service::AddDowntime(const String& author, const String& comment,
 		m_Downtimes = downtimes;
 	}
 
-	String id = Utility::NewUUID();
+	String id = Utility::NewUniqueID();
 	downtimes->Set(id, downtime);
 
 	Touch("downtimes");





More information about the icinga-checkins mailing list