mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
Add a function for retrieving registered data sources
This commit is contained in:
parent
109770ac31
commit
8fe39ab39b
@ -28,7 +28,6 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
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<std::string, data_source_factory> 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<int>::factory,
|
||||
std::placeholders::_1, std::placeholders::_2, &asdf_)
|
||||
);
|
||||
|
||||
conky::register_disabled_data_source zxcv("zxcv", "BUILD_ZXCV");
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
|
||||
#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<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.
|
||||
@ -102,6 +105,11 @@ namespace conky {
|
||||
public:
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user