comparison plugin/FeatureExtractionPluginFactory.cpp @ 1223:c2207877689d piper

Avoid instantiating all plugins (in piper client) on startup, using plugin static data instead. Problem of where to get the units field from is still pending.
author Chris Cannam
date Thu, 20 Oct 2016 14:06:58 +0100
parents 77320e522253
children ab050519c4ba
comparison
equal deleted inserted replaced
1222:771a17925576 1223:c2207877689d
29 29
30 #include <iostream> 30 #include <iostream>
31 31
32 #include "base/Profiler.h" 32 #include "base/Profiler.h"
33 33
34 #include "vamp-client/ProcessQtTransport.h"
35 #include "vamp-client/CapnpRRClient.h"
36
34 using namespace std; 37 using namespace std;
35 38
36 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1 39 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1
37 40
38 static FeatureExtractionPluginFactory *_nativeInstance = 0; 41 static FeatureExtractionPluginFactory *_nativeInstance = 0;
58 PluginIdentifier::parseIdentifier(identifier, type, soName, label); 61 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
59 return instance(type); 62 return instance(type);
60 } 63 }
61 64
62 FeatureExtractionPluginFactory::FeatureExtractionPluginFactory() : 65 FeatureExtractionPluginFactory::FeatureExtractionPluginFactory() :
63 m_serverName("piper-cpp/bin/piper-vamp-server"), 66 m_serverName("piper-cpp/bin/piper-vamp-server") //!!!
64 m_transport(m_serverName),
65 m_client(&m_transport)
66 { 67 {
67 } 68 }
68 69
69 vector<QString> 70 vector<QString>
70 FeatureExtractionPluginFactory::getAllPluginIdentifiers() 71 FeatureExtractionPluginFactory::getAllPluginIdentifiers()
126 } else { 127 } else {
127 return ap; 128 return ap;
128 } 129 }
129 } 130 }
130 131
132 piper_vamp::PluginStaticData
133 FeatureExtractionPluginFactory::getPluginStaticData(QString identifier)
134 {
135 QString type, soname, label;
136 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
137 std::string pluginKey = (soname + ":" + label).toStdString();
138
139 for (const auto &d: m_pluginData) {
140 if (d.pluginKey == pluginKey) {
141 return d;
142 }
143 }
144 return {};
145 }
146
131 QString 147 QString
132 FeatureExtractionPluginFactory::getPluginCategory(QString identifier) 148 FeatureExtractionPluginFactory::getPluginCategory(QString identifier)
133 { 149 {
134 return m_taxonomy[identifier]; 150 if (m_taxonomy.find(identifier) != m_taxonomy.end()) {
151 return m_taxonomy[identifier];
152 } else {
153 return {};
154 }
135 } 155 }
136 156
137 void 157 void
138 FeatureExtractionPluginFactory::populate() 158 FeatureExtractionPluginFactory::populate()
139 { 159 {
140 piper_vamp::ListResponse lr = m_client.listPluginData(); 160 piper_vamp::client::ProcessQtTransport transport(m_serverName);
161 piper_vamp::client::CapnpRRClient client(&transport);
162 piper_vamp::ListResponse lr = client.listPluginData();
141 m_pluginData = lr.available; 163 m_pluginData = lr.available;
142 164
143 for (const auto &pd: m_pluginData) { 165 for (const auto &pd: m_pluginData) {
144 166
145 QString identifier = 167 QString identifier =
147 169
148 QStringList catlist; 170 QStringList catlist;
149 for (const auto &cs: pd.category) { 171 for (const auto &cs: pd.category) {
150 catlist.push_back(QString::fromStdString(cs)); 172 catlist.push_back(QString::fromStdString(cs));
151 } 173 }
174
152 m_taxonomy[identifier] = catlist.join(" > "); 175 m_taxonomy[identifier] = catlist.join(" > ");
153 } 176 }
154 } 177 }
155 178