2014-07-31 00:35:19 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#ifndef OSQUERY_REGISTRY_INIT_REGISTRY_H
|
|
|
|
#define OSQUERY_REGISTRY_INIT_REGISTRY_H
|
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
|
|
|
#include "osquery/registry/registry_template.h"
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
|
|
|
class InitRegistry : public RegistryTemplate<> {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Singleton.
|
|
|
|
*/
|
|
|
|
static InitRegistry& get() {
|
2014-08-15 07:25:30 +00:00
|
|
|
static InitRegistry instance; // Thread-safe.
|
2014-07-31 00:35:19 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-08-15 07:25:30 +00:00
|
|
|
InitRegistry() {}
|
2014-07-31 00:35:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The most standard way to register an init func is to use this class
|
|
|
|
* as a static instance in some file to ensure the function gets called
|
|
|
|
* once main actually begins.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
*
|
|
|
|
* static RegisterInitFunc reg1(&setupFancyTable);
|
|
|
|
* static RegisterInitFunc reg2(std::bind(&setupSomething, 10, 15));
|
|
|
|
* static RegisterInitFunc reg3([] { setupSomethingElse(20, 25); });
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct RegisterInitFunc : private boost::noncopyable {
|
|
|
|
explicit RegisterInitFunc(InitRegistry::Func func,
|
|
|
|
int priority = InitRegistry::kDefaultPriority) {
|
|
|
|
InitRegistry::get().registerFunc(std::move(func), priority);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
} // namespace osquery
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-05 23:13:55 +00:00
|
|
|
#endif /* OSQUERY_REGISTRY_INIT_REGISTRY_H */
|