OidSpace.h

// OidSpace.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2011

#include "Ceda/cxUtils/xostream.h"
@import "Ceda/cxObject/Guid2.h"
@import "OID.h"

namespace ceda
{
/*
Sites use a global object identifier space, effectively 160 bit, hopefully allowing any computer to 
generate unique identifiers across the world.

An OidSpaceGuid is a 128 bit GUID that uniquely identifies an Oid Space.  It is assumed that sites 
can independently generate OidSpaceGuids that do not clash.

Each OidSpaceGuid identifies its own 32 bit address space indexed by a Local Identifier (OidLow). 
OidLows can easily be repeated across the system.   However the pair (OidSpaceGuid, OidLow) 
forms a globally unique 160 bit identifier for an object.
 
Each site stores its own persistent bijective map between 32 bit OID Space Identifier (OidHigh) 
and OidSpaceGuid.  This allows the 160 bit (OidSpaceGuid,OidLow) to be locally represented as a 
correponding (OidHigh,OidLow) which is 64 bit and matches the OIDs used in the local LSS.

This limits a given site to 2^64 objects,  taken from up to 2^32 different Oid Spaces.
  
Object identifiers are always stored and sent over the wire using 64 bit OIDs.  However OIDs 
that are sent over the wire must be accompanied by (OidHigh,OidSpaceGuid) pairs.   This allows 
the receiver to set up a mapping from remote OidHigh to local OidHigh,  to allow OIDs to be 
translated.  An (OidHigh,OidSpaceGuid) pair only needs to be sent at most once in a given session 
between two computers.  Therefore this overhead can be minimised.
*/

// 128 bit guid used to uniquely identify an OidSpace - which is a 32 bit address space used 
// by a computer for its OID allocations.
$typedef+ Guid OidSpaceGuid;

$struct+ Goid
{
    #if CEDA_LSS_USE_CONTIGUOUS_SEID_SPACE
        // We can't test oidLow, because oidLow=0 doesn't imply a null oid
        explicit operator bool() const { return oidSpaceGuid != Guid_NULL; }
    #else
        explicit operator bool() const { return oidLow != 0; }
    #endif
    
    $OidSpaceGuid oidSpaceGuid;
    $OidLow oidLow;
};

@api xostream& operator<<(xostream& os, const Goid& g);

@def bool CEDA_VALIDATE_OID_READER_WRITER_ORDER = false

} // namespace ceda