| 1 | // |
|---|---|
| 2 | // SplitterChannel.cpp |
| 3 | // |
| 4 | // Library: Foundation |
| 5 | // Package: Logging |
| 6 | // Module: SplitterChannel |
| 7 | // |
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 9 | // and Contributors. |
| 10 | // |
| 11 | // SPDX-License-Identifier: BSL-1.0 |
| 12 | // |
| 13 | |
| 14 | |
| 15 | #include "Poco/SplitterChannel.h" |
| 16 | #include "Poco/LoggingRegistry.h" |
| 17 | #include "Poco/StringTokenizer.h" |
| 18 | |
| 19 | |
| 20 | namespace Poco { |
| 21 | |
| 22 | |
| 23 | SplitterChannel::SplitterChannel() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | |
| 28 | SplitterChannel::~SplitterChannel() |
| 29 | { |
| 30 | try |
| 31 | { |
| 32 | close(); |
| 33 | } |
| 34 | catch (...) |
| 35 | { |
| 36 | poco_unexpected(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | |
| 41 | void SplitterChannel::addChannel(Channel::Ptr pChannel) |
| 42 | { |
| 43 | poco_check_ptr (pChannel); |
| 44 | |
| 45 | FastMutex::ScopedLock lock(_mutex); |
| 46 | _channels.push_back(pChannel); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void SplitterChannel::removeChannel(Channel::Ptr pChannel) |
| 51 | { |
| 52 | FastMutex::ScopedLock lock(_mutex); |
| 53 | |
| 54 | for (ChannelVec::iterator it = _channels.begin(); it != _channels.end(); ++it) |
| 55 | { |
| 56 | if (*it == pChannel) |
| 57 | { |
| 58 | _channels.erase(it); |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | |
| 65 | void SplitterChannel::setProperty(const std::string& name, const std::string& value) |
| 66 | { |
| 67 | if (name.compare(0, 7, "channel") == 0) |
| 68 | { |
| 69 | StringTokenizer tokenizer(value, ",;", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); |
| 70 | for (StringTokenizer::Iterator it = tokenizer.begin(); it != tokenizer.end(); ++it) |
| 71 | { |
| 72 | addChannel(LoggingRegistry::defaultRegistry().channelForName(*it)); |
| 73 | } |
| 74 | } |
| 75 | else Channel::setProperty(name, value); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | void SplitterChannel::log(const Message& msg) |
| 80 | { |
| 81 | FastMutex::ScopedLock lock(_mutex); |
| 82 | |
| 83 | for (ChannelVec::iterator it = _channels.begin(); it != _channels.end(); ++it) |
| 84 | { |
| 85 | (*it)->log(msg); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void SplitterChannel::close() |
| 91 | { |
| 92 | FastMutex::ScopedLock lock(_mutex); |
| 93 | _channels.clear(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | int SplitterChannel::count() const |
| 98 | { |
| 99 | FastMutex::ScopedLock lock(_mutex); |
| 100 | return (int) _channels.size(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | } // namespace Poco |
| 105 |