From abe43ab439bba463f4727a98ed0cc0c6a5e8251f Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Mon, 19 Feb 2018 13:34:43 -0600 Subject: Extend storage array to contain additional data This array was originally just an array of objects of type 'any'. This commit changes it to be an array of tuples of type to add an extra field for use by anything that needs it. For example, the storage is currently used to store property values, and a future change to the CountCondition class will now also store the result of the comparisons done between the property values and another value specified in the rule YAML. Then, a callback will be able to see the result of whether each property passed the check. Tested: Build and run unit tests Change-Id: I58f32c9f4068b15a02b1ff7f28871161cafebddb Signed-off-by: Matt Spinler --- src/count.hpp | 4 ++-- src/data_types.hpp | 5 +++-- src/event.hpp | 7 ++++--- src/journal.cpp | 5 +++-- src/propertywatchimpl.hpp | 3 ++- src/templates/generated.mako.hpp | 2 +- src/test/propertywatchtest.cpp | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/count.hpp b/src/count.hpp index 51a76eb..0ac6420 100644 --- a/src/count.hpp +++ b/src/count.hpp @@ -64,12 +64,12 @@ class CountCondition : public IndexedConditional const auto& storage = std::get<2>( item.second); // Don't count properties that don't exist. - if (storage.get().empty()) + if (std::get<0>(storage.get()).empty()) { return false; } const auto& value = any_ns::any_cast( - storage); + std::get<0>(storage.get())); return propertyOp(value); }); // *INDENT-ON* diff --git a/src/data_types.hpp b/src/data_types.hpp index 12d1d6d..f1512db 100644 --- a/src/data_types.hpp +++ b/src/data_types.hpp @@ -18,7 +18,8 @@ constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; constexpr auto pathIndex = 0; constexpr auto propertyIndex = 2; -constexpr auto valueIndex = 2; +constexpr auto storageIndex = 2; +constexpr auto valueIndex = 0; constexpr auto metaIndex = 1; enum class Context @@ -70,7 +71,7 @@ using PropertyIndex = TupleRefMap < TupleOfRefs< const std::string, const std::string, - any_ns::any>, + std::tuple>, const std::string, const std::string, const std::string >; diff --git a/src/event.hpp b/src/event.hpp index ad02986..b5f1e90 100644 --- a/src/event.hpp +++ b/src/event.hpp @@ -46,10 +46,11 @@ class EventBase : public IndexedCallback for (const auto& n : index) { const auto& path = std::get(n.first); - const auto& propertyMeta = std::get(n.first); - const auto& value = std::get(n.second); + const auto& propertyMeta = std::get(n.first); + const auto& storage = std::get(n.second); + const auto& value = std::get(storage.get()); - if (!value.get().empty()) + if (!value.empty()) { createEvent( path, diff --git a/src/journal.cpp b/src/journal.cpp index c348cfb..7069c74 100644 --- a/src/journal.cpp +++ b/src/journal.cpp @@ -29,9 +29,10 @@ void JournalBase::operator()(Context ctx) const auto& path = std::get<0>(n.first); const auto& pathMeta = std::get<0>(n.second); const auto& propertyMeta = std::get<1>(n.second); - const auto& value = std::get<2>(n.second); + const auto& storage = std::get<2>(n.second); + const auto& value = std::get<0>(storage.get()); - if (!value.get().empty()) + if (!value.empty()) { log(message, pathMeta, diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp index 43875b9..9fe57d5 100644 --- a/src/propertywatchimpl.hpp +++ b/src/propertywatchimpl.hpp @@ -146,7 +146,8 @@ void PropertyWatchOfType::propertiesChanged( continue; } - std::get<2>(item->second).get() = p.second.template get(); + std::get<0>(std::get<2>(item->second).get()) = + p.second.template get(); // Invoke callback if present. this->callback(Context::SIGNAL); diff --git a/src/templates/generated.mako.hpp b/src/templates/generated.mako.hpp index 4a5b87c..1b73198 100644 --- a/src/templates/generated.mako.hpp +++ b/src/templates/generated.mako.hpp @@ -93,7 +93,7 @@ struct ConfigProperties struct ConfigPropertyStorage { - using Storage = std::array; + using Storage = std::array, ${len(instances)}>; static auto& get() { diff --git a/src/test/propertywatchtest.cpp b/src/test/propertywatchtest.cpp index b92dbec..c97e8d3 100644 --- a/src/test/propertywatchtest.cpp +++ b/src/test/propertywatchtest.cpp @@ -27,7 +27,7 @@ const std::array properties = const std::string meta; -std::array storage = { }; +std::array, 8> storage = { }; const PropertyIndex watchIndex = { @@ -204,7 +204,7 @@ void testStart() ndx = 0; for (auto s : storage) { - ASSERT_EQ(s.empty(), false); + ASSERT_EQ(std::get<0>(s).empty(), false); ASSERT_EQ(any_ns::any_cast(s), ExpectedValues::get(ndx)); ++ndx; } -- cgit v1.2.1