Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * qa_logger.cpp - QA for Logger 00004 * 00005 * Generated: Wed Jan 17 14:19:45 2007 00006 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 // Do not include in api reference 00025 ///@cond QA 00026 00027 #include <core/threading/thread.h> 00028 #include <utils/system/signal.h> 00029 #include <utils/logging/console.h> 00030 #include <utils/logging/multi.h> 00031 #include <utils/logging/logger.h> 00032 00033 #include <cstdio> 00034 00035 using namespace fawkes; 00036 00037 class LoggerQAThread : public Thread 00038 { 00039 public: 00040 LoggerQAThread(const char *name, Logger *logger) 00041 : Thread(name) 00042 { 00043 this->logger = logger; 00044 i = 0; 00045 } 00046 00047 virtual void loop() 00048 { 00049 ++i; 00050 printf("%s: Testing: %i\n", name(), i); 00051 logger->log_info(name(), "Testing: %i", i); 00052 } 00053 00054 private: 00055 unsigned int i; 00056 Logger *logger; 00057 }; 00058 00059 00060 class LoggerQAMain : public SignalHandler 00061 { 00062 public: 00063 LoggerQAMain() 00064 { 00065 cl = ml = NULL; 00066 t1 = t2 = t3 = t4 = t5 = t6 = NULL; 00067 } 00068 00069 ~LoggerQAMain() 00070 { 00071 delete t1; 00072 delete t2; 00073 delete t3; 00074 delete t4; 00075 delete t5; 00076 delete t6; 00077 // also deletes cl! 00078 delete ml; 00079 } 00080 00081 virtual void handle_signal(int signum) 00082 { 00083 printf("Signal received, cancelling threads\n"); 00084 t1->cancel(); 00085 t2->cancel(); 00086 t3->cancel(); 00087 t4->cancel(); 00088 t5->cancel(); 00089 t6->cancel(); 00090 printf("Threads cancelled\n"); 00091 } 00092 00093 void run() 00094 { 00095 cl = new ConsoleLogger(); 00096 ml = new MultiLogger(cl); 00097 00098 t1 = new LoggerQAThread("L-1-", ml); 00099 t2 = new LoggerQAThread("L-2-", ml); 00100 t3 = new LoggerQAThread("L-3-", ml); 00101 t4 = new LoggerQAThread("L-4-", ml); 00102 t5 = new LoggerQAThread("L-5-", ml); 00103 t6 = new LoggerQAThread("L-6-", ml); 00104 00105 t1->start(); 00106 t2->start(); 00107 t3->start(); 00108 t4->start(); 00109 t5->start(); 00110 t6->start(); 00111 t1->join(); 00112 t2->join(); 00113 t3->join(); 00114 t4->join(); 00115 t5->join(); 00116 t6->join(); 00117 } 00118 00119 private: 00120 Logger *cl; 00121 Logger *ml; 00122 LoggerQAThread *t1; 00123 LoggerQAThread *t2; 00124 LoggerQAThread *t3; 00125 LoggerQAThread *t4; 00126 LoggerQAThread *t5; 00127 LoggerQAThread *t6; 00128 }; 00129 00130 int 00131 main(int argc, char **argv) 00132 { 00133 00134 /* 00135 ConsoleLogger cl; 00136 00137 Exception e("Test Exception"); 00138 00139 cl.log_debug("QA", "DEBUG test output %i", 1); 00140 cl.log_info("QA", "DEBUG test output %i", 2); 00141 cl.log_warn("QA", "DEBUG test output %i", 3); 00142 cl.log_error("QA", "DEBUG test output %i", 4); 00143 00144 cl.log_debug("QA", e); 00145 cl.log_info("QA", e); 00146 cl.log_warn("QA", e); 00147 cl.log_error("QA", e); 00148 00149 ConsoleLogger *clp = new ConsoleLogger(); 00150 00151 clp->log_debug("QA", "DEBUG test output %i", 1); 00152 clp->log_info("QA", "DEBUG test output %i", 2); 00153 clp->log_warn("QA", "DEBUG test output %i", 3); 00154 clp->log_error("QA", "DEBUG test output %i", 4); 00155 00156 clp->log_debug("QA", e); 00157 clp->log_info("QA", e); 00158 clp->log_warn("QA", e); 00159 clp->log_error("QA", e); 00160 00161 LoggerTestThread *tt = new LoggerTestThread(clp); 00162 tt->start(); 00163 tt->join(); 00164 delete tt; 00165 00166 delete clp; 00167 */ 00168 00169 LoggerQAMain main; 00170 SignalManager::register_handler(SIGINT, &main); 00171 main.run(); 00172 SignalManager::finalize(); 00173 00174 return 0; 00175 } 00176 00177 /// @endcond