source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/net/socketappenderskeleton.h@ 12

Last change on this file since 12 was 2, checked in by sgosseli, 12 years ago

Add 3rd party libraries (log4cxx).

File size: 6.7 KB
Line 
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_NET_SOCKET_APPENDER_SKELETON_H
19#define _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
20
21#include <log4cxx/appenderskeleton.h>
22#include <log4cxx/helpers/socket.h>
23#include <log4cxx/helpers/thread.h>
24#include <log4cxx/helpers/objectoutputstream.h>
25
26namespace log4cxx
27{
28
29 namespace net
30 {
31
32 /**
33 * Abstract base class for SocketAppender and XMLSocketAppender
34 */
35 class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton
36 {
37 private:
38 /**
39 host name
40 */
41 LogString remoteHost;
42
43 /**
44 IP address
45 */
46 helpers::InetAddressPtr address;
47
48 int port;
49 int reconnectionDelay;
50 bool locationInfo;
51
52 public:
53 SocketAppenderSkeleton(int defaultPort, int reconnectionDelay);
54 ~SocketAppenderSkeleton();
55
56 /**
57 Connects to remote server at <code>address</code> and <code>port</code>.
58 */
59 SocketAppenderSkeleton(helpers::InetAddressPtr address, int port, int reconnectionDelay);
60
61 /**
62 Connects to remote server at <code>host</code> and <code>port</code>.
63 */
64 SocketAppenderSkeleton(const LogString& host, int port, int reconnectionDelay);
65
66 /**
67 Connect to the specified <b>RemoteHost</b> and <b>Port</b>.
68 */
69 void activateOptions(log4cxx::helpers::Pool& p);
70
71 void close();
72
73
74 /**
75 * This appender does not use a layout. Hence, this method
76 * returns <code>false</code>.
77 *
78 */
79 bool requiresLayout() const
80 { return false; }
81
82 /**
83 * The <b>RemoteHost</b> option takes a string value which should be
84 * the host name of the server where a
85 * Apache Chainsaw or compatible is running.
86 * */
87 inline void setRemoteHost(const LogString& host)
88 { address = helpers::InetAddress::getByName(host);
89 remoteHost.assign(host); }
90
91 /**
92 Returns value of the <b>RemoteHost</b> option.
93 */
94 inline const LogString& getRemoteHost() const
95 { return remoteHost; }
96
97 /**
98 The <b>Port</b> option takes a positive integer representing
99 the port where the server is waiting for connections.
100 */
101 void setPort(int port1)
102 { this->port = port1; }
103
104 /**
105 Returns value of the <b>Port</b> option.
106 */
107 int getPort() const
108 { return port; }
109
110 /**
111 The <b>LocationInfo</b> option takes a boolean value. If true,
112 the information sent to the remote host will include location
113 information. By default no location information is sent to the server.
114 */
115 void setLocationInfo(bool locationInfo1)
116 { this->locationInfo = locationInfo1; }
117
118 /**
119 Returns value of the <b>LocationInfo</b> option.
120 */
121 bool getLocationInfo() const
122 { return locationInfo; }
123
124 /**
125 The <b>ReconnectionDelay</b> option takes a positive integer
126 representing the number of milliseconds to wait between each
127 failed connection attempt to the server. The default value of
128 this option is 30000 which corresponds to 30 seconds.
129
130 <p>Setting this option to zero turns off reconnection
131 capability.
132 */
133 void setReconnectionDelay(int reconnectionDelay1)
134 { this->reconnectionDelay = reconnectionDelay1; }
135
136 /**
137 Returns value of the <b>ReconnectionDelay</b> option.
138 */
139 int getReconnectionDelay() const
140 { return reconnectionDelay; }
141
142 void fireConnector();
143
144 void setOption(const LogString& option,
145 const LogString& value);
146
147 protected:
148
149 virtual void setSocket(log4cxx::helpers::SocketPtr& socket, log4cxx::helpers::Pool& p) = 0;
150
151 virtual void cleanUp(log4cxx::helpers::Pool& p) = 0;
152
153 virtual int getDefaultDelay() const = 0;
154
155 virtual int getDefaultPort() const = 0;
156
157 private:
158 void connect(log4cxx::helpers::Pool& p);
159 /**
160 The Connector will reconnect when the server becomes available
161 again. It does this by attempting to open a new connection every
162 <code>reconnectionDelay</code> milliseconds.
163
164 <p>It stops trying whenever a connection is established. It will
165 restart to try reconnect to the server when previpously open
166 connection is droppped.
167 */
168
169 helpers::Thread thread;
170 static void* LOG4CXX_THREAD_FUNC monitor(apr_thread_t* thread, void* data);
171 SocketAppenderSkeleton(const SocketAppenderSkeleton&);
172 SocketAppenderSkeleton& operator=(const SocketAppenderSkeleton&);
173
174 }; // class SocketAppenderSkeleton
175 } // namespace net
176} // namespace log4cxx
177
178#endif // _LOG4CXX_NET_SOCKET_APPENDER_SKELETON_H
179
Note: See TracBrowser for help on using the repository browser.