UUID.st
changeset 2978 4497be5fc993
parent 2977 afc4d10019c7
child 3121 ca7d3132c33f
equal deleted inserted replaced
2977:afc4d10019c7 2978:4497be5fc993
   166                       16r13 16r14 16r15 16r16] msb:true.    
   166                       16r13 16r14 16r15 16r16] msb:true.    
   167     "
   167     "
   168 !
   168 !
   169 
   169 
   170 fromBytes:aByteArray msb:msb
   170 fromBytes:aByteArray msb:msb
       
   171     <resource: #obsolete>
   171     "Set the UUID from aByteArray. UUIDS are stored internally as MSB-first. 
   172     "Set the UUID from aByteArray. UUIDS are stored internally as MSB-first. 
   172      So, alway set
   173      So, alway set
   173         msb = true      if reading from network or persistent storage"
   174         msb = true      if reading from network or persistent storage"
   174 
   175 
   175     self obsoleteMethodWarning:'use fromBytes:MSB:'.
   176     self obsoleteMethodWarning:'use fromBytes:MSB:'.
   389 
   390 
   390     ^ (Timestamp now getMilliseconds + 12219292800000) * 10000.
   391     ^ (Timestamp now getMilliseconds + 12219292800000) * 10000.
   391 !
   392 !
   392 
   393 
   393 getValidMACAddress
   394 getValidMACAddress
   394     "return the first valid MAC address (i.e. having at least one byte ~~ 0)"
   395     "return the first valid MAC address (i.e. having at least 6 bytes with the first six bytes ~~ 0)"
   395 
   396 
   396     CachedMACAddress isNil ifTrue:[
   397     CachedMACAddress isNil ifTrue:[
   397         CachedMACAddress := false.      "cache the fact, that there is no MAC address" 
   398         CachedMACAddress := false.      "negative caching: remember the fact, that there is no MAC address" 
   398         [
   399         [
   399             CachedMACAddress := OperatingSystem getNetworkMACAddresses 
   400             CachedMACAddress := OperatingSystem getNetworkMACAddresses 
   400                                     detect:[:macAddress | macAddress ~= #[0 0 0 0 0 0]]
   401                                     detect:[:macAddress | macAddress size >= 6 
       
   402                                                             and:[(macAddress startsWith:#[0 0 0 0 0 0]) not]]
   401                                     ifNone:false.
   403                                     ifNone:false.
   402         ] on:PrimitiveFailure do:[:ex| "ignore"].
   404         ] on:PrimitiveFailure do:[:ex| "ignore"].
   403     ].
   405     ].
   404 
   406 
   405     ^ CachedMACAddress
   407     ^ CachedMACAddress
   585     "multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7"
   587     "multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7"
   586     self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40).
   588     self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40).
   587     self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80).
   589     self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80).
   588 
   590 
   589     "
   591     "
   590       self new genRandomUUID
   592       self genRandomUUID
   591 
       
   592       self genRandomUUID genRandomUUID
   593       self genRandomUUID genRandomUUID
   593     "
   594     "
   594 
   595 
   595     "
   596     "
   596       |uuids sample|
   597       |uuids sample|
   877 ! !
   878 ! !
   878 
   879 
   879 !UUID class methodsFor:'documentation'!
   880 !UUID class methodsFor:'documentation'!
   880 
   881 
   881 version
   882 version
   882     ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.44 2013-04-22 15:48:57 stefan Exp $'
   883     ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.45 2013-04-25 07:12:17 stefan Exp $'
   883 !
   884 !
   884 
   885 
   885 version_CVS
   886 version_CVS
   886     ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.44 2013-04-22 15:48:57 stefan Exp $'
   887     ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.45 2013-04-25 07:12:17 stefan Exp $'
   887 ! !
   888 ! !
   888 
   889 
   889 
   890 
   890 UUID initialize!
   891 UUID initialize!