/src/logging-log4cxx/src/main/cpp/action.cpp
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | #include <log4cxx/logstring.h> |
18 | | #include <log4cxx/rolling/action.h> |
19 | | #include <log4cxx/private/action_priv.h> |
20 | | #include <log4cxx/helpers/loglog.h> |
21 | | #include <mutex> |
22 | | |
23 | | using namespace LOG4CXX_NS; |
24 | | using namespace LOG4CXX_NS::rolling; |
25 | | using namespace LOG4CXX_NS::helpers; |
26 | | |
27 | | IMPLEMENT_LOG4CXX_OBJECT(Action) |
28 | | |
29 | | Action::Action() : |
30 | 0 | m_priv( std::make_unique<Action::ActionPrivate>() ) |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | Action::Action( std::unique_ptr<ActionPrivate> priv ) : |
35 | 4 | m_priv( std::move(priv) ) {} |
36 | | |
37 | | Action::~Action() |
38 | 4 | { |
39 | 4 | } |
40 | | |
41 | | void Action::run() |
42 | 0 | { |
43 | 0 | std::lock_guard<std::mutex> lock(m_priv->mutex); |
44 | |
|
45 | 0 | if (!m_priv->closed) |
46 | 0 | { |
47 | 0 | try |
48 | 0 | { |
49 | 0 | execute(); |
50 | 0 | } |
51 | 0 | catch (std::exception& ex) |
52 | 0 | { |
53 | 0 | helpers::LogLog::error(getName() + LOG4CXX_STR(" raised the following exception"), ex); |
54 | 0 | } |
55 | |
|
56 | 0 | m_priv->complete = true; |
57 | 0 | m_priv->closed = true; |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | /** |
62 | | * {@inheritDoc} |
63 | | */ |
64 | | void Action::close() |
65 | 0 | { |
66 | 0 | std::lock_guard<std::mutex> lock(m_priv->mutex); |
67 | 0 | m_priv->closed = true; |
68 | 0 | } |
69 | | |
70 | | /** |
71 | | * Tests if the action is complete. |
72 | | * @return true if action is complete. |
73 | | */ |
74 | | bool Action::isComplete() const |
75 | 0 | { |
76 | 0 | return m_priv->complete; |
77 | 0 | } |
78 | | |
79 | | LogString Action::getName() const |
80 | 0 | { |
81 | 0 | return m_priv->actionName; |
82 | 0 | } |
83 | | |
84 | | #if LOG4CXX_ABI_VERSION <= 15 |
85 | | bool Action::execute() const |
86 | 4 | { |
87 | 4 | helpers::Pool p; |
88 | 4 | return execute(p); |
89 | 4 | } |
90 | | |
91 | | /** |
92 | | * Capture exception. |
93 | | * |
94 | | * @param ex exception. |
95 | | */ |
96 | | void Action::reportException(const std::exception& /* ex */) |
97 | 0 | { |
98 | 0 | } |
99 | | |
100 | | void Action::run(helpers::Pool&) |
101 | 0 | { |
102 | 0 | run(); |
103 | 0 | } |
104 | | #else |
105 | | bool Action::execute(helpers::Pool&) const |
106 | | { |
107 | | return execute(); |
108 | | } |
109 | | |
110 | | #endif |