1 /* Copyright 2016-present Facebook, Inc.
2  * Licensed under the Apache License, Version 2.0 */
3 #pragma once
4 
5 #include "watchman_system.h"
6 #include <future>
7 #include <vector>
8 #include "scm/SCM.h"
9 #include "watchman_perf.h"
10 #include "watchman_query.h"
11 #include "watchman_string.h"
12 
13 struct watchman_file;
14 struct watchman_dir;
15 struct watchman_glob_tree;
16 
17 namespace watchman {
18 
19 class QueryableView : public std::enable_shared_from_this<QueryableView> {
20  public:
21   virtual ~QueryableView();
22 
23   /** Perform a time-based (since) query and emit results to the supplied
24   * query context */
25   virtual void timeGenerator(w_query* query, struct w_query_ctx* ctx) const;
26 
27   /** Walks all files with the suffix(es) configured in the query */
28   virtual void suffixGenerator(w_query* query, struct w_query_ctx* ctx) const;
29 
30   /** Walks files that match the supplied set of paths */
31   virtual void pathGenerator(w_query* query, struct w_query_ctx* ctx) const;
32 
33   virtual void globGenerator(w_query* query, struct w_query_ctx* ctx) const;
34 
35   virtual void allFilesGenerator(w_query* query, struct w_query_ctx* ctx) const;
36   virtual ClockPosition getMostRecentRootNumberAndTickValue() const = 0;
37   virtual w_string getCurrentClockString() const = 0;
38   virtual uint32_t getLastAgeOutTickValue() const;
39   virtual time_t getLastAgeOutTimeStamp() const;
40   virtual void ageOut(w_perf_t& sample, std::chrono::seconds minAge);
41   virtual bool syncToNow(std::chrono::milliseconds timeout) = 0;
42 
43   // Specialized query function that is used to test whether
44   // version control files exist as part of some settling handling.
45   // It should query the view and return true if any of the named
46   // files current exist in the view.
47   virtual bool doAnyOfTheseFilesExist(
48       const std::vector<w_string>& fileNames) const = 0;
49 
50   bool isVCSOperationInProgress() const;
51 
52   // Start up any helper threads
53   virtual void startThreads(const std::shared_ptr<w_root_t>& root);
54   // Request that helper threads shutdown (but does not join them)
55   virtual void signalThreads();
56   // Request that helper threads wake up and re-evaluate their state
57   virtual void wakeThreads();
58 
59   virtual const w_string& getName() const = 0;
60 
61   virtual std::shared_future<void> waitUntilReadyToQuery(
62       const std::shared_ptr<w_root_t>& root) = 0;
63 
64   // Return the SCM detected for this watched root
65   virtual SCM* getSCM() const = 0;
66 };
67 }
68