Example Standalone Application#
The sdv::app::CAppControl class is used to switch between startup/configuration/running phases and to load configuration files. Afterwards it is possible to access all loaded objects and interfaces.
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
The location of the framework runtime directory can be set via environment variables. If there is no environment variable set, the framework runtime directory must be set.
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
After startup where it is possible to set the first Config File, the configuration mode should be set. After loading all Config File entries, the running mode should be set. For a proper shutdown, Shutdown should be called before ending the application.
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
To find all required VAPI Component and Config File the corresponding folders can be added to the list of folders where the system searches for the files.
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
During configuration mode multiple config files can be loaded.
#include <iostream>
#include <support/app_control.h>
#include "example_interfaces.h"
#include "example_reception_interfaces.h"
#include "example_transfer_interfaces.h"
/**
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
* @return Return true if environment variable is found otherwise false
*/
bool IsSDVFrameworkEnvironmentSet()
{
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
if (envVariable)
{
return true;
}
return false;
}
#if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain()
#else
extern "C" int main()
#endif
{
sdv::app::CAppControl appcontrol;
if (!IsSDVFrameworkEnvironmentSet())
{
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
}
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
bResult &= appcontrol.Startup("");
appcontrol.SetConfigMode();
bResult &= appcontrol.AddConfigSearchDir("config");
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
if (!bResult)
{
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
appcontrol.Shutdown();
return 0;
}
appcontrol.SetRunningMode();
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
if (!hello1 || !bye1 || !hello2 || !bye2)
{
hello1->SayHello();
bye1->SayGoodbye();
hello2->SayHello();
bye2->SayGoodbye();
}
else
{
std::cout << "Could not get all interfaces interface" << std::endl;
}
appcontrol.Shutdown();
return 0;
}
After setting the running mode, loaded objects and interfaces can be used. For safety reasons, changes to the configuration should not be made in running mode.