EventService: Support for Server Sent Events(SSE)

Add support for Server Sent Events(SSE)
Filters support is not part of this commit.

Tested:
 - GET on URI /redfish/v1/EventService/Subscriptions/SSE/
   from chrome browser, can see all BMC Events on browser.
 - Redfish validator is successful.

Change-Id: Icd10cdad20c4529f64c97b67d46f2e4a7e0c329c
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index ba1ea19..adb6238 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -398,6 +398,66 @@
     }
 };
 
+class EventServiceSSE : public Node
+{
+  public:
+    EventServiceSSE(CrowApp& app) :
+        Node(app, "/redfish/v1/EventService/Subscriptions/SSE/")
+    {
+        entityPrivileges = {
+            {boost::beast::http::verb::get, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::head, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::put, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
+            {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
+    }
+
+  private:
+    void doGet(crow::Response& res, const crow::Request& req,
+               const std::vector<std::string>& params) override
+    {
+        if (EventServiceManager::getInstance().getNumberOfSubscriptions() >=
+            maxNoOfSubscriptions)
+        {
+            messages::eventSubscriptionLimitExceeded(res);
+            res.end();
+            return;
+        }
+
+        std::shared_ptr<crow::Request::Adaptor> sseConn =
+            std::make_shared<crow::Request::Adaptor>(std::move(req.socket()));
+        std::shared_ptr<Subscription> subValue =
+            std::make_shared<Subscription>(sseConn);
+
+        // GET on this URI means, Its SSE subscriptionType.
+        subValue->subscriptionType = "SSE";
+        subValue->protocol = "Redfish";
+
+        char* filters = req.urlParams.get("$filter");
+        if (filters == nullptr)
+        {
+            subValue->eventFormatType = "Event";
+            subValue->retryPolicy = "TerminateAfterRetries";
+        }
+        else
+        {
+            // TODO: Need to read this from query params.
+            subValue->eventFormatType = "Event";
+            subValue->retryPolicy = "TerminateAfterRetries";
+        }
+
+        std::string id =
+            EventServiceManager::getInstance().addSubscription(subValue, false);
+        if (id.empty())
+        {
+            messages::internalError(res);
+            res.end();
+            return;
+        }
+    }
+};
+
 class EventDestination : public Node
 {
   public: