Line data Source code
1 : /**
2 : * @file rest_commanded_object_.hpp REST commanded object
3 : * implementation that counts the number of executed commands
4 : * and prints out statistics about it.
5 : *
6 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 : #ifndef RESTCMD_TEST_APPS_REST_COMMANDED_OBJECT_HPP_
11 : #define RESTCMD_TEST_APPS_REST_COMMANDED_OBJECT_HPP_
12 :
13 : #include "cmdlib/CommandedObject.hpp"
14 :
15 : #include "logging/Logging.hpp"
16 :
17 : #include <stdexcept>
18 : #include <string>
19 :
20 : struct RestCommandedObject : public dunedaq::cmdlib::CommandedObject
21 : {
22 : int counter_ = 0;
23 : std::atomic<bool>& runmarker_;
24 : std::thread stats_;
25 :
26 : // NOLINTNEXTLINE(runtime/increment_decrement)
27 0 : void execute(const dunedaq::cmdlib::cmdobj_t& /*command*/) { ++counter_; }
28 :
29 0 : explicit RestCommandedObject(std::atomic<bool>& rm)
30 0 : : runmarker_(rm)
31 : {
32 0 : stats_ = std::thread([&]() {
33 0 : while (runmarker_) {
34 0 : TLOG() << "Total number of commands received: " << counter_;
35 0 : std::this_thread::sleep_for(std::chrono::seconds(5));
36 : }
37 0 : });
38 0 : }
39 :
40 0 : ~RestCommandedObject()
41 0 : {
42 0 : if (stats_.joinable()) {
43 0 : stats_.join();
44 : }
45 0 : }
46 :
47 : RestCommandedObject(const RestCommandedObject&) = delete; ///< RestCommandedObject is not copy-constructible
48 : RestCommandedObject& operator=(const RestCommandedObject&) = delete; ///< RestCommandedObject is not copy-assignable
49 : RestCommandedObject(RestCommandedObject&&) = delete; ///< RestCommandedObject is not move-constructible
50 : RestCommandedObject& operator=(RestCommandedObject&&) = delete; ///< RestCommandedObject is not move-assignable
51 : };
52 :
53 : #endif // RESTCMD_TEST_APPS_REST_COMMANDED_OBJECT_HPP_
|