AsyncChannel.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // AsyncChannel.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/AsyncChannel.h#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: AsyncChannel
  9. //
  10. // Definition of the AsyncChannel class.
  11. //
  12. // Copyright (c) 2004-2007, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_AsyncChannel_INCLUDED
  18. #define Foundation_AsyncChannel_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/Channel.h"
  21. #include "Poco/Thread.h"
  22. #include "Poco/Mutex.h"
  23. #include "Poco/Runnable.h"
  24. #include "Poco/NotificationQueue.h"
  25. namespace Poco {
  26. class Foundation_API AsyncChannel: public Channel, public Runnable
  27. /// A channel uses a separate thread for logging.
  28. ///
  29. /// Using this channel can help to improve the performance of
  30. /// applications that produce huge amounts of log messages or
  31. /// that write log messages to multiple channels simultaneously.
  32. ///
  33. /// All log messages are put into a queue and this queue is
  34. /// then processed by a separate thread.
  35. {
  36. public:
  37. AsyncChannel(Channel* pChannel = 0, Thread::Priority prio = Thread::PRIO_NORMAL);
  38. /// Creates the AsyncChannel and connects it to
  39. /// the given channel.
  40. void setChannel(Channel* pChannel);
  41. /// Connects the AsyncChannel to the given target channel.
  42. /// All messages will be forwarded to this channel.
  43. Channel* getChannel() const;
  44. /// Returns the target channel.
  45. void open();
  46. /// Opens the channel and creates the
  47. /// background logging thread.
  48. void close();
  49. /// Closes the channel and stops the background
  50. /// logging thread.
  51. void log(const Message& msg);
  52. /// Queues the message for processing by the
  53. /// background thread.
  54. void setProperty(const std::string& name, const std::string& value);
  55. /// Sets or changes a configuration property.
  56. ///
  57. /// The "channel" property allows setting the target
  58. /// channel via the LoggingRegistry.
  59. /// The "channel" property is set-only.
  60. ///
  61. /// The "priority" property allows setting the thread
  62. /// priority. The following values are supported:
  63. /// * lowest
  64. /// * low
  65. /// * normal (default)
  66. /// * high
  67. /// * highest
  68. ///
  69. /// The "priority" property is set-only.
  70. protected:
  71. ~AsyncChannel();
  72. void run();
  73. void setPriority(const std::string& value);
  74. private:
  75. Channel* _pChannel;
  76. Thread _thread;
  77. FastMutex _threadMutex;
  78. FastMutex _channelMutex;
  79. NotificationQueue _queue;
  80. };
  81. } // namespace Poco
  82. #endif // Foundation_AsyncChannel_INCLUDED