1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-30 14:09:13 +00:00

Add a function for retrieving registered data sources

This commit is contained in:
Pavel Labath 2010-02-11 21:01:59 +01:00
parent 109770ac31
commit 8fe39ab39b
2 changed files with 22 additions and 3 deletions

View File

@ -28,7 +28,6 @@
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <unordered_map>
namespace conky { namespace conky {
namespace { namespace {
@ -45,7 +44,6 @@ namespace conky {
* different modules is not defined, so register_source could be called before this * 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. * object is constructed. Therefore, we create it on the first call to register_source.
*/ */
typedef std::unordered_map<std::string, data_source_factory> data_sources_t;
data_sources_t *data_sources; data_sources_t *data_sources;
void register_data_source_(const std::string &name, const data_source_factory &factory_func) 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) 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<int>::factory,
std::placeholders::_1, std::placeholders::_2, &asdf_)
);
conky::register_disabled_data_source zxcv("zxcv", "BUILD_ZXCV");

View File

@ -28,6 +28,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <unordered_map>
#include "luamm.hh" #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 * 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. * pop the table after consuming it and return the data source.
*/ */
typedef std::function<std::shared_ptr<data_source_base> (lua::state &l, const std::string &name)> data_source_factory; typedef std::function<
std::shared_ptr<data_source_base> (lua::state &l, const std::string &name)
> data_source_factory;
/* /*
* A base class for all data sources. * A base class for all data sources.
@ -102,6 +105,11 @@ namespace conky {
public: public:
register_disabled_data_source(const std::string &name, const std::string &setting); register_disabled_data_source(const std::string &name, const std::string &setting);
}; };
typedef std::unordered_map<std::string, data_source_factory> data_sources_t;
// returns the list of registered data sources
const data_sources_t& get_data_sources();
} }
#endif /* DATA_SOURCE_HH */ #endif /* DATA_SOURCE_HH */