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