Chris@2: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@2: Chris@2: #ifndef PLUGIN_CANDIDATES_H Chris@2: #define PLUGIN_CANDIDATES_H Chris@2: Chris@2: #include Chris@2: #include Chris@2: #include Chris@2: Chris@2: /** Chris@2: * Class to identify and list candidate shared-library files possibly Chris@2: * containing plugins. Uses a separate process (the "helper", whose Chris@2: * executable name must be provided at construction) to test-load each Chris@2: * library in order to winnow out any that fail to load or crash on Chris@2: * load. Chris@2: * Chris@2: * Requires C++11 and the Qt5 QtCore library. Chris@2: */ Chris@2: class PluginCandidates Chris@2: { Chris@2: typedef std::vector stringlist; Chris@2: Chris@2: public: Chris@2: /** Construct a PluginCandidates scanner that uses the given Chris@2: * executable as its load check helper. Chris@2: */ Chris@2: PluginCandidates(std::string helperExecutableName); Chris@2: Chris@2: /** Scan the libraries found in the given plugin path (i.e. list Chris@2: * of plugin directories), checking that the given descriptor Chris@2: * function can be looked up in each. Store the results Chris@2: * internally, associated with the given (arbitrary) tag, for Chris@2: * later querying using getCandidateLibrariesFor() and Chris@2: * getFailedLibrariesFor(). Chris@2: * Chris@2: * Not thread-safe. Chris@2: */ Chris@2: void scan(std::string tag, Chris@2: stringlist pluginPath, Chris@2: std::string descriptorFunctionName); Chris@2: Chris@2: /** Return list of plugin library paths that were checked Chris@2: * successfully during the scan for the given tag. Chris@2: */ Chris@2: stringlist getCandidateLibrariesFor(std::string tag); Chris@2: Chris@2: struct FailureRec { Chris@2: std::string library; Chris@2: std::string message; Chris@2: }; Chris@2: Chris@2: /** Return list of failure reports arising from the prior scan for Chris@2: * the given tag. Chris@2: */ Chris@2: std::vector getFailedLibrariesFor(std::string tag); Chris@2: Chris@2: private: Chris@2: std::string m_helper; Chris@2: std::map m_candidates; Chris@2: std::map > m_failures; Chris@2: Chris@2: stringlist getLibrariesInPath(stringlist path); Chris@2: stringlist runHelper(stringlist libraries, std::string descriptor); Chris@2: void recordResult(std::string tag, stringlist results); Chris@2: }; Chris@2: Chris@2: #endif