Skip to content

Commit 09827c3

Browse files
committed
added node.js
2 parents 46f0a20 + 0c0af59 commit 09827c3

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ if(SWIG_FOUND)
334334
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/infoLoggerForGo.go DESTINATION ${CMAKE_INSTALL_LIBDIR})
335335
endif()
336336

337+
#library for Javascript / node.js
338+
find_program(NODE_EXECUTABLE node)
339+
get_filename_component(NODE_DIR ${NODE_EXECUTABLE} DIRECTORY)
340+
find_path(NODEJS_INCLUDE_DIRS NAMES node.h PATHS ${Nodejs_ROOT} ${Nodejs_ROOT}/include ${NODE_DIR}/../include/node)
341+
if (NODEJS_INCLUDE_DIRS)
342+
message("Bindings for node.js will be generated")
343+
message("Using NODEJS_INCLUDE_DIRS=${NODEJS_INCLUDE_DIRS}")
344+
set(CMAKE_SWIG_FLAGS -module infoLoggerForNodejs -v8)
345+
swig_add_library(infoLoggerForNodejs LANGUAGE javascript SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
346+
target_include_directories(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${NODEJS_INCLUDE_DIRS})
347+
target_compile_definitions(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE -DBUILDING_NODE_EXTENSION)
348+
set_target_properties(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PROPERTIES OUTPUT_NAME infoLogger SUFFIX ".node")
349+
install(TARGETS ${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
350+
endif()
351+
337352
endif()
338353

339354

doc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ The InfoLogger library allows to inject messages directly from programs, as show
216216
217217
Usually, one will only take care of defining the per-message messageOptions struct and a context with appropriate Facility field set, all other being set automatically.
218218
219-
* InfoLogger library is also available for: Tcl, Python, Go.
219+
* InfoLogger library is also available for: Tcl, Python, Go, Node.js.
220220
It allows to log message from scripting languages. A simplified subset of the InfoLogger C++ API is made available through SWIG-generated modules.
221221
Details of the functions accessible from the scripting interface are provided in [a separate document](scriptingAPI.md).
222222
223223
224+
224225
## Configuration
225226
226227
* Description and example of parameters for each InfoLogger component can be found in /opt/o2-InfoLogger/etc/*.cfg.

doc/scriptingAPI.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,18 @@ Example usage is shown below. Library files listed there are available from the
8787
}
8888
```
8989
90+
* **Node.js**
91+
* Library files: `infoLogger.node`
92+
* Code example: (interactive interpreter from the command line)
93+
```
94+
node
95+
var infoLoggerModule=require("infoLogger");
96+
var logHandle=new infoLoggerModule.InfoLogger();
97+
logHandle.logInfo("This is a test");
98+
logHandle.logError("Something went wrong");
99+
```
100+
101+
102+
90103
## Tips
91104
Don't forget to delete the objects if necessary!

src/infoLogger.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
%}
1414

1515

16+
#ifdef SWIG_JAVASCRIPT_V8
17+
%inline %{
18+
#include <node.h>
19+
%}
20+
#endif
21+
22+
1623
%include <exception.i>
1724
%exception {
1825
try {

0 commit comments

Comments
 (0)