Implement API to send SOL payload when console data is available

Change-Id: I7869d389b589c59e0c76000da9bfd72b9e67c064
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index 0272e6c..350a96c 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -103,13 +103,22 @@
     // The instance is hardcoded to 1, in the case of supporting multiple
     // payload instances we would need to populate it from userdata
     uint8_t instance = 1;
+    int rc = 0;
     auto bufferSize = std::get<sol::Manager&>(singletonPool).dataBuffer.size();
 
     try
     {
         if(bufferSize > 0)
         {
-            // Send the SOL payload
+            auto& context = std::get<sol::Manager&>(singletonPool).getContext
+                    (instance);
+
+            rc = context.sendOutboundPayload();
+
+            if (rc == 0)
+            {
+                return 0;
+            }
         }
 
         std::get<eventloop::EventLoop&>(singletonPool).switchTimer(
diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp
index ee0eb39..24339f0 100644
--- a/sol/sol_context.cpp
+++ b/sol/sol_context.cpp
@@ -150,6 +150,39 @@
     sendPayload(payloadCache);
 }
 
+int Context::sendOutboundPayload()
+{
+    if (payloadCache.size() != 0)
+    {
+        std::get<eventloop::EventLoop&>(singletonPool).switchTimer(
+                payloadInstance, eventloop::Timers::ACCUMULATE, true);
+        return -1;
+    }
+
+    auto bufferSize = std::get<sol::Manager&>(singletonPool).dataBuffer.size();
+    auto readSize = std::min(bufferSize, MAX_PAYLOAD_SIZE);
+
+    payloadCache.resize(sizeof(Payload) + readSize);
+    auto response = reinterpret_cast<Payload*>(payloadCache.data());
+    response->packetAckSeqNum = 0;
+    response->acceptedCharCount = 0;
+    response->outOperation.ack = false;
+    response->packetSeqNum = seqNums.incOutboundSeqNum();
+
+    auto handle = std::get<sol::Manager&>(singletonPool).dataBuffer.read();
+    std::copy_n(handle, readSize, payloadCache.data() + sizeof(Payload));
+    expectedCharCount = readSize;
+
+    std::get<eventloop::EventLoop&>(singletonPool).switchTimer(
+            payloadInstance, eventloop::Timers::RETRY, true);
+    std::get<eventloop::EventLoop&>(singletonPool).switchTimer(
+            payloadInstance, eventloop::Timers::ACCUMULATE, false);
+
+    sendPayload(payloadCache);
+
+    return 0;
+}
+
 void Context::resendPayload(bool clear)
 {