Apache Log4cxx Version 1.1.0
Loading...
Searching...
No Matches
aprinitializer.h
Go to the documentation of this file.
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
18#ifndef _LOG4CXX_HELPERS_APRINITIALIZER_H
19#define _LOG4CXX_HELPERS_APRINITIALIZER_H
20
21#ifndef LOG4CXX
22 #error "aprinitializer.h should only be included by log4cxx implementation"
23#endif
24
26#include <list>
28
29extern "C" {
32 struct apr_pool_t;
33}
34
35#include <mutex>
36#include <functional>
37
38namespace log4cxx
39{
40namespace helpers
41{
42class FileWatchdog;
43
45{
46 public:
47 static log4cxx_time_t initialize();
48 static apr_pool_t* getRootPool();
50 static bool isDestructed;
51
57 static void registerCleanup(FileWatchdog* watchdog);
58 static void unregisterCleanup(FileWatchdog* watchdog);
59 static void unregisterAll();
63 template <class T> static void setUnique(const std::shared_ptr<T>& pObject)
64 {
65 getInstance().addObject(typeid(T).hash_code(), pObject);
66 }
70 template <class T> static std::shared_ptr<T> getOrAddUnique(std::function<ObjectPtr()> creator)
71 {
72 return cast<T>(getInstance().findOrAddObject(typeid(T).hash_code(), creator));
73 }
74
75
76 private: // Constructors
78 APRInitializer(const APRInitializer&) = delete;
79 APRInitializer& operator=(const APRInitializer&) = delete;
80 private: // Modifiers
81 void addObject(size_t key, const ObjectPtr& pObject);
82 const ObjectPtr& findOrAddObject(size_t key, std::function<ObjectPtr()> creator);
83 void stopWatchDogs();
84 private: // Attributes
85 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(APRInitializerPrivate, m_priv)
86 private: // Class methods
87 static APRInitializer& getInstance();
88
89 public: // Destructor
91};
92} // namespace helpers
93} // namespace log4cxx
94
95#endif //_LOG4CXX_HELPERS_APRINITIALIZER_H
struct apr_threadkey_t apr_threadkey_t
Definition: aprinitializer.h:31
struct apr_thread_mutex_t apr_thread_mutex_t
Definition: aprinitializer.h:30
Definition: aprinitializer.h:45
static apr_threadkey_t * getTlsKey()
static std::shared_ptr< T > getOrAddUnique(std::function< ObjectPtr()> creator)
Fetch or add a single instance type ObjectPtr for deletion prior to termination.
Definition: aprinitializer.h:70
static void registerCleanup(FileWatchdog *watchdog)
Register a FileWatchdog for deletion prior to termination.
static log4cxx_time_t initialize()
static apr_pool_t * getRootPool()
static void setUnique(const std::shared_ptr< T > &pObject)
Store a single instance type ObjectPtr for deletion prior to termination.
Definition: aprinitializer.h:63
static bool isDestructed
Definition: aprinitializer.h:50
static void unregisterCleanup(FileWatchdog *watchdog)
Check every now and then that a certain file has not changed.
Definition: filewatchdog.h:39
std::shared_ptr< Object > ObjectPtr
Definition: optionconverter.h:41
Definition: configuration.h:25