mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-07-02 05:35:11 +00:00
Update sdv_packager (#6)
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
#*******************************************************************************
|
||||
# Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
#
|
||||
# This program and the accompanying materials are made available under the
|
||||
# terms of the Apache License Version 2.0 which is available at
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# Erik Verhoeven - initial API and implementation
|
||||
#*******************************************************************************
|
||||
|
||||
# Define project
|
||||
project(RepositoryTests VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
@@ -10,7 +23,7 @@ message("Use IDL compiler: ${SDVIDL}")
|
||||
|
||||
# Compile the IDL
|
||||
add_custom_command(
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/generated/test_component.h
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/generated/test_component.h ${PROJECT_SOURCE_DIR}/generated/ps/proxystub.cpp ${PROJECT_SOURCE_DIR}/generated/serdes/test_component_serdes.h
|
||||
DEPENDS sdv_idl_compiler
|
||||
MAIN_DEPENDENCY test_component.idl
|
||||
COMMENT "Build test_component.idl"
|
||||
@@ -19,9 +32,10 @@ add_custom_command(
|
||||
)
|
||||
|
||||
set_source_files_properties(test_component_ps.cpp OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/generated/test_component.h)
|
||||
set_source_files_properties(test_component_ps.cpp OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/generated/ps/proxystub.cpp)
|
||||
set_source_files_properties(test_component_ps.cpp OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/generated/serdes/test_component_serdes.h)
|
||||
set_source_files_properties(test_component.cpp OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/generated/test_component.h)
|
||||
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(ComponentTest_Repository_ps SHARED
|
||||
"test_component_ps.cpp"
|
||||
@@ -43,9 +57,7 @@ set_target_properties(ComponentTest_Repository_test_module PROPERTIES SUFFIX ".s
|
||||
|
||||
# Execute the installation helper utility to create an installation manifest for the core files.
|
||||
add_custom_target(ComponentTest_Repository_install_manifest
|
||||
# TODO EVE
|
||||
# COMMAND "$<TARGET_FILE:sdv_packager>" -O. --instance2005 -NComponentTest_Repository "$<TARGET_FILE:ComponentTest_Repository_test_module>" "$<TARGET_FILE:ComponentTest_Repository_ps>" "-I$<TARGET_FILE_DIR:ComponentTest_Repository_test_module>" --settings --create_configtest.toml --exclude_config_class"TestObject_CreateChain" --exclude_config_class"TestObject_CreateChainLock" --exclude_config_class"TestObject_CreateChainLockThread" --exclude_config_class"TestObject_CreateDuringShutdown" --exclude_config_class"TestObject_IObjectControlFail"
|
||||
COMMAND "$<TARGET_FILE:sdv_packager>" DIRECT_INSTALL ComponentTest_Repository --instance2005 "$<TARGET_FILE:ComponentTest_Repository_test_module>" "$<TARGET_FILE:ComponentTest_Repository_ps>" "-I$<TARGET_FILE_DIR:ComponentTest_Repository_test_module>" --overwrite --user_config
|
||||
COMMAND "$<TARGET_FILE:sdv_packager>" DIRECT_INSTALL ComponentTest_Repository -T. --instance2005 "$<TARGET_FILE:ComponentTest_Repository_test_module>" "$<TARGET_FILE:ComponentTest_Repository_ps>" "-I$<TARGET_FILE_DIR:ComponentTest_Repository_test_module>" --overwrite --user_config+TestObject_ComplexHelloService+TestObject_HelloUtility --interface_config+Example_Object+Example_Object_2+TestObject_HelloDevice+TestObject_BasicHelloService+TestObject_SystemHelloService
|
||||
DEPENDS ComponentTest_Repository_test_module ComponentTest_Repository_ps
|
||||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
||||
)
|
||||
@@ -53,7 +65,7 @@ add_custom_target(ComponentTest_Repository_install_manifest
|
||||
# Define target
|
||||
add_executable(ComponentTest_Repository
|
||||
"repository_test.cpp"
|
||||
"isolation_test.cpp"
|
||||
"isolation_test.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(ComponentTest_Repository ${CMAKE_DL_LIBS} GTest::GTest)
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/sdv_core.h>
|
||||
@@ -39,9 +52,8 @@ ViewFilter = "Fatal"
|
||||
Mode = "Main"
|
||||
Instance = 2005
|
||||
)code");
|
||||
|
||||
if (!bRet)
|
||||
std::cout << "Failed to start the application for instance 1234." << std::endl;
|
||||
std::cout << "Failed to start the application for instance 2005." << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +65,7 @@ Instance = 2005
|
||||
}
|
||||
};
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedSystemService)
|
||||
TEST_F(CIsolatedComponentTest, LoadNonIsolatedSystemService)
|
||||
{
|
||||
// Load the hello system service
|
||||
IHello* pHello = sdv::core::GetObject<IHello>("TestObject_SystemHelloService");
|
||||
@@ -67,9 +77,7 @@ TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedSystemService)
|
||||
EXPECT_EQ(tPID, GetProcessID()); // Runs in main process
|
||||
}
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedDevice)
|
||||
TEST_F(CIsolatedComponentTest, LoadNonIsolatedDevice)
|
||||
{
|
||||
// Load the hello device
|
||||
IHello* pHello = sdv::core::GetObject<IHello>("TestObject_HelloDevice");
|
||||
@@ -81,9 +89,7 @@ TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedDevice)
|
||||
EXPECT_EQ(tPID, GetProcessID()); // Runs in main process
|
||||
}
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedBasicService)
|
||||
TEST_F(CIsolatedComponentTest, LoadNonIsolatedBasicService)
|
||||
{
|
||||
// Load the hello basic service
|
||||
IHello* pHello = sdv::core::GetObject<IHello>("TestObject_BasicHelloService");
|
||||
@@ -95,9 +101,7 @@ TEST_F(CIsolatedComponentTest, DISABLED_LoadNonIsolatedBasicService)
|
||||
EXPECT_EQ(tPID, GetProcessID()); // Runs in main process
|
||||
}
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST_F(CIsolatedComponentTest, DISABLED_LoadIsolatedComplexService)
|
||||
TEST_F(CIsolatedComponentTest, LoadIsolatedComplexService)
|
||||
{
|
||||
// Load the hello basic service
|
||||
IHello* pHello = sdv::core::GetObject<IHello>("TestObject_ComplexHelloService");
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <interfaces/repository.h>
|
||||
#include <support/local_service_access.h>
|
||||
@@ -29,38 +42,43 @@ public:
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig) override
|
||||
{
|
||||
FAIL() << "Error: Initialize should not be called by Repo Service!";
|
||||
// m_eObjectStatus = sdv::EObjectStatus::initialization_failure;
|
||||
// m_eObjectState = sdv::EObjectState::initialization_failure;
|
||||
}
|
||||
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
virtual sdv::EObjectState GetObjectState() const override
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
return m_eObjectState;
|
||||
}
|
||||
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
virtual void SetOperationMode(sdv::EOperationMode eMode) override
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
m_eObjectState = sdv::EObjectState::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
m_eObjectState = sdv::EObjectState::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Shutdown()
|
||||
virtual sdv::u8string GetObjectConfig() const override
|
||||
{
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
return {};
|
||||
}
|
||||
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
virtual void Shutdown() override
|
||||
{
|
||||
m_eObjectState = sdv::EObjectState::destruction_pending;
|
||||
}
|
||||
|
||||
sdv::EObjectState m_eObjectState = sdv::EObjectState::initialization_pending;
|
||||
};
|
||||
|
||||
TEST(RepositoryTest, LoadNonexistentModule)
|
||||
@@ -366,7 +384,7 @@ Mode = "Essential"
|
||||
|
||||
ASSERT_TRUE(pModuleControl->Load((GetExecDirectory() / "ComponentTest_Repository_test_module.sdv").generic_u8string()));
|
||||
|
||||
bool bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", nullptr, "ChainedObject");
|
||||
bool bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", nullptr, "chained_object = \"ChainedObject\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("TestObject_CreateChain"));
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("ChainedObject"));
|
||||
@@ -404,7 +422,8 @@ Mode = "Essential"
|
||||
for (uint32_t i = 0; i < LoopCount; ++i)
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
bool bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Bar_" + count, "BarFoo_" + count);
|
||||
bool bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Bar_" + count,
|
||||
"chained_object = \"BarFoo_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("BarFoo_" + count));
|
||||
}
|
||||
@@ -413,7 +432,8 @@ Mode = "Essential"
|
||||
for (uint32_t i = 0; i < LoopCount; ++i)
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
bool bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count, "FooBar_" + count);
|
||||
bool bRes =
|
||||
pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count, "chained_object =\"FooBar_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("FooBar_" + count));
|
||||
}
|
||||
@@ -460,7 +480,8 @@ Mode = "Essential"
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
//locks using TestLockService during construction
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChainLock", "Bar_" + count, "BarFoo_" + count);
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChainLock", "Bar_" + count,
|
||||
"chained_object = \"BarFoo_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("BarFoo_" + count));
|
||||
}
|
||||
@@ -470,7 +491,8 @@ Mode = "Essential"
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
pLock->Lock();
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count, "FooBar_" + count);
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count,
|
||||
"chained_object = \"FooBar_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("FooBar_" + count));
|
||||
pLock->Unlock();
|
||||
@@ -518,7 +540,8 @@ Mode = "Essential"
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
//locks using TestLockService during construction in a seperate thread
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChainLockThread", "Bar_" + count, "BarFoo_" + count);
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChainLockThread", "Bar_" + count,
|
||||
"chained_object = \"BarFoo_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("BarFoo_" + count));
|
||||
}
|
||||
@@ -528,7 +551,8 @@ Mode = "Essential"
|
||||
{
|
||||
std::string count = std::to_string(i);
|
||||
pLock->Lock();
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count, "FooBar_" + count);
|
||||
bRes = pRepositoryControl->CreateObject("TestObject_CreateChain", "Foo_" + count,
|
||||
"chained_object = \"FooBar_" + count + "\"");
|
||||
EXPECT_TRUE(bRes);
|
||||
EXPECT_NE(nullptr, pObjectAccess->GetObject("FooBar_" + count));
|
||||
pLock->Unlock();
|
||||
@@ -593,9 +617,7 @@ Mode = "Essential"
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST(RepositoryTest, DISABLED_MainApplication_GetInstalledAndLoadedComponent)
|
||||
TEST(RepositoryTest, MainApplication_GetInstalledAndLoadedComponent)
|
||||
{
|
||||
// Start the app control. The application automatically loads the installation manifests and the application configuration,
|
||||
// starting automatically the objects.
|
||||
@@ -618,9 +640,7 @@ Instance = 2005
|
||||
control.Shutdown();
|
||||
}
|
||||
|
||||
// TODO EVE: Disabled until the implementation of configuration installation is finished. See
|
||||
// https://dev.azure.com/SW4ZF/AZP-431_DivDI_Vehicle_API/_workitems/edit/705891
|
||||
TEST(RepositoryTest, DISABLED_MainApplication_GetInstalledComponent)
|
||||
TEST(RepositoryTest, MainApplication_GetInstalledComponent)
|
||||
{
|
||||
// Start the app control. The application automatically loads the installation manifests, but since there is no application
|
||||
// configuration, it doesn't load the objects.
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
@@ -27,7 +40,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(ITestLock)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestLockService")
|
||||
|
||||
void Lock() override
|
||||
@@ -49,88 +62,26 @@ DEFINE_SDV_OBJECT(CTestLockService)
|
||||
/**
|
||||
* @brief Example component testing IObjectControl
|
||||
*/
|
||||
class CTestObjectControl
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectControl : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
~CTestObjectControl()
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::destruction_pending);
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Example_Object")
|
||||
|
||||
/**
|
||||
* @brief Initialize method. On success, a subsequent call to GetStatus returns EObjectStatus::running
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown method called before the object is destroyed.
|
||||
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
|
||||
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
|
||||
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
|
||||
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectControl)
|
||||
@@ -138,87 +89,26 @@ DEFINE_SDV_OBJECT(CTestObjectControl)
|
||||
/**
|
||||
* @brief Example component testing IObjectControl - 2nd component to test duplicate instantiation
|
||||
*/
|
||||
class CTestObjectControl2
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectControl2 : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
~CTestObjectControl2()
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::destruction_pending);
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Example_Object_2")
|
||||
|
||||
/**
|
||||
* @brief Initialize method. On success, a subsequent call to GetStatus returns EObjectStatus::running
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown method called before the object is destroyed.
|
||||
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
|
||||
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
|
||||
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
|
||||
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectControl2)
|
||||
@@ -226,70 +116,26 @@ DEFINE_SDV_OBJECT(CTestObjectControl2)
|
||||
/**
|
||||
* @brief Example component testing IObjectControl
|
||||
*/
|
||||
class CTestObjectControlFail
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectControlFail : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_IObjectControlFail")
|
||||
|
||||
/**
|
||||
* @brief Initialize method. On success, a subsequent call to GetStatus returns EObjectStatus::running
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown method called before the object is destroyed.
|
||||
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
|
||||
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
|
||||
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
|
||||
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectControlFail)
|
||||
@@ -297,95 +143,45 @@ DEFINE_SDV_OBJECT(CTestObjectControlFail)
|
||||
/**
|
||||
* @brief Example component testing chained object creation in Initialize
|
||||
*/
|
||||
class CTestObjectCreate
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectCreate : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_CreateChain")
|
||||
|
||||
BEGIN_SDV_PARAM_MAP()
|
||||
SDV_PARAM_ENTRY(m_ssChainedObject, "chained_object", "", "", "Name of the chained object")
|
||||
END_SDV_PARAM_MAP()
|
||||
|
||||
/**
|
||||
* @brief Initialize method. On success, a subsequent call to GetStatus returns EObjectStatus::running
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual void Initialize( const sdv::u8string& ssObjectConfig)
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
|
||||
//create new example object with name ssObjectConfig
|
||||
|
||||
auto pRepo = sdv::core::GetObject("RepositoryService");
|
||||
ASSERT_TRUE(pRepo);
|
||||
if (!pRepo) return false;
|
||||
|
||||
auto pCreate = sdv::TInterfaceAccessPtr(pRepo).GetInterface<sdv::core::IRepositoryControl>();
|
||||
ASSERT_TRUE(pCreate);
|
||||
if (!pCreate) return false;
|
||||
|
||||
ASSERT_FALSE(ssObjectConfig.empty());
|
||||
if (m_ssChainedObject.empty())
|
||||
return false;
|
||||
|
||||
ASSERT_TRUE(pCreate->CreateObject("Example_Object", ssObjectConfig,nullptr));
|
||||
if (!pCreate->CreateObject("Example_Object", m_ssChainedObject, nullptr))
|
||||
return false;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown method called before the object is destroyed.
|
||||
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
|
||||
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
|
||||
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
|
||||
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
std::string m_ssChainedObject; ///< Name of the chained object
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectCreate)
|
||||
@@ -393,31 +189,26 @@ DEFINE_SDV_OBJECT(CTestObjectCreate)
|
||||
/**
|
||||
* @brief Example component testing chained object creation in Initialize while holding a lock
|
||||
*/
|
||||
class CTestObjectCreateLock
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectCreateLock: public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_CreateChainLock")
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
virtual void Initialize(const sdv::u8string& ssObjectConfig)
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
BEGIN_SDV_PARAM_MAP()
|
||||
SDV_PARAM_ENTRY(m_ssChainedObject, "chained_object", "", "", "Name of the chained object")
|
||||
END_SDV_PARAM_MAP()
|
||||
|
||||
/**
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
//create new example object with name ssObjectConfig while holding lock
|
||||
|
||||
auto pLock = sdv::core::GetObject<ITestLock>("TestLockService");
|
||||
ASSERT_NE(pLock,nullptr);
|
||||
if (!pLock) return false;
|
||||
|
||||
struct SAutoLock
|
||||
{
|
||||
@@ -427,67 +218,25 @@ public:
|
||||
} sAutoLock(pLock);
|
||||
|
||||
auto pRepo = sdv::core::GetObject("RepositoryService");
|
||||
ASSERT_TRUE(pRepo);
|
||||
if (!pRepo) return false;
|
||||
|
||||
auto pCreate = sdv::TInterfaceAccessPtr(pRepo).GetInterface<sdv::core::IRepositoryControl>();
|
||||
ASSERT_TRUE(pCreate);
|
||||
if (!pCreate) return false;
|
||||
|
||||
ASSERT_FALSE(ssObjectConfig.empty());
|
||||
if (m_ssChainedObject.empty()) return false;
|
||||
|
||||
ASSERT_TRUE(pCreate->CreateObject("Example_Object", ssObjectConfig, nullptr));
|
||||
if (!pCreate->CreateObject("Example_Object", m_ssChainedObject, nullptr)) return false;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
std::string m_ssChainedObject; ///< Name of the chained object
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectCreateLock)
|
||||
@@ -495,33 +244,33 @@ DEFINE_SDV_OBJECT(CTestObjectCreateLock)
|
||||
/**
|
||||
* @brief Example component testing chained object creation in Initialize in extra thread holding a lock
|
||||
*/
|
||||
class CTestObjectCreateLockThread
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectCreateLockThread : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_CreateChainLockThread")
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
virtual void Initialize(const sdv::u8string& ssObjectConfig)
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
BEGIN_SDV_PARAM_MAP()
|
||||
SDV_PARAM_ENTRY(m_ssChainedObject, "chained_object", "", "", "Name of the chained object")
|
||||
END_SDV_PARAM_MAP()
|
||||
|
||||
auto fun = [ssObjectConfig]()
|
||||
/**
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
bool bResult = true;
|
||||
auto fun = [this, &bResult]()
|
||||
{
|
||||
//create new example object with name ssObjectConfig while holding lock
|
||||
|
||||
auto pLock = sdv::core::GetObject<ITestLock>("TestLockService");
|
||||
ASSERT_NE(pLock, nullptr);
|
||||
if (!pLock)
|
||||
{
|
||||
bResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
struct SAutoLock
|
||||
{
|
||||
@@ -531,72 +280,46 @@ public:
|
||||
} sAutoLock(pLock);
|
||||
|
||||
auto pRepo = sdv::core::GetObject("RepositoryService");
|
||||
ASSERT_TRUE(pRepo);
|
||||
if (!pRepo)
|
||||
{
|
||||
bResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto pCreate = sdv::TInterfaceAccessPtr(pRepo).GetInterface<sdv::core::IRepositoryControl>();
|
||||
ASSERT_TRUE(pCreate);
|
||||
if (!pCreate)
|
||||
{
|
||||
bResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT_FALSE(ssObjectConfig.empty());
|
||||
if (m_ssChainedObject.empty())
|
||||
{
|
||||
bResult = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT_TRUE(pCreate->CreateObject("Example_Object", ssObjectConfig, nullptr));
|
||||
if (!pCreate->CreateObject("Example_Object", m_ssChainedObject, nullptr))
|
||||
{
|
||||
bResult = false;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
std::thread testThread(fun);
|
||||
|
||||
testThread.join();
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
return bResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
virtual void OnShutdown() override
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
std::string m_ssChainedObject; ///< Name of the chained object
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestObjectCreateLockThread)
|
||||
@@ -605,78 +328,30 @@ DEFINE_SDV_OBJECT(CTestObjectCreateLockThread)
|
||||
/**
|
||||
* @brief Example component testing IObjectControl
|
||||
*/
|
||||
class CTestObjectCreateDuringShutdown
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
class CTestObjectCreateDuringShutdown : public sdv::CSdvObject
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_CreateDuringShutdown")
|
||||
|
||||
/**
|
||||
* @brief Initialize method. On success, a subsequent call to GetStatus returns EObjectStatus::running
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
|
||||
* @return Returns 'true' when the initialization was successful, 'false' when not.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
|
||||
virtual bool OnInitialize() override
|
||||
{
|
||||
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::initialized;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const
|
||||
{
|
||||
return m_eObjectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
|
||||
m_eObjectStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shutdown method called before the object is destroyed.
|
||||
* @brief Shutdown method called before the object is destroyed. Overload of sdv::CSdvObject::OnShutdown.
|
||||
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
|
||||
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
|
||||
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
|
||||
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
|
||||
* Any subsequent call to GetObjectState should return EObjectState::destruction_pending
|
||||
*/
|
||||
virtual void Shutdown()
|
||||
virtual void OnShutdown() override
|
||||
{
|
||||
EXPECT_TRUE(m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized ||
|
||||
m_eObjectStatus == sdv::EObjectStatus::configuring);
|
||||
if (m_eObjectStatus != sdv::EObjectStatus::running && m_eObjectStatus != sdv::EObjectStatus::initialized
|
||||
&& m_eObjectStatus != sdv::EObjectStatus::configuring)
|
||||
std::cout << "Object status = " << static_cast<uint32_t>(m_eObjectStatus) << " (expected initialized=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::initialized) << " or configuring=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::configuring) << " or running=" <<
|
||||
static_cast<uint32_t>(sdv::EObjectStatus::running) << ")." << std::endl;
|
||||
|
||||
//create new example object
|
||||
//this is allowed during shutdown as it's needed in case new proxies are created
|
||||
|
||||
@@ -687,12 +362,7 @@ public:
|
||||
ASSERT_TRUE(pCreate);
|
||||
|
||||
ASSERT_FALSE(pCreate->CreateObject("Example_Object", nullptr, nullptr));
|
||||
|
||||
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
private:
|
||||
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
|
||||
};
|
||||
DEFINE_SDV_OBJECT(CTestObjectCreateDuringShutdown)
|
||||
|
||||
@@ -707,7 +377,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(IHello)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_HelloDevice")
|
||||
|
||||
/**
|
||||
@@ -740,7 +410,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(IHello)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::basic_service)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_BasicHelloService")
|
||||
|
||||
/**
|
||||
@@ -781,7 +451,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(IHello)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::ComplexService)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::complex_service)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_ComplexHelloService")
|
||||
|
||||
/**
|
||||
@@ -814,7 +484,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(IHello)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Utility)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::utility)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_HelloUtility")
|
||||
|
||||
/**
|
||||
@@ -847,7 +517,7 @@ public:
|
||||
SDV_INTERFACE_ENTRY(IHello)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::SystemObject)
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::system_object)
|
||||
DECLARE_OBJECT_CLASS_NAME("TestObject_SystemHelloService")
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include <interfaces/core.idl>
|
||||
#include <interfaces/process.idl>
|
||||
|
||||
|
||||
@@ -1 +1,14 @@
|
||||
/********************************************************************************
|
||||
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Apache License Version 2.0 which is available at
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Erik Verhoeven - initial API and implementation
|
||||
********************************************************************************/
|
||||
|
||||
#include "generated/ps/proxystub.cpp"
|
||||
Reference in New Issue
Block a user