From 1bcae439abba8f22719c91012526a392f0252392 Mon Sep 17 00:00:00 2001
From: Aaron <arosen@nicira.com>
Date: Mon, 12 Aug 2013 12:05:08 -0700
Subject: [PATCH] Add run_with_changes() method to Idl

This patch adds the method run_with_changes() to Idl which allows
one to determine the changes that occurred to the database without
having to read the entire table.

Signed-off-by: Aaron Rosen <arosen@nicira.com>
---
 python/ovs/db/idl.py |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 55fbcba..90aba69 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -150,9 +150,19 @@ class Idl:
 
         As an alternative to checking the return value, the client may check
         for changes in self.change_seqno."""
+        return self.__process_messages()
+
+    def run_with_changes(self):
+        """This method performs the same operation as run() but also returns
+        a list of the jsonrpc messages processed in order to determine which
+        changes have occurred since last run."""
+        return self.__process_messages(return_changes=True)
+
+    def __process_messages(self, return_changes=False):
         assert not self.txn
         initial_change_seqno = self.change_seqno
         self._session.run()
+        changes = []
         i = 0
         while i < 50:
             i += 1
@@ -176,6 +186,8 @@ class Idl:
                 and len(msg.params) == 2
                 and msg.params[0] == None):
                 # Database contents changed.
+                if return_changes:
+                    changes.append(msg)
                 self.__parse_update(msg.params[1])
             elif (msg.type == ovs.jsonrpc.Message.T_REPLY
                   and self._monitor_request_id is not None
@@ -218,6 +230,8 @@ class Idl:
                          % (self._session.get_name(),
                              ovs.jsonrpc.Message.type_to_string(msg.type)))
 
+        if return_changes:
+            return (initial_change_seqno != self.change_seqno, changes)
         return initial_change_seqno != self.change_seqno
 
     def wait(self, poller):
-- 
1.7.9.5

