/******************************************************************************* NAME biosLib.h VERSION %version: 3 % UPDATE DATE %date_modified: Mon Dec 14 08:22:31 2015 % PROGRAMMER %created_by: dhoyer % Copyright 2015-2017 NetApp, Inc. All Rights Reserved. DESCRIPTION: Simple class used during throw/catch conditions for error handling *******************************************************************************/ #ifndef __INCbiosLib #define __INCbiosLib /*** INCLUDES ***/ #include #include #include #include #include #include //#include namespace bios { /** * \brief Simple class used in the throw operation to report error conditions * * This class is used to throw error conditions in the BIOS functions */ class BiosFail: public std::exception { public: /** * \brief Constructor for BiosFail class * * \param[in] msg is string containing error message */ BiosFail(const char* msg) { message = strdup(msg); }; /** * \brief Destructor for BiosFail class * */ virtual ~BiosFail() throw() { free(message); }; /** * \brief Function to provide user reference to error message * * \return reference string to the error message */ virtual const char* what() const throw() { return message; }; private: // Stored error message char* message; }; /** * \brief This function logs error message and throws error condition * * \param[in] msg is a format string for the message * \param[in] VA_LIST variable list of optional parameters * * \throws bios::BiosFail with message */ inline void logErr(const char* msg, ...) { static const size_t MAX_LEN = 512; char buffer[MAX_LEN]; va_list args; va_start(args, msg); (void)vsnprintf(buffer, MAX_LEN, msg, args); va_end(args); //eseriesLog("eseries-bios-utils", ESERIES_LOG_ERROR, "%s", buffer); //sprintf("**Error: %s\n", buffer); throw bios::BiosFail(buffer); } /** * \brief This function logs warning message * * \param[in] msg is a format string for the message * \param[in] VA_LIST variable list of optional parameters */ inline void logWarn(const char* msg, ...) { static const size_t MAX_LEN = 512; char buffer[MAX_LEN]; va_list args; va_start(args, msg); (void)vsnprintf(buffer, MAX_LEN, msg, args); va_end(args); //eseriesLog("eseries-bios-utils", ESERIES_LOG_WARN, "%s", buffer); printf("**Warning: %s\n", buffer); //std::cerr << buffer << std::endl; } /** * \brief This function logs normal message * * \param[in] msg is a format string for the message * \param[in] VA_LIST variable list of optional parameters */ inline void logNorm(const char* msg, ...) { static const size_t MAX_LEN = 512; char buffer[MAX_LEN]; va_list args; va_start(args, msg); (void)vsnprintf(buffer, MAX_LEN, msg, args); va_end(args); //eseriesLog("eseries-bios-utils", ESERIES_LOG_NORMAL, "%s", buffer); printf("%s\n", buffer); //std::cout << buffer << std::endl; } } #endif /* End of __INCbiosLib */