/*-1* Copyright (c) 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: Alan Somers (Spectra Logic Corporation)30*/3132/**33* \file devdctl_guid.h34*35* Definition of the Guid class.36*/37#ifndef _DEVDCTL_GUID_H_38#define _DEVDCTL_GUID_H_3940/*============================ Namespace Control =============================*/41namespace DevdCtl42{4344/*============================= Class Definitions ============================*/45/*----------------------------------- Guid -----------------------------------*/46/**47* \brief Object that represents guids.48*49* It can generally be manipulated as a uint64_t, but with a special50* value INVALID_GUID that does not equal any valid guid.51*52* As of this writing, this class is only used to represent ZFS53* guids in events and spa_generate_guid() in spa_misc.c explicitly54* refuses to return a guid of 0. So this class uses 0 as the value55* for INVALID_GUID. In the future, if 0 is allowed to be a valid56* guid, the implementation of this class must change.57*/58class Guid59{60public:61/* Constructors */62/* Default constructor: an Invalid guid */63Guid();64/* Construct a guid from a provided integer */65Guid(uint64_t guid);66/* Construct a guid from a string in base 8, 10, or 16 */67Guid(const std::string &guid);68static Guid InvalidGuid();6970/* Test the validity of this guid. */71bool IsValid() const;7273/* Comparison to other Guid operators */74bool operator==(const Guid& rhs) const;75bool operator!=(const Guid& rhs) const;7677/* Integer conversion operators */78operator uint64_t() const;79operator bool() const;8081protected:82static const uint64_t INVALID_GUID = 0;8384/* The integer value of the GUID. */85uint64_t m_GUID;86};8788//- Guid Inline Public Methods ------------------------------------------------89inline90Guid::Guid()91: m_GUID(INVALID_GUID)92{93}9495inline96Guid::Guid(uint64_t guid)97: m_GUID(guid)98{99}100101inline Guid102Guid::InvalidGuid()103{104return (Guid(INVALID_GUID));105}106107inline bool108Guid::IsValid() const109{110return (m_GUID != INVALID_GUID);111}112113inline bool114Guid::operator==(const Guid& rhs) const115{116return (m_GUID == rhs.m_GUID);117}118119inline bool120Guid::operator!=(const Guid& rhs) const121{122return (m_GUID != rhs.m_GUID);123}124125inline126Guid::operator uint64_t() const127{128return (m_GUID);129}130131inline132Guid::operator bool() const133{134return (m_GUID != INVALID_GUID);135}136137/** Convert the GUID into its string representation */138std::ostream& operator<< (std::ostream& out, Guid g);139140} // namespace DevdCtl141#endif /* _DEVDCTL_GUID_H_ */142143144