annotate get-version.cpp @ 66:85768d48e6ce

Add get-version utility
author Chris Cannam
date Wed, 12 Feb 2020 14:41:09 +0000
parents
children 38cd115c91d4
rev   line source
Chris@66 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@66 2 /*
Chris@66 3 Copyright (c) 2020 Queen Mary, University of London
Chris@66 4
Chris@66 5 Permission is hereby granted, free of charge, to any person
Chris@66 6 obtaining a copy of this software and associated documentation
Chris@66 7 files (the "Software"), to deal in the Software without
Chris@66 8 restriction, including without limitation the rights to use, copy,
Chris@66 9 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@66 10 of the Software, and to permit persons to whom the Software is
Chris@66 11 furnished to do so, subject to the following conditions:
Chris@66 12
Chris@66 13 The above copyright notice and this permission notice shall be
Chris@66 14 included in all copies or substantial portions of the Software.
Chris@66 15
Chris@66 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@66 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@66 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@66 19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@66 20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@66 21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@66 22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@66 23
Chris@66 24 Except as contained in this notice, the names of the Centre for
Chris@66 25 Digital Music and Queen Mary, University of London shall not be
Chris@66 26 used in advertising or otherwise to promote the sale, use or other
Chris@66 27 dealings in this Software without prior written authorization.
Chris@66 28 */
Chris@66 29
Chris@66 30 #include <vamp-hostsdk/PluginHostAdapter.h>
Chris@66 31
Chris@66 32 // Undocumented internal API
Chris@66 33 #include <vamp-hostsdk/../src/vamp-hostsdk/Files.h>
Chris@66 34
Chris@66 35 #include <iostream>
Chris@66 36 #include <string>
Chris@66 37
Chris@66 38 using namespace std;
Chris@66 39
Chris@66 40 void usage(const char *me)
Chris@66 41 {
Chris@66 42 cerr << endl;
Chris@66 43 cerr << "Usage: " << me << " <soname>" << endl;
Chris@66 44 cerr << endl;
Chris@66 45 cerr << "Loads the Vamp plugin library found in <soname> and lists\n"
Chris@66 46 << "the plugin versions found therein. Plugins are listed one per\n"
Chris@66 47 << "line, with the plugin id and version number separated by a colon."
Chris@66 48 << endl;
Chris@66 49 cerr << endl;
Chris@66 50 cerr << "Note that <soname> must be the path to a plugin library, not\n"
Chris@66 51 << "merely the name of the library. That is, no search path is used.\n"
Chris@66 52 << "The file path should be UTF-8 encoded (on all platforms)."
Chris@66 53 << endl;
Chris@66 54 cerr << endl;
Chris@66 55 cerr << "The return code is 0 if the plugin library was successfully\n"
Chris@66 56 << "loaded, otherwise 1. An error message may be printed to stderr\n"
Chris@66 57 << "in the latter case." << endl;
Chris@66 58 cerr << endl;
Chris@66 59 exit(2);
Chris@66 60 }
Chris@66 61
Chris@66 62 int main(int argc, char **argv)
Chris@66 63 {
Chris@66 64 char *scooter = argv[0];
Chris@66 65 char *name = 0;
Chris@66 66 while (scooter && *scooter) {
Chris@66 67 if (*scooter == '/' || *scooter == '\\') name = ++scooter;
Chris@66 68 else ++scooter;
Chris@66 69 }
Chris@66 70 if (!name || !*name) name = argv[0];
Chris@66 71
Chris@66 72 if (argc != 2) usage(name);
Chris@66 73 if (string(argv[1]) == string("-?")) usage(name);
Chris@66 74
Chris@66 75 string libraryPath(argv[1]);
Chris@66 76
Chris@66 77 void *handle = Files::loadLibrary(libraryPath);
Chris@66 78 if (!handle) {
Chris@66 79 cerr << "Unable to load library " << libraryPath << endl;
Chris@66 80 return 1;
Chris@66 81 }
Chris@66 82
Chris@66 83 VampGetPluginDescriptorFunction fn =
Chris@66 84 (VampGetPluginDescriptorFunction)Files::lookupInLibrary
Chris@66 85 (handle, "vampGetPluginDescriptor");
Chris@66 86
Chris@66 87 if (!fn) {
Chris@66 88 cerr << "No vampGetPluginDescriptor function found in library \""
Chris@66 89 << libraryPath << "\"" << endl;
Chris@66 90 Files::unloadLibrary(handle);
Chris@66 91 return 1;
Chris@66 92 }
Chris@66 93
Chris@66 94 int index = 0;
Chris@66 95 const VampPluginDescriptor *descriptor = 0;
Chris@66 96
Chris@66 97 while ((descriptor = fn(VAMP_API_VERSION, index))) {
Chris@66 98 cout << descriptor->identifier << ":"
Chris@66 99 << descriptor->pluginVersion << endl;
Chris@66 100 ++index;
Chris@66 101 }
Chris@66 102
Chris@66 103 Files::unloadLibrary(handle);
Chris@66 104
Chris@66 105 return 0;
Chris@66 106 }