Add TaskService

This adds tasks service to Redfish and creates an
example for crashdump. The TaskData object creates
tasks that can be updated based on d-bus matches. It
also has a configurable timeout using timers. Task
Monitor uses these task objects to reply with a 202
until the async task is done, then a 204 when it is
either failed or completed.

Messages support will come in future commit.

Tested: Validator passed, wrote script to poll monitor,
verified that got 202 with location header and retry-after
set correctly, then 204, then 404.

Change-Id: I109e671baa1c1eeff1a11ae578e7361bf6ef9f14
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index aede366..2f065ec 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -19,6 +19,7 @@
 #include "registries.hpp"
 #include "registries/base_message_registry.hpp"
 #include "registries/openbmc_message_registry.hpp"
+#include "task.hpp"
 
 #include <systemd/sd-journal.h>
 
@@ -1849,30 +1850,37 @@
     {
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
 
-        auto generateonDemandLogCallback =
-            [asyncResp](const boost::system::error_code ec,
-                        const std::string &resp) {
-                if (ec)
+        auto generateonDemandLogCallback = [asyncResp](
+                                               const boost::system::error_code
+                                                   ec,
+                                               const std::string &resp) {
+            if (ec)
+            {
+                if (ec.value() == boost::system::errc::operation_not_supported)
                 {
-                    if (ec.value() ==
-                        boost::system::errc::operation_not_supported)
-                    {
-                        messages::resourceInStandby(asyncResp->res);
-                    }
-                    else if (ec.value() ==
-                             boost::system::errc::device_or_resource_busy)
-                    {
-                        messages::serviceTemporarilyUnavailable(asyncResp->res,
-                                                                "60");
-                    }
-                    else
-                    {
-                        messages::internalError(asyncResp->res);
-                    }
-                    return;
+                    messages::resourceInStandby(asyncResp->res);
                 }
-                asyncResp->res.result(boost::beast::http::status::no_content);
-            };
+                else if (ec.value() ==
+                         boost::system::errc::device_or_resource_busy)
+                {
+                    messages::serviceTemporarilyUnavailable(asyncResp->res,
+                                                            "60");
+                }
+                else
+                {
+                    messages::internalError(asyncResp->res);
+                }
+                return;
+            }
+            std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
+                [](boost::system::error_code, sdbusplus::message::message &,
+                   const std::shared_ptr<task::TaskData> &) { return true; },
+                "type='signal',interface='org.freedesktop.DBus.Properties',"
+                "member='PropertiesChanged',arg0namespace='com.intel."
+                "crashdump'");
+            task->startTimer(std::chrono::minutes(5));
+            task->populateResp(asyncResp->res);
+        };
         crow::connections::systemBus->async_method_call(
             std::move(generateonDemandLogCallback), crashdumpObject,
             crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");