forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchman_clockspec.h
87 lines (72 loc) · 2.4 KB
/
watchman_clockspec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#pragma once
#include <folly/Synchronized.h>
#include <unordered_map>
#include "Logging.h"
struct watchman_clock {
uint32_t ticks;
time_t timestamp;
};
typedef struct watchman_clock w_clock_t;
struct w_query_ctx;
struct w_query_since;
struct ClockPosition {
uint32_t rootNumber{0};
uint32_t ticks{0};
ClockPosition() = default;
ClockPosition(uint32_t rootNumber, uint32_t ticks)
: rootNumber(rootNumber), ticks(ticks) {}
w_string toClockString() const;
};
enum w_clockspec_tag { w_cs_timestamp, w_cs_clock, w_cs_named_cursor };
struct ClockSpec {
enum w_clockspec_tag tag;
time_t timestamp;
struct {
uint64_t start_time;
int pid;
ClockPosition position;
} clock;
struct {
w_string cursor;
} named_cursor;
// Optional SCM merge base parameters
w_string scmMergeBase;
w_string scmMergeBaseWith;
// Optional saved state parameters
json_ref savedStateConfig;
w_string savedStateStorageType;
w_string savedStateCommitId;
ClockSpec();
explicit ClockSpec(const ClockPosition& position);
explicit ClockSpec(const json_ref& value);
/** Given a json value, parse out a clockspec.
* Will return nullptr if the input was json null, indicating
* an absence of a specified clock value.
* Throws std::domain_error for badly formed clockspec value.
*/
static std::unique_ptr<ClockSpec> parseOptionalClockSpec(
const json_ref& value);
/** Evaluate the clockspec against the inputs, returning
* the effective since parameter.
* If cursorMap is passed in, it MUST be unlocked, as this method
* will acquire a lock to evaluate a named cursor. */
struct w_query_since evaluate(
const ClockPosition& position,
const uint32_t lastAgeOutTick,
folly::Synchronized<std::unordered_map<w_string, uint32_t>>* cursorMap =
nullptr) const;
/** Initializes some global state needed for clockspec evaluation */
static void init();
inline const ClockPosition& position() const {
w_check(tag == w_cs_clock, "position() called for non-clock clockspec");
return clock.position;
}
bool hasScmParams() const;
bool hasSavedStateParams() const;
/** Returns a json value representing the current state of this ClockSpec
* that can be parsed by the ClockSpec(const json_ref&)
* constructor of this class */
json_ref toJson() const;
};