Example Standalone Application#
The sdv::app::CAppControl class allows to set the EObjectStatus mode and to load configuration files. Afterwards its 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 its possible to set the first Config File the configuration mode``should be set. After loading of all :term:`Config File` the ``running mode
should be set. For a proper shutdown the 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 of the running mode
the objects and interfaces if available can be used. For safety reasn changes to the configuration cannot be made in running mode., e.g. the timer service cannot create a timer, it will fail.