iceoryx_introspection/introspection_app.hpp🔗
Namespaces🔗
Name |
---|
iox |
iox::client |
iox::client::introspection |
Classes🔗
Name | |
---|---|
class | iox::client::introspection::IntrospectionApp base class for introspection |
Source code🔗
// Copyright (c) 2019 by Robert Bosch GmbH. 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_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
#define IOX_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
#include "iceoryx_hoofs/platform/getopt.hpp"
#include "iceoryx_introspection/introspection_types.hpp"
#include "iceoryx_posh/popo/subscriber.hpp"
#include <map>
#include <ncurses.h>
#include <vector>
namespace iox
{
namespace client
{
namespace introspection
{
static constexpr option longOptions[] = {{"help", no_argument, nullptr, 'h'},
{"version", no_argument, nullptr, 'v'},
{"time", required_argument, nullptr, 't'},
{"mempool", no_argument, nullptr, 0},
{"port", no_argument, nullptr, 0},
{"process", no_argument, nullptr, 0},
{"all", no_argument, nullptr, 0},
{nullptr, 0, nullptr, 0}};
static constexpr const char* shortOptions = "hvt:";
static constexpr iox::units::Duration MIN_UPDATE_PERIOD = 500_ms;
static constexpr iox::units::Duration DEFAULT_UPDATE_PERIOD = 1000_ms;
static constexpr iox::units::Duration MAX_UPDATE_PERIOD = 10000_ms;
enum class ColorPairs : uint8_t
{
redOnBlack = 1,
whiteOnRed
};
static const std::map<PrettyOptions, uint32_t> prettyMap = {
{PrettyOptions::title, A_BOLD | COLOR_PAIR(static_cast<uint8_t>(ColorPairs::redOnBlack))},
{PrettyOptions::highlight, A_BOLD | A_UNDERLINE},
{PrettyOptions::error, A_BOLD | COLOR_PAIR(static_cast<uint8_t>(ColorPairs::whiteOnRed))},
{PrettyOptions::bold, A_BOLD},
{PrettyOptions::normal, A_NORMAL}};
class IntrospectionApp
{
public:
IntrospectionApp(int argc, char* argv[]) noexcept;
virtual ~IntrospectionApp() noexcept {};
virtual void run() noexcept = 0;
protected:
enum class CmdLineArgumentParsingMode
{
ALL,
ONE
};
IntrospectionSelection introspectionSelection;
bool doIntrospection = false;
IntrospectionApp() noexcept;
void
parseCmdLineArguments(int argc,
char** argv,
CmdLineArgumentParsingMode cmdLineParsingMode = CmdLineArgumentParsingMode::ALL) noexcept;
void runIntrospection(const iox::units::Duration updatePeriodMs,
const IntrospectionSelection introspectionSelection);
private:
void initTerminal();
void clearToBottom();
void closeTerminal();
void refreshTerminal();
void updateDisplayYX();
void waitForUserInput(int32_t timeoutMs);
void printShortInfo(const std::string& binaryName) noexcept;
void prettyPrint(const std::string& str, const PrettyOptions pr = PrettyOptions::normal);
void printProcessIntrospectionData(const ProcessIntrospectionFieldTopic* processIntrospectionField);
void printMemPoolInfo(const MemPoolIntrospectionInfo& introspectionInfo);
template <typename Subscriber>
bool waitForSubscription(Subscriber& port);
std::vector<ComposedPublisherPortData>
composePublisherPortData(const PortIntrospectionFieldTopic* portData,
const PortThroughputIntrospectionFieldTopic* throughputData);
std::vector<ComposedSubscriberPortData>
composeSubscriberPortData(const PortIntrospectionFieldTopic* portData,
const SubscriberPortChangingIntrospectionFieldTopic* subscriberPortChangingData);
void printPortIntrospectionData(const std::vector<ComposedPublisherPortData>& publisherPortData,
const std::vector<ComposedSubscriberPortData>& subscriberPortData);
void printHelp() noexcept;
template <typename T>
T bounded(T input, T min, T max) noexcept
{
return ((input >= min) ? ((input <= max) ? input : max) : min);
}
iox::units::Duration updatePeriodMs = DEFAULT_UPDATE_PERIOD;
WINDOW* pad;
int32_t yPad{0};
int32_t xPad{0};
};
} // namespace introspection
} // namespace client
} // namespace iox
#endif // IOX_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
Updated on 2 April 2022 at 16:37:47 CEST