Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * aspect_provider.cpp - Fawkes Aspect Provider initializer/finalizer 00004 * 00005 * Created: Thu Nov 25 12:20:43 2010 (Thanksgiving, Pittsburgh) 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/inifins/aspect_provider.h> 00025 #include <aspect/aspect_provider.h> 00026 #include <aspect/manager.h> 00027 00028 namespace fawkes { 00029 #if 0 /* just to make Emacs auto-indent happy */ 00030 } 00031 #endif 00032 00033 /** @class AspectProviderAspectIniFin <aspect/inifins/aspect_provider.h> 00034 * Initializer/finalizer for the AspectProviderAspect. 00035 * This initializer/finalizer will register the AspectIniFin instance with 00036 * the main aspect manager on init, and unregister it on finalization. it 00037 * will deny unloading if there are still threads using the provided aspect. 00038 * @author Tim Niemueller 00039 */ 00040 00041 /** Constructor. 00042 * @param manager aspect manager to register new aspects to 00043 */ 00044 AspectProviderAspectIniFin::AspectProviderAspectIniFin(AspectManager *manager) 00045 : AspectIniFin("AspectProviderAspect") 00046 { 00047 __aspect_manager = manager; 00048 } 00049 00050 00051 void 00052 AspectProviderAspectIniFin::init(Thread *thread) 00053 { 00054 AspectProviderAspect *provider_thread; 00055 provider_thread = dynamic_cast<AspectProviderAspect *>(thread); 00056 00057 if (provider_thread == NULL) { 00058 throw CannotInitializeThreadException("Thread '%s' claims to have the " 00059 "AspectProviderAspect, but RTTI says it " 00060 "has not. ", thread->name()); 00061 } 00062 00063 __aspect_manager->register_inifin(provider_thread->aspect_provider_inifin()); 00064 } 00065 00066 00067 bool 00068 AspectProviderAspectIniFin::prepare_finalize(Thread *thread) 00069 { 00070 AspectProviderAspect *p_thr; 00071 p_thr = dynamic_cast<AspectProviderAspect *>(thread); 00072 00073 if (p_thr == NULL) return true; 00074 00075 return ! __aspect_manager->has_threads_for_aspect(p_thr->aspect_provider_name()); 00076 } 00077 00078 00079 void 00080 AspectProviderAspectIniFin::finalize(Thread *thread) 00081 { 00082 AspectProviderAspect *provider_thread; 00083 provider_thread = dynamic_cast<AspectProviderAspect *>(thread); 00084 00085 if (provider_thread == NULL) { 00086 throw CannotFinalizeThreadException("Thread '%s' claims to have the " 00087 "AspectProviderAspect, but RTTI says it " 00088 "has not. ", thread->name()); 00089 } 00090 00091 __aspect_manager->unregister_inifin(provider_thread->aspect_provider_inifin()); 00092 } 00093 00094 00095 } // end namespace fawkes