/**
 * @file propertywatch.hpp
 * @brief PropertyWatch class declarations.
 *
 * In general class users should include propertywatchimpl.hpp instead to avoid
 * link failures.
 */
#pragma once

#include "data_types.hpp"
#include "filters.hpp"
#include "watch.hpp"

#include <string>

namespace phosphor
{
namespace dbus
{
namespace monitoring
{

class Callback;

/** @class PropertyWatch
 *  @brief Type agnostic, factored out logic for property watches.
 *
 *  A property watch maintains the state of one or more DBus properties
 *  as specified by the supplied index.
 */
template <typename DBusInterfaceType>
class PropertyWatch : public Watch
{
  public:
    PropertyWatch() = delete;
    PropertyWatch(const PropertyWatch&) = delete;
    PropertyWatch(PropertyWatch&&) = default;
    PropertyWatch& operator=(const PropertyWatch&) = delete;
    PropertyWatch& operator=(PropertyWatch&&) = default;
    virtual ~PropertyWatch() = default;
    PropertyWatch(const PropertyIndex& watchIndex,
                  bool ignoreStartCallback = false,
                  Callback* callback = nullptr) :
        Watch(), index(watchIndex), cb(callback), alreadyRan(false),
        ignoreStartCallback(ignoreStartCallback)
    {}

    /** @brief Start the watch.
     *
     *  Watch start interface implementation for PropertyWatch.
     */
    void start() override;

    /** @brief Run the watch callback method.
     *
     *  Watch callback interface implementation for PropertyWatch.
     */
    void callback(Context ctx) override;

    /** @brief Update properties.
     *
     *  Subclasses to query the properties specified by the index
     *  and update the cache.
     *
     *  @param[in] busName - The busname hosting the interface to query.
     *  @param[in] path - The path of the interface to query.
     *  @param[in] interface - The interface to query.
     */
    virtual void updateProperties(const std::string& busName,
                                  const std::string& path,
                                  const std::string& interface) = 0;

    /** @brief Dbus signal callback for PropertiesChanged.
     *
     *  Subclasses to update the cache.
     *
     *  @param[in] message - The org.freedesktop.DBus.PropertiesChanged
     *               message.
     *  @param[in] path - The path associated with the message.
     *  @param[in] interface - The interface associated with the message.
     */
    virtual void propertiesChanged(sdbusplus::message_t&,
                                   const std::string& path,
                                   const std::string& interface) = 0;

    /** @brief Dbus signal callback for InterfacesAdded.
     *
     *  Subclasses to update the cache.
     *
     *  @param[in] msg - The org.freedesktop.DBus.PropertiesChanged
     *               message.
     */
    virtual void interfacesAdded(sdbusplus::message_t& msg) = 0;

  protected:
    /** @brief Property names and their associated storage. */
    const PropertyIndex& index;

    /** @brief Optional callback method. */
    Callback* const cb;

    /** @brief The start method should only be invoked once. */
    bool alreadyRan;

    /** @brief Ignore callback on start */
    bool ignoreStartCallback;
};

/** @class PropertyWatchOfType
 *  @brief Type specific logic for PropertyWatch.
 *
 *  @tparam DBusInterfaceType - DBus access delegate.
 *  @tparam T - The type of the properties being watched.
 */
template <typename T, typename DBusInterfaceType>
class PropertyWatchOfType : public PropertyWatch<DBusInterfaceType>
{
  public:
    PropertyWatchOfType() = default;
    PropertyWatchOfType(const PropertyWatchOfType&) = delete;
    PropertyWatchOfType(PropertyWatchOfType&&) = default;
    PropertyWatchOfType& operator=(const PropertyWatchOfType&) = delete;
    PropertyWatchOfType& operator=(PropertyWatchOfType&&) = default;
    ~PropertyWatchOfType() = default;
    PropertyWatchOfType(const PropertyIndex& watchIndex, Callback& callback,
                        bool ignoreStartCallback = false,
                        Filters* filterOps = nullptr) :
        PropertyWatch<DBusInterfaceType>(watchIndex, ignoreStartCallback,
                                         &callback),
        filterOps(filterOps)
    {}
    explicit PropertyWatchOfType(const PropertyIndex& watchIndex,
                                 bool ignoreStartCallback = false,
                                 Filters* filterOps = nullptr) :
        PropertyWatch<DBusInterfaceType>(watchIndex, ignoreStartCallback,
                                         nullptr),
        filterOps(filterOps)
    {}

    /** @brief PropertyMatch implementation for PropertyWatchOfType.
     *
     *  @param[in] busName - The busname hosting the interface to query.
     *  @param[in] path - The path of the interface to query.
     *  @param[in] interface - The interface to query.
     */
    void updateProperties(const std::string& busName, const std::string& path,
                          const std::string& interface) override;

    /** @brief PropertyMatch implementation for PropertyWatchOfType.
     *
     *  @param[in] msg - The org.freedesktop.DBus.PropertiesChanged
     *               message.
     *  @param[in] path - The path associated with the message.
     *  @param[in] interface - The interface associated with the message.
     */
    void propertiesChanged(sdbusplus::message_t& msg, const std::string& path,
                           const std::string& interface) override;

    /** @brief DBus agnostic implementation of interfacesAdded.
     *
     *  @param[in] path - The path of the properties that changed.
     *  @param[in] interface - The interface of the properties that
     *                  changed.
     *  @param[in] properties - The properties that changed.
     */
    void propertiesChanged(const std::string& path,
                           const std::string& interface,
                           const PropertiesChanged<T>& properties);

    /** @brief PropertyMatch implementation for PropertyWatchOfType.
     *
     *  @param[in] msg - The org.freedesktop.DBus.PropertiesChanged
     *               message.
     */
    void interfacesAdded(sdbusplus::message_t& msg) override;

    /** @brief DBus agnostic implementation of interfacesAdded.
     *
     *  @param[in] path - The path of the added interfaces.
     *  @param[in] interfaces - The added interfaces.
     */
    void interfacesAdded(const std::string& path,
                         const InterfacesAdded<T>& interfaces);

  private:
    /** @brief Optional filter operations to perform on property changes. */
    Filters* const filterOps;
};

} // namespace monitoring
} // namespace dbus
} // namespace phosphor
