annotate plugincandidates.h @ 3:3bae396cf8e0

Start to organise as a Qt project, with a main (command-line) executable
author Chris Cannam
date Wed, 13 Apr 2016 09:12:04 +0100
parents 2288c1d05c28
children 6f891a9c6434
rev   line source
Chris@2 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@2 2
Chris@2 3 #ifndef PLUGIN_CANDIDATES_H
Chris@2 4 #define PLUGIN_CANDIDATES_H
Chris@2 5
Chris@2 6 #include <string>
Chris@2 7 #include <vector>
Chris@2 8 #include <map>
Chris@2 9
Chris@2 10 /**
Chris@2 11 * Class to identify and list candidate shared-library files possibly
Chris@2 12 * containing plugins. Uses a separate process (the "helper", whose
Chris@2 13 * executable name must be provided at construction) to test-load each
Chris@2 14 * library in order to winnow out any that fail to load or crash on
Chris@2 15 * load.
Chris@2 16 *
Chris@2 17 * Requires C++11 and the Qt5 QtCore library.
Chris@2 18 */
Chris@2 19 class PluginCandidates
Chris@2 20 {
Chris@2 21 typedef std::vector<std::string> stringlist;
Chris@2 22
Chris@2 23 public:
Chris@2 24 /** Construct a PluginCandidates scanner that uses the given
Chris@2 25 * executable as its load check helper.
Chris@2 26 */
Chris@2 27 PluginCandidates(std::string helperExecutableName);
Chris@2 28
Chris@2 29 /** Scan the libraries found in the given plugin path (i.e. list
Chris@2 30 * of plugin directories), checking that the given descriptor
Chris@2 31 * function can be looked up in each. Store the results
Chris@2 32 * internally, associated with the given (arbitrary) tag, for
Chris@2 33 * later querying using getCandidateLibrariesFor() and
Chris@2 34 * getFailedLibrariesFor().
Chris@2 35 *
Chris@2 36 * Not thread-safe.
Chris@2 37 */
Chris@2 38 void scan(std::string tag,
Chris@2 39 stringlist pluginPath,
Chris@2 40 std::string descriptorFunctionName);
Chris@2 41
Chris@2 42 /** Return list of plugin library paths that were checked
Chris@2 43 * successfully during the scan for the given tag.
Chris@2 44 */
Chris@2 45 stringlist getCandidateLibrariesFor(std::string tag);
Chris@2 46
Chris@2 47 struct FailureRec {
Chris@2 48 std::string library;
Chris@2 49 std::string message;
Chris@2 50 };
Chris@2 51
Chris@2 52 /** Return list of failure reports arising from the prior scan for
Chris@2 53 * the given tag.
Chris@2 54 */
Chris@2 55 std::vector<FailureRec> getFailedLibrariesFor(std::string tag);
Chris@2 56
Chris@2 57 private:
Chris@2 58 std::string m_helper;
Chris@2 59 std::map<std::string, stringlist> m_candidates;
Chris@2 60 std::map<std::string, std::vector<FailureRec> > m_failures;
Chris@2 61
Chris@2 62 stringlist getLibrariesInPath(stringlist path);
Chris@2 63 stringlist runHelper(stringlist libraries, std::string descriptor);
Chris@2 64 void recordResult(std::string tag, stringlist results);
Chris@2 65 };
Chris@2 66
Chris@2 67 #endif