Esempio n. 1
0
	size_t PluginEngine::loadPlugins( const std::string & pluginFldr ) {
		//	1. get all files in pluginFldr that conform to a platform-dependent
		//		naming convention.
		//	2. For each one, try to open it and determine if it has the interface
		//		expected for this plugin engine
		//	3. If it does, register it with the appropriate manager.
		//			(NOt entirely sure what this means yet...ultimately, the manager
		//			has to be able to provide information about the entity in the
		//			plug-in and provide the ability to insantiate it.  "information"
		//			may also include the ability to parse itself from the xml.

		StringList files;
	#ifdef _MSC_VER
		std::string extension( "*.dll" );
	#else
		std::string extension( "*.so" );
	#endif
		if ( !os::listdir( pluginFldr, files, extension ) ) {
			return 0;
		}

		StringListCItr itr = files.begin();
		for ( ; itr != files.end(); ++itr ) {
			std::string fullPath;
			if ( ! os::path::absPath( os::path::join( 2, pluginFldr.c_str(), (*itr).c_str() ), fullPath ) ) {
				logger << Logger::ERR_MSG << "Unable to get absolute path for " << (*itr);
				continue;
			}
			Plugin * plugin;
			try {
				plugin = new Plugin( fullPath );
			} catch ( std::exception & ) {
				logger << Logger::ERR_MSG << "Failed loading " << fullPath << " as a plug-in";
				continue;
			}
			logger << Logger::INFO_MSG << "Loaded: " << plugin->getName() << "\n";;
			logger << "\t" << plugin->getDescription();
			plugin->registerPlugin( this );
			_plugins.insert( PluginMap::value_type( (*itr), plugin ) );
		}

		return files.size();
	}
