|
| 1 | +/* |
| 2 | + * Copyright (C) Istituto Italiano di Tecnologia (IIT) |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This software may be modified and distributed under the terms of the |
| 6 | + * GNU Lesser General Public License v2.1 or any later version. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <cstdlib> |
| 10 | +#include <iostream> |
| 11 | + |
| 12 | +#include "BlockFactory/Core/Block.h" |
| 13 | +#include "BlockFactory/Core/FactorySingleton.h" |
| 14 | + |
| 15 | +int main(int argc, char* argv[]) |
| 16 | +{ |
| 17 | + std::string commandName = "blockfactory-exists"; |
| 18 | + if (argc != 3) |
| 19 | + { |
| 20 | + std::cout << commandName << ": Utility to check for the existence " |
| 21 | + << "of a given block inside a given plugin." << std::endl; |
| 22 | + std::cout << "USAGE : " << commandName << " pluginName blockName" << std::endl; |
| 23 | + std::cout << " : Note that the pluginName should be specified without prefix (lib) or suffix (.dll, .so, .dylib)." << std::endl; |
| 24 | + |
| 25 | + return EXIT_FAILURE; |
| 26 | + } |
| 27 | + |
| 28 | + // Get the class name and the library name from the parameter |
| 29 | + const std::string blockName(argv[2]); |
| 30 | + const std::string pluginName(argv[1]); |
| 31 | + |
| 32 | + // Get the block factory |
| 33 | + auto factory = blockfactory::core::ClassFactorySingleton::getInstance().getClassFactory( |
| 34 | + {pluginName, blockName}); |
| 35 | + |
| 36 | + if (!factory) { |
| 37 | + std::cerr << "ERROR: Failed to get factory object (blockName=" << blockName |
| 38 | + << ",pluginName=" << pluginName << ")"; |
| 39 | + return EXIT_FAILURE; |
| 40 | + } |
| 41 | + |
| 42 | + if (!factory->isValid()) { |
| 43 | + std::cerr << "ERROR: Factory error (" << static_cast<std::uint32_t>(factory->getStatus()) |
| 44 | + << "): " << factory->getError().c_str(); |
| 45 | + return EXIT_FAILURE; |
| 46 | + } |
| 47 | + |
| 48 | + std::cout << "SUCCESS: Block \"" << blockName |
| 49 | + << "\" found and loaded from plugin \"" << pluginName << "\"." << std::endl; |
| 50 | + return EXIT_SUCCESS; |
| 51 | +} |
0 commit comments