You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-05-06 15:25:19
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10683/plugins/LogTarget/Console Modified Files: ConsoleLogTarget.cpp Log Message: - Use the new Factory code. Index: ConsoleLogTarget.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console/ConsoleLogTarget.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ConsoleLogTarget.cpp 28 Apr 2005 11:22:14 -0000 1.2 +++ ConsoleLogTarget.cpp 6 May 2005 15:25:09 -0000 1.3 @@ -18,7 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "pclasses/Plugin/Plugin.h" +#include "pclasses/System/Plugin.h" #include "pclasses/App/LogTarget.h" #include <iostream> @@ -60,5 +60,5 @@ ostream* _out; }; -PLUGIN_REGISTER_TYPE(LogTarget, ConsoleLogTarget); -PLUGIN_REGISTER_ALIAS(LogTarget, Console, ConsoleLogTarget); +P_PLUGIN_REGISTER_TYPE(LogTarget, ConsoleLogTarget); +P_PLUGIN_REGISTER_ALIAS(LogTarget, Console, ConsoleLogTarget); |
From: Christian P. <cp...@us...> - 2005-05-06 15:25:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10491/include/pclasses/App Modified Files: LogTarget.h Log Message: - Use the new Factory code. Index: LogTarget.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/App/LogTarget.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LogTarget.h 24 Apr 2005 11:36:31 -0000 1.2 +++ LogTarget.h 6 May 2005 15:24:34 -0000 1.3 @@ -63,8 +63,7 @@ }; //! LogTarget factory -typedef NamedTypeFactory<LogTarget> LogTargetFactory; - +typedef Factory<LogTarget> LogTargetFactory; } // !namespace App |
From: Christian P. <cp...@us...> - 2005-05-06 15:25:03
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10491/src/App Modified Files: LogManager.cpp Log Message: - Use the new Factory code. Index: LogManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogManager.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- LogManager.cpp 28 Apr 2005 10:34:06 -0000 1.3 +++ LogManager.cpp 6 May 2005 15:24:35 -0000 1.4 @@ -19,7 +19,6 @@ ***************************************************************************/ #include "pclasses/Phoenix.h" -#include "pclasses/Plugin/Plugin.h" #include "pclasses/App/LogTarget.h" #include "pclasses/App/LogChannel.h" #include "pclasses/App/LogManager.h" @@ -112,9 +111,7 @@ LogTarget* LogManager::addTarget(LogChannel* channel, const std::string& name, const std::string& type) { - typedef Plugin::PluginManager<LogTarget> PM; - - LogTarget* target = PM::instance().create(type); + LogTarget* target = LogTargetFactory::instance().create(type); if(target) { if(!channel->addTarget(name, target)) |
From: Christian P. <cp...@us...> - 2005-05-06 15:22:55
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10123/src/System Added Files: Plugin.cpp Log Message: - Added new PluginManager based on the new Factory code --- NEW FILE: Plugin.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/pclasses-config.h" #include "pclasses/Factory.h" #include "pclasses/Trace.h" #include "pclasses/System/Plugin.h" #include "pclasses/System/Directory.h" namespace P { namespace System { PluginManager::PluginManager() { P_TRACE(PluginManager) << "PluginManager()"; } PluginManager::~PluginManager() { } PathFinder& PluginManager::pathFinder(const std::string& ifaceType) { PathFinderMap::iterator i = _pathFinders.find(ifaceType); if(i == _pathFinders.end()) { P_TRACE(PluginManager) << "add PathFinder for ifaceType=" << ifaceType; PathFinder& pathFinder = _pathFinders[ifaceType]; pathFinder.addExtension(std::string(".")+SharedLib::extension()); return pathFinder; } return i->second; } void PluginManager::addPluginDir(const std::string& ifaceType, const Unicode::String& dir) throw(SystemError) { P_TRACE(PluginManager) << "addPluginDir(" << ifaceType << ", " << dir << ")"; const Directory d(dir); // throws on error d.begin(); // avoid 'unused var' warning. // ^^^ need to find a more elegant solution for that. pathFinder(ifaceType).addPath( dir ); } SharedLib* PluginManager::addPlugin(const std::string& ifaceType, const Unicode::String& so_name) throw(SystemError) { // look for cached entry: PluginMap::const_iterator it = _pluginMap.find( so_name ); if( _pluginMap.end() != it ) { return (*it).second; } // find a DLL file: Unicode::String fn = pathFinder(ifaceType).find( so_name ); if( fn.empty() ) return 0; // check for entry cached under DLL's file name: it = _pluginMap.find( fn ); if( _pluginMap.end() != it ) { return (*it).second; } // open DLL and, if workie, cache it: SharedLib * shl = new SharedLib(fn); _pluginMap.insert(std::make_pair(fn,shl)); return shl; } PluginManager& PluginManager::instance() { static PluginManager inst; return inst; } class PluginTypeLoader { public: PluginTypeLoader() { FactoryBase::registerLoader(&loader); P_TRACE(PluginTypeLoader) << "PluginTypeLoader registered with FactoryBase"; } static void loader(const std::string& ifaceType, const std::string& contextType, const std::string& key) { P_TRACE_GLOBAL() << "PluginTypeLoader::loader() ifaceType=" << ifaceType << ", contextType=" << contextType << ", key=" << key; PluginManager& pluginMgr = PluginManager::instance(); pluginMgr.addPlugin(ifaceType, key); } }; PluginTypeLoader pluginLoader; } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-05-06 15:22:54
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10123/include/pclasses/System Added Files: Plugin.h Log Message: - Added new PluginManager based on the new Factory code --- NEW FILE: Plugin.h --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ // Based on the excellect Factory/Classloader code // from stephan beal <st...@s1...> #ifndef P_System_Plugin_h #define P_System_Plugin_h #include <pclasses/Export.h> #include <pclasses/NonCopyable.h> #include <pclasses/Unicode/String.h> #include <pclasses/System/PathFinder.h> #include <pclasses/System/SharedLib.h> #include <map> #include <string> #include <typeinfo> namespace P { namespace System { class PSYSTEM_EXPORT PluginManager: public NonCopyable { public: typedef std::map<Unicode::String, SharedLib*> PluginMap; typedef std::map<std::string, PathFinder> PathFinderMap; void addPluginDir(const std::string& ifaceType, const Unicode::String& dir) throw(SystemError); template <class TypeName> void addPluginDir(const Unicode::String& dir) throw(SystemError) { addPluginDir(typeid(TypeName).name(), dir); } SharedLib* addPlugin(const std::string& ifaceType, const Unicode::String& soName) throw(SystemError); template <class TypeName> void addPlugin(const Unicode::String& soName) throw(SystemError) { addPlugin(typeid(TypeName).name(), soName); } static PluginManager& instance(); private: PathFinder& pathFinder(const std::string& ifaceType); PluginManager(); ~PluginManager(); PathFinderMap _pathFinders; PluginMap _pluginMap; }; } // !namespace System } // !namespace P //! Registers a type in the Factory on static initialization /*! \param Iface Interface of the type to be registered \param type Type to register */ #define P_PLUGIN_REGISTER_TYPE(Iface, type) \ void type##_Factory_init() { P_FACTORY_REGISTER_TYPE(Iface, type); } \ int type##_Factory_init_placeholder = ( type##_Factory_init(), 0 ); #define P_PLUGIN_REGISTER_ALIAS(Iface, alias, type) \ void type##_Factory_alias_init() { P_FACTORY_REGISTER_ALIAS(Iface, alias, type); } \ int type##_Factory_alias_init_placeholder = ( type##_Factory_alias_init(), 0 ); #endif |
From: Christian P. <cp...@us...> - 2005-05-06 15:22:54
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10123/include/pclasses/Plugin Removed Files: Plugin.h Log Message: - Added new PluginManager based on the new Factory code --- Plugin.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-05-06 15:21:13
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9502/include/pclasses Modified Files: AtomicTraits.h Added Files: CoreMutex.h Log Message: - Renamed AtomicMutex to CoreMutex. We need a mutex in the core module for thread-safety. Index: AtomicTraits.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/AtomicTraits.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- AtomicTraits.h 23 Apr 2005 11:59:08 -0000 1.5 +++ AtomicTraits.h 6 May 2005 15:21:01 -0000 1.6 @@ -21,40 +21,14 @@ #ifndef P_AtomicTraits_h #define P_AtomicTraits_h +#include <pclasses/pclasses-config.h> #include <pclasses/Export.h> +#include <pclasses/CoreMutex.h> namespace P { namespace Traits { -//! AtomicMutex -/*! - The AtomicMutex class is used by the default implementation of - AtomicTraits<> to provide atomicity for types that dont have a - AtomicTraits specialisation. -*/ -class PCORE_EXPORT AtomicMutex { - public: - AtomicMutex(); - ~AtomicMutex(); - - void lock() throw(); - void unlock() throw(); - - class ScopedLock { - public: - ScopedLock(AtomicMutex& mtx); - ~ScopedLock(); - - private: - AtomicMutex& _mtx; - }; - - private: - unsigned long _handle; -}; - - //! Atomic traits /*! The AtomicTraits template supplies the actual implementation for the @@ -66,6 +40,8 @@ template <class Type> struct AtomicTraits { + typedef CoreMutex AtomicMutex; + struct AtomicType { Type value; AtomicMutex lock; --- NEW FILE: CoreMutex.h --- /*************************************************************************** * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_CoreMutex_h #define P_CoreMutex_h #include <pclasses/Export.h> #include <pclasses/NonCopyable.h> namespace P { //! CoreMutex /*! The CoreMutex class is a minimalistic Mutex class used by the P::Classes Core module where locking is necessary. */ class PCORE_EXPORT CoreMutex: public NonCopyable { public: CoreMutex(); ~CoreMutex(); void lock() throw(); void unlock() throw(); class ScopedLock: public NonCopyable { public: ScopedLock(CoreMutex& mtx); ~ScopedLock(); private: CoreMutex& _mtx; }; private: unsigned long _handle; }; } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-05-06 15:21:11
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9502/src Added Files: CoreMutex.posix.cpp CoreMutex.win32.cpp Removed Files: AtomicMutex.posix.cpp AtomicMutex.win32.cpp Log Message: - Renamed AtomicMutex to CoreMutex. We need a mutex in the core module for thread-safety. --- NEW FILE: CoreMutex.win32.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/CoreMutex.h" #include <windows.h> namespace P { namespace Traits { CoreMutex::CoreMutex() : _handle((unsigned long)new CRITICAL_SECTION) { InitializeCriticalSection((CRITICAL_SECTION*)_handle)); } CoreMutex::~CoreMutex() { DeleteCriticalSection((CRITICAL_SECTION*)_handle)); delete (CRITICAL_SECTION*)_handle; } void CoreMutex::lock() throw() { EnterCriticalSection((CRITICAL_SECTION*)_handle)); } void CoreMutex::unlock() throw() { LeaveCriticalSection((CRITICAL_SECTION*)_handle)); } CoreMutex::ScopedLock::ScopedLock(CoreMutex& mtx) : _mtx(mtx) { _mtx.lock(); } CoreMutex::ScopedLock::~ScopedLock() { _mtx.unlock(); } } // !namespace Traits } // !namespace P --- NEW FILE: CoreMutex.posix.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/CoreMutex.h" #include <pthread.h> namespace P { namespace Traits { CoreMutex::CoreMutex() : _handle((unsigned long)new pthread_mutex_t) { pthread_mutex_init((pthread_mutex_t*)_handle, 0); } CoreMutex::~CoreMutex() { pthread_mutex_destroy((pthread_mutex_t*)_handle); delete (pthread_mutex_t*)_handle; } void CoreMutex::lock() throw() { pthread_mutex_lock((pthread_mutex_t*)_handle); } void CoreMutex::unlock() throw() { pthread_mutex_unlock((pthread_mutex_t*)_handle); } CoreMutex::ScopedLock::ScopedLock(CoreMutex& mtx) : _mtx(mtx) { _mtx.lock(); } CoreMutex::ScopedLock::~ScopedLock() { _mtx.unlock(); } } // !namespace Traits } // !namespace P --- AtomicMutex.posix.cpp DELETED --- --- AtomicMutex.win32.cpp DELETED --- |
From: Christian P. <cp...@us...> - 2005-05-06 15:16:25
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7519/include/pclasses Modified Files: Factory.h Log Message: - Rewrite of Factory<>. The new Factory eliminates the problem that client- and library code use different Factory instances. We address this problem by introducing a non-templated base class for the Factory template. Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Factory.h 28 Apr 2005 10:35:39 -0000 1.21 +++ Factory.h 6 May 2005 15:16:01 -0000 1.22 @@ -1,535 +1,284 @@ -#ifndef p_FACTORY_H_INCLUDED -#define p_FACTORY_H_INCLUDED 1 -// Author: stephan beal <st...@s1...> -// License: Public Domain +/*************************************************************************** + * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * + * cp...@se... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ -#include <string> -#include <map> +// Based on the excellect Factory/Classloader code +// from stephan beal <st...@s1...> -#include <functional> +#ifndef P_Factory_h +#define P_Factory_h -#include <pclasses/Phoenix.h> // i don't like this dep, but i also don't like - // what happens in some cases when i don't use - // phoenix. :/ -#include <pclasses/SharingContext.h> #include <pclasses/Trace.h> +#include <pclasses/Export.h> +#include <pclasses/NonCopyable.h> +#include <pclasses/SharingContext.h> -namespace P -{ - /** - The Hook namespace holds classes intended to be used to - allow client-side code to hook in to the framework's - behaviour, replacing certain parts of the core with their - own. - */ - namespace Hook - { - /** - FactoryCreateHook is a helper object factory for the P::Factory - API. - - General conventions: - - SubT must derive from (or be) T and must be Default - Constructuable on the heap. In short, the following must be - able to succeed: - - <pre> - T * foo = new SubT; - </pre> - - Clients may freely specialize this type to hook their - factories in to P, and the above 'new' requirement need - not be imposed by client-side specializations. For example, - specializations are used to provide no-op factories for - abstract types, where 'new T' cannot work. - */ - - template < class T, class SubT > - struct FactoryCreateHook - { - /** - The type returned by create() and - operator(). - */ - typedef T * ResultType; - - /** - A typedef for the second template parameter for this - type. - */ - typedef SubT actual_type; - - /** - This creates a new SubT, which is assumed to be a - subclass of T. It can be used as a factory for - Factory & class_loader. - - If T or SubT are abstract types, you must - specialize this type such that create() returns 0 - for those. That is, we "simulate" creation of - abstract types by returning 0. - - The caller owns the returned pointer, which - may be 0. - */ - static ResultType create() - { - return new actual_type; - } - - /** - Same as create(). - */ - ResultType operator()() - { - return this->create(); - } - }; - - - /** - FactoryInstanceHook provides a way for non-core - code to manipulate or swap out the object returned - by Factory::instance(). - - Client code may want to specialize this to, e.g., plug in a - DLL-aware object lookups, auto-loading of plugins, etc. - - Specializing this type on a specific T will cause: - - MyFacT & fac = MyFacT::instance(); - - to trigger a call to operator()( fac ) the first - time fac is initialized AND on any re-initializations - (which may get called post-main()). - - - FactoryT is expected to be of type ::P::Factory<>, - but there is nothing in the implementation which is actually - specific to that type. - */ - template <typename FactoryT> - struct FactoryInstanceHook - { - typedef FactoryInstanceHook<FactoryT> ThisType; - - /** - Specializations of this type may initialize - instance() here. It will be called whenever Phoenix - initializes the object. See Phoenix for details. - - The default implementation does nothing. - */ - void operator()( FactoryT & ) throw() - { - } - - /** - The default implementation returns a shared Factory object. - THIS type's operator() will be called on the factory immediately - after creating the factory. - */ - static FactoryT & instance() - { - typedef ::P::Phoenix<FactoryT, ::P::Sharing::FactoryContext, ThisType > PHX; - return PHX::instance(); - } - }; - } // namespace Hook - - - /** - Factory is essentially a static classloader, capable of - loading classes by using registered factories for a given - set of keys (e.g., class names). - - Classloaders, at least in my experience, need to be able to - load all classes which derive from some given type. Without - a common base class, one can't safely attempt to cast from - an arbitrary pointer to the type we want to load. That's - where the InterfaceT parameter comes in. All objects - instantiated via this loader must inherit from InterfaceT. - - KeyType is a type which specifies the type of key used to - look up classes, defaulting to std::string. - - For this default implementation, both InterfaceT and - KeyType must be Default Constructable, and InterfaceT must - be constructable on the heap (e.g., via new - InterfaceT()). Clients supplying FactoryCreateHook or - FactoryInstanceHook specializations may apply other - requirements to InterfaceT and ImplT - - Thus InterfaceT must be a "plain type", without any pointer - or reference qualification. - - The default implementation holds no per-instance state, - thus it can be copied quickly. - - Sample usage: +#include <map> +#include <list> +#include <string> +#include <typeinfo> - <pre> -Factory<MyInterface> & fac = Factory<MyInterface>::instance(); -fac.registerFactory( "my_key", P::Hook::FactoryCreateHook<MyInterface,MyClass>::create ); -MyInterface *foo = fac.create( "some_key" ); // == NULL -foo = fac.create( "my_key" ); // == a new MyClass object - </pre> +namespace P { - Note that all instantiations of the same Factory type use - the same object factories map. The ContextType template - parameter can be used to limit the scope of a - Factory<InterfaceT>, such that it it does not collide with - other Factory<InterfaceT> instantiations. ContextType is - only used as a marker type, and is never instantiated by - this class. Used cleverly, it can allow you quite a bit - of freedom in what code has access to which factories. - */ - template < class InterfaceT, - class ContextT = Sharing::FactoryContext, - class KeyType = std::string - > - class Factory - { +//! Base class for the Factory template class +/*! + We need this base class to ensure that client- and library-code + will share the same Factory-instances. If we would put the instance- + creation code into a template class each compilation unit will use + it's own instance, leading to unwanted behaviour. +*/ +class PCORE_EXPORT FactoryBase: public NonCopyable { public: + //! Type for factory creation hook function + typedef FactoryBase* (*FactoryCreateFunc)(); + //! Type for type loader hook functions + typedef void (*LoaderFunc)(const std::string&, const std::string&, + const std::string&); - /** - A typedef for the KeyType used by this class. + //! Register a type loader hook + /*! + Loaders are called by the Factory class when no type is known + for a requested key. This allows non-core- and client-code to + register types with the Factory on their first use. + For example, the PluginManager makes use of this function to + dynamically load types from DLLs. + \param lf A pointer to a type-loader hook function. */ - typedef KeyType key_type; + static void registerLoader(LoaderFunc lf); - /** Same as ContextT parameterized type. */ - typedef ContextT ContextType; + protected: - /** - A typedef for the InterfaceT used by this class. - For conformance with the Adaptable Unary Functor - model - */ - typedef InterfaceT value_type; - /** - Same as (InterfaceT *). + //! Returns the Factory-instance for the given interface-type + /*! + This function returns the shared instance of a Factory object + for the given interface and context-type. If no existing instance + is found, a new one is created by a call to the given + FactoryCreateFunc. + Note that the type-strings are obtained by a call to + typeid(Type).name(). + \param ifaceType The interface for which the Factory should be + returned. + \param contextType The context for which the Factory should be + returned. + \param func A pointer to the function which gets called when the + Factory is created. */ - typedef InterfaceT * ResultType; + static FactoryBase& instance(const std::string& ifaceType, + const std::string& contextType, + FactoryCreateFunc func); - /** - Convenience typedef. + //! Runs all registered type-loaders + /*! + This method calls all registered type-loaders. + Note that the type-strings are obtained using a call to + typeid(Type).name(). + \param ifaceType The interface for which types should be loaded. + \param contextType The context in which types should be loaded. + \param key The requested key (class name) for the given interface. */ - typedef Factory< InterfaceT, ContextType, KeyType > ThisType; + static void loadType(const std::string& ifaceType, + const std::string& contextType, const std::string& key); - /** - A map type for storing lookup key aliases. - */ - typedef std::map<key_type,key_type> AliasMap; + FactoryBase(); + ~FactoryBase(); +}; +//! Type factory +/*! + Factory is essentially a static classloader, capable of loading classes + by using registered factories for a given set of keys (e.g., class names). - Factory() {} + InterfaceT must be default constructable. - virtual ~Factory() {} + Note that all instantiations of the same Factory type use the same object + factories map. The ContextT template parameter can be used to limit the + scope of a Factory<InterfaceT>, such that it does not collide with other + Factory<InterfaceT> instantiations. ContextT is only used as a marker + type, and is never instantiated by this class. Used cleverly, it can allow + you quite a bit of freedom in what code has access to which factories. +*/ +template <class InterfaceT, class ContextT = Sharing::FactoryContext> +class Factory: FactoryBase { + public: + typedef InterfaceT* (*TypeCreateFunc)(); - /** - The type of factories used by this class: a - function taking void and returning (value_type - *). See factoryMap(). + typedef std::map<std::string, TypeCreateFunc> FactoryMap; + typedef std::map<std::string, std::string> AliasMap; - todo: implement proper functor support. + //! Instantiate an object + /*! + Tries to instantiate an instance of InterfaceT using the given + key. Returns NULL if no object could be created for the given key. */ - typedef ResultType ( *FactoryFuncType ) (); + InterfaceT* create(const std::string& key) + { + std::string realKey = expandAlias(key); + typename FactoryMap::const_iterator i = + _factoryMap.find(realKey); - /** - Internal container type used for mapping keys to - factories. - */ - typedef std::map < key_type, FactoryFuncType > FactoryMap; + // try to load the requested type via the registered loaders... + if(i == _factoryMap.end()) + { + loadType(typeid(InterfaceT).name(), typeid(ContextT).name(), + realKey); + i = _factoryMap.find(realKey); + } - /** - Returns the map of classname aliases. - */ - AliasMap & aliases() - { - return ::P::Phoenix<AliasMap,ThisType>::instance(); + if(i != _factoryMap.end()) + return (i->second)(); + + return 0; } - /** - Returns the map of classname aliases. - */ - const AliasMap & aliases() const + void destroy(InterfaceT* obj) { - return ::P::Phoenix<AliasMap,ThisType>::instance(); + delete obj; } - /** - Aliases 'alias' as an equivalent of 'isthesameas'. - - This can be used to register multiple named via a - single factory. - */ - void alias( const key_type & alias, const key_type & isthesameas ) + //! Add an alias for a class-name + /*! + Adds an alias for a class-name. This can be used to register multiple + names via a single factory. Note that aliases are allowed to be + recursive. + \param aliasKey The alias that should be added. + \param isKey The key (class-name) that alias should expand to. + */ + void alias(const std::string& aliasKey, const std::string& isKey) { - this->aliases()[alias] = isthesameas; + P_TRACE(Factory) << "Register alias=" << aliasKey + << " for key=" << isKey; + + _aliasMap.insert(std::make_pair(aliasKey, isKey)); } - /** - Expands the given alias recursively. If a recursive alias is detected, - the last expansion is returned - i.e., the same as _alias. - */ - key_type expandAliases( const key_type & _alias ) const + //! Expand alias + /*! + Expands the given alias recursively. If a recursive alias is detected, + the last expansion is returned - i.e., the same as <alias>. + \param alias The alias that should be expanded. + */ + std::string expandAlias(const std::string& alias) const { - P_TRACE(Factory) << "expandAlias("<<_alias<<")"; - typename AliasMap::const_iterator cit = this->aliases().find( _alias ), - cet = this->aliases().end(); - if( cet == cit ) + P_TRACE(Factory) << "expandAlias("<<alias<<")"; + typename AliasMap::const_iterator cit = _aliasMap.find(alias), + cet = _aliasMap.end(); + if(cet == cit) { - P_TRACE(Factory) << "No alias found for '"<<_alias<<"'"; - return _alias; + P_TRACE(Factory) << "No alias found for '"<<alias<<"'"; + return alias; } - key_type exp = (*cit).second; - while( 1 ) + std::string exp = (*cit).second; + while(1) { - cit = this->aliases().find( exp ); - if( cet == cit ) + cit = _aliasMap.find(exp); + if(cet == cit) { - P_TRACE(Factory) << "Returning '"<<_alias<<"' unaliased: '" << exp<<"'"; + P_TRACE(Factory) << "Returning '"<<alias<<"' unaliased: '" << exp << "'"; return exp; } exp = (*cit).second; - if( exp == _alias ) - { // circular aliasing - P_TRACE(Factory) << "Warning: circular alias '"<<_alias<<"'."; + if(exp == alias) + { + P_TRACE(Factory) << "Warning: circular alias '"<<alias<<"'."; return exp; } } return exp; } - - /** - Tries to instantiate an instance of value_type - using the given key. Returns 0 if no object - could be loaded for the given key. - - Subtypes are free to implement, e.g., DLL lookups. - - This implementation calls expandAliases(_key) to - unexpand any aliased class names. Subclasses - "should" do the same, but are not strictly required - to. + //! Test if the factory provides a type + /*! + Returns true if the given key is registered. */ - virtual ResultType create( const key_type & _key ) // throw() ???? + bool provides(const std::string& key) const { - key_type key = this->expandAliases( _key ); - typename FactoryMap::const_iterator it = factoryMap().find( key ); - if ( it != factoryMap().end() ) // found a factory? + std::string realKey = expandAlias(key); + typename FactoryMap::const_iterator i = _factoryMap.find(realKey); + if(i == _factoryMap.end()) { - return ( it->second ) (); // run our factory. - } - return 0; - } - - - /** - Deletes obj. Subclasses are free to do custom - accounting, garbage collection, or whatever, by - overriding this. - - Note that it is not practical to expect all clients - to call this in order to destroy their objects, so - the utility of this function is highly arguable. + loadType(typeid(InterfaceT).name(), typeid(ContextT).name(), + realKey); - Subclasses are free to dictate a must-destroy() - policy if they wish. - */ - virtual void destroy( ResultType obj ) - { - delete obj; - } + i = _factoryMap.find(realKey); + } - /** - Returns this->create(key). - */ - ResultType operator()( const key_type & key ) - { - return this->create( key ); + return i != _factoryMap.end(); } - - /** - Registers a factory using the given key. If fp is - NULL then a default factory is used. Note that fp - may not return a type other than - ThisType::value_type *, but the actual object it - creates may be a polymorphic subclass of - value_type. See the FactoryCreateHook class for a - factory which does this subtype-to-base conversion. + //! Register a factory using the given key + /*! + Registers a factory using the given key. Note that fc may not + return a type other than InterfaceT *, but the actual object + it creates may be a polymorphic subclass of InterfaceT. */ - virtual void registerFactory( const key_type & key, FactoryFuncType fp ) - { - P_TRACE(Factory) << "registerFactory("<<key<<",facfunc)"; - factoryMap().insert( typename FactoryMap::value_type( key, fp ) ); - } - - template <typename TypeName> - void registerType( const key_type & key, TypeName ) + void registerFactory(const std::string& key, TypeCreateFunc fc) { - registerFactory( key, Hook::FactoryCreateHook<InterfaceT,TypeName>::create ); - } - - /** - Returns the internal key-to-factory map. It is safe - for clients to modify this except in multi-threaded - environments, and then all guarantees go out the - window. That said, it should never be necessary for - clients to use this. - - TODO: use a Hook or Traits type to allow the user - to replace this object with his own, so that he can - control the scope of the map more fully. - - - At the moment this returns the same object for all - instances of ThisType. Providing a private map from - each instance is under consideration. If we do that - we also will have to change aliasing support to - work the same. + P_TRACE(Factory) << "registerFactory(): key=" << key << ", fc=" + << typeid(fc).name(); - The reasoning behind using static factory maps is - essentially this: we can only have one definition - of each type. We normally want factories to always - return an instance constructed in the same way. If - we allow multiple factories per type we might - introduce hard-to-track inconsistencies in client - code, where different factories than intended are - accidentally used. OTOH, private factory maps - would open up some interesting possibilities. - */ - FactoryMap & factoryMap() - { - //return this->m_facs; - return Phoenix<FactoryMap,ContextType>::instance(); - } - const FactoryMap & factoryMap() const - { - //return this->m_facs; - return Phoenix<FactoryMap,ContextType>::instance(); + _factoryMap.insert(std::make_pair(key, fc)); } - /** - Returns true if the given key is registered. This is sometimes useful - for checking whether a factory needs to be re-registered, which - is sometimes necessary post-main(), when the internal map gets hosed - before clients are done using it. + //! Register a type using a default-factory + /*! + Registers a type using a default-factory implementation and the + given key. */ - bool provides( const key_type & key ) const + template <class TypeName> + void registerType(const std::string& key, TypeName) { - return factoryMap().end() != factoryMap().find( key ); + registerFactory(key, &typeCreateHook<TypeName>); } - /** - Returns a shared reference to a Factory. - - */ - static Factory & instance() + //! Returns the shared instance of the Factory + static Factory& instance() { - return Hook::FactoryInstanceHook<ThisType>::instance(); + return static_cast<Factory&>( + FactoryBase::instance(typeid(InterfaceT).name(), + typeid(ContextT).name(), &createHook)); } -// private: -// FactoryMap m_facs; - - }; // class Factory - - /** - NamedTypeFactory works for string-keyed types. It is - expected that this will be the most-used factory - implementation, as non-string-keyed factories are rare in - practice (but sometimes very useful). - A note to doxygen users: for some reason the parent class - isn't showing up via doxygen. :/ See Factory<InterfaceT>. - */ - template <typename InterfaceT> - struct NamedTypeFactory : public Factory< InterfaceT, Sharing::FactoryContext, std::string > - { - typedef Factory< InterfaceT, Sharing::FactoryContext, std::string > ParentType; - - typedef typename ParentType::ResultType ResultType; - typedef typename ParentType::FactoryFuncType FactoryFuncType; - - virtual ~NamedTypeFactory(){} - }; - - /* - Two helper macros to register types with the plugin manager... - added by cproch - */ - - //! Register type with NamedTypeFactory - #define NAMEDTYPEFACTORY_REGISTER_TYPE(b, c) \ - P::NamedTypeFactory<b>::instance().registerType(#c, c()) + private: + Factory() {} + ~Factory() {} - //! Register type-alias with NamedTypeFactory - #define NAMEDTYPEFACTORY_REGISTER_ALIAS(b, n, c) \ - P::NamedTypeFactory<b>::instance().registerType(n, c()) + static FactoryBase* createHook() + { return new Factory(); } - /** - The CL namespace encapsulates P's classloader-related API. + template <class TypeName> + static InterfaceT* typeCreateHook() + { return new TypeName(); } - All of the functions in this API use the object - NamedTypeFactory<InterfaceT>::instance() for - factory-related operations. Thus, using the various Hook - classes you can force these functions to use your factory. + FactoryMap _factoryMap; + AliasMap _aliasMap; +}; - i don't like this namespace. Maybe move these functions - into Factory itself??? They're simply proxying that type, - after all. - */ - namespace CL { - - using namespace ::P; +} // !namespace P - /** - Registers classname with InterfaceT. If factory_function is 0 - then ::P::Hook::FactoryCreateHook<InterfaceT,InterfaceT>::create is - used. If InterfaceT is abstract then you must specialize - ::P::Hook::FactoryCreateHook<InterfaceT,InterfaceT>, as documented - in FactoryCreateHook::create(). - */ - template <typename InterfaceT> - void registerBase( const std::string & classname, InterfaceT *(*factory_function)() = 0 ) - { - NamedTypeFactory<InterfaceT>::instance().registerFactory( classname, - ( 0 != factory_function ) - ? factory_function - : ::P::Hook::FactoryCreateHook<InterfaceT,InterfaceT>::create - ); - } - /** - Registers a factory creating ImplT objects with the - InterfaceT classloader. If factory_function is 0 then - ::P::Hook::FactoryCreateHook<InterfaceT,ImplT>::create is - used. - */ - template <typename InterfaceT, typename ImplT> - void registerSubtype( const std::string & classname, InterfaceT *(*factory_function)() = 0 ) - { - NamedTypeFactory<InterfaceT>::instance().registerFactory( classname, - ( 0 != factory_function ) - ? factory_function - : ::P::Hook::FactoryCreateHook<InterfaceT,ImplT>::create - ); - } - - /** - Returns the same as NamedTypeFactory<InterfaceT>::instance().create( classname ). - */ - template <typename InterfaceT> - InterfaceT * create( const std::string & classname ) - { - return NamedTypeFactory<InterfaceT>::instance().create( classname ); - } - } // namespace CL +//! Register type with the Factory +#define P_FACTORY_REGISTER_TYPE(Iface, c) \ + P::Factory<Iface>::instance().registerType(#c, c()) +//! Register alias with the Factory +#define P_FACTORY_REGISTER_ALIAS(Iface, a, c) \ + P::Factory<Iface>::instance().alias(#a, #c) -} // namespace P -#endif // p_FACTORY_H_INCLUDED +#endif |
From: Christian P. <cp...@us...> - 2005-05-06 15:16:14
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7519/src Added Files: Factory.cpp Log Message: - Rewrite of Factory<>. The new Factory eliminates the problem that client- and library code use different Factory instances. We address this problem by introducing a non-templated base class for the Factory template. --- NEW FILE: Factory.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Trace.h" #include "pclasses/Factory.h" namespace P { /* The FactoryInstanceMap holds the instances of our Factory objects. */ class FactoryInstanceMap { public: typedef std::pair<std::string, std::string> InstanceKey; typedef std::map<InstanceKey, FactoryBase*> FactoryMap; static FactoryInstanceMap& instance() { static FactoryInstanceMap inst; return inst; } void addFactory(const std::string& ifaceType, const std::string& contextType, FactoryBase* fac) { P_TRACE(FactoryInstanceMap) << "FactoryBase added for ifaceType=" << ifaceType << ", contextType=" << contextType; _factories[std::make_pair(ifaceType,contextType)] = fac; } FactoryBase* findFactory(const std::string& ifaceType, const std::string& contextType) { FactoryMap::const_iterator i = _factories.find(std::make_pair(ifaceType,contextType)); return i != _factories.end() ? i->second : 0; } private: FactoryInstanceMap() {} ~FactoryInstanceMap() {} FactoryMap _factories; }; typedef std::list<FactoryBase::LoaderFunc> FactoryLoaderList; FactoryLoaderList FactoryLoaders; FactoryBase::FactoryBase() { } FactoryBase::~FactoryBase() { } void FactoryBase::loadType(const std::string& ifaceType, const std::string& contextType, const std::string& key) { P_TRACE_GLOBAL() << "FactoryBase::loadType() running loaders for ifaceType=" << ifaceType << ", contextType=" << contextType << ", key=" << key; FactoryLoaderList::const_iterator i = FactoryLoaders.begin(); while(i != FactoryLoaders.end()) { (*i)(ifaceType, contextType, key); ++i; } } void FactoryBase::registerLoader(LoaderFunc lf) { FactoryLoaders.push_back(lf); } FactoryBase& FactoryBase::instance(const std::string& ifaceType, const std::string& contextType, FactoryCreateFunc createFunc) { FactoryInstanceMap& instMap = FactoryInstanceMap::instance(); FactoryBase* ret = instMap.findFactory(ifaceType, contextType); if(!ret) { ret = createFunc(); instMap.addFactory(ifaceType, contextType, ret); } return *ret; } } // !namespace P |
From: Christian P. <cp...@us...> - 2005-04-28 12:24:55
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32756/include/pclasses Modified Files: StringList.h Log Message: - Fixed gcc 3.4 "base is a template" issue Index: StringList.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/StringList.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StringList.h 28 Apr 2005 10:15:02 -0000 1.1 +++ StringList.h 28 Apr 2005 12:24:45 -0000 1.2 @@ -46,12 +46,12 @@ StringType join(const StringType& separator) const { StringType ret; - typename string_list::const_iterator i = begin(); - while(i != end()) + typename string_list::const_iterator i = this->begin(); + while(i != this->end()) { ret += *i; ++i; - if(i != end()) + if(i != this->end()) ret += separator; } |
From: Christian P. <cp...@us...> - 2005-04-28 11:26:15
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31279/plugins/LogTarget Modified Files: Makefile.am Log Message: - Added File directory to Makefile.am, configure.in Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/LogTarget/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.am 10 Jan 2005 13:05:01 -0000 1.1 +++ Makefile.am 28 Apr 2005 11:26:05 -0000 1.2 @@ -1,2 +1,2 @@ -SUBDIRS = Console +SUBDIRS = Console File |
From: Christian P. <cp...@us...> - 2005-04-28 11:26:15
|
Update of /cvsroot/pclasses/pclasses2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31279 Modified Files: configure.in Log Message: - Added File directory to Makefile.am, configure.in Index: configure.in =================================================================== RCS file: /cvsroot/pclasses/pclasses2/configure.in,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- configure.in 26 Apr 2005 12:10:46 -0000 1.10 +++ configure.in 28 Apr 2005 11:26:05 -0000 1.11 @@ -264,6 +264,7 @@ plugins/Makefile \ plugins/LogTarget/Makefile \ plugins/LogTarget/Console/Makefile \ + plugins/LogTarget/File/Makefile \ test/Makefile) AC_PREFIX_CONFIG_H("PCLASSES", include/pclasses/config.h, |
From: Christian P. <cp...@us...> - 2005-04-28 11:24:58
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/File In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30732/plugins/LogTarget/File Added Files: Makefile.am FileLogTarget.cpp Log Message: - Added FileLogTarget plugin --- NEW FILE: FileLogTarget.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Plugin/Plugin.h" #include "pclasses/IO/IOStream.h" #include "pclasses/System/File.h" #include "pclasses/App/LogTarget.h" #include <iostream> using namespace P; using namespace P::IO; using namespace P::System; using namespace P::App; using namespace std; class FileLogTarget: public LogTarget { public: FileLogTarget() : _file(), _out(0) { } ~FileLogTarget() throw() { if(_out) delete _out; } void open(const URL& url) throw(IOError) { _file.open(url.path(), IODevice::Write, IODevice::OpenCreate, IODevice::AllowRead); _out = new IOStream(_file); } void close() throw(IOError) { _file.close(); delete _out; } void reload() throw(IOError) { } void output(const LogMessage& msg) throw(IOError) { (*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl; } bool valid() const throw() { return _file.valid(); } private: File _file; IOStream* _out; }; PLUGIN_REGISTER_TYPE(LogTarget, FileLogTarget); PLUGIN_REGISTER_ALIAS(LogTarget, File, FileLogTarget); --- NEW FILE: Makefile.am --- INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes) METASOURCES = AUTO pkglib_LTLIBRARIES = FileLogTarget.la FileLogTarget_la_SOURCES = FileLogTarget.cpp FileLogTarget_la_LDFLAGS = -module -avoid-version FileLogTarget_la_LIBADD = $(top_builddir)/src/libpclasses.la \ $(top_builddir)/src/App/libpclasses_app.la |
From: Christian P. <cp...@us...> - 2005-04-28 11:22:56
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/File In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29691/plugins/LogTarget/File Log Message: Directory /cvsroot/pclasses/pclasses2/plugins/LogTarget/File added to the repository |
From: Christian P. <cp...@us...> - 2005-04-28 11:22:23
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29197/plugins/LogTarget/Console Modified Files: ConsoleLogTarget.cpp Log Message: - Removed needless check for loglevel >= msglevel Index: ConsoleLogTarget.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console/ConsoleLogTarget.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ConsoleLogTarget.cpp 10 Jan 2005 13:05:01 -0000 1.1 +++ ConsoleLogTarget.cpp 28 Apr 2005 11:22:14 -0000 1.2 @@ -48,8 +48,7 @@ void output(const LogMessage& msg) throw(IOError) { - if(msg.level() >= logLevel()) - (*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl; + (*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl; } bool valid() const throw() |
From: Christian P. <cp...@us...> - 2005-04-28 11:16:46
|
Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25727/plugins/LogTarget/Console Modified Files: Makefile.am Log Message: - Renamed shared lib to match plugin class name Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/plugins/LogTarget/Console/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.am 16 Jan 2005 00:19:33 -0000 1.2 +++ Makefile.am 28 Apr 2005 11:16:36 -0000 1.3 @@ -1,10 +1,10 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes) METASOURCES = AUTO -pkglib_LTLIBRARIES = plog_console.la +pkglib_LTLIBRARIES = ConsoleLogTarget.la -plog_console_la_SOURCES = ConsoleLogTarget.cpp -plog_console_la_LDFLAGS = -module -avoid-version +ConsoleLogTarget_la_SOURCES = ConsoleLogTarget.cpp +ConsoleLogTarget_la_LDFLAGS = -module -avoid-version -plog_console_la_LIBADD = $(top_builddir)/src/libpclasses.la \ +ConsoleLogTarget_la_LIBADD = $(top_builddir)/src/libpclasses.la \ $(top_builddir)/src/App/libpclasses_app.la |
From: Christian P. <cp...@us...> - 2005-04-28 11:02:16
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14464/include/pclasses/System Removed Files: SerialDevice.h Log Message: - Removed bogus SerialDevice code --- SerialDevice.h DELETED --- |
From: Christian P. <cp...@us...> - 2005-04-28 11:02:16
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14464/src/System Removed Files: SerialDevice.linux.cpp Log Message: - Removed bogus SerialDevice code --- SerialDevice.linux.cpp DELETED --- |
From: Christian P. <cp...@us...> - 2005-04-28 10:52:49
|
Update of /cvsroot/pclasses/pclasses2/m4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13223/m4 Modified Files: etr_socket_nsl.m4 Log Message: - Modified configure check to support -Wall -Werror Index: etr_socket_nsl.m4 =================================================================== RCS file: /cvsroot/pclasses/pclasses2/m4/etr_socket_nsl.m4,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- etr_socket_nsl.m4 22 Dec 2004 17:54:33 -0000 1.1.1.1 +++ etr_socket_nsl.m4 28 Apr 2005 10:52:40 -0000 1.2 @@ -18,10 +18,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> + #include <unistd.h> ], [ struct in_addr add; int sd = socket(AF_INET, SOCK_STREAM, 0); + close(sd); inet_ntoa(add); ], ac_cv_socket_libs=-lc, ac_cv_socket_libs=no) @@ -34,10 +36,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> + #include <unistd.h> ], [ struct in_addr add; int sd = socket(AF_INET, SOCK_STREAM, 0); + close(sd); inet_ntoa(add); ], ac_cv_socket_libs=-lsocket, ac_cv_socket_libs=no) @@ -51,10 +55,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> + #include <unistd.h> ], [ struct in_addr add; int sd = socket(AF_INET, SOCK_STREAM, 0); + close(sd); inet_ntoa(add); ], ac_cv_socket_libs="-lsocket -lnsl", ac_cv_socket_libs=no) |
From: Christian P. <cp...@us...> - 2005-04-28 10:38:04
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4440/include/pclasses/System Modified Files: SharedLib.h Log Message: - Removed SharedLib::SharedLib(const std::string&,...) - Added some trace messages Index: SharedLib.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/SharedLib.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- SharedLib.h 24 Jan 2005 01:19:25 -0000 1.9 +++ SharedLib.h 28 Apr 2005 10:37:50 -0000 1.10 @@ -69,9 +69,6 @@ SharedLib(const Unicode::String& name, BindMode mode = BindLazy) throw(SystemError); - SharedLib(const std::string& name, BindMode mode = BindLazy) - throw(SystemError); - //! Destructor /*! The destructor unloads the shared library from memory. @@ -110,7 +107,8 @@ by this function and will be cleaned up during application shut-down (post-main()). */ -PSYSTEM_EXPORT SharedLib *openSharedLib( const std::string & path ) throw(RuntimeError); +PSYSTEM_EXPORT SharedLib *openSharedLib(const Unicode::String& path) + throw(SystemError); } // !namespace System |
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4440/src/System Modified Files: SharedLib.common.cpp SharedLib.dl.cpp SharedLib.dyld.cpp SharedLib.ltdl.cpp SharedLib.shl.cpp SharedLib.win32.cpp SharedLibCache.h Log Message: - Removed SharedLib::SharedLib(const std::string&,...) - Added some trace messages Index: SharedLib.dyld.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dyld.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- SharedLib.dyld.cpp 25 Dec 2004 16:02:51 -0000 1.6 +++ SharedLib.dyld.cpp 28 Apr 2005 10:37:50 -0000 1.7 @@ -48,9 +48,7 @@ SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { -// Unicode::String realName = name; -// realName.append(".dyld"); - + //TODO: use the SharedLibCache !! int flags = BindMode2Flags(mode) | NSLINKMODULE_OPTION_RETURN_ON_ERROR; NSObjectFileImage file; @@ -63,24 +61,6 @@ _handle = (unsigned long)out; } -SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) -{ -// std::ostringstream realName; -// realName << name; -// realName << ".dyld"; - - int flags = BindMode2Flags(mode) | NSLINKMODULE_OPTION_RETURN_ON_ERROR; - - NSObjectFileImage file; - NSObjectFileImageReturnCode ret; - ret = NSCreateObjectFileImageFromFile(name.c_str(), &file); - if(ret != NSObjectFileImageSuccess) - throw SystemError(0, "Could not load shared library", P_SOURCEINFO); - - NSModule out = NSLinkModule(file, name.c_str(), flags); - _handle = (unsigned long)out; -} - SharedLib::~SharedLib() throw() { NSUnLinkModule((NSModule)_handle, NSUNLINKMODULE_OPTION_NONE); Index: SharedLib.dl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.dl.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- SharedLib.dl.cpp 24 Jan 2005 01:23:32 -0000 1.10 +++ SharedLib.dl.cpp 28 Apr 2005 10:37:50 -0000 1.11 @@ -18,19 +18,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" #include <dlfcn.h> #include <errno.h> -#include <string> -#include <sstream> - namespace P { namespace System { +// cproch: why do we need this libdl_init() crap ??? void libdl_init() { dlopen( 0, RTLD_NOW | RTLD_GLOBAL ); @@ -41,6 +40,7 @@ { void operator()(unsigned long handle) { + P_TRACE(SharedLibCloser) << "closing handle=" << handle; dlclose((void*)handle); } }; @@ -66,85 +66,44 @@ SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { - Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); - CriticalSection::ScopedLock lck(cache.mutex); - - // see if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(name.utf8()); - if(i == cache.end()) - { - _handle = (unsigned long)dlopen(name.utf8().c_str(), BindMode2Flags(mode)); - if(!_handle) - throw SystemError(errno, dlerror(), P_SOURCEINFO); - - // add it to the handle cache - cache.add(name.utf8(), _handle); - } - else - { - _handle = i->second; - } -} + P_TRACE(SharedLib) << "SharedLib(" << name << "," << mode << ")"; -SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) -{ Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); + std::string utf8name = name.utf8(); + // see if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(name); + Cache::iterator i = cache.lookup(utf8name); if(i == cache.end()) { - _handle = (unsigned long)dlopen(name.c_str(), BindMode2Flags(mode)); + _handle = (unsigned long)dlopen(utf8name.c_str(), BindMode2Flags(mode)); if(!_handle) throw SystemError(errno, dlerror(), P_SOURCEINFO); + P_TRACE(SharedLib) << "library opened, handle=" << _handle; + // add it to the handle cache - cache.add(name, _handle); + cache.add(utf8name, _handle); } else { _handle = i->second; + P_TRACE(SharedLib) << "library opened (cached), handle=" << _handle; } } SharedLib::~SharedLib() throw() { -// dlclose((void*)_handle); -/***** -dlclose() is a BAD IDEA: - -Post-main(): - -#0 0x4001272b in strlen () from /lib/ld-linux.so.2 -#1 0x4000ce20 in _dl_signal_error () from /lib/ld-linux.so.2 -#2 0x40331947 in _dl_close () from /lib/tls/libc.so.6 -#3 0x40370d1a in dlclose_doit () from /lib/libdl.so.2 -#4 0x4000cd56 in _dl_catch_error () from /lib/ld-linux.so.2 -#5 0x40371085 in _dlerror_run () from /lib/libdl.so.2 -#6 0x40370cf0 in dlclose () from /lib/libdl.so.2 -#7 0x400398eb in ~SharedLib (this=0x8053c60) at SharedLib.dl.cpp:77 -#8 0x0804c9d8 in ~PluginCleaner (this=0x8051ec4) at Plugin.h:43 -#9 0x0804ea7c in ~PluginManager (this=0x8051ec0) at Plugin.h:106 -#10 0x0804d8cf in ~Phoenix (this=0x8051ec0) at Phoenix.h:196 -#11 0x0804bce5 in __tcf_1 () at Phoenix.h:161 -#12 0x40271820 in exit () from /lib/tls/libc.so.6 -#13 0x4025cb1a in __libc_start_main () from /lib/tls/libc.so.6 -#14 0x0804a1f1 in _start () at start.S:119 - -HOWEVER, not doing a dlclose() causes: -*** glibc detected *** double free or corruption: 0x08053c60 *** - -*****/ + // we don't leak the handle! + // the handle is owned by the SharedLibCache and will be + // freed upon application cleanup... } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { - if( ! symbol ) - { - throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); - } void* addr = dlsym((void*)_handle, symbol); + P_TRACE(SharedLib) << "operator[](" << symbol << ") = " << addr; if(!addr) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); Index: SharedLib.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.common.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SharedLib.common.cpp 28 Dec 2004 15:55:16 -0000 1.2 +++ SharedLib.common.cpp 28 Apr 2005 10:37:50 -0000 1.3 @@ -75,7 +75,7 @@ } - SharedLib * openSharedLib( const std::string & path ) throw(RuntimeError) + SharedLib * openSharedLib( const Unicode::String & path ) throw(SystemError) { //CERR << "openSharedLib("<<path<<")\n"; SharedLib * sh = new SharedLib( path ); Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- SharedLib.win32.cpp 24 Jan 2005 01:21:32 -0000 1.8 +++ SharedLib.win32.cpp 28 Apr 2005 10:37:50 -0000 1.9 @@ -18,14 +18,12 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" #include <windows.h> -#include <string> -#include <sstream> - namespace P { namespace System { @@ -34,6 +32,7 @@ { void operator()(unsigned long handle) { + P_TRACE(SharedLibCloser) << "closing handle=" << handle; FreeLibrary((HMODULE)handle); } }; @@ -42,6 +41,8 @@ SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { + P_TRACE(SharedLib) << "SharedLib(" << name << "," << mode << ")"; + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); @@ -54,48 +55,29 @@ if(!_handle) throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); - // add the handle to the cache - cache.add(name.utf8(), _handle); - } - else - { - _handle = i->second; - } -} - -SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) -{ - Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); - CriticalSection::ScopedLock lck(cache.mutex); - - // se if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(name); - if(i == cache.end()) - { - _handle = (unsigned long)LoadLibrary(name.c_str()); - if(!_handle) - throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); + P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add the handle to the cache - cache.add(name, _handle); + cache.add(name.utf8(), _handle); } else { _handle = i->second; + P_TRACE(SharedLib) << "library opened (cached), handle=" << _handle; } } SharedLib::~SharedLib() throw() { + // we don't leak the handle! + // the handle is owned by the SharedLibCache and will be + // freed upon application cleanup... } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { - if( ! symbol ) - { - throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); - } void* addr = GetProcAddress((HMODULE)_handle, symbol); + P_TRACE(SharedLib) << "operator[](" << symbol << ") = " << addr; if(!addr) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); Index: SharedLibCache.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLibCache.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SharedLibCache.h 26 Dec 2004 14:54:50 -0000 1.4 +++ SharedLibCache.h 28 Apr 2005 10:37:50 -0000 1.5 @@ -21,6 +21,7 @@ #ifndef P_System_SharedLibCache_h #define P_System_SharedLibCache_h +#include "pclasses/Trace.h" #include "pclasses/Phoenix.h" #include "pclasses/System/CriticalSection.h" @@ -48,6 +49,7 @@ typename map_t::iterator it = _handles.begin(); while(_handles.end() != it) { + P_TRACE(SharedLibCache) << "destroy " << it->first; fun(it->second); ++it; } @@ -58,7 +60,10 @@ { iterator i = _handles.find(name); if(i == _handles.end()) + { + P_TRACE(SharedLibCache) << "add(" << name << "," << handle << ")"; _handles[name] = handle; + } } iterator lookup(const std::string& name) const Index: SharedLib.ltdl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.ltdl.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- SharedLib.ltdl.cpp 26 Dec 2004 14:50:52 -0000 1.8 +++ SharedLib.ltdl.cpp 28 Apr 2005 10:37:50 -0000 1.9 @@ -18,22 +18,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/SharedLib.h" -#include "pclasses/Phoenix.h" #include "SharedLibCache.h" #include <ltdl.h> #include <errno.h> -#include <string> -#include <sstream> -#include <map> -#include <utility> // make_pair() - namespace P { namespace System { +// cproch: why do we need this ltdl_init() crap ??? void ltdl_init() { lt_dlinit(); @@ -41,92 +37,61 @@ } int ltdl_init_placeholder = (ltdl_init(),0); -struct ltdl_sharing_context {}; // marker class - -int BindMode2Flags(SharedLib::BindMode mode) -{ // ltdl doesn't use dlopen() flags - return 0; -} - -struct SharedLibCloser +struct SharedLibCloser { void operator()(lt_dlhandle handle) { + P_TRACE(SharedLibCloser) << "closing handle=" << (unsigned long)handle; lt_dlclose(handle); } }; typedef SharedLibCache<lt_dlhandle, SharedLibCloser> Cache; - SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) : _handle(0) { -// Please don't do this: -// Unicode::String realName = name; -// realName.append(".so"); - - //@fixme _handle = (unsigned long)dlopen(realName.utf8(), BindMode2Flags(mode)); - if(!_handle) - throw SystemError(errno, lt_dlerror(), P_SOURCEINFO); -} - - -#ifndef CERR -#define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " -#endif - + P_TRACE(SharedLib) << "SharedLib(" << name << "," << mode << ")"; -SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) - : _handle(0) -{ Cache& cache = shared_lib_cache<lt_dlhandle, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); + std::string utf8name = name.utf8(); + // see if we can get it from the handle cache ... - Cache::iterator i = cache.lookup(name); + Cache::iterator i = cache.lookup(utf8name); if(i == cache.end()) { - lt_dlhandle h = lt_dlopen(name.c_str() /** BindMode2Flags(mode) */ ); - if( h ) - { - _handle = (unsigned long)h; - - // add it to the handle cache - cache.add(name, h); - } - else - { - // CERR << "SharedLib("<<name<<") failed.\n"; + lt_dlhandle h = lt_dlopen(utf8name.c_str() /** BindMode2Flags(mode) */ ); + if(!h) throw SystemError(errno, lt_dlerror(), P_SOURCEINFO); - } + + _handle = (unsigned long)h; + P_TRACE(SharedLib) << "library opened, handle=" << _handle; + + // add it to the handle cache + cache.add(utf8name, h); } else { _handle = (unsigned long)i->second; + P_TRACE(SharedLib) << "library opened (cached), handle=" << _handle; } } SharedLib::~SharedLib() throw() { + // we don't leak the handle! + // the handle is owned by the SharedLibCache and will be + // freed upon application cleanup... } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { - if( ! symbol ) - { - throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); - } - - lt_dlhandle lth = (lt_dlhandle)_handle; - void* addr = lt_dlsym( lth, symbol); + void* addr = lt_dlsym((lt_dlhandle)_handle, symbol); + P_TRACE(SharedLib) << "operator[](" << symbol << ") = " << addr; if(!addr) - { - std::ostringstream os; - os << "Symbol '"<<symbol<<"' not found in shared library."; - throw RuntimeError(os.str(), P_SOURCEINFO); -// throw RuntimeError("Symbol not found in SharedLib.", P_SOURCEINFO); - } + throw RuntimeError("Symbol not found in SharedLib.", P_SOURCEINFO); return addr; } Index: SharedLib.shl.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.shl.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- SharedLib.shl.cpp 26 Dec 2004 14:38:09 -0000 1.7 +++ SharedLib.shl.cpp 28 Apr 2005 10:37:50 -0000 1.8 @@ -18,15 +18,13 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/SharedLib.h" #include "SharedLibCache.h" #include <dl.h> #include <errno.h> -#include <string> -#include <sstream> - namespace P { namespace System { @@ -35,6 +33,7 @@ { void operator()(unsigned long handle) { + P_TRACE(SharedLibCloser) << "closing handle=" << handle; shl_unload((shl_t*)handle); } }; @@ -60,57 +59,46 @@ SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { -// Unicode::String realName = name; -// realName.append(".sl"); - - _handle = (unsigned long)shl_load(name.utf8(), BindMode2Flags(mode)); - - //@fixme dlerror() on hpux ?? - if(!_handle) - throw SystemError(errno, dlerror(), P_SOURCEINFO); -} + P_TRACE(SharedLib) << "SharedLib(" << name << "," << mode << ")"; -SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) -{ -// std::ostringstream realName; -// realName << name; -// realName << ".sl"; Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); + std::string utf8name = name.utf8(); + // se if we have the handle cached ... - unsigned long handle = cache.lookup(name); - if(handle == Cache::InvalidHandle) + Cache::Iterator i = cache.lookup(utf8name); + if(i == cache.end()) { - _handle = (unsigned long)shl_load(name.str().c_str(), - BindMode2Flags(mode)); - - //@fixme dlerror() on hpux ?? + _handle = (unsigned long)shl_load(utf8name.c_str(), BindMode2Flags(mode)); if(!_handle) - throw SystemError(errno, dlerror(), P_SOURCEINFO); + throw SystemError(errno, "Error loading shared library", P_SOURCEINFO); + + P_TRACE(SharedLib) << "library opened, handle=" << _handle; // add the handle to the cache - cache.add(name, _handle); + cache.add(utf8name, _handle); } else { - _handle = handle; + _handle = i->second; + P_TRACE(SharedLib) << "library opened (cached), handle=" << _handle; } } SharedLib::~SharedLib() throw() { + // we don't leak the handle! + // the handle is owned by the SharedLibCache and will be + // freed upon application cleanup... } void* SharedLib::operator[](const char* symbol) throw(RuntimeError) { - if( ! symbol ) - { - throw RuntimeError( "Invalid symbol (null).", P_SOURCEINFO ); - } - void* address = 0; - if(shl_findsym((shl_t*)&_handle, symbol, TYPE_UNDEFINED, (void*)&address)) != 0) + int ret = shl_findsym((shl_t*)&_handle, symbol, TYPE_UNDEFINED, (void*)&address)); + P_TRACE(SharedLib) << "operator[](" << symbol << ") = " << addr; + if(ret != 0) throw RuntimeError("Symbol not found in shared library", P_SOURCEINFO); return address; |
From: Christian P. <cp...@us...> - 2005-04-28 10:35:48
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3559/include/pclasses/Plugin Modified Files: Plugin.h Log Message: - Use new tracing macro Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Plugin.h 31 Jan 2005 11:21:11 -0000 1.15 +++ Plugin.h 28 Apr 2005 10:35:40 -0000 1.16 @@ -4,16 +4,14 @@ #include <list> #include <string> #include <map> -#include "pclasses/pclasses-config.h" -#include "pclasses/Factory.h" -#include "pclasses/NonCopyable.h" -#include "pclasses/System/SharedLib.h" -#include "pclasses/System/PathFinder.h" -#include "pclasses/System/Directory.h" - -#ifndef CERR -#define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " -#endif +#include <pclasses/pclasses-config.h> +#include <pclasses/Factory.h> +#include <pclasses/NonCopyable.h> +#include <pclasses/Trace.h> +#include <pclasses/Unicode/String.h> +#include <pclasses/System/SharedLib.h> +#include <pclasses/System/PathFinder.h> +#include <pclasses/System/Directory.h> namespace P { namespace Plugin { @@ -32,11 +30,11 @@ */ template <class InterfaceT> class PluginManager : - public ::P::NamedTypeFactory< InterfaceT > + public NamedTypeFactory< InterfaceT > { public: typedef InterfaceT InterfaceType; - typedef ::P::NamedTypeFactory< InterfaceT > ParentType; + typedef NamedTypeFactory< InterfaceT > ParentType; typedef PluginManager<InterfaceType> ThisType; typedef typename ParentType::FactoryFuncType FactoryFuncType; typedef typename ParentType::ResultType ResultType; @@ -44,7 +42,7 @@ /** A type used to hold SharedLib handles. */ - typedef std::map<std::string,::P::System::SharedLib *> PluginsMap; + typedef std::map<Unicode::String, System::SharedLib *> PluginsMap; /** Creates a PluginManager with a default search path @@ -82,18 +80,18 @@ ResultType create( const std::string & _feature ) { std::string feature = this->expandAliases( _feature ); - //CERR << "create("<<_feature<<" ["<<feature<<"])\n"; + P_TRACE(PluginManager) << "create("<<_feature<<" ["<<feature<<"])"; InterfaceType * ret = ParentType::create( feature ); if( ret ) return ret; - std::string dll = this->findPlugin( feature ); + Unicode::String dll = this->findPlugin( feature ); if( dll.empty() ) { - //CERR << "No dll found for feature '"<<feature<<"'!\n"; + P_TRACE(PluginManager) << "No dll found for feature '"<<feature<<"'!"; return 0; } try { - //CERR << "Adding plugin '"<<dll<<"'!\n"; + P_TRACE(PluginManager) << "Adding plugin '"<<dll<<"'!"; this->addPlugin( dll ); ret = ParentType::create( feature ); } @@ -111,11 +109,10 @@ thrown. */ - void addPluginDir( const std::string & dir ) throw(::P::RuntimeError) + void addPluginDir( const Unicode::String & dir ) throw(RuntimeError) { - //CERR << "addPluginDir("<<dir<<").\n"; - using ::P::System::Directory; - const Directory d(dir); // throws on error + P_TRACE(PluginManager) << "addPluginDir("<<dir<<")"; + const System::Directory d(dir); // throws on error d.begin(); // avoid 'unused var' warning. // ^^^ need to find a more elegant solution for that. this->searchPath().addPath( dir ); @@ -136,8 +133,8 @@ multiple times with the same so_name will return the same SharedLib object. */ - ::P::System::SharedLib * - addPlugin( const std::string & so_name ) throw(::P::RuntimeError) + System::SharedLib * + addPlugin(const Unicode::String& so_name) throw(RuntimeError) { typedef typename PluginsMap::iterator IT; // look for cached entry: @@ -148,10 +145,10 @@ } // find a DLL file: - std::string fn = this->searchPath().find( so_name ); + Unicode::String fn = this->searchPath().find( so_name ); if( fn.empty() ) { - throw ::P::System::SystemError( 0, (std::string("No plugin found for '")+so_name+"'.").c_str(), P_SOURCEINFO ); + throw RuntimeError( std::string("No plugin found for '")+so_name.utf8()+"'.", P_SOURCEINFO ); } // check for entry cached under DLL's file name: @@ -162,7 +159,7 @@ } // open DLL and, if workie, cache it: - ::P::System::SharedLib * shl = ::P::System::openSharedLib( fn ); + System::SharedLib * shl = System::openSharedLib( fn ); m_smap.insert( std::make_pair( fn, shl ) ); return shl; } @@ -175,13 +172,13 @@ */ static ThisType & instance() { - return ::P::Hook::FactoryInstanceHook<ThisType>::instance(); + return Hook::FactoryInstanceHook<ThisType>::instance(); } /** This object's search path. Clients are free to modify it. */ - ::P::System::PathFinder & searchPath() + System::PathFinder & searchPath() { return this->m_path; } @@ -189,7 +186,7 @@ /** This object's search path. */ - const ::P::System::PathFinder & searchPath() const + const System::PathFinder & searchPath() const { return this->m_path; } @@ -235,7 +232,7 @@ Returns a path to a plugin file on success or an empty string on error. */ - std::string findPlugin( const std::string & name ) const + Unicode::String findPlugin( const Unicode::String & name ) const { return this->searchPath().find( name ); } @@ -256,7 +253,7 @@ this->m_path.addExtension(std::string(".")+System::SharedLib::extension()); } PluginsMap m_smap; - ::P::System::PathFinder m_path; + System::PathFinder m_path; // ^^^^ todo: consider making this static. }; @@ -274,7 +271,7 @@ pluginManager<T>().addPluginDir(pluginname). */ template <typename T> - void addPluginDir( const std::string & path ) throw(RuntimeError) + void addPluginDir( const Unicode::String & path ) throw(RuntimeError) { return pluginManager<T>().addPluginDir( path ); } @@ -284,8 +281,8 @@ pluginManager<T>().addPlugin(pluginname). */ template <typename T> - ::P::System::SharedLib * - addPlugin( const std::string & pluginname ) throw(RuntimeError) + System::SharedLib * + addPlugin( const Unicode::String & pluginname ) throw(RuntimeError) { return pluginManager<T>().addPlugin( pluginname ); } @@ -295,7 +292,7 @@ pluginManager<T>().findPlugin(name). */ template <typename T> - std::string findPlugin( const std::string & name ) + Unicode::String findPlugin( const Unicode::String & name ) { return pluginManager<T>().findPlugin( name ); } @@ -305,7 +302,7 @@ pluginManager<T>().searchPath(). */ template <typename T> - ::P::System::PathFinder & searchPath() + System::PathFinder & searchPath() { return pluginManager<T>().searchPath(); } @@ -350,10 +347,10 @@ lookups in the core without it knowing so. :) */ template < typename InterfaceT > - struct FactoryInstanceHook< ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > > + struct FactoryInstanceHook< Factory< InterfaceT, Sharing::FactoryContext, std::string > > { - typedef ::P::Factory< InterfaceT, ::P::Sharing::FactoryContext, std::string > FactoryType; - typedef ::P::Plugin::PluginManager< InterfaceT > RealFactoryType; + typedef Factory< InterfaceT, Sharing::FactoryContext, std::string > FactoryType; + typedef Plugin::PluginManager< InterfaceT > RealFactoryType; typedef FactoryInstanceHook<FactoryType> ThisType; /** @@ -372,7 +369,7 @@ */ static FactoryType & instance() { - typedef ::P::Phoenix<RealFactoryType, ::P::Sharing::FactoryContext, ThisType > PHX; + typedef Phoenix<RealFactoryType, Sharing::FactoryContext, ThisType > PHX; return PHX::instance(); } }; |
From: Christian P. <cp...@us...> - 2005-04-28 10:35:48
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3559/include/pclasses Modified Files: Factory.h Log Message: - Use new tracing macro Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- Factory.h 15 Jan 2005 23:40:22 -0000 1.20 +++ Factory.h 28 Apr 2005 10:35:39 -0000 1.21 @@ -12,6 +12,7 @@ // what happens in some cases when i don't use // phoenix. :/ #include <pclasses/SharingContext.h> +#include <pclasses/Trace.h> namespace P { @@ -276,12 +277,12 @@ */ key_type expandAliases( const key_type & _alias ) const { - //CERR << "expandAlias("<<_alias<<")\n"; + P_TRACE(Factory) << "expandAlias("<<_alias<<")"; typename AliasMap::const_iterator cit = this->aliases().find( _alias ), cet = this->aliases().end(); if( cet == cit ) { - //CERR << "No alias found for "<<_alias<<"\n"; + P_TRACE(Factory) << "No alias found for '"<<_alias<<"'"; return _alias; } key_type exp = (*cit).second; @@ -290,13 +291,13 @@ cit = this->aliases().find( exp ); if( cet == cit ) { - // CERR << "Returning '"<<_alias<<"' unaliased: " << exp<<"\n"; + P_TRACE(Factory) << "Returning '"<<_alias<<"' unaliased: '" << exp<<"'"; return exp; } exp = (*cit).second; if( exp == _alias ) { // circular aliasing - // CERR << "Warning: circular alias '"<<_alias<<"'."; + P_TRACE(Factory) << "Warning: circular alias '"<<_alias<<"'."; return exp; } } @@ -365,7 +366,7 @@ */ virtual void registerFactory( const key_type & key, FactoryFuncType fp ) { - //CERR << "registerFactory("<<key<<",facfunc)\n"; + P_TRACE(Factory) << "registerFactory("<<key<<",facfunc)"; factoryMap().insert( typename FactoryMap::value_type( key, fp ) ); } |
From: Christian P. <cp...@us...> - 2005-04-28 10:34:15
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2766/src/App Modified Files: LogChannel.cpp LogManager.cpp LogTarget.cpp Log Message: - Some small fixes for the logging framework Index: LogManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogManager.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LogManager.cpp 11 Jan 2005 14:58:30 -0000 1.2 +++ LogManager.cpp 28 Apr 2005 10:34:06 -0000 1.3 @@ -70,7 +70,7 @@ LogChannel* chan = channel(name); if(!chan) { - chan = new LogChannel(); + chan = new LogChannel(name); _channels[name] = chan; } Index: LogTarget.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogTarget.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- LogTarget.cpp 10 Jan 2005 02:38:57 -0000 1.1 +++ LogTarget.cpp 28 Apr 2005 10:34:06 -0000 1.2 @@ -25,6 +25,7 @@ namespace App { LogTarget::LogTarget() +: _logLevel(LogMessage::Debug) { } Index: LogChannel.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogChannel.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- LogChannel.cpp 16 Jan 2005 01:58:15 -0000 1.2 +++ LogChannel.cpp 28 Apr 2005 10:34:06 -0000 1.3 @@ -121,13 +121,14 @@ s->msg << (char)ch; } - - return ch; + + return traits_type::not_eof(ch); } -LogChannel::LogChannel() -: std::ostream(new LogStreamBuffer(*this)) +LogChannel::LogChannel(const std::string& name) +: std::ostream(new LogStreamBuffer(*this)), + _name(name), _logLevel(LogMessage::Warning) { } @@ -137,6 +138,11 @@ delete rdbuf(); } +const std::string& LogChannel::name() const +{ + return _name; +} + bool LogChannel::addTarget(const std::string& name, LogTarget* target) { TargetMap::const_iterator i = _targets.find(name); @@ -203,7 +209,7 @@ LogTarget* target = i->second; try { - if(target->valid()) + if(target->valid() && msg.level() >= target->logLevel()) target->output(msg); } // close target if output() did throw |