NVMeContext: Split out NVMeMCTPContext

The MCTP-oriented implementation of NVMeContext requires linking against
a libmctp build that provides an SMBus binding implementation. The SMBus
binding implementation isn't upstream, and neither are the kernel
interfaces it relies on.

Later, an NVMe MI Basic implementation will be introduced. NVMe MI Basic
only requires support for SMBus block reads rather than MCTP, though is
not as fully featured as the MCTP interface and is not required to be
supported by implementers of the NVMe specification.

For now, reduce NVMeContext to a base class that NVMeMCTPContext
extends and only use the NVMeMCTPContext type where explicitly
required. This opens up the opportunity to make MCTP support a
build-time configurable option.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I6920f79ca389481f3be43ee9a0d336bf8f72d55b
diff --git a/src/NVMeContext.cpp b/src/NVMeMCTPContext.cpp
similarity index 95%
rename from src/NVMeContext.cpp
rename to src/NVMeMCTPContext.cpp
index 36be841..40bb8ac 100644
--- a/src/NVMeContext.cpp
+++ b/src/NVMeMCTPContext.cpp
@@ -14,7 +14,7 @@
 // limitations under the License.
 */
 
-#include "NVMeContext.hpp"
+#include "NVMeMCTPContext.hpp"
 
 #include "NVMeDevice.hpp"
 
@@ -164,7 +164,7 @@
     return reading;
 }
 
-void NVMeContext::processResponse(void* msg, size_t len)
+void NVMeMCTPContext::processResponse(void* msg, size_t len)
 {
     struct nvme_mi_msg_response_header header
     {};
@@ -314,7 +314,7 @@
     return mctp_message_tx(&mctp, 0, messageBuf.data(), msgSize);
 }
 
-void NVMeContext::readResponse()
+void NVMeMCTPContext::readResponse()
 {
     nvmeSlaveSocket.async_wait(
         boost::asio::ip::tcp::socket::wait_error,
@@ -331,7 +331,7 @@
         });
 }
 
-void NVMeContext::readAndProcessNVMeSensor()
+void NVMeMCTPContext::readAndProcessNVMeSensor()
 {
     struct nvme_mi_msg_request requestMsg = {};
     requestMsg.header.opcode = NVME_MI_OPCODE_HEALTH_STATUS_POLL;
@@ -386,14 +386,15 @@
     }
 }
 
-NVMeContext::NVMeContext(boost::asio::io_service& io, int rootBus) :
-    scanTimer(io), rootBus(rootBus), mctpResponseTimer(io), nvmeSlaveSocket(io)
+NVMeMCTPContext::NVMeMCTPContext(boost::asio::io_service& io, int rootBus) :
+    NVMeContext::NVMeContext(io, rootBus), nvmeSlaveSocket(io),
+    mctpResponseTimer(io)
 {
     nvmeSlaveSocket.assign(boost::asio::ip::tcp::v4(),
                            nvmeMCTP::getInFd(rootBus));
 }
 
-void NVMeContext::pollNVMeDevices()
+void NVMeMCTPContext::pollNVMeDevices()
 {
     scanTimer.expires_from_now(boost::posix_time::seconds(1));
     scanTimer.async_wait(
@@ -416,20 +417,16 @@
         });
 }
 
-void NVMeContext::close()
+void NVMeMCTPContext::close()
 {
-    scanTimer.cancel();
+    this->NVMeContext::close();
+
     mctpResponseTimer.cancel();
     nvmeSlaveSocket.cancel();
     nvmeMCTP::closeInFd(rootBus);
 }
 
-void NVMeContext::addSensor(std::shared_ptr<NVMeSensor> sensor)
-{
-    sensors.emplace_back(sensor);
-}
-
-NVMeContext::~NVMeContext()
+NVMeMCTPContext::~NVMeMCTPContext()
 {
     close();
 }
diff --git a/src/NVMeSensorMain.cpp b/src/NVMeSensorMain.cpp
index d744ece..6c10eb5 100644
--- a/src/NVMeSensorMain.cpp
+++ b/src/NVMeSensorMain.cpp
@@ -15,6 +15,7 @@
 */
 
 #include <NVMeContext.hpp>
+#include <NVMeMCTPContext.hpp>
 #include <NVMeSensor.hpp>
 #include <boost/asio/deadline_timer.hpp>
 
@@ -127,7 +128,7 @@
                 }
                 else
                 {
-                    context = std::make_shared<NVMeContext>(io, rootBus);
+                    context = std::make_shared<NVMeMCTPContext>(io, rootBus);
                     nvmeDeviceMap[rootBus] = context;
                 }
 
diff --git a/src/meson.build b/src/meson.build
index cd861cb..c1f77ca 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -158,7 +158,7 @@
         'nvmesensor',
         'NVMeSensorMain.cpp',
         'NVMeSensor.cpp',
-        'NVMeContext.cpp',
+        'NVMeMCTPContext.cpp',
         dependencies: [
             i2c,
             sdbusplus,