comparison checker/plugincandidates.h @ 8:25e00373f597

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