aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/public/sdk/cpp/client/ydb_extension/extension.h
blob: 3371bffddc55d0738158cf0207cafee1bdadc8a9 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <ydb/public/sdk/cpp/client/ydb_driver/driver.h>

#include <library/cpp/monlib/metrics/metric_registry.h>

namespace Ydb {
namespace Discovery {

class ListEndpointsResult;

}
}

namespace NYdb {

class IExtensionApi {
public:
    friend class TDriver;
public:
    virtual ~IExtensionApi() = default;
private:
    void SelfRegister(TDriver driver);
};

class IExtension {
    friend class TDriver;
public:
    virtual ~IExtension() = default;
private:
    void SelfRegister(TDriver driver);
};

namespace NSdkStats {

class IStatApi: public IExtensionApi {
public:
    static IStatApi* Create(TDriver driver);
public:
    virtual void SetMetricRegistry(NMonitoring::IMetricRegistry* sensorsRegistry) = 0;
    virtual void Accept(NMonitoring::IMetricConsumer* consumer) const = 0;
};

class DestroyedClientException: public yexception {};

} // namespace NSdkStats


class IDiscoveryMutatorApi: public IExtensionApi {
public:
    using TMutatorCb = std::function<TStatus(Ydb::Discovery::ListEndpointsResult* proto, TStatus status, const TStringType& database)>;

    static IDiscoveryMutatorApi* Create(TDriver driver);
public:
    virtual void SetMutatorCb(TMutatorCb&& mutator) = 0;
};


template<typename TExtension>
void TDriver::AddExtension(typename TExtension::TParams params) {
    typename TExtension::IApi* api = TExtension::IApi::Create(*this);
    auto extension = new TExtension(params, api);
    extension->SelfRegister(*this);
    if (api)
        api->SelfRegister(*this);
}

} // namespace NYdb