LCOV - code coverage report
Current view: top level - cmdlib/test/plugins - dummyCommandFacility.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 30 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 7 0

            Line data    Source code
       1              : /**
       2              :  * @file dummy_command_facility_.cxx Dummy command facility
       3              :  * implementation of the CommandFacility interface
       4              :  *
       5              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       6              :  * Licensing/copyright details are in the COPYING file that you should have
       7              :  * received with this code.
       8              :  */
       9              : #include "cmdlib/CommandFacility.hpp"
      10              : 
      11              : #include "logging/Logging.hpp"
      12              : #include <cetlib/BasicPluginFactory.h>
      13              : #include <nlohmann/json.hpp>
      14              : 
      15              : #include <chrono>
      16              : #include <memory>
      17              : #include <string>
      18              : #include <thread>
      19              : 
      20              : using namespace dunedaq::cmdlib;
      21              : using namespace std::chrono_literals;
      22              : 
      23              : class dummyCommandFacility : public CommandFacility
      24              : {
      25              : public:
      26            0 :   explicit dummyCommandFacility(std::string uri, int n)
      27            0 :     : CommandFacility(uri)
      28            0 :     , n_command{ n }
      29              :   {
      30            0 :   }
      31              : 
      32            0 :   void run(std::atomic<bool>& end_marker)
      33              :   {
      34            0 :     TLOG() << "Going for a run... " << n_command;
      35              : 
      36            0 :     bool once = true;
      37            0 :     while (end_marker) {
      38            0 :       if (once) {
      39              :         // execute n_command quick commands
      40            0 :         for (auto i = 0; i < n_command; ++i) {
      41            0 :           auto democmd =
      42            0 :             nlohmann::json::parse("{\"happy\": true, \"pi\": 3.141, \"count\": " + std::to_string(i) + "}");
      43            0 :           inherited::execute_command(democmd, cmd::CommandReply());
      44            0 :         }
      45              : 
      46              :         // execute 1 slow command
      47            0 :         auto slowcmd = nlohmann::json::parse("{\"asd\": true}");
      48            0 :         inherited::execute_command(slowcmd, cmd::CommandReply());
      49              : 
      50              :         // execute again n_command quick command
      51            0 :         for (auto i = 0; i < n_command; ++i) {
      52            0 :           auto democmd =
      53            0 :             nlohmann::json::parse("{\"happy\": true, \"pi\": 3.141, \"count\": " + std::to_string(i) + "}");
      54            0 :           inherited::execute_command(democmd, cmd::CommandReply());
      55            0 :         }
      56            0 :         once = false;
      57            0 :       }
      58              :     }
      59              : 
      60            0 :     TLOG_DEBUG(1) << "Finished.";
      61            0 :   }
      62              : 
      63              : protected:
      64              :   typedef CommandFacility inherited;
      65              :   int n_command;
      66              : 
      67            0 :   void completion_callback(const cmdobj_t& cmd, cmd::CommandReply& meta)
      68              :   {
      69            0 :     TLOG() << "Command " << cmd << "\nexecution resulted with: " << meta.result;
      70            0 :   }
      71              : };
      72              : 
      73              : extern "C"
      74              : {
      75            0 :   std::shared_ptr<dunedaq::cmdlib::CommandFacility> make(std::string uri, int n)
      76              :   {
      77            0 :     return std::shared_ptr<dunedaq::cmdlib::CommandFacility>(new dummyCommandFacility(uri, n));
      78              :   }
      79              : }
        

Generated by: LCOV version 2.0-1