// Copyright 2020-2025 Jeisson Hidalgo-Cespedes. ECCI-UCR. CC BY 4.0 #pragma once #include #include #include "common.hpp" // Forward declarations class PacketConsumer; class PacketDispatcher; class PacketProducer; /** * @brief Controller class that simulates the message passing between * producer and consumers through a dispatcher. */ class PacketSimulation { DISABLE_COPY(PacketSimulation); private: /// Number of packages to be produced size_t packageCount = 0; /// Number of consumer threads size_t consumerCount = 0; /// Delay of producer to create a package, negative for max random int productorDelay = 0; /// Delay of dispatcher to dispatch a package, negative for max random int dispatcherDelay = 0; /// Delay of consumer to consume a package, negative for max random int consumerDelay = 0; private: /// Producer of the simulated network messages PacketProducer* producer = nullptr; /// A dispatcher of the of the simulated network messages PacketDispatcher* dispatcher = nullptr; /// Consumers of the simulated network messages std::vector consumers; public: /// Constructor PacketSimulation() = default; /// Destructor ~PacketSimulation(); /// Start the simulation int start(int argc, char* argv[]); private: /// Analyze the command line arguments int analyzeArguments(int argc, char* argv[]); /// Create network threads: producers, consumers, assemblers and dispatchers void createThreadObjects(); /// Intercommunicate threads using queues void connectQueues(); /// Start the execution of threads void startThreads(); /// Wait (join) the secondary threads void joinThreads(); };