/*-1* Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Justin T. Gibbs (Spectra Logic Corporation)30*/3132/**33* \file zfsd_exception.h34*35* Definition of the ZfsdException class hierarchy. All exceptions36* explicitly thrown by Zfsd are defined here.37*/38#ifndef _DEVDCTL_EXCEPTION_H_39#define _DEVDCTL_EXCEPTION_H_4041/*============================ Namespace Control =============================*/42namespace DevdCtl43{4445/*============================= Class Definitions ============================*/4647/*--------------------------------- Exception --------------------------------*/48/**49* \brief Class allowing unified reporting/logging of exceptional events.50*/51class Exception52{53public:54/**55* \brief Exception constructor allowing arbitrary string56* data to be reported.57*58* \param fmt Printf-like string format specifier.59*/60Exception(const char *fmt, ...);6162/**63* \brief Augment/Modify a Exception's string data.64*/65std::string& GetString();6667/**68* \brief Emit exception data to syslog(3).69*/70virtual void Log() const;7172protected:73Exception();7475/**76* \brief Convert exception string format and arguments provided77* in event constructors into a linear string.78*/79void FormatLog(const char *fmt, va_list ap);8081std::string m_log;82};8384inline std::string &85Exception::GetString()86{87return (m_log);88}8990/*------------------------------ ParseException ------------------------------*/91/**92* Exception thrown when an event string is not converted to an actionable93* Event object.94*/95class ParseException : public Exception96{97public:98enum Type99{100/** Improperly formatted event string encountered. */101INVALID_FORMAT,102103/** No handlers for this event type. */104DISCARDED_EVENT_TYPE,105106/** Unhandled event type. */107UNKNOWN_EVENT_TYPE108};109110/**111* Constructor112*113* \param type The type of this exception.114* \param parsedBuffer The parsing buffer active at the time of115* the exception.116* \param offset The location in the parse buffer where this117* exception occurred.118*/119ParseException(Type type, const std::string &parsedBuffer,120size_t offset = 0);121122/**123* Accessor124*125* \return The classification for this exception.126*/127Type GetType() const;128129/**130* Accessor131*132* \return The offset into the event string where this exception133* occurred.134*/135size_t GetOffset() const;136137private:138/** The type of this exception. */139Type m_type;140141/** The parsing buffer that was active at the time of the exception. */142const std::string m_parsedBuffer;143144/**145* The offset into the event string buffer from where this146* exception was triggered.147*/148size_t m_offset;149};150151//- ParseException Inline Const Public Methods ---------------------------------152inline ParseException::Type153ParseException::GetType() const154{155return (m_type);156}157158inline size_t159ParseException::GetOffset() const160{161return (m_offset);162}163164} // namespace DevdCtl165#endif /* _DEVDCTL_EXCEPTION_H_ */166167168