1
#pragma once
2

            
3
#include <string>
4

            
5
#include "envoy/config/config_provider.h"
6
#include "envoy/server/filter_config.h"
7
#include "envoy/singleton/instance.h"
8

            
9
#include "source/common/protobuf/protobuf.h"
10

            
11
namespace Envoy {
12
namespace Config {
13

            
14
/**
15
 * A ConfigProvider manager which instantiates static and dynamic (xDS) providers.
16
 *
17
 * ConfigProvider objects are owned by the caller of the
18
 * createXdsConfigProvider()/createStaticConfigProvider() functions. The ConfigProviderManager holds
19
 * raw pointers to those objects.
20
 *
21
 * Configuration implementations returned by ConfigProvider::config() are immutable, which allows
22
 * them to share the underlying objects such as config protos and subscriptions (for dynamic
23
 * providers) without synchronization related performance penalties. This enables linear memory
24
 * growth based on the size of the configuration set, regardless of the number of threads/objects
25
 * that must hold a reference/pointer to them.
26
 */
27
class ConfigProviderManager : public Singleton::Instance {
28
public:
29
  class OptionalArg {
30
  public:
31
133
    virtual ~OptionalArg() = default;
32
  };
33

            
34
  class NullOptionalArg : public OptionalArg {
35
  public:
36
11
    NullOptionalArg() = default;
37
11
    ~NullOptionalArg() override = default;
38
  };
39

            
40
9722
  ~ConfigProviderManager() override = default;
41

            
42
  /**
43
   * Returns a dynamic ConfigProvider which receives configuration via an xDS API.
44
   * A shared ownership model is used, such that the underlying subscription, config proto
45
   * and Config are shared amongst all providers relying on the same config source.
46
   * @param config_source_proto supplies the proto containing the xDS API configuration.
47
   * @param factory_context is the context to use for the provider.
48
   * @param init_manager is the Init::Manager to use for the provider.
49
   * @param stat_prefix supplies the prefix to use for statistics.
50
   * @param optarg supplies an optional argument with data specific to the concrete class.
51
   * @return ConfigProviderPtr a newly allocated dynamic config provider which shares underlying
52
   *                           data structures with other dynamic providers configured with the same
53
   *                           API source.
54
   */
55
  virtual ConfigProviderPtr
56
  createXdsConfigProvider(const Protobuf::Message& config_source_proto,
57
                          Server::Configuration::ServerFactoryContext& factory_context,
58
                          Init::Manager& init_manager, const std::string& stat_prefix,
59
                          const OptionalArg& optarg) PURE;
60

            
61
  /**
62
   * Returns a ConfigProvider associated with a statically specified configuration. This is intended
63
   * to be used when a set of configuration protos is required to build the full configuration.
64
   * @param config_protos supplies a vector of configuration protos.
65
   * @param factory_context is the context to use for the provider.
66
   * @param optarg supplies an optional argument with data specific to the concrete class.
67
   * @return ConfigProviderPtr a newly allocated static config provider.
68
   */
69
  virtual ConfigProviderPtr
70
  createStaticConfigProvider(ProtobufTypes::ConstMessagePtrVector&& config_protos,
71
                             Server::Configuration::ServerFactoryContext& factory_context,
72
                             const OptionalArg& optarg) PURE;
73
};
74

            
75
} // namespace Config
76
} // namespace Envoy