comparison src/knownplugincandidates.cpp @ 35:4154894d638c plugin-path-config

Trim KnownPlugins class down to static info and environment variable lookup; introduce KnownPluginCandidates to provide its former API
author Chris Cannam
date Wed, 06 Jun 2018 15:54:26 +0100
parents
children 40c6936c2fc9
comparison
equal deleted inserted replaced
34:6905d8b146f6 35:4154894d638c
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 /*
3 Copyright (c) 2016-2018 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 #include "knownplugincandidates.h"
31
32 #include <sstream>
33
34 using namespace std;
35
36 /** This returns true if the helper has a name ending in "-32". By our
37 * convention, this means that it is a 32-bit helper found on a
38 * 64-bit system, so (depending on the OS) we may need to look in
39 * 32-bit-specific paths. Note that is32bit() is *not* usually true
40 * on 32-bit systems; it's used specifically to indicate a
41 * "non-native" 32-bit helper.
42 */
43 static
44 bool
45 is32bit(string helperExecutableName)
46 {
47 return helperExecutableName.find("-32") != string::npos;
48 }
49
50 KnownPluginCandidates::KnownPluginCandidates(string helperExecutableName,
51 PluginCandidates::LogCallback *cb) :
52 m_known(is32bit(helperExecutableName) ?
53 KnownPlugins::FormatNonNative32Bit :
54 KnownPlugins::FormatNative),
55 m_candidates(helperExecutableName),
56 m_helperExecutableName(helperExecutableName)
57 {
58 m_candidates.setLogCallback(cb);
59
60 auto knownTypes = m_known.getKnownPluginTypes();
61
62 for (auto type: knownTypes) {
63 m_candidates.scan(m_known.getTagFor(type),
64 m_known.getPathFor(type),
65 m_known.getDescriptorFor(type));
66 }
67 }
68
69 string
70 KnownPluginCandidates::getFailureReport() const
71 {
72 vector<PluginCandidates::FailureRec> failures;
73
74 for (auto t: getKnownPluginTypes()) {
75 auto ff = m_candidates.getFailedLibrariesFor(m_known.getTagFor(t));
76 failures.insert(failures.end(), ff.begin(), ff.end());
77 }
78
79 if (failures.empty()) return "";
80
81 int n = int(failures.size());
82 int i = 0;
83
84 ostringstream os;
85
86 os << "<ul>";
87 for (auto f: failures) {
88 os << "<li>" + f.library;
89 if (f.message != "") {
90 os << "<br><i>" + f.message + "</i>";
91 } else {
92 os << "<br><i>unknown error</i>";
93 }
94 os << "</li>";
95
96 if (n > 10) {
97 if (++i == 5) {
98 os << "<li>(... and " << (n - i) << " further failures)</li>";
99 break;
100 }
101 }
102 }
103 os << "</ul>";
104
105 return os.str();
106 }