Skip to content

iceoryx_posh/internal/roudi/process_manager.hpp🔗

Namespaces🔗

Name
iox
iox::roudi

Classes🔗

Name
class iox::roudi::ProcessManagerInterface
class iox::roudi::ProcessManager

Source code🔗

// Copyright (c) 2019, 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_POSH_ROUDI_PROCESS_MANAGER_HPP
#define IOX_POSH_ROUDI_PROCESS_MANAGER_HPP

#include "iceoryx_posh/internal/mepoo/segment_manager.hpp"
#include "iceoryx_posh/internal/roudi/introspection/process_introspection.hpp"
#include "iceoryx_posh/internal/roudi/port_manager.hpp"
#include "iceoryx_posh/internal/roudi/process.hpp"
#include "iceoryx_posh/internal/runtime/ipc_interface_user.hpp"
#include "iceoryx_posh/mepoo/chunk_header.hpp"
#include "iceoryx_posh/version/compatibility_check_level.hpp"
#include "iceoryx_posh/version/version_info.hpp"
#include "iceoryx_utils/cxx/list.hpp"
#include "iceoryx_utils/error_handling/error_handling.hpp"
#include "iceoryx_utils/posix_wrapper/posix_access_rights.hpp"

#include <cstdint>
#include <ctime>

namespace iox
{
namespace roudi
{
class ProcessManagerInterface
{
  public:
    virtual void sendServiceRegistryChangeCounterToProcess(const RuntimeName_t& process_name) noexcept = 0;
    virtual void discoveryUpdate() noexcept = 0;

    virtual ~ProcessManagerInterface() noexcept = default;
};

class ProcessManager : public ProcessManagerInterface
{
  public:
    using ProcessList_t = cxx::list<Process, MAX_PROCESS_NUMBER>;
    using PortConfigInfo = iox::runtime::PortConfigInfo;

    enum class TerminationFeedback
    {
        SEND_ACK_TO_PROCESS,
        DO_NOT_SEND_ACK_TO_PROCESS
    };

    ProcessManager(RouDiMemoryInterface& roudiMemoryInterface,
                   PortManager& portManager,
                   const version::CompatibilityCheckLevel compatibilityCheckLevel) noexcept;
    virtual ~ProcessManager() noexcept override = default;

    ProcessManager(const ProcessManager& other) = delete;
    ProcessManager& operator=(const ProcessManager& other) = delete;

    bool registerProcess(const RuntimeName_t& name,
                         const uint32_t pid,
                         const posix::PosixUser user,
                         const bool isMonitored,
                         const int64_t transmissionTimestamp,
                         const uint64_t sessionId,
                         const version::VersionInfo& versionInfo) noexcept;

    bool unregisterProcess(const RuntimeName_t& name) noexcept;

    void killAllProcesses() noexcept;

    void printWarningForRegisteredProcessesAndClearProcessList() noexcept;

    bool isAnyRegisteredProcessStillRunning() noexcept;

    void handleProcessShutdownPreparationRequest(const RuntimeName_t& name) noexcept;

    void requestShutdownOfAllProcesses() noexcept;

    void updateLivelinessOfProcess(const RuntimeName_t& name) noexcept;

    void findServiceForProcess(const RuntimeName_t& name, const capro::ServiceDescription& service) noexcept;

    void
    addInterfaceForProcess(const RuntimeName_t& name, capro::Interfaces interface, const NodeName_t& node) noexcept;

    void addApplicationForProcess(const RuntimeName_t& name) noexcept;

    void addNodeForProcess(const RuntimeName_t& process, const NodeName_t& node) noexcept;

    void addSubscriberForProcess(const RuntimeName_t& name,
                                 const capro::ServiceDescription& service,
                                 const popo::SubscriberOptions& subscriberOptions,
                                 const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept;

    void addPublisherForProcess(const RuntimeName_t& name,
                                const capro::ServiceDescription& service,
                                const popo::PublisherOptions& publisherOptions,
                                const PortConfigInfo& portConfigInfo = PortConfigInfo()) noexcept;

    void addConditionVariableForProcess(const RuntimeName_t& runtimeName) noexcept;

    void initIntrospection(ProcessIntrospectionType* processIntrospection) noexcept;

    void run() noexcept;

    popo::PublisherPortData* addIntrospectionPublisherPort(const capro::ServiceDescription& service,
                                                           const RuntimeName_t& process_name) noexcept;

    void sendMessageNotSupportedToRuntime(const RuntimeName_t& name) noexcept;

    void sendServiceRegistryChangeCounterToProcess(const RuntimeName_t& process_name) noexcept override;

  private:
    bool searchForProcessAndThen(const RuntimeName_t& name,
                                 cxx::function_ref<void(Process&)> AndThenCallable,
                                 cxx::function_ref<void()> OrElseCallable) noexcept;

    void monitorProcesses() noexcept;
    void discoveryUpdate() noexcept override;

    bool addProcess(const RuntimeName_t& name,
                    const uint32_t pid,
                    const posix::PosixUser& user,
                    const bool isMonitored,
                    const int64_t transmissionTimestamp,
                    const uint64_t sessionId,
                    const version::VersionInfo& versionInfo) noexcept;

    bool searchForProcessAndRemoveIt(const RuntimeName_t& name, const TerminationFeedback feedback) noexcept;

    bool removeProcessAndDeleteRespectiveSharedMemoryObjects(ProcessList_t::iterator& processIter,
                                                             const TerminationFeedback feedback) noexcept;

    enum class ShutdownPolicy
    {
        SIG_TERM,
        SIG_KILL
    };

    bool requestShutdownOfProcess(Process& process, ShutdownPolicy shutdownPolicy) noexcept;

    bool isProcessAlive(const Process& process) noexcept;

    void evaluateKillError(const Process& process,
                           const int32_t& errnum,
                           const char* errorString,
                           ShutdownPolicy shutdownPolicy) noexcept;

    RouDiMemoryInterface& m_roudiMemoryInterface;
    PortManager& m_portManager;
    mepoo::SegmentManager<>* m_segmentManager{nullptr};
    mepoo::MemoryManager* m_introspectionMemoryManager{nullptr};
    rp::BaseRelativePointer::id_t m_mgmtSegmentId{rp::BaseRelativePointer::NULL_POINTER_ID};
    ProcessList_t m_processList;
    ProcessIntrospectionType* m_processIntrospection{nullptr};
    version::CompatibilityCheckLevel m_compatibilityCheckLevel;
};

} // namespace roudi
} // namespace iox

#endif // IOX_POSH_ROUDI_PROCESS_MANAGER_HPP

Updated on 31 May 2022 at 15:29:16 CEST