UUID.st
author Stefan Vogel <sv@exept.de>
Tue, 14 Mar 2006 22:04:26 +0100
changeset 1613 feef745939ea
parent 1612 2877abd0a002
child 1647 124e977b6a8f
permissions -rw-r--r--
Use UTC time
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2002 by eXept Software AG
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
ByteArray variableByteSubclass:#UUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:''
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    17
	classVariableNames:'CachedMACAddress Lock SequenceNumber LastTime Increment
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    18
		NameSpaceDNS NameSpaceDN NameSpaceURL NameSpaceOID'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
1304
1c58aa764724 category
Claus Gittinger <cg@exept.de>
parents: 1287
diff changeset
    20
	category:'Net-Communication-Support'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2002 by eXept Software AG
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    37
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    38
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    39
documentation
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    40
"
1544
6c339f276b91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    41
    128-bit Universal Unique Ids (UUIDs) as defined by OpenGroup/DCE
6c339f276b91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1543
diff changeset
    42
        http://www.opengroup.org/onlinepubs/9629399/apdxa.htm.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    43
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    44
    See also RFC4122.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    45
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    46
    A UUID is unique in time and space (at least until about Year 3400).
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    47
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    48
    Several fields if the UUID are interpreted as integers, so host/network byte
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    49
    order is relevant. UUIDs are stored in a ByteArray in network byte order (MSB-first),
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    50
    so they may be exported/imported between different machines.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    51
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    52
    You can import UUIDs in host byte order using #fromNativeBytes:
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    53
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    54
    [author:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    55
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    56
    [instance variables:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    57
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    58
    [class variables:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    59
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    60
    [see also:]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    61
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    62
"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    63
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    64
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    65
!UUID class methodsFor:'initialization'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    66
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    67
initialize
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    68
    "I want to get informed about image restarts"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    69
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    70
    Lock isNil ifTrue:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    71
        Lock := RecursionLock new name:'UUID'.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    72
        LastTime := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    73
        Increment := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    74
        ObjectMemory addDependent:self.
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    75
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    76
        NameSpaceDNS := self fromBytes:#[16r6B 16rA7 16rB8 16r10 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    77
        NameSpaceURL := self fromBytes:#[16r6B 16rA7 16rB8 16r11 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    78
        NameSpaceOID := self fromBytes:#[16r6B 16rA7 16rB8 16r12 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
    79
        NameSpaceDN  := self fromBytes:#[16r6B 16rA7 16rB8 16r14 16r9D 16rAD 16r11 16rD1 16r80 16rB4 16r0 16rC0 16r4F 16rD4 16r30 16rC8].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    80
    ]
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    81
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    82
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    83
update:something with:aParameter from:changedObject
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    84
    "flush cached MAC address (may have been restarted on another host)"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    85
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    86
    (something == #restarted) ifTrue:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    87
        CachedMACAddress := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    88
        SequenceNumber := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
    89
    ]
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
!UUID class methodsFor:'instance creation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
    94
fromBytes:aByteArray
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    95
    "set uuid from aByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    96
     aByteArray must be 16 bytes in network byte order (MSB-first)"
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
    97
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
    98
    |uuid|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    uuid := self new.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    uuid replaceFrom:1 to:16 with:aByteArray.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   102
    ^ uuid.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   104
    "    
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   105
     UUID fromBytes:#[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   106
                      16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   107
                      16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   108
                      16r13 16r14 16r15 16r16]. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   109
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   110
!
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   112
fromBytes:aByteArray msb:msb
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   113
    "Set the UUID from aByteArray. UUIDS are stored internally as MSB-first. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   114
     So, alway set
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   115
        msb = true      if reading from network or persistent storage"
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   117
    |uuid|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   118
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   119
    uuid := self fromBytes:aByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   120
    msb ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   121
        self adjustByteOrder:uuid.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    ^ uuid
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
                      16r13 16r14 16r15 16r16] msb:false. 
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
                      16r13 16r14 16r15 16r16] msb:true.    
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   140
fromNativeBytes:aByteArray
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   141
    "convert bytes to uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   142
     aByteArray represents a UUID in host byte order 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   143
     - e.g. an UUID fetched from the Windows OS"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   144
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   145
    |uuid|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   146
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   147
    uuid := self fromBytes:aByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   148
    self isBigEndian ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   149
        self adjustByteOrder:uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   150
    ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   151
    ^ uuid.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   152
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   153
    "    
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   154
     UUID fromNativeBytes:#[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   155
                              16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   156
                              16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   157
                              16r13 16r14 16r15 16r16]. 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   158
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   159
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   160
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   161
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   162
genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   163
    "generate a new random UUID"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   164
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   165
    ^ self new genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   166
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   167
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   168
      self genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   169
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   170
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   171
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   172
genUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   173
    "generate a uuid.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   174
     If a physical mac address can be retrieved from the OS,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   175
     a mac-address/timestamp uuid is generated,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   176
     otherwise a random uuid will be generated."
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    ^ self new genUUID
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   179
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   180
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   181
      self genUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   182
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
new
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    ^ super new:16
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
new:size
1320
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   190
    "allow creating with exact size. We need this for XMLStandardDecoder"
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   191
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   192
    size ~~ 16 ifTrue:[
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   193
        ^ self shouldNotImplement.
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   194
    ].
