Merge lp:~zorba-coders/zorba/feature-uuid into lp:zorba
- feature-uuid
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Chris Hillery |
Approved revision: | 10990 |
Merged at revision: | 11014 |
Proposed branch: | lp:~zorba-coders/zorba/feature-uuid |
Merge into: | lp:zorba |
Diff against target: |
1159 lines (+458/-476) 20 files modified
CMakeCompiler.txt (+21/-0) CMakeLists.txt (+1/-0) ChangeLog (+1/-0) doc/zorba/build_prerequisites.dox (+1/-0) doc/zorba/build_ubuntu.dox (+1/-1) include/zorba/config.h.cmake (+1/-0) src/runtime/random/random_impl.cpp (+19/-11) src/store/naive/simple_store.cpp (+8/-4) src/store/naive/store.cpp (+0/-1) src/unit_tests/CMakeLists.txt (+1/-0) src/unit_tests/test_uuid.cpp (+42/-0) src/unit_tests/unit_test_list.h (+1/-0) src/unit_tests/unit_tests.cpp (+1/-0) src/util/CMakeLists.txt (+1/-2) src/util/uuid.cpp (+102/-0) src/util/uuid.h (+257/-0) src/util/uuid/sysdep.cpp (+0/-59) src/util/uuid/sysdep.h (+0/-57) src/util/uuid/uuid.cpp (+0/-297) src/util/uuid/uuid.h (+0/-44) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/feature-uuid |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Hillery | Approve | ||
Rodolfo Ochoa | Approve | ||
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+118268@code.launchpad.net |
Commit message
Replaced UUID with thin layer over native platform implementation.
Description of the change
Replaced UUID with thin layer over native platform implementation.
- 10978. By Paul J. Lucas
-
Removed unnecessary #include.
Paul J. Lucas (paul-lucas) : | # |
Paul J. Lucas (paul-lucas) wrote : | # |
Matthias Brantner (matthias-brantner) wrote : | # |
Doesn't build on 32-bit Ubuntu 11.04 with g++ 4.5.2.
[ 68%] Building CXX object src/CMakeFiles/
In file included from /home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
/home/mbrantner
- 10979. By Paul J. Lucas
-
Now using stdint.h
- 10980. By Paul J. Lucas
-
Merge from trunk.
Paul J. Lucas (paul-lucas) wrote : | # |
It should be fixed.
Matthias Brantner (matthias-brantner) : | # |
- 10981. By Paul J. Lucas
-
More comments.
Rodolfo Ochoa (rodolfo-ochoa) wrote : | # |
From Windows compiling I'm having:
Error 88 error C2440: '=' : cannot convert from 'u_long (__stdcall *)(u_long)' to 'uint32_t' C:\dev\
Error 89 error C2440: '=' : cannot convert from 'u_long (__stdcall *)(u_long)' to 'uint32_t' C:\dev\
Error 90 error C3861: 'ntohl': identifier not found C:\dev\
Error 178 error C3861: 'ntohl': identifier not found C:\dev\
Error 179 error C2440: 'initializing' : cannot convert from 'u_long (__stdcall *)(u_long)' to 'const uint32_t' C:\dev\
Error 180 error C3861: 'ntohs': identifier not found C:\dev\
Error 181 error C2440: 'initializing' : cannot convert from 'u_short (__stdcall *)(u_short)' to 'const uint16_t' C:\dev\
Error 182 error C3861: 'ntohs': identifier not found C:\dev\
Error 183 error C2440: 'initializing' : cannot convert from 'u_short (__stdcall *)(u_short)' to 'const uint16_t' C:\dev\
Paul J. Lucas (paul-lucas) wrote : | # |
Rodolfo: I don't understand why there are errors. I actually test compiled this under Windows using Windows 7 and Visual Studio 2010.
According to <http://
Any ideas?
- 10982. By Paul J. Lucas
-
Removed uuid.cpp dependency on ntohs() and ntohl().
- 10983. By Paul J. Lucas
-
Removed all ntohl() -- not really necessary.
Paul J. Lucas (paul-lucas) wrote : | # |
Actually, I just removed all the problematic code so it should compile on Windows. Please try again.
- 10984. By Paul J. Lucas
-
get_version() now properly returns "unknown" when unknown.
Rodolfo Ochoa (rodolfo-ochoa) wrote : | # |
Yep, that works!
- 10985. By Paul J. Lucas
-
Added comment.
Chris Hillery (ceejatec) wrote : | # |
My only concern is that for non-Apple, non-Windows platforms, you add -luuid to the link line, but there's no CMake stuff to search for a uuid library or to ensure that such an option will compile/link successfully. Is it a guarantee that it will always be available, at least on Linux?
Paul J. Lucas (paul-lucas) wrote : | # |
> My only concern is that for non-Apple, non-Windows platforms, you add -luuid
> to the link line, but there's no CMake stuff to search for a uuid library or
> to ensure that such an option will compile/link successfully. Is it a
> guarantee that it will always be available, at least on Linux?
Good catch. I don't suppose you could add the relevant CMake stuff to find libuuid?
- 10986. By Paul J. Lucas
-
Merge from trunk.
Chris Hillery (ceejatec) wrote : | # |
> Good catch. I don't suppose you could add the relevant CMake stuff to find
> libuuid?
1. Are the things you compile/link against on Windows and Mac guaranteed to exist? (ie, do I only need to find libuuid on Linux platforms)
2. What should happen if I *don't* find it? Can the UUID code be made optional at compile time? Would that mean we need a ZORBA_WITH_UUID or something like that? Or, do we have a hard requirement on libuuid and the build should fail without it?
It does appear that on Ubuntu, at least, libuuid comes from the package "libuuid1", which is part of the "minimal" Task and is depended on by some pretty low-level packages such as util-linux and e2fsprogs. It's not clear to me whether it's at all possible to have a functional Linux/Ubuntu system without libuuid existing. So maybe it's OK to assume it will always be there.
Paul J. Lucas (paul-lucas) wrote : | # |
> 1. Are the things you compile/link against on Windows and Mac guaranteed to
> exist? (ie, do I only need to find libuuid on Linux platforms)
Yes.
> 2. What should happen if I *don't* find it? Can the UUID code be made optional
> at compile time? Would that mean we need a ZORBA_WITH_UUID or something like
> that? Or, do we have a hard requirement on libuuid and the build should fail
> without it?
I think it has to be the latter, but Matthias might know.
Matthias Brantner (matthias-brantner) wrote : | # |
> > 1. Are the things you compile/link against on Windows and Mac guaranteed to
> > exist? (ie, do I only need to find libuuid on Linux platforms)
>
> Yes.
>
> > 2. What should happen if I *don't* find it? Can the UUID code be made
> optional
> > at compile time? Would that mean we need a ZORBA_WITH_UUID or something like
> > that? Or, do we have a hard requirement on libuuid and the build should fail
> > without it?
>
> I think it has to be the latter, but Matthias might know.
I think it should be a hard requirement. UUID functionality comes with Windows and Mac. On Linux, the library should always be available. Also, as far as I understood, we already depended on libuuid before.
Chris Hillery (ceejatec) wrote : | # |
> Also, as far as I understood, we already depended on libuuid before.
As far as I can tell, no, we didn't. But, if we should have a hard requirement, so be it. As I said, it looks like it's pretty much standard on Linux.
Paul J. Lucas (paul-lucas) wrote : | # |
> As far as I can tell, no, we didn't. But, if we should have a hard
> requirement, so be it. As I said, it looks like it's pretty much standard on
> Linux.
Chris: Can you therefore please add the CMake magic to test for libuuid when not on Mac/Windows? Thanks.
- 10987. By Chris Hillery
-
Make missing uuid.h on Linux a fatal error; check that -luuid works.
Chris Hillery (ceejatec) wrote : | # |
Turns out this is less standard than I thought. On my standard Ubuntu installation, I cannot compile this branch without installing the "uuid-dev" Ubuntu package, which is where uuid/uuid.h comes from.
I have added a bit of CMake stuff to check that -luuid works if ZORBA_HAVE_UUID_H is true. I also added a clause to make CMake configuration fail is ZORBA_HAVE_UUID_H is false, and you're not on Apple or Win32.
However, I'm a bit uneasy about adding a new hard requirement like this. At the very least, if we decide that this way of doing things is correct, we need to update the Linux build documentation to list the UUID development headers as a build requirement, and mention the uuid-dev on the Ubuntu build page. I won't have time to do that this week due to NoSQL Now, so Paul, please take a crack at it (assuming we decide that it is going to be a new requirement).
- 10988. By Paul J. Lucas
-
Merge from trunk.
- 10989. By Paul J. Lucas
-
Added mention of libUUID to documentation.
Paul J. Lucas (paul-lucas) wrote : | # |
I added a mention to the build documentation. Approve now?
- 10990. By Paul J. Lucas
-
Merge from trunk.
Chris Hillery (ceejatec) wrote : | # |
I still don't love the additional dependency, but I think it probably makes sense not to roll our own UUID libs, so I'll approve this. I wonder if the RQ machine will have it?...
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job feature-
All tests succeeded!
Preview Diff
1 | === modified file 'CMakeCompiler.txt' |
2 | --- CMakeCompiler.txt 2012-08-30 13:45:43 +0000 |
3 | +++ CMakeCompiler.txt 2012-08-30 23:54:18 +0000 |
4 | @@ -241,3 +241,24 @@ |
5 | ENDIF (NOT CMAKE_C_FLAGS MATCHES "-fvisibility") |
6 | ENDIF ( ZORBA_GNUCOMPILER_MAJOR_VERSION GREATER 3 ) |
7 | ENDIF(CMAKE_COMPILER_IS_GNUCC) |
8 | + |
9 | +IF (APPLE) |
10 | + # Needed for CFUUID*() functions in util/uuid.c. |
11 | + SET(CMAKE_SHARED_LINKER_FLAGS "-framework CoreFoundation ${CMAKE_SHARED_LINKER_FLAGS}") |
12 | +ELSEIF (WIN32) |
13 | + # Needed for UuidCreateSequential() function in util/uuid.c. |
14 | + SET(requiredlibs ${requiredlibs} "Rpcrt4") |
15 | +ELSEIF (ZORBA_HAVE_UUID_H) |
16 | + # Needed for uuid_generate() function in util/uuid.c. |
17 | + SET(CMAKE_SHARED_LINKER_FLAGS "-luuid ${CMAKE_SHARED_LINKER_FLAGS}") |
18 | + # Double-check that we can link against the required library. |
19 | + CHECK_LIBRARY_EXISTS(uuid uuid_generate "" LIBUUID_EXISTS) |
20 | + IF (NOT LIBUUID_EXISTS) |
21 | + MESSAGE (FATAL_ERROR "Could not find libuuid - required on Linux!") |
22 | + ENDIF (NOT LIBUUID_EXISTS) |
23 | +ELSE (APPLE) |
24 | + # We're not Apple or Win32, and we didn't find uuid.h - can't compile |
25 | + MESSAGE (FATAL_ERROR "Could not find uuid/uuid.h header, which is " |
26 | + "required on Linux. On Ubuntu, the 'uuid-dev' package is required; " |
27 | + "look for similar packages on other platforms.") |
28 | +ENDIF (APPLE) |
29 | |
30 | === modified file 'CMakeLists.txt' |
31 | --- CMakeLists.txt 2012-08-30 13:45:43 +0000 |
32 | +++ CMakeLists.txt 2012-08-30 23:54:18 +0000 |
33 | @@ -101,6 +101,7 @@ |
34 | CHECK_INCLUDE_FILES ("execinfo.h" ZORBA_HAVE_EXECINFO_H) |
35 | ENDIF (NOT APPLE OR ${CMAKE_SYSTEM_VERSION} VERSION_GREATER "10.4") |
36 | CHECK_INCLUDE_FILE_CXX ("FlexLexer.h" ZORBA_HAVE_FLEXLEXER_H) |
37 | +CHECK_INCLUDE_FILES ("uuid/uuid.h" ZORBA_HAVE_UUID_H) |
38 | |
39 | CHECK_FUNCTION_EXISTS (strtof ZORBA_HAVE_STRTOF_FUNCTION) |
40 | CHECK_FUNCTION_EXISTS (strtoll ZORBA_HAVE_STRTOLL_FUNCTION) |
41 | |
42 | === modified file 'ChangeLog' |
43 | --- ChangeLog 2012-08-30 15:14:16 +0000 |
44 | +++ ChangeLog 2012-08-30 23:54:18 +0000 |
45 | @@ -16,6 +16,7 @@ |
46 | * Fixed bugs #899364 and 899363 (throw XQST0103 in case of non-distinct window |
47 | variables) |
48 | * Fixed bug #899366 (enforce the type declaration of a window variable) |
49 | + * Now using native UUID libraries. |
50 | * Fixed bug #1024892 (index declaration references udf declared after the index) |
51 | * Fixed bug #1038410 (Memory leaks in parser, trace iterator, and general index) |
52 | * Fixed bug #1039488 (inserting more than one pair at once in a JSON object) |
53 | |
54 | === modified file 'doc/zorba/build_prerequisites.dox' |
55 | --- doc/zorba/build_prerequisites.dox 2012-05-02 10:40:42 +0000 |
56 | +++ doc/zorba/build_prerequisites.dox 2012-08-30 23:54:18 +0000 |
57 | @@ -33,6 +33,7 @@ |
58 | |
59 | - Libxml2 2.2.16 or later (http://xmlsoft.org/) |
60 | - Iconv 1.12 (used by Libxml2; http://www.gnu.org/software/libiconv/) |
61 | +- libUUID (non-Mac, non-Windows only; http://linux.die.net/man/3/libuuid) |
62 | |
63 | \subsection recommended_core_zorba Recommended for Core Zorba |
64 | |
65 | |
66 | === modified file 'doc/zorba/build_ubuntu.dox' |
67 | --- doc/zorba/build_ubuntu.dox 2012-08-30 13:45:43 +0000 |
68 | +++ doc/zorba/build_ubuntu.dox 2012-08-30 23:54:18 +0000 |
69 | @@ -24,7 +24,7 @@ |
70 | \subsection ubuntu_libs Core Zorba Library Dependencies |
71 | Required libraries for core Zorba: |
72 | \code |
73 | -sudo apt-get install libxml2-dev |
74 | +sudo apt-get install libxml2-dev uuid-dev |
75 | \endcode |
76 | |
77 | Recommended libraries for core Zorba: |
78 | |
79 | === modified file 'include/zorba/config.h.cmake' |
80 | --- include/zorba/config.h.cmake 2012-08-30 13:45:43 +0000 |
81 | +++ include/zorba/config.h.cmake 2012-08-30 23:54:18 +0000 |
82 | @@ -52,6 +52,7 @@ |
83 | #cmakedefine ZORBA_HAVE_SYS_TYPES_H |
84 | #cmakedefine ZORBA_HAVE_USTRING_H |
85 | #cmakedefine ZORBA_HAVE_UTYPES_H |
86 | +#cmakedefine ZORBA_HAVE_UUID_H |
87 | |
88 | // Platform functions |
89 | #cmakedefine ZORBA_HAVE_CLOCKGETTIME_FUNCTION |
90 | |
91 | === modified file 'src/runtime/random/random_impl.cpp' |
92 | --- src/runtime/random/random_impl.cpp 2012-08-30 13:45:43 +0000 |
93 | +++ src/runtime/random/random_impl.cpp 2012-08-30 23:54:18 +0000 |
94 | @@ -15,6 +15,8 @@ |
95 | */ |
96 | #include "stdafx.h" |
97 | |
98 | +#include <sstream> |
99 | + |
100 | #include "system/globalenv.h" |
101 | |
102 | #include "runtime/random/random.h" |
103 | @@ -27,7 +29,7 @@ |
104 | #include <zorba/util/time.h> |
105 | #include <limits> |
106 | |
107 | -#include "util/uuid/uuid.h" |
108 | +#include "util/uuid.h" |
109 | |
110 | namespace zorba { |
111 | |
112 | @@ -104,6 +106,7 @@ |
113 | store::Item_t num; |
114 | unsigned int int_seed; |
115 | long walltime_millis; |
116 | + uint32_t time_low; |
117 | zstring ltmp; |
118 | |
119 | RandomIteratorState* state; |
120 | @@ -125,11 +128,16 @@ |
121 | time::get_current_walltime( lCurrWallTime ); |
122 | walltime_millis = time::get_walltime_in_millis( lCurrWallTime ); |
123 | |
124 | - uuid_t u; |
125 | - memset(&u, 0, sizeof(uuid_t)); |
126 | - uuid_create(&u); |
127 | - |
128 | - walltime_millis += u.time_low; |
129 | + uuid u; |
130 | + uuid::create(&u); |
131 | + // |
132 | + // Note that the time_low field as extracted here is always big-endian even |
133 | + // on a little-endian CPU, but it doesn't really matter since it's only |
134 | + // being used as a fancy random-number generator seed. |
135 | + // |
136 | + time_low = |
137 | + (u.data[0] << 24) | (u.data[1] << 16) | (u.data[2] << 8) | u.data[3]; |
138 | + walltime_millis += time_low; |
139 | |
140 | int_seed = walltime_millis % std::numeric_limits<unsigned int>::max(); |
141 | |
142 | @@ -151,16 +159,16 @@ |
143 | UuidIterator::nextImpl(store::Item_t& result, PlanState& planState) const |
144 | { |
145 | store::Item_t item; |
146 | - uuid_t u; |
147 | + uuid u; |
148 | zstring uuidStr; |
149 | + std::ostringstream oss; |
150 | |
151 | PlanIteratorState* state; |
152 | DEFAULT_STACK_INIT(PlanIteratorState, state, planState); |
153 | |
154 | - memset(&u, 0, sizeof(uuid_t)); |
155 | - |
156 | - uuid_create(&u); |
157 | - uuidStr = uuidToString(u); |
158 | + uuid::create(&u); |
159 | + oss << u; |
160 | + uuidStr = oss.str(); |
161 | |
162 | GENV_ITEMFACTORY->createString(result, uuidStr); |
163 | STACK_PUSH(true, state); |
164 | |
165 | === modified file 'src/store/naive/simple_store.cpp' |
166 | --- src/store/naive/simple_store.cpp 2012-08-30 13:45:43 +0000 |
167 | +++ src/store/naive/simple_store.cpp 2012-08-30 23:54:18 +0000 |
168 | @@ -15,6 +15,8 @@ |
169 | */ |
170 | #include "stdafx.h" |
171 | |
172 | +#include <sstream> |
173 | + |
174 | #include "simple_store.h" |
175 | #include "store_defs.h" |
176 | |
177 | @@ -30,7 +32,7 @@ |
178 | #include "diagnostics/diagnostic.h" |
179 | #include <zorba/diagnostic_list.h> |
180 | |
181 | -#include "util/uuid/uuid.h" |
182 | +#include "util/uuid.h" |
183 | #include "zorbautils/string_util.h" |
184 | |
185 | #ifdef ZORBA_WITH_JSON |
186 | @@ -288,9 +290,11 @@ |
187 | return theItemFactory->createAnyURI(result, id); |
188 | } |
189 | |
190 | - uuid_t uuid; |
191 | - uuid_create(&uuid); |
192 | - zstring uuidStr = uuidToURI(uuid); |
193 | + uuid u; |
194 | + uuid::create(&u); |
195 | + std::ostringstream oss; |
196 | + oss << "urn:uuid:" << u; |
197 | + zstring uuidStr = oss.str(); |
198 | |
199 | assignReference(xmlNode, uuidStr); |
200 | |
201 | |
202 | === modified file 'src/store/naive/store.cpp' |
203 | --- src/store/naive/store.cpp 2012-08-30 13:45:43 +0000 |
204 | +++ src/store/naive/store.cpp 2012-08-30 23:54:18 +0000 |
205 | @@ -58,7 +58,6 @@ |
206 | #include "tree_id_generator.h" |
207 | |
208 | #include "util/cxx_util.h" |
209 | -#include "util/uuid/uuid.h" |
210 | #include "zorbautils/string_util.h" |
211 | |
212 | #ifndef ZORBA_NO_FULL_TEXT |
213 | |
214 | === modified file 'src/unit_tests/CMakeLists.txt' |
215 | --- src/unit_tests/CMakeLists.txt 2012-08-30 13:45:43 +0000 |
216 | +++ src/unit_tests/CMakeLists.txt 2012-08-30 23:54:18 +0000 |
217 | @@ -20,6 +20,7 @@ |
218 | test_json_parser.cpp |
219 | test_string.cpp |
220 | test_uri.cpp |
221 | + test_uuid.cpp |
222 | unit_tests.cpp |
223 | test_uri.cpp |
224 | test_json_parser.cpp |
225 | |
226 | === added file 'src/unit_tests/test_uuid.cpp' |
227 | --- src/unit_tests/test_uuid.cpp 1970-01-01 00:00:00 +0000 |
228 | +++ src/unit_tests/test_uuid.cpp 2012-08-30 23:54:18 +0000 |
229 | @@ -0,0 +1,42 @@ |
230 | +/* |
231 | + * Copyright 2006-2010 The FLWOR Foundation. |
232 | + * |
233 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
234 | + * you may not use this file except in compliance with the License. |
235 | + * You may obtain a copy of the License at |
236 | + * |
237 | + * http://www.apache.org/licenses/LICENSE-2.0 |
238 | + * |
239 | + * Unless required by applicable law or agreed to in writing, software |
240 | + * distributed under the License is distributed on an "AS IS" BASIS, |
241 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
242 | + * See the License for the specific language governing permissions and |
243 | + * limitations under the License. |
244 | + */ |
245 | + |
246 | +#include "stdafx.h" |
247 | +#include <iostream> |
248 | + |
249 | +#include "util/uuid.h" |
250 | + |
251 | +using namespace std; |
252 | +using namespace zorba; |
253 | + |
254 | +/////////////////////////////////////////////////////////////////////////////// |
255 | + |
256 | +/////////////////////////////////////////////////////////////////////////////// |
257 | + |
258 | +namespace zorba { |
259 | +namespace UnitTests { |
260 | + |
261 | +int test_uuid( int argc, char *argv[] ) { |
262 | + uuid u; |
263 | + uuid::create( &u ); |
264 | + cout << u << endl; |
265 | + return 0; |
266 | +} |
267 | + |
268 | +} // namespace UnitTests |
269 | +} // namespace zorba |
270 | + |
271 | +/* vim:set et sw=2 ts=2: */ |
272 | |
273 | === modified file 'src/unit_tests/unit_test_list.h' |
274 | --- src/unit_tests/unit_test_list.h 2012-08-30 13:45:43 +0000 |
275 | +++ src/unit_tests/unit_test_list.h 2012-08-30 23:54:18 +0000 |
276 | @@ -45,6 +45,7 @@ |
277 | #ifndef ZORBA_HAVE_UNIQUE_PTR |
278 | int test_unique_ptr( int, char*[] ); |
279 | #endif /* ZORBA_HAVE_UNIQUE_PTR */ |
280 | + int test_uuid( int, char*[] ); |
281 | #ifndef ZORBA_HAVE_UNORDERED_MAP |
282 | int test_unordered_map( int, char*[] ); |
283 | #endif /* ZORBA_HAVE_UNORDERED_MAP */ |
284 | |
285 | === modified file 'src/unit_tests/unit_tests.cpp' |
286 | --- src/unit_tests/unit_tests.cpp 2012-08-30 13:45:43 +0000 |
287 | +++ src/unit_tests/unit_tests.cpp 2012-08-30 23:54:18 +0000 |
288 | @@ -54,6 +54,7 @@ |
289 | #ifndef ZORBA_HAVE_UNIQUE_PTR |
290 | libunittests["unique_ptr"] = test_unique_ptr; |
291 | #endif /* ZORBA_HAVE_UNIQUE_PTR */ |
292 | + libunittests["uuid"] = test_uuid; |
293 | #ifndef ZORBA_HAVE_UNORDERED_MAP |
294 | libunittests["unordered_map"] = test_unordered_map; |
295 | #endif /* ZORBA_HAVE_UNORDERED_MAP */ |
296 | |
297 | === modified file 'src/util/CMakeLists.txt' |
298 | --- src/util/CMakeLists.txt 2012-08-30 13:45:43 +0000 |
299 | +++ src/util/CMakeLists.txt 2012-08-30 23:54:18 +0000 |
300 | @@ -29,11 +29,10 @@ |
301 | unicode_categories.cpp |
302 | uri_util.cpp |
303 | utf8_util.cpp |
304 | + uuid.cpp |
305 | xml_util.cpp |
306 | fx/fxcharheap.cpp |
307 | string/empty_rep_base.cpp |
308 | - uuid/sysdep.cpp |
309 | - uuid/uuid.cpp |
310 | http_util.h |
311 | http_util.cpp) |
312 | |
313 | |
314 | === removed directory 'src/util/uuid' |
315 | === added file 'src/util/uuid.cpp' |
316 | --- src/util/uuid.cpp 1970-01-01 00:00:00 +0000 |
317 | +++ src/util/uuid.cpp 2012-08-30 23:54:18 +0000 |
318 | @@ -0,0 +1,102 @@ |
319 | +/* |
320 | + * Copyright 2006-2008 The FLWOR Foundation. |
321 | + * |
322 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
323 | + * you may not use this file except in compliance with the License. |
324 | + * You may obtain a copy of the License at |
325 | + * |
326 | + * http://www.apache.org/licenses/LICENSE-2.0 |
327 | + * |
328 | + * Unless required by applicable law or agreed to in writing, software |
329 | + * distributed under the License is distributed on an "AS IS" BASIS, |
330 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
331 | + * See the License for the specific language governing permissions and |
332 | + * limitations under the License. |
333 | + */ |
334 | + |
335 | +#include <zorba/config.h> |
336 | + |
337 | +#include <cstdio> /* for sprintf(3) */ |
338 | + |
339 | +#if defined( __APPLE__ ) |
340 | +# include <cstring> /* for memcpy(3) */ |
341 | +# include <CoreFoundation/CoreFoundation.h> |
342 | +#elif defined( ZORBA_HAVE_UUID_H ) |
343 | +# include <uuid/uuid.h> |
344 | +#elif defined( _WIN32 ) |
345 | +# include <Rpc.h> |
346 | +#else |
347 | +# error "Unsupported operating system for generating UUIDs" |
348 | +#endif |
349 | + |
350 | +#include "uuid.h" |
351 | + |
352 | +using namespace std; |
353 | + |
354 | +namespace zorba { |
355 | + |
356 | +/////////////////////////////////////////////////////////////////////////////// |
357 | + |
358 | +void uuid::create( uuid *result ) { |
359 | +#if defined( __APPLE__ ) |
360 | + CFUUIDRef uuid_ref = CFUUIDCreate( NULL ); |
361 | + CFUUIDBytes uuid_bytes = CFUUIDGetUUIDBytes( uuid_ref ); |
362 | + CFRelease( uuid_ref ); |
363 | + ::memcpy( result->data, &uuid_bytes, sizeof result->data ); |
364 | +#elif defined( ZORBA_HAVE_UUID_H ) |
365 | + uuid_generate( result->data ); |
366 | +#elif defined( _WIN32 ) |
367 | + UuidCreateSequential( (UUID*)result->data ); |
368 | +#endif /* _WIN32 */ |
369 | +} |
370 | + |
371 | +uuid::variant uuid::get_variant() const { |
372 | + value_type const octet8 = data[8]; |
373 | + if ( (octet8 & 0x80u) == 0x00u ) |
374 | + return ncs; |
375 | + if ( (octet8 & 0xC0u) == 0x80u ) |
376 | + return rfc4122; |
377 | + if ( (octet8 & 0xE0u) == 0xC0u ) |
378 | + return microsoft; |
379 | + return future; |
380 | +} |
381 | + |
382 | +uuid::version uuid::get_version() const { |
383 | + value_type const temp = data[6] & 0xF0u; |
384 | + switch ( temp ) { |
385 | + case time_based: |
386 | + case dce_security: |
387 | + case name_based_md5: |
388 | + case random_number_based: |
389 | + case name_based_sha1: |
390 | + return static_cast<version>( temp ); |
391 | + default: |
392 | + return unknown; |
393 | + } |
394 | +} |
395 | + |
396 | +/////////////////////////////////////////////////////////////////////////////// |
397 | + |
398 | +ostream& operator<<( ostream &os, uuid const &u ) { |
399 | + char buf[37]; |
400 | + sprintf( // verbose & tedious, but fast |
401 | + buf, |
402 | + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
403 | + u.data[ 0], u.data[ 1], u.data[ 2], u.data[ 3], |
404 | + u.data[ 4], u.data[ 5], u.data[ 6], u.data[ 7], |
405 | + u.data[ 8], u.data[ 9], u.data[10], u.data[11], |
406 | + u.data[12], u.data[13], u.data[14], u.data[15] |
407 | + ); |
408 | + return os << buf; |
409 | +} |
410 | + |
411 | +/////////////////////////////////////////////////////////////////////////////// |
412 | + |
413 | +} // namespace zorba |
414 | + |
415 | +/* |
416 | + * Local variables: |
417 | + * mode: c++ |
418 | + * End: |
419 | + */ |
420 | +/* vim:set et sw=2 ts=2: */ |
421 | |
422 | === added file 'src/util/uuid.h' |
423 | --- src/util/uuid.h 1970-01-01 00:00:00 +0000 |
424 | +++ src/util/uuid.h 2012-08-30 23:54:18 +0000 |
425 | @@ -0,0 +1,257 @@ |
426 | +/* |
427 | + * Copyright 2006-2008 The FLWOR Foundation. |
428 | + * |
429 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
430 | + * you may not use this file except in compliance with the License. |
431 | + * You may obtain a copy of the License at |
432 | + * |
433 | + * http://www.apache.org/licenses/LICENSE-2.0 |
434 | + * |
435 | + * Unless required by applicable law or agreed to in writing, software |
436 | + * distributed under the License is distributed on an "AS IS" BASIS, |
437 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
438 | + * See the License for the specific language governing permissions and |
439 | + * limitations under the License. |
440 | + */ |
441 | + |
442 | +#pragma once |
443 | +#ifndef ZORBA_UUID_H |
444 | +#define ZORBA_UUID_H |
445 | + |
446 | +#include <algorithm> |
447 | +#include <iostream> |
448 | + |
449 | +#include "zorbamisc/config/stdint.h" |
450 | + |
451 | +namespace zorba { |
452 | + |
453 | +/////////////////////////////////////////////////////////////////////////////// |
454 | + |
455 | +/** |
456 | + * A %uuid contains the raw bytes for a UUID. Note that this is intentially a |
457 | + * \c struct with no constructors, no destructor, and no user-defined |
458 | + * assignment operators so that it remains a POD. |
459 | + * |
460 | + * See also: |
461 | + * - RFC 4122: A Universally Unique IDentifier (UUID) URN Namespace. |
462 | + * - http://en.wikipedia.org/wiki/Universally_unique_identifier |
463 | + * |
464 | + * The UUID data is stored as an array of 16 8-bit bytes comprising the 128 |
465 | + * bits that is a UUID. The data is intentionally \e not stored as shown in |
466 | + * "Appendix A - Sample Implementation" of RFC 4122 (the \c struct with |
467 | + * individial fields such as \c time_low, \c time_mid, etc.) since C++ does not |
468 | + * guarantee that the \c struct fields will be laid out in memory as shown in |
469 | + * section "4.1.2. Layout and Byte Order" due to possible padding. |
470 | + */ |
471 | +struct uuid { |
472 | + typedef uint8_t value_type; |
473 | + typedef value_type& reference; |
474 | + typedef value_type const& const_reference; |
475 | + typedef value_type* pointer; |
476 | + typedef value_type const* const_pointer; |
477 | + typedef std::size_t size_type; |
478 | + typedef std::ptrdiff_t difference_type; |
479 | + |
480 | + typedef pointer iterator; |
481 | + typedef const_pointer const_iterator; |
482 | + |
483 | + enum variant { |
484 | + ncs, ///< NCS backward compatibility |
485 | + rfc4122, ///< RFC 4122 |
486 | + microsoft, ///< Microsoft compatibility |
487 | + future ///< Reserved for future use |
488 | + }; |
489 | + |
490 | + enum version { |
491 | + unknown, |
492 | + time_based = 0x10, |
493 | + dce_security = 0x20, |
494 | + name_based_md5 = 0x30, |
495 | + random_number_based = 0x40, |
496 | + name_based_sha1 = 0x50 |
497 | + }; |
498 | + |
499 | + /** |
500 | + * The raw UUID data. |
501 | + */ |
502 | + value_type data[16]; |
503 | + |
504 | + /** |
505 | + * Creates a UUID. The variant and version of the UUID created is |
506 | + * platform-dependent. |
507 | + * |
508 | + * @param result A pointer to the result. |
509 | + */ |
510 | + static void create( uuid *result ); |
511 | + |
512 | + /** |
513 | + * Creates an iterator to the beginning of the data. |
514 | + * |
515 | + * @return Returns said iterator. |
516 | + */ |
517 | + iterator begin() { |
518 | + return data; |
519 | + } |
520 | + |
521 | + /** |
522 | + * Creates a const_iterator to the beginning of the data. |
523 | + * |
524 | + * @return Returns said iterator. |
525 | + */ |
526 | + const_iterator begin() const { |
527 | + return data; |
528 | + } |
529 | + |
530 | + /** |
531 | + * Creates an iterator to one past the end of the data. |
532 | + * |
533 | + * @return Returns said iterator. |
534 | + */ |
535 | + iterator end() { |
536 | + return data + size(); |
537 | + } |
538 | + |
539 | + /** |
540 | + * Creates a const_iterator to one past the end of the data. |
541 | + * |
542 | + * @return Returns said iterator. |
543 | + */ |
544 | + const_iterator end() const { |
545 | + return data + size(); |
546 | + } |
547 | + |
548 | + /** |
549 | + * Gets the size of the UUID data. |
550 | + * |
551 | + * @return Always returns 16. |
552 | + */ |
553 | + size_type size() const { |
554 | + return sizeof( data ); |
555 | + } |
556 | + |
557 | + /** |
558 | + * Swaps this UUID's data with that of another. |
559 | + * |
560 | + * @param that The other UUID to swap data with. |
561 | + */ |
562 | + void swap( uuid &that ) { |
563 | + std::swap_ranges( begin(), end(), that.begin() ); |
564 | + } |
565 | + |
566 | + /** |
567 | + * Gets the variant of this UUID. |
568 | + * |
569 | + * @return Returns said variant. |
570 | + */ |
571 | + variant get_variant() const; |
572 | + |
573 | + /** |
574 | + * Gets the version of this UUID. |
575 | + * |
576 | + * @return Returns said version. |
577 | + */ |
578 | + version get_version() const; |
579 | +}; |
580 | + |
581 | +////////// Functions ////////////////////////////////////////////////////////// |
582 | + |
583 | +/** |
584 | + * Swaps two UUIDs' data. |
585 | + * |
586 | + * @param u1 The first UUID. |
587 | + * @param u2 The second UUID. |
588 | + */ |
589 | +inline void swap( uuid &u1, uuid &u2 ) { |
590 | + u1.swap( u2 ); |
591 | +} |
592 | + |
593 | +/** |
594 | + * Compares two UUIDs for equality. |
595 | + * |
596 | + * @param u1 The first UUID. |
597 | + * @param u2 The second UUID. |
598 | + * @return Returns \c true only if the two UUIDs are equal. |
599 | + */ |
600 | +inline bool operator==( uuid const &u1, uuid const &u2 ) { |
601 | + return std::equal( u1.begin(), u1.end(), u2.begin() ); |
602 | +} |
603 | + |
604 | +/** |
605 | + * Compares two UUIDs for inequality. |
606 | + * |
607 | + * @param u1 The first UUID. |
608 | + * @param u2 The second UUID. |
609 | + * @return Returns \c true only if the two UUIDs are not equal. |
610 | + */ |
611 | +inline bool operator!=( uuid const &u1, uuid const &u2 ) { |
612 | + return !(u1 == u2); |
613 | +} |
614 | + |
615 | +/** |
616 | + * Compares two UUIDs for less-than. |
617 | + * |
618 | + * @param u1 The first UUID. |
619 | + * @param u2 The second UUID. |
620 | + * @return Returns \c true only if the first UUID is less than the second. |
621 | + */ |
622 | +inline bool operator<( uuid const &u1, uuid const &u2 ) { |
623 | + return std::lexicographical_compare( |
624 | + u1.begin(), u1.end(), u2.begin(), u2.end() |
625 | + ); |
626 | +} |
627 | + |
628 | +/** |
629 | + * Compares two UUIDs for less-than-or-equal-to. |
630 | + * |
631 | + * @param u1 The first UUID. |
632 | + * @param u2 The second UUID. |
633 | + * @return Returns \c true only if the first UUID is less than or equal to the |
634 | + * second. |
635 | + */ |
636 | +inline bool operator<=( uuid const &u1, uuid const &u2 ) { |
637 | + return !(u2 < u1); |
638 | +} |
639 | + |
640 | +/** |
641 | + * Compares two UUIDs for greater-than. |
642 | + * |
643 | + * @param u1 The first UUID. |
644 | + * @param u2 The second UUID. |
645 | + * @return Returns \c true only if the first UUID is greater than the second. |
646 | + */ |
647 | +inline bool operator>( uuid const &u1, uuid const &u2 ) { |
648 | + return u2 < u1; |
649 | +} |
650 | + |
651 | +/** |
652 | + * Compares two UUIDs for greater-than-or-equal-to. |
653 | + * |
654 | + * @param u1 The first UUID. |
655 | + * @param u2 The second UUID. |
656 | + * @return Returns \c true only if the first UUID is greater than or equal to |
657 | + * the second. |
658 | + */ |
659 | +inline bool operator>=( uuid const &u1, uuid const &u2 ) { |
660 | + return !(u1 < u2); |
661 | +} |
662 | + |
663 | +/** |
664 | + * Emits the given UUID to the given ostream in canonical UUID format. |
665 | + * |
666 | + * @param os The ostream to emit to. |
667 | + * @param u The UUID to emit. |
668 | + * @return Returns \a os. |
669 | + */ |
670 | +std::ostream& operator<<( std::ostream &os, uuid const &u ); |
671 | + |
672 | +/////////////////////////////////////////////////////////////////////////////// |
673 | + |
674 | +} // namespace zorba |
675 | + |
676 | +#endif /* ZORBA_UUID_H */ |
677 | +/* |
678 | + * Local variables: |
679 | + * mode: c++ |
680 | + * End: |
681 | + */ |
682 | +/* vim:set et sw=2 ts=2: */ |
683 | |
684 | === removed file 'src/util/uuid/sysdep.cpp' |
685 | --- src/util/uuid/sysdep.cpp 2012-08-30 13:45:43 +0000 |
686 | +++ src/util/uuid/sysdep.cpp 1970-01-01 00:00:00 +0000 |
687 | @@ -1,59 +0,0 @@ |
688 | -/* |
689 | - * Copyright 2006-2008 The FLWOR Foundation. |
690 | - * |
691 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
692 | - * you may not use this file except in compliance with the License. |
693 | - * You may obtain a copy of the License at |
694 | - * |
695 | - * http://www.apache.org/licenses/LICENSE-2.0 |
696 | - * |
697 | - * Unless required by applicable law or agreed to in writing, software |
698 | - * distributed under the License is distributed on an "AS IS" BASIS, |
699 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
700 | - * See the License for the specific language governing permissions and |
701 | - * limitations under the License. |
702 | - */ |
703 | -#include "stdafx.h" |
704 | - |
705 | -#include "sysdep.h" |
706 | - |
707 | -namespace zorba { |
708 | -/* system dependent call to get the current system time. Returned as |
709 | - 100ns ticks since UUID epoch, but resolution may be less than |
710 | - 100ns. */ |
711 | -#ifdef WIN32 |
712 | - |
713 | -void get_system_time(xs_unsignedLong *uuid_time) |
714 | -{ |
715 | - ULARGE_INTEGER time; |
716 | - |
717 | - /* NT keeps time in FILETIME format which is 100ns ticks since |
718 | - Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582. |
719 | - The difference is 17 Days in Oct + 30 (Nov) + 31 (Dec) |
720 | - + 18 years and 5 leap days, meaning P6653D*/ |
721 | - GetSystemTimeAsFileTime((FILETIME *)&time); |
722 | - time.QuadPart += (xs_unsignedLong) (1000*1000*10) // seconds |
723 | - * (xs_unsignedLong) (60 * 60 * 24) // days |
724 | - * (xs_unsignedLong) (17+30+31+365*18+5); // 6653 of days |
725 | - *uuid_time = time.QuadPart; |
726 | -} |
727 | - |
728 | -#else |
729 | - |
730 | -void get_system_time(xs_unsignedLong *uuid_time) |
731 | -{ |
732 | - struct timeval tp; |
733 | - |
734 | - gettimeofday(&tp, (struct timezone *)0); |
735 | - |
736 | - /* Offset between UUID formatted times and Unix formatted times. |
737 | - UUID UTC base time is October 15, 1582. |
738 | - Unix base time is January 1, 1970, meaning P141427D*/ |
739 | - *uuid_time = ((xs_unsignedLong)tp.tv_sec * 10000000) |
740 | - + ((xs_unsignedLong)tp.tv_usec * 10) |
741 | - + I64(0x01B21DD213814000); |
742 | -} |
743 | - |
744 | -#endif |
745 | -}/*namespace zorba*/ |
746 | -/* vim:set et sw=2 ts=2: */ |
747 | |
748 | === removed file 'src/util/uuid/sysdep.h' |
749 | --- src/util/uuid/sysdep.h 2012-08-30 13:45:43 +0000 |
750 | +++ src/util/uuid/sysdep.h 1970-01-01 00:00:00 +0000 |
751 | @@ -1,57 +0,0 @@ |
752 | -/* |
753 | - * Copyright 2006-2008 The FLWOR Foundation. |
754 | - * |
755 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
756 | - * you may not use this file except in compliance with the License. |
757 | - * You may obtain a copy of the License at |
758 | - * |
759 | - * http://www.apache.org/licenses/LICENSE-2.0 |
760 | - * |
761 | - * Unless required by applicable law or agreed to in writing, software |
762 | - * distributed under the License is distributed on an "AS IS" BASIS, |
763 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
764 | - * See the License for the specific language governing permissions and |
765 | - * limitations under the License. |
766 | - */ |
767 | - |
768 | -#ifndef ZORBA_UTIL_UUID_SYSDEP_H |
769 | -#define ZORBA_UTIL_UUID_SYSDEP_H |
770 | - |
771 | -#include "zorbatypes/schema_types.h" |
772 | - |
773 | -#ifdef WIN32 |
774 | - #include <windows.h> |
775 | -#else |
776 | - #include <sys/types.h> |
777 | - #include <sys/time.h> |
778 | -#endif |
779 | - |
780 | -/* Set the following to a calls to get and release a global lock */ |
781 | -#define LOCK |
782 | -#define UNLOCK |
783 | - |
784 | -// /* Set this to what your compiler uses for 64-bit data type */ |
785 | -#ifdef WIN32 |
786 | - #define unsigned64_t unsigned __int64 |
787 | - #define I64(C) C |
788 | -#else |
789 | - #define unsigned64_t unsigned long long |
790 | - #define I64(C) C##LL |
791 | -#endif |
792 | - |
793 | -namespace zorba { |
794 | - |
795 | -/* set the following to the number of 100ns ticks of the actual |
796 | -resolution of your system's clock */ |
797 | -#define UUIDS_PER_TICK 1024 |
798 | - |
799 | -typedef struct { |
800 | - char nodeID[6]; |
801 | -} uuid_node_t; |
802 | - |
803 | -void get_system_time(xs_unsignedLong *uuid_time); |
804 | - |
805 | -}/*namespace zorba*/ |
806 | - |
807 | -#endif /* ZORBA_UTIL_UUID_SYSDEP_H */ |
808 | -/* vim:set et sw=2 ts=2: */ |
809 | |
810 | === removed file 'src/util/uuid/uuid.cpp' |
811 | --- src/util/uuid/uuid.cpp 2012-08-30 13:45:43 +0000 |
812 | +++ src/util/uuid/uuid.cpp 1970-01-01 00:00:00 +0000 |
813 | @@ -1,297 +0,0 @@ |
814 | -/* |
815 | - * Copyright 2006-2008 The FLWOR Foundation. |
816 | - * |
817 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
818 | - * you may not use this file except in compliance with the License. |
819 | - * You may obtain a copy of the License at |
820 | - * |
821 | - * http://www.apache.org/licenses/LICENSE-2.0 |
822 | - * |
823 | - * Unless required by applicable law or agreed to in writing, software |
824 | - * distributed under the License is distributed on an "AS IS" BASIS, |
825 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
826 | - * See the License for the specific language governing permissions and |
827 | - * limitations under the License. |
828 | - */ |
829 | -#include "stdafx.h" |
830 | - |
831 | -#include <string.h> |
832 | -#include <stdio.h> |
833 | -#include <stdlib.h> |
834 | - |
835 | -#include "util/uuid/sysdep.h" |
836 | -#include "util/uuid/uuid.h" |
837 | -#include "util/fs_util.h" |
838 | - |
839 | -namespace zorba { |
840 | - |
841 | -/* various forward declarations */ |
842 | -static int read_state(xs_short *clockseq, xs_unsignedLong *timestamp, |
843 | - uuid_node_t *node); |
844 | -static void write_state(xs_short clockseq, xs_unsignedLong timestamp, |
845 | - uuid_node_t node); |
846 | -static void format_uuid_v1(uuid_t *uuid, xs_short clockseq, |
847 | - xs_unsignedLong timestamp, uuid_node_t node); |
848 | -static void get_current_time(xs_unsignedLong *timestamp); |
849 | -static xs_short true_random(void); |
850 | - |
851 | -int uuid_create(uuid_t *uuid) |
852 | -{ |
853 | - xs_unsignedLong timestamp, last_time; |
854 | - xs_short clockseq; |
855 | - uuid_node_t node; |
856 | - memset(&node, 0, sizeof(uuid_node_t)); |
857 | - uuid_node_t last_node; |
858 | - memset(&last_node, 0, sizeof(uuid_node_t)); |
859 | - int f; |
860 | - |
861 | - //acquire system-wide lock so we're alone |
862 | - LOCK; |
863 | - //get time, node ID, saved state from non-volatile storage |
864 | - get_current_time(×tamp); |
865 | -// get_ieee_node_identifier(&node); |
866 | - f = read_state(&clockseq, &last_time, &last_node); |
867 | - |
868 | - //if no NV state, or if clock went backwards, or node ID |
869 | - //changed (e.g., new network card) change clockseq |
870 | - if (!f || memcmp(&node, &last_node, sizeof node)) |
871 | - clockseq = true_random(); |
872 | - else if (timestamp < last_time) |
873 | - clockseq++; |
874 | - |
875 | - //save the state for next time |
876 | - write_state(clockseq, timestamp, node); |
877 | - |
878 | - UNLOCK; |
879 | - |
880 | - //stuff fields into the UUID |
881 | - format_uuid_v1(uuid, clockseq, timestamp, node); |
882 | - return 1; |
883 | -} |
884 | - |
885 | -/* format_uuid_v1 -- make a UUID from the timestamp, clockseq, |
886 | - and node ID */ |
887 | -void format_uuid_v1(uuid_t* uuid, xs_short clock_seq, |
888 | - xs_unsignedLong timestamp, uuid_node_t node) |
889 | -{ |
890 | - //Construct a version 1 uuid with the information we've gathered plus a few constants. |
891 | - uuid->time_low = (xs_unsignedInt)(timestamp & 0xFFFFFFFF); |
892 | - uuid->time_mid = (xs_unsignedShort)((timestamp >> 32) & 0xFFFF); |
893 | - uuid->time_hi_and_version =(xs_unsignedShort)((timestamp >> 48) & 0x0FFF); |
894 | - uuid->time_hi_and_version |= (1 << 12); |
895 | - uuid->clock_seq_low = clock_seq & 0xFF; |
896 | - uuid->clock_seq_hi_and_reserved = (clock_seq & 0x3F00) >> 8; |
897 | - uuid->clock_seq_hi_and_reserved |= 0x80; |
898 | - memcpy(&uuid->node, &node, sizeof uuid->node); |
899 | -} |
900 | - |
901 | -/* data type for UUID generator persistent state */ |
902 | -typedef struct { |
903 | - xs_unsignedLong ts; // saved timestamp |
904 | - uuid_node_t node; // saved node ID |
905 | - xs_short cs; // saved clock sequence |
906 | -} uuid_state; |
907 | - |
908 | -static uuid_state st; |
909 | - |
910 | -zstring get_tmp_state_name() |
911 | -{ |
912 | - zstring lTmpFileName; |
913 | -#ifdef ZORBA_WITH_FILE_ACCESS |
914 | - fs::get_temp_file<zstring>(&lTmpFileName); |
915 | - lTmpFileName = lTmpFileName.substr(0, lTmpFileName.find_last_of(fs::dir_separator) + 1); |
916 | -#endif |
917 | - return lTmpFileName += "state"; |
918 | -} |
919 | - |
920 | -//read_state -- read UUID generator state from non-volatile store |
921 | -int read_state(xs_short *clockseq, xs_unsignedLong *timestamp, |
922 | - uuid_node_t *node) |
923 | -{ |
924 | - static int inited = 0; |
925 | - FILE *fp = 0; |
926 | - |
927 | - //only need to read state once per boot |
928 | - if (!inited) { |
929 | -#ifdef WIN32 |
930 | - errno_t err = fopen_s( &fp, get_tmp_state_name().c_str(), "rb"); |
931 | - if ( err != 0) |
932 | - return 0; |
933 | -#else |
934 | - fp = fopen(get_tmp_state_name().c_str(), "rb"); |
935 | - if (fp == NULL) |
936 | - return 0; |
937 | -#endif |
938 | - |
939 | - size_t lReadLength = fread(&st, sizeof st, 1, fp); |
940 | - fclose(fp); |
941 | - if (lReadLength == 0) |
942 | - return 0; |
943 | - inited = 1; |
944 | - } |
945 | - *clockseq = st.cs; |
946 | - *timestamp = st.ts; |
947 | - *node = st.node; |
948 | - return 1; |
949 | -} |
950 | - |
951 | -// write_state -- save UUID generator state back to non-volatile storage |
952 | -void write_state(xs_short clockseq, xs_unsignedLong timestamp, |
953 | - uuid_node_t node) |
954 | -{ |
955 | - volatile static bool inited = false; |
956 | - static xs_unsignedLong next_save; |
957 | - FILE* fp = 0; |
958 | - |
959 | - if (!inited) { |
960 | - next_save = timestamp; |
961 | - inited = 1; |
962 | - } |
963 | - |
964 | - //always save state to volatile shared state |
965 | - st.cs = clockseq; |
966 | - st.ts = timestamp; |
967 | - st.node = node; |
968 | - if (timestamp >= next_save) { |
969 | -#ifdef WIN32 |
970 | - errno_t err = fopen_s( &fp, get_tmp_state_name().c_str(), "wb"); |
971 | - if ( err != 0) |
972 | - return ; |
973 | -#else |
974 | - fp = fopen(get_tmp_state_name().c_str(), "wb"); |
975 | - if (fp == NULL) |
976 | - return ; |
977 | -#endif |
978 | - fwrite(&st, sizeof st, 1, fp); |
979 | - fclose(fp); |
980 | - //schedule next save for 10 seconds from now |
981 | - next_save = timestamp + (10 * 10 * 1000 * 1000); |
982 | - } |
983 | -} |
984 | - |
985 | -// get-current_time -- get time as 60-bit 100ns ticks since UUID epoch. |
986 | -// Compensate for the fact that real clock resolution is less than 100ns. |
987 | -void get_current_time(xs_unsignedLong *timestamp) |
988 | -{ |
989 | - static int inited = 0; |
990 | - static xs_unsignedLong time_last; |
991 | - static xs_short uuids_this_tick; |
992 | - xs_unsignedLong time_now; |
993 | - |
994 | - if (!inited) { |
995 | - get_system_time(&time_now); |
996 | - uuids_this_tick = UUIDS_PER_TICK; |
997 | - inited = 1; |
998 | - } |
999 | - |
1000 | - for ( ; ; ) { |
1001 | - get_system_time(&time_now); |
1002 | - |
1003 | - //if clock reading changed since last UUID generated |
1004 | - if (time_last != time_now) { |
1005 | - //reset count of uuids gen'd with this clock reading |
1006 | - uuids_this_tick = 0; |
1007 | - time_last = time_now; |
1008 | - break; |
1009 | - } |
1010 | - if (uuids_this_tick < UUIDS_PER_TICK) { |
1011 | - uuids_this_tick++; |
1012 | - break; |
1013 | - } |
1014 | - //going too fast for our clock; spin |
1015 | - } |
1016 | - // add the count of uuids to low order bits of the clock reading |
1017 | - *timestamp = time_now + uuids_this_tick; |
1018 | -} |
1019 | - |
1020 | -// true_random -- this does not generate a crypto-quality random number. |
1021 | -static xs_short true_random(void) |
1022 | -{ |
1023 | - static int inited = 0; |
1024 | - xs_unsignedLong time_now; |
1025 | - |
1026 | - if (!inited) { |
1027 | - get_system_time(&time_now); |
1028 | - time_now = time_now / UUIDS_PER_TICK; |
1029 | - srand((unsigned int) |
1030 | - (((time_now >> 32) ^ time_now) & 0xffffffff)); |
1031 | - inited = 1; |
1032 | - } |
1033 | - |
1034 | - return rand(); |
1035 | -} |
1036 | - |
1037 | -uuid_t NameSpace_DNS = { // 6ba7b810-9dad-11d1-80b4-00c04fd430c8 |
1038 | - 0x6ba7b810, |
1039 | - 0x9dad, |
1040 | - 0x11d1, |
1041 | - 0x80, |
1042 | - 0xb4, |
1043 | - { |
1044 | - 0x00, (unsigned char)0xc0, |
1045 | - 0x4f, (unsigned char)0xd4, |
1046 | - 0x30, (unsigned char)0xc8 |
1047 | - } |
1048 | -}; |
1049 | - |
1050 | -/* uuidToString -- transform a UUID to a string*/ |
1051 | -zstring uuidToString(const uuid_t& u) |
1052 | -{ |
1053 | - char lBuffer[174]; |
1054 | - sprintf(lBuffer, "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-9300a64ac3cd", u.time_low, u.time_mid, |
1055 | - u.time_hi_and_version, u.clock_seq_hi_and_reserved, |
1056 | - u.clock_seq_low); |
1057 | - |
1058 | - zstring lResult = lBuffer; |
1059 | - return lResult; |
1060 | -} |
1061 | - |
1062 | -/* uuidToString -- transform a UUID to a uri*/ |
1063 | -zstring uuidToURI(const uuid_t& u) |
1064 | -{ |
1065 | - char lBuffer[200]; |
1066 | - sprintf(lBuffer, "urn:uuid:%8.8x-%4.4x-%4.4x-%2.2x%2.2x-9300a64ac3cd", u.time_low, u.time_mid, |
1067 | - u.time_hi_and_version, u.clock_seq_hi_and_reserved, |
1068 | - u.clock_seq_low); |
1069 | - |
1070 | - zstring lResult = lBuffer; |
1071 | - return lResult; |
1072 | -} |
1073 | - |
1074 | -/* |
1075 | -//This appendix lists the name space IDs for some potentially |
1076 | -//interesting namespaces, as initialized C structures and in the |
1077 | -//string representation defined above. |
1078 | - |
1079 | -// Name string is a URL |
1080 | -uuid_t NameSpace_URL = { // 6ba7b811-9dad-11d1-80b4-00c04fd430c8 |
1081 | - 0x6ba7b811, |
1082 | - 0x9dad, |
1083 | - 0x11d1, |
1084 | - 0x80, |
1085 | - 0xb4, |
1086 | - {0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} |
1087 | -}; |
1088 | - |
1089 | -// Name string is an ISO OID |
1090 | -uuid_t NameSpace_OID = { // 6ba7b812-9dad-11d1-80b4-00c04fd430c8 |
1091 | - 0x6ba7b812, |
1092 | - 0x9dad, |
1093 | - 0x11d1, |
1094 | - 0x80, |
1095 | - 0xb4, |
1096 | - {0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} |
1097 | -}; |
1098 | - |
1099 | -// Name string is an X.500 DN (in DER or a text output format) |
1100 | -uuid_t NameSpace_X500 = { // 6ba7b814-9dad-11d1-80b4-00c04fd430c8 |
1101 | - 0x6ba7b814, |
1102 | - 0x9dad, |
1103 | - 0x11d1, |
1104 | - 0x80, |
1105 | - 0xb4, |
1106 | - {0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8} |
1107 | -}; |
1108 | -*/ |
1109 | -} |
1110 | -/* vim:set et sw=2 ts=2: */ |
1111 | |
1112 | === removed file 'src/util/uuid/uuid.h' |
1113 | --- src/util/uuid/uuid.h 2012-08-30 13:45:43 +0000 |
1114 | +++ src/util/uuid/uuid.h 1970-01-01 00:00:00 +0000 |
1115 | @@ -1,44 +0,0 @@ |
1116 | -/* |
1117 | - * Copyright 2006-2008 The FLWOR Foundation. |
1118 | - * |
1119 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
1120 | - * you may not use this file except in compliance with the License. |
1121 | - * You may obtain a copy of the License at |
1122 | - * |
1123 | - * http://www.apache.org/licenses/LICENSE-2.0 |
1124 | - * |
1125 | - * Unless required by applicable law or agreed to in writing, software |
1126 | - * distributed under the License is distributed on an "AS IS" BASIS, |
1127 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
1128 | - * See the License for the specific language governing permissions and |
1129 | - * limitations under the License. |
1130 | - */ |
1131 | - |
1132 | -#ifndef ZORBA_UTIL_UUID_H |
1133 | -#define ZORBA_UTIL_UUID_H |
1134 | - |
1135 | -#undef uuid_t |
1136 | - |
1137 | -namespace zorba { |
1138 | - |
1139 | -typedef struct { |
1140 | - xs_unsignedInt time_low; |
1141 | - xs_unsignedShort time_mid; |
1142 | - xs_unsignedShort time_hi_and_version; |
1143 | - xs_unsignedByte clock_seq_hi_and_reserved; |
1144 | - xs_unsignedByte clock_seq_low; |
1145 | - xs_byte node[6]; |
1146 | -} uuid_t; |
1147 | - |
1148 | -/* uuid_create -- generate a UUID */ |
1149 | -int uuid_create(uuid_t * uuid); |
1150 | - |
1151 | -/* uuidToString -- transform a UUID to a string */ |
1152 | -zstring uuidToString(const uuid_t& uuid); |
1153 | - |
1154 | -/* uuidToURI -- transform a UUID to a URI-formatted string */ |
1155 | -zstring uuidToURI(const uuid_t& uuid); |
1156 | - |
1157 | -} // namespace zorba |
1158 | -#endif /* ZORBA_UTIL_UUID_H */ |
1159 | -/* vim:set et sw=2 ts=2: */ |
Chris: please look at the CMake stuff I changed.
Rodolfo: please look at the Windows-specific stuff (including the Windows-specific CMake stuff).