A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / log4cplus / loggingserver / loggingserver.cxx
blob2a37a243d65fa535d693328744818c7ff02697a8
1 // Module: LOG4CPLUS
2 // File: loggingserver.cxx
3 // Created: 5/2003
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2003-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
13 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <cstdlib>
22 #include <iostream>
23 #include <log4cplus/config.hxx>
24 #include <log4cplus/configurator.h>
25 #include <log4cplus/consoleappender.h>
26 #include <log4cplus/socketappender.h>
27 #include <log4cplus/helpers/loglog.h>
28 #include <log4cplus/helpers/socket.h>
29 #include <log4cplus/helpers/threads.h>
30 #include <log4cplus/spi/loggerimpl.h>
31 #include <log4cplus/spi/loggingevent.h>
34 using namespace std;
35 using namespace log4cplus;
36 using namespace log4cplus::helpers;
37 using namespace log4cplus::thread;
40 namespace loggingserver {
41 class ClientThread : public AbstractThread {
42 public:
43 ClientThread(Socket clientsock_)
44 : clientsock(clientsock_)
46 cout << "Received a client connection!!!!" << endl;
49 ~ClientThread()
51 cout << "Client connection closed." << endl;
54 virtual void run();
56 private:
57 Socket clientsock;
65 int
66 main(int argc, char** argv)
68 if(argc < 3) {
69 cout << "Usage: port config_file" << endl;
70 return 1;
72 int port = std::atoi(argv[1]);
73 tstring configFile = LOG4CPLUS_C_STR_TO_TSTRING(argv[2]);
75 PropertyConfigurator config(configFile);
76 config.configure();
78 ServerSocket serverSocket(port);
79 if (!serverSocket.isOpen()) {
80 cout << "Could not open server socket, maybe port "
81 << port << " is already in use." << endl;
82 return 2;
85 while(1) {
86 loggingserver::ClientThread *thr =
87 new loggingserver::ClientThread(serverSocket.accept());
88 thr->start();
91 return 0;
95 ////////////////////////////////////////////////////////////////////////////////
96 // loggingserver::ClientThread implementation
97 ////////////////////////////////////////////////////////////////////////////////
100 void
101 loggingserver::ClientThread::run()
103 while(1) {
104 if(!clientsock.isOpen()) {
105 return;
107 SocketBuffer msgSizeBuffer(sizeof(unsigned int));
108 if(!clientsock.read(msgSizeBuffer)) {
109 return;
112 unsigned int msgSize = msgSizeBuffer.readInt();
114 SocketBuffer buffer(msgSize);
115 if(!clientsock.read(buffer)) {
116 return;
119 spi::InternalLoggingEvent event = readFromBuffer(buffer);
120 Logger logger = Logger::getInstance(event.getLoggerName());
121 logger.callAppenders(event);