Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/common/pure.h" 4 : 5 : #include "source/common/common/assert.h" 6 : #include "source/common/protobuf/protobuf.h" 7 : 8 : namespace Envoy { 9 : namespace Config { 10 : 11 : /** 12 : * Base class for an extension factory. 13 : */ 14 : class UntypedFactory { 15 : public: 16 11 : virtual ~UntypedFactory() = default; 17 : 18 : /** 19 : * Name of the factory, a reversed DNS name is encouraged to avoid cross-org conflict. 20 : * It's used as key in the metadata map, as well as key in the factory registry. 21 : */ 22 : virtual std::string name() const PURE; 23 : 24 : /** 25 : * @return std::string the identifying category name for objects 26 : * created by this factory. Used for automatic registration with 27 : * FactoryCategoryRegistry. 28 : */ 29 : virtual std::string category() const PURE; 30 : 31 : /** 32 : * @return all full names of configuration protos that used by the factory. Empty set 33 : * will be returned for untyped factories. 34 : */ 35 306 : virtual std::set<std::string> configTypes() { return {}; } 36 : }; 37 : 38 : /** 39 : * Base class for an extension factory configured by a typed proto message. 40 : */ 41 : class TypedFactory : public UntypedFactory { 42 : public: 43 11 : ~TypedFactory() override = default; 44 : 45 : /** 46 : * @return ProtobufTypes::MessagePtr create empty config proto message for v2. The config, which 47 : * arrives in an opaque google.protobuf.Struct message, will be converted to JSON and then parsed 48 : * into this empty proto. 49 : */ 50 : virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE; 51 : 52 1072 : std::set<std::string> configTypes() override { 53 1072 : auto ptr = createEmptyConfigProto(); 54 1072 : ASSERT(ptr != nullptr); 55 1072 : Protobuf::ReflectableMessage reflectable_message = createReflectableMessage(*ptr); 56 1072 : return {reflectable_message->GetDescriptor()->full_name()}; 57 1072 : } 58 : }; 59 : 60 : } // namespace Config 61 : } // namespace Envoy