mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
registry docs
This commit is contained in:
parent
3ca56b42a9
commit
1f42458bfb
@ -1,4 +1,4 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -14,28 +14,40 @@
|
||||
|
||||
namespace osquery {
|
||||
|
||||
// A simple registry system for making values available by key across
|
||||
// components.
|
||||
//
|
||||
// To use this registry, make a header like so:
|
||||
//
|
||||
// #include "osquery/registry.h"
|
||||
//
|
||||
// DECLARE_REGISTRY(MathFuncs, int, std::function<double(double)>)
|
||||
// #define REGISTERED_MATH_FUNCS REGISTRY(MathFuncs)
|
||||
// #define REGISTER_MATH_FUNC(id, func) \
|
||||
// REGISTER(MathFuncs, id, func)
|
||||
//
|
||||
// Client code may then advertise an entry from a .cpp like so:
|
||||
// #include "my/registry/header.h"
|
||||
// REGISTER_MATH_FUNC(1, sqrt);
|
||||
//
|
||||
// Server code may then access the set of registered values by using
|
||||
// REGISTERED_MATH_FUNCS as a map, which will be populated after
|
||||
// osquery::InitRegistry::get().run() has been called.
|
||||
/** @brief A simple registry system for making values available by key across
|
||||
* components.
|
||||
*
|
||||
* To use this registry, make a header like so:
|
||||
*
|
||||
* @code{.cpp}
|
||||
* #include "osquery/registry.h"
|
||||
*
|
||||
* DECLARE_REGISTRY(MathFuncs, int, std::function<double(double)>)
|
||||
* #define REGISTERED_MATH_FUNCS REGISTRY(MathFuncs)
|
||||
* #define REGISTER_MATH_FUNC(id, func) \
|
||||
* REGISTER(MathFuncs, id, func)
|
||||
* @endcode
|
||||
*
|
||||
* Client code may then advertise an entry from a .cpp like so:
|
||||
*
|
||||
* @code{.cpp}
|
||||
* #include "my/registry/header.h"
|
||||
* REGISTER_MATH_FUNC(1, sqrt);
|
||||
* @endcode
|
||||
*
|
||||
* Server code may then access the set of registered values by using
|
||||
* `REGISTERED_MATH_FUNCS` as a map, which will be populated after
|
||||
* `osquery::InitRegistry::get().run()` has been called.
|
||||
*/
|
||||
template <class Key, class Value>
|
||||
class Registry : public std::unordered_map<Key, Value> {
|
||||
public:
|
||||
/** @brief Register a value in the global registry
|
||||
*
|
||||
* This is used internally by the `DECLARE_REGISTRY` registration workflow.
|
||||
* If you're calling this method directly, you're probably doing something
|
||||
* incorrectly.
|
||||
*/
|
||||
void registerValue(const Key& key,
|
||||
const Value& value,
|
||||
const char* displayName = "registry") {
|
||||
@ -55,7 +67,7 @@ class Registry : public std::unordered_map<Key, Value> {
|
||||
namespace registries { \
|
||||
class registryName : public Registry<KeyType, ObjectType> {}; \
|
||||
} \
|
||||
} // osquery::registries
|
||||
} * osquery::registries
|
||||
|
||||
#define REGISTRY(registryName) \
|
||||
(osquery::Singleton<osquery::registries::registryName>::get())
|
||||
|
Loading…
Reference in New Issue
Block a user