Skip to content

Commit e36a10b

Browse files
committed
Add blockfactory-exists command line tool
Add a simple command line tool to check if a given block exists in a given plugin. Added Tools CMake component to contain command line tools.
1 parent b4d0810 commit e36a10b

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

sources/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ if(USES_MATLAB)
99
add_subdirectory(Simulink)
1010
endif()
1111

12+
add_subdirectory(Tools)
13+
1214
# ========================
1315
# MAIN BLOCKFACTORY TARGET
1416
# ========================
1517

1618
# Dummy target
1719
add_library(BlockFactory INTERFACE)
1820

19-
set(BLOCKFACTORY_DEPENDENCIES BlockFactoryCore BlockFactorySimulinkCoder)
21+
set(BLOCKFACTORY_DEPENDENCIES BlockFactoryCore BlockFactorySimulinkCoder BlockFactoryTools)
2022
if (USES_MATLAB)
2123
list(APPEND BLOCKFACTORY_DEPENDENCIES BlockFactorySimulink)
2224
endif()

sources/Tools/CMakeLists.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) Istituto Italiano di Tecnologia (IIT). All rights reserved.
2+
# This software may be modified and distributed under the terms of the
3+
# GNU Lesser General Public License v2.1 or any later version.
4+
5+
set(BLOCKFACTORY_EXISTS_SRC
6+
src/BlockfactoryExists.cpp)
7+
8+
add_executable(blockfactory-exists ${BLOCKFACTORY_EXISTS_SRC})
9+
10+
target_link_libraries(blockfactory-exists PRIVATE BlockFactory::Core)
11+
12+
target_compile_warnings(blockfactory-exists
13+
WARNINGS_AS_ERRORS ${TREAT_WARNINGS_AS_ERRORS}
14+
DEPENDS ENABLE_WARNINGS)
15+
16+
install(
17+
TARGETS blockfactory-exists
18+
EXPORT BlockFactoryToolsExport
19+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
20+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
21+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
22+
23+
install_basic_package_files(BlockFactoryTools
24+
VERSION ${PROJECT_VERSION}
25+
COMPATIBILITY AnyNewerVersion
26+
EXPORT BlockFactoryToolsExport
27+
FIRST_TARGET blockfactory-exists
28+
NAMESPACE BlockFactory::
29+
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)