Skip to content

Commit 1464290

Browse files
committed
Further significant revision of extension interface, now with class; still some TODOs
1 parent ee0f46b commit 1464290

8 files changed

+91
-60
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ set( with-modelset "full" CACHE STRING "The modelset to include. Sample configur
6767
set( with-models OFF CACHE STRING "The models to include as a semicolon-separated list of model headers (without the .h extension). This option is mutually exclusive with -Dwith-modelset. [default=OFF]." )
6868
set( tics_per_ms "1000.0" CACHE STRING "Specify elementary unit of time [default=1000 tics per ms]." )
6969
set( tics_per_step "100" CACHE STRING "Specify resolution [default=100 tics per step]." )
70-
set( external-modules OFF CACHE STRING "External NEST modules to be linked in, separated by ';', [default=OFF]." )
7170
set( with-detailed-timers OFF CACHE STRING "Build with detailed internal time measurements [default=OFF]. Detailed timers can affect the performance." )
7271
set( target-bits-split "standard" CACHE STRING "Split of the 64-bit target neuron identifier type [default='standard']. 'standard' is recommended for most users. If running on more than 262144 MPI processes or more than 512 threads, change to 'hpc'." )
7372

@@ -136,7 +135,6 @@ nest_process_with_libraries()
136135
nest_process_with_includes()
137136
nest_process_with_defines()
138137
nest_process_static_libraries()
139-
nest_process_external_modules()
140138
nest_process_tics_per_ms()
141139
nest_process_tics_per_step()
142140
nest_process_with_libltdl()

cmake/ConfigureSummary.cmake

-12
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ function( NEST_PRINT_CONFIG_SUMMARY )
4343
message( "Built-in modelset : ${with-modelset}" )
4444
endif ()
4545

46-
message( "" )
47-
if ( external-modules )
48-
message( "User modules : ${external-modules}" )
49-
foreach ( mod ${external-modules} )
50-
message( " ${mod}:" )
51-
message( " Header : ${${mod}_EXT_MOD_INCLUDE}" )
52-
message( " Library : ${${mod}_EXT_MOD_LIBRARY}" )
53-
endforeach ()
54-
else ()
55-
message( "User modules : None" )
56-
endif ()
57-
5846
message( "" )
5947
if ( HAVE_PYTHON )
6048
message( "Python bindings : Yes (Python ${Python_VERSION}: ${PYTHON})" )

cmake/ProcessOptions.cmake

-37
Original file line numberDiff line numberDiff line change
@@ -222,43 +222,6 @@ function( NEST_PROCESS_STATIC_LIBRARIES )
222222
endif ()
223223
endfunction()
224224

225-
function( NEST_PROCESS_EXTERNAL_MODULES )
226-
if ( external-modules )
227-
# headers from external modules will be installed here
228-
include_directories( "${CMAKE_INSTALL_FULL_INCLUDEDIR}" )
229-
230-
# put all external libs into this variable
231-
set( EXTERNAL_MODULE_LIBRARIES )
232-
# put all external headers into this variable
233-
set( EXTERNAL_MODULE_INCLUDES )
234-
foreach ( mod ${external-modules} )
235-
# find module header
236-
find_file( ${mod}_EXT_MOD_INCLUDE
237-
NAMES ${mod}module.h
238-
HINTS "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${mod}module"
239-
)
240-
if ( ${mod}_EXT_MOD_INCLUDE STREQUAL "${mod}_EXT_MOD_INCLUDE-NOTFOUND" )
241-
printError( "Cannot find header for external module '${mod}'. "
242-
"Should be '${CMAKE_INSTALL_FULL_INCLUDEDIR}/${mod}module/${mod}module.h' ." )
243-
endif ()
244-
list( APPEND EXTERNAL_MODULE_INCLUDES ${${mod}_EXT_MOD_INCLUDE} )
245-
246-
# find module library
247-
find_library( ${mod}_EXT_MOD_LIBRARY
248-
NAMES ${mod}module
249-
HINTS "${CMAKE_INSTALL_FULL_LIBDIR}/nest"
250-
)
251-
if ( ${mod}_EXT_MOD_LIBRARY STREQUAL "${mod}_EXT_MOD_LIBRARY-NOTFOUND" )
252-
printError( "Cannot find library for external module '${mod}'." )
253-
endif ()
254-
list( APPEND EXTERNAL_MODULE_LIBRARIES "${${mod}_EXT_MOD_LIBRARY}" )
255-
endforeach ()
256-
257-
set( EXTERNAL_MODULE_LIBRARIES ${EXTERNAL_MODULE_LIBRARIES} PARENT_SCOPE )
258-
set( EXTERNAL_MODULE_INCLUDES ${EXTERNAL_MODULE_INCLUDES} PARENT_SCOPE )
259-
endif ()
260-
endfunction()
261-
262225
function( NEST_PROCESS_TICS_PER_MS )
263226
# Set tics per ms / step
264227
if ( tics_per_ms )

nest/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ set_target_properties( nest_lib
5656

5757
target_link_libraries( nest
5858
nestutil nestkernel sli_lib sli_readline models
59-
${EXTERNAL_MODULE_LIBRARIES} OpenMP::OpenMP_CXX )
59+
OpenMP::OpenMP_CXX )
6060

6161
target_link_libraries( nest_lib
62-
nestutil nestkernel sli_lib models ${EXTERNAL_MODULE_LIBRARIES}
62+
nestutil nestkernel sli_lib models
6363
OpenMP::OpenMP_CXX )
6464

6565
target_include_directories( nest PRIVATE
@@ -88,7 +88,6 @@ target_include_directories( nest_lib PRIVATE
8888
${Python_INCLUDE_DIRS}
8989
)
9090

91-
9291
if ( HAVE_PYTHON )
9392
target_compile_definitions( nest_lib PRIVATE
9493
-D_IS_PYNEST

nestkernel/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ set ( nestkernel_sources
115115
spatial.h spatial.cpp
116116
stimulation_backend.h
117117
buffer_resize_log.h buffer_resize_log.cpp
118+
nest_extension_interface.h
118119
)
119120

120121

nestkernel/module_manager.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
// Includes from nestkernel:
3131
#include "kernel_manager.h"
32+
#include "nest_extension_interface.h"
3233

3334
// Includes from sli:
3435
#include "arraydatum.h"
@@ -59,7 +60,8 @@ ModuleManager::finalize( const bool )
5960
// unload all loaded modules
6061
for ( const auto& [ name, handle ] : modules_ )
6162
{
62-
lt_dlclose( handle );
63+
// TODO: If this is not commented out, unloading leads to a seg-fault.
64+
// lt_dlclose( handle );
6365
}
6466
modules_.clear();
6567
}
@@ -112,8 +114,7 @@ ModuleManager::install( const std::string& name )
112114
}
113115

114116
// see if we can find the register_components symbol in the module
115-
using reg_func_type = void();
116-
reg_func_type* register_components = ( reg_func_type* ) lt_dlsym( hModule, "register_components" );
117+
NESTExtensionInterface* extension = reinterpret_cast< NESTExtensionInterface* >( lt_dlsym( hModule, "module" ) );
117118
char* errstr = ( char* ) lt_dlerror();
118119
if ( errstr )
119120
{
@@ -128,7 +129,7 @@ ModuleManager::install( const std::string& name )
128129
// all is well an we can register module components
129130
try
130131
{
131-
register_components();
132+
extension->init();
132133
}
133134
catch ( std::exception& e )
134135
{
@@ -140,7 +141,7 @@ ModuleManager::install( const std::string& name )
140141
// add the handle to list of loaded modules
141142
modules_[ name ] = hModule;
142143

143-
LOG( M_INFO, "Install", ( "loaded module " + name ).c_str() );
144+
LOG( M_INFO, "Install", ( "loaded module " + extension->name() ).c_str() );
144145
}
145146

146147
} // namespace nest

nestkernel/nest_extension_interface.h

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* nest_extension_interface.h
3+
*
4+
* This file is part of NEST.
5+
*
6+
* Copyright (C) 2004 The NEST Initiative
7+
*
8+
* NEST is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* NEST is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with NEST. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#ifndef NEST_EXTENSION_INTERFACE_H
24+
#define NEST_EXTENSION_INTERFACE_H
25+
26+
// Includes from nestkernel; placed here so module developer does not need to
27+
// include them manually
28+
#include "config.h"
29+
#include "connection_manager_impl.h"
30+
#include "connector_model_impl.h"
31+
#include "exceptions.h"
32+
#include "genericmodel.h"
33+
#include "genericmodel_impl.h"
34+
#include "io_manager_impl.h"
35+
#include "kernel_manager.h"
36+
#include "model.h"
37+
#include "model_manager_impl.h"
38+
#include "nest.h"
39+
#include "nest_impl.h"
40+
#include "nestmodule.h"
41+
#include "target_identifier.h"
42+
43+
// C++ includes
44+
#include <string>
45+
46+
/**
47+
* Interface for NEST Extenstion Modules.
48+
*
49+
* All NEST Extension Modules must be derived from this interface class.
50+
*
51+
* Method init() will be called after the module is loaded.
52+
*
53+
* The constructor should be empty.
54+
*/
55+
56+
class NESTExtensionInterface
57+
{
58+
public:
59+
virtual ~NESTExtensionInterface()
60+
{
61+
}
62+
63+
/**
64+
* Initialize module, register all components with kernel
65+
*/
66+
virtual void init() = 0;
67+
68+
//! Name of module
69+
virtual std::string name() = 0;
70+
71+
//! Contact information
72+
virtual std::string contact() = 0;
73+
74+
//! Website
75+
virtual std::string url() = 0;
76+
77+
//! Permanent URI
78+
virtual std::string uri() = 0;
79+
};
80+
81+
#endif // #ifndef NEST_EXTENSION_INTERFACE_H

pynest/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ if ( HAVE_PYTHON )
5454
endif ()
5555

5656
target_link_libraries( pynestkernel
57-
nest_lib nestutil nestkernel sli_lib models ${EXTERNAL_MODULE_LIBRARIES}
57+
nest_lib nestutil nestkernel sli_lib models
5858
)
5959

6060
target_include_directories( pynestkernel PRIVATE

0 commit comments

Comments
 (0)