ctkErrorLogFDMessageHandler_p.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkErrorLogFDMessageHandler_p_h
  15. #define __ctkErrorLogFDMessageHandler_p_h
  16. // Qt includes
  17. #include <QMutex>
  18. #include <QThread>
  19. // CTK includes
  20. #include "ctkErrorLogAbstractMessageHandler.h"
  21. #include "ctkErrorLogTerminalOutput.h"
  22. // STD includes
  23. #include <cstdio>
  24. class ctkErrorLogFDMessageHandler;
  25. // --------------------------------------------------------------------------
  26. // ctkFDHandler
  27. // --------------------------------------------------------------------------
  28. /// \ingroup Core
  29. class ctkFDHandler : public QThread
  30. {
  31. Q_OBJECT
  32. Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
  33. public:
  34. typedef ctkFDHandler Self;
  35. ctkFDHandler(ctkErrorLogFDMessageHandler* messageHandler,
  36. ctkErrorLogLevel::LogLevel logLevel,
  37. ctkErrorLogTerminalOutput::TerminalOutput terminalOutput);
  38. virtual ~ctkFDHandler();
  39. /// Enable/Disable the handler.
  40. void setEnabled(bool value);
  41. /// Return if the handler is enabled. This methods is thread-safe.
  42. bool enabled()const;
  43. FILE* terminalOutputFile();
  44. protected:
  45. void setupPipe();
  46. void run();
  47. private:
  48. ctkErrorLogFDMessageHandler * MessageHandler;
  49. ctkErrorLogLevel::LogLevel LogLevel;
  50. ctkErrorLogTerminalOutput::TerminalOutput TerminalOutput;
  51. int SavedFDNumber;
  52. fpos_t SavedFDPos;
  53. int Pipe[2]; // 0: Read, 1: Write
  54. bool Initialized;
  55. mutable QMutex EnableMutex;
  56. bool Enabled;
  57. };
  58. #endif