Skip to content

Commit

Permalink
fixup! fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusBgm committed Nov 6, 2024
1 parent 488f29a commit ddcb5eb
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions Demos/include/SilKitApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SilKitApplication

// SIL Kit API
std::shared_ptr<Config::IParticipantConfiguration> participantConfiguration_;
std::shared_ptr<IParticipant> participant_;
std::unique_ptr<IParticipant> participant_;
ILifecycleService* lifecycleService_{nullptr};
ITimeSyncService* timeSyncService_{nullptr};

Expand All @@ -51,36 +51,31 @@ class SilKitApplication

// Configuration
std::string participantName_;
CommandlineParser cli_;

private:

void ParseArguments(int argc, char**argv)
{

CommandlineParser commandlineParser;
commandlineParser.Add<CommandlineParser::Flag>("async", "a", "[--async]", "-a, --async: run in asynchronous mode.");
commandlineParser.Add<CommandlineParser::Option>("registry-uri", "u", "silkit://localhost:8500", "[--registry-uri <silkitUri>]",
"-u, --registry-uri <silkitUri>: The 'silkit://' URI of the registry.");

try
{
commandlineParser.ParseArguments(argc, argv);
cli_.ParseArguments(argc, argv);
}
catch (const std::exception& e)
{
std::cerr << "Error: " << e.what() << std::endl;
commandlineParser.PrintUsageInfo(std::cerr, argv[0]);
cli_.PrintUsageInfo(std::cerr, argv[0]);

exit(-1);
}

if (commandlineParser.Get<CommandlineParser::Flag>("async").Value())
if (cli_.Get<CommandlineParser::Flag>("async").Value())
{
arguments_.runAsync = true;
}
if (commandlineParser.Get<CommandlineParser::Option>("registry-uri").HasValue())
if (cli_.Get<CommandlineParser::Option>("registry-uri").HasValue())
{
arguments_.registryUri = commandlineParser.Get<CommandlineParser::Option>("registry-uri").HasValue();
arguments_.registryUri = cli_.Get<CommandlineParser::Option>("registry-uri").HasValue();
}
}

Expand Down Expand Up @@ -114,6 +109,8 @@ class SilKitApplication
lifecycleService_->SetShutdownHandler(std::bind(&SilKitApplication::ShutdownHandler, this));
lifecycleService_->SetAbortHandler(std::bind(&SilKitApplication::AbortHandler, this));

lifecycleService_->SetCommunicationReadyHandler(std::bind(&SilKitApplication::OnCommunicationReady, this));


if (arguments_.runAsync)
{
Expand All @@ -123,7 +120,6 @@ class SilKitApplication
}
else
{
lifecycleService_->SetCommunicationReadyHandler(std::bind(&SilKitApplication::OnCommunicationReady, this));
timeSyncService_ = lifecycleService_->CreateTimeSyncService();
timeSyncService_->SetSimulationStepHandler(std::bind(&SilKitApplication::SimulationStepHandler, this, std::placeholders::_1, std::placeholders::_2), 1ms);
}
Expand Down Expand Up @@ -221,29 +217,39 @@ class SilKitApplication
return participantName_;
}

CommandlineParser& GetCli() // TODO naming is botched
{
return cli_;
}

public:
SilKitApplication() = default;
SilKitApplication(std::string participantName)
SilKitApplication(std::string participantName)//TODO SilKitApplication(int argc, char** argv)
: participantName_{std::move(participantName)}
{

cli_.Add<CommandlineParser::Flag>("async", "a", "[--async]", "-a, --async: run in asynchronous mode.");
cli_.Add<CommandlineParser::Option>("registry-uri", "u", "silkit://localhost:8500", "[--registry-uri <silkitUri>]",
"-u, --registry-uri <silkitUri>: The 'silkit://' URI of the registry.");
}

virtual ~SilKitApplication() = default;

int Main(int argc, char** argv)
{
try
{
//SpecifyArguments();
ParseArguments(argc, argv);

Setup();
OnSetup();
SetupDone();
Setup(); // generic SIL Kit initialization
OnSetup(); // user supplied initialization
SetupDone(); // starting of operations

WaitUntilDone();
WaitUntilDone(); // let the simulation run in a different thread

OnTeardown();
TearDown();
OnTeardown(); // stop all services and controllers
TearDown(); //clean up resources

return mainResult;
}
Expand Down

0 comments on commit ddcb5eb

Please sign in to comment.