Moved configuration handling into cli handler code
Cleanup: moved the updating of configuration object to
command line handling code to remove some single-use booleans.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I503e72c07b35a1537d93241a26a92f87854ba105
diff --git a/attn/attn_config.cpp b/attn/attn_config.cpp
index caee221..e2d4a72 100644
--- a/attn/attn_config.cpp
+++ b/attn/attn_config.cpp
@@ -4,10 +4,9 @@
{
/** @brief Main constructor */
-Config::Config(bool i_vital, bool i_checkstop, bool i_terminate,
- bool i_breakpoints)
+Config::Config()
{
- setConfig(i_vital, i_checkstop, i_terminate, i_breakpoints);
+ setFlagAll();
}
/** @brief Get state of flag */
@@ -22,26 +21,28 @@
iv_flags.set(i_flag);
}
+/** @brief Set all configuration flags */
+void Config::setFlagAll()
+{
+ iv_flags.set(enVital);
+ iv_flags.set(enCheckstop);
+ iv_flags.set(enTerminate);
+ iv_flags.set(enBreakpoints);
+}
+
/** @brief Clear configuration flag */
void Config::clearFlag(AttentionFlag i_flag)
{
iv_flags.reset(i_flag);
}
-/** @brief Set state of all configuration data */
-void Config::setConfig(bool i_vital, bool i_checkstop, bool i_terminate,
- bool i_breakpoints)
+/** @brief Clear all configuration flags */
+void Config::clearFlagAll()
{
- (true == i_vital) ? iv_flags.set(enVital) : iv_flags.reset(enVital);
-
- (true == i_checkstop) ? iv_flags.set(enCheckstop)
- : iv_flags.reset(enCheckstop);
-
- (true == i_terminate) ? iv_flags.set(enTerminate)
- : iv_flags.reset(enTerminate);
-
- (true == i_breakpoints) ? iv_flags.set(enBreakpoints)
- : iv_flags.reset(enBreakpoints);
+ iv_flags.reset(enVital);
+ iv_flags.reset(enCheckstop);
+ iv_flags.reset(enTerminate);
+ iv_flags.reset(enBreakpoints);
}
} // namespace attn
diff --git a/attn/attn_config.hpp b/attn/attn_config.hpp
index ec8013b..32f885e 100644
--- a/attn/attn_config.hpp
+++ b/attn/attn_config.hpp
@@ -19,20 +19,7 @@
{
public: // methods
/** @brief Default constructor */
- Config() = delete;
-
- /** @brief Crate configuration object
- *
- * Create a configuration object to hold the attention handler
- * configuration data
- *
- * @param i_vital Enable vital attention handling
- * @param i_checkstop Enable checkstop attention handling
- * @param i_terminate Enable TI attention handling
- * @param i_+breakpoint Enable breakpoint attention handling
- */
- Config(bool i_vital, bool i_checkstop, bool i_terminate,
- bool i_breakpoints);
+ Config();
/** @brief Default destructor */
~Config() = default;
@@ -43,9 +30,15 @@
/** @brief Set configuration flag */
void setFlag(AttentionFlag i_flag);
+ /** @brief Set all configuration flags */
+ void setFlagAll();
+
/** @brief Clear configuration flag */
void clearFlag(AttentionFlag i_flag);
+ /** @brief Clear all configuration flags */
+ void clearFlagAll();
+
/** @brief Set state of all configuration data */
void setConfig(bool i_vital, bool i_checkstop, bool i_terminate,
bool i_breakpoints);
diff --git a/cli.cpp b/cli.cpp
index 4ace713..3fcff3a 100644
--- a/cli.cpp
+++ b/cli.cpp
@@ -1,3 +1,5 @@
+#include <attn/attn_config.hpp>
+
#include <algorithm>
#include <string>
@@ -15,8 +17,7 @@
}
/** @brief Parse command line for configuration flags */
-void parseConfig(char** i_begin, char** i_end, bool& o_vital, bool& o_checkstop,
- bool& o_terminate, bool& o_breakpoints)
+void parseConfig(char** i_begin, char** i_end, attn::Config* o_config)
{
char* setting;
@@ -26,18 +27,12 @@
{
if (std::string("off") == setting)
{
- o_vital = false;
- o_checkstop = false;
- o_terminate = false;
- o_breakpoints = false;
+ o_config->clearFlagAll();
}
if (std::string("on") == setting)
{
- o_vital = true;
- o_checkstop = true;
- o_terminate = true;
- o_breakpoints = true;
+ o_config->setFlagAll();
}
}
// Parse individual options
@@ -46,41 +41,41 @@
setting = getCliSetting(i_begin, i_end, "--vital");
if (std::string("off") == setting)
{
- o_vital = false;
+ o_config->clearFlag(attn::enVital);
}
if (std::string("on") == setting)
{
- o_vital = true;
+ o_config->setFlag(attn::enVital);
}
setting = getCliSetting(i_begin, i_end, "--checkstop");
if (std::string("off") == setting)
{
- o_checkstop = false;
+ o_config->clearFlag(attn::enCheckstop);
}
if (std::string("on") == setting)
{
- o_checkstop = true;
+ o_config->setFlag(attn::enCheckstop);
}
setting = getCliSetting(i_begin, i_end, "--terminate");
if (std::string("off") == setting)
{
- o_terminate = false;
+ o_config->clearFlag(attn::enTerminate);
}
if (std::string("on") == setting)
{
- o_terminate = true;
+ o_config->setFlag(attn::enTerminate);
}
setting = getCliSetting(i_begin, i_end, "--breakpoints");
if (std::string("off") == setting)
{
- o_breakpoints = false;
+ o_config->clearFlag(attn::enBreakpoints);
}
if (std::string("on") == setting)
{
- o_breakpoints = true;
+ o_config->setFlag(attn::enBreakpoints);
}
}
}
diff --git a/cli.hpp b/cli.hpp
index f046b8c..6ae4e63 100644
--- a/cli.hpp
+++ b/cli.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <attn/attn_config.hpp>
+
#include <string>
/*
@@ -28,12 +30,11 @@
*
* @brief Get configuration flags from command line
*
+ * Parse the command line for configuration options and update the
+ * attention handler configuration object as needed.
+ *
* @param i_begin command line args vector begin
* @param i_end command line args vector end
- * @param i_vital vital handler enable option
- * @param i_checkatop checkstop handler enable option
- * @param i_terminate TI handler enable option
- * @param i_breakpoints breakpoint handler enable option
+ * @param o_config pointer to attention handler configuration object
*/
-void parseConfig(char** i_begin, char** i_end, bool& i_vital, bool& i_checkstop,
- bool& i_terminate, bool& i_breakpoints);
+void parseConfig(char** i_begin, char** i_end, attn::Config* o_config);
diff --git a/listener.cpp b/listener.cpp
index c8ae642..e0640aa 100644
--- a/listener.cpp
+++ b/listener.cpp
@@ -39,10 +39,6 @@
{
using namespace boost::interprocess;
- // convert thread params to main arguments
- int argc = static_cast<MainArgs_t*>(i_params)->argc;
- char** argv = static_cast<MainArgs_t*>(i_params)->argv;
-
// vector to hold messages sent to listener
std::vector<std::string> messages;
@@ -55,19 +51,8 @@
// status of gpio monitor
bool gpioMonEnabled = false;
- // Parse command line args to see if any flags were passed, update the
- // booleans accordingly and pass them to the config object constructor.
- bool vital_enable = true;
- bool checkstop_enable = true;
- bool ti_enable = true;
- bool bp_enable = true;
-
- // parse config options
- parseConfig(argv, argv + argc, vital_enable, checkstop_enable, ti_enable,
- bp_enable);
-
// create config
- attn::Config config(vital_enable, checkstop_enable, ti_enable, bp_enable);
+ attn::Config attnConfig;
// initialize pdbg targets
pdbg_targets_init(nullptr);
@@ -124,12 +109,7 @@
}
// parse config options
- parseConfig(argv.data(), argv.data() + argc, vital_enable,
- checkstop_enable, ti_enable, bp_enable);
-
- // set config
- config.setConfig(vital_enable, checkstop_enable, ti_enable,
- bp_enable);
+ parseConfig(argv.data(), argv.data() + argc, &attnConfig);
// start attention handler daemon?
if (true ==
@@ -138,7 +118,7 @@
if (false == gpioMonEnabled)
{
if (0 == pthread_create(&ptidGpio, NULL, &threadGpioMon,
- &config))
+ &attnConfig))
{
gpioMonEnabled = true;
}
diff --git a/test/end2end/main.cpp b/test/end2end/main.cpp
index fe637f6..c523842 100644
--- a/test/end2end/main.cpp
+++ b/test/end2end/main.cpp
@@ -9,24 +9,17 @@
{
int rc = 0; // return code
- // attention handler configuration flags
- bool vital_enable = true;
- bool checkstop_enable = true;
- bool ti_enable = true;
- bool bp_enable = true;
-
// initialize pdbg targets
pdbg_targets_init(nullptr);
- // convert cmd line args to config values
- parseConfig(argv, argv + argc, vital_enable, checkstop_enable, ti_enable,
- bp_enable);
-
// create attention handler config object
- attn::Config config(vital_enable, checkstop_enable, ti_enable, bp_enable);
+ attn::Config attnConfig;
+
+ // convert cmd line args to config values
+ parseConfig(argv, argv + argc, &attnConfig);
// exercise attention gpio event path
- attn::attnHandler(&config);
+ attn::attnHandler(&attnConfig);
return rc;
}