Coverage Report

Created: 2026-06-05 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/oflog/libsrc/apndimpl.cc
Line
Count
Source
1
// Module:  Log4CPLUS
2
// File:    appenderattachableimpl.cxx
3
// Created: 6/2001
4
// Author:  Tad E. Smith
5
//
6
//
7
// Copyright 2001-2010 Tad E. Smith
8
//
9
// Licensed under the Apache License, Version 2.0 (the "License");
10
// you may not use this file except in compliance with the License.
11
// You may obtain a copy of the License at
12
//
13
//     http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software
16
// distributed under the License is distributed on an "AS IS" BASIS,
17
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
// See the License for the specific language governing permissions and
19
// limitations under the License.
20
21
22
#include "dcmtk/oflog/appender.h"
23
#include "dcmtk/oflog/helpers/apndimpl.h"
24
#include "dcmtk/oflog/helpers/loglog.h"
25
#include "dcmtk/oflog/spi/logevent.h"
26
#include "dcmtk/oflog/thread/syncpub.h"
27
28
#include <algorithm>
29
30
31
namespace dcmtk
32
{
33
namespace log4cplus
34
{
35
36
37
namespace spi
38
{
39
40
41
AppenderAttachable::~AppenderAttachable()
42
27
{ }
43
44
45
} // namespace spi
46
47
48
namespace helpers
49
{
50
51
52
//////////////////////////////////////////////////////////////////////////////
53
// log4cplus::helpers::AppenderAttachableImpl ctor and dtor
54
//////////////////////////////////////////////////////////////////////////////
55
56
AppenderAttachableImpl::AppenderAttachableImpl() :
57
6
    appender_list_mutex(),
58
6
    appenderList()
59
6
{ }
60
61
62
AppenderAttachableImpl::~AppenderAttachableImpl()
63
0
{ }
64
65
66
67
///////////////////////////////////////////////////////////////////////////////
68
// log4cplus::helpers::AppenderAttachableImpl public methods
69
///////////////////////////////////////////////////////////////////////////////
70
71
void
72
AppenderAttachableImpl::addAppender(SharedAppenderPtr newAppender)
73
3
{
74
3
    if(newAppender == NULL) {
75
0
        getLogLog().warn( DCMTK_LOG4CPLUS_TEXT("Tried to add NULL appender") );
76
0
        return;
77
0
    }
78
79
3
    thread::MutexGuard guard (appender_list_mutex);
80
81
3
    ListType::iterator it = 
82
3
        STD_NAMESPACE find(appenderList.begin(), appenderList.end(), newAppender);
83
3
    if(it == appenderList.end()) {
84
3
        appenderList.push_back(newAppender);
85
3
    }
86
3
}
87
88
89
90
AppenderAttachableImpl::ListType
91
AppenderAttachableImpl::getAllAppenders()
92
0
{
93
0
    thread::MutexGuard guard (appender_list_mutex);
94
    
95
0
    return appenderList;
96
0
}
97
98
99
100
SharedAppenderPtr 
101
AppenderAttachableImpl::getAppender(const log4cplus::tstring& name)
102
0
{
103
0
    thread::MutexGuard guard (appender_list_mutex);
104
105
0
    for(ListType::iterator it=appenderList.begin(); 
106
0
        it!=appenderList.end(); 
107
0
        ++it)
108
0
    {
109
0
        if((*it)->getName() == name) {
110
0
            return *it;
111
0
        }
112
0
    }
113
114
0
    return SharedAppenderPtr(NULL);
115
0
}
116
117
118
119
void 
120
AppenderAttachableImpl::removeAllAppenders()
121
0
{
122
0
    thread::MutexGuard guard (appender_list_mutex);
123
124
0
    appenderList.clear();
125
0
}
126
127
128
129
void 
130
AppenderAttachableImpl::removeAppender(SharedAppenderPtr appender)
131
0
{
132
0
    if(appender == NULL) {
133
0
        getLogLog().warn( DCMTK_LOG4CPLUS_TEXT("Tried to remove NULL appender") );
134
0
        return;
135
0
    }
136
137
0
    thread::MutexGuard guard (appender_list_mutex);
138
139
0
    ListType::iterator it =
140
0
        STD_NAMESPACE find(appenderList.begin(), appenderList.end(), appender);
141
0
    if(it != appenderList.end()) {
142
0
        appenderList.erase(it);
143
0
    }
144
0
}
145
146
147
148
void 
149
AppenderAttachableImpl::removeAppender(const log4cplus::tstring& name)
150
0
{
151
0
    removeAppender(getAppender(name));
152
0
}
153
154
155
156
int 
157
AppenderAttachableImpl::appendLoopOnAppenders(const spi::InternalLoggingEvent& event) const
158
0
{
159
0
    int count = 0;
160
161
0
    thread::MutexGuard guard (appender_list_mutex);
162
163
0
    for(ListType::const_iterator it=appenderList.begin();
164
0
        it!=appenderList.end();
165
0
        ++it)
166
0
    {
167
0
        ++count;
168
0
        (*it)->doAppend(event);
169
0
    }
170
171
0
    return count;
172
0
}
173
174
175
} // namespace helpers
176
177
178
} // namespace log4cplus
179
} // end namespace dcmtk