Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
po/POTFILES.in | 1 +
src/util/virevent.c | 25 +++++++++++++++++++++++++
src/util/virevent.h | 2 ++
3 files changed, 28 insertions(+)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index debb51cd70..b396797ff2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -238,6 +238,7 @@
@SRCDIR(a)/src/util/virdnsmasq.c
@SRCDIR(a)/src/util/virerror.c
@SRCDIR(a)/src/util/virerror.h
+@SRCDIR(a)/src/util/virevent.c
@SRCDIR(a)/src/util/vireventpoll.c
@SRCDIR(a)/src/util/virfcp.c
@SRCDIR(a)/src/util/virfdstream.c
diff --git a/src/util/virevent.c b/src/util/virevent.c
index 3cac9f9472..a86acf64c0 100644
--- a/src/util/virevent.c
+++ b/src/util/virevent.c
@@ -29,6 +29,9 @@
VIR_LOG_INIT("util.event");
+
+#define VIR_FROM_THIS VIR_FROM_EVENT
+
static virEventAddHandleFunc addHandleImpl;
static virEventUpdateHandleFunc updateHandleImpl;
static virEventRemoveHandleFunc removeHandleImpl;
@@ -251,6 +254,26 @@ void virEventRegisterImpl(virEventAddHandleFunc addHandle,
removeTimeoutImpl = removeTimeout;
}
+
+/**
+ * virEventRequireImpl:
+ *
+ * Require that there is an event loop implementation
+ * registered.
+ *
+ * Returns: -1 if no event loop is registered, 0 otherwise
+ */
+int virEventRequireImpl(void)
+{
+ if (!addHandleImpl || !addTimeoutImpl) {
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("An event loop implementation must be registered"));
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* virEventRegisterDefaultImpl:
*
@@ -276,6 +299,8 @@ int virEventRegisterDefaultImpl(void)
{
VIR_DEBUG("registering default event implementation");
+ virInitialize();
+
virResetLastError();
if (virEventPollInit() < 0) {
diff --git a/src/util/virevent.h b/src/util/virevent.h
index 0b4f7d2b1b..6c8fdcbac4 100644
--- a/src/util/virevent.h
+++ b/src/util/virevent.h
@@ -21,3 +21,5 @@
#pragma once
#include "internal.h"
+
+int virEventRequireImpl(void);
--
2.23.0