FruDevice: Refactor i2c device monitor

In kernel inotify, it is ensured that only complete events are returned
when reading inotify fd (In inotify_user.c:get_one_event()). So the
pendingBuffer in FruDevice is not needed. This patch handles the read
buffer in-place.

Tested:
Verified i2c bus changes are handled properly when loading/unloading
i2c mux driver.

Change-Id: I08777e0a0bc2c951ee03f716b0ec0171ea2aede5
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 59d94d4..620da6e 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -1423,7 +1423,6 @@
     int fd = inotify_init();
     inotify_add_watch(fd, i2CDevLocation, IN_CREATE | IN_MOVED_TO | IN_DELETE);
     std::array<char, 4096> readBuffer;
-    std::string pendingBuffer;
     // monitor for new i2c devices
     boost::asio::posix::stream_descriptor dirWatch(io, fd);
     std::function<void(const boost::system::error_code, std::size_t)>
@@ -1434,12 +1433,11 @@
                 std::cout << "Callback Error " << ec << "\n";
                 return;
             }
-            pendingBuffer += std::string(readBuffer.data(), bytesTransferred);
-            while (pendingBuffer.size() > sizeof(inotify_event))
+            size_t index = 0;
+            while ((index + sizeof(inotify_event)) <= bytesTransferred)
             {
                 const inotify_event* iEvent =
-                    reinterpret_cast<const inotify_event*>(
-                        pendingBuffer.data());
+                    reinterpret_cast<const inotify_event*>(&readBuffer[index]);
                 switch (iEvent->mask)
                 {
                     case IN_CREATE:
@@ -1461,8 +1459,7 @@
                                          objServer, systemBus);
                         }
                 }
-
-                pendingBuffer.erase(0, sizeof(inotify_event) + iEvent->len);
+                index += sizeof(inotify_event) + iEvent->len;
             }
 
             dirWatch.async_read_some(boost::asio::buffer(readBuffer),