blob: 0c5960fb362b1ae0d55a6924112dd9310b11d052 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/config/helper/legacysubscriber.h>
#include <vespa/vespalib/stllike/string.h>
namespace search {
template <typename ME, typename CFG>
class SubscriptionProxyNg : public config::IFetcherCallback<CFG>
{
typedef void (ME::*Method)(const CFG &cfg);
private:
ME &_target;
Method _method;
config::LegacySubscriber *_subscriber;
vespalib::string _cfgId;
SubscriptionProxyNg(const SubscriptionProxyNg&);
SubscriptionProxyNg &operator=(const SubscriptionProxyNg&);
public:
SubscriptionProxyNg(ME &target, Method method)
: _target(target),
_method(method),
_subscriber(NULL),
_cfgId("")
{
}
virtual ~SubscriptionProxyNg() {
unsubscribe();
}
const char *getConfigId() const {
return _cfgId.c_str();
}
void subscribe(const char *configId) {
if (_subscriber != NULL) {
if (configId != NULL && strcmp(configId, _subscriber->id().c_str()) == 0)
{
return; // same id; ignore
} else {
unsubscribe();
}
}
if (configId != NULL && configId[0] != '\0') {
_cfgId = configId;
_subscriber = new config::LegacySubscriber();
_subscriber->subscribe<CFG>(configId, this);
}
}
void unsubscribe() {
delete _subscriber;
_subscriber = NULL;
_cfgId = "";
}
virtual void configure(std::unique_ptr<CFG> cfg) override {
(_target.*_method)(*cfg);
}
};
} // namespace search
|