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
|
|
|
|
|
*
|
|
|
|
|
* Contributors:
|
|
|
|
|
* Erik Verhoeven - initial API and implementation
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
2025-11-04 13:28:06 +01:00
|
|
|
#ifndef CLIENT_H
|
|
|
|
|
#define CLIENT_H
|
|
|
|
|
|
|
|
|
|
#include <support/pssup.h>
|
|
|
|
|
#include <support/component_impl.h>
|
|
|
|
|
#include <interfaces/com.h>
|
|
|
|
|
|
|
|
|
|
// Forward declaration.
|
2026-07-03 14:53:48 +02:00
|
|
|
class CClientConnect;
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Class managing the connection and providing access to the server repository through a proxy.
|
|
|
|
|
*/
|
|
|
|
|
class CRepositoryProxy : public sdv::IInterfaceAccess, public sdv::IObjectDestroy
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* @brief Constructor
|
|
|
|
|
* @param[in] rClient Reference to the client class.
|
|
|
|
|
* @param[in] tConnection The connection ID to the server.
|
|
|
|
|
* @param[in] pRepositoryProxy Proxy to the server repository.
|
|
|
|
|
*/
|
2026-07-03 14:53:48 +02:00
|
|
|
CRepositoryProxy(CClientConnect& rClient, sdv::com::TConnectionID tConnection, sdv::IInterfaceAccess* pRepositoryProxy);
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Do not allow a copy constructor.
|
|
|
|
|
* @param[in] rRepository Reference to the remote repository.
|
|
|
|
|
*/
|
|
|
|
|
CRepositoryProxy(const CRepositoryProxy& rRepository) = delete;
|
|
|
|
|
|
|
|
|
|
// Interface map
|
|
|
|
|
BEGIN_SDV_INTERFACE_MAP()
|
|
|
|
|
SDV_INTERFACE_ENTRY(sdv::IObjectDestroy)
|
|
|
|
|
SDV_INTERFACE_CHAIN_MEMBER(m_ptrRepositoryProxy)
|
|
|
|
|
END_SDV_INTERFACE_MAP()
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Copy assignment is not allowed.
|
|
|
|
|
* @param[in] rRepository Reference to the remote repository.
|
|
|
|
|
*/
|
|
|
|
|
CRepositoryProxy& operator=(const CRepositoryProxy& rRepository) = delete;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Destroy the object. Overload of sdv::IObjectDestroy::DestroyObject.
|
|
|
|
|
* @attention After a call of this function, all exposed interfaces render invalid and should not be used any more.
|
|
|
|
|
*/
|
|
|
|
|
virtual void DestroyObject() override;
|
|
|
|
|
|
2026-07-03 14:53:48 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Get the connection ID for this connection.
|
|
|
|
|
* @return The connection ID.
|
|
|
|
|
*/
|
|
|
|
|
sdv::com::TConnectionID GetConnectionID() const;
|
|
|
|
|
|
2025-11-04 13:28:06 +01:00
|
|
|
private:
|
2026-07-03 14:53:48 +02:00
|
|
|
CClientConnect& m_rClient; ///< Reference to the client object.
|
2025-11-04 13:28:06 +01:00
|
|
|
sdv::com::TConnectionID m_tConnection = {}; ///< Connection ID.
|
|
|
|
|
sdv::TInterfaceAccessPtr m_ptrRepositoryProxy; ///< Smart pointer to the remote repository.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Client object
|
|
|
|
|
*/
|
2026-07-03 14:53:48 +02:00
|
|
|
class CClientConnect : public sdv::CSdvObject, public sdv::com::IClientConnect
|
2025-11-04 13:28:06 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Interface map
|
|
|
|
|
BEGIN_SDV_INTERFACE_MAP()
|
|
|
|
|
SDV_INTERFACE_ENTRY(sdv::com::IClientConnect)
|
|
|
|
|
END_SDV_INTERFACE_MAP()
|
|
|
|
|
|
|
|
|
|
// Object declaration
|
2026-03-27 14:12:49 +01:00
|
|
|
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::system_object)
|
2026-07-03 14:53:48 +02:00
|
|
|
DECLARE_OBJECT_CLASS_NAME("ClientConnectService")
|
|
|
|
|
DECLARE_OBJECT_DEPENDENCIES("CommunicationControl")
|
|
|
|
|
|
|
|
|
|
// Parameter map
|
|
|
|
|
BEGIN_SDV_PARAM_MAP()
|
|
|
|
|
SDV_PARAM_ENABLE_LOCKING()
|
|
|
|
|
SDV_PARAM_GROUP("Provider")
|
|
|
|
|
SDV_PARAM_ENTRY(m_ssProvider, "Name", "", "", "Provider name to create a connection for.")
|
|
|
|
|
END_SDV_PARAM_MAP()
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
2026-03-27 14:12:49 +01:00
|
|
|
* @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.
|
2025-11-04 13:28:06 +01:00
|
|
|
*/
|
2026-03-27 14:12:49 +01:00
|
|
|
virtual bool OnInitialize() override;
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
2026-03-27 14:12:49 +01:00
|
|
|
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
|
|
|
|
|
*/
|
|
|
|
|
virtual void OnShutdown() override;
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
2026-07-03 14:53:48 +02:00
|
|
|
* @brief Connect to a remote system. Overload of IClientConnect::Connect.
|
|
|
|
|
* @return Returns whether connect was successful.
|
2025-11-04 13:28:06 +01:00
|
|
|
*/
|
2026-07-03 14:53:48 +02:00
|
|
|
virtual bool Connect() override;
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
/**
|
2026-07-03 14:53:48 +02:00
|
|
|
* @brief Disconnect from a connected system. Overload of IClientConnect::Disconnect.
|
|
|
|
|
* @return Returns whether disconnect was successful.
|
2025-11-04 13:28:06 +01:00
|
|
|
*/
|
2026-07-03 14:53:48 +02:00
|
|
|
bool Disconnect() override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief State of the current connection. Overload of IClientConnect::IsConnected.
|
|
|
|
|
* @return Returns whether an active connection exists.
|
|
|
|
|
* @return The connect state.
|
|
|
|
|
*/
|
|
|
|
|
bool IsConnected() const override;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Get the remote repository that is available after connection. Overload of IClientConnect::GetRemoteRepository.
|
|
|
|
|
* @remarks For main, isolated and external applications, the remote repository will be automatically linked to the
|
|
|
|
|
* local repository. Hence a requests for the repository is not needed. For all other applications, access must be
|
|
|
|
|
* explicitly acquired through this interface.
|
|
|
|
|
* @return Interface to the remote repository if a successful connection is established. The interface is valid until
|
|
|
|
|
* disconnect is called or the client connection service is terminated.
|
|
|
|
|
*/
|
|
|
|
|
sdv::IInterfaceAccess* GetRemoteRepository() override;
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
private:
|
2026-07-03 14:53:48 +02:00
|
|
|
mutable std::mutex m_mtx; ///< Protect against multiple parallel connection activities.
|
|
|
|
|
sdv::u8string m_ssProvider; ///< Name of the provider to use for the listening.
|
|
|
|
|
std::shared_ptr<CRepositoryProxy> m_ptrRemoteRepo; ///< Interface to the remote repository.
|
2025-11-04 13:28:06 +01:00
|
|
|
};
|
|
|
|
|
|
2026-07-03 14:53:48 +02:00
|
|
|
DEFINE_SDV_OBJECT(CClientConnect)
|
2025-11-04 13:28:06 +01:00
|
|
|
|
|
|
|
|
#endif // !defined CLIENT_H
|