
On 03/25/2017 08:51 AM, John Ferlan wrote:
Rather than 'n' repetitive code segments, let's create a single macro which will make the code easier to read.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- daemon/remote.c | 120 +++++++++++++++----------------------------------------- 1 file changed, 31 insertions(+), 89 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c index 1c9708c..6fdafce 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1623,6 +1623,24 @@ void remoteRelayConnectionClosedEvent(virConnectPtr conn ATTRIBUTE_UNUSED, int r &msg); }
+#define CLEAN_EVENT_CALLBACK(conn, eventCallbacks, neventCallbacks, name) \ + do { \ + size_t i; \ + for (i = 0; i < neventCallbacks; i++) { \ + int callbackID = eventCallbacks[i]->callbackID; \ + if (callbackID < 0) { \ + VIR_WARN("unexpected incomplete %s callback %zu", name, i); \ + continue; \ + } \ + VIR_DEBUG("Deregistering remote %s event relay %d", \ + name, callbackID); \ + eventCallbacks[i]->callbackID = -1; \ + if (virConnectDomainEventDeregisterAny(conn, callbackID) < 0) \
This call is different for each loop, and you've made them all identical. You need to make the deregister function an argument to the macro. Otherwise it seems like a nice de-duplication of code. ACK if you fix that.