locate_images.h

Go to the documentation of this file.
00001 /**
00002  * @file locate_images.h
00003  * Location of binary images
00004  *
00005  * @remark Copyright 2002 OProfile authors
00006  * @remark Read the file COPYING
00007  *
00008  * @author Philippe Elie
00009  * @author John Levon
00010  */
00011 
00012 #ifndef LOCATE_IMAGES_H
00013 #define LOCATE_IMAGES_H
00014 
00015 #include <string>
00016 #include <map>
00017 #include <vector>
00018 
00019 #include "image_errors.h"
00020 
00021 /**
00022  * A class containing mappings from an image basename,
00023  * such as 'floppy.ko', to locations in the paths passed
00024  * in to populate().
00025  *
00026  * The name may exist multiple times; all locations are recorded
00027  * in this container.
00028  */
00029 class extra_images {
00030 public:
00031         extra_images();
00032 
00033         /// add all filenames found in the given paths prefixed by the
00034         /// archive path or the root path, recursively
00035         void populate(std::vector<std::string> const & paths,
00036                       std::string const & archive_path,
00037                       std::string const & root_path);
00038 
00039         /// base class for matcher functors object
00040         struct matcher {
00041                 std::string const & value;
00042         public:
00043                 explicit matcher(std::string const & v) : value(v) {}
00044                 virtual ~matcher() {}
00045                 /// default functor allowing trivial match
00046                 virtual bool operator()(std::string const & str) const {
00047                         return str == value;
00048                 }
00049         };
00050 
00051         /**
00052          * return a vector of all directories that match the functor
00053          */
00054         std::vector<std::string> const find(matcher const & match) const;
00055 
00056         /// return a vector of all directories that match the given name
00057         std::vector<std::string> const find(std::string const & name) const;
00058 
00059         /**
00060          * @param image_name binary image name
00061          * @param error errors are flagged in this passed enum ref
00062          * @param fixup if true return the fixed image name else always return
00063          *  image_name and update error
00064          *
00065          * Locate a (number of) matching absolute paths to the given image
00066          * name. If we fail to find the file we fill in error and return the
00067          * original string.
00068          */
00069         std::string const find_image_path(std::string const & image_name,
00070                                 image_error & error, bool fixup) const;
00071 
00072         /// return the archive path used to populate the images name map
00073         std::string get_archive_path() const { return archive_path; }
00074 
00075         /// Given an image name returned by find_image_path() return
00076         /// a filename with the archive_path or root_path stripped.
00077         std::string strip_path_prefix(std::string const & image) const;
00078 
00079         /// return the uid for this extra_images, first valid uid is 1
00080         int get_uid() const { return uid; }
00081 
00082 private:
00083         void populate(std::vector<std::string> const & paths,
00084                       std::string const & prefix_path);
00085 
00086         std::string const locate_image(std::string const & image_name,
00087                                 image_error & error, bool fixup) const;
00088 
00089         typedef std::multimap<std::string, std::string> images_t;
00090         typedef images_t::value_type value_type;
00091         typedef images_t::const_iterator const_iterator;
00092 
00093         /// map from image basename to owning directory
00094         images_t images;
00095         /// the archive path passed to populate the images name map.
00096         std::string archive_path;
00097         /// A prefix added to locate binaries if they can't be found
00098         /// through the archive path
00099         std::string root_path;
00100 
00101         /// unique identifier, first valid uid is 1
00102         int uid;
00103         /// unique uid generator
00104         static int suid;
00105 };
00106 
00107 #endif /* LOCATE_IMAGES_H */

Generated on Thu Jul 17 19:52:46 2008 for oprofile by  doxygen 1.4.6