otsdaq  v2_05_02_indev
WorkLoopManager.h
1 #ifndef _ots_WorkLoopManager_h
2 #define _ots_WorkLoopManager_h
3 
4 #include <toolbox/task/WorkLoop.h>
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
7 #include <xgi/Method.h> //for cgicc::Cgicc
8 #pragma GCC diagnostic pop
9 #include <xoap/MessageReference.h>
10 
11 #include <ctime>
12 #include <map>
13 #include <string>
14 
15 namespace ots
16 {
17 class HttpXmlDocument;
18 class SOAPCommand;
19 
21 {
22  public:
23  typedef unsigned long long RequestNumber;
24 
25  WorkLoopManager(toolbox::task::ActionSignature* job);
26  ~WorkLoopManager(void);
27 
28  // All requests that can change the request map like
29  // forceDeleteAllRequests, deleteAllInactiveRequests, deleteAllTimedOutRequests
30  // forceThisRequest -> even if there are already maxWorkLoops this request must be
31  // accepted!!
32  // and more...
33  // MUST BE HANDLED LIKE ALL THE OTHER REQUESTS!!!!!! THROUGH THE processRequest
34  // Method!
35  HttpXmlDocument processRequest(cgicc::Cgicc& cgi);
36  HttpXmlDocument processRequest(const xoap::MessageReference& message);
37  bool report(toolbox::task::WorkLoop* workLoop, std::string result, float progress, bool status);
38  bool removeProcessedRequests(void);
39  std::string getWorkLoopRequest(toolbox::task::WorkLoop* workLoop);
40  void translateWorkLoopName(toolbox::task::WorkLoop* workLoop, SOAPCommand& soapCommand);
41 
42  // Getters
43  bool getRequestResult(cgicc::Cgicc& cgi, HttpXmlDocument& xmldoc);
44  xoap::MessageReference getMessage(toolbox::task::WorkLoop* workLoop);
45 
46  private:
47  const std::string cWorkLoopType_;
48  enum
49  {
50  maxWorkLoops = 5
51  };
52  enum
53  {
54  timeOutInSeconds = 20
55  };
56  struct WorkLoopStruct
57  {
58  toolbox::task::WorkLoop* workLoop;
59  std::string workLoopName;
60  std::string request;
61  std::string result;
62  bool done;
63  float progress;
64  time_t requestStartTime;
65  time_t requestLastTimeChecked;
66  xoap::MessageReference message;
67  };
68  HttpXmlDocument processRequest(std::string workLoopName, const xoap::MessageReference* message = 0);
69  bool removeWorkLoop(toolbox::task::WorkLoop* workLoop);
70  bool removeWorkLoop(RequestNumber requestNumber);
71  bool removeTimedOutRequests(void);
72  std::string composeWorkLoopName(RequestNumber requestNumber, cgicc::Cgicc& cgi);
73  std::string composeWorkLoopName(RequestNumber requestNumber, const xoap::MessageReference& message);
74  RequestNumber getWorkLoopRequestNumber(toolbox::task::WorkLoop* workLoop);
75  RequestNumber getWorkLoopRequestNumber(std::string workLoopName); // This can only be
76  // used by the class
77  // because it is
78  // careful to use
79  // the right format
80  std::string getWorkLoopRequest(std::string workLoopName); // This can only be used by
81  // the class because it is
82  // careful to use the right
83  // format
84 
85  std::map<RequestNumber, WorkLoopStruct> workLoops_;
86  toolbox::task::ActionSignature* job_;
87  unsigned long long requestNumber_;
88  std::string requestName_;
89 };
90 
91 } // namespace ots
92 
93 #endif