Esempio n. 2
0
const VampPluginDescriptor *
PluginAdapterBase::Impl::getDescriptor()
{
#ifdef DEBUG_PLUGIN_ADAPTER
    std::cerr << "PluginAdapterBase::Impl[" << this << "]::getDescriptor" << std::endl;
#endif

    if (m_populated) return &m_descriptor;

    Plugin *plugin = m_base->createPlugin(48000);

    if (plugin->getVampApiVersion() != VAMP_API_VERSION) {
        std::cerr << "Vamp::PluginAdapterBase::Impl::getDescriptor: ERROR: "
                  << "Plugin object API version "
                  << plugin->getVampApiVersion()
                  << " does not match actual API version "
                  << VAMP_API_VERSION << std::endl;
        delete plugin;
        return 0;
    }

    m_parameters = plugin->getParameterDescriptors();
    m_programs = plugin->getPrograms();

    m_descriptor.vampApiVersion = plugin->getVampApiVersion();
    m_descriptor.identifier = strdup(plugin->getIdentifier().c_str());
    m_descriptor.name = strdup(plugin->getName().c_str());
    m_descriptor.description = strdup(plugin->getDescription().c_str());
    m_descriptor.maker = strdup(plugin->getMaker().c_str());
    m_descriptor.pluginVersion = plugin->getPluginVersion();
    m_descriptor.copyright = strdup(plugin->getCopyright().c_str());
    
    m_descriptor.parameterCount = m_parameters.size();
    m_descriptor.parameters = (const VampParameterDescriptor **)
        malloc(m_parameters.size() * sizeof(VampParameterDescriptor));

    unsigned int i;
    
    for (i = 0; i < m_parameters.size(); ++i) {
        VampParameterDescriptor *desc = (VampParameterDescriptor *)
            malloc(sizeof(VampParameterDescriptor));
        desc->identifier = strdup(m_parameters[i].identifier.c_str());
        desc->name = strdup(m_parameters[i].name.c_str());
        desc->description = strdup(m_parameters[i].description.c_str());
        desc->unit = strdup(m_parameters[i].unit.c_str());
        desc->minValue = m_parameters[i].minValue;
        desc->maxValue = m_parameters[i].maxValue;
        desc->defaultValue = m_parameters[i].defaultValue;
        desc->isQuantized = m_parameters[i].isQuantized;
        desc->quantizeStep = m_parameters[i].quantizeStep;
        desc->valueNames = 0;
        if (desc->isQuantized && !m_parameters[i].valueNames.empty()) {
            desc->valueNames = (const char **)
                malloc((m_parameters[i].valueNames.size()+1) * sizeof(char *));
            for (unsigned int j = 0; j < m_parameters[i].valueNames.size(); ++j) {
                desc->valueNames[j] = strdup(m_parameters[i].valueNames[j].c_str());
            }
            desc->valueNames[m_parameters[i].valueNames.size()] = 0;
        }
        m_descriptor.parameters[i] = desc;
    }
    
    m_descriptor.programCount = m_programs.size();
    m_descriptor.programs = (const char **)
        malloc(m_programs.size() * sizeof(const char *));
    
    for (i = 0; i < m_programs.size(); ++i) {
        m_descriptor.programs[i] = strdup(m_programs[i].c_str());
    }
    
    if (plugin->getInputDomain() == Plugin::FrequencyDomain) {
        m_descriptor.inputDomain = vampFrequencyDomain;
    } else {
        m_descriptor.inputDomain = vampTimeDomain;
    }

    m_descriptor.instantiate = vampInstantiate;
    m_descriptor.cleanup = vampCleanup;
    m_descriptor.initialise = vampInitialise;
    m_descriptor.reset = vampReset;
    m_descriptor.getParameter = vampGetParameter;
    m_descriptor.setParameter = vampSetParameter;
    m_descriptor.getCurrentProgram = vampGetCurrentProgram;
    m_descriptor.selectProgram = vampSelectProgram;
    m_descriptor.getPreferredStepSize = vampGetPreferredStepSize;
    m_descriptor.getPreferredBlockSize = vampGetPreferredBlockSize;
    m_descriptor.getMinChannelCount = vampGetMinChannelCount;
    m_descriptor.getMaxChannelCount = vampGetMaxChannelCount;
    m_descriptor.getOutputCount = vampGetOutputCount;
    m_descriptor.getOutputDescriptor = vampGetOutputDescriptor;
    m_descriptor.releaseOutputDescriptor = vampReleaseOutputDescriptor;
    m_descriptor.process = vampProcess;
    m_descriptor.getRemainingFeatures = vampGetRemainingFeatures;
    m_descriptor.releaseFeatureSet = vampReleaseFeatureSet;
    
    if (!m_adapterMap) {
        m_adapterMap = new AdapterMap;
    }
    (*m_adapterMap)[&m_descriptor] = this;

    delete plugin;

    m_populated = true;
    return &m_descriptor;
}
LRESULT PluginListView::notify(WPARAM /*wParam*/, LPARAM lParam)
{
	switch (((LPNMHDR)lParam)->code)
    {

		case LVN_GETDISPINFO:
		{
			if (_listMode == LISTMODE_LIST)
			{
				NMLVDISPINFO* plvdi = (NMLVDISPINFO*)lParam;    

				Plugin* plugin = reinterpret_cast<Plugin*>(plvdi->item.lParam);

				switch (plvdi->item.iSubItem)
				{
					case 0:
					{
						
						
						plvdi->item.pszText = const_cast<TCHAR*>(plugin->getName().c_str());
						break;
					}
					case 1:
					{
						plvdi->item.pszText = const_cast<TCHAR*>(plugin->getCategory().c_str());
						break;
					}

					default:
						if (plvdi->item.iSubItem == _nVersionColumns + 2)
						{
							plvdi->item.pszText = const_cast<TCHAR*>(plugin->getStability().c_str());
						} 
						else
						{
							switch(_columns[plvdi->item.iSubItem - 2])
							{
								case VERSION_INSTALLED:
									plvdi->item.pszText = plugin->getInstalledVersion().getDisplayString();
									plvdi->item.cchTextMax = (int)_tcslen(plvdi->item.pszText);
									break;

								case VERSION_AVAILABLE:
									plvdi->item.pszText = plugin->getVersion().getDisplayString();
									plvdi->item.cchTextMax = (int)_tcslen(plvdi->item.pszText);
									break;
							}
						}
						break;
				 }
				 return TRUE;
			}
			break;
		}

		case LVN_COLUMNCLICK:
			{
				NMLISTVIEW *colInfo = reinterpret_cast<NMLISTVIEW*>(lParam);
				int (CALLBACK *compareFunc)(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) = NULL;
				LVSORTCOLUMN sortColumn = LVSORTCOLUMN_NAME;

				if (colInfo->iSubItem < 2 || colInfo->iSubItem == _nVersionColumns + 2)
				{
					compareFunc = PluginListView::stringComparer;
					
					if (colInfo->iSubItem == 1)
					{
						sortColumn = LVSORTCOLUMN_CATEGORY;
					}
					else if (colInfo->iSubItem == _nVersionColumns + 2)
					{
						sortColumn = LVSORTCOLUMN_STABILITY;
					}
				}
				else
				{
					compareFunc = PluginListView::versionComparer;
					
					switch(_columns[colInfo->iSubItem - 2])
					{
						case VERSION_AVAILABLE:
							sortColumn = LVSORTCOLUMN_VERSIONAVAILABLE;
							break;

						case VERSION_INSTALLED:
							sortColumn = LVSORTCOLUMN_VERSIONINSTALLED;
							break;
							
						// Just in case there's another one introduced at some point (beta version or something)
						default:
							sortColumn = LVSORTCOLUMN_VERSIONAVAILABLE;
							break;
					}
				}

				ListView_SortItems(_hListView, compareFunc, static_cast<LPARAM>(sortColumn));
			}
			break;

		case NM_CLICK:
			if (_hDescription && lParam)
			{

				LPNMITEMACTIVATE itemActivate = reinterpret_cast<LPNMITEMACTIVATE>(lParam);
				if (itemActivate->iItem >= 0)
				{
					ListView_SetItemState(_hListView, getCurrentSelectedIndex(), 0, LVIS_SELECTED);
					ListView_SetItemState(_hListView, itemActivate->iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
				}
			
			}
			break;
		
		case LVN_ITEMCHANGED:
		{
			LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(lParam);
			if (pnmv->uNewState & LVIS_SELECTED)
			{
				Plugin* plugin = reinterpret_cast<Plugin*>(pnmv->lParam);
				if (plugin && _hDescription)
				{
					if (_displayUpdateDesc)
						::SendMessage(_hDescription, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(plugin->getUpdateDescription().c_str()));
					else
						::SendMessage(_hDescription, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(plugin->getDescription().c_str()));
				}
			}
		}
	}

	return FALSE;
}
Esempio n. 4
0
void
printPluginCategoryList()
{
    PluginLoader *loader = PluginLoader::getInstance();

    vector<PluginLoader::PluginKey> plugins = loader->listPlugins();

    set<string> printedcats;

    for (size_t i = 0; i < plugins.size(); ++i) {

        PluginLoader::PluginKey key = plugins[i];
        
        PluginLoader::PluginCategoryHierarchy category =
            loader->getPluginCategory(key);

        Plugin *plugin = loader->loadPlugin(key, 48000);
        if (!plugin) continue;

        string catstr = "";

        if (category.empty()) catstr = '|';
        else {
            for (size_t j = 0; j < category.size(); ++j) {
                catstr += category[j];
                catstr += '|';
                if (printedcats.find(catstr) == printedcats.end()) {
                    std::cout << catstr << std::endl;
                    printedcats.insert(catstr);
                }
            }
        }

        std::cout << catstr << key << ":::" << plugin->getName() << ":::" << plugin->getMaker() << ":::" << plugin->getDescription() << std::endl;
    }
}
Esempio n. 5
0
void
enumeratePlugins(Verbosity verbosity)
{
    PluginLoader *loader = PluginLoader::getInstance();

    if (verbosity == PluginInformation) {
        cout << "\nVamp plugin libraries found in search path:" << endl;
    }

    vector<PluginLoader::PluginKey> plugins = loader->listPlugins();
    typedef multimap<string, PluginLoader::PluginKey>
        LibraryMap;
    LibraryMap libraryMap;

    for (size_t i = 0; i < plugins.size(); ++i) {
        string path = loader->getLibraryPathForPlugin(plugins[i]);
        libraryMap.insert(LibraryMap::value_type(path, plugins[i]));
    }

    string prevPath = "";
    int index = 0;

    for (LibraryMap::iterator i = libraryMap.begin();
         i != libraryMap.end(); ++i) {
        
        string path = i->first;
        PluginLoader::PluginKey key = i->second;

        if (path != prevPath) {
            prevPath = path;
            index = 0;
            if (verbosity == PluginInformation) {
                cout << "\n  " << path << ":" << endl;
            } else if (verbosity == PluginInformationDetailed) {
                string::size_type ki = i->second.find(':');
                string text = "Library \"" + i->second.substr(0, ki) + "\"";
                cout << "\n" << header(text, 1);
            }
        }

        Plugin *plugin = loader->loadPlugin(key, 48000);
        if (plugin) {

            char c = char('A' + index);
            if (c > 'Z') c = char('a' + (index - 26));

            PluginLoader::PluginCategoryHierarchy category =
                loader->getPluginCategory(key);
            string catstr;
            if (!category.empty()) {
                for (size_t ci = 0; ci < category.size(); ++ci) {
                    if (ci > 0) catstr += " > ";
                        catstr += category[ci];
                }
            }

            if (verbosity == PluginInformation) {

                cout << "    [" << c << "] [v"
                     << plugin->getVampApiVersion() << "] "
                     << plugin->getName() << ", \""
                     << plugin->getIdentifier() << "\"" << " ["
                     << plugin->getMaker() << "]" << endl;
                
                if (catstr != "") {
                    cout << "       > " << catstr << endl;
                }

                if (plugin->getDescription() != "") {
                    cout << "        - " << plugin->getDescription() << endl;
                }

            } else if (verbosity == PluginInformationDetailed) {

                cout << header(plugin->getName(), 2);
                cout << " - Identifier:         "
                     << key << endl;
                cout << " - Plugin Version:     " 
                     << plugin->getPluginVersion() << endl;
                cout << " - Vamp API Version:   "
                     << plugin->getVampApiVersion() << endl;
                cout << " - Maker:              \""
                     << plugin->getMaker() << "\"" << endl;
                cout << " - Copyright:          \""
                     << plugin->getCopyright() << "\"" << endl;
                cout << " - Description:        \""
                     << plugin->getDescription() << "\"" << endl;
                cout << " - Input Domain:       "
                     << (plugin->getInputDomain() == Vamp::Plugin::TimeDomain ?
                         "Time Domain" : "Frequency Domain") << endl;
                cout << " - Default Step Size:  " 
                     << plugin->getPreferredStepSize() << endl;
                cout << " - Default Block Size: " 
                     << plugin->getPreferredBlockSize() << endl;
                cout << " - Minimum Channels:   " 
                     << plugin->getMinChannelCount() << endl;
                cout << " - Maximum Channels:   " 
                     << plugin->getMaxChannelCount() << endl;

            } else if (verbosity == PluginIds) {
                cout << "vamp:" << key << endl;
            }
            
            Plugin::OutputList outputs =
                plugin->getOutputDescriptors();

            if (verbosity == PluginInformationDetailed) {

                Plugin::ParameterList params = plugin->getParameterDescriptors();
                for (size_t j = 0; j < params.size(); ++j) {
                    Plugin::ParameterDescriptor &pd(params[j]);
                    cout << "\nParameter " << j+1 << ": \"" << pd.name << "\"" << endl;
                    cout << " - Identifier:         " << pd.identifier << endl;
                    cout << " - Description:        \"" << pd.description << "\"" << endl;
                    if (pd.unit != "") {
                        cout << " - Unit:               " << pd.unit << endl;
                    }
                    cout << " - Range:              ";
                    cout << pd.minValue << " -> " << pd.maxValue << endl;
                    cout << " - Default:            ";
                    cout << pd.defaultValue << endl;
                    if (pd.isQuantized) {
                        cout << " - Quantize Step:      "
                             << pd.quantizeStep << endl;
                    }
                    if (!pd.valueNames.empty()) {
                        cout << " - Value Names:        ";
                        for (size_t k = 0; k < pd.valueNames.size(); ++k) {
                            if (k > 0) cout << ", ";
                            cout << "\"" << pd.valueNames[k] << "\"";
                        }
                        cout << endl;
                    }
                }

                if (outputs.empty()) {
                    cout << "\n** Note: This plugin reports no outputs!" << endl;
                }
                for (size_t j = 0; j < outputs.size(); ++j) {
                    Plugin::OutputDescriptor &od(outputs[j]);
                    cout << "\nOutput " << j+1 << ": \"" << od.name << "\"" << endl;
                    cout << " - Identifier:         " << od.identifier << endl;
                    cout << " - Description:        \"" << od.description << "\"" << endl;
                    if (od.unit != "") {
                        cout << " - Unit:               " << od.unit << endl;
                    }
                    if (od.hasFixedBinCount) {
                        cout << " - Default Bin Count:  " << od.binCount << endl;
                    }
                    if (!od.binNames.empty()) {
                        bool have = false;
                        for (size_t k = 0; k < od.binNames.size(); ++k) {
                            if (od.binNames[k] != "") {
                                have = true; break;
                            }
                        }
                        if (have) {
                            cout << " - Bin Names:          ";
                            for (size_t k = 0; k < od.binNames.size(); ++k) {
                                if (k > 0) cout << ", ";
                                cout << "\"" << od.binNames[k] << "\"";
                            }
                            cout << endl;
                        }
                    }
                    if (od.hasKnownExtents) {
                        cout << " - Default Extents:    ";
                        cout << od.minValue << " -> " << od.maxValue << endl;
                    }
                    if (od.isQuantized) {
                        cout << " - Quantize Step:      "
                             << od.quantizeStep << endl;
                    }
                    cout << " - Sample Type:        "
                         << (od.sampleType ==
                             Plugin::OutputDescriptor::OneSamplePerStep ?
                             "One Sample Per Step" :
                             od.sampleType ==
                             Plugin::OutputDescriptor::FixedSampleRate ?
                             "Fixed Sample Rate" :
                             "Variable Sample Rate") << endl;
                    if (od.sampleType !=
                        Plugin::OutputDescriptor::OneSamplePerStep) {
                        cout << " - Default Rate:       "
                             << od.sampleRate << endl;
                    }
                    cout << " - Has Duration:       "
                         << (od.hasDuration ? "Yes" : "No") << endl;
                }
            }

            if (outputs.size() > 1 || verbosity == PluginOutputIds) {
                for (size_t j = 0; j < outputs.size(); ++j) {
                    if (verbosity == PluginInformation) {
                        cout << "         (" << j << ") "
                             << outputs[j].name << ", \""
                             << outputs[j].identifier << "\"" << endl;
                        if (outputs[j].description != "") {
                            cout << "             - " 
                                 << outputs[j].description << endl;
                        }
                    } else if (verbosity == PluginOutputIds) {
                        cout << "vamp:" << key << ":" << outputs[j].identifier << endl;
                    }
                }
            }

            ++index;

            delete plugin;
        }
    }

    if (verbosity == PluginInformation ||
        verbosity == PluginInformationDetailed) {
        cout << endl;
    }
}
Esempio n. 6
0
int mtsutil(int argc, char **argv) {
	char optchar, *end_ptr = NULL;

	try {
		/* Default settings */
		int nprocs = getProcessorCount();
		std::string nodeName = getHostName(),
					networkHosts = "", destFile="";
		bool quietMode = false;
		ELogLevel logLevel = EInfo;
		FileResolver *fileResolver = Thread::getThread()->getFileResolver();
		bool testCaseMode = false;

		if (argc < 2) {
			help();
			return 0;
		}

		optind = 1;
		/* Parse command-line arguments */
		while ((optchar = getopt(argc, argv, "+a:c:s:n:p:qhvt")) != -1) {
			switch (optchar) {
				case 'a': {
						std::vector<std::string> paths = tokenize(optarg, ";");
						for (unsigned int i=0; i<paths.size(); ++i) 
							fileResolver->addPath(paths[i]);
					}
					break;
				case 'c':
					networkHosts = networkHosts + std::string(";") + std::string(optarg);
					break;
				case 't':
					testCaseMode = true;
					break;
				case 's': {
						std::ifstream is(optarg);
						if (is.fail())
							SLog(EError, "Could not open host file!");
						std::string host;
						while (is >> host) {
							if (host.length() < 1 || host.c_str()[0] == '#')
								continue;
							networkHosts = networkHosts + std::string(";") + host;
						}
					}
					break;
				case 'n':
					nodeName = optarg;
					break;
				case 'v':
					logLevel = EDebug;
					break;
				case 'p':
					nprocs = strtol(optarg, &end_ptr, 10);
					if (*end_ptr != '\0')
						SLog(EError, "Could not parse the processor count!");
					break;
				case 'q':
					quietMode = true;
					break;
				case 'h':
				default:
					help();
					return 0;
			}
		}

		/* Configure the logging subsystem */
		ref<Logger> log = Thread::getThread()->getLogger();
		log->setLogLevel(logLevel);
	
		/* Initialize OpenMP */
		Thread::initializeOpenMP(nprocs);

		/* Disable the default appenders */
		for (size_t i=0; i<log->getAppenderCount(); ++i) {
			Appender *appender = log->getAppender(i);
			if (appender->getClass()->derivesFrom(MTS_CLASS(StreamAppender)))
				log->removeAppender(appender);
		}

		log->addAppender(new StreamAppender(formatString("mitsuba.%s.log", nodeName.c_str())));
		if (!quietMode)
			log->addAppender(new StreamAppender(&std::cout));

		SLog(EInfo, "Mitsuba version %s, Copyright (c) " MTS_YEAR " Wenzel Jakob",
				Version(MTS_VERSION).toStringComplete().c_str());

		/* Configure the scheduling subsystem */
		Scheduler *scheduler = Scheduler::getInstance();
		for (int i=0; i<nprocs; ++i)
			scheduler->registerWorker(new LocalWorker(formatString("wrk%i", i)));
		std::vector<std::string> hosts = tokenize(networkHosts, ";");

		/* Establish network connections to nested servers */ 
		for (size_t i=0; i<hosts.size(); ++i) {
			const std::string &hostName = hosts[i];
			ref<Stream> stream;

			if (hostName.find("@") == std::string::npos) {
				int port = MTS_DEFAULT_PORT;
				std::vector<std::string> tokens = tokenize(hostName, ":");
				if (tokens.size() == 0 || tokens.size() > 2) {
					SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
				} else if (tokens.size() == 2) {
					port = strtol(tokens[1].c_str(), &end_ptr, 10);
					if (*end_ptr != '\0')
						SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
				}
				stream = new SocketStream(tokens[0], port);
			} else {
				std::string path = "~/mitsuba"; // default path if not specified
				std::vector<std::string> tokens = tokenize(hostName, "@:");
				if (tokens.size() < 2 || tokens.size() > 3) {
					SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
				} else if (tokens.size() == 3) {
					path = tokens[2];
				}
				std::vector<std::string> cmdLine;
				cmdLine.push_back(formatString("bash -c 'cd %s; . setpath.sh; mtssrv -ls'", path.c_str()));
				stream = new SSHStream(tokens[0], tokens[1], cmdLine);
			}
			try {
				scheduler->registerWorker(new RemoteWorker(formatString("net%i", i), stream));
			} catch (std::runtime_error &e) {
				if (hostName.find("@") != std::string::npos) {
#if defined(WIN32)
					SLog(EWarn, "Please ensure that passwordless authentication "
						"using plink.exe and pageant.exe is enabled (see the documentation for more information)");
#else
					SLog(EWarn, "Please ensure that passwordless authentication "
						"is enabled (e.g. using ssh-agent - see the documentation for more information)");
#endif
				}
				throw e;
			}
		}

		scheduler->start();

		if (testCaseMode) {
			std::vector<fs::path> dirPaths = fileResolver->resolveAll("plugins");
			std::set<std::string> seen;
			int executed = 0, succeeded = 0;
		
			for (size_t i=0; i<dirPaths.size(); ++i) {
				fs::path dirPath = fs::complete(dirPaths[i]);

				if (!fs::exists(dirPath) || !fs::is_directory(dirPath))
					break;

				fs::directory_iterator end, it(dirPath);

				for (; it != end; ++it) {
					if (!fs::is_regular_file(it->status()))
						continue;
					std::string extension(boost::to_lower_copy(it->path().extension()));
#if defined(WIN32)
					if (extension != ".dll")
						continue;
#elif defined(__OSX__)
					if (extension != ".dylib")
						continue;
#elif defined(__LINUX__)
					if (extension != ".so")
						continue;
#else
#error Unknown operating system!
#endif
					std::string shortName = it->path().stem();
					if (seen.find(shortName) != seen.end() || !boost::starts_with(shortName, "test_"))
						continue;
					seen.insert(shortName);
					Plugin plugin(shortName, it->path());
					if (!plugin.isUtility())
						continue;

					ref<Utility> utility = plugin.createUtility();

					TestCase *testCase = static_cast<TestCase *>(utility.get());
					if (!utility->getClass()->derivesFrom(MTS_CLASS(TestCase)))
						SLog(EError, "This is not a test case!");

					if (testCase->run(argc-optind, argv+optind) != 0)
						SLog(EError, "Testcase unexpectedly returned with a nonzero value.");

					executed += testCase->getExecuted();
					succeeded += testCase->getSucceeded();
				}
			}

			SLog(EInfo, "Ran %i tests, %i succeeded, %i failed.", executed, succeeded, executed-succeeded);
		} else {
			if (argc <= optind) {
				std::cerr << "A utility name must be supplied!" << endl;
				return -1;
			}
			fs::path pluginName(argv[optind]);

			/* Build the full plugin file name */
#if defined(WIN32)
			pluginName.replace_extension(".dll");
#elif defined(__OSX__)
			pluginName.replace_extension(".dylib");
#elif defined(__LINUX__)
			pluginName.replace_extension(".so");
#else
#error Unknown operating system!
#endif
			fs::path fullName = fileResolver->resolve(fs::path("plugins") / pluginName);

			if (!fs::exists(fullName)) {
				/* Plugin not found! */
				SLog(EError, "Utility \"%s\" not found (run \"mtsutil\" without arguments to "
					"see a list of available utilities)", fullName.file_string().c_str());
			}

			SLog(EInfo, "Loading utility \"%s\" ..", argv[optind]);
			Plugin *plugin = new Plugin(argv[optind], fullName);
			if (!plugin->isUtility())
				SLog(EError, "This plugin does not implement the 'Utility' interface!");
			Statistics::getInstance()->logPlugin(argv[optind], plugin->getDescription());
		
			ref<Utility> utility = plugin->createUtility();

			int retval = utility->run(argc-optind, argv+optind);
			scheduler->pause();
			utility = NULL;
			delete plugin;
			return retval;
		}
	} catch (const std::exception &e) {
		std::cerr << "Caught a critical exeption: " << e.what() << std::endl;
	} catch (...) {
		std::cerr << "Caught a critical exeption of unknown type!" << endl;
	}

	return 0;
}