fc8265f89040 XMLStandardDecoder compatibility
Stefan Vogel <sv@exept.de>
parents: 1304
diff changeset
   195
    ^ super new:size.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   196
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   197
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   198
readFrom:aStringOrStream onError:errorBlock
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   199
    |d offs s uuid t byte|
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   200
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   201
    Error handle:[:ex |
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   202
        ^ errorBlock value.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   203
    ] do:[
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   204
        s := aStringOrStream readStream.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   205
        uuid := self new.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   206
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   207
        s skipSeparators.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   208
        s peek == ${ ifTrue:[s next].
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   209
        s skipSeparators.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   210
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   211
        t := s next:8.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   212
        d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   213
        uuid unsignedLongAt:1 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   214
        offs := 5.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   215
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   216
        s next.         "skip $-"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   217
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   218
        1 to:2 do:[:i |
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   219
            t := s next:4.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   220
            d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   221
            uuid unsignedShortAt:offs put:d bigEndian:true.
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   222
            offs := offs + 2.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   223
            s next.     "skip $-"
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   224
        ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   225
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   226
        1 to:2 do:[:i |
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   227
            t := s next:2.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   228
            d := Integer readFrom:t radix:16 onError:[^ errorBlock value].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   229
            uuid at:offs put:d.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   230
            offs := offs + 1.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   231
        ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   232
        s next.         "skip $-"
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   233
1543
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   234
        1 to:6 do:[:i |
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   235
            t := s next:2.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   236
            byte := Integer readFrom:t radix:16 onError:[^ errorBlock value].
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   237
            uuid at:offs put:byte.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   238
            offs := offs + 1.
929986f0910a fixed readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1491
diff changeset
   239
        ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   240
    ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   241
    ^ uuid
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   242
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   243
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   244
     UUID readFrom:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77' 
1601
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   245
     UUID fromString:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77'
b0dfbe332caf WARNING: byte order of internal byte-representation changed;
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   246
     UUID fromString:'00000001-0000-0000-C000-000000000046'
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   247
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   250
!UUID class methodsFor:'helpers'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   251
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   252
adjustByteOrder:aByteArray
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   253
    "change the byte order of the uuid"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   254
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   255
    |d|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   256
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   257
    d := aByteArray unsignedLongAt:1 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   258
    aByteArray unsignedLongAt:1 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   259
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   260
    d := aByteArray unsignedShortAt:1+4 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   261
    aByteArray unsignedShortAt:1+4 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   262
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   263
    d := aByteArray unsignedShortAt:1+4+2 bigEndian:false.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   264
    aByteArray unsignedShortAt:1+4+2 put:d bigEndian:true.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   265
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   266
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   267
getDtssUtcTime
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   268
    "return the DTSS based time in 100 nsec intervals
1613
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   269
     DTSS UTC base time is October 15, 1582 (the start of the Gregorian Calendar).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   270
     Unix base time is January 1, 1970.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   271
     The difference between both is: 122192928000000000"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   272
1613
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   273
    |t|
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   274
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   275
    t := Timestamp now.
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   276
    ^ (t getMilliseconds + (t utcOffset * 1000) + 12219292800000) * 10000.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   277
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   278
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   279
getValidMACAddress
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   280
    "return the first valid MAC address (i.e. having at least one byte ~~ 0)"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   281
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   282
    CachedMACAddress isNil ifTrue:[
1491
512b21b45a9e noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents: 1467
diff changeset
   283
        |dictOfIf ipAddr|
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   284
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   285
        CachedMACAddress := false.      "cache the fact, that there is no MAC address" 
1577
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   286
        [
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   287
            dictOfIf := OperatingSystem getNetworkMACAddresses.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   288
1577
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   289
            dictOfIf do:[:macAddress |
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   290
                (macAddress contains:[:byte | byte ~~ 0]) ifTrue:[
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   291
                    ^ CachedMACAddress := macAddress
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   292
                ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   293
            ].
1577
c0db2891f228 Ignore primitive failures when doing #getNetworkMACAddresses
Stefan Vogel <sv@exept.de>
parents: 1544
diff changeset
   294
        ] on:PrimitiveFailure do:[:ex| "ignore"].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   295
    ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   296
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   297
    ^ CachedMACAddress
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   298
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   299
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   300
       CachedMACAddress := nil.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   301
       self getValidMACAddress
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   302
    "
1491
512b21b45a9e noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents: 1467
diff changeset
   303
512b21b45a9e noMacAddress fallBack (NT4.0)
Claus Gittinger <cg@exept.de>
parents: 1467
diff changeset
   304
    "Modified: / 17-11-2004 / 01:45:53 / cg"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   305
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   306
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   307
!UUID methodsFor:'accessing'!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   308
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   309
clockSeqHiAndReserved
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   310
    ^ self at:9
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   311
!
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   312
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   313
clockSeqLow
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   314
    ^ self at:10
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   315
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   316
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   317
node
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   318
    ^ self copyFrom:11 to:16
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   319
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   320
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   321
timeHighAndVersion
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   322
    ^ self unsignedShortAt:7 bigEndian:true
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   323
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   324
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   325
timeLow
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   326
    ^ self unsignedLongAt:1 bigEndian:true
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   327
!
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   328
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   329
timeMid
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   330
    ^ self unsignedShortAt:5 bigEndian:true
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   331
! !
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   332
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
!UUID methodsFor:'converting'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   335
asBytes
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   336
    "convert this UUID to a ByteArray in network byte order (MSB-first)"
1382
626693b1fed7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1320
diff changeset
   337
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   338
    |bytes|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    bytes := ByteArray new:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    bytes replaceFrom:1 to:16 with:self.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   342
    ^ bytes
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   344
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   345
     |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   346
        
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   347
     bytes := #[16r01 16r02 16r03 16r04
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   348
                      16r05 16r06 16r07 16r08
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   349
                      16r09 16r10 16r11 16r12
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   350
                      16r13 16r14 16r15 16r16].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   351
     (UUID fromBytes:bytes) asBytes ~= bytes ifTrue:[self halt] 
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   352
    "
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   353
!
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   355
asBytesMSB:msb
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   356
    "convert this UUID to a ByteArray.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   357
     If msb == false, it is converted into LSB-first byte oredering"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   358
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   359
    |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   360
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   361
    bytes := self asBytes.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   362
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   363
    msb ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   364
        self class adjustByteOrder:bytes.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
    ^ bytes
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   367
!
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   368
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   369
asNativeBytes
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   370
    "convert this uuid to a ByteArray in host byte order.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   371
     Use this only to pass the UUID to the OS (Windows)"
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   372
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   373
    |bytes|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   374
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   375
    bytes := self asBytes.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   376
    self class isBigEndian ifFalse:[
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   377
        self class adjustByteOrder:bytes.
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   378
    ].
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   379
    ^ bytes.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
!UUID methodsFor:'generating uuids'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   384
genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   385
    "answer a randomly generated uuid as defined in RFC4122 section 4.4"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   386
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   387
    self replaceFrom:1 to:16 with:(RandomGenerator new nextBytes:16).
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   388
    "multiplex the 4 bit version number (Version 4 -> Random UUID) in high bits of byte 7"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   389
    self at:7 put:(((self at:7) bitAnd:16r0F) bitOr:16r40).
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   390
    self at:9 put:(((self at:9) bitAnd:16r3F) bitOr:16r80).
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   391
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   392
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   393
      self new genRandomUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   394
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   395
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   396
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   397
      1 to: 100 do:[ : el |
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   398
          Transcript show:el.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   399
          Transcript show:': '.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   400
          Transcript showCR:(UUID new genRandomUUID).
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   401
      ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   402
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   403
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   404
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   405
genTimestampUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   406
    "generate a timestamp (and mac-address) based uuid"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   407
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   408
    |macBytes utcTime seqNr|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   410
    macBytes := self class getValidMACAddress.
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   411
    macBytes size ~~ 6 ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   412
        self error:'no mac address - cannot generate UUID'.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   413
    ].
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   415
    "use 60 bit counter of 100ns ticks since 00:00:00 15.oct 1582 (sigh)"
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   416
    utcTime := self class getDtssUtcTime.
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   417
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   418
    Lock critical:[
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   419
        SequenceNumber isNil ifTrue:[
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   420
            SequenceNumber := RandomGenerator new nextIntegerBetween:0 and:16383.
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   421
        ].
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   422
        utcTime > (LastTime+Increment) ifTrue:[
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   423
            Increment := 0.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   424
        ] ifFalse:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   425
            LastTime = utcTime ifTrue:[
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   426
                "clock didn't advance since last call. Simply add a tick"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   427
                Increment := Increment + 1.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   428
            ] ifFalse:[
1467
a394ade68816 Protect against a nil SequenceNumber
Stefan Vogel <sv@exept.de>
parents: 1447
diff changeset
   429
                "clock went backwards - increment SequenceNumber"
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   430
                Increment := 0.
1214
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   431
                SequenceNumber := SequenceNumber + 1.
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   432
                SequenceNumber >= 16384 ifTrue:[SequenceNumber := 0].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   433
            ].
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
        ].
1214
7ae6b9302754 Fix previous change
Stefan Vogel <sv@exept.de>
parents: 1213
diff changeset
   435
        
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   436
        LastTime := utcTime.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   437
        utcTime := utcTime + Increment.
1610
5f79965e186b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1608
diff changeset
   438
        seqNr := SequenceNumber.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   441
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   442
    "time low: long"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   443
    self unsignedLongAt:1 put:(utcTime bitAnd:16rFFFFFFFF) bigEndian:true.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   444
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   445
    "time med: short"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   446
    utcTime := utcTime bitShift:-32.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   447
    self unsignedShortAt:5 put:(utcTime bitAnd:16rFFFF) bigEndian:true.
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   448
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   449
    "time high and version: short
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   450
     multiplex the 4 bit version number in highest 4 bits (version 1 -> time based version)"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   451
    self unsignedShortAt:7 put:((utcTime bitShift:-16) bitOr:16r1000) bigEndian:true.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   453
    "2 sequence bytes + reserved bits (this is not a short!!)"
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   454
    self at:9  put:(((seqNr bitShift:-8) bitAnd:16r3F) bitOr:16r80).
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   455
    self at:10 put:(seqNr bitAnd:16rFF).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   456
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   457
    "48 bits of MAC-Address"
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   458
    self replaceFrom:11 to:16 with:macBytes startingAt:1.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
    "
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   461
      self new genTimestampUUID
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   462
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   464
    "
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   465
      1 to: 100 do:[ : el |
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   466
          Transcript show:el.
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   467
          Transcript show:': '.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   468
          Transcript showCR:(UUID new genTimestampUUID).
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   469
      ].
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   470
    "
1608
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   471
!
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   472
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   473
genUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   474
    "generate a uuid - the existing uuid bytes are overwritten.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   475
     If a physical mac address can be retrieved from the OS,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   476
     a mac-address/timestamp uuid is generated,
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   477
     otherwise a random uuid will be generated."
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   478
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   479
    CachedMACAddress isNil ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   480
        self class getValidMACAddress.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   481
    ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   482
    CachedMACAddress == false ifTrue:[
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   483
        "no mac address - generate random UUID"
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   484
        ^ self genRandomUUID.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   485
    ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   486
    ^ self genTimestampUUID.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   487
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   488
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   489
      self genUUID
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   490
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   491
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   492
    "
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   493
      1 to: 100 do:[ : el |
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   494
          Transcript show:el.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   495
          Transcript show:': '.
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   496
          Transcript showCR:(UUID genUUID).
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   497
      ].
e1cf5d2b6f2f Add random UUID in case there is no mac address
Stefan Vogel <sv@exept.de>
parents: 1602
diff changeset
   498
    "
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
!UUID methodsFor:'printing'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
displayString
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
    ^ self printString
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
printOn:aStream
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   508
    |d tmpStream|
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   510
    tmpStream := '' writeStream.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   512
    1 to:4 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   513
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   514
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   515
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   516
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   517
    5 to:6 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   518
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   519
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   520
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   521
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   522
    7 to:8 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   523
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   524
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   525
    ].
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   526
    tmpStream nextPut:$-.
1612
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   527
    9 to:10 do:[:idx|
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   528
        d := self at:idx.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   529
        d printOn:tmpStream base:16 size:2 fill:$0.
2877abd0a002 Byte ordering issues
Stefan Vogel <sv@exept.de>
parents: 1611
diff changeset
   530
    ].
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   531
    tmpStream nextPut:$-.
1602
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   532
    11 to:16 do:[:idx|
6ffbb8db78a4 Fix byte ordering.
Stefan Vogel <sv@exept.de>
parents: 1601
diff changeset
   533
        d := self at:idx.
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   534
        d printOn:tmpStream base:16 size:2 fill:$0.
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   537
    aStream nextPutAll:(tmpStream contents asLowercase).
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
version
1613
feef745939ea Use UTC time
Stefan Vogel <sv@exept.de>
parents: 1612
diff changeset
   543
    ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.21 2006-03-14 21:04:26 stefan Exp $'
1188
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
! !
1213
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   545
5a23a433a990 Refactoring
Stefan Vogel <sv@exept.de>
parents: 1188
diff changeset
   546
UUID initialize!