i2c: Support explicit open/close and re-open

Add the ability to explicitly open and close the I2CInterface/I2CDevice.
Also add support to re-open the I2CInterface/I2CDevice after it was
closed.

This support is needed for use cases like the following:

* I2C device information (bus and address) is parsed from a
  configuration file at standby.  However, an I2C connection to the
  device should not be opened yet.   The device may not have power until
  the system has been booted.  Additionally, if the device is a FRU,
  it could be replaced (remove + add) while at standby, leading to
  communication errors.

* The device is sometimes bound to a device driver.  The I2C connection
  should only be open during the time periods when the device driver
  is not bound.

Tested:
* Verified create() function with default value of OPEN, explicit value
  of OPEN, and explicit value of CLOSED.
* Verified device interface can be explicitly opened, closed, and
  re-opened.
* Verified read() and write() functions still work when device interface
  is open.
* Verified open() fails with appropriate error if already open.
* Verified read() fails with appropriate error if not open.
* Verified write() fails with appropriate error if not open.
* Verified close() fails with appropriate error if not open.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I0182966f0b0614eac0de69eb95d960035f9d0426
diff --git a/tools/i2c/test/mocked_i2c_interface.hpp b/tools/i2c/test/mocked_i2c_interface.hpp
index 5bb0a3a..5f3b3a3 100644
--- a/tools/i2c/test/mocked_i2c_interface.hpp
+++ b/tools/i2c/test/mocked_i2c_interface.hpp
@@ -12,6 +12,10 @@
   public:
     virtual ~MockedI2CInterface() = default;
 
+    MOCK_METHOD(void, open, (), (override));
+    MOCK_METHOD(bool, isOpen, (), (const, override));
+    MOCK_METHOD(void, close, (), (override));
+
     MOCK_METHOD(void, read, (uint8_t & data), (override));
     MOCK_METHOD(void, read, (uint8_t addr, uint8_t& data), (override));
     MOCK_METHOD(void, read, (uint8_t addr, uint16_t& data), (override));
@@ -27,7 +31,9 @@
                 (override));
 };
 
-std::unique_ptr<I2CInterface> create(uint8_t /*busId*/, uint8_t /*devAddr*/)
+std::unique_ptr<I2CInterface>
+    create(uint8_t /*busId*/, uint8_t /*devAddr*/,
+           I2CInterface::InitialState /*initialState*/)
 {
     return std::make_unique<MockedI2CInterface>();
 }