aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/vespa/config/helper/legacysubscriber.hpp
blob: c11f97e81b75f72cea3cdeb31fcf174873b631b0 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "legacysubscriber.h"
#include "configfetcher.hpp"
#include <vespa/config/common/configcontext.h>

namespace config {

template <typename ConfigType>
void
LegacySubscriber::subscribe(const std::string & configId, IFetcherCallback<ConfigType> * callback)
{
    if (isLegacyConfigId(configId)) {
        std::string legacyId(legacyConfigId2ConfigId(configId));
        std::unique_ptr<SourceSpec> spec(legacyConfigId2Spec(configId));
        _fetcher = std::make_unique<ConfigFetcher>(std::make_shared<ConfigContext>(*spec));
        _fetcher->subscribe<ConfigType>(legacyId, callback);
    } else {
        _fetcher = std::make_unique<ConfigFetcher>();
        _fetcher->subscribe<ConfigType>(configId, callback);
    }
    _configId = configId;
    _fetcher->start();
}

} // namespace config