sync_manager: Create sync watch class
Create a watch class to monitor the files and directories
specified in the synclist file.
Store the file descriptors and file names in a map to be
able to know the full path of the file that triggered the
event. The watch descriptor number does not change so it
can be a single variable.
Change-Id: I211225ddc012af85d9be39ae5d40b8258d73435d
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/sync_manager_main.cpp b/sync_manager_main.cpp
index 09aea5c..46a2d95 100644
--- a/sync_manager_main.cpp
+++ b/sync_manager_main.cpp
@@ -1,15 +1,41 @@
+#include <exception>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/manager.hpp>
+#include <systemd/sd-event.h>
#include "config.h"
#include "sync_manager.hpp"
+#include "sync_watch.hpp"
int main(int argc, char* argv[])
{
auto bus = sdbusplus::bus::new_default();
+ sd_event* loop = nullptr;
+ sd_event_default(&loop);
+
sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
- phosphor::software::manager::Sync syncManager();
- bus.request_name(SYNC_BUSNAME);
+
+ try
+ {
+ phosphor::software::manager::Sync syncManager;
+ bus.request_name(SYNC_BUSNAME);
+
+ using namespace phosphor::software::manager;
+ phosphor::software::manager::SyncWatch watch(
+ *loop, std::bind(std::mem_fn(&Sync::processEntry), &syncManager));
+ bus.attach_event(loop, SD_EVENT_PRIORITY_NORMAL);
+ sd_event_loop(loop);
+ }
+ catch (std::exception& e)
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>(e.what());
+ sd_event_unref(loop);
+ return -1;
+ }
+
+ sd_event_unref(loop);
return 0;
}