1//
2// UUIDGenerator.h
3//
4// Library: Foundation
5// Package: UUID
6// Module: UUID
7//
8// Definition of the UUIDGenerator class.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_UUIDGenerator_INCLUDED
18#define Foundation_UUIDGenerator_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/UUID.h"
23#include "Poco/Mutex.h"
24#include "Poco/Random.h"
25#include "Poco/Timestamp.h"
26#include "Poco/Environment.h"
27
28
29namespace Poco {
30
31
32class DigestEngine;
33
34
35class Foundation_API UUIDGenerator
36 /// This class implements a generator for Universal Unique Identifiers,
37 /// as specified in Appendix A of the DCE 1.1 Remote Procedure
38 /// Call Specification (http://www.opengroup.org/onlinepubs/9629399/),
39 /// RFC 2518 (WebDAV), section 6.4.1 and the UUIDs and GUIDs internet
40 /// draft by Leach/Salz from February, 1998
41 /// (http://ftp.ics.uci.edu/pub/ietf/webdav/uuid-guid/draft-leach-uuids-guids-01.txt)
42{
43public:
44 UUIDGenerator();
45 /// Creates the UUIDGenerator.
46
47 ~UUIDGenerator();
48 /// Destroys the UUIDGenerator.
49
50 UUID create();
51 /// Creates a new time-based UUID, using the MAC address of
52 /// one of the system's ethernet adapters.
53 ///
54 /// Throws a SystemException if no MAC address can be
55 /// obtained.
56
57 UUID createFromName(const UUID& nsid, const std::string& name);
58 /// Creates a name-based UUID.
59
60 UUID createFromName(const UUID& nsid, const std::string& name, DigestEngine& de);
61 /// Creates a name-based UUID, using the given digest engine.
62 ///
63 /// Note: in order to create a standard-compliant UUID, the given DigestEngine
64 /// must be either an instance of MD5Engine or SHA1Engine. The version field of
65 /// the UUID will be set accordingly.
66
67 UUID createFromName(const UUID& nsid, const std::string& name, DigestEngine& de, UUID::Version version);
68 /// Creates a name-based UUID, using the given digest engine and version.
69
70 UUID createRandom();
71 /// Creates a random UUID.
72
73 UUID createOne();
74 /// Tries to create and return a time-based UUID (see create()), and,
75 /// if that does not work due to the unavailability of a MAC address,
76 /// creates and returns a random UUID (see createRandom()).
77 ///
78 /// The UUID::version() method can be used to determine the actual kind of
79 /// the UUID generated.
80
81 static UUIDGenerator& defaultGenerator();
82 /// Returns a reference to the default UUIDGenerator.
83
84protected:
85 Timestamp::UtcTimeVal timeStamp();
86 void getNode();
87
88private:
89 FastMutex _mutex;
90 Random _random;
91 Timestamp _lastTime;
92 int _ticks;
93 Environment::NodeId _node;
94 bool _haveNode;
95
96 UUIDGenerator(const UUIDGenerator&);
97 UUIDGenerator& operator = (const UUIDGenerator&);
98};
99
100
101} // namespace Poco
102
103
104#endif // Foundation_UUIDGenerator_INCLUDED
105