|
| 1 | +/* SPDX-License-Identifier: BSD-3-Clause |
| 2 | + * Copyright(c) 2025 Intel Corporation |
| 3 | + */ |
| 4 | + |
| 5 | +#include "handler_base.hpp" |
| 6 | + |
| 7 | +#include <cstdio> |
| 8 | +#include <stdexcept> |
| 9 | + |
| 10 | +Handlers::Handlers(st_tests_context* ctx, FrameTestStrategy* frameTestStrategy) |
| 11 | + : ctx(ctx), frameTestStrategy(frameTestStrategy) { |
| 12 | +} |
| 13 | + |
| 14 | +Handlers::~Handlers() { |
| 15 | + session.stop(); |
| 16 | +} |
| 17 | + |
| 18 | +void Handlers::startSession( |
| 19 | + std::vector<std::function<void(std::atomic<bool>&)>> threadFunctions, bool isRx) { |
| 20 | + for (auto& func : threadFunctions) { |
| 21 | + session.addThread(func, isRx); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +void Handlers::stopSession() { |
| 26 | + session.stop(); |
| 27 | +} |
| 28 | + |
| 29 | +void Handlers::setSessionPortsTx(struct st_tx_port* port, int txPortIdx, |
| 30 | + int txPortRedundantIdx) { |
| 31 | + if (!ctx) { |
| 32 | + throw std::runtime_error("setSessionPortsTx no ctx (ctx is null)"); |
| 33 | + } else if (txPortIdx >= (int)ctx->para.num_ports) { |
| 34 | + throw std::runtime_error("setSessionPortsTx txPortIdx out of range"); |
| 35 | + } else if (txPortRedundantIdx >= (int)ctx->para.num_ports) { |
| 36 | + throw std::runtime_error("setSessionPortsTx txPortRedundantIdx out of range"); |
| 37 | + } |
| 38 | + |
| 39 | + if (txPortIdx >= 0) { |
| 40 | + snprintf(port->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", |
| 41 | + ctx->para.port[txPortIdx]); |
| 42 | + int num_ports = 1; |
| 43 | + |
| 44 | + if (txPortRedundantIdx >= 0) { |
| 45 | + snprintf(port->port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", |
| 46 | + ctx->para.port[txPortRedundantIdx]); |
| 47 | + num_ports = 2; |
| 48 | + } |
| 49 | + |
| 50 | + port->num_port = num_ports; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +void Handlers::setSessionPortsRx(struct st_rx_port* port, int rxPortIdx, |
| 55 | + int rxPortRedundantIdx) { |
| 56 | + if (!ctx) { |
| 57 | + throw std::runtime_error("setSessionPortsRx no ctx (ctx is null)"); |
| 58 | + } else if (rxPortIdx >= (int)ctx->para.num_ports) { |
| 59 | + throw std::runtime_error("setSessionPortsRx rxPortIdx out of range"); |
| 60 | + } else if (rxPortRedundantIdx >= (int)ctx->para.num_ports) { |
| 61 | + throw std::runtime_error("setSessionPortsRx rxPortRedundantIdx out of range"); |
| 62 | + } |
| 63 | + |
| 64 | + if (rxPortIdx >= 0) { |
| 65 | + snprintf(port->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", |
| 66 | + ctx->para.port[rxPortIdx]); |
| 67 | + int num_ports = 1; |
| 68 | + |
| 69 | + if (rxPortRedundantIdx >= 0) { |
| 70 | + snprintf(port->port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", |
| 71 | + ctx->para.port[rxPortRedundantIdx]); |
| 72 | + num_ports = 2; |
| 73 | + } |
| 74 | + port->num_port = num_ports; |
| 75 | + } |
| 76 | +} |
0 commit comments