Skip to content

iceoryx_posh/internal/roudi/introspection/process_introspection.hpp🔗

Namespaces🔗

Name
iox
iox::roudi

Classes🔗

Name
class iox::roudi::ProcessIntrospection
This class handles the process intropection for RouDi. It is recommended to use the ProcessIntrospectionType alias which sets the intended template parameter. The class tracks the adding and removal of processes and sends it to the introspection client if subscribed.

Source code🔗

// Copyright (c) 2019 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_INTROSPECTION_PROCESS_INTROSPECTION_HPP
#define IOX_POSH_ROUDI_INTROSPECTION_PROCESS_INTROSPECTION_HPP

#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/internal/popo/ports/publisher_port_user.hpp"
#include "iceoryx_posh/roudi/introspection_types.hpp"
#include "iceoryx_utils/cxx/list.hpp"
#include "iceoryx_utils/cxx/method_callback.hpp"
#include "iceoryx_utils/internal/concurrent/periodic_task.hpp"

#include <mutex>

namespace iox
{
namespace roudi
{
template <typename PublisherPort>
class ProcessIntrospection
{
  public:
    ProcessIntrospection() noexcept;
    ~ProcessIntrospection() noexcept;

    // delete copy constructor and assignment operator
    ProcessIntrospection(ProcessIntrospection const&) = delete;
    ProcessIntrospection& operator=(ProcessIntrospection const&) = delete;
    // delete move constructor and assignment operator
    ProcessIntrospection(ProcessIntrospection&&) = delete;
    ProcessIntrospection& operator=(ProcessIntrospection&&) = delete;


    void addProcess(const int pid, const RuntimeName_t& name) noexcept;

    void removeProcess(const int pid) noexcept;

    void addNode(const RuntimeName_t& runtimeName, const NodeName_t& node) noexcept;

    void removeNode(const RuntimeName_t& runtimeName, const NodeName_t& node) noexcept;

    void registerPublisherPort(PublisherPort&& publisherPort) noexcept;

    void run() noexcept;

    void stop() noexcept;

    void setSendInterval(const units::Duration interval) noexcept;

  protected:
    cxx::optional<PublisherPort> m_publisherPort;
    void send() noexcept;

  private:
    using ProcessList_t = cxx::list<ProcessIntrospectionData, MAX_PROCESS_NUMBER>;
    ProcessList_t m_processList;
    bool m_processListNewData{true}; // true because we want to have a valid field, even with an empty list

    std::mutex m_mutex;

    units::Duration m_sendInterval{units::Duration::fromSeconds(1U)};
    concurrent::PeriodicTask<cxx::MethodCallback<void>> m_publishingTask{
        concurrent::PeriodicTaskManualStart, "ProcessIntr", *this, &ProcessIntrospection::send};
};

using ProcessIntrospectionType = ProcessIntrospection<PublisherPortUserType>;

} // namespace roudi
} // namespace iox

#include "iceoryx_posh/internal/roudi/introspection/process_introspection.inl"

#endif // IOX_POSH_ROUDI_INTROSPECTION_PROCESS_INTROSPECTION_HPP

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