diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-06-29 18:35:00 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-07-29 23:57:59 +0530 |
commit | ee4d83dfc7b6cf3b5979541ab5b1918b68e6bbdb (patch) | |
tree | 4d186ddf133d77880e857fccdddb71fcc155a6bf /occ_errors.hpp | |
parent | 554d60059e7d0b699b3cdcbe8de2c341613e9931 (diff) | |
download | openpower-occ-control-ee4d83dfc7b6cf3b5979541ab5b1918b68e6bbdb.tar.gz openpower-occ-control-ee4d83dfc7b6cf3b5979541ab5b1918b68e6bbdb.zip |
Add support to watch for OCC errors
Change-Id: I98d95020a2d01e281e5c8efa825d6b4bd4c6c160
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_errors.hpp')
-rw-r--r-- | occ_errors.hpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/occ_errors.hpp b/occ_errors.hpp new file mode 100644 index 0000000..1e66ffc --- /dev/null +++ b/occ_errors.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include <unistd.h> +#include <functional> +#include <experimental/filesystem> +#include "occ_events.hpp" +#include "config.h" +namespace open_power +{ +namespace occ +{ + +namespace fs = std::experimental::filesystem; + +/** @class Error + * @brief Monitors for OCC device error condition + */ +class Error +{ + public: + Error() = delete; + Error(const Error&) = delete; + Error& operator=(const Error&) = delete; + Error(Error&&) = default; + Error& operator=(Error&&) = default; + + /** @brief Constructs the Error object + * + * @param[in] event - reference to sd_event unique_ptr + * @param[in] file - File used by driver to communicate errors + * @param[in] callBack - Optional function callback on error condition + */ + Error(EventPtr& event, + const fs::path& file, + std::function<void()> callBack = nullptr) : + event(event), + file(fs::path(DEV_PATH) / file), + callBack(callBack) + { + // Nothing to do here. + } + + ~Error() + { + if (fd>= 0) + { + close(fd); + } + } + + /** @brief Starts to monitor for error conditions */ + void addWatch(); + + /** @brief Removes error watch */ + void removeWatch(); + + private: + /** @brief sd_event wrapped in unique_ptr */ + EventPtr& event; + + /** @brief event source wrapped in unique_ptr */ + EventSourcePtr eventSource; + + /** Error file */ + const fs::path file; + + /** @brief Optional function to call on error scenario */ + std::function<void()> callBack; + + /** @brief File descriptor to watch for errors */ + int fd = -1; + + /** @brief attaches FD to events and sets up callback handler */ + void registerCallBack(); + + /** @brief Opens the file and populates fd */ + void openFile(); + + /** @brief Reads file data + * + * @return data read. Since its a /sysfs entry, + * it would be a string + */ + std::string readFile(int) const; + + /** @brief Callback handler when the FD has some activity on it + * + * @param[in] es - Populated event source + * @param[in] fd - Associated File descriptor + * @param[in] revents - Type of event + * @param[in] userData - User data that was passed during registration + * + * @return - 0 or positive number on success and negative + * errno otherwise + */ + static int processEvents(sd_event_source* es, int fd, + uint32_t revents, void* userData); + + /** @brief When the error event is received, analyzes it + * and makes a callback to error handler if the + * content denotes an error condition + */ + void analyzeEvent(); +}; + +} // namespace occ +} // namespace open_power |