1 | // |
---|
2 | // UUIDGenerator.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/include/Poco/UUIDGenerator.h#3 $ |
---|
5 | // |
---|
6 | // Library: Foundation |
---|
7 | // Package: UUID |
---|
8 | // Module: UUID |
---|
9 | // |
---|
10 | // Definition of the UUIDGenerator class. |
---|
11 | // |
---|
12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
13 | // and Contributors. |
---|
14 | // |
---|
15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef Foundation_UUIDGenerator_INCLUDED |
---|
40 | #define Foundation_UUIDGenerator_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Foundation.h" |
---|
44 | #include "Poco/UUID.h" |
---|
45 | #include "Poco/Mutex.h" |
---|
46 | #include "Poco/Random.h" |
---|
47 | #include "Poco/Timestamp.h" |
---|
48 | #include "Poco/Environment.h" |
---|
49 | |
---|
50 | |
---|
51 | namespace Poco { |
---|
52 | |
---|
53 | |
---|
54 | class DigestEngine; |
---|
55 | |
---|
56 | |
---|
57 | class Foundation_API UUIDGenerator |
---|
58 | /// This class implements a generator for Universal Unique Identifiers, |
---|
59 | /// as specified in Appendix A of the DCE 1.1 Remote Procedure |
---|
60 | /// Call Specification (http://www.opengroup.org/onlinepubs/9629399/), |
---|
61 | /// RFC 2518 (WebDAV), section 6.4.1 and the UUIDs and GUIDs internet |
---|
62 | /// draft by Leach/Salz from February, 1998 |
---|
63 | /// (http://ftp.ics.uci.edu/pub/ietf/webdav/uuid-guid/draft-leach-uuids-guids-01.txt) |
---|
64 | { |
---|
65 | public: |
---|
66 | UUIDGenerator(); |
---|
67 | /// Creates the UUIDGenerator. |
---|
68 | |
---|
69 | ~UUIDGenerator(); |
---|
70 | /// Destroys the UUIDGenerator. |
---|
71 | |
---|
72 | UUID create(); |
---|
73 | /// Creates a new time-based UUID, using the MAC address of |
---|
74 | /// one of the system's ethernet adapters. |
---|
75 | /// |
---|
76 | /// Throws a SystemException if no MAC address can be |
---|
77 | /// obtained. |
---|
78 | |
---|
79 | UUID createFromName(const UUID& nsid, const std::string& name); |
---|
80 | /// Creates a name-based UUID. |
---|
81 | |
---|
82 | UUID createFromName(const UUID& nsid, const std::string& name, DigestEngine& de); |
---|
83 | /// Creates a name-based UUID, using the given digest engine. |
---|
84 | |
---|
85 | UUID createRandom(); |
---|
86 | /// Creates a random UUID. |
---|
87 | |
---|
88 | UUID createOne(); |
---|
89 | /// Tries to create and return a time-based UUID (see create()), and, |
---|
90 | /// if that does not work due to the unavailability of a MAC address, |
---|
91 | /// creates and returns a random UUID (see createRandom()). |
---|
92 | /// |
---|
93 | /// The UUID::version() method can be used to determine the actual kind of |
---|
94 | /// the UUID generated. |
---|
95 | |
---|
96 | static UUIDGenerator& defaultGenerator(); |
---|
97 | /// Returns a reference to the default UUIDGenerator. |
---|
98 | |
---|
99 | protected: |
---|
100 | Timestamp::UtcTimeVal timeStamp(); |
---|
101 | void getNode(); |
---|
102 | |
---|
103 | private: |
---|
104 | FastMutex _mutex; |
---|
105 | Random _random; |
---|
106 | Timestamp _lastTime; |
---|
107 | int _ticks; |
---|
108 | Environment::NodeId _node; |
---|
109 | bool _haveNode; |
---|
110 | |
---|
111 | UUIDGenerator(const UUIDGenerator&); |
---|
112 | UUIDGenerator& operator = (const UUIDGenerator&); |
---|
113 | }; |
---|
114 | |
---|
115 | |
---|
116 | } // namespace Poco |
---|
117 | |
---|
118 | |
---|
119 | #endif // Foundation_UUIDGenerator_INCLUDED |
---|