From 8fe39ab39b757b0343c4bd2a5344df71441bda81 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 11 Feb 2010 21:01:59 +0100 Subject: [PATCH] Add a function for retrieving registered data sources --- src/data-source.cc | 15 +++++++++++++-- src/data-source.hh | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/data-source.cc b/src/data-source.cc index 5ce84d29..1ff8b3f5 100644 --- a/src/data-source.cc +++ b/src/data-source.cc @@ -28,7 +28,6 @@ #include #include #include -#include namespace conky { namespace { @@ -45,7 +44,6 @@ namespace conky { * different modules is not defined, so register_source could be called before this * object is constructed. Therefore, we create it on the first call to register_source. */ - typedef std::unordered_map data_sources_t; data_sources_t *data_sources; void register_data_source_(const std::string &name, const data_source_factory &factory_func) @@ -103,4 +101,17 @@ namespace conky { std::placeholders::_1, std::placeholders::_2, setting) ); } + + // at least one data source should always be registered, so the pointer will not be null + const data_sources_t& get_data_sources() + { return *data_sources; } } + +/////////// example data sources, remove after real data sources are available /////// +int asdf_ = 47; +conky::register_data_source asdf("asdf", std::bind( + conky::simple_numeric_source::factory, + std::placeholders::_1, std::placeholders::_2, &asdf_) + ); + +conky::register_disabled_data_source zxcv("zxcv", "BUILD_ZXCV"); diff --git a/src/data-source.hh b/src/data-source.hh index f11806eb..11713784 100644 --- a/src/data-source.hh +++ b/src/data-source.hh @@ -28,6 +28,7 @@ #include #include #include +#include #include "luamm.hh" @@ -39,7 +40,9 @@ namespace conky { * Recieves a lua table on the stack and the name the object was registered with. It should * pop the table after consuming it and return the data source. */ - typedef std::function (lua::state &l, const std::string &name)> data_source_factory; + typedef std::function< + std::shared_ptr (lua::state &l, const std::string &name) + > data_source_factory; /* * A base class for all data sources. @@ -102,6 +105,11 @@ namespace conky { public: register_disabled_data_source(const std::string &name, const std::string &setting); }; + + typedef std::unordered_map data_sources_t; + + // returns the list of registered data sources + const data_sources_t& get_data_sources(); } #endif /* DATA_SOURCE_HH */