2 * @file locate_images.h
3 * Location of binary images
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
8 * @author Philippe Elie
12 #ifndef LOCATE_IMAGES_H
13 #define LOCATE_IMAGES_H
19 #include "image_errors.h"
22 * A class containing mappings from an image basename,
23 * such as 'floppy.ko', to locations in the paths passed
26 * The name may exist multiple times; all locations are recorded
33 /// add all filenames found in the given paths prefixed by the
34 /// archive path or the root path, recursively
35 void populate(std::vector<std::string> const & paths,
36 std::string const & archive_path,
37 std::string const & root_path);
39 /// base class for matcher functors object
41 std::string const & value;
43 explicit matcher(std::string const & v) : value(v) {}
45 /// default functor allowing trivial match
46 virtual bool operator()(std::string const & str) const {
52 * return a vector of all directories that match the functor
54 std::vector<std::string> const find(matcher const & match) const;
56 /// return a vector of all directories that match the given name
57 std::vector<std::string> const find(std::string const & name) const;
60 * @param image_name binary image name
61 * @param error errors are flagged in this passed enum ref
62 * @param fixup if true return the fixed image name else always return
63 * image_name and update error
65 * Locate a (number of) matching absolute paths to the given image
66 * name. If we fail to find the file we fill in error and return the
69 std::string const find_image_path(std::string const & image_name,
70 image_error & error, bool fixup) const;
72 /// return the archive path used to populate the images name map
73 std::string get_archive_path() const { return archive_path; }
75 /// Given an image name returned by find_image_path() return
76 /// a filename with the archive_path or root_path stripped.
77 std::string strip_path_prefix(std::string const & image) const;
79 /// return the uid for this extra_images, first valid uid is 1
80 int get_uid() const { return uid; }
83 void populate(std::vector<std::string> const & paths,
84 std::string const & prefix_path);
86 std::string const locate_image(std::string const & image_name,
87 image_error & error, bool fixup) const;
89 typedef std::multimap<std::string, std::string> images_t;
90 typedef images_t::value_type value_type;
91 typedef images_t::const_iterator const_iterator;
93 /// map from image basename to owning directory
95 /// the archive path passed to populate the images name map.
96 std::string archive_path;
97 /// A prefix added to locate binaries if they can't be found
98 /// through the archive path
99 std::string root_path;
101 /// unique identifier, first valid uid is 1
103 /// unique uid generator
107 #endif /* LOCATE_IMAGES_H */