MpdWebScreenshots.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // -------------------------------------------------------------------------
  2. // ----- MpdWebScreenshots header file -----
  3. // ----- Created 11/12/15 by K. Smirnov -----
  4. // -------------------------------------------------------------------------
  5. #ifndef MPDWEBSCREENSHOTS_H
  6. #define MPDWEBSCREENSHOTS_H
  7. #include "MpdEventManager.h"
  8. #include "FairTask.h"
  9. #include "TString.h"
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #define BUFFER_SIZE 512
  12. #define MAX_FILE_SIZE 1024*1024
  13. #define MAX_CONNECTIONS 3
  14. ///////////////////////////////////////////////////////////////////////////////
  15. struct www_thread_par
  16. {
  17. int web_port;
  18. TString outputDir;
  19. int daemon;
  20. };
  21. class MpdWebScreenshots : public FairTask
  22. {
  23. public:
  24. // Standard constructor
  25. //*@param name Name of task
  26. //*@outputDir Output directory
  27. //*@param iVerbose Verbosity level
  28. MpdWebScreenshots(const char* name, char* output_dir, bool isWebServer = false, Int_t iVerbose = 0);
  29. // Destructor
  30. virtual ~MpdWebScreenshots();
  31. // Set verbosity level. For this task and all of the subtasks.
  32. void SetVerbose(Int_t iVerbose) { fVerbose = iVerbose; }
  33. // Executed task
  34. virtual void Exec(Option_t* option);
  35. virtual InitStatus Init();
  36. virtual void SetParContainers();
  37. // Action after each event
  38. virtual void Finish();
  39. //Set format of saved files
  40. void SetFormatFiles(int i_format_files) { iFormatFiles = i_format_files; }
  41. //Set quantity of files
  42. void SetMultiFiles(bool is_multi_files) { isMultiFiles = is_multi_files; }
  43. //Set Number port
  44. void SetPort(int NumberPort) { web_port = NumberPort; }
  45. private:
  46. // Default constructor
  47. MpdWebScreenshots();
  48. MpdWebScreenshots(const MpdWebScreenshots&);
  49. MpdWebScreenshots& operator=(const MpdWebScreenshots&);
  50. static int daemonize();
  51. static int sendString(const char* message, int socket);
  52. static void sendHeader(const char* Status_code, char* Content_Type, int TotalSize, int socket);
  53. static void sendHTML(char* statusCode, char* contentType, char* content, int size, int socket);
  54. static void sendFile(FILE* fp, int connecting_socket);
  55. static int scan(char* input, char* output, unsigned int start, int max);
  56. static int checkMime(char* extension, char* mime_type);
  57. static int getHttpVersion(char* input, char* output);
  58. static int GetExtension(char* input, char* output, int max);
  59. static int handleHttpGET(char* input, TString output_dir, int connecting_socket);
  60. static int getRequestType(char* input);
  61. static int receive(int connecting_socket, TString output_dir);
  62. static int acceptConnection(int currentSocket, TString output_dir);
  63. static int start(int webPort, TString output_dir);
  64. static int start_server(void* ptr);
  65. MpdEventManager* fMan;
  66. // 0 - PNG, 1 -JPG, 2 - both types
  67. int iFormatFiles;
  68. // 0 - one (the same) file event.png; 1 - multiple files event_nnn.png (event1.png and etc.)
  69. bool isMultiFiles;
  70. TString outputDir;
  71. int web_port;
  72. int daemon;
  73. bool isWebStarted;
  74. bool isWeb;
  75. ClassDef(MpdWebScreenshots,1);
  76. };
  77. #endif