2026-03-27 14:12:49 +01:00
|
|
|
/********************************************************************************
|
|
|
|
|
* 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
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
2025-11-04 13:28:06 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
#include "complex_service.h"
|
|
|
|
|
|
|
|
|
|
|
2026-03-27 14:12:49 +01:00
|
|
|
bool CTrunkExampleService::OnInitialize()
|
2025-11-04 13:28:06 +01:00
|
|
|
{
|
|
|
|
|
// Request the basic service for speed.
|
|
|
|
|
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
|
|
|
|
|
if (pSpeedSvc)
|
|
|
|
|
{
|
|
|
|
|
// Register speed change event handler.
|
|
|
|
|
pSpeedSvc->RegisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request the basic service for opening the trunk
|
|
|
|
|
m_pTrunkSvc = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>();
|
|
|
|
|
|
|
|
|
|
if ((!pSpeedSvc) || (!m_pTrunkSvc))
|
|
|
|
|
{
|
|
|
|
|
SDV_LOG_ERROR("Could not get interfaces : [CTrunkExampleService]");
|
2026-03-27 14:12:49 +01:00
|
|
|
return false;
|
2025-11-04 13:28:06 +01:00
|
|
|
}
|
2026-03-27 14:12:49 +01:00
|
|
|
return true;
|
2025-11-04 13:28:06 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 14:12:49 +01:00
|
|
|
void CTrunkExampleService::OnShutdown()
|
2025-11-04 13:28:06 +01:00
|
|
|
{
|
|
|
|
|
// Unregister trunk change event handler.
|
|
|
|
|
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
|
|
|
|
|
if (pSpeedSvc)
|
|
|
|
|
pSpeedSvc->UnregisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CTrunkExampleService::SetSpeed(float value)
|
|
|
|
|
{
|
|
|
|
|
m_Speed = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CTrunkExampleService::PopTrunk()
|
|
|
|
|
{
|
|
|
|
|
if (m_Speed == 0.0)
|
|
|
|
|
{
|
|
|
|
|
return m_pTrunkSvc->SetOpen(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|