diff --git a/Cpp/Executables/Main/Nymph.cc b/Cpp/Executables/Main/Nymph.cc index ac2b460..014fcf1 100644 --- a/Cpp/Executables/Main/Nymph.cc +++ b/Cpp/Executables/Main/Nymph.cc @@ -63,21 +63,28 @@ int main( int argc, char** argv ) // Start handling signals scarab::signal_handler t_sig_hand; + int the_return = -1; + // Create the application scarab::main_app the_main; + //Runs RunNymph() and sets the_return based on its return value + auto t_callback = [&](){ + // If any subcommands were called, we don't execute the main callback + if( the_main.get_subcommands().size() > 0 ) return; + the_return = Nymph::RunNymph( the_main.primary_config() ); + }; + the_main.callback( t_callback ); + + // Checks for the existence of a processor type and lists processors + scarab::config_decorator* t_proc_check = the_main.add_config_subcommand( "proc-check", "Check if a processor type is known" ); + t_proc_check->this_app()->callback( [&](){ the_return = Nymph::ProcessorCheck(the_main.primary_config()); } ); + the_main.require_subcommand(0, 1); the_main.set_global_verbosity(scarab::logger::ELevel::eDebug); // add the typical CL options Nymph::AddRunNymphOptions( the_main ); - - //Runs RunNymph() and sets the_return based on its return value - int the_return = -1; - auto t_callback = [&](){ - the_return = Nymph::RunNymph( the_main.primary_config() ); - }; - - the_main.callback( t_callback ); + Nymph::AddProcessorCheckOptions( t_proc_check ); // Parse CL options and run the application CLI11_PARSE( the_main, argc, argv ); diff --git a/Cpp/Library/Implementation/RunNymph.cc b/Cpp/Library/Implementation/RunNymph.cc index 3521d24..21196b9 100644 --- a/Cpp/Library/Implementation/RunNymph.cc +++ b/Cpp/Library/Implementation/RunNymph.cc @@ -69,4 +69,49 @@ namespace Nymph // options an_app.add_config_flag< bool >( "--dry-run", "dry-run", "Load the config, setup processors, but do not execute the run" ); } + + int ProcessorCheck( scarab::param_node& a_config ) + { + ProcessorToolbox tb; + + LWARN( nlog, a_config ); + + if( a_config.has( "list-procs" ) && a_config["list-procs"]().as_bool() ) + { + using factory_type = const scarab::factory< Processor, const std::string& >; + factory_type* t_factory = tb.ProcFactory(); + std::stringstream t_list_ss; + for( auto it = t_factory->begin(); it != t_factory->end(); ++it ) + { + t_list_ss << it->first << '\n'; + + } + LPROG( nlog, "Available processors:\n" << t_list_ss.str() ); + return RETURN_SUCCESS; + } + else + { + if( ! a_config.has( "proc-type" ) || a_config["proc-type"]().as_string().empty() ) + { + LERROR( nlog, "No processor type was provided to check" ); + return RETURN_ERROR; + } + std::string t_proc_type( a_config["proc-type"]().as_string() ); + bool t_proc_is_available = tb.CouldBuild( t_proc_type ); + if( ! t_proc_is_available ) + { + LWARN( nlog, "Processor <" << t_proc_type << "> is NOT registered with the processor toolbox" ); + return -1; + } + LPROG( nlog, "Processor <" << t_proc_type << "> is known to the processor toolbox" ); + return RETURN_SUCCESS; + } + } + + void AddProcessorCheckOptions( scarab::config_decorator* a_subcommand ) + { + // options + a_subcommand->add_config_option< std::string >( "proc-type", "proc-type", "Query Nymph to see if this processor type has been registered; returns 0 if present; -1 if not present" ); + a_subcommand->add_config_flag< bool >( "-l,--list-procs", "list-procs", "List available processors" ); + } } diff --git a/Cpp/Library/Implementation/RunNymph.hh b/Cpp/Library/Implementation/RunNymph.hh index aba61f4..9a6ad01 100644 --- a/Cpp/Library/Implementation/RunNymph.hh +++ b/Cpp/Library/Implementation/RunNymph.hh @@ -10,6 +10,7 @@ namespace scarab { + class config_decorator; class main_app; class param_node; } @@ -17,8 +18,10 @@ namespace scarab namespace Nymph { int RunNymph( scarab::param_node& config ); - void AddRunNymphOptions( scarab::main_app& an_app ); + + int ProcessorCheck( scarab::param_node& config ); + void AddProcessorCheckOptions( scarab::config_decorator* an_app ); } diff --git a/Cpp/Library/Processor/ProcessorToolbox.hh b/Cpp/Library/Processor/ProcessorToolbox.hh index c51283c..76ac86e 100644 --- a/Cpp/Library/Processor/ProcessorToolbox.hh +++ b/Cpp/Library/Processor/ProcessorToolbox.hh @@ -118,6 +118,8 @@ namespace Nymph /// Also clears the run queue void ClearProcessors(); + const scarab::factory< Processor, const std::string& >* ProcFactory() const; + protected: ProcessorMap fProcMap; @@ -177,5 +179,10 @@ namespace Nymph return MakeConnection(signalProcName, signalName, slotProcName, slotName, std::numeric_limits< int >::min()); } + inline const scarab::factory< Processor, const std::string& >* ProcessorToolbox::ProcFactory() const + { + return fProcFactory; + } + } /* namespace Nymph */ #endif /* NYMPH_PROCESSORTOOLBOX_HH_ */ diff --git a/Scarab b/Scarab index b899601..cb559e0 160000 --- a/Scarab +++ b/Scarab @@ -1 +1 @@ -Subproject commit b899601d9c5f6a81734b6bd78f3056a1bf52b708 +Subproject commit cb559e090c950f56a6ddb12d1ae1f10a338440e7