#define CEPH_CONFIG_OBS_H
#include <set>
+#include <vector>
#include <string>
#include "common/config_fwd.h"
class md_config_obs_impl {
public:
virtual ~md_config_obs_impl() {}
+
/** @brief Get a table of strings specifying the configuration keys in which the object is interested.
* This is called when the object is subscribed to configuration changes with add_observer().
* The returned table should not be freed until the observer is removed with remove_observer().
- * Note that it is not possible to change the set of tracked keys without re-subscribing. */
- virtual const char** get_tracked_conf_keys() const = 0;
+ * Note that it is not possible to change the set of tracked keys without re-subscribing.
+ *
+ * DEPRECATED! Use get_tracked_keys() instead.
+ */
+ virtual const char** get_tracked_conf_keys() const {
+ return nullptr;
+ }
+
+ /**
+ * Returns a vector of strings specifying the configuration keys in which
+ * the object is interested.
+ * Note - the strings in the returned vector are 'moveable'. The caller
+ * (ostensibly the observer manager) is expected to move them into its
+ * map.
+ */
+ virtual std::vector<std::string> get_tracked_keys() const noexcept {
+ return {};
+ }
+
/// React to a configuration change.
virtual void handle_conf_change(const ConfigProxy& conf,
const std::set <std::string> &changed) = 0;
- /// Unused for now
- virtual void handle_subsys_change(const ConfigProxy& conf,
- const std::set<int>& changed) { }
};
}
template<class ConfigObs>
void ObserverMgr<ConfigObs>::add_observer(ConfigObs* observer)
{
- const char **keys = observer->get_tracked_conf_keys();
auto ptr = std::make_shared<ConfigObs*>(observer);
- for (const char ** k = keys; *k; ++k) {
- observers.emplace(*k, ptr);
+
+ for (auto&& k : observer->get_tracked_keys()) {
+ observers.emplace(std::move(k), ptr);
+ }
+
+ // legacy observer interface:
+ if (const char** keys = observer->get_tracked_conf_keys(); keys) {
+ for (const char** k = keys; *k; ++k) {
+ observers.emplace(*k, ptr);
+ }
}
}