Code Search for Developers
 
 
  

tracker.h from osgDesigner at Krugle


Show tracker.h syntax highlighted

#ifndef __GEN_PROG_PLUGIN_DETAIL_TRACKER_H__
#define __GEN_PROG_PLUGIN_DETAIL_TRACKER_H__ 1


// ** standart include
#include <vector>
#include <string>

// ** logger include
#include <osg/Notify>

// ** filesystem include
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>


#include <gen_prog/plugin/detail/dynamic_library_identifier.h>


namespace gen_prog
{   
    namespace plugin
    {
        namespace detail
        {
            /* plugin_identifier is a tracker implementation
             *  
             
             */
            class plugin_identifier
            {
                public:
                    
                    typedef boost::filesystem::path                     path_type;
                    typedef std::vector<path_type>                      path_list;
                    
                    typedef std::string                                 dynamic_library_key_type;
                    typedef std::string                                 module_key_type;
                    
                    void getDirectoryList(path_list & pathList) const
                    {
                        pathList.push_back("/usr/local/lib/");
                        pathList.push_back("/usr/lib/");       
                    }
                    
                    bool isValidModuleKey(const module_key_type & moduleKey) const
                    { return (moduleKey.empty() == false); }
                    
                    module_key_type toModuleKey(const dynamic_library_key_type & dlKey) const
                    { return (dlKey); }
                    
                    dynamic_library_key_type toDynamicLibraryKey(const module_key_type & moduleKey) const
                    { return (moduleKey); }
            };
        
        
            /* path_tracker is a utility template to create a tracker.
             * 
             *      @\param MI : implementation of the tracker, must implemente the following function
             *                   void getDirectoryList(dynamic_library_path_list & pathList)
             *                   bool isValidKey(const dynamic_library_plugin_key_type & dlPluginKey)
             *                   key_type toDynamicLibraryPluginKey(dynamic_library_path & path)
             *                   key_type toDynamicLibraryKey(dynamic_library_key & path)
             * 
             *      @\param DLI : identifier of dynamic library, must provide the following function
             *                    key_type toKey(path_type & dlPath);
             *                    bool validPath(path_type & dlPath);
             */
            template < typename PI, typename DLI >
            class module_identifier_helper : public PI
            {
                public:
                    
                    typedef PI                                                          plugin_identifier_type;
                    typedef DLI                                                         dynamic_library_identifier_type;
                   
                   
                    typedef typename plugin_identifier_type::path_type                  path_type;
                    typedef typename plugin_identifier_type::path_list                  path_list;
                        
                    typedef typename plugin_identifier_type::dynamic_library_key_type   dynamic_library_key_type;
                    typedef typename std::vector< dynamic_library_key_type >            dynamic_library_key_list;
                    
                    typedef typename plugin_identifier_type::module_key_type            module_key_type;
                    typedef typename std::vector< module_key_type >                     module_key_list;
                   
                   
                   
                    std::size_t getAvailablePath(path_list & pathList) const
                    {
                        path_list directoryList;
                        getDirectoryList(directoryList);
        
                        // ** iterate in different pluginDirectories to find plugins
                        for (typename path_list::iterator path_it = directoryList.begin(); path_it != directoryList.end(); ++path_it)
                        {
                            try
                            {
                                if (boost::filesystem::exists(*path_it) == true && boost::filesystem::is_directory(*path_it) == true)
                                {
                                    osg::notify(osg::DEBUG_INFO) << "gen_prog plugin module_identifier : Scan directory : " << path_it->native_file_string() << std::endl;
                                    
                                    boost::filesystem::directory_iterator end_iter;
                                    for (boost::filesystem::directory_iterator dir_itr(*path_it); dir_itr != end_iter; ++dir_itr)
                                    {
                                        osg::notify(osg::DEBUG_INFO) << "gen_prog plugin module_identifier : File      " << dir_itr->native_file_string();
                                        if ((boost::filesystem::is_directory(*dir_itr) == false) && 
                                            _dynamicLibraryIdentifier.isValidPath(*dir_itr) && 
                                            isValidModuleKey(toModuleKey(_dynamicLibraryIdentifier.pathToKey(*dir_itr))) &&
                                            (std::find(pathList.begin(), pathList.end(), *dir_itr) == pathList.end()))
                                        {
                                            pathList.push_back(*dir_itr);
                                            osg::notify(osg::DEBUG_INFO) << " accepted" << std::endl;
                                        }
                                        else
                                            osg::notify(osg::DEBUG_INFO) << " rejected" << std::endl;
                                    }
                                }
                                else
                                {
                                    osg::notify(osg::DEBUG_INFO) << "gen_prog plugin module_identifier : No directory : " << path_it->native_file_string() << std::endl;
                                }
                            }
                            catch (const std::exception& ex)
                            {
                                osg::notify(osg::WARN) << "gen_prog plugin module_identifier : Catch exception : " << ex.what() << std::endl;
                            }
                        }
    
                        return (pathList.size());
                    }
                    
                    std::size_t getAvailableKey(module_key_list & moduleKeyList) const
                    {
                        path_list dlPathList;
                        getAvailablePath(dlPathList);
                        
                        for (typename path_list::const_iterator it = dlPathList.begin(); it != dlPathList.end(); ++it)
                            moduleKeyList.push_back(toModuleKey(_dynamicLibraryIdentifier.pathToKey(*it)));
                        
                        return (moduleKeyList.size());
                    }
                    
                    
                        
                protected:
                    dynamic_library_identifier_type _dynamicLibraryIdentifier;
            };
        }        
    }
}

#endif // ** __GEN_PROG_PLUGIN_DETAIL_TRACKER_H__ ** //




See more files for this project here

osgDesigner

osgDesigner is a graphical tool used to modify an OpenSceneGraph (OSG) scene using the osgIntrospection framework. OpenSceneGraph developpers will be able to extend osgDesigner at need using (editor | render | osgIntrospection wrapper) plugin system.

Project homepage: http://sourceforge.net/projects/osgdesigner
Programming language(s): C++,Shell Script
License: other

  dynamic_library_identifier.h
  singleton.h
  thread_locker.h
  tracker.h