netipmid: use shared_ptr on session instead of shared_ptr+references

session objects were being created and held by shared_ptr objects and
then shared via reference. This is dangerous and sidesteps the whole
point of a shared_ptr, which is to share reference-counted ownership.
This replaces the usage with a shared_ptr, which shows shared ownership.

Change-Id: Ie22d812a6d260d606201eca6a9011e773c89e487
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/message_handler.cpp b/message_handler.cpp
index b9cc6ab..68c1b60 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -168,7 +168,7 @@
         std::get<session::Manager&>(singletonPool).getSession(sessionID);
 
     // Flatten the packet
-    auto packet = parser::flatten(outMessage, sessionHeader, *session);
+    auto packet = parser::flatten(outMessage, sessionHeader, session);
 
     // Write the packet
     auto writeStatus = channel->write(packet);
diff --git a/message_parsers.cpp b/message_parsers.cpp
index ddb9d01..d7074fa 100644
--- a/message_parsers.cpp
+++ b/message_parsers.cpp
@@ -55,7 +55,8 @@
 }
 
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             SessionHeader authType, session::Session& session)
+                             SessionHeader authType,
+                             std::shared_ptr<session::Session> session)
 {
     // Call the flatten routine based on the header type
     switch (authType)
@@ -108,7 +109,7 @@
 }
 
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             session::Session& session)
+                             std::shared_ptr<session::Session> session)
 {
     std::vector<uint8_t> packet(sizeof(SessionHeader_t));
 
@@ -191,7 +192,7 @@
 }
 
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             session::Session& session)
+                             std::shared_ptr<session::Session> session)
 {
     std::vector<uint8_t> packet(sizeof(SessionHeader_t));
 
@@ -243,7 +244,8 @@
 namespace internal
 {
 
-void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session)
+void addSequenceNumber(std::vector<uint8_t>& packet,
+                       std::shared_ptr<session::Session> session)
 {
     SessionHeader_t* header = reinterpret_cast<SessionHeader_t*>(packet.data());
 
@@ -253,7 +255,7 @@
     }
     else
     {
-        auto seqNum = session.sequenceNums.increment();
+        auto seqNum = session->sequenceNums.increment();
         header->sessSeqNum = endian::to_ipmi(seqNum);
     }
 }
diff --git a/message_parsers.hpp b/message_parsers.hpp
index b38da40..489eb23 100644
--- a/message_parsers.hpp
+++ b/message_parsers.hpp
@@ -73,7 +73,8 @@
  * @return IPMI packet on success
  */
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             SessionHeader authType, session::Session& session);
+                             SessionHeader authType,
+                             std::shared_ptr<session::Session> session);
 
 } // namespace parser
 
@@ -112,7 +113,7 @@
  * @return IPMI packet on success
  */
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             session::Session& session);
+                             std::shared_ptr<session::Session> session);
 
 } // namespace ipmi15parser
 
@@ -159,7 +160,7 @@
  * @return IPMI packet on success
  */
 std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
-                             session::Session& session);
+                             std::shared_ptr<session::Session> session);
 
 namespace internal
 {
@@ -171,7 +172,8 @@
  * @param[in] session - session handle
  *
  */
-void addSequenceNumber(std::vector<uint8_t>& packet, session::Session& session);
+void addSequenceNumber(std::vector<uint8_t>& packet,
+                       std::shared_ptr<session::Session> session);
 
 /**
  * @brief Verify the integrity data of the incoming IPMI packet