UUID.st
author Claus Gittinger <cg@exept.de>
Mon, 28 Apr 2003 14:09:08 +0200
changeset 1188 58856b846271
child 1213 5a23a433a990
permissions -rw-r--r--
initial checkin
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:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:'NextSeqNr'
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'System-Communication-Support'
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
AbsoluteTime variableByteSubclass:#UTCTime
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	instanceVariableNames:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	classVariableNames:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
	poolDictionaries:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	privateIn:UUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
Object variableByteSubclass:#UUIDRandom
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	instanceVariableNames:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
	classVariableNames:'rand_m rand_ia rand_ib rand_irand'
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
	poolDictionaries:''
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	privateIn:UUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
copyright
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 COPYRIGHT (c) 2002 by eXept Software AG
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
              All Rights Reserved
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 This software is furnished under a license and may be used
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
 only in accordance with the terms of that license and with the
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
 inclusion of the above copyright notice.   This software may not
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 be provided or otherwise made available to, or used by, any
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 other person.  No title to or ownership of the software is
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
 hereby transferred.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
!UUID class methodsFor:'instance creation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
fromBytes:aByteArray msb:msb
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    |uuid d1 d2 d3|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    uuid := self new.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    uuid replaceFrom:1 to:16 with:aByteArray.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    msb ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
        d1 := aByteArray unsignedLongAt:1 bigEndian:msb.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        uuid unsignedLongAt:1 put:d1 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        d2 := aByteArray unsignedShortAt:1+4 bigEndian:msb.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
        uuid unsignedShortAt:1+4 put:d2 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        d3 := aByteArray unsignedShortAt:1+4+2 bigEndian:msb.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        uuid unsignedShortAt:1+4+2 put:d3 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    ^ uuid
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
                      16r13 16r14 16r15 16r16] msb:false. 
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
     UUID fromBytes:#[16r01 16r02 16r03 16r04
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
                      16r05 16r06 16r07 16r08
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
                      16r09 16r10 16r11 16r12
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
                      16r13 16r14 16r15 16r16] msb:true.    
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
fromString:aString
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    |d offs s uuid t byte|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    s := aString readStream.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    uuid := self new.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    offs := 1.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    s skipSeparators.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    s peek == ${ ifTrue:[s next].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    s skipSeparators.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    t := s next:8.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    d := Integer readFrom:t radix:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    uuid unsignedLongAt:1 put:d bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    offs := offs + 4.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    s next.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    1 to:2 do:[:i |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
        t := s next:4.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
        d := Integer readFrom:t radix:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        uuid unsignedShortAt:offs put:d bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
        offs := offs + 2.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        s next.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    t := s next:4.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    d := Integer readFrom:t radix:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    uuid unsignedShortAt:offs put:d bigEndian:true.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
    offs := offs + 2.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    s next.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    1 to:6 do:[:i |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
        t := s next:2.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
        byte := Integer readFrom:t radix:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
        uuid at:offs put:byte.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
        offs := offs + 1.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    ^ uuid
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
     UUID fromString:'5ab2e9b4-3d48-11d2-9ea4-80c5140aaa77' 
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
genUUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    ^ self new genUUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
new
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    ^ super new:16
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
new:size
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    self shouldNotImplement
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!UUID class methodsFor:'defaults'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
uuidVersion
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    ^ 1
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!UUID methodsFor:'converting'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
asBytesMSB:msb
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    |bytes d1 d2 d3|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    bytes := ByteArray new:16.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    bytes replaceFrom:1 to:16 with:self.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    msb ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
        d1 := self unsignedLongAt:1 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
        d2 := self unsignedShortAt:1+4 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
        d3 := self unsignedShortAt:1+4+2 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
        bytes unsignedLongAt:1 put:d1 bigEndian:true.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
        bytes unsignedShortAt:1+4 put:d2 bigEndian:true.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
        bytes unsignedShortAt:1+4+2 put:d3 bigEndian:true.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    ^ bytes
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
!UUID methodsFor:'generating uuids'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
genUUID
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    |macBytes utcTime length byte uuidClockSeq|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
    NextSeqNr isNil ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
        NextSeqNr := 1.                Socket new
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    macBytes := self getValidMACAdress.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    macBytes isNil ifTrue:[ ^ nil].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    self replaceFrom:16-6+1 to:16 with:macBytes startingAt:1.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    "/ use 60 bit 100ns ticks since 00:00:00 15.oct 1582 (sigh)
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    utcTime := UTCTime now.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    length := utcTime digitLength.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "/ time_low bytes 1-4
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    1 to: 4 do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
        byte := utcTime digitAt:(length - el + 1).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
        self at:el + 1 put:byte.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    "/ time_mid bytes 5-6
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    5 to: 6 do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
        byte := utcTime digitAt:(length - el + 1).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
        self at:el put:byte.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    "/ time_high bytes 6-7 multiplexed with version
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    7 to: 8 do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
        byte := utcTime digitAt:(length - el + 1).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
        (el == 6) ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
            byte := byte bitOr:(self class uuidVersion bitShift:4).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
        ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
        self at:el put:byte.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    "/ clock_seq bytes 8-9 
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    uuidClockSeq := UUIDRandom getUuidRandom.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    9 to: 10 do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
        byte := uuidClockSeq digitAt:2 - el + 9.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
        self at:el put:byte.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    self genUUID.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    1 to: 100 do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
        Transcript show:el.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
        Transcript show:': '.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
        Transcript showCR:(UUID genUUID).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    "
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
getValidMACAdress
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    | macBytes dictOfIf |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    dictOfIf := OperatingSystem getNetworkMACAdresses.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    dictOfIf keysAndValuesDo:[ : key : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
        ((el value select:([:e | e ~= 0] )) notEmpty) ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
            macBytes := el value.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
            ^ macBytes
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
        ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    ^ nil
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
!UUID methodsFor:'printing'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
displayString
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    ^ self printString
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
printOn:aStream
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    |offs d byte|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    offs := 1.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    d := self unsignedLongAt:1 bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    offs := offs + 4.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    aStream nextPutAll:((d printStringRadix:16) asLowercase leftPaddedTo:8 with:$0).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    aStream nextPut:$-.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    2 timesRepeat:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
        d := self unsignedShortAt:offs bigEndian:false.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
        offs := offs + 2.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
        aStream nextPutAll:((d printStringRadix:16) asLowercase leftPaddedTo:4 with:$0).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
        aStream nextPut:$-.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    d := self unsignedShortAt:offs bigEndian:true.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    offs := offs + 2.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    aStream nextPutAll:((d printStringRadix:16) asLowercase leftPaddedTo:4 with:$0).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
    aStream nextPut:$-.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
    6 timesRepeat:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
        byte := self at:offs.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
        offs := offs + 1.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
        aStream nextPutAll:((byte printStringRadix:16) asLowercase leftPaddedTo:2 with:$0).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
!UUID::UTCTime class methodsFor:'constants'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
baseTimeDiff
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
 return the constant designation difference in Unix and DTSS base times in 100 nsec intervals
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
 DTSS UTC base time is October 15, 1582.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
 Unix base time is January 1, 1970.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
"
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
    ^ 16r01B21DD213814000
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
!UUID::UTCTime class methodsFor:'instance creation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
now
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
    | utcTime |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    utcTime := super now.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
    ^ utcTime getMilliseconds * 10000 + self baseTimeDiff.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
!UUID::UUIDRandom class methodsFor:'defaults'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
rand_ia_init
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
    ^ 11113
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
rand_ib_init
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    ^ 104322
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
rand_irand_init
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
    ^ 4181
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
rand_m_init
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
    ^ 971
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
!UUID::UUIDRandom class methodsFor:'instance creation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
getUuidRandom
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    | utcTime length seed retValue|
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
    rand_m isNil ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
        rand_m := self rand_m_init.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
    rand_ia isNil ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
        rand_ia := self rand_ia_init.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
    rand_ib isNil ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
        rand_ib := self rand_ib_init.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
    rand_irand isNil ifTrue:[
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
        rand_irand := self rand_irand_init.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
        utcTime := UUID::UTCTime now.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
        length := utcTime digitLength.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
        seed := 0.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
        1 to: length do:[ : el |
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
            seed := seed bitXor:(utcTime digitAt:el).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
        ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
        rand_irand := rand_irand + seed + OperatingSystem getProcessId.        
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    rand_m := rand_m + 7.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
    rand_ia := rand_ia + 1907.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    rand_ib := rand_ib + 73939.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
    (rand_m >= 9973) ifTrue:[ rand_m := rand_m - 9871 ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    (rand_ia >= 99991) ifTrue:[ rand_ia := rand_ia - 89989 ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
    (rand_ib >= 224729) ifTrue:[ rand_ib := rand_ib - 96233 ].
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
    rand_irand := (rand_irand * rand_m) + rand_ia + rand_ib.
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    retValue := ((rand_irand bitShift:-16) bitXor:(rand_irand bitAnd:16r3fff)).
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    ^ retValue
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
    
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
"/ self getUuidRandom
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
! !
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
!UUID class methodsFor:'documentation'!
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
version
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    ^ '$Header: /cvs/stx/stx/libbasic2/UUID.st,v 1.1 2003-04-28 12:09:08 cg Exp $'
58856b846271 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
! !