1169691Skan/*- 2169691Skan * Copyright (c) 2012, 2013 Spectra Logic Corporation 3169691Skan * All rights reserved. 4169691Skan * 5169691Skan * Redistribution and use in source and binary forms, with or without 6169691Skan * modification, are permitted provided that the following conditions 7169691Skan * are met: 8169691Skan * 1. Redistributions of source code must retain the above copyright 9169691Skan * notice, this list of conditions, and the following disclaimer, 10169691Skan * without modification. 11169691Skan * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12169691Skan * substantially similar to the "NO WARRANTY" disclaimer below 13169691Skan * ("Disclaimer") and any redistribution must be conditioned upon 14169691Skan * including a substantially similar Disclaimer requirement for further 15169691Skan * binary redistribution. 16169691Skan * 17169691Skan * NO WARRANTY 18169691Skan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19169691Skan * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20169691Skan * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21169691Skan * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22169691Skan * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23169691Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24169691Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26169691Skan * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27169691Skan * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28169691Skan * POSSIBILITY OF SUCH DAMAGES. 29169691Skan * 30169691Skan * Authors: Alan Somers (Spectra Logic Corporation) 31169691Skan */ 32169691Skan 33169691Skan/** 34169691Skan * \file devdctl_guid.h 35169691Skan * 36169691Skan * Definition of the Guid class. 37169691Skan */ 38169691Skan#ifndef _DEVDCTL_GUID_H_ 39169691Skan#define _DEVDCTL_GUID_H_ 40169691Skan 41169691Skan/*============================ Namespace Control =============================*/ 42169691Skannamespace DevdCtl 43169691Skan{ 44169691Skan 45169691Skan/*============================= Class Definitions ============================*/ 46169691Skan/*----------------------------------- Guid -----------------------------------*/ 47169691Skan/** 48169691Skan * \brief Object that represents guids. 49169691Skan * 50169691Skan * It can generally be manipulated as a uint64_t, but with a special 51169691Skan * value INVALID_GUID that does not equal any valid guid. 52169691Skan * 53169691Skan * As of this writing, this class is only used to represent ZFS 54169691Skan * guids in events and spa_generate_guid() in spa_misc.c explicitly 55169691Skan * refuses to return a guid of 0. So this class uses 0 as the value 56169691Skan * for INVALID_GUID. In the future, if 0 is allowed to be a valid 57169691Skan * guid, the implementation of this class must change. 58169691Skan */ 59169691Skanclass Guid 60169691Skan{ 61169691Skanpublic: 62169691Skan /* Constructors */ 63169691Skan /* Default constructor: an Invalid guid */ 64169691Skan Guid(); 65169691Skan /* Construct a guid from a provided integer */ 66169691Skan Guid(uint64_t guid); 67169691Skan /* Construct a guid from a string in base 8, 10, or 16 */ 68169691Skan Guid(const std::string &guid); 69169691Skan static Guid InvalidGuid(); 70169691Skan 71169691Skan /* Test the validity of this guid. */ 72169691Skan bool IsValid() const; 73169691Skan 74169691Skan /* Comparison to other Guid operators */ 75169691Skan bool operator==(const Guid& rhs) const; 76169691Skan bool operator!=(const Guid& rhs) const; 77169691Skan 78169691Skan /* Integer conversion operators */ 79169691Skan operator uint64_t() const; 80169691Skan operator bool() const; 81169691Skan 82169691Skanprotected: 83169691Skan static const uint64_t INVALID_GUID = 0; 84169691Skan 85169691Skan /* The integer value of the GUID. */ 86169691Skan uint64_t m_GUID; 87169691Skan}; 88169691Skan 89169691Skan//- Guid Inline Public Methods ------------------------------------------------ 90169691Skaninline 91169691SkanGuid::Guid() 92169691Skan : m_GUID(INVALID_GUID) 93169691Skan{ 94169691Skan} 95169691Skan 96169691Skaninline 97169691SkanGuid::Guid(uint64_t guid) 98169691Skan : m_GUID(guid) 99169691Skan{ 100169691Skan} 101169691Skan 102169691Skaninline Guid 103169691SkanGuid::InvalidGuid() 104169691Skan{ 105169691Skan return (Guid(INVALID_GUID)); 106169691Skan} 107169691Skan 108169691Skaninline bool 109169691SkanGuid::IsValid() const 110169691Skan{ 111169691Skan return (m_GUID != INVALID_GUID); 112169691Skan} 113169691Skan 114169691Skaninline bool 115169691SkanGuid::operator==(const Guid& rhs) const 116169691Skan{ 117169691Skan return (m_GUID == rhs.m_GUID); 118169691Skan} 119169691Skan 120169691Skaninline bool 121169691SkanGuid::operator!=(const Guid& rhs) const 122169691Skan{ 123169691Skan return (m_GUID != rhs.m_GUID); 124169691Skan} 125169691Skan 126169691Skaninline 127169691SkanGuid::operator uint64_t() const 128169691Skan{ 129169691Skan return (m_GUID); 130169691Skan} 131169691Skan 132169691Skaninline 133169691SkanGuid::operator bool() const 134169691Skan{ 135169691Skan return (m_GUID != INVALID_GUID); 136169691Skan} 137169691Skan 138169691Skan/** Convert the GUID into its string representation */ 139169691Skanstd::ostream& operator<< (std::ostream& out, Guid g); 140 141} // namespace DevdCtl 142#endif /* _DEVDCTL_GUID_H_ */ 143