| 1 | // |
| 2 | // Channel.h |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Logging |
| 6 | // Module: Channel |
| 7 | // |
| 8 | // Definition of the Channel class. |
| 9 | // |
| 10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 11 | // and Contributors. |
| 12 | // |
| 13 | // SPDX-License-Identifier: BSL-1.0 |
| 14 | // |
| 15 | |
| 16 | |
| 17 | #ifndef Foundation_Channel_INCLUDED |
| 18 | #define Foundation_Channel_INCLUDED |
| 19 | |
| 20 | |
| 21 | #include "Poco/Foundation.h" |
| 22 | #include "Poco/Configurable.h" |
| 23 | #include "Poco/Mutex.h" |
| 24 | #include "Poco/RefCountedObject.h" |
| 25 | #include "Poco/AutoPtr.h" |
| 26 | |
| 27 | |
| 28 | namespace Poco { |
| 29 | |
| 30 | |
| 31 | class Message; |
| 32 | |
| 33 | |
| 34 | class Foundation_API Channel: public Configurable, public RefCountedObject |
| 35 | /// The base class for all Channel classes. |
| 36 | /// |
| 37 | /// Supports reference counting based garbage |
| 38 | /// collection and provides trivial implementations |
| 39 | /// of getProperty() and setProperty(). |
| 40 | { |
| 41 | public: |
| 42 | typedef AutoPtr<Channel> Ptr; |
| 43 | |
| 44 | Channel(); |
| 45 | /// Creates the channel and initializes |
| 46 | /// the reference count to one. |
| 47 | |
| 48 | virtual void open(); |
| 49 | /// Does whatever is necessary to open the channel. |
| 50 | /// The default implementation does nothing. |
| 51 | |
| 52 | virtual void close(); |
| 53 | /// Does whatever is necessary to close the channel. |
| 54 | /// The default implementation does nothing. |
| 55 | |
| 56 | virtual void log(const Message& msg) = 0; |
| 57 | /// Logs the given message to the channel. Must be |
| 58 | /// overridden by subclasses. |
| 59 | /// |
| 60 | /// If the channel has not been opened yet, the log() |
| 61 | /// method will open it. |
| 62 | |
| 63 | void setProperty(const std::string& name, const std::string& value); |
| 64 | /// Throws a PropertyNotSupportedException. |
| 65 | |
| 66 | std::string getProperty(const std::string& name) const; |
| 67 | /// Throws a PropertyNotSupportedException. |
| 68 | |
| 69 | protected: |
| 70 | virtual ~Channel(); |
| 71 | |
| 72 | private: |
| 73 | Channel(const Channel&); |
| 74 | Channel& operator = (const Channel&); |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | } // namespace Poco |
| 79 | |
| 80 | |
| 81 | #endif // Foundation_Channel_INCLUDED |
| 82 | |