-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from robotology/add-exists-tool
Add blockfactory-exists command line tool
- Loading branch information
Showing
3 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
set(BLOCKFACTORY_EXISTS_SRC | ||
src/BlockfactoryExists.cpp) | ||
|
||
add_executable(blockfactory-exists ${BLOCKFACTORY_EXISTS_SRC}) | ||
|
||
target_link_libraries(blockfactory-exists PRIVATE BlockFactory::Core) | ||
|
||
target_compile_warnings(blockfactory-exists | ||
WARNINGS_AS_ERRORS ${TREAT_WARNINGS_AS_ERRORS} | ||
DEPENDS ENABLE_WARNINGS) | ||
|
||
install( | ||
TARGETS blockfactory-exists | ||
EXPORT BlockFactoryToolsExport | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
install_basic_package_files(BlockFactoryTools | ||
VERSION ${PROJECT_VERSION} | ||
COMPATIBILITY AnyNewerVersion | ||
EXPORT BlockFactoryToolsExport | ||
FIRST_TARGET blockfactory-exists | ||
NAMESPACE BlockFactory:: | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) Istituto Italiano di Tecnologia (IIT) | ||
* All rights reserved. | ||
* | ||
* This software may be modified and distributed under the terms of the | ||
* GNU Lesser General Public License v2.1 or any later version. | ||
*/ | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "BlockFactory/Core/Block.h" | ||
#include "BlockFactory/Core/FactorySingleton.h" | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
std::string commandName = "blockfactory-exists"; | ||
if (argc != 3) | ||
{ | ||
std::cout << commandName << ": Utility to check for the existence " | ||
<< "of a given block inside a given plugin." << std::endl; | ||
std::cout << "USAGE : " << commandName << " pluginName blockName" << std::endl; | ||
std::cout << " : Note that the pluginName should be specified without prefix (lib) or suffix (.dll, .so, .dylib)." << std::endl; | ||
|
||
return EXIT_FAILURE; | ||
} | ||
|
||
// Get the class name and the library name from the parameter | ||
const std::string blockName(argv[2]); | ||
const std::string pluginName(argv[1]); | ||
|
||
// Get the block factory | ||
auto factory = blockfactory::core::ClassFactorySingleton::getInstance().getClassFactory( | ||
{pluginName, blockName}); | ||
|
||
if (!factory) { | ||
std::cerr << "ERROR: Failed to get factory object (blockName=" << blockName | ||
<< ",pluginName=" << pluginName << ")"; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (!factory->isValid()) { | ||
std::cerr << "ERROR: Factory error (" << static_cast<std::uint32_t>(factory->getStatus()) | ||
<< "): " << factory->getError().c_str(); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::cout << "SUCCESS: Block \"" << blockName | ||
<< "\" found and loaded from plugin \"" << pluginName << "\"." << std::endl; | ||
return EXIT_SUCCESS; | ||
} |