|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @brief Generic interface of output plugin |
| 4 | + * @author Pavel Siska <[email protected]> |
| 5 | + * @author Vaclav Bartos <[email protected]> |
| 6 | + * @author Jiri Havranek <[email protected]> |
| 7 | + * @date 2025 |
| 8 | + * |
| 9 | + * Copyright (c) 2025 CESNET |
| 10 | + * |
| 11 | + * SPDX-License-Identifier: BSD-3-Clause |
| 12 | + */ |
| 13 | + |
| 14 | +#pragma once |
| 15 | + |
| 16 | +#include "api.hpp" |
| 17 | +#include "flowifc.hpp" |
| 18 | +#include "plugin.hpp" |
| 19 | +#include "process.hpp" |
| 20 | + |
| 21 | +#include <cstdint> |
| 22 | +#include <string> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +namespace ipxp { |
| 26 | + |
| 27 | +#define DEFAULT_EXPORTER_ID 1 |
| 28 | + |
| 29 | +/** |
| 30 | + * \brief Base class for flow exporters. |
| 31 | + */ |
| 32 | +class IPXP_API OutputPlugin : public Plugin { |
| 33 | +public: |
| 34 | + typedef std::vector<std::pair<std::string, ProcessPlugin*>> Plugins; |
| 35 | + uint64_t m_flows_seen; /**< Number of flows received to export. */ |
| 36 | + uint64_t m_flows_dropped; /**< Number of flows that could not be exported. */ |
| 37 | + |
| 38 | + OutputPlugin() |
| 39 | + : m_flows_seen(0) |
| 40 | + , m_flows_dropped(0) |
| 41 | + { |
| 42 | + } |
| 43 | + virtual ~OutputPlugin() {} |
| 44 | + |
| 45 | + virtual void init(const char* params, Plugins& plugins) = 0; |
| 46 | + |
| 47 | + enum class Result { EXPORTED = 0, DROPPED }; |
| 48 | + /** |
| 49 | + * \brief Send flow record to output interface. |
| 50 | + * \param [in] flow Flow to send. |
| 51 | + * \return 0 on success |
| 52 | + */ |
| 53 | + virtual int export_flow(const Flow& flow) = 0; |
| 54 | + |
| 55 | + /** |
| 56 | + * \brief Force exporter to flush flows to collector. |
| 57 | + */ |
| 58 | + virtual void flush() {} |
| 59 | +}; |
| 60 | + |
| 61 | +/** |
| 62 | + * @brief Factory template for creating plugins. |
| 63 | + * |
| 64 | + * This template allows dynamic creation of plugin instances based on the specified |
| 65 | + * base class and constructor argument types. |
| 66 | + * |
| 67 | + * @tparam Base The base class for the plugin. |
| 68 | + * @tparam Args The argument types required for the plugin constructor. |
| 69 | + */ |
| 70 | +template<typename Base, typename... Args> |
| 71 | +class IPXP_API PluginFactory; |
| 72 | + |
| 73 | +/** |
| 74 | + * @brief Type alias for the OutputPlugin factory. |
| 75 | + * |
| 76 | + * Provides a factory for creating OutputPlugin instances using a string-based constructor. |
| 77 | + */ |
| 78 | +using OutputPluginFactory = PluginFactory<OutputPlugin, const std::string&>; |
| 79 | + |
| 80 | +} // namespace ipxp |
0 commit comments