diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/neh/factory.cpp | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/neh/factory.cpp')
-rw-r--r-- | library/cpp/neh/factory.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/library/cpp/neh/factory.cpp b/library/cpp/neh/factory.cpp new file mode 100644 index 00000000000..5b9fd700e69 --- /dev/null +++ b/library/cpp/neh/factory.cpp @@ -0,0 +1,67 @@ +#include "factory.h" +#include "udp.h" +#include "netliba.h" +#include "https.h" +#include "http2.h" +#include "inproc.h" +#include "tcp.h" +#include "tcp2.h" + +#include <util/generic/hash.h> +#include <util/generic/strbuf.h> +#include <util/generic/singleton.h> + +using namespace NNeh; + +namespace { + class TProtocolFactory: public IProtocolFactory, public THashMap<TStringBuf, IProtocol*> { + public: + inline TProtocolFactory() { + Register(NetLibaProtocol()); + Register(Http1Protocol()); + Register(Post1Protocol()); + Register(Full1Protocol()); + Register(UdpProtocol()); + Register(InProcProtocol()); + Register(TcpProtocol()); + Register(Tcp2Protocol()); + Register(Http2Protocol()); + Register(Post2Protocol()); + Register(Full2Protocol()); + Register(SSLGetProtocol()); + Register(SSLPostProtocol()); + Register(SSLFullProtocol()); + Register(UnixSocketGetProtocol()); + Register(UnixSocketPostProtocol()); + Register(UnixSocketFullProtocol()); + } + + IProtocol* Protocol(const TStringBuf& proto) override { + const_iterator it = find(proto); + + if (it == end()) { + ythrow yexception() << "unsupported scheme " << proto; + } + + return it->second; + } + + void Register(IProtocol* proto) override { + (*this)[proto->Scheme()] = proto; + } + }; + + IProtocolFactory* GLOBAL_FACTORY = nullptr; +} + +void NNeh::SetGlobalFactory(IProtocolFactory* factory) { + GLOBAL_FACTORY = factory; +} + +IProtocolFactory* NNeh::ProtocolFactory() { + if (GLOBAL_FACTORY) { + return GLOBAL_FACTORY; + } + + return Singleton<TProtocolFactory>(); +} |