annotate checker/plugincandidates.h @ 64:e839338d3869 tip

Further Windows fix
author Chris Cannam
date Wed, 15 Apr 2020 16:30:40 +0100
parents 81ce3ba92b16
children
rev   line source
Chris@2 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@5 2 /*
Chris@40 3 Copyright (c) 2016-2018 Queen Mary, University of London
Chris@5 4
Chris@5 5 Permission is hereby granted, free of charge, to any person
Chris@5 6 obtaining a copy of this software and associated documentation
Chris@5 7 files (the "Software"), to deal in the Software without
Chris@5 8 restriction, including without limitation the rights to use, copy,
Chris@5 9 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@5 10 of the Software, and to permit persons to whom the Software is
Chris@5 11 furnished to do so, subject to the following conditions:
Chris@5 12
Chris@5 13 The above copyright notice and this permission notice shall be
Chris@5 14 included in all copies or substantial portions of the Software.
Chris@5 15
Chris@5 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@5 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@5 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@5 19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@5 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@5 21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@5 22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@5 23
Chris@5 24 Except as contained in this notice, the names of the Centre for
Chris@5 25 Digital Music and Queen Mary, University of London shall not be
Chris@5 26 used in advertising or otherwise to promote the sale, use or other
Chris@5 27 dealings in this Software without prior written authorization.
Chris@5 28 */
Chris@2 29
Chris@2 30 #ifndef PLUGIN_CANDIDATES_H
Chris@2 31 #define PLUGIN_CANDIDATES_H
Chris@2 32
Chris@2 33 #include <string>
Chris@2 34 #include <vector>
Chris@2 35 #include <map>
Chris@2 36
Chris@40 37 #include "checkcode.h"
Chris@40 38
Chris@55 39 class QProcess;
Chris@55 40
Chris@2 41 /**
Chris@2 42 * Class to identify and list candidate shared-library files possibly
Chris@2 43 * containing plugins. Uses a separate process (the "helper", whose
Chris@2 44 * executable name must be provided at construction) to test-load each
Chris@2 45 * library in order to winnow out any that fail to load or crash on
Chris@2 46 * load.
Chris@2 47 *
Chris@2 48 * Requires C++11 and the Qt5 QtCore library.
Chris@2 49 */
Chris@2 50 class PluginCandidates
Chris@2 51 {
Chris@2 52 typedef std::vector<std::string> stringlist;
Chris@6 53
Chris@2 54 public:
Chris@2 55 /** Construct a PluginCandidates scanner that uses the given
Chris@2 56 * executable as its load check helper.
Chris@2 57 */
Chris@2 58 PluginCandidates(std::string helperExecutableName);
Chris@2 59
Chris@6 60 struct LogCallback {
Chris@8 61 virtual ~LogCallback() { }
Chris@24 62
Chris@24 63 /// implementation is responsible for adding \n and flushing output
Chris@6 64 virtual void log(std::string) = 0;
Chris@6 65 };
Chris@6 66
Chris@6 67 /** Set a callback to be called for log output.
Chris@6 68 */
Chris@6 69 void setLogCallback(LogCallback *cb);
Chris@6 70
Chris@2 71 /** Scan the libraries found in the given plugin path (i.e. list
Chris@2 72 * of plugin directories), checking that the given descriptor
Chris@4 73 * symbol can be looked up in each. Store the results
Chris@2 74 * internally, associated with the given (arbitrary) tag, for
Chris@2 75 * later querying using getCandidateLibrariesFor() and
Chris@2 76 * getFailedLibrariesFor().
Chris@2 77 *
Chris@2 78 * Not thread-safe.
Chris@2 79 */
Chris@2 80 void scan(std::string tag,
Chris@19 81 stringlist pluginPath,
Chris@19 82 std::string descriptorSymbolName);
Chris@2 83
Chris@2 84 /** Return list of plugin library paths that were checked
Chris@2 85 * successfully during the scan for the given tag.
Chris@2 86 */
Chris@4 87 stringlist getCandidateLibrariesFor(std::string tag) const;
Chris@40 88
Chris@40 89 struct FailureRec {
Chris@2 90
Chris@40 91 /// Path of failed library file
Chris@19 92 std::string library;
Chris@40 93
Chris@40 94 /// General class of failure
Chris@40 95 PluginCheckCode code;
Chris@40 96
Chris@40 97 /// Optional additional system-level message, already translated
Chris@19 98 std::string message;
Chris@2 99 };
Chris@2 100
Chris@2 101 /** Return list of failure reports arising from the prior scan for
Chris@2 102 * the given tag.
Chris@2 103 */
Chris@4 104 std::vector<FailureRec> getFailedLibrariesFor(std::string tag) const;
Chris@2 105
Chris@2 106 private:
Chris@2 107 std::string m_helper;
Chris@2 108 std::map<std::string, stringlist> m_candidates;
Chris@2 109 std::map<std::string, std::vector<FailureRec> > m_failures;
Chris@6 110 LogCallback *m_logCallback;
Chris@2 111
Chris@2 112 stringlist getLibrariesInPath(stringlist path);
Chris@40 113 std::string getHelperCompatibilityVersion();
Chris@2 114 stringlist runHelper(stringlist libraries, std::string descriptor);
Chris@2 115 void recordResult(std::string tag, stringlist results);
Chris@55 116 void logErrors(QProcess *);
Chris@6 117 void log(std::string);
Chris@2 118 };
Chris@2 119
Chris@2 120 #endif