Program Listing for File client.h#

Return to documentation for file (ipc_connect\client.h)

/********************************************************************************
 * 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
 ********************************************************************************/

#ifndef CLIENT_H
#define CLIENT_H

#include <support/pssup.h>
#include <support/component_impl.h>
#include <interfaces/com.h>

// Forward declaration.
class CClientConnect;

class CRepositoryProxy : public sdv::IInterfaceAccess, public sdv::IObjectDestroy
{
public:
    CRepositoryProxy(CClientConnect& rClient, sdv::com::TConnectionID tConnection, sdv::IInterfaceAccess* pRepositoryProxy);

    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()


    CRepositoryProxy& operator=(const CRepositoryProxy& rRepository) = delete;

    virtual void DestroyObject() override;

    sdv::com::TConnectionID GetConnectionID() const;

private:
    CClientConnect&                 m_rClient;
    sdv::com::TConnectionID         m_tConnection = {};
    sdv::TInterfaceAccessPtr        m_ptrRepositoryProxy;
};

class CClientConnect : public sdv::CSdvObject, public sdv::com::IClientConnect
{
public:
    // Interface map
    BEGIN_SDV_INTERFACE_MAP()
        SDV_INTERFACE_ENTRY(sdv::com::IClientConnect)
    END_SDV_INTERFACE_MAP()

    // Object declaration
    DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::system_object)
    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()


    virtual bool OnInitialize() override;

    virtual void OnShutdown() override;

    virtual bool Connect() override;

    bool Disconnect() override;

    bool IsConnected() const override;

    sdv::IInterfaceAccess* GetRemoteRepository() override;

private:
    mutable std::mutex                  m_mtx;
    sdv::u8string                       m_ssProvider;
    std::shared_ptr<CRepositoryProxy>   m_ptrRemoteRepo;
};

DEFINE_SDV_OBJECT(CClientConnect)

#endif // !defined CLIENT_H