aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/neh/factory.h
blob: 17bebef8ed0f7c2ac81815c35dc28e738b5ea47e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include "neh.h"
#include "rpc.h"

namespace NNeh {
    struct TParsedLocation;

    class IProtocol {
    public:
        virtual ~IProtocol() {
        }
        virtual IRequesterRef CreateRequester(IOnRequest* cb, const TParsedLocation& loc) = 0;
        virtual THandleRef ScheduleRequest(const TMessage& msg, IOnRecv* fallback, TServiceStatRef&) = 0;
        virtual THandleRef ScheduleAsyncRequest(const TMessage& msg, IOnRecv* fallback, TServiceStatRef& statRef, bool useAsyncSendRequest = false) {
            Y_UNUSED(useAsyncSendRequest);
            return ScheduleRequest(msg, fallback, statRef);
        }
        virtual TStringBuf Scheme() const noexcept = 0;
        virtual bool SetOption(TStringBuf name, TStringBuf value) {
            Y_UNUSED(name);
            Y_UNUSED(value);
            return false;
        }
    };

    class IProtocolFactory {
    public:
        virtual IProtocol* Protocol(const TStringBuf& scheme) = 0;
        virtual void Register(IProtocol* proto) = 0;
        virtual ~IProtocolFactory() {
        }
    };

    void SetGlobalFactory(IProtocolFactory* factory);
    IProtocolFactory* ProtocolFactory();
}