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_REST_COMMANDED_OBJECT_HPP_
11 : #define RESTCMD_TEST_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 0 : void execute(const dunedaq::cmdlib::cmdobj_t& /*command*/) {
27 0 : ++counter_;
28 0 : }
29 :
30 0 : explicit RestCommandedObject(std::atomic<bool>& rm) : runmarker_(rm) {
31 0 : stats_ = std::thread([&](){
32 0 : while(runmarker_) {
33 0 : TLOG() <<"Total number of commands received: " << counter_;
34 0 : std::this_thread::sleep_for(std::chrono::seconds(5));
35 : }
36 0 : });
37 0 : }
38 :
39 0 : ~RestCommandedObject(){
40 0 : if (stats_.joinable()) {
41 0 : stats_.join();
42 : }
43 0 : }
44 :
45 : RestCommandedObject(const RestCommandedObject&) =
46 : delete; ///< RestCommandedObject is not copy-constructible
47 : RestCommandedObject& operator=(const RestCommandedObject&) =
48 : delete; ///< RestCommandedObject is not copy-assignable
49 : RestCommandedObject(RestCommandedObject&&) =
50 : delete; ///< RestCommandedObject is not move-constructible
51 : RestCommandedObject& operator=(RestCommandedObject&&) =
52 : delete; ///< RestCommandedObject is not move-assignable
53 :
54 : };
55 :
56 : #endif // RESTCMD_TEST_REST_COMMANDED_OBJECT_HPP_
|