manager: add status
Add a status field to assist keeping track of manager state.
STARTING - the manager is initializing
RUNNING - the manager event loop is running
STOPPING - the manager is shutting down
Remove the old _shutdown property and make use of _status == (or !=) STOPPING.
Change-Id: I8326cb164aba32f2d64bbf4fa0753932821571ff
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/manager.cpp b/manager.cpp
index 0aa2176..72a95d9 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -58,12 +58,12 @@
}
Manager::Manager(sdbusplus::bus::bus&& bus, const char* root) :
- ServerObject<ManagerIface>(bus, root), _shutdown(false), _root(root),
- _bus(std::move(bus)), _manager(_bus, root)
+ ServerObject<ManagerIface>(bus, root), _root(root), _bus(std::move(bus)),
+ _manager(_bus, root),
#ifdef CREATE_ASSOCIATIONS
- ,
- _associations(_bus)
+ _associations(_bus),
#endif
+ _status(ManagerStatus::STARTING)
{
for (auto& group : _events)
{
@@ -97,7 +97,7 @@
void Manager::shutdown() noexcept
{
- _shutdown = true;
+ _status = ManagerStatus::STOPPING;
}
void Manager::run(const char* busname)
@@ -116,8 +116,10 @@
}
}
+ _status = ManagerStatus::RUNNING;
_bus.request_name(busname);
- while (!_shutdown)
+
+ while (_status != ManagerStatus::STOPPING)
{
try
{
diff --git a/manager.hpp b/manager.hpp
index 3046024..ab1133c 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -183,9 +183,6 @@
ObjectReferences::iterator pos, bool emitSignals,
bool restoreFromCache);
- /** @brief Provided for testing only. */
- volatile bool _shutdown;
-
/** @brief Path prefix applied to any relative paths. */
const char* _root;
@@ -214,6 +211,9 @@
#ifdef CREATE_ASSOCIATIONS
associations::Manager _associations;
#endif
+
+ /** @brief Manager status indicator */
+ volatile enum class ManagerStatus { STARTING, RUNNING, STOPPING } _status;
};
} // namespace manager