1
#pragma once
2

            
3
#include "envoy/extensions/common/async_files/v3/async_file_manager.pb.h"
4
#include "envoy/singleton/instance.h"
5
#include "envoy/singleton/manager.h"
6

            
7
#include "source/extensions/common/async_files/async_file_manager.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace Common {
12
namespace AsyncFiles {
13

            
14
// A singleton factory for instantiating AsyncFileManagers.
15
//
16
// This ensures that each distinct id from an AsyncFileManagerConfig represents
17
// only one AsyncFileManager.
18
class AsyncFileManagerFactory : public Singleton::Instance {
19
public:
20
  // Returns an AsyncFileManagerFactory.
21
  //
22
  // Destroying this factory destroys the mapping from ids to AsyncFileManagers. Make sure
23
  // an instance of the returned shared_ptr remains in scope for the lifetime of the managers,
24
  // to avoid accidentally generating duplicate managers.
25
  //
26
  // Specifically, the singleton manager *does not* keep a reference to the returned singleton
27
  // - the factory persists only as long as there is a live reference to it.
28
  static std::shared_ptr<AsyncFileManagerFactory> singleton(Singleton::Manager* singleton_manager);
29
  virtual std::shared_ptr<AsyncFileManager> getAsyncFileManager(
30
      const envoy::extensions::common::async_files::v3::AsyncFileManagerConfig& config,
31
      Api::OsSysCalls* substitute_posix_file_operations = nullptr) PURE;
32
};
33

            
34
} // namespace AsyncFiles
35
} // namespace Common
36
} // namespace Extensions
37
} // namespace Envoy