GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/uuid.h Lines: 5 5 100.0 %
Date: 2019-02-03 02:48:13 Branches: 0 0 - %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#ifndef CVMFS_UUID_H_
6
#define CVMFS_UUID_H_
7
8
#include <inttypes.h>
9
#include <uuid/uuid.h>
10
11
#include <string>
12
13
namespace cvmfs {
14
15
/**
16
 * Holds a unique identifies which is either read from a file or, if the file
17
 * does not yet exist, created and stored in a file.  This is how it is used to
18
 * identify a cvmfs cache directory.
19
 *
20
 * In order to create many UUIDs for short-lived objects, use the CreateOneTime
21
 * factory method.
22
 */
23
100388
class Uuid {
24
 public:
25
  static Uuid *Create(const std::string &store_path);
26
  static std::string CreateOneTime();
27
276
  std::string uuid() const { return uuid_; }
28
100055
  const unsigned char *data() const {
29
100055
    return reinterpret_cast<const unsigned char *>(&uuid_presentation_.uuid);
30
  }
31
100055
  unsigned size() const { return sizeof(uuid_presentation_.uuid); }
32
33
 private:
34
  void MkUuid();
35
  Uuid();
36
37
  std::string uuid_;
38
  union {
39
    uuid_t uuid;
40
    struct __attribute__((__packed__)) {
41
      uint32_t a;
42
      uint16_t b;
43
      uint16_t c;
44
      uint16_t d;
45
      uint32_t e1;
46
      uint16_t e2;
47
    } split;
48
  } uuid_presentation_;
49
};
50
51
}  // namespace cvmfs
52
53
#endif  // CVMFS_UUID_H_