watch: Remove unused code

This is dead code as nothing is instantiating Watch objects

Change-Id: I34c9675a245e87e12577a0b1df22a1476fe6207b
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/meson.build b/src/meson.build
index 08decbd..8f301ca 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -76,7 +76,6 @@
   'vlan_interface.cpp',
   'rtnetlink_server.cpp',
   'dns_updater.cpp',
-  'watch.cpp',
   implicit_include_directories: false,
   include_directories: src_includes,
   dependencies: networkd_deps)
diff --git a/src/network_manager_main.cpp b/src/network_manager_main.cpp
index b72e32d..2c0918a 100644
--- a/src/network_manager_main.cpp
+++ b/src/network_manager_main.cpp
@@ -3,7 +3,6 @@
 #include "network_manager.hpp"
 #include "rtnetlink_server.hpp"
 #include "types.hpp"
-#include "watch.hpp"
 
 #include <linux/netlink.h>
 
diff --git a/src/watch.cpp b/src/watch.cpp
deleted file mode 100644
index 0efe300..0000000
--- a/src/watch.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-#include "watch.hpp"
-
-#include <errno.h>
-#include <sys/inotify.h>
-
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
-
-namespace phosphor
-{
-namespace network
-{
-namespace inotify
-{
-
-using namespace phosphor::logging;
-using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-
-Watch::Watch(phosphor::network::EventPtr& eventPtr, fs::path path,
-             UserCallBack userFunc, int flags, uint32_t mask, uint32_t events) :
-    path(path),
-    userFunc(userFunc), flags(flags), mask(mask), events(events),
-    fd(inotifyInit())
-{
-    // Check if watch file exists
-    // This is supposed to be there always
-    if (!fs::is_regular_file(path))
-    {
-        log<level::ERR>("Watch file doesn't exist",
-                        entry("FILE=%s", path.c_str()));
-        elog<InternalFailure>();
-    }
-
-    auto dirPath = path.parent_path();
-    wd = inotify_add_watch(fd(), dirPath.c_str(), mask);
-    if (wd == -1)
-    {
-        log<level::ERR>("Error from inotify_add_watch",
-                        entry("ERRNO=%d", errno));
-        elog<InternalFailure>();
-    }
-
-    // Register the fd with sd_event infrastructure and setup a
-    // callback handler to be invoked on events
-    auto rc = sd_event_add_io(eventPtr.get(), nullptr, fd(), events,
-                              Watch::processEvents, this);
-    if (rc < 0)
-    {
-        // Failed to add to event loop
-        log<level::ERR>("Error registering with sd_event_add_io",
-                        entry("RC=%d", rc));
-        elog<InternalFailure>();
-    }
-}
-
-int Watch::inotifyInit()
-{
-    auto fd = inotify_init1(flags);
-    if (fd < 0)
-    {
-        log<level::ERR>("Error from inotify_init1", entry("ERRNO=%d", errno));
-        elog<InternalFailure>();
-    }
-    return fd;
-}
-
-int Watch::processEvents(sd_event_source* /*eventSource*/, int fd,
-                         uint32_t retEvents, void* userData)
-{
-    auto watch = static_cast<Watch*>(userData);
-
-    // Not the ones we are interested in
-    if (!(retEvents & watch->events))
-    {
-        return 0;
-    }
-
-    // Buffer size to be used while reading events.
-    // per inotify(7), below number should be fine for reading
-    // at-least one event
-    constexpr auto maxBytes = sizeof(struct inotify_event) + NAME_MAX + 1;
-    uint8_t eventData[maxBytes]{};
-
-    auto bytes = read(fd, eventData, maxBytes);
-    if (bytes <= 0)
-    {
-        // Failed to read inotify event data
-        // Report error and return
-        log<level::ERR>("Error reading inotify event",
-                        entry("ERRNO=%d", errno));
-        report<InternalFailure>();
-        return 0;
-    }
-
-    auto offset = 0;
-    auto stateFile = watch->path.filename();
-    while (offset < bytes)
-    {
-        auto event = reinterpret_cast<inotify_event*>(&eventData[offset]);
-
-        // Filter the interesting ones
-        auto mask = event->mask & watch->mask;
-        if (mask)
-        {
-            if ((event->len > 0) &&
-                (strstr(event->name, stateFile.string().c_str())))
-            {
-                if (watch->userFunc)
-                {
-                    watch->userFunc(watch->path);
-                }
-                // Found the event of interest
-                break;
-            }
-        }
-        // Move past this entry
-        offset += offsetof(inotify_event, name) + event->len;
-    }
-    return 0;
-}
-
-} // namespace inotify
-} // namespace network
-} // namespace phosphor
diff --git a/src/watch.hpp b/src/watch.hpp
deleted file mode 100644
index b45f53f..0000000
--- a/src/watch.hpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#pragma once
-
-#include "dns_updater.hpp"
-#include "types.hpp"
-#include "util.hpp"
-
-#include <sys/inotify.h>
-#include <systemd/sd-event.h>
-
-#include <filesystem>
-#include <functional>
-#include <map>
-
-namespace phosphor
-{
-namespace network
-{
-namespace inotify
-{
-
-namespace fs = std::filesystem;
-
-// Auxiliary callback to be invoked on inotify events
-using UserCallBack = std::function<void(const std::string&)>;
-
-/** @class Watch
- *
- *  @brief Adds inotify watch on directory
- *
- *  @details Calls back user function on matching events
- */
-class Watch
-{
-  public:
-    Watch() = delete;
-    Watch(const Watch&) = delete;
-    Watch& operator=(const Watch&) = delete;
-    Watch(Watch&&) = delete;
-    Watch& operator=(Watch&&) = delete;
-
-    /** @brief Hooks inotify watch with sd-event
-     *
-     *  @param[in] eventPtr - Reference to sd_event wrapped in unique_ptr
-     *  @param[in] path     - File path to be watched
-     *  @param[in] userFunc - User specific callback function on events
-     *  @param[in] flags    - Flags to be supplied to inotify
-     *  @param[in] mask     - Mask of events to be supplied to inotify
-     *  @param[in] events   - Events to be watched
-     */
-    Watch(phosphor::network::EventPtr& eventPtr, const fs::path path,
-          UserCallBack userFunc, int flags = IN_NONBLOCK,
-          uint32_t mask = IN_CLOSE_WRITE, uint32_t events = EPOLLIN);
-
-    /** @brief Remove inotify watch and close fd's */
-    ~Watch()
-    {
-        if ((fd() >= 0) && (wd >= 0))
-        {
-            inotify_rm_watch(fd(), wd);
-        }
-    }
-
-  private:
-    /** @brief Callback invoked when inotify event fires
-     *
-     *  @details On a matching event, calls back into user supplied
-     *           function if there is one registered
-     *
-     *  @param[in] eventSource - Event source
-     *  @param[in] fd          - Inotify fd
-     *  @param[in] retEvents   - Events that matched for fd
-     *  @param[in] userData    - Pointer to Watch object
-     *
-     *  @returns 0 on success, -1 on fail
-     */
-    static int processEvents(sd_event_source* eventSource, int fd,
-                             uint32_t retEvents, void* userData);
-
-    /** @brief Initializes an inotify instance
-     *
-     *  @return Descriptor on success, -1 on failure
-     */
-    int inotifyInit();
-
-    /** @brief File path to be watched */
-    const fs::path path;
-
-    /** @brief User callback function */
-    UserCallBack userFunc;
-
-    /** @brief Inotify flags */
-    int flags;
-
-    /** @brief Mask of events */
-    uint32_t mask;
-
-    /** @brief Events to be watched */
-    uint32_t events;
-
-    /** @brief Watch descriptor */
-    int wd = -1;
-
-    /** @brief File descriptor manager */
-    phosphor::Descriptor fd;
-};
-
-} // namespace inotify
-} // namespace network
-} // namespace phosphor