BuildCache
remote_cache_provider.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2019 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_REMOTE_CACHE_PROVIDER_HPP_
21 #define BUILDCACHE_REMOTE_CACHE_PROVIDER_HPP_
22 
23 #include <cache/cache_entry.hpp>
24 #include <cache/expected_file.hpp>
25 
26 #include <map>
27 #include <string>
28 
29 namespace bcache {
30 
32 public:
34  virtual ~remote_cache_provider_t();
35 
39  virtual bool connect(const std::string& host_description) = 0;
40 
43  virtual bool is_connected() const = 0;
44 
48  virtual cache_entry_t lookup(const std::string& hash) = 0;
49 
55  virtual void add(const std::string& hash,
56  const cache_entry_t& entry,
57  const std::map<std::string, expected_file_t>& expected_files) = 0;
58 
64  virtual void get_file(const std::string& hash,
65  const std::string& source_id,
66  const std::string& target_path,
67  const bool is_compressed) = 0;
68 
69 protected:
70  // Constructor called by child classes.
72 
79  static bool parse_host_description(const std::string& host_description,
80  std::string& host,
81  int& port,
82  std::string& path);
83 
86  static int connection_timeout_ms();
87 
90  static int transfer_timeout_ms();
91 
92 private:
93  // Prohibit copy & assignment.
95  remote_cache_provider_t& operator=(const remote_cache_provider_t&) = delete;
96 };
97 
98 } // namespace bcache
99 
100 #endif // BUILDCACHE_REMOTE_CACHE_PROVIDER_HPP_
bcache::remote_cache_provider_t::get_file
virtual void get_file(const std::string &hash, const std::string &source_id, const std::string &target_path, const bool is_compressed)=0
Copy a cached file to the local file system.
bcache::remote_cache_provider_t::is_connected
virtual bool is_connected() const =0
Check if we have a connection to the remote cache.
bcache::remote_cache_provider_t::~remote_cache_provider_t
virtual ~remote_cache_provider_t()
De-initialzie the remote cache object.
Definition: remote_cache_provider.cpp:30
bcache::remote_cache_provider_t
Definition: remote_cache_provider.hpp:31
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::remote_cache_provider_t::lookup
virtual cache_entry_t lookup(const std::string &hash)=0
Check if an entry exists in the cache.
bcache::remote_cache_provider_t::add
virtual void add(const std::string &hash, const cache_entry_t &entry, const std::map< std::string, expected_file_t > &expected_files)=0
Adds a set of files to the cache.
bcache::remote_cache_provider_t::connection_timeout_ms
static int connection_timeout_ms()
Get the timeout for remote connections.
Definition: remote_cache_provider.cpp:85
bcache::remote_cache_provider_t::parse_host_description
static bool parse_host_description(const std::string &host_description, std::string &host, int &port, std::string &path)
Parse a host description string.
Definition: remote_cache_provider.cpp:33
bcache::cache_entry_t
Meta data for a single cache entry.
Definition: cache_entry.hpp:28
bcache::remote_cache_provider_t::connect
virtual bool connect(const std::string &host_description)=0
Connect to the remote cache.
bcache::remote_cache_provider_t::transfer_timeout_ms
static int transfer_timeout_ms()
Get the timeout for remote transfers.
Definition: remote_cache_provider.cpp:91