Blame 0003-Feature-alternative-range2random-provider-glib.patch

Jan Pokorný 0c140f
From cd8c7245e4f50269ec62b36cb56ef21e659c7578 Mon Sep 17 00:00:00 2001
Jan Pokorný b4585a
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
Jan Pokorný b4585a
Date: Wed, 24 Feb 2016 02:12:34 +0100
Jan Pokorný b4585a
Subject: [PATCH 3/6] Feature: alternative range2random provider: glib
Jan Pokorný b4585a
Jan Pokorný b4585a
Also check if cl_rand_from_interval is actually defined in
Jan Pokorný b4585a
<clplumbing/cl_random.h> (not the case with older glue/plumb lib).
Jan Pokorný b4585a
---
Jan Pokorný b4585a
 booth.spec                  |  2 ++
Jan Pokorný b4585a
 configure.ac                | 24 ++++++++++++++++++++++++
Jan Pokorný b4585a
 src/Makefile.am             |  8 ++++++++
Jan Pokorný b4585a
 src/alt/range2random_glib.c | 33 +++++++++++++++++++++++++++++++++
Jan Pokorný b4585a
 src/alt/range2random_glib.h | 22 ++++++++++++++++++++++
Jan Pokorný b4585a
 src/ticket.c                |  6 +++++-
Jan Pokorný b4585a
 6 files changed, 94 insertions(+), 1 deletion(-)
Jan Pokorný b4585a
 create mode 100644 src/alt/range2random_glib.c
Jan Pokorný b4585a
 create mode 100644 src/alt/range2random_glib.h
Jan Pokorný b4585a
Jan Pokorný b4585a
diff --git a/booth.spec b/booth.spec
Jan Pokorný b4585a
index cc73af2..b88ff4c 100644
Jan Pokorný b4585a
--- a/booth.spec
Jan Pokorný b4585a
+++ b/booth.spec
Jan Pokorný b4585a
@@ -69,6 +69,8 @@ BuildRequires:  libglue-devel
Jan Pokorný b4585a
 %else
Jan Pokorný b4585a
 # logging provider
Jan Pokorný b4585a
 BuildRequires:  pkgconfig(libqb)
Jan Pokorný b4585a
+# random2range provider
Jan Pokorný b4585a
+BuildRequires:  pkgconfig(glib-2.0)
Jan Pokorný b4585a
 %endif
Jan Pokorný b4585a
 BuildRequires:  libxml2-devel
Jan Pokorný b4585a
 BuildRequires:  zlib-devel
Jan Pokorný b4585a
diff --git a/configure.ac b/configure.ac
Jan Pokorný 0c140f
index 32a7dd1..10e131d 100644
Jan Pokorný b4585a
--- a/configure.ac
Jan Pokorný b4585a
+++ b/configure.ac
Jan Pokorný 0c140f
@@ -245,6 +245,29 @@ libqb)
Jan Pokorný b4585a
 esac
Jan Pokorný b4585a
 AM_CONDITIONAL([LOGGING_LIBQB], [test "x$logging_provider" = "xlibqb"])
Jan Pokorný b4585a
 
Jan Pokorný b4585a
+# figure out range2random provider
Jan Pokorný b4585a
+range2random_provider=""
Jan Pokorný b4585a
+if test "x$range2random_provider" = "x" && test "x$with_glue" = "xyes"; then
Jan Pokorný b4585a
+       AC_CHECK_LIB([plumb], [get_next_random], [range2random_provider="libplumb"])
Jan Pokorný b4585a
+       AC_CHECK_DECL([cl_rand_from_interval], [], [range2random_provider=""],
Jan Pokorný b4585a
+		     [#include <clplumbing/cl_random.h>])
Jan Pokorný b4585a
+fi
Jan Pokorný b4585a
+if test "x$range2random_provider" = "x" && test "x$with_glue" = "xno"; then
Jan Pokorný b4585a
+       AC_CHECK_LIB([glib-2.0], [g_random_int_range], [range2random_provider="glib"])
Jan Pokorný b4585a
+fi
Jan Pokorný b4585a
+case "$range2random_provider" in
Jan Pokorný b4585a
+libplumb)
Jan Pokorný b4585a
+	;;
Jan Pokorný b4585a
+glib)
Jan Pokorný b4585a
+	PKG_CHECK_MODULES([GLIB], [glib-2.0])
Jan Pokorný b4585a
+	AC_DEFINE([RANGE2RANDOM_GLIB], [], [use glib as a range2random provider])
Jan Pokorný b4585a
+	;;
Jan Pokorný b4585a
+*)
Jan Pokorný b4585a
+	AC_MSG_ERROR([range2random provider required (libplumb, or glib when --without-glue)])
Jan Pokorný b4585a
+	;;
Jan Pokorný b4585a
+esac
Jan Pokorný b4585a
+AM_CONDITIONAL([RANGE2RANDOM_GLIB], [test "x$range2random_provider" = "xglib"])
Jan Pokorný b4585a
+
Jan Pokorný b4585a
 # OS detection
Jan Pokorný b4585a
 # THIS SECTION MUST DIE!
Jan Pokorný b4585a
 CP=cp
Jan Pokorný 0c140f
@@ -474,6 +497,7 @@ AC_MSG_RESULT([  booth config dir         = ${BOOTHSYSCONFDIR}])
Jan Pokorný b4585a
 AC_MSG_RESULT([  SOCKETDIR                = ${SOCKETDIR}])
Jan Pokorný b4585a
 AC_MSG_RESULT([  Features                 = ${PACKAGE_FEATURES}])
Jan Pokorný b4585a
 AC_MSG_RESULT([  Logging provider         = ${logging_provider}])
Jan Pokorný b4585a
+AC_MSG_RESULT([  Range2random provider    = ${range2random_provider}])
Jan Pokorný b4585a
 AC_MSG_RESULT([])
Jan Pokorný b4585a
 AC_MSG_RESULT([$PACKAGE build info:])
Jan Pokorný b4585a
 AC_MSG_RESULT([  Library SONAME           = ${SONAME}])
Jan Pokorný b4585a
diff --git a/src/Makefile.am b/src/Makefile.am
Jan Pokorný b4585a
index 49c3ac4..317710e 100644
Jan Pokorný b4585a
--- a/src/Makefile.am
Jan Pokorný b4585a
+++ b/src/Makefile.am
Jan Pokorný b4585a
@@ -33,5 +33,13 @@ boothd_SOURCES		+= alt/logging_libqb.c
Jan Pokorný b4585a
 noinst_HEADERS		+= alt/logging_libqb.h
Jan Pokorný b4585a
 endif
Jan Pokorný b4585a
 
Jan Pokorný b4585a
+if !RANGE2RANDOM_GLIB
Jan Pokorný b4585a
+boothd_LDADD		+= -lplumb
Jan Pokorný b4585a
+else
Jan Pokorný b4585a
+boothd_LDADD		+= $(GLIB_LIBS)
Jan Pokorný b4585a
+boothd_SOURCES		+= alt/range2random_glib.c
Jan Pokorný b4585a
+noinst_HEADERS		+= alt/range2random_glib.h
Jan Pokorný b4585a
+endif
Jan Pokorný b4585a
+
Jan Pokorný b4585a
 lint:
Jan Pokorný b4585a
 	-splint $(INCLUDES) $(LINT_FLAGS) $(CFLAGS) *.c
Jan Pokorný b4585a
diff --git a/src/alt/range2random_glib.c b/src/alt/range2random_glib.c
Jan Pokorný b4585a
new file mode 100644
Jan Pokorný b4585a
index 0000000..8363559
Jan Pokorný b4585a
--- /dev/null
Jan Pokorný b4585a
+++ b/src/alt/range2random_glib.c
Jan Pokorný b4585a
@@ -0,0 +1,33 @@
Jan Pokorný b4585a
+/*
Jan Pokorný b4585a
+ * Copyright (C) 2016 Jan Pokorny <jpokorny@redhat.com>
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * This program is free software; you can redistribute it and/or
Jan Pokorný b4585a
+ * modify it under the terms of the GNU General Public
Jan Pokorný b4585a
+ * License as published by the Free Software Foundation; either
Jan Pokorný b4585a
+ * version 2.1 of the License, or (at your option) any later version.
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * This software is distributed in the hope that it will be useful,
Jan Pokorný b4585a
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Pokorný b4585a
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Jan Pokorný b4585a
+ * General Public License for more details.
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * You should have received a copy of the GNU General Public
Jan Pokorný b4585a
+ * License along with this library; if not, write to the Free Software
Jan Pokorný b4585a
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Jan Pokorný b4585a
+ */
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+#include <assert.h>
Jan Pokorný b4585a
+#include <stdlib.h>
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+#include <glib.h>
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+#include "range2random_glib.h"
Jan Pokorný b4585a
+#include "ticket.h"
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+int
Jan Pokorný b4585a
+alt_glib_rand_from_interval(int from, int to)
Jan Pokorný b4585a
+{
Jan Pokorný b4585a
+       assert(from >= 0 && from < to);
Jan Pokorný b4585a
+       assert(sizeof(to) <= sizeof(gint32) || (to < 0x7fffffff));
Jan Pokorný b4585a
+       return (int) g_random_int_range(from, to);
Jan Pokorný b4585a
+}
Jan Pokorný b4585a
diff --git a/src/alt/range2random_glib.h b/src/alt/range2random_glib.h
Jan Pokorný b4585a
new file mode 100644
Jan Pokorný b4585a
index 0000000..4b87c46
Jan Pokorný b4585a
--- /dev/null
Jan Pokorný b4585a
+++ b/src/alt/range2random_glib.h
Jan Pokorný b4585a
@@ -0,0 +1,22 @@
Jan Pokorný b4585a
+/*
Jan Pokorný b4585a
+ * Copyright (C) 2016 Jan Pokorny <jpokorny@redhat.com>
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * This program is free software; you can redistribute it and/or
Jan Pokorný b4585a
+ * modify it under the terms of the GNU General Public
Jan Pokorný b4585a
+ * License as published by the Free Software Foundation; either
Jan Pokorný b4585a
+ * version 2.1 of the License, or (at your option) any later version.
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * This software is distributed in the hope that it will be useful,
Jan Pokorný b4585a
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Pokorný b4585a
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Jan Pokorný b4585a
+ * General Public License for more details.
Jan Pokorný b4585a
+ *
Jan Pokorný b4585a
+ * You should have received a copy of the GNU General Public
Jan Pokorný b4585a
+ * License along with this library; if not, write to the Free Software
Jan Pokorný b4585a
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Jan Pokorný b4585a
+ */
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+int alt_glib_rand_from_interval(int from, int to);
Jan Pokorný b4585a
+
Jan Pokorný b4585a
+#define cl_rand_from_interval(from, to) \
Jan Pokorný b4585a
+	alt_glib_rand_from_interval(from, to)
Jan Pokorný b4585a
diff --git a/src/ticket.c b/src/ticket.c
Jan Pokorný 0c140f
index 09743f7..8d4cc12 100644
Jan Pokorný b4585a
--- a/src/ticket.c
Jan Pokorný b4585a
+++ b/src/ticket.c
Jan Pokorný b4585a
@@ -25,8 +25,12 @@
Jan Pokorný b4585a
 #include <stdio.h>
Jan Pokorný b4585a
 #include <assert.h>
Jan Pokorný b4585a
 #include <time.h>
Jan Pokorný b4585a
-#include <clplumbing/cl_random.h>
Jan Pokorný b4585a
 #include "b_config.h"
Jan Pokorný b4585a
+#ifndef RANGE2RANDOM_GLIB
Jan Pokorný b4585a
+#include <clplumbing/cl_random.h>
Jan Pokorný b4585a
+#else
Jan Pokorný b4585a
+#include "alt/range2random_glib.h"
Jan Pokorný b4585a
+#endif
Jan Pokorný b4585a
 #include "ticket.h"
Jan Pokorný b4585a
 #include "config.h"
Jan Pokorný b4585a
 #include "pacemaker.h"
Jan Pokorný b4585a
-- 
Jan Pokorný b4585a
2.4.11
Jan Pokorný b4585a