Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * thread_producer.cpp - Thread producer aspect for Fawkes 00004 * 00005 * Created: Tue Nov 20 11:26:24 2007 00006 * Copyright 2006-2010 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 #include <aspect/thread_producer.h> 00025 00026 namespace fawkes { 00027 #if 0 /* just to make Emacs auto-indent happy */ 00028 } 00029 #endif 00030 00031 /** @class ThreadProducerAspect <aspect/thread_producer.h> 00032 * Aspect for thread producing threads. 00033 * Some threads have to be started by a plugin after it is loaded. Thus 00034 * they produce threads while they run. They may also stop this thread 00035 * at any one time. To have all these threads registered with a central 00036 * instance for easier instrumentation and performance assessment these 00037 * threads should be registered with a central thread collector. 00038 * 00039 * Additionally the threads that are produced can have aspects that are 00040 * then initialized by the thread collector (if running inside Fawkes). 00041 * Note that initializing an aspect may fail and then an exception is 00042 * thrown to indicate the error. You have to catch this exception and 00043 * you may never start a thread in that case or unpredictable behavior 00044 * will happen. 00045 * 00046 * This is possible with the ThreadProducerAspect. With this aspect you 00047 * get access to a thread collector instance to register threads with. 00048 * 00049 * Remember to unregister the produced threads if they are cancelled, 00050 * joined or even deleted! 00051 * 00052 * @ingroup Aspects 00053 * @author Tim Niemueller 00054 */ 00055 00056 00057 /** @var ThreadCollector * ThreadProducerAspect::thread_collector 00058 * Thread collector. 00059 * Use this thread collector to register/unregister threads as they are 00060 * created/deleted. It is set when the thread starts. 00061 */ 00062 00063 /** Constructor. */ 00064 ThreadProducerAspect::ThreadProducerAspect() 00065 { 00066 add_aspect("ThreadProducerAspect"); 00067 } 00068 00069 /** Virtual empty destructor. */ 00070 ThreadProducerAspect::~ThreadProducerAspect() 00071 { 00072 } 00073 00074 00075 /** Init thread producer aspect. 00076 * This set the thread collector. 00077 * It is guaranteed that this is called for a thread with the ThreadProducerAspect 00078 * before start is called (when running regularly inside Fawkes). 00079 * @param collector thread collector 00080 */ 00081 void 00082 ThreadProducerAspect::init_ThreadProducerAspect(ThreadCollector *collector) 00083 { 00084 thread_collector = collector; 00085 } 00086 00087 } // end namespace fawkes