Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Cpp/Executables/Main/Nymph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
45 changes: 45 additions & 0 deletions Cpp/Library/Implementation/RunNymph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}
5 changes: 4 additions & 1 deletion Cpp/Library/Implementation/RunNymph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

namespace scarab
{
class config_decorator;
class main_app;
class param_node;
}

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 );
}


Expand Down
7 changes: 7 additions & 0 deletions Cpp/Library/Processor/ProcessorToolbox.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_ */