diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd25070d..c8d2fd692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,66 +1,8 @@ # SlideRule top-level CMake build script project (SLIDERULE LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -# Set a default build type if none was specified -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(default_build_type "Release") - if(EXISTS "${CMAKE_SOURCE_DIR}/.git") - set(default_build_type "Debug") - endif() - message(STATUS "Setting build type to '${default_build_type}' as none was specified.") - set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) -endif() - -# Set a default platform -if(NOT CMAKE_BUILD_PLATFORM) - set(CMAKE_BUILD_PLATFORM "Linux" CACHE STRING "Choose the target platform." FORCE) -endif() - -################### -# Project Options # -################### - -# Project Options # - -option (PYTHON_BINDINGS "Create Python bindings, including h5lite module" OFF) -option (SHARED_LIBRARY "Create shared library instead of sliderule binary" OFF) -option (SERVER_APP "Create sliderule server binary" ON) - -# Library Options # - -option (ENABLE_COMPAT "Use C++11 for compatibility with older compilers" OFF) -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) -option (ENABLE_TIME_HEARTBEAT "Instruct TimeLib to use a 1KHz heart beat timer to set millisecond time resolution" OFF) -option (ENABLE_CUSTOM_ALLOCATOR "Override new and delete operators globally for debug purposes" OFF) -option (ENABLE_H5CORO_ATTRIBUTE_SUPPORT "H5Coro will read and process attribute messages" OFF) -option (ENABLE_APACHE_ARROW_10_COMPAT "Use Apache Arrow 11 interface" OFF) -option (ENABLE_BEST_EFFORT_CONDA_ENV "Attempt to alleviate some issues with running in a conda environment") - -# Package Options # - -option (USE_ARROW_PACKAGE "Include the Apache Arrow package" OFF) -option (USE_AWS_PACKAGE "Include the AWS package" OFF) -option (USE_CCSDS_PACKAGE "Include the CCSDS package" ON) -option (USE_GEO_PACKAGE "Include the GEO package" OFF) -option (USE_H5_PACKAGE "Include the HDF5 package" ON) -option (USE_LEGACY_PACKAGE "Include the Legacy package" ON) -option (USE_NETSVC_PACKAGE "Include the Network Services package" OFF) -option (USE_PISTACHE_PACKAGE "Include the Pistache package" OFF) - -# Platform Options # - -option (ENABLE_TRACING "Instantiate trace points" OFF) -option (ENABLE_TERMINAL "Instantiate terminal messages" ON) +include(${CMAKE_CURRENT_SOURCE_DIR}/project-config.cmake) ##################### # Target: SlideRule # @@ -74,47 +16,12 @@ else() add_library(slideruleLib STATIC "") endif() -# Version Information # - -file(STRINGS ${PROJECT_SOURCE_DIR}/version.txt TGTVER) -string(REPLACE "v" "" LIBVER ${TGTVER}) - -# C++ Version # - -if(${ENABLE_COMPAT}) - set(CXX_VERSION 11) -else() - set(CXX_VERSION 17) # required if using pistache package -endif() - -# Platform # - -set_property(GLOBAL PROPERTY platform "") +# Platform Config # if(CMAKE_BUILD_PLATFORM MATCHES "Linux") - - # Prefer libraries installed in /usr/local - INCLUDE_DIRECTORIES(/usr/local/include) - LINK_DIRECTORIES(/usr/local/lib) - - # Set Environment Variables - set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") - set (CONFDIR ${INSTALLDIR}/etc/sliderule) - set (INCDIR ${INSTALLDIR}/include/sliderule) - - # Include Linux Platform # add_subdirectory (platforms/linux) - elseif(CMAKE_BUILD_PLATFORM MATCHES "Windows") - - # Set Environment Variables - set (INSTALLDIR "C:\\Program Files\\SlideRule" CACHE STRING "Installation directory for library and executables") - set (CONFDIR ${INSTALLDIR}\etc\sliderule) - set (INCDIR ${INSTALLDIR}\include\sliderule) - - # Include Windows Platform # add_subdirectory (platforms/windows) - endif() # Target Properties # @@ -124,14 +31,8 @@ set_target_properties (slideruleLib PROPERTIES OUTPUT_NAME sliderule) set_target_properties (slideruleLib PROPERTIES ENABLE_EXPORTS true) set_target_properties (slideruleLib PROPERTIES CXX_STANDARD ${CXX_VERSION}) -if(${PYTHON_BINDINGS}) - set_target_properties (slideruleLib PROPERTIES POSITION_INDEPENDENT_CODE 1) -endif() - # Compile Definitions # -set (RUNTIMEDIR ${CONFDIR} CACHE STRING "Runtime directory for plugins and configuration scripts") - if (${ENABLE_TIME_HEARTBEAT}) message (STATUS "Enabling time heartbeat") target_compile_definitions (slideruleLib PUBLIC TIME_HEARTBEAT) @@ -248,12 +149,6 @@ add_subdirectory (scripts) install (TARGETS slideruleLib DESTINATION ${INSTALLDIR}/lib) -if(${PYTHON_BINDINGS}) - - add_subdirectory (targets/binding-python) - -elseif(${SERVER_APP} AND (CMAKE_BUILD_PLATFORM MATCHES "Linux")) - +if(${SERVER_APP} AND (CMAKE_BUILD_PLATFORM MATCHES "Linux")) add_subdirectory (targets/server-linux) - endif() diff --git a/Makefile b/Makefile index fc7ddc202..e5336f2ff 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,6 @@ USGS3DEP_BUILD = $(BUILD)/usgs3dep OPENDATA_BUILD = $(BUILD)/opendata SWOT_BUILD = $(BUILD)/swot -# when using the llvm toolchain to build the source -CLANG_OPT = -DCMAKE_USER_MAKE_RULES_OVERRIDE=$(ROOT)/platforms/linux/ClangOverrides.txt -D_CMAKE_TOOLCHAIN_PREFIX=llvm- - -# for a MacOSX host to have this ip command you must install homebrew(see https://brew.sh/) then run 'brew install iproute2mac' on your mac host -MYIP ?= $(shell (ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$$/\1/p')) - ######################## # Core Framework Targets ######################## @@ -223,19 +217,6 @@ uninstall-swot: ## uninstall most recent install of icesat2 plugin from system # Development Targets ######################## -scan: prep ## perform static analysis - cd $(SLIDERULE_BUILD); export CC=clang; export CXX=clang++; scan-build cmake $(CLANG_OPT) $(DEVCFG) $(ROOT) - cd $(SLIDERULE_BUILD); scan-build -o scan-results make - -asan: prep ## build address sanitizer debug version of sliderule binary - cd $(SLIDERULE_BUILD); export CC=clang; export CXX=clang++; cmake $(CLANG_OPT) $(DEVCFG) -DCMAKE_BUILD_TYPE=Debug -DENABLE_ADDRESS_SANITIZER=ON $(ROOT) - cd $(SLIDERULE_BUILD); make - -ctags: ## generate ctags - if [ -d ".clangd/index/" ]; then rm -f .clangd/index/*; fi ## clear clagnd index (before clangd-11) - if [ -d ".cache/clangd/index/" ]; then rm -f .cache/clangd/index/*; fi ## clear clagnd index (clangd-11) - /usr/bin/jq -s 'add' $(SLIDERULE_BUILD)/compile_commands.json $(PGC_BUILD)/compile_commands.json $(ICESAT2_BUILD)/compile_commands.json $(GEDI_BUILD)/compile_commands.json $(LANDSAT_BUILD)/compile_commands.json $(USGS3DEP_BUILD)/compile_commands.json $(OPENDATA_BUILD)/compile_commands.json $(SWOT_BUILD)/compile_commands.json > compile_commands.json - testmem: ## run memory test on sliderule valgrind --leak-check=full --track-origins=yes --track-fds=yes sliderule $(testcase) @@ -256,14 +237,15 @@ testcov: ## analyze results of test coverage report genhtml $(SLIDERULE_BUILD)/coverage.info --output-directory $(SLIDERULE_BUILD)/coverage_html # firefox $(SLIDERULE_BUILD)/coverage_html/index.html -testpy: ## run python binding test - cp scripts/systests/coro.py $(SLIDERULE_BUILD) - cd $(SLIDERULE_BUILD); /usr/bin/python3 coro.py - ######################## # Global Targets ######################## +ctags: ## generate ctags + if [ -d ".clangd/index/" ]; then rm -f .clangd/index/*; fi ## clear clagnd index (before clangd-11) + if [ -d ".cache/clangd/index/" ]; then rm -f .cache/clangd/index/*; fi ## clear clagnd index (clangd-11) + /usr/bin/jq -s 'add' $(SLIDERULE_BUILD)/compile_commands.json $(PGC_BUILD)/compile_commands.json $(ICESAT2_BUILD)/compile_commands.json $(GEDI_BUILD)/compile_commands.json $(LANDSAT_BUILD)/compile_commands.json $(USGS3DEP_BUILD)/compile_commands.json $(OPENDATA_BUILD)/compile_commands.json $(SWOT_BUILD)/compile_commands.json > compile_commands.json + prep: ## create necessary build directories mkdir -p $(SLIDERULE_BUILD) mkdir -p $(PGC_BUILD) diff --git a/README.md b/README.md index fb7702bcf..70bc4eebf 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,7 @@ Options include: -DRUNTIMEDIR=[directory] location for run-time files like plugins, configuration files, and lua scripts default: /usr/local/etc/sliderule - -DPYTHON_BINDINGS=[ON|OFF] build python bindings instead of sliderule executable (overrides all other targets) - default: OFF - - -DSHARED_LIBRARY=[ON|OFF] build sliderule as a shared library (overrides all other targets except for PYTHON_BINDINGS) + -DSHARED_LIBRARY=[ON|OFF] build sliderule as a shared library (overrides all other targets) default: OFF -DENABLE_COMPAT=[ON|OFF] configure build for older tool chains (needed to build on CentOS 7) diff --git a/clients/nodejs/Makefile b/clients/nodejs/Makefile index 1c365895b..33c189066 100644 --- a/clients/nodejs/Makefile +++ b/clients/nodejs/Makefile @@ -16,7 +16,10 @@ publish: ## publish package to npm registry login: ## login to npm registry npm login --scope sliderule --auth-type legacy -install: ## install project (installs dependencies in package.json file) +update: ## update project (updates dependencies in package-lock.json file) + cd sliderule; npm install + +install: ## install project (installs dependencies in package-lock.json file) cd sliderule; npm install init: ## initialize project diff --git a/clients/nodejs/sliderule/package-lock.json b/clients/nodejs/sliderule/package-lock.json index 346bf6ba7..15854caa1 100644 --- a/clients/nodejs/sliderule/package-lock.json +++ b/clients/nodejs/sliderule/package-lock.json @@ -1,12 +1,12 @@ { - "name": "sliderule", - "version": "3.3.0", + "name": "@sliderule/sliderule", + "version": "4.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "sliderule", - "version": "3.3.0", + "name": "@sliderule/sliderule", + "version": "4.0.2", "license": "BSD-3-Clause", "dependencies": { "netrc": "^0.1.4" @@ -29,47 +29,119 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.21.4", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", - "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", + "version": "7.22.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", + "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", "dev": true, "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.13", + "chalk": "^2.4.2" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/code-frame/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/@babel/code-frame/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/@babel/code-frame/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@babel/code-frame/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/compat-data": { - "version": "7.21.7", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.21.7.tgz", - "integrity": "sha512-KYMqFYTaenzMK4yUtf4EW9wc4N9ef80FsbMtkwool5zpwl4YrT1SdWYSTRcT94KO4hannogdS+LxY7L+arP3gA==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.23.2.tgz", + "integrity": "sha512-0S9TQMmDHlqAZ2ITT95irXKfxN9bncq8ZCoJhun3nHL/lLUxd2NKBJYoNGWH7S0hz6fRQwWlAWn/ILM0C70KZQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.21.8.tgz", - "integrity": "sha512-YeM22Sondbo523Sz0+CirSPnbj9bG3P0CdHcBZdqUuaeOaYEFbOLoGU7lebvGP6P5J/WE9wOn7u7C4J9HvS1xQ==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.2.tgz", + "integrity": "sha512-n7s51eWdaWZ3vGT2tD4T7J6eJs3QoBXydv7vkUM06Bf1cbVD2Kc2UrkzhiQwobfV7NwOnQXYL7UBJ5VPU+RGoQ==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-compilation-targets": "^7.21.5", - "@babel/helper-module-transforms": "^7.21.5", - "@babel/helpers": "^7.21.5", - "@babel/parser": "^7.21.8", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5", - "convert-source-map": "^1.7.0", + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-compilation-targets": "^7.22.15", + "@babel/helper-module-transforms": "^7.23.0", + "@babel/helpers": "^7.23.2", + "@babel/parser": "^7.23.0", + "@babel/template": "^7.22.15", + "@babel/traverse": "^7.23.2", + "@babel/types": "^7.23.0", + "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", - "json5": "^2.2.2", - "semver": "^6.3.0" + "json5": "^2.2.3", + "semver": "^6.3.1" }, "engines": { "node": ">=6.9.0" @@ -79,19 +151,13 @@ "url": "https://opencollective.com/babel" } }, - "node_modules/@babel/core/node_modules/convert-source-map": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", - "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true - }, "node_modules/@babel/generator": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.21.5.tgz", - "integrity": "sha512-SrKK/sRv8GesIW1bDagf9cCG38IOMYZusoe1dfg0D8aiUe3Amvoj1QtjTPAWcfrZFvIwlleLb0gxzQidL9w14w==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", + "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", "dev": true, "dependencies": { - "@babel/types": "^7.21.5", + "@babel/types": "^7.23.0", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -101,171 +167,168 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.21.5.tgz", - "integrity": "sha512-1RkbFGUKex4lvsB9yhIfWltJM5cZKUftB2eNajaDv3dCMEp49iBG0K14uH8NnX9IPux2+mK7JGEOB0jn48/J6w==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.15.tgz", + "integrity": "sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.21.5", - "@babel/helper-validator-option": "^7.21.0", - "browserslist": "^4.21.3", + "@babel/compat-data": "^7.22.9", + "@babel/helper-validator-option": "^7.22.15", + "browserslist": "^4.21.9", "lru-cache": "^5.1.1", - "semver": "^6.3.0" + "semver": "^6.3.1" }, "engines": { "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0" } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.21.5.tgz", - "integrity": "sha512-IYl4gZ3ETsWocUWgsFZLM5i1BYx9SoemminVEXadgLBa9TdeorzgLKm8wWLA6J1N/kT3Kch8XIk1laNzYoHKvQ==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-function-name": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.21.0.tgz", - "integrity": "sha512-HfK1aMRanKHpxemaY2gqBmL04iAPOPRj7DxtNbiDOrJK+gdwkiNRVpCpUJYbUT+aZyemKN8brqTOxzCaG6ExRg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dev": true, "dependencies": { - "@babel/template": "^7.20.7", - "@babel/types": "^7.21.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "dev": true, "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.21.4", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.21.4.tgz", - "integrity": "sha512-orajc5T2PsRYUN3ZryCEFeMDYwyw09c/pZeaQEZPH0MpKzSvn3e0uXsDBu3k03VI+9DBiRo+l22BfKTpKwa/Wg==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.22.15.tgz", + "integrity": "sha512-0pYVBnDKZO2fnSPCrgM/6WMc7eS20Fbok+0r88fp+YtWVLZrp4CkafFGIp+W0VKw4a22sgebPT99y+FDNMdP4w==", "dev": true, "dependencies": { - "@babel/types": "^7.21.4" + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.21.5.tgz", - "integrity": "sha512-bI2Z9zBGY2q5yMHoBvJ2a9iX3ZOAzJPm7Q8Yz6YeoUjU/Cvhmi2G4QyTNyPBqqXSgTjUxRg3L0xV45HvkNWWBw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz", + "integrity": "sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==", "dev": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.21.5", - "@babel/helper-module-imports": "^7.21.4", - "@babel/helper-simple-access": "^7.21.5", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/helper-validator-identifier": "^7.19.1", - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-module-imports": "^7.22.15", + "@babel/helper-simple-access": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/helper-validator-identifier": "^7.22.20" }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.21.5.tgz", - "integrity": "sha512-0WDaIlXKOX/3KfBK/dwP1oQGiPh6rjMkT7HIRv7i5RR2VUMwrx5ZL0dwBkKx7+SW1zwNdgjHd34IMk5ZjTeHVg==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", + "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-simple-access": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.21.5.tgz", - "integrity": "sha512-ENPDAMC1wAjR0uaCUwliBdiSl1KBJAVnMTzXqi64c2MG8MPR6ii4qf7bSXDqSFbr4W6W028/rf5ivoHop5/mkg==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz", + "integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==", "dev": true, "dependencies": { - "@babel/types": "^7.21.5" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dev": true, "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.21.5.tgz", - "integrity": "sha512-5pTUx3hAJaZIdW99sJ6ZUUgWq/Y+Hja7TowEnLNMm1VivRgZQL3vpBY3qUACVsvw+yQU6+YgfBVmcbLaZtrA1w==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.21.0.tgz", - "integrity": "sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz", + "integrity": "sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.21.5.tgz", - "integrity": "sha512-BSY+JSlHxOmGsPTydUkPf1MdMQ3M81x5xGCOVgWM3G8XH77sJ292Y2oqcp0CbbgxhqBuI46iUz1tT7hqP7EfgA==", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.2.tgz", + "integrity": "sha512-lzchcp8SjTSVe/fPmLwtWVBFC7+Tbn8LGHDVfDp9JGxpAY5opSaEFgt8UQvrnECWOTdji2mOWMz1rOhkHscmGQ==", "dev": true, "dependencies": { - "@babel/template": "^7.20.7", - "@babel/traverse": "^7.21.5", - "@babel/types": "^7.21.5" + "@babel/template": "^7.22.15", + "@babel/traverse": "^7.23.2", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", + "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, "engines": { @@ -344,9 +407,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.21.8", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.8.tgz", - "integrity": "sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", + "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -416,12 +479,12 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.21.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.21.4.tgz", - "integrity": "sha512-5hewiLct5OKyh6PLKEYaFclcqtIgCb6bmELouxjF6up5q3Sov7rOayW4RwhbaBL0dit8rA80GNfY+UuDp2mBbQ==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.22.5.tgz", + "integrity": "sha512-gvyP4hZrgrs/wWMaocvxZ44Hw0b3W8Pe+cMxc8V1ULQ07oh8VNbIRaoD1LRZVTvD+0nieDKjfgKg89sD7rrKrg==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.20.2" + "@babel/helper-plugin-utils": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -518,12 +581,12 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.21.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.21.4.tgz", - "integrity": "sha512-xz0D39NvhQn4t4RNsHmDnnsaQizIlUkdtYvLs8La1BlfjQ6JEwxkJGeqJMW2tAXx+q6H+WFuUTXNdYVpEya0YA==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.22.5.tgz", + "integrity": "sha512-1mS2o03i7t1c6VzH6fdQ3OA8tcEIxwG18zIPRp+UY1Ihv6W+XZzBCVxExF9upussPXJ0xE9XRHwMoNs1ep/nRQ==", "dev": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.20.2" + "@babel/helper-plugin-utils": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -533,33 +596,33 @@ } }, "node_modules/@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.21.5.tgz", - "integrity": "sha512-AhQoI3YjWi6u/y/ntv7k48mcrCXmus0t79J9qPNlk/lAsFlCiJ047RmbfMOawySTHtywXhbXgpx/8nXMYd+oFw==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.21.4", - "@babel/generator": "^7.21.5", - "@babel/helper-environment-visitor": "^7.21.5", - "@babel/helper-function-name": "^7.21.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.21.5", - "@babel/types": "^7.21.5", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.0", + "@babel/types": "^7.23.0", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -568,13 +631,13 @@ } }, "node_modules/@babel/types": { - "version": "7.21.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.21.5.tgz", - "integrity": "sha512-m4AfNvVF2mVC/F7fDEdH2El3HzUg9It/XsCxZiOTTA3m3qYfcSVSbTfM6Q9xG+hYDniZssYhlXKKUMD5m8tF4Q==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", + "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.21.5", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, "engines": { @@ -613,16 +676,16 @@ } }, "node_modules/@jest/console": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/console/-/console-29.5.0.tgz", - "integrity": "sha512-NEpkObxPwyw/XxZVLPmAGKE89IQRp4puc6IQRPru6JKd1M3fW9v1xM1AnzIJE65hbCkzQAdnL8P47e9hzhiYLQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/console/-/console-29.7.0.tgz", + "integrity": "sha512-5Ni4CU7XHQi32IJ398EEP4RrB8eV09sXP2ROqD4bksHrnTree52PsxvX8tpL8LvTZ3pFzXyPbNQReSN41CAhOg==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0", "slash": "^3.0.0" }, "engines": { @@ -630,37 +693,37 @@ } }, "node_modules/@jest/core": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/core/-/core-29.5.0.tgz", - "integrity": "sha512-28UzQc7ulUrOQw1IsN/kv1QES3q2kkbl/wGslyhAclqZ/8cMdB5M68BffkIdSJgKBUt50d3hbwJ92XESlE7LiQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/core/-/core-29.7.0.tgz", + "integrity": "sha512-n7aeXWKMnGtDA48y8TLWJPJmLmmZ642Ceo78cYWEpiD7FzDgmNDV/GCVRorPABdXLJZ/9wzzgZAlHjXjxDHGsg==", "dev": true, "dependencies": { - "@jest/console": "^29.5.0", - "@jest/reporters": "^29.5.0", - "@jest/test-result": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/console": "^29.7.0", + "@jest/reporters": "^29.7.0", + "@jest/test-result": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", "ansi-escapes": "^4.2.1", "chalk": "^4.0.0", "ci-info": "^3.2.0", "exit": "^0.1.2", "graceful-fs": "^4.2.9", - "jest-changed-files": "^29.5.0", - "jest-config": "^29.5.0", - "jest-haste-map": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.5.0", - "jest-resolve-dependencies": "^29.5.0", - "jest-runner": "^29.5.0", - "jest-runtime": "^29.5.0", - "jest-snapshot": "^29.5.0", - "jest-util": "^29.5.0", - "jest-validate": "^29.5.0", - "jest-watcher": "^29.5.0", + "jest-changed-files": "^29.7.0", + "jest-config": "^29.7.0", + "jest-haste-map": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.7.0", + "jest-resolve-dependencies": "^29.7.0", + "jest-runner": "^29.7.0", + "jest-runtime": "^29.7.0", + "jest-snapshot": "^29.7.0", + "jest-util": "^29.7.0", + "jest-validate": "^29.7.0", + "jest-watcher": "^29.7.0", "micromatch": "^4.0.4", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "slash": "^3.0.0", "strip-ansi": "^6.0.0" }, @@ -677,89 +740,89 @@ } }, "node_modules/@jest/environment": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.5.0.tgz", - "integrity": "sha512-5FXw2+wD29YU1d4I2htpRX7jYnAyTRjP2CsXQdo9SAM8g3ifxWPSV0HnClSn71xwctr0U3oZIIH+dtbfmnbXVQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", + "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", "dev": true, "dependencies": { - "@jest/fake-timers": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.5.0" + "jest-mock": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-PueDR2HGihN3ciUNGr4uelropW7rqUfTiOn+8u0leg/42UhblPxHkfoh0Ruu3I9Y1962P3u2DY4+h7GVTSVU6g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==", "dev": true, "dependencies": { - "expect": "^29.5.0", - "jest-snapshot": "^29.5.0" + "expect": "^29.7.0", + "jest-snapshot": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.5.0.tgz", - "integrity": "sha512-fmKzsidoXQT2KwnrwE0SQq3uj8Z763vzR8LnLBwC2qYWEFpjX8daRsk6rHUM1QvNlEW/UJXNXm59ztmJJWs2Mg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", + "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", "dev": true, "dependencies": { - "jest-get-type": "^29.4.3" + "jest-get-type": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/fake-timers": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.5.0.tgz", - "integrity": "sha512-9ARvuAAQcBwDAqOnglWq2zwNIRUDtk/SCkp/ToGEhFv5r86K21l+VEs0qNTaXtyiY0lEePl3kylijSYJQqdbDg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.7.0.tgz", + "integrity": "sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@sinonjs/fake-timers": "^10.0.2", "@types/node": "*", - "jest-message-util": "^29.5.0", - "jest-mock": "^29.5.0", - "jest-util": "^29.5.0" + "jest-message-util": "^29.7.0", + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/globals": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.5.0.tgz", - "integrity": "sha512-S02y0qMWGihdzNbUiqSAiKSpSozSuHX5UYc7QbnHP+D9Lyw8DgGGCinrN9uSuHPeKgSSzvPom2q1nAtBvUsvPQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.7.0.tgz", + "integrity": "sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==", "dev": true, "dependencies": { - "@jest/environment": "^29.5.0", - "@jest/expect": "^29.5.0", - "@jest/types": "^29.5.0", - "jest-mock": "^29.5.0" + "@jest/environment": "^29.7.0", + "@jest/expect": "^29.7.0", + "@jest/types": "^29.6.3", + "jest-mock": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/reporters": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-29.5.0.tgz", - "integrity": "sha512-D05STXqj/M8bP9hQNSICtPqz97u7ffGzZu+9XLucXhkOFBqKcXe04JLZOgIekOxdb73MAoBUFnqvf7MCpKk5OA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-29.7.0.tgz", + "integrity": "sha512-DApq0KJbJOEzAFYjHADNNxAE3KbhxQB1y5Kplb5Waqw6zVbuWatSnMjE5gs8FUgEPmNsnZA3NCWl9NG0ia04Pg==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", - "@jest/console": "^29.5.0", - "@jest/test-result": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", - "@jridgewell/trace-mapping": "^0.3.15", + "@jest/console": "^29.7.0", + "@jest/test-result": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", + "@jridgewell/trace-mapping": "^0.3.18", "@types/node": "*", "chalk": "^4.0.0", "collect-v8-coverage": "^1.0.0", @@ -767,13 +830,13 @@ "glob": "^7.1.3", "graceful-fs": "^4.2.9", "istanbul-lib-coverage": "^3.0.0", - "istanbul-lib-instrument": "^5.1.0", + "istanbul-lib-instrument": "^6.0.0", "istanbul-lib-report": "^3.0.0", "istanbul-lib-source-maps": "^4.0.0", "istanbul-reports": "^3.1.3", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0", - "jest-worker": "^29.5.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", "slash": "^3.0.0", "string-length": "^4.0.1", "strip-ansi": "^6.0.0", @@ -792,24 +855,24 @@ } }, "node_modules/@jest/schemas": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.4.3.tgz", - "integrity": "sha512-VLYKXQmtmuEz6IxJsrZwzG9NvtkQsWNnWMsKxqWNu3+CnfzJQhp0WDDKWLVV9hLKr0l3SLLFRqcYHjhtyuDVxg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", "dev": true, "dependencies": { - "@sinclair/typebox": "^0.25.16" + "@sinclair/typebox": "^0.27.8" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/source-map": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/@jest/source-map/-/source-map-29.4.3.tgz", - "integrity": "sha512-qyt/mb6rLyd9j1jUts4EQncvS6Yy3PM9HghnNv86QBlV+zdL2inCdK1tuVlL+J+lpiw2BI67qXOrX3UurBqQ1w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/source-map/-/source-map-29.6.3.tgz", + "integrity": "sha512-MHjT95QuipcPrpLM+8JMSzFx6eHp5Bm+4XeFDJlwsvVBjmKNiIAvasGK2fxz2WbGRlnvqehFbh07MMa7n3YJnw==", "dev": true, "dependencies": { - "@jridgewell/trace-mapping": "^0.3.15", + "@jridgewell/trace-mapping": "^0.3.18", "callsites": "^3.0.0", "graceful-fs": "^4.2.9" }, @@ -818,13 +881,13 @@ } }, "node_modules/@jest/test-result": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-29.5.0.tgz", - "integrity": "sha512-fGl4rfitnbfLsrfx1uUpDEESS7zM8JdgZgOCQuxQvL1Sn/I6ijeAVQWGfXI9zb1i9Mzo495cIpVZhA0yr60PkQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/test-result/-/test-result-29.7.0.tgz", + "integrity": "sha512-Fdx+tv6x1zlkJPcWXmMDAG2HBnaR9XPSd5aDWQVsfrZmLVT3lU1cwyxLgRmXR9yrq4NBoEm9BMsfgFzTQAbJYA==", "dev": true, "dependencies": { - "@jest/console": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/console": "^29.7.0", + "@jest/types": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "collect-v8-coverage": "^1.0.0" }, @@ -833,14 +896,14 @@ } }, "node_modules/@jest/test-sequencer": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-29.5.0.tgz", - "integrity": "sha512-yPafQEcKjkSfDXyvtgiV4pevSeyuA6MQr6ZIdVkWJly9vkqjnFfcfhRQqpD5whjoU8EORki752xQmjaqoFjzMQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-29.7.0.tgz", + "integrity": "sha512-GQwJ5WZVrKnOJuiYiAF52UNUJXgTZx1NHjFSEB0qEMmSZKAkdMoIzw/Cj6x6NF4AvV23AUqDpFzQkN/eYCYTxw==", "dev": true, "dependencies": { - "@jest/test-result": "^29.5.0", + "@jest/test-result": "^29.7.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", + "jest-haste-map": "^29.7.0", "slash": "^3.0.0" }, "engines": { @@ -848,22 +911,22 @@ } }, "node_modules/@jest/transform": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.5.0.tgz", - "integrity": "sha512-8vbeZWqLJOvHaDfeMuoHITGKSz5qWc9u04lnWrQE3VyuSw604PzQM824ZeX9XSjUCeDiE3GuxZe5UKa8J61NQw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.7.0.tgz", + "integrity": "sha512-ok/BTPFzFKVMwO5eOHRrvnBVHdRy9IrsrW1GpMaQ9MCnilNLXQKmAX8s1YXDFaai9xJpac2ySzV0YeRRECr2Vw==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", - "@jest/types": "^29.5.0", - "@jridgewell/trace-mapping": "^0.3.15", + "@jest/types": "^29.6.3", + "@jridgewell/trace-mapping": "^0.3.18", "babel-plugin-istanbul": "^6.1.1", "chalk": "^4.0.0", "convert-source-map": "^2.0.0", "fast-json-stable-stringify": "^2.1.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", + "jest-haste-map": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", "micromatch": "^4.0.4", "pirates": "^4.0.4", "slash": "^3.0.0", @@ -874,12 +937,12 @@ } }, "node_modules/@jest/types": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.5.0.tgz", - "integrity": "sha512-qbu7kN6czmVRc3xWFQcAN03RAUamgppVUdXrvl1Wr3jlNF93o9mJbGcDWrwGB6ht44u7efB1qCFgVQmca24Uog==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", "dev": true, "dependencies": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", @@ -905,9 +968,9 @@ } }, "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", "dev": true, "engines": { "node": ">=6.0.0" @@ -929,25 +992,19 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.18", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", - "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", + "version": "0.3.20", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz", + "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==", "dev": true, "dependencies": { - "@jridgewell/resolve-uri": "3.1.0", - "@jridgewell/sourcemap-codec": "1.4.14" + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, "node_modules/@sinclair/typebox": { - "version": "0.25.24", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", - "integrity": "sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==", + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", "dev": true }, "node_modules/@sinonjs/commons": { @@ -960,18 +1017,18 @@ } }, "node_modules/@sinonjs/fake-timers": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.2.0.tgz", - "integrity": "sha512-OPwQlEdg40HAj5KNF8WW6q2KG4Z+cBCZb3m4ninfTZKaBmbIJodviQsDBoYMPHkOyJJMHnOJo5j2+LKDOhOACg==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", "dev": true, "dependencies": { "@sinonjs/commons": "^3.0.0" } }, "node_modules/@types/babel__core": { - "version": "7.20.0", - "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", - "integrity": "sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.3.tgz", + "integrity": "sha512-54fjTSeSHwfan8AyHWrKbfBWiEUrNTZsUwPTDSNaaP1QDQIZbeNUg3a59E9D+375MzUw/x1vx2/0F5LBz+AeYA==", "dev": true, "dependencies": { "@babel/parser": "^7.20.7", @@ -982,18 +1039,18 @@ } }, "node_modules/@types/babel__generator": { - "version": "7.6.4", - "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.4.tgz", - "integrity": "sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==", + "version": "7.6.6", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.6.tgz", + "integrity": "sha512-66BXMKb/sUWbMdBNdMvajU7i/44RkrA3z/Yt1c7R5xejt8qh84iU54yUWCtm0QwGJlDcf/gg4zd/x4mpLAlb/w==", "dev": true, "dependencies": { "@babel/types": "^7.0.0" } }, "node_modules/@types/babel__template": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.1.tgz", - "integrity": "sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.3.tgz", + "integrity": "sha512-ciwyCLeuRfxboZ4isgdNZi/tkt06m8Tw6uGbBSBgWrnnZGNXiEyM27xc/PjXGQLqlZ6ylbgHMnm7ccF9tCkOeQ==", "dev": true, "dependencies": { "@babel/parser": "^7.1.0", @@ -1001,78 +1058,75 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.18.5", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.5.tgz", - "integrity": "sha512-enCvTL8m/EHS/zIvJno9nE+ndYPh1/oNFzRYRmtUqJICG2VnCSBzMLW5VN2KCQU91f23tsNKR8v7VJJQMatl7Q==", + "version": "7.20.3", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.3.tgz", + "integrity": "sha512-Lsh766rGEFbaxMIDH7Qa+Yha8cMVI3qAK6CHt3OR0YfxOIn5Z54iHiyDRycHrBqeIiqGa20Kpsv1cavfBKkRSw==", "dev": true, "dependencies": { - "@babel/types": "^7.3.0" + "@babel/types": "^7.20.7" } }, "node_modules/@types/graceful-fs": { - "version": "4.1.6", - "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz", - "integrity": "sha512-Sig0SNORX9fdW+bQuTEovKj3uHcUL6LQKbCrrqb1X7J6/ReAbhCXRAhc+SMejhLELFj2QcyuxmUooZ4bt5ReSw==", + "version": "4.1.8", + "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.8.tgz", + "integrity": "sha512-NhRH7YzWq8WiNKVavKPBmtLYZHxNY19Hh+az28O/phfp68CF45pMFud+ZzJ8ewnxnC5smIdF3dqFeiSUQ5I+pw==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz", + "integrity": "sha512-zONci81DZYCZjiLe0r6equvZut0b+dBRPBN5kBDjsONnutYNtJMoWQ9uR2RkL1gLG9NMTzvf+29e5RFfPbeKhQ==", "dev": true }, "node_modules/@types/istanbul-lib-report": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", - "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.2.tgz", + "integrity": "sha512-8toY6FgdltSdONav1XtUHl4LN1yTmLza+EuDazb/fEmRNCwjyqNVIQWs2IfC74IqjHkREs/nQ2FWq5kZU9IC0w==", "dev": true, "dependencies": { "@types/istanbul-lib-coverage": "*" } }, "node_modules/@types/istanbul-reports": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", - "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.3.tgz", + "integrity": "sha512-1nESsePMBlf0RPRffLZi5ujYh7IH1BWL4y9pr+Bn3cJBdxz+RTP8bUFljLz9HvzhhOSWKdyBZ4DIivdL6rvgZg==", "dev": true, "dependencies": { "@types/istanbul-lib-report": "*" } }, "node_modules/@types/node": { - "version": "20.2.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.1.tgz", - "integrity": "sha512-DqJociPbZP1lbZ5SQPk4oag6W7AyaGMO6gSfRwq3PWl4PXTwJpRQJhDq4W0kzrg3w6tJ1SwlvGZ5uKFHY13LIg==", - "dev": true - }, - "node_modules/@types/prettier": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz", - "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==", - "dev": true + "version": "20.8.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.8.tgz", + "integrity": "sha512-YRsdVxq6OaLfmR9Hy816IMp33xOBjfyOgUd77ehqg96CFywxAPbDbXvAsuN2KVg2HOT8Eh6uAfU+l4WffwPVrQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.25.1" + } }, "node_modules/@types/stack-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", - "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.2.tgz", + "integrity": "sha512-g7CK9nHdwjK2n0ymT2CW698FuWJRIx+RP6embAzZ2Qi8/ilIrA1Imt2LVSeHUzKvpoi7BhmmQcXz95eS0f2JXw==", "dev": true }, "node_modules/@types/yargs": { - "version": "17.0.24", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", - "integrity": "sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==", + "version": "17.0.29", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.29.tgz", + "integrity": "sha512-nacjqA3ee9zRF/++a3FUY1suHTFKZeHba2n8WeDw9cCVdmzmHpIxyzOJBcpHvvEmS8E9KqWlSnWHUkOrkhWcvA==", "dev": true, "dependencies": { "@types/yargs-parser": "*" } }, "node_modules/@types/yargs-parser": { - "version": "21.0.0", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz", - "integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==", + "version": "21.0.2", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.2.tgz", + "integrity": "sha512-5qcvofLPbfjmBfKaLfj/+f+Sbd6pN4zl7w7VSVI5uz7m9QZTuB2aZAa2uo1wHFBNN2x6g/SoTkXmd8mQnQF2Cw==", "dev": true }, "node_modules/ansi-escapes": { @@ -1137,15 +1191,15 @@ } }, "node_modules/babel-jest": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.5.0.tgz", - "integrity": "sha512-mA4eCDh5mSo2EcA9xQjVTpmbbNk32Zb3Q3QFQsNhaK56Q+yoXowzFodLux30HRgyOho5rsQ6B0P9QpMkvvnJ0Q==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", + "integrity": "sha512-BrvGY3xZSwEcCzKvKsCi2GgHqDqsYkOP4/by5xCgIwGXQxIEh+8ew3gmrE1y7XRR6LHZIj6yLYnUi/mm2KXKBg==", "dev": true, "dependencies": { - "@jest/transform": "^29.5.0", + "@jest/transform": "^29.7.0", "@types/babel__core": "^7.1.14", "babel-plugin-istanbul": "^6.1.1", - "babel-preset-jest": "^29.5.0", + "babel-preset-jest": "^29.6.3", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "slash": "^3.0.0" @@ -1173,10 +1227,26 @@ "node": ">=8" } }, + "node_modules/babel-plugin-istanbul/node_modules/istanbul-lib-instrument": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-5.2.1.tgz", + "integrity": "sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==", + "dev": true, + "dependencies": { + "@babel/core": "^7.12.3", + "@babel/parser": "^7.14.7", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.2.0", + "semver": "^6.3.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/babel-plugin-jest-hoist": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-29.5.0.tgz", - "integrity": "sha512-zSuuuAlTMT4mzLj2nPnUm6fsE6270vdOfnpbJ+RmruU75UhLFvL0N2NgI7xpeS7NaB6hGqmd5pVpGTDYvi4Q3w==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-29.6.3.tgz", + "integrity": "sha512-ESAc/RJvGTFEzRwOTT4+lNDk/GNHMkKbNzsvT0qKRfDyyYTskxB5rnU2njIDYVxXCBHHEI1c0YwHob3WaYujOg==", "dev": true, "dependencies": { "@babel/template": "^7.3.3", @@ -1212,12 +1282,12 @@ } }, "node_modules/babel-preset-jest": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-29.5.0.tgz", - "integrity": "sha512-JOMloxOqdiBSxMAzjRaH023/vvcaSaec49zvg+2LmNsktC7ei39LTJGw02J+9uUtTZUq6xbLyJ4dxe9sSmIuAg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-29.6.3.tgz", + "integrity": "sha512-0B3bhxR6snWXJZtR/RliHTDPRgn1sNHOR0yVtq/IiQFyuOVjFS+wuio/R4gSNkyYmKmJB4wGZv2NZanmKmTnNA==", "dev": true, "dependencies": { - "babel-plugin-jest-hoist": "^29.5.0", + "babel-plugin-jest-hoist": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0" }, "engines": { @@ -1256,9 +1326,9 @@ } }, "node_modules/browserslist": { - "version": "4.21.5", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.5.tgz", - "integrity": "sha512-tUkiguQGW7S3IhB7N+c2MV/HZPSCPAAiYBZXLsBhFB/PCy6ZKKsZrmBayHV9fdGV/ARIfJ14NkxKzRDjvp7L6w==", + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.1.tgz", + "integrity": "sha512-FEVc202+2iuClEhZhrWy6ZiAcRLvNMyYcxZ8raemul1DYVOVdFsbqckWLdsixQZCpJlwe77Z3UTalE7jsjnKfQ==", "dev": true, "funding": [ { @@ -1268,13 +1338,17 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ], "dependencies": { - "caniuse-lite": "^1.0.30001449", - "electron-to-chromium": "^1.4.284", - "node-releases": "^2.0.8", - "update-browserslist-db": "^1.0.10" + "caniuse-lite": "^1.0.30001541", + "electron-to-chromium": "^1.4.535", + "node-releases": "^2.0.13", + "update-browserslist-db": "^1.0.13" }, "bin": { "browserslist": "cli.js" @@ -1317,9 +1391,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001488", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001488.tgz", - "integrity": "sha512-NORIQuuL4xGpIy6iCCQGN4iFjlBXtfKWIenlUuyZJumLRIindLb7wXM+GO8erEhb7vXfcnf4BAg2PrSDN5TNLQ==", + "version": "1.0.30001553", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001553.tgz", + "integrity": "sha512-N0ttd6TrFfuqKNi+pMgWJTb9qrdJu4JSpgPFLe/lrD19ugC6fZgF0pUewRowDwzdDnb9V41mFcdlYgl/PyKf4A==", "dev": true, "funding": [ { @@ -1362,9 +1436,9 @@ } }, "node_modules/ci-info": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", - "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", + "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", "dev": true, "funding": [ { @@ -1377,9 +1451,9 @@ } }, "node_modules/cjs-module-lexer": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz", - "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.3.tgz", + "integrity": "sha512-0TNiGstbQmCFwt4akjjBg5pLRTSyj/PkWQ1ZoO2zntmg9yLqSRxwEa4iCfQLGjqhiqBfOJa7W/E8wfGrTDmlZQ==", "dev": true }, "node_modules/cliui": { @@ -1407,9 +1481,9 @@ } }, "node_modules/collect-v8-coverage": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz", - "integrity": "sha512-iBPtljfCNcTKNAto0KEtDfZ3qzjJvqE3aTGZsbhjSBlorqpXJlaWWtPO35D+ZImoC3KWejX64o+yPGxhWSTzfg==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", + "integrity": "sha512-lHl4d5/ONEbLlJvaJNtsF/Lz+WvB07u2ycqTYbdrq7UypDXailES4valYb2eWiJFxZlVmpGekfqoxQhzyFdT4Q==", "dev": true }, "node_modules/color-convert": { @@ -1442,6 +1516,27 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true }, + "node_modules/create-jest": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", + "integrity": "sha512-Adz2bdH0Vq3F53KEMJOoftQFutWCukm6J24wbPWRO4k1kMY7gS7ds/uoJkNuV8wDCtWWnuwGcJwpWcih+zEW1Q==", + "dev": true, + "dependencies": { + "@jest/types": "^29.6.3", + "chalk": "^4.0.0", + "exit": "^0.1.2", + "graceful-fs": "^4.2.9", + "jest-config": "^29.7.0", + "jest-util": "^29.7.0", + "prompts": "^2.0.1" + }, + "bin": { + "create-jest": "bin/create-jest.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -1474,10 +1569,18 @@ } }, "node_modules/dedent": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz", - "integrity": "sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==", - "dev": true + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.5.1.tgz", + "integrity": "sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg==", + "dev": true, + "peerDependencies": { + "babel-plugin-macros": "^3.1.0" + }, + "peerDependenciesMeta": { + "babel-plugin-macros": { + "optional": true + } + } }, "node_modules/deepmerge": { "version": "4.3.1", @@ -1498,18 +1601,18 @@ } }, "node_modules/diff-sequences": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.4.3.tgz", - "integrity": "sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/electron-to-chromium": { - "version": "1.4.399", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.399.tgz", - "integrity": "sha512-+V1aNvVgoWNWYIbMOiQ1n5fRIaY4SlQ/uRlrsCjLrUwr/3OvQgiX2f5vdav4oArVT9TnttJKcPCqjwPNyZqw/A==", + "version": "1.4.565", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.565.tgz", + "integrity": "sha512-XbMoT6yIvg2xzcbs5hCADi0dXBh4//En3oFXmtPX+jiyyiCTiM9DGFT2SLottjpEs9Z8Mh8SqahbR96MaHfuSg==", "dev": true }, "node_modules/emittery": { @@ -1603,16 +1706,16 @@ } }, "node_modules/expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-yM7xqUrCO2JdpFo4XpM82t+PJBFybdqoQuJLDGeDX2ij8NZzqRHyu3Hp188/JX7SWqud+7t4MUdvcgGBICMHZg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", "dev": true, "dependencies": { - "@jest/expect-utils": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0" + "@jest/expect-utils": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -1665,9 +1768,9 @@ "dev": true }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, "optional": true, @@ -1679,10 +1782,13 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/gensync": { "version": "1.0.0-beta.2", @@ -1758,18 +1864,6 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1779,6 +1873,18 @@ "node": ">=8" } }, + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -1845,12 +1951,12 @@ "dev": true }, "node_modules/is-core-module": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", - "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", "dev": true, "dependencies": { - "has": "^1.0.3" + "hasown": "^2.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1911,33 +2017,66 @@ } }, "node_modules/istanbul-lib-instrument": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-5.2.1.tgz", - "integrity": "sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-6.0.1.tgz", + "integrity": "sha512-EAMEJBsYuyyztxMxW3g7ugGPkrZsV57v0Hmv3mm1uQsmB+QnZuepg731CRaIgeUVSdmsTngOkSnauNF8p7FIhA==", "dev": true, "dependencies": { "@babel/core": "^7.12.3", "@babel/parser": "^7.14.7", "@istanbuljs/schema": "^0.1.2", "istanbul-lib-coverage": "^3.2.0", - "semver": "^6.3.0" + "semver": "^7.5.4" }, "engines": { - "node": ">=8" + "node": ">=10" + } + }, + "node_modules/istanbul-lib-instrument/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" } }, + "node_modules/istanbul-lib-instrument/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-lib-instrument/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/istanbul-lib-report": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", - "integrity": "sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", "dev": true, "dependencies": { "istanbul-lib-coverage": "^3.0.0", - "make-dir": "^3.0.0", + "make-dir": "^4.0.0", "supports-color": "^7.1.0" }, "engines": { - "node": ">=8" + "node": ">=10" } }, "node_modules/istanbul-lib-source-maps": { @@ -1955,9 +2094,9 @@ } }, "node_modules/istanbul-reports": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.5.tgz", - "integrity": "sha512-nUsEMa9pBt/NOHqbcbeJEgqIlY/K7rVWUX6Lql2orY5e9roQOthbR3vtY4zzf2orPELg80fnxxk9zUyPlgwD1w==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.6.tgz", + "integrity": "sha512-TLgnMkKg3iTDsQ9PbPTdpfAK2DzjF9mqUG7RMgcQl8oFjad8ob4laGxv5XV5U9MAfx8D6tSJiUyuAwzLicaxlg==", "dev": true, "dependencies": { "html-escaper": "^2.0.0", @@ -1968,15 +2107,15 @@ } }, "node_modules/jest": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest/-/jest-29.5.0.tgz", - "integrity": "sha512-juMg3he2uru1QoXX078zTa7pO85QyB9xajZc6bU+d9yEGwrKX6+vGmJQ3UdVZsvTEUARIdObzH68QItim6OSSQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", + "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, "dependencies": { - "@jest/core": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/core": "^29.7.0", + "@jest/types": "^29.6.3", "import-local": "^3.0.2", - "jest-cli": "^29.5.0" + "jest-cli": "^29.7.0" }, "bin": { "jest": "bin/jest.js" @@ -1994,12 +2133,13 @@ } }, "node_modules/jest-changed-files": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-29.5.0.tgz", - "integrity": "sha512-IFG34IUMUaNBIxjQXF/iu7g6EcdMrGRRxaUSw92I/2g2YC6vCdTltl4nHvt7Ci5nSJwXIkCu8Ka1DKF+X7Z1Ag==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-29.7.0.tgz", + "integrity": "sha512-fEArFiwf1BpQ+4bXSprcDc3/x4HSzL4al2tozwVpDFpsxALjLYdyiIK4e5Vz66GQJIbXJ82+35PtysofptNX2w==", "dev": true, "dependencies": { "execa": "^5.0.0", + "jest-util": "^29.7.0", "p-limit": "^3.1.0" }, "engines": { @@ -2007,28 +2147,28 @@ } }, "node_modules/jest-circus": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-29.5.0.tgz", - "integrity": "sha512-gq/ongqeQKAplVxqJmbeUOJJKkW3dDNPY8PjhJ5G0lBRvu0e3EWGxGy5cI4LAGA7gV2UHCtWBI4EMXK8c9nQKA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-circus/-/jest-circus-29.7.0.tgz", + "integrity": "sha512-3E1nCMgipcTkCocFwM90XXQab9bS+GMsjdpmPrlelaxwD93Ad8iVEjX/vvHPdLPnFf+L40u+5+iutRdA1N9myw==", "dev": true, "dependencies": { - "@jest/environment": "^29.5.0", - "@jest/expect": "^29.5.0", - "@jest/test-result": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/environment": "^29.7.0", + "@jest/expect": "^29.7.0", + "@jest/test-result": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "co": "^4.6.0", - "dedent": "^0.7.0", + "dedent": "^1.0.0", "is-generator-fn": "^2.0.0", - "jest-each": "^29.5.0", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-runtime": "^29.5.0", - "jest-snapshot": "^29.5.0", - "jest-util": "^29.5.0", + "jest-each": "^29.7.0", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-runtime": "^29.7.0", + "jest-snapshot": "^29.7.0", + "jest-util": "^29.7.0", "p-limit": "^3.1.0", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "pure-rand": "^6.0.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" @@ -2038,22 +2178,21 @@ } }, "node_modules/jest-cli": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.5.0.tgz", - "integrity": "sha512-L1KcP1l4HtfwdxXNFCL5bmUbLQiKrakMUriBEcc1Vfz6gx31ORKdreuWvmQVBit+1ss9NNR3yxjwfwzZNdQXJw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-29.7.0.tgz", + "integrity": "sha512-OVVobw2IubN/GSYsxETi+gOe7Ka59EFMR/twOU3Jb2GnKKeMGJB5SGUUrEz3SFVmJASUdZUzy83sLNNQ2gZslg==", "dev": true, "dependencies": { - "@jest/core": "^29.5.0", - "@jest/test-result": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/core": "^29.7.0", + "@jest/test-result": "^29.7.0", + "@jest/types": "^29.6.3", "chalk": "^4.0.0", + "create-jest": "^29.7.0", "exit": "^0.1.2", - "graceful-fs": "^4.2.9", "import-local": "^3.0.2", - "jest-config": "^29.5.0", - "jest-util": "^29.5.0", - "jest-validate": "^29.5.0", - "prompts": "^2.0.1", + "jest-config": "^29.7.0", + "jest-util": "^29.7.0", + "jest-validate": "^29.7.0", "yargs": "^17.3.1" }, "bin": { @@ -2072,31 +2211,31 @@ } }, "node_modules/jest-config": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-29.5.0.tgz", - "integrity": "sha512-kvDUKBnNJPNBmFFOhDbm59iu1Fii1Q6SxyhXfvylq3UTHbg6o7j/g8k2dZyXWLvfdKB1vAPxNZnMgtKJcmu3kA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-29.7.0.tgz", + "integrity": "sha512-uXbpfeQ7R6TZBqI3/TxCU4q4ttk3u0PJeC+E0zbfSoSjq6bJ7buBPxzQPL0ifrkY4DNu4JUdk0ImlBUYi840eQ==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", - "@jest/test-sequencer": "^29.5.0", - "@jest/types": "^29.5.0", - "babel-jest": "^29.5.0", + "@jest/test-sequencer": "^29.7.0", + "@jest/types": "^29.6.3", + "babel-jest": "^29.7.0", "chalk": "^4.0.0", "ci-info": "^3.2.0", "deepmerge": "^4.2.2", "glob": "^7.1.3", "graceful-fs": "^4.2.9", - "jest-circus": "^29.5.0", - "jest-environment-node": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.5.0", - "jest-runner": "^29.5.0", - "jest-util": "^29.5.0", - "jest-validate": "^29.5.0", + "jest-circus": "^29.7.0", + "jest-environment-node": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.7.0", + "jest-runner": "^29.7.0", + "jest-util": "^29.7.0", + "jest-validate": "^29.7.0", "micromatch": "^4.0.4", "parse-json": "^5.2.0", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "slash": "^3.0.0", "strip-json-comments": "^3.1.1" }, @@ -2117,24 +2256,24 @@ } }, "node_modules/jest-diff": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.5.0.tgz", - "integrity": "sha512-LtxijLLZBduXnHSniy0WMdaHjmQnt3g5sa16W4p0HqukYTTsyTW3GD1q41TyGl5YFXj/5B2U6dlh5FM1LIMgxw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", + "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==", "dev": true, "dependencies": { "chalk": "^4.0.0", - "diff-sequences": "^29.4.3", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "diff-sequences": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-docblock": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-29.4.3.tgz", - "integrity": "sha512-fzdTftThczeSD9nZ3fzA/4KkHtnmllawWrXO69vtI+L9WjEIuXWs4AmyME7lN5hU7dB0sHhuPfcKofRsUb/2Fg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-29.7.0.tgz", + "integrity": "sha512-q617Auw3A612guyaFgsbFeYpNP5t2aoUNLwBUbc/0kD1R4t9ixDbyFTHd1nok4epoVFpr7PmeWHrhvuV3XaJ4g==", "dev": true, "dependencies": { "detect-newline": "^3.0.0" @@ -2144,62 +2283,62 @@ } }, "node_modules/jest-each": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-29.5.0.tgz", - "integrity": "sha512-HM5kIJ1BTnVt+DQZ2ALp3rzXEl+g726csObrW/jpEGl+CDSSQpOJJX2KE/vEg8cxcMXdyEPu6U4QX5eruQv5hA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-29.7.0.tgz", + "integrity": "sha512-gns+Er14+ZrEoC5fhOfYCY1LOHHr0TI+rQUHZS8Ttw2l7gl+80eHc/gFf2Ktkw0+SIACDTeWvpFcv3B04VembQ==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "chalk": "^4.0.0", - "jest-get-type": "^29.4.3", - "jest-util": "^29.5.0", - "pretty-format": "^29.5.0" + "jest-get-type": "^29.6.3", + "jest-util": "^29.7.0", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-environment-node": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.5.0.tgz", - "integrity": "sha512-ExxuIK/+yQ+6PRGaHkKewYtg6hto2uGCgvKdb2nfJfKXgZ17DfXjvbZ+jA1Qt9A8EQSfPnt5FKIfnOO3u1h9qw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.7.0.tgz", + "integrity": "sha512-DOSwCRqXirTOyheM+4d5YZOrWcdu0LNZ87ewUoywbcb2XR4wKgqiG8vNeYwhjFMbEkfju7wx2GYH0P2gevGvFw==", "dev": true, "dependencies": { - "@jest/environment": "^29.5.0", - "@jest/fake-timers": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/environment": "^29.7.0", + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.5.0", - "jest-util": "^29.5.0" + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-get-type": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz", - "integrity": "sha512-J5Xez4nRRMjk8emnTpWrlkyb9pfRQQanDrvWHhsR1+VUfbwxi30eVcZFlcdGInRibU4G5LwHXpI7IRHU0CY+gg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-haste-map": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.5.0.tgz", - "integrity": "sha512-IspOPnnBro8YfVYSw6yDRKh/TiCdRngjxeacCps1cQ9cgVN6+10JUcuJ1EabrgYLOATsIAigxA0rLR9x/YlrSA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", + "integrity": "sha512-fP8u2pyfqx0K1rGn1R9pyE0/KTn+G7PxktWidOBTqFPLYX0b9ksaMFkhK5vrS3DVun09pckLdlx90QthlW7AmA==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/graceful-fs": "^4.1.3", "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", "graceful-fs": "^4.2.9", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", - "jest-worker": "^29.5.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", "micromatch": "^4.0.4", "walker": "^1.0.8" }, @@ -2211,46 +2350,46 @@ } }, "node_modules/jest-leak-detector": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.5.0.tgz", - "integrity": "sha512-u9YdeeVnghBUtpN5mVxjID7KbkKE1QU4f6uUwuxiY0vYRi9BUCLKlPEZfDGR67ofdFmDz9oPAy2G92Ujrntmow==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz", + "integrity": "sha512-kYA8IJcSYtST2BY9I+SMC32nDpBT3J2NvWJx8+JCuCdl/CR1I4EKUJROiP8XtCcxqgTTBGJNdbB1A8XRKbTetw==", "dev": true, "dependencies": { - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-matcher-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.5.0.tgz", - "integrity": "sha512-lecRtgm/rjIK0CQ7LPQwzCs2VwW6WAahA55YBuI+xqmhm7LAaxokSB8C97yJeYyT+HvQkH741StzpU41wohhWw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", + "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", "dev": true, "dependencies": { "chalk": "^4.0.0", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-message-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.5.0.tgz", - "integrity": "sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", + "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", "dev": true, "dependencies": { "@babel/code-frame": "^7.12.13", - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/stack-utils": "^2.0.0", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "micromatch": "^4.0.4", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" }, @@ -2259,14 +2398,14 @@ } }, "node_modules/jest-mock": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.5.0.tgz", - "integrity": "sha512-GqOzvdWDE4fAV2bWQLQCkujxYWL7RxjCnj71b5VhDAGOevB3qj3Ovg26A5NI84ZpODxyzaozXLOh2NCgkbvyaw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", + "integrity": "sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-util": "^29.5.0" + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -2290,26 +2429,26 @@ } }, "node_modules/jest-regex-util": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.4.3.tgz", - "integrity": "sha512-O4FglZaMmWXbGHSQInfXewIsd1LMn9p3ZXB/6r4FOkyhX2/iP/soMG98jGvk/A3HAN78+5VWcBGO0BJAPRh4kg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", "dev": true, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-resolve": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-29.5.0.tgz", - "integrity": "sha512-1TzxJ37FQq7J10jPtQjcc+MkCkE3GBpBecsSUWJ0qZNJpmg6m0D9/7II03yJulm3H/fvVjgqLh/k2eYg+ui52w==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-29.7.0.tgz", + "integrity": "sha512-IOVhZSrg+UvVAshDSDtHyFCCBUl/Q3AAJv8iZ6ZjnZ74xzvwuzLXid9IIIPgTnY62SJjfuupMKZsZQRsCvxEgA==", "dev": true, "dependencies": { "chalk": "^4.0.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", + "jest-haste-map": "^29.7.0", "jest-pnp-resolver": "^1.2.2", - "jest-util": "^29.5.0", - "jest-validate": "^29.5.0", + "jest-util": "^29.7.0", + "jest-validate": "^29.7.0", "resolve": "^1.20.0", "resolve.exports": "^2.0.0", "slash": "^3.0.0" @@ -2319,43 +2458,43 @@ } }, "node_modules/jest-resolve-dependencies": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-29.5.0.tgz", - "integrity": "sha512-sjV3GFr0hDJMBpYeUuGduP+YeCRbd7S/ck6IvL3kQ9cpySYKqcqhdLLC2rFwrcL7tz5vYibomBrsFYWkIGGjOg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-29.7.0.tgz", + "integrity": "sha512-un0zD/6qxJ+S0et7WxeI3H5XSe9lTBBR7bOHCHXkKR6luG5mwDDlIzVQ0V5cZCuoTgEdcdwzTghYkTWfubi+nA==", "dev": true, "dependencies": { - "jest-regex-util": "^29.4.3", - "jest-snapshot": "^29.5.0" + "jest-regex-util": "^29.6.3", + "jest-snapshot": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-runner": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-29.5.0.tgz", - "integrity": "sha512-m7b6ypERhFghJsslMLhydaXBiLf7+jXy8FwGRHO3BGV1mcQpPbwiqiKUR2zU2NJuNeMenJmlFZCsIqzJCTeGLQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-29.7.0.tgz", + "integrity": "sha512-fsc4N6cPCAahybGBfTRcq5wFR6fpLznMg47sY5aDpsoejOcVYFb07AHuSnR0liMcPTgBsA3ZJL6kFOjPdoNipQ==", "dev": true, "dependencies": { - "@jest/console": "^29.5.0", - "@jest/environment": "^29.5.0", - "@jest/test-result": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/console": "^29.7.0", + "@jest/environment": "^29.7.0", + "@jest/test-result": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "emittery": "^0.13.1", "graceful-fs": "^4.2.9", - "jest-docblock": "^29.4.3", - "jest-environment-node": "^29.5.0", - "jest-haste-map": "^29.5.0", - "jest-leak-detector": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-resolve": "^29.5.0", - "jest-runtime": "^29.5.0", - "jest-util": "^29.5.0", - "jest-watcher": "^29.5.0", - "jest-worker": "^29.5.0", + "jest-docblock": "^29.7.0", + "jest-environment-node": "^29.7.0", + "jest-haste-map": "^29.7.0", + "jest-leak-detector": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-resolve": "^29.7.0", + "jest-runtime": "^29.7.0", + "jest-util": "^29.7.0", + "jest-watcher": "^29.7.0", + "jest-worker": "^29.7.0", "p-limit": "^3.1.0", "source-map-support": "0.5.13" }, @@ -2364,31 +2503,31 @@ } }, "node_modules/jest-runtime": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.5.0.tgz", - "integrity": "sha512-1Hr6Hh7bAgXQP+pln3homOiEZtCDZFqwmle7Ew2j8OlbkIu6uE3Y/etJQG8MLQs3Zy90xrp2C0BRrtPHG4zryw==", - "dev": true, - "dependencies": { - "@jest/environment": "^29.5.0", - "@jest/fake-timers": "^29.5.0", - "@jest/globals": "^29.5.0", - "@jest/source-map": "^29.4.3", - "@jest/test-result": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.7.0.tgz", + "integrity": "sha512-gUnLjgwdGqW7B4LvOIkbKs9WGbn+QLqRQQ9juC6HndeDiezIwhDP+mhMwHWCEcfQ5RUXa6OPnFF8BJh5xegwwQ==", + "dev": true, + "dependencies": { + "@jest/environment": "^29.7.0", + "@jest/fake-timers": "^29.7.0", + "@jest/globals": "^29.7.0", + "@jest/source-map": "^29.6.3", + "@jest/test-result": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "cjs-module-lexer": "^1.0.0", "collect-v8-coverage": "^1.0.0", "glob": "^7.1.3", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-mock": "^29.5.0", - "jest-regex-util": "^29.4.3", - "jest-resolve": "^29.5.0", - "jest-snapshot": "^29.5.0", - "jest-util": "^29.5.0", + "jest-haste-map": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-mock": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-resolve": "^29.7.0", + "jest-snapshot": "^29.7.0", + "jest-util": "^29.7.0", "slash": "^3.0.0", "strip-bom": "^4.0.0" }, @@ -2397,34 +2536,31 @@ } }, "node_modules/jest-snapshot": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.5.0.tgz", - "integrity": "sha512-x7Wolra5V0tt3wRs3/ts3S6ciSQVypgGQlJpz2rsdQYoUKxMxPNaoHMGJN6qAuPJqS+2iQ1ZUn5kl7HCyls84g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.7.0.tgz", + "integrity": "sha512-Rm0BMWtxBcioHr1/OX5YCP8Uov4riHvKPknOGs804Zg9JGZgmIBkbtlxJC/7Z4msKYVbIJtfU+tKb8xlYNfdkw==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", "@babel/generator": "^7.7.2", "@babel/plugin-syntax-jsx": "^7.7.2", "@babel/plugin-syntax-typescript": "^7.7.2", - "@babel/traverse": "^7.7.2", "@babel/types": "^7.3.3", - "@jest/expect-utils": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", - "@types/babel__traverse": "^7.0.6", - "@types/prettier": "^2.1.5", + "@jest/expect-utils": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0", "chalk": "^4.0.0", - "expect": "^29.5.0", + "expect": "^29.7.0", "graceful-fs": "^4.2.9", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0", + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0", "natural-compare": "^1.4.0", - "pretty-format": "^29.5.0", - "semver": "^7.3.5" + "pretty-format": "^29.7.0", + "semver": "^7.5.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -2443,9 +2579,9 @@ } }, "node_modules/jest-snapshot/node_modules/semver": { - "version": "7.5.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.1.tgz", - "integrity": "sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -2464,12 +2600,12 @@ "dev": true }, "node_modules/jest-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.5.0.tgz", - "integrity": "sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", + "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "ci-info": "^3.2.0", @@ -2481,17 +2617,17 @@ } }, "node_modules/jest-validate": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.5.0.tgz", - "integrity": "sha512-pC26etNIi+y3HV8A+tUGr/lph9B18GnzSRAkPaaZJIE1eFdiYm6/CewuiJQ8/RlfHd1u/8Ioi8/sJ+CmbA+zAQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", + "integrity": "sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==", "dev": true, "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "camelcase": "^6.2.0", "chalk": "^4.0.0", - "jest-get-type": "^29.4.3", + "jest-get-type": "^29.6.3", "leven": "^3.1.0", - "pretty-format": "^29.5.0" + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -2510,18 +2646,18 @@ } }, "node_modules/jest-watcher": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-29.5.0.tgz", - "integrity": "sha512-KmTojKcapuqYrKDpRwfqcQ3zjMlwu27SYext9pt4GlF5FUgB+7XE1mcCnSm6a4uUpFyQIkb6ZhzZvHl+jiBCiA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-watcher/-/jest-watcher-29.7.0.tgz", + "integrity": "sha512-49Fg7WXkU3Vl2h6LbLtMQ/HyB6rXSIX7SqvBLQmssRBGN9I0PNvPmAmCWSOY6SOvrjhI/F7/bGAv9RtnsPA03g==", "dev": true, "dependencies": { - "@jest/test-result": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/test-result": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", "ansi-escapes": "^4.2.1", "chalk": "^4.0.0", "emittery": "^0.13.1", - "jest-util": "^29.5.0", + "jest-util": "^29.7.0", "string-length": "^4.0.1" }, "engines": { @@ -2529,13 +2665,13 @@ } }, "node_modules/jest-worker": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.5.0.tgz", - "integrity": "sha512-NcrQnevGoSp4b5kg+akIpthoAFHxPBcb5P6mYPY0fUNT+sSvmtu6jlkEle3anczUKIKEbMxFimk9oTP/tpIPgA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", + "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", "dev": true, "dependencies": { "@types/node": "*", - "jest-util": "^29.5.0", + "jest-util": "^29.7.0", "merge-stream": "^2.0.0", "supports-color": "^8.0.0" }, @@ -2653,20 +2789,53 @@ } }, "node_modules/make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", "dev": true, "dependencies": { - "semver": "^6.0.0" + "semver": "^7.5.3" }, "engines": { - "node": ">=8" + "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-dir/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/make-dir/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -2740,9 +2909,9 @@ "dev": true }, "node_modules/node-releases": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", - "integrity": "sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==", + "version": "2.0.13", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz", + "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==", "dev": true }, "node_modules/normalize-path": { @@ -2911,9 +3080,9 @@ } }, "node_modules/pirates": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.5.tgz", - "integrity": "sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==", + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", + "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", "dev": true, "engines": { "node": ">= 6" @@ -2932,12 +3101,12 @@ } }, "node_modules/pretty-format": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.5.0.tgz", - "integrity": "sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", "dev": true, "dependencies": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", "react-is": "^18.0.0" }, @@ -2971,9 +3140,9 @@ } }, "node_modules/pure-rand": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.0.2.tgz", - "integrity": "sha512-6Yg0ekpKICSjPswYOuC5sku/TSWaRYlA0qsXqJgM/d/4pLPHPuTxK7Nbf7jFKzAeedUhR8C7K9Uv63FBsSo8xQ==", + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.0.4.tgz", + "integrity": "sha512-LA0Y9kxMYv47GIPJy6MI84fqTd2HmYZI83W/kM/SkKfDlajnZYfmXFTxkbY+xSBPkLJxltMa9hIkmdc29eguMA==", "dev": true, "funding": [ { @@ -3002,12 +3171,12 @@ } }, "node_modules/resolve": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", - "integrity": "sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==", + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dev": true, "dependencies": { - "is-core-module": "^2.11.0", + "is-core-module": "^2.13.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, @@ -3049,9 +3218,9 @@ } }, "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -3291,10 +3460,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "dev": true + }, "node_modules/update-browserslist-db": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz", - "integrity": "sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==", + "version": "1.0.13", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", + "integrity": "sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==", "dev": true, "funding": [ { @@ -3322,25 +3497,19 @@ } }, "node_modules/v8-to-istanbul": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.0.tgz", - "integrity": "sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==", + "version": "9.1.3", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz", + "integrity": "sha512-9lDD+EVI2fjFsMWXc6dy5JJzBsVTcQ2fVkfBvncZ6xJWG9wtBhOldG+mHkSL0+V1K/xgZz0JDO5UT5hFwHUghg==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.12", "@types/istanbul-lib-coverage": "^2.0.1", - "convert-source-map": "^1.6.0" + "convert-source-map": "^2.0.0" }, "engines": { "node": ">=10.12.0" } }, - "node_modules/v8-to-istanbul/node_modules/convert-source-map": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", - "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true - }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", diff --git a/clients/python/grand_mesa_10m_worldcover.json b/clients/python/grand_mesa_10m_worldcover.json deleted file mode 100644 index c18387703..000000000 --- a/clients/python/grand_mesa_10m_worldcover.json +++ /dev/null @@ -1,301 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2020_AWS_V1:ESA_WorldCover_10m_2020_v100_N36W108", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -108, - 39 - ], - [ - -108, - 36 - ], - [ - -105, - 36 - ], - [ - -105, - 39 - ], - [ - -108, - 39 - ] - ] - ] - }, - "properties": { - "datetime": "2020-12-31T23:59:59Z", - "start_datetime": "2020-01-01T00:00:00Z", - "end_datetime": "2020-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v100/2020/map/ESA_WorldCover_10m_2020_v100_N36W108_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2020_AWS_V1:ESA_WorldCover_10m_2020_v100_N36W111", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -111, - 39 - ], - [ - -111, - 36 - ], - [ - -108, - 36 - ], - [ - -108, - 39 - ], - [ - -111, - 39 - ] - ] - ] - }, - "properties": { - "datetime": "2020-12-31T23:59:59Z", - "start_datetime": "2020-01-01T00:00:00Z", - "end_datetime": "2020-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v100/2020/map/ESA_WorldCover_10m_2020_v100_N36W111_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2020_AWS_V1:ESA_WorldCover_10m_2020_v100_N39W108", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -108, - 42 - ], - [ - -108, - 39 - ], - [ - -105, - 39 - ], - [ - -105, - 42 - ], - [ - -108, - 42 - ] - ] - ] - }, - "properties": { - "datetime": "2020-12-31T23:59:59Z", - "start_datetime": "2020-01-01T00:00:00Z", - "end_datetime": "2020-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v100/2020/map/ESA_WorldCover_10m_2020_v100_N39W108_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2020_AWS_V1:ESA_WorldCover_10m_2020_v100_N39W111", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -111, - 42 - ], - [ - -111, - 39 - ], - [ - -108, - 39 - ], - [ - -108, - 42 - ], - [ - -111, - 42 - ] - ] - ] - }, - "properties": { - "datetime": "2020-12-31T23:59:59Z", - "start_datetime": "2020-01-01T00:00:00Z", - "end_datetime": "2020-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v100/2020/map/ESA_WorldCover_10m_2020_v100_N39W111_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2021_AWS_V2:ESA_WorldCover_10m_2021_v200_N36W108", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -108, - 39 - ], - [ - -108, - 36 - ], - [ - -105, - 36 - ], - [ - -105, - 39 - ], - [ - -108, - 39 - ] - ] - ] - }, - "properties": { - "datetime": "2021-12-31T23:59:59Z", - "start_datetime": "2021-01-01T00:00:00Z", - "end_datetime": "2021-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v200/2021/map/ESA_WorldCover_10m_2021_v200_N36W108_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2021_AWS_V2:ESA_WorldCover_10m_2021_v200_N36W111", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -111, - 39 - ], - [ - -111, - 36 - ], - [ - -108, - 36 - ], - [ - -108, - 39 - ], - [ - -111, - 39 - ] - ] - ] - }, - "properties": { - "datetime": "2021-12-31T23:59:59Z", - "start_datetime": "2021-01-01T00:00:00Z", - "end_datetime": "2021-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v200/2021/map/ESA_WorldCover_10m_2021_v200_N36W111_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2021_AWS_V2:ESA_WorldCover_10m_2021_v200_N39W108", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -108, - 42 - ], - [ - -108, - 39 - ], - [ - -105, - 39 - ], - [ - -105, - 42 - ], - [ - -108, - 42 - ] - ] - ] - }, - "properties": { - "datetime": "2021-12-31T23:59:59Z", - "start_datetime": "2021-01-01T00:00:00Z", - "end_datetime": "2021-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v200/2021/map/ESA_WorldCover_10m_2021_v200_N39W108_Map.tif" - } - }, - { - "type": "Feature", - "id": "urn:eop:VITO:ESA_WorldCover_10m_2021_AWS_V2:ESA_WorldCover_10m_2021_v200_N39W111", - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - -111, - 42 - ], - [ - -111, - 39 - ], - [ - -108, - 39 - ], - [ - -108, - 42 - ], - [ - -111, - 42 - ] - ] - ] - }, - "properties": { - "datetime": "2021-12-31T23:59:59Z", - "start_datetime": "2021-01-01T00:00:00Z", - "end_datetime": "2021-12-31T23:59:59Z", - "url": "s3://esa-worldcover/v200/2021/map/ESA_WorldCover_10m_2021_v200_N39W111_Map.tif" - } - } - ] -} \ No newline at end of file diff --git a/clients/python/tests/conftest.py b/clients/python/tests/conftest.py index 1ba8b966c..3be7462c3 100644 --- a/clients/python/tests/conftest.py +++ b/clients/python/tests/conftest.py @@ -8,6 +8,7 @@ def pytest_addoption(parser): parser.addoption("--domain", action="store", default="slideruleearth.io") parser.addoption("--organization", action="store", default="sliderule") parser.addoption("--desired_nodes", action="store", default=None) + parser.addoption("--performance", action="store_true", default=False) @pytest.fixture(scope='session') def domain(request): @@ -36,3 +37,7 @@ def desired_nodes(request): @pytest.fixture(scope='function') def init(domain, organization, desired_nodes): return sliderule.init(domain, verbose=True, loglevel=logging.DEBUG, organization=organization, desired_nodes=desired_nodes, bypass_dns=True) + +@pytest.fixture(scope='session') +def performance(request): + return request.config.option.performance diff --git a/clients/python/tests/test_icesat2.py b/clients/python/tests/test_icesat2.py index f77bd1ca0..147b9753b 100644 --- a/clients/python/tests/test_icesat2.py +++ b/clients/python/tests/test_icesat2.py @@ -9,7 +9,7 @@ @pytest.mark.network class TestAlgorithm: - def test_atl06(self, init): + def test_atl06(self, init, performance): resource = "ATL03_20181019065445_03150111_005_01.h5" parms = { "cnf": "atl03_high", "ats": 20.0, @@ -20,12 +20,12 @@ def test_atl06(self, init): perf_start = time.perf_counter() gdf = icesat2.atl06(parms, resource) assert init - assert (time.perf_counter() - perf_start) < 50 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["h_mean"]) == 622419 + assert not performance or (time.perf_counter() - perf_start) < 50 - def test_atl06p(self, init): + def test_atl06p(self, init, performance): resource = "ATL03_20181019065445_03150111_005_01.h5" parms = { "cnf": "atl03_high", "ats": 20.0, @@ -36,12 +36,12 @@ def test_atl06p(self, init): perf_start = time.perf_counter() gdf = icesat2.atl06p(parms, resources=[resource]) assert init - assert (time.perf_counter() - perf_start) < 50 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["h_mean"]) == 622419 + assert not performance or (time.perf_counter() - perf_start) < 50 - def test_atl03s(self, init): + def test_atl03s(self, init, performance): resource = "ATL03_20181019065445_03150111_005_01.h5" region = [ { "lat": -80.75, "lon": -70.00 }, { "lat": -81.00, "lon": -70.00 }, @@ -62,12 +62,12 @@ def test_atl03s(self, init): perf_start = time.perf_counter() gdf = icesat2.atl03s(parms, resource) assert init - assert (time.perf_counter() - perf_start) < 40 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 488690 + assert not performance or (time.perf_counter() - perf_start) < 40 - def test_atl03sp(self, init): + def test_atl03sp(self, init, performance): resource = "ATL03_20181019065445_03150111_005_01.h5" region = [ { "lat": -80.75, "lon": -70.00 }, { "lat": -81.00, "lon": -70.00 }, @@ -88,12 +88,12 @@ def test_atl03sp(self, init): perf_start = time.perf_counter() gdf = icesat2.atl03sp(parms, resources=[resource]) assert init - assert (time.perf_counter() - perf_start) < 40 assert min(gdf["rgt"]) == 315 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 488690 + assert not performance or (time.perf_counter() - perf_start) < 40 - def test_atl08(self, init): + def test_atl08(self, init, performance): resource = "ATL03_20181213075606_11560106_005_01.h5" track = 1 region = [ {"lon": -108.3435200747503, "lat": 38.89102961045247}, @@ -114,7 +114,6 @@ def test_atl08(self, init): perf_start = time.perf_counter() gdf = icesat2.atl03s(parms, resource) assert init - assert (time.perf_counter() - perf_start) < 30 assert min(gdf["rgt"]) == 1156 assert min(gdf["cycle"]) == 1 assert len(gdf["height"]) == 241127 @@ -123,6 +122,7 @@ def test_atl08(self, init): assert len(gdf[gdf["atl08_class"] == 2]) == 54292 assert len(gdf[gdf["atl08_class"] == 3]) == 18285 assert len(gdf[gdf["atl08_class"] == 4]) == 15978 + assert not performance or (time.perf_counter() - perf_start) < 30 def test_gs(self, init): resource_prefix = "20210114170723_03311012_005_01.h5" diff --git a/clients/python/tests/test_landsat.py b/clients/python/tests/test_landsat.py index 3cff2acfb..39305c060 100644 --- a/clients/python/tests/test_landsat.py +++ b/clients/python/tests/test_landsat.py @@ -57,7 +57,10 @@ def test_subset167(self, init): {"lon": -177.0000000001, "lat": 51.0000000001} ] catalog = earthdata.stac(short_name="HLS", polygon=polygon, time_start=time_start, time_end=time_end, as_str=True) rqst = {"samples": {"asset": "landsat-hls", "catalog": catalog, "bands": ["VAA", "VZA", "Fmask","SAA", "SZA", "NDSI", "NDVI", "NDWI","B01", "B02", "B03", "B04", "B05", "B06","B07", "B08", "B09", "B10", "B11", "B12", "B8A"]}, "extents": [[-179.87, 50.45, -178.27, 51.44]]} + default_request_timeout = sliderule.request_timeout + sliderule.set_rqst_timeout((10,600)) rsps = sliderule.source("subsets", rqst) + sliderule.set_rqst_timeout(default_request_timeout) subsets = rsps['subsets'][0] assert init assert len(subsets) == 167 diff --git a/clients/python/tests/test_meritdem.py b/clients/python/tests/test_meritdem.py index fba336458..8bb5721b4 100644 --- a/clients/python/tests/test_meritdem.py +++ b/clients/python/tests/test_meritdem.py @@ -8,7 +8,10 @@ @pytest.mark.network class TestMerit: def test_sample(self, init): + default_request_timeout = sliderule.request_timeout + sliderule.set_rqst_timeout((10,600)) gdf = raster.sample("merit-dem", [[-172, 51.7], [-172, 51.71], [-172, 51.72], [-172, 51.73], [-172, 51.74]]) + sliderule.set_rqst_timeout(default_request_timeout) assert init assert gdf["value"][0] == -99990000 assert len(gdf) == 5 diff --git a/docs/rtd/source/conf.py b/docs/rtd/source/conf.py index 91e66abe5..8f0700795 100644 --- a/docs/rtd/source/conf.py +++ b/docs/rtd/source/conf.py @@ -108,6 +108,8 @@ "/", ) ], + "build_id": f' {release}', + "build_url": "https://github.com/ICESat2-SlideRule/sliderule/releases/tag/v4.0.1" } # Load the custom CSS files (needs sphinx >= 1.6 for this to work) diff --git a/docs/rtd/source/release_notes/release-v4.0.0.md b/docs/rtd/source/release_notes/release-v4.0.0.md index e8922b96a..eacaa970f 100644 --- a/docs/rtd/source/release_notes/release-v4.0.0.md +++ b/docs/rtd/source/release_notes/release-v4.0.0.md @@ -122,10 +122,6 @@ parms = { "poly": region['poly'], [https://github.com/ICESat2-SlideRule/sliderule/releases/tag/v4.0.0](https://github.com/ICESat2-SlideRule/sliderule/releases/tag/v4.0.0) -[https://github.com/ICESat2-SlideRule/sliderule-icesat2/releases/tag/v4.0.0](https://github.com/ICESat2-SlideRule/sliderule-icesat2/releases/tag/v4.0.0) - -[https://github.com/ICESat2-SlideRule/sliderule-python/releases/tag/v4.0.0](https://github.com/ICESat2-SlideRule/sliderule-python/releases/tag/v4.0.0) - ## Benchmarks ``` diff --git a/packages/arrow/ArrowParms.cpp b/packages/arrow/ArrowParms.cpp index a1a120eb3..51f565f62 100644 --- a/packages/arrow/ArrowParms.cpp +++ b/packages/arrow/ArrowParms.cpp @@ -51,8 +51,8 @@ const char* ArrowParms::REGION = "region"; const char* ArrowParms::CREDENTIALS = "credentials"; const char* ArrowParms::OBJECT_TYPE = "ArrowParms"; -const char* ArrowParms::LuaMetaName = "ArrowParms"; -const struct luaL_Reg ArrowParms::LuaMetaTable[] = { +const char* ArrowParms::LUA_META_NAME = "ArrowParms"; +const struct luaL_Reg ArrowParms::LUA_META_TABLE[] = { {"isnative", luaIsNative}, {"isfeather", luaIsFeather}, {"isparquet", luaIsParquet}, @@ -83,7 +83,7 @@ int ArrowParms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -92,7 +92,7 @@ int ArrowParms::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ ArrowParms::ArrowParms (lua_State* L, int index): - LuaObject (L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject (L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), path (NULL), format (NATIVE), open_on_complete (false), @@ -148,7 +148,7 @@ ArrowParms::ArrowParms (lua_State* L, int index): } else if(asset_name != NULL) { - Asset* asset = (Asset*)LuaObject::getLuaObjectByName(asset_name, Asset::OBJECT_TYPE); + Asset* asset = dynamic_cast(LuaObject::getLuaObjectByName(asset_name, Asset::OBJECT_TYPE)); region = StringLib::duplicate(asset->getRegion()); asset->releaseLuaObject(); } @@ -217,12 +217,12 @@ void ArrowParms::cleanup (void) *----------------------------------------------------------------------------*/ ArrowParms::format_t ArrowParms::str2outputformat (const char* fmt_str) { - if (!fmt_str) return UNSUPPORTED; - else if(StringLib::match(fmt_str, "native")) return NATIVE; - else if(StringLib::match(fmt_str, "feather")) return FEATHER; - else if(StringLib::match(fmt_str, "parquet")) return PARQUET; - else if(StringLib::match(fmt_str, "csv")) return CSV; - else return UNSUPPORTED; + if(!fmt_str) return UNSUPPORTED; + if(StringLib::match(fmt_str, "native")) return NATIVE; + if(StringLib::match(fmt_str, "feather")) return FEATHER; + if(StringLib::match(fmt_str, "parquet")) return PARQUET; + if(StringLib::match(fmt_str, "csv")) return CSV; + return UNSUPPORTED; } /*---------------------------------------------------------------------------- @@ -232,7 +232,7 @@ int ArrowParms::luaIsNative (lua_State* L) { try { - ArrowParms* lua_obj = (ArrowParms*)getLuaSelf(L, 1); + ArrowParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); return returnLuaStatus(L, lua_obj->format == NATIVE); } catch(const RunTimeException& e) @@ -248,7 +248,7 @@ int ArrowParms::luaIsFeather (lua_State* L) { try { - ArrowParms* lua_obj = (ArrowParms*)getLuaSelf(L, 1); + ArrowParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); return returnLuaStatus(L, lua_obj->format == FEATHER); } catch(const RunTimeException& e) @@ -264,7 +264,7 @@ int ArrowParms::luaIsParquet (lua_State* L) { try { - ArrowParms* lua_obj = (ArrowParms*)getLuaSelf(L, 1); + ArrowParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); return returnLuaStatus(L, lua_obj->format == PARQUET); } catch(const RunTimeException& e) @@ -280,7 +280,7 @@ int ArrowParms::luaIsCSV (lua_State* L) { try { - ArrowParms* lua_obj = (ArrowParms*)getLuaSelf(L, 1); + ArrowParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); return returnLuaStatus(L, lua_obj->format == CSV); } catch(const RunTimeException& e) @@ -296,7 +296,7 @@ int ArrowParms::luaPath (lua_State* L) { try { - ArrowParms* lua_obj = (ArrowParms*)getLuaSelf(L, 1); + ArrowParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); if(lua_obj->path) lua_pushstring(L, lua_obj->path); else lua_pushnil(L); return 1; diff --git a/packages/arrow/ArrowParms.h b/packages/arrow/ArrowParms.h index f7d6375c0..e7be8f56d 100644 --- a/packages/arrow/ArrowParms.h +++ b/packages/arrow/ArrowParms.h @@ -85,8 +85,8 @@ class ArrowParms: public LuaObject static const char* CREDENTIALS; static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Data @@ -117,13 +117,13 @@ class ArrowParms: public LuaObject * Methods *--------------------------------------------------------------------*/ - void cleanup (void); - format_t str2outputformat (const char* fmt_str); - static int luaIsNative (lua_State* L); - static int luaIsFeather (lua_State* L); - static int luaIsParquet (lua_State* L); - static int luaIsCSV (lua_State* L); - static int luaPath (lua_State* L); + void cleanup (void); + static format_t str2outputformat (const char* fmt_str); + static int luaIsNative (lua_State* L); + static int luaIsFeather (lua_State* L); + static int luaIsParquet (lua_State* L); + static int luaIsCSV (lua_State* L); + static int luaPath (lua_State* L); }; #endif /* __arrow_parms__ */ diff --git a/packages/arrow/ParquetBuilder.cpp b/packages/arrow/ParquetBuilder.cpp index bc6cbd284..36667f375 100644 --- a/packages/arrow/ParquetBuilder.cpp +++ b/packages/arrow/ParquetBuilder.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "core.h" #include "ParquetBuilder.h" @@ -51,18 +52,13 @@ #include "aws.h" #endif -using std::shared_ptr; -using std::unique_ptr; -using std::make_shared; -using std::vector; - /****************************************************************************** * STATIC DATA ******************************************************************************/ const char* ParquetBuilder::OBJECT_TYPE = "ParquetBuilder"; -const char* ParquetBuilder::LuaMetaName = "ParquetBuilder"; -const struct luaL_Reg ParquetBuilder::LuaMetaTable[] = { +const char* ParquetBuilder::LUA_META_NAME = "ParquetBuilder"; +const struct luaL_Reg ParquetBuilder::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -199,7 +195,7 @@ struct ParquetBuilder::impl static void appendGeoMetaData (const std::shared_ptr& metadata) { /* Initialize Meta Data String */ - SafeString geostr(R"json({ + string geostr(R"json({ "version": "1.0.0-beta.1", "primary_column": "geometry", "columns": { @@ -249,14 +245,11 @@ struct ParquetBuilder::impl })json"); /* Reformat JSON */ - const char* oldtxt[2] = { " ", "\n" }; - const char* newtxt[2] = { "", " " }; - geostr.inreplace(oldtxt, newtxt, 2); + geostr = std::regex_replace(geostr, std::regex(" "), ""); + geostr = std::regex_replace(geostr, std::regex("\n"), " "); /* Append Meta String */ - const char* str = geostr.str(); - metadata->Append("geo", str); - + metadata->Append("geo", geostr.c_str()); } /*---------------------------------------------------------------------------- @@ -268,15 +261,15 @@ struct ParquetBuilder::impl int64_t launch_time_gps = TimeLib::sys2gpstime(OsApi::getLaunchTime()); TimeLib::gmt_time_t timeinfo = TimeLib::gps2gmttime(launch_time_gps); TimeLib::date_t dateinfo = TimeLib::gmt2date(timeinfo); - SafeString timestr("%04d-%02d-%02dT%02d:%02d:%02dZ", timeinfo.year, dateinfo.month, dateinfo.day, timeinfo.hour, timeinfo.minute, timeinfo.second); + FString timestr("%04d-%02d-%02dT%02d:%02d:%02dZ", timeinfo.year, dateinfo.month, dateinfo.day, timeinfo.hour, timeinfo.minute, timeinfo.second); /* Build Duration String */ int64_t duration = TimeLib::gpstime() - launch_time_gps; - SafeString durationstr("%ld", duration); + FString durationstr("%ld", duration); /* Build Package String */ const char** pkg_list = LuaEngine::getPkgList(); - SafeString packagestr("["); + string packagestr("["); if(pkg_list) { int index = 0; @@ -292,26 +285,30 @@ struct ParquetBuilder::impl delete [] pkg_list; /* Initialize Meta Data String */ - SafeString metastr(R"json({ + string metastr(R"json({ "server": { - "environment":"$1", - "version":"$2", - "duration":$3, - "packages":$4, - "commit":"$5", - "launch":"$6" + "environment":"_1_", + "version":"_2_", + "duration":_3_, + "packages":_4_, + "commit":"_5_", + "launch":"_6_" } })json"); /* Fill In Meta Data String */ - const char* oldtxt[8] = { " ", "\n", "$1", "$2", "$3", "$4", "$5", "$6" }; - const char* newtxt[8] = { "", " ", OsApi::getEnvVersion(), LIBID, durationstr.str(), packagestr.str(), BUILDINFO, timestr.str() }; - metastr.inreplace(oldtxt, newtxt, 8); + metastr = std::regex_replace(metastr, std::regex(" "), ""); + metastr = std::regex_replace(metastr, std::regex("\n"), " "); + metastr = std::regex_replace(metastr, std::regex("_1_"), OsApi::getEnvVersion()); + metastr = std::regex_replace(metastr, std::regex("_2_"), LIBID); + metastr = std::regex_replace(metastr, std::regex("_3_"), durationstr.c_str()); + metastr = std::regex_replace(metastr, std::regex("_4_"), packagestr.c_str()); + metastr = std::regex_replace(metastr, std::regex("_5_"), BUILDINFO); + metastr = std::regex_replace(metastr, std::regex("_6_"), timestr.c_str()); /* Append Meta String */ - const char* str = metastr.str(); - metadata->Append("sliderule", str); + metadata->Append("sliderule", metastr.c_str()); } /*---------------------------------------------------------------------------- @@ -324,8 +321,8 @@ struct ParquetBuilder::impl bool as_geo) { /* Initialize Pandas Meta Data String */ - SafeString pandasstr(R"json({ - "index_columns": [$INDEX], + string pandasstr(R"json({ + "index_columns": [_INDEX_], "column_indexes": [ { "name": null, @@ -335,18 +332,18 @@ struct ParquetBuilder::impl "metadata": {"encoding": "UTF-8"} } ], - "columns": [$COLUMNS], + "columns": [_COLUMNS_], "creator": {"library": "pyarrow", "version": "10.0.1"}, "pandas_version": "1.5.3" })json"); /* Build Columns String */ - SafeString columns; + string columns; int index = 0; for(const std::string& field_name: _schema->field_names()) { /* Initialize Column String */ - SafeString columnstr(R"json({"name": "$NAME", "field_name": "$NAME", "pandas_type": "$PTYPE", "numpy_type": "$NTYPE", "metadata": null})json"); + string columnstr(R"json({"name": "_NAME_", "field_name": "_NAME_", "pandas_type": "_PTYPE_", "numpy_type": "_NTYPE_", "metadata": null})json"); const char* pandas_type = ""; const char* numpy_type = ""; bool is_last_entry = false; @@ -387,9 +384,9 @@ struct ParquetBuilder::impl } /* Fill In Column String */ - const char* oldtxt[3] = { "$NAME", "$PTYPE", "$NTYPE" }; - const char* newtxt[3] = { field_name.c_str(), pandas_type, numpy_type }; - columnstr.inreplace(oldtxt, newtxt, 3); + columnstr = std::regex_replace(columnstr, std::regex("_NAME_"), field_name.c_str()); + columnstr = std::regex_replace(columnstr, std::regex("_PTYPE_"), pandas_type); + columnstr = std::regex_replace(columnstr, std::regex("_NTYPE_"), numpy_type); /* Add Comma */ if(!is_last_entry) @@ -402,17 +399,16 @@ struct ParquetBuilder::impl } /* Build Index String */ - SafeString indexstr("\"%s\"", index_key ? index_key : ""); - if(!index_key) indexstr = ""; + FString indexstr("\"%s\"", index_key ? index_key : ""); /* Fill In Pandas Meta Data String */ - const char* oldtxt[4] = { " ", "\n", "$INDEX", "$COLUMNS" }; - const char* newtxt[4] = { "", " ", indexstr.str(), columns.str() }; - pandasstr.inreplace(oldtxt, newtxt, 4); + pandasstr = std::regex_replace(pandasstr, std::regex(" "), ""); + pandasstr = std::regex_replace(pandasstr, std::regex("\n"), " "); + pandasstr = std::regex_replace(pandasstr, std::regex("_INDEX_"), index_key ? indexstr.c_str() : ""); + pandasstr = std::regex_replace(pandasstr, std::regex("_COLUMNS_"), columns.c_str()); /* Append Meta String */ - const char* str = pandasstr.str(); - metadata->Append("pandas", str); + metadata->Append("pandas", pandasstr.c_str()); } }; @@ -430,7 +426,7 @@ int ParquetBuilder::luaCreate (lua_State* L) try { /* Get Parameters */ - _parms = (ArrowParms*)getLuaObject(L, 1, ArrowParms::OBJECT_TYPE); + _parms = dynamic_cast(getLuaObject(L, 1, ArrowParms::OBJECT_TYPE)); const char* outq_name = getLuaString(L, 2); const char* inq_name = getLuaString(L, 3); const char* rec_type = getLuaString(L, 4); @@ -471,7 +467,7 @@ int ParquetBuilder::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(_parms) _parms->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -501,11 +497,12 @@ void ParquetBuilder::deinit (void) *----------------------------------------------------------------------------*/ ParquetBuilder::ParquetBuilder (lua_State* L, ArrowParms* _parms, const char* outq_name, const char* inq_name, - const char* rec_type, const char* id, geo_data_t geo, const char* index_key): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + const char* rec_type, const char* id, const geo_data_t& geo, const char* index_key): + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), parms(_parms), recType(StringLib::duplicate(rec_type)), batchRecType(NULL), + fieldList(LIST_BLOCK_SIZE), geoData(geo) { assert(_parms); @@ -519,7 +516,7 @@ ParquetBuilder::ParquetBuilder (lua_State* L, ArrowParms* _parms, /* Define Table Schema */ vector> schema_vector; - pimpl->addFieldsToSchema(schema_vector, fieldList, &batchRecType, geoData, rec_type, 0, 0); + ParquetBuilder::impl::addFieldsToSchema(schema_vector, fieldList, &batchRecType, geoData, rec_type, 0, 0); if(geoData.as_geo) schema_vector.push_back(arrow::field("geometry", arrow::binary())); pimpl->schema = make_shared(schema_vector); fieldIterator = new field_iterator_t(fieldList); @@ -535,8 +532,8 @@ ParquetBuilder::ParquetBuilder (lua_State* L, ArrowParms* _parms, inQ = new Subscriber(inq_name, MsgQ::SUBSCRIBER_OF_CONFIDENCE, qdepth); /* Create Unique Temporary Filename */ - SafeString tmp_file("%s%s.parquet", TMP_FILE_PREFIX, id); - fileName = tmp_file.str(true); + FString tmp_file("%s%s.parquet", TMP_FILE_PREFIX, id); + fileName = tmp_file.c_str(true); /* Create Arrow Output Stream */ shared_ptr file_output_stream; @@ -553,9 +550,9 @@ ParquetBuilder::ParquetBuilder (lua_State* L, ArrowParms* _parms, /* Build GeoParquet MetaData */ auto metadata = pimpl->schema->metadata() ? pimpl->schema->metadata()->Copy() : std::make_shared(); - if(geoData.as_geo) pimpl->appendGeoMetaData(metadata); - pimpl->appendServerMetaData(metadata); - pimpl->appendPandasMetaData(metadata, pimpl->schema, fieldIterator, index_key, geoData.as_geo); + if(geoData.as_geo) ParquetBuilder::impl::appendGeoMetaData(metadata); + ParquetBuilder::impl::appendServerMetaData(metadata); + ParquetBuilder::impl::appendPandasMetaData(metadata, pimpl->schema, fieldIterator, index_key, geoData.as_geo); pimpl->schema = pimpl->schema->WithMetadata(metadata); /* Create Parquet Writer */ @@ -606,7 +603,7 @@ ParquetBuilder::~ParquetBuilder(void) *----------------------------------------------------------------------------*/ void* ParquetBuilder::builderThread(void* parm) { - ParquetBuilder* builder = (ParquetBuilder*)parm; + ParquetBuilder* builder = static_cast(parm); int row_cnt = 0; /* Early Exit on No Writer */ @@ -687,7 +684,6 @@ void* ParquetBuilder::builderThread(void* parm) /* Process Remaining Records */ builder->processRecordBatch(row_cnt); - row_cnt = 0; /* Close Parquet Writer */ (void)builder->pimpl->parquetWriter->Close(); diff --git a/packages/arrow/ParquetBuilder.h b/packages/arrow/ParquetBuilder.h index 1c4c2e6a9..29a5c72a2 100644 --- a/packages/arrow/ParquetBuilder.h +++ b/packages/arrow/ParquetBuilder.h @@ -71,8 +71,8 @@ class ParquetBuilder: public LuaObject static const int QUEUE_BUFFER_FACTOR = 3; static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const char* metaRecType; static const RecordObject::fieldDef_t metaRecDef[]; @@ -110,7 +110,7 @@ class ParquetBuilder: public LuaObject * Types *--------------------------------------------------------------------*/ - typedef List field_list_t; + typedef List field_list_t; typedef field_list_t::Iterator field_iterator_t; typedef struct { @@ -163,7 +163,7 @@ class ParquetBuilder: public LuaObject ParquetBuilder (lua_State* L, ArrowParms* parms, const char* outq_name, const char* inq_name, - const char* rec_type, const char* id, geo_data_t geo, const char* index_key); + const char* rec_type, const char* id, const geo_data_t& geo, const char* index_key); ~ParquetBuilder (void); static void* builderThread (void* parm); diff --git a/packages/aws/CredentialStore.cpp b/packages/aws/CredentialStore.cpp index 99cad352e..ea13abfb3 100644 --- a/packages/aws/CredentialStore.cpp +++ b/packages/aws/CredentialStore.cpp @@ -45,7 +45,6 @@ Mutex CredentialStore::credentialLock; Dictionary CredentialStore::credentialStore(STARTING_STORE_SIZE); -Dictionary CredentialStore::metricIds(STARTING_STORE_SIZE); const char* CredentialStore::LIBRARY_NAME = "CredentialStore"; const char* CredentialStore::EXPIRATION_GPS_METRIC = "exp_gps"; @@ -116,31 +115,6 @@ bool CredentialStore::put (const char* host, Credential& credential) { /* Store Credentials */ status = credentialStore.add(host, credential); - - /* Find/Register Metric Id */ - int32_t metric_id = EventLib::INVALID_METRIC; - if(!metricIds.find(host, &metric_id)) - { - metric_id = EventLib::registerMetric(LIBRARY_NAME, EventLib::GAUGE, "%s:%s", host ? host : "", EXPIRATION_GPS_METRIC); - metricIds.add(host, metric_id); - } - - /* Update Metric */ - if(metric_id != EventLib::INVALID_METRIC) - { - if(credential.expiration != NULL) - { - update_metric(DEBUG, metric_id, credential.expirationGps); - } - else - { - mlog(CRITICAL, "Null expiration time supplied to credential for %s", host); - } - } - else - { - mlog(CRITICAL, "Unable to register credential metric for %s", host); - } } credentialLock.unlock(); diff --git a/packages/aws/CredentialStore.h b/packages/aws/CredentialStore.h index 3dadc1fc7..e7dc1a284 100644 --- a/packages/aws/CredentialStore.h +++ b/packages/aws/CredentialStore.h @@ -97,7 +97,7 @@ class CredentialStore copy(c); }; - const Credential& operator=(const Credential& c) { + Credential& operator=(const Credential& c) { cleanup(); copy(c); return *this; @@ -185,7 +185,7 @@ class CredentialStore } }; - void toLua (lua_State* L) + void toLua (lua_State* L) const { lua_newtable(L); @@ -217,11 +217,11 @@ class CredentialStore expirationGps = 0L; } - void cleanup (void) { - if(accessKeyId) delete [] accessKeyId; - if(secretAccessKey) delete [] secretAccessKey; - if(sessionToken) delete [] sessionToken; - if(expiration) delete [] expiration; + void cleanup (void) const { + delete [] accessKeyId; + delete [] secretAccessKey; + delete [] sessionToken; + delete [] expiration; } void copy (const Credential& c) { diff --git a/packages/aws/S3CacheIODriver.cpp b/packages/aws/S3CacheIODriver.cpp index 3c604770e..153d47e8a 100644 --- a/packages/aws/S3CacheIODriver.cpp +++ b/packages/aws/S3CacheIODriver.cpp @@ -44,12 +44,13 @@ #include #include #include +#include /****************************************************************************** * STATIC DATA ******************************************************************************/ -const char* S3CacheIODriver::FORMAT = "s3cache"; +const char* S3CacheIODriver::CACHE_FORMAT = "s3cache"; const char* S3CacheIODriver::DEFAULT_CACHE_ROOT = ".cache"; const char* S3CacheIODriver::cacheRoot = NULL; @@ -59,7 +60,7 @@ okey_t S3CacheIODriver::cacheIndex = 0; Mutex S3CacheIODriver::cacheMut; Dictionary S3CacheIODriver::cacheLookUp; -MgOrdering S3CacheIODriver::cacheFiles; +S3CacheIODriver::FileOrdering S3CacheIODriver::cacheFiles; /****************************************************************************** * FILE IO DRIVER CLASS @@ -124,7 +125,7 @@ int S3CacheIODriver::createCache (const char* cache_root, int max_files) } /* Set Cache Root */ - if(cacheRoot) delete [] cacheRoot; + delete [] cacheRoot; cacheRoot = StringLib::duplicate(cache_root); /* Set Maximum Number of Files */ @@ -149,15 +150,16 @@ int S3CacheIODriver::createCache (const char* cache_root, int max_files) StringLib::format(cache_filepath, MAX_STR_SIZE, "%s%c%s", cacheRoot, PATH_DELIMETER, ent->d_name); /* Reformat Filename to Key */ - SafeString key("%s", ent->d_name); - key.replace("#", PATH_DELIMETER_STR); + char* sanitized_dir_name = StringLib::duplicate(ent->d_name); + StringLib::replace(sanitized_dir_name, '#', PATH_DELIMETER); + string* cache_key = new string(sanitized_dir_name); + delete [] sanitized_dir_name; /* Add File to Cache */ + mlog(INFO, "Caching %s for S3 retrieval", cache_key->c_str()); cacheIndex++; - cacheLookUp.add(key.str(), cacheIndex); - const char* cache_key = StringLib::duplicate(key.str()); + cacheLookUp.add(cache_key->c_str(), cacheIndex); cacheFiles.add(cacheIndex, cache_key); - mlog(INFO, "Caching %s for S3 retrieval", key.str()); } } } @@ -239,7 +241,7 @@ bool S3CacheIODriver::fileGet (const char* bucket, const char* key, const char** cacheIndex++; cacheFiles.remove(cacheLookUp[key]); cacheLookUp.add(key, cacheIndex); - const char* cache_key = StringLib::duplicate(key); + string* cache_key = new string(key); cacheFiles.add(cacheIndex, cache_key); found_in_cache = true; } @@ -247,22 +249,23 @@ bool S3CacheIODriver::fileGet (const char* bucket, const char* key, const char** cacheMut.unlock(); /* Build Cache Filename */ - SafeString cache_filename("%s", key); - cache_filename.replace(PATH_DELIMETER_STR, "#"); - SafeString cache_filepath("%s%c%s", cacheRoot, PATH_DELIMETER, cache_filename.str()); + char* cache_filename = StringLib::duplicate(key); + StringLib::replace(cache_filename, PATH_DELIMETER, '#'); + FString cache_filepath("%s%c%s", cacheRoot, PATH_DELIMETER, cache_filename); + delete [] cache_filename; /* Log Operation */ - mlog(DEBUG, "S3 %s object %s in bucket %s: %s", found_in_cache ? "cache hit on" : "download of", key, bucket, cache_filepath.str()); + mlog(DEBUG, "S3 %s object %s in bucket %s: %s", found_in_cache ? "cache hit on" : "download of", key, bucket, cache_filepath.c_str()); /* Quick Exit If Cache Hit */ if(found_in_cache) { - *file = cache_filepath.str(true); + *file = cache_filepath.c_str(true); return true; } /* Download File */ - int64_t bytes_read = get(cache_filepath.str(), bucket, key, asset->getRegion(), &latestCredentials); + int64_t bytes_read = get(cache_filepath.c_str(), bucket, key, asset->getRegion(), &latestCredentials); if(bytes_read <= 0) { mlog(CRITICAL, "Failed to download S3 object: %ld", (long int)bytes_read); @@ -275,28 +278,29 @@ bool S3CacheIODriver::fileGet (const char* bucket, const char* key, const char** if(cacheLookUp.length() >= cacheMaxSize) { /* Get Oldest File from Cache */ - const char* oldest_key = NULL; + string* oldest_key = NULL; okey_t index = cacheFiles.first(&oldest_key); if(oldest_key != NULL) { /* Delete File in Local File System */ - SafeString oldest_filename("%s", oldest_key); - oldest_filename.replace(PATH_DELIMETER_STR, "#"); - SafeString oldest_filepath("%s%c%s", cacheRoot, PATH_DELIMETER, oldest_filename.str()); - remove(oldest_filepath.str()); + char* oldest_filename = StringLib::duplicate(oldest_key->c_str()); + StringLib::replace(oldest_filename, PATH_DELIMETER, '#'); + FString oldest_filepath("%s%c%s", cacheRoot, PATH_DELIMETER, oldest_filename); + remove(oldest_filepath.c_str()); cacheFiles.remove(index); + delete [] oldest_filename; } } /* Add New File to Cache */ cacheIndex++; cacheLookUp.add(key, cacheIndex); - const char* cache_key = StringLib::duplicate(key); + string* cache_key = new string(key); cacheFiles.add(cacheIndex, cache_key); } cacheMut.unlock(); /* Return Success */ - *file = cache_filepath.str(true); + *file = cache_filepath.c_str(true); return true; } diff --git a/packages/aws/S3CacheIODriver.h b/packages/aws/S3CacheIODriver.h index d26251187..211a24385 100644 --- a/packages/aws/S3CacheIODriver.h +++ b/packages/aws/S3CacheIODriver.h @@ -55,7 +55,7 @@ class S3CacheIODriver: public S3CurlIODriver * Constants *--------------------------------------------------------------------*/ - static const char* FORMAT; + static const char* CACHE_FORMAT; static const char* DEFAULT_CACHE_ROOT; static const int DEFAULT_MAX_CACHE_FILES = 16; @@ -68,7 +68,7 @@ class S3CacheIODriver: public S3CurlIODriver static IODriver* create (const Asset* _asset, const char* resource); static int luaCreateCache (lua_State* L); static int createCache (const char* cache_root=DEFAULT_CACHE_ROOT, int max_files=DEFAULT_MAX_CACHE_FILES); - int64_t ioRead (uint8_t* data, int64_t size, uint64_t pos); + int64_t ioRead (uint8_t* data, int64_t size, uint64_t pos) override; private: @@ -81,19 +81,24 @@ class S3CacheIODriver: public S3CurlIODriver bool fileGet (const char* bucket, const char* key, const char** file); + /*-------------------------------------------------------------------- + * Types + *--------------------------------------------------------------------*/ + + typedef Ordering FileOrdering; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static const char* cacheRoot; - static int cacheMaxSize; - static Mutex cacheMut; - static okey_t cacheIndex; - static Dictionary cacheLookUp; - static MgOrdering cacheFiles; + static const char* cacheRoot; + static int cacheMaxSize; + static Mutex cacheMut; + static okey_t cacheIndex; + static Dictionary cacheLookUp; + static FileOrdering cacheFiles; - const Asset* asset; - fileptr_t ioFile; + fileptr_t ioFile; }; #endif /* __s3_cache_io_driver__ */ diff --git a/packages/aws/S3CurlIODriver.cpp b/packages/aws/S3CurlIODriver.cpp index 3bd77b4ee..bbf75df0b 100644 --- a/packages/aws/S3CurlIODriver.cpp +++ b/packages/aws/S3CurlIODriver.cpp @@ -155,24 +155,26 @@ static headers_t buildReadHeadersV2 (const char* bucket, const char* key, Creden /* Build Date String and Date Header */ TimeLib::gmt_time_t gmt_time = TimeLib::gmttime(); TimeLib::date_t gmt_date = TimeLib::gmt2date(gmt_time); - SafeString date("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); - SafeString dateHeader("Date: %s", date.str()); - headers = curl_slist_append(headers, dateHeader.str()); + FString date("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); + FString dateHeader("Date: %s", date.c_str()); + headers = curl_slist_append(headers, dateHeader.c_str()); if(credentials && credentials->provided) { /* Build SecurityToken Header */ - SafeString securityTokenHeader("x-amz-security-token:%s", credentials->sessionToken); - headers = curl_slist_append(headers, securityTokenHeader.str()); + FString securityTokenHeader("x-amz-security-token:%s", credentials->sessionToken); + headers = curl_slist_append(headers, securityTokenHeader.c_str()); /* Build Authorization Header */ - SafeString stringToSign("GET\n\n\n%s\n%s\n/%s/%s", date.str(), securityTokenHeader.str(), bucket, key); + FString stringToSign("GET\n\n\n%s\n%s\n/%s/%s", date.c_str(), securityTokenHeader.c_str(), bucket, key); unsigned char hash[EVP_MAX_MD_SIZE]; unsigned int hash_size = EVP_MAX_MD_SIZE; // set below with actual size - HMAC(EVP_sha1(), credentials->secretAccessKey, StringLib::size(credentials->secretAccessKey), (unsigned char*)stringToSign.str(), stringToSign.bytes() - 1, hash, &hash_size); - SafeString encodedHash(64, hash, hash_size); - SafeString authorizationHeader("Authorization: AWS %s:%s", credentials->accessKeyId, encodedHash.str()); - headers = curl_slist_append(headers, authorizationHeader.str()); + HMAC(EVP_sha1(), credentials->secretAccessKey, StringLib::size(credentials->secretAccessKey), (unsigned char*)stringToSign.c_str(), stringToSign.size(), hash, &hash_size); + int encoded_hash_size = static_cast(hash_size); + const char* encodedHash = StringLib::b64encode(hash, &encoded_hash_size); + FString authorizationHeader("Authorization: AWS %s:%s", credentials->accessKeyId, encodedHash); + headers = curl_slist_append(headers, authorizationHeader.c_str()); + delete [] encodedHash; } /* Return */ @@ -192,16 +194,16 @@ static headers_t buildWriteHeadersV2 (const char* bucket, const char* key, const /* Build Date String and Date Header */ TimeLib::gmt_time_t gmt_time = TimeLib::gmttime(); TimeLib::date_t gmt_date = TimeLib::gmt2date(gmt_time); - SafeString date("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); - SafeString dateHeader("Date: %s", date.str()); - headers = curl_slist_append(headers, dateHeader.str()); + FString date("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); + FString dateHeader("Date: %s", date.c_str()); + headers = curl_slist_append(headers, dateHeader.c_str()); /* Content Headers */ - SafeString contentType("application/octet-stream"); - SafeString contentTypeHeader("Content-Type: %s", contentType.str()); - headers = curl_slist_append(headers, contentTypeHeader.str()); - SafeString contentLengthHeader("Content-Length: %ld", content_length); - headers = curl_slist_append(headers, contentLengthHeader.str()); + FString contentType("application/octet-stream"); + FString contentTypeHeader("Content-Type: %s", contentType.c_str()); + headers = curl_slist_append(headers, contentTypeHeader.c_str()); + FString contentLengthHeader("Content-Length: %ld", content_length); + headers = curl_slist_append(headers, contentLengthHeader.c_str()); /* Initialize and Remove Unwanted Headers */ headers = curl_slist_append(headers, "Transfer-Encoding:"); @@ -209,17 +211,19 @@ static headers_t buildWriteHeadersV2 (const char* bucket, const char* key, const if(credentials && credentials->provided) { /* Build SecurityToken Header */ - SafeString securityTokenHeader("x-amz-security-token:%s", credentials->sessionToken); - headers = curl_slist_append(headers, securityTokenHeader.str()); + FString securityTokenHeader("x-amz-security-token:%s", credentials->sessionToken); + headers = curl_slist_append(headers, securityTokenHeader.c_str()); /* Build Authorization Header */ - SafeString stringToSign("PUT\n\n%s\n%s\n%s\n/%s/%s", contentType.str(), date.str(), securityTokenHeader.str(), bucket, key); + FString stringToSign("PUT\n\n%s\n%s\n%s\n/%s/%s", contentType.c_str(), date.c_str(), securityTokenHeader.c_str(), bucket, key); unsigned char hash[EVP_MAX_MD_SIZE]; unsigned int hash_size = EVP_MAX_MD_SIZE; // set below with actual size - HMAC(EVP_sha1(), credentials->secretAccessKey, StringLib::size(credentials->secretAccessKey), (unsigned char*)stringToSign.str(), stringToSign.bytes() - 1, hash, &hash_size); - SafeString encodedHash(64, hash, hash_size); - SafeString authorizationHeader("Authorization: AWS %s:%s", credentials->accessKeyId, encodedHash.str()); - headers = curl_slist_append(headers, authorizationHeader.str()); + HMAC(EVP_sha1(), credentials->secretAccessKey, StringLib::size(credentials->secretAccessKey), (unsigned char*)stringToSign.c_str(), stringToSign.length(), hash, &hash_size); + int encoded_hash_size = static_cast(hash_size); + const char* encodedHash = StringLib::b64encode(hash, &encoded_hash_size); + FString authorizationHeader("Authorization: AWS %s:%s", credentials->accessKeyId, encodedHash); + headers = curl_slist_append(headers, authorizationHeader.c_str()); + delete [] encodedHash; } /* Return */ @@ -247,25 +251,25 @@ static headers_t buildWriteHeadersV4 (const char* bucket, const char* key, const /* Build Date String */ TimeLib::gmt_time_t gmt_time = TimeLib::gmttime(); TimeLib::date_t gmt_date = TimeLib::gmt2date(gmt_time); - SafeString timestamp("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); + FString timestamp("%04d%02d%02dT%02d%02d%02dZ", gmt_date.year, gmt_date.month, gmt_date.day, gmt_time.hour, gmt_time.minute, gmt_time.second); /* Build Canonical Request */ char canonical_request_hash[SHA256_HEX_STR_SIZE]; - SafeString canonical_request("PUT\n/%s\n\ncontent-length:%ld\ndate:%s\nhost:%s.s3.amazonaws.com\nx-amz-content-sha256:UNSIGNED-PAYLOAD\nx-amz-date:%s\nx-amz-security-token:%s\n\ncontent-length;date;host;x-amz-content-sha256;x-amz-date;x-amz-security-token\nUNSIGNED-PAYLOAD", - key, content_length, timestamp.str(), bucket, timestamp.str(), credentials->sessionToken); - sha256hash(canonical_request.str(), canonical_request.bytes() - 1, canonical_request_hash); + FString canonical_request("PUT\n/%s\n\ncontent-length:%ld\ndate:%s\nhost:%s.s3.amazonaws.com\nx-amz-content-sha256:UNSIGNED-PAYLOAD\nx-amz-date:%s\nx-amz-security-token:%s\n\ncontent-length;date;host;x-amz-content-sha256;x-amz-date;x-amz-security-token\nUNSIGNED-PAYLOAD", + key, content_length, timestamp.c_str(), bucket, timestamp.c_str(), credentials->sessionToken); + sha256hash(canonical_request.c_str(), canonical_request.length(), canonical_request_hash); /* Build String To Sign */ - SafeString date("%04d%02d%02d", gmt_date.year, gmt_date.month, gmt_date.day); - SafeString scope("%s/%s/s3/aws4_request", date.str(), region); - SafeString str2sign("AWS4-HMAC-SHA256\n%s\n%s\n%s", timestamp.str(), scope.str(), canonical_request_hash); + FString date("%04d%02d%02d", gmt_date.year, gmt_date.month, gmt_date.day); + FString scope("%s/%s/s3/aws4_request", date.c_str(), region); + FString str2sign("AWS4-HMAC-SHA256\n%s\n%s\n%s", timestamp.c_str(), scope.c_str(), canonical_request_hash); /* Calculate Signature */ - SafeString secret_access_key_str2sign("AWS4%s", credentials->secretAccessKey); + FString secret_access_key_str2sign("AWS4%s", credentials->secretAccessKey); unsigned char date_key[EVP_MAX_MD_SIZE]; unsigned int date_key_size = EVP_MAX_MD_SIZE; // set below with actual size - HMAC(EVP_sha256(), secret_access_key_str2sign.str(), secret_access_key_str2sign.bytes() - 1, (unsigned char*)date.str(), date.bytes() - 1, date_key, &date_key_size); + HMAC(EVP_sha256(), secret_access_key_str2sign.c_str(), secret_access_key_str2sign.length(), (unsigned char*)date.c_str(), date.length(), date_key, &date_key_size); unsigned char date_region_key[EVP_MAX_MD_SIZE]; unsigned int date_region_key_size = EVP_MAX_MD_SIZE; // set below with actual size @@ -281,7 +285,7 @@ static headers_t buildWriteHeadersV4 (const char* bucket, const char* key, const unsigned char signature[EVP_MAX_MD_SIZE]; unsigned int signature_size = EVP_MAX_MD_SIZE; // set below with actual size - HMAC(EVP_sha256(), signing_key, signing_key_size, (unsigned char*)str2sign.str(), str2sign.bytes() - 1, signature, &signature_size); + HMAC(EVP_sha256(), signing_key, signing_key_size, (unsigned char*)str2sign.c_str(), str2sign.length(), signature, &signature_size); char signature_hex[SHA256_HEX_STR_SIZE]; StringLib::b16encode(signature, signature_size, true, signature_hex); @@ -291,18 +295,18 @@ static headers_t buildWriteHeadersV4 (const char* bucket, const char* key, const headers = curl_slist_append(headers, "Transfer-Encoding:"); /* Build Headers */ - SafeString date_hdr("Date: %s", timestamp.str()); - headers = curl_slist_append(headers, date_hdr.str()); - SafeString content_length_hdr("Content-Length: %ld", content_length); - headers = curl_slist_append(headers, content_length_hdr.str()); - SafeString auth_hdr("Authorization: AWS4-HMAC-SHA256 Credential=%s/%s/%s/s3/aws4_request,SignedHeaders=content-length;date;host;x-amz-content-sha256;x-amz-date;x-amz-security-token,Signature=%s", credentials->accessKeyId, date.str(), region, signature_hex); - headers = curl_slist_append(headers, auth_hdr.str()); - SafeString amz_date_hdr("x-amz-date: %s", timestamp.str()); - headers = curl_slist_append(headers, amz_date_hdr.str()); - SafeString amz_token_hdr("x-amz-security-token: %s", credentials->sessionToken); - headers = curl_slist_append(headers, amz_date_hdr.str()); - SafeString amz_content_sha256_hdr("x-amz-content-sha256: %s", "UNSIGNED-PAYLOAD"); - headers = curl_slist_append(headers, amz_content_sha256_hdr.str()); + FString date_hdr("Date: %s", timestamp.c_str()); + headers = curl_slist_append(headers, date_hdr.c_str()); + FString content_length_hdr("Content-Length: %ld", content_length); + headers = curl_slist_append(headers, content_length_hdr.c_str()); + FString auth_hdr("Authorization: AWS4-HMAC-SHA256 Credential=%s/%s/%s/s3/aws4_request,SignedHeaders=content-length;date;host;x-amz-content-sha256;x-amz-date;x-amz-security-token,Signature=%s", credentials->accessKeyId, date.c_str(), region, signature_hex); + headers = curl_slist_append(headers, auth_hdr.c_str()); + FString amz_date_hdr("x-amz-date: %s", timestamp.c_str()); + headers = curl_slist_append(headers, amz_date_hdr.c_str()); + FString amz_token_hdr("x-amz-security-token: %s", credentials->sessionToken); + headers = curl_slist_append(headers, amz_date_hdr.c_str()); + FString amz_content_sha256_hdr("x-amz-content-sha256: %s", "UNSIGNED-PAYLOAD"); + headers = curl_slist_append(headers, amz_content_sha256_hdr.c_str()); /* Return Headers */ return headers; @@ -311,14 +315,14 @@ static headers_t buildWriteHeadersV4 (const char* bucket, const char* key, const /*---------------------------------------------------------------------------- * initializeReadRequest *----------------------------------------------------------------------------*/ -static CURL* initializeReadRequest (SafeString& url, headers_t headers, write_cb_t write_cb, void* write_parm) +static CURL* initializeReadRequest (FString& url, headers_t headers, write_cb_t write_cb, void* write_parm) { /* Initialize cURL */ CURL* curl = curl_easy_init(); if(curl) { /* Set Options */ - curl_easy_setopt(curl, CURLOPT_URL, url.str()); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_TIMEOUT, S3CurlIODriver::READ_TIMEOUT); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, S3CurlIODriver::CONNECTION_TIMEOUT); @@ -341,14 +345,14 @@ static CURL* initializeReadRequest (SafeString& url, headers_t headers, write_cb /*---------------------------------------------------------------------------- * initializeWriteRequest *----------------------------------------------------------------------------*/ -static CURL* initializeWriteRequest (SafeString& url, headers_t headers, write_cb_t read_cb, void* read_parm) +static CURL* initializeWriteRequest (FString& url, headers_t headers, write_cb_t read_cb, void* read_parm) { /* Initialize cURL */ CURL* curl = curl_easy_init(); if(curl) { /* Set Options */ - curl_easy_setopt(curl, CURLOPT_URL, url.str()); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_PUT, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_TIMEOUT, S3CurlIODriver::READ_TIMEOUT); @@ -376,7 +380,7 @@ static CURL* initializeWriteRequest (SafeString& url, headers_t headers, write_c const char* S3CurlIODriver::DEFAULT_REGION = "us-west-2"; const char* S3CurlIODriver::DEFAULT_IDENTITY = "iam-role"; -const char* S3CurlIODriver::FORMAT = "s3"; +const char* S3CurlIODriver::CURL_FORMAT = "s3"; /****************************************************************************** * AWS S3 cURL I/O DRIVER CLASS @@ -410,7 +414,11 @@ int64_t S3CurlIODriver::get (uint8_t* data, int64_t size, uint64_t pos, const ch if(key_ptr[0] == '/') key_ptr++; /* Build URL */ - SafeString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); + FString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); + + /* Check Size and Initialize Data */ + assert(size > 0); + data[0] = 0; /* Setup Buffer for Callback */ fixed_data_t info = { @@ -430,8 +438,8 @@ int64_t S3CurlIODriver::get (uint8_t* data, int64_t size, uint64_t pos, const ch /* Build Range Header */ unsigned long start_byte = pos + info.index; unsigned long end_byte = pos + size - info.index - 1; - SafeString rangeHeader("Range: bytes=%lu-%lu", start_byte, end_byte); - headers = curl_slist_append(headers, rangeHeader.str()); + FString rangeHeader("Range: bytes=%lu-%lu", start_byte, end_byte); + headers = curl_slist_append(headers, rangeHeader.c_str()); /* Initialize cURL Request */ CURL* curl = initializeReadRequest(url, headers, curlWriteFixed, &info); @@ -522,14 +530,14 @@ int64_t S3CurlIODriver::get (uint8_t** data, const char* bucket, const char* key List rsps_set; /* Build URL */ - SafeString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); + FString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); /* Initialize cURL Request */ - bool rqst_complete = false; - int attempts = ATTEMPTS_PER_REQUEST; CURL* curl = initializeReadRequest(url, headers, curlWriteStreaming, &rsps_set); if(curl) { + bool rqst_complete = false; + int attempts = ATTEMPTS_PER_REQUEST; while(!rqst_complete && (attempts-- > 0)) { /* Perform Request */ @@ -634,14 +642,14 @@ int64_t S3CurlIODriver::get (const char* filename, const char* bucket, const cha if(data.fd) { /* Build URL */ - SafeString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); + FString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); /* Initialize cURL Request */ - bool rqst_complete = false; - int attempts = ATTEMPTS_PER_REQUEST; CURL* curl = initializeReadRequest(url, headers, curlWriteFile, &data); if(curl) { + bool rqst_complete = false; + int attempts = ATTEMPTS_PER_REQUEST; while(!rqst_complete && (attempts-- > 0)) { /* Perform Request */ @@ -732,14 +740,14 @@ int64_t S3CurlIODriver::put (const char* filename, const char* bucket, const cha struct curl_slist* headers = buildWriteHeadersV2(bucket, key_ptr, region, credentials, content_length); /* Build URL */ - SafeString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); + FString url("https://s3.%s.amazonaws.com/%s/%s", region, bucket, key_ptr); /* Initialize cURL Request */ - bool rqst_complete = false; - int attempts = ATTEMPTS_PER_REQUEST; CURL* curl = initializeWriteRequest(url, headers, curlReadFile, &data); if(curl) { + bool rqst_complete = false; + int attempts = ATTEMPTS_PER_REQUEST; while(!rqst_complete && (attempts-- > 0)) { /* Perform Request */ @@ -906,7 +914,7 @@ int S3CurlIODriver::luaRead(lua_State* L) /* Check Parameters */ if(size <= 0) throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid size: %ld", size); - else if(pos < 0) throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid position: %ld", pos); + if(pos < 0) throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid position: %ld", pos); /* Get Credentials */ CredentialStore::Credential credentials = CredentialStore::get(identity); @@ -1000,10 +1008,10 @@ S3CurlIODriver::S3CurlIODriver (const Asset* _asset): S3CurlIODriver::S3CurlIODriver (const Asset* _asset, const char* resource): asset(_asset) { - SafeString resourcepath("%s/%s", asset->getPath(), resource); + FString resourcepath("%s/%s", asset->getPath(), resource); /* Allocate Memory */ - ioBucket = StringLib::duplicate(resourcepath.str()); + ioBucket = StringLib::duplicate(resourcepath.c_str()); /* * Differentiate Bucket and Key @@ -1031,5 +1039,5 @@ S3CurlIODriver::~S3CurlIODriver (void) * only ioBucket is freed because ioKey only points * into the memory allocated to ioBucket */ - if(ioBucket) delete [] ioBucket; + delete [] ioBucket; } diff --git a/packages/aws/S3CurlIODriver.h b/packages/aws/S3CurlIODriver.h index 2e3e28711..cafec8300 100644 --- a/packages/aws/S3CurlIODriver.h +++ b/packages/aws/S3CurlIODriver.h @@ -62,7 +62,7 @@ class S3CurlIODriver: public Asset::IODriver static const long SSL_VERIFYHOST = 0; static const char* DEFAULT_REGION; static const char* DEFAULT_IDENTITY; - static const char* FORMAT; + static const char* CURL_FORMAT; /*-------------------------------------------------------------------- * Methods @@ -102,8 +102,8 @@ class S3CurlIODriver: public Asset::IODriver * Methods *--------------------------------------------------------------------*/ - S3CurlIODriver (const Asset* _asset); - S3CurlIODriver (const Asset* _asset, const char* resource); + explicit S3CurlIODriver (const Asset* _asset); + explicit S3CurlIODriver (const Asset* _asset, const char* resource); virtual ~S3CurlIODriver (void); /*-------------------------------------------------------------------- diff --git a/packages/aws/aws.cpp b/packages/aws/aws.cpp index cd99c06bb..eb1e0c758 100644 --- a/packages/aws/aws.cpp +++ b/packages/aws/aws.cpp @@ -79,8 +79,8 @@ void initaws (void) CredentialStore::init(); /* Register I/O Drivers */ - Asset::registerDriver(S3CacheIODriver::FORMAT, S3CacheIODriver::create); - Asset::registerDriver(S3CurlIODriver::FORMAT, S3CurlIODriver::create); + Asset::registerDriver(S3CacheIODriver::CACHE_FORMAT, S3CacheIODriver::create); + Asset::registerDriver(S3CurlIODriver::CURL_FORMAT, S3CurlIODriver::create); /* Extend Lua */ LuaEngine::extend(LUA_AWS_LIBNAME, aws_open); diff --git a/packages/ccsds/CcsdsPacket.cpp b/packages/ccsds/CcsdsPacket.cpp index f61684fb4..3d601cd20 100644 --- a/packages/ccsds/CcsdsPacket.cpp +++ b/packages/ccsds/CcsdsPacket.cpp @@ -38,6 +38,37 @@ #include +/****************************************************************************** + * CCSDS PACKET + ******************************************************************************/ + +/*---------------------------------------------------------------------------- + * Constructor + *----------------------------------------------------------------------------*/ +CcsdsPacket::CcsdsPacket(type_t _type): + buffer(NULL), + index(0), + is_malloced(false), + max_pkt_len(0), + pkt_type(_type) +{ +} + +/*---------------------------------------------------------------------------- + * Destructor + *----------------------------------------------------------------------------*/ +CcsdsPacket::~CcsdsPacket(void) +{ +} + +/*---------------------------------------------------------------------------- + * getType + *----------------------------------------------------------------------------*/ +CcsdsPacket::type_t CcsdsPacket::getType(void) +{ + return pkt_type; +} + /****************************************************************************** * CCSDS SPACE PACKET - PUBLIC FUNCTIONS ******************************************************************************/ @@ -77,7 +108,7 @@ CcsdsSpacePacket::CcsdsSpacePacket(uint16_t apid, int len, bool clear): CcsdsPac else { buffer = new unsigned char[len]; - initPkt(apid, len, clear); + CcsdsSpacePacket::initPkt(apid, len, clear); index = CCSDS_SPACE_HEADER_SIZE; // start after primary header is_malloced = true; max_pkt_len = len; @@ -513,8 +544,8 @@ void CcsdsSpacePacket::initPkt(int apid, int len, bool clear) index = 0; // restart at beginning of packet - setAPID(apid); - setLEN(len); + CcsdsSpacePacket::setAPID(apid); + CcsdsSpacePacket::setLEN(len); } /*---------------------------------------------------------------------------- @@ -567,14 +598,13 @@ bool CcsdsSpacePacket::validChecksum(void) const *----------------------------------------------------------------------------*/ int CcsdsSpacePacket::computeChecksum(void) const { - uint16_t len = getLEN(); - uint8_t cs = 0xFF; - int i = 0; - if(getLEN() > 7 && isCMD() && hasSHDR()) { + uint16_t len = getLEN(); if((max_pkt_len <= 0) || (len <= max_pkt_len)) { + uint8_t cs = 0xFF; + int i = 0; while (len--) { if(i != 7) @@ -708,6 +738,9 @@ int CcsdsSpacePacket::getHdrSize(void) const *----------------------------------------------------------------------------*/ CcsdsSpacePacket& CcsdsSpacePacket::operator=(const CcsdsSpacePacket& rhp) { + /* Check Self Assignment */ + if(this == &rhp) return *this; + /* Get Buffer and Buffer Length */ if(max_pkt_len < rhp.max_pkt_len) { diff --git a/packages/ccsds/CcsdsPacket.h b/packages/ccsds/CcsdsPacket.h index 28b445c0f..1baba0d50 100644 --- a/packages/ccsds/CcsdsPacket.h +++ b/packages/ccsds/CcsdsPacket.h @@ -161,9 +161,9 @@ class CcsdsPacket * Methods *--------------------------------------------------------------------*/ - CcsdsPacket (type_t _type) { pkt_type = _type; } - virtual ~CcsdsPacket (void) { } - type_t getType (void) { return pkt_type; } + CcsdsPacket (type_t _type); + virtual ~CcsdsPacket (void); + type_t getType (void); virtual int getAPID (void) const = 0; virtual void setAPID (int apid) = 0; @@ -243,8 +243,8 @@ class CcsdsSpacePacket: public CcsdsPacket CcsdsSpacePacket (unsigned char* buf, int size, bool copy=false); ~CcsdsSpacePacket (void); - int getAPID (void) const; - void setAPID (int apid); + int getAPID (void) const override; + void setAPID (int apid) override; bool hasSHDR (void) const; void setSHDR (bool value); bool isCMD (void) const; @@ -253,12 +253,12 @@ class CcsdsSpacePacket: public CcsdsPacket void setTLM (void); uint8_t getVERS (void) const; void setVERS (uint8_t value); - int getSEQ (void) const; - void setSEQ (int value); + int getSEQ (void) const override; + void setSEQ (int value) override; seg_flags_t getSEQFLG (void) const; void setSEQFLG (seg_flags_t value); - int getLEN (void) const; - void setLEN (int value); + int getLEN (void) const override; + void setLEN (int value) override; int getFunctionCode (void) const; bool setFunctionCode (uint8_t value); @@ -272,20 +272,20 @@ class CcsdsSpacePacket: public CcsdsPacket pkt_time_t getCdsTimeAsGmt (void) const; bool setCdsTime (double gps); - void initPkt (int apid, int len, bool clear); - void resetPkt (void); + void initPkt (int apid, int len, bool clear) override; + void resetPkt (void) override; bool loadChecksum (void); bool validChecksum (void) const; int computeChecksum (void) const; - bool setIndex (int offset); - int getIndex (void) const; - int appendStream (unsigned char* bytes, int len); - bool isFull (void) const; + bool setIndex (int offset) override; + int getIndex (void) const override; + int appendStream (unsigned char* bytes, int len) override; + bool isFull (void) const override; - unsigned char* getBuffer (void); - unsigned char* getPayload (void); - int getHdrSize (void) const; + unsigned char* getBuffer (void) override; + unsigned char* getPayload (void) override; + int getHdrSize (void) const override; CcsdsSpacePacket& operator= (const CcsdsSpacePacket& rhp); @@ -307,24 +307,24 @@ class CcsdsEncapPacket: public CcsdsPacket CcsdsEncapPacket (int len=CCSDS_MAX_SPACE_PACKET_SIZE); ~CcsdsEncapPacket (void); - int getAPID (void) const; - void setAPID (int apid); - int getSEQ (void) const; - void setSEQ (int value); - int getLEN (void) const; - void setLEN (int value); + int getAPID (void) const override; + void setAPID (int apid) override; + int getSEQ (void) const override; + void setSEQ (int value) override; + int getLEN (void) const override; + void setLEN (int value) override; - void initPkt (int apid, int len, bool clear); - void resetPkt (void); + void initPkt (int apid, int len, bool clear) override; + void resetPkt (void) override; - bool setIndex (int offset); - int getIndex (void) const; - int appendStream (unsigned char* bytes, int len); - bool isFull (void) const; + bool setIndex (int offset) override; + int getIndex (void) const override; + int appendStream (unsigned char* bytes, int len) override; + bool isFull (void) const override; - unsigned char* getBuffer (void); - unsigned char* getPayload (void); - int getHdrSize (void) const; + unsigned char* getBuffer (void) override; + unsigned char* getPayload (void) override; + int getHdrSize (void) const override; }; #endif /* __ccsds_packet__*/ diff --git a/packages/ccsds/CcsdsPacketInterleaver.cpp b/packages/ccsds/CcsdsPacketInterleaver.cpp index 1d07ed963..b6376b9b1 100644 --- a/packages/ccsds/CcsdsPacketInterleaver.cpp +++ b/packages/ccsds/CcsdsPacketInterleaver.cpp @@ -43,8 +43,8 @@ ******************************************************************************/ const char* CcsdsPacketInterleaver::OBJECT_TYPE = "CcsdsPacketInterleaver"; -const char* CcsdsPacketInterleaver::LuaMetaName = "CcsdsPacketInterleaver"; -const struct luaL_Reg CcsdsPacketInterleaver::LuaMetaTable[] = { +const char* CcsdsPacketInterleaver::LUA_META_NAME = "CcsdsPacketInterleaver"; +const struct luaL_Reg CcsdsPacketInterleaver::LUA_META_TABLE[] = { {"start", luaSetStartTime}, {"stop", luaSetStopTime}, {NULL, NULL} @@ -62,26 +62,32 @@ int CcsdsPacketInterleaver::luaCreate (lua_State* L) try { /* Get Input Queues */ - MgList inq_names; int inq_table_index = 1; - if(lua_istable(L, inq_table_index)) + if(!lua_istable(L, inq_table_index)) { - /* Get number of names in table */ - int num_names = lua_rawlen(L, inq_table_index); + throw RunTimeException(CRITICAL, RTE_ERROR, "Must supply table of input queues"); + } - /* Iterate through each name in table */ - for(int i = 0; i < num_names; i++) - { - /* Get name */ - lua_rawgeti(L, inq_table_index, i+1); - const char* name_str = StringLib::duplicate(getLuaString(L, -1)); + /* Get number of names in table */ + int num_names = lua_rawlen(L, inq_table_index); + if(num_names <= 0) + { + throw RunTimeException(CRITICAL, RTE_ERROR, "Must supply at least one input queue"); + } - /* Add name to list */ - inq_names.add(name_str); + /* Iterate through each name in table */ + List inq_names(num_names); + for(int i = 0; i < num_names; i++) + { + /* Get name */ + lua_rawgeti(L, inq_table_index, i+1); + string name_str(getLuaString(L, -1)); - /* Clean up stack */ - lua_pop(L, 1); - } + /* Add name to list */ + inq_names.add(name_str); + + /* Clean up stack */ + lua_pop(L, 1); } /* Get Output Queue */ @@ -104,13 +110,13 @@ int CcsdsPacketInterleaver::luaCreate (lua_State* L) /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -CcsdsPacketInterleaver::CcsdsPacketInterleaver(lua_State* L, MgList& inq_names, const char* outq_name): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) +CcsdsPacketInterleaver::CcsdsPacketInterleaver(lua_State* L, List& inq_names, const char* outq_name): + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { /* Create Input Streams */ for(int i = 0; i < inq_names.length(); i++) { - Subscriber* sub = new Subscriber(inq_names[i]); + Subscriber* sub = new Subscriber(inq_names[i].c_str()); inQs.add(sub); } @@ -133,10 +139,6 @@ CcsdsPacketInterleaver::~CcsdsPacketInterleaver(void) { active = false; delete pid; - for(int i = 0; i < inQs.length(); i++) - { - delete inQs[i]; - } delete outQ; } @@ -151,7 +153,7 @@ void* CcsdsPacketInterleaver::processorThread(void* parm) { assert(parm); - CcsdsPacketInterleaver* processor = (CcsdsPacketInterleaver*)parm; + CcsdsPacketInterleaver* processor = static_cast(parm); /* Get Number of Inputs */ int num_inputs = processor->inQs.length(); @@ -290,7 +292,7 @@ int CcsdsPacketInterleaver::luaSetStartTime (lua_State* L) try { /* Get Self */ - CcsdsPacketInterleaver* lua_obj = (CcsdsPacketInterleaver*)getLuaSelf(L, 1); + CcsdsPacketInterleaver* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* gmt_str = getLuaString(L, 2); @@ -324,7 +326,7 @@ int CcsdsPacketInterleaver::luaSetStopTime (lua_State* L) try { /* Get Self */ - CcsdsPacketInterleaver* lua_obj = (CcsdsPacketInterleaver*)getLuaSelf(L, 1); + CcsdsPacketInterleaver* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* gmt_str = getLuaString(L, 2); diff --git a/packages/ccsds/CcsdsPacketInterleaver.h b/packages/ccsds/CcsdsPacketInterleaver.h index 7ab79fb16..d1fe1397d 100644 --- a/packages/ccsds/CcsdsPacketInterleaver.h +++ b/packages/ccsds/CcsdsPacketInterleaver.h @@ -54,8 +54,8 @@ class CcsdsPacketInterleaver: public LuaObject *--------------------------------------------------------------------*/ static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -69,7 +69,7 @@ class CcsdsPacketInterleaver: public LuaObject * Methods *--------------------------------------------------------------------*/ - CcsdsPacketInterleaver (lua_State* L, MgList& inq_names, const char* outq_name); + CcsdsPacketInterleaver (lua_State* L, List& inq_names, const char* outq_name); virtual ~CcsdsPacketInterleaver (void); private: diff --git a/packages/ccsds/CcsdsPacketParser.cpp b/packages/ccsds/CcsdsPacketParser.cpp index a2c94a52a..ffe577ff8 100644 --- a/packages/ccsds/CcsdsPacketParser.cpp +++ b/packages/ccsds/CcsdsPacketParser.cpp @@ -44,8 +44,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsPacketParser::LuaMetaName = "CcsdsPacketParser"; -const struct luaL_Reg CcsdsPacketParser::LuaMetaTable[] = { +const char* CcsdsPacketParser::LUA_META_NAME = "CcsdsPacketParser"; +const struct luaL_Reg CcsdsPacketParser::LUA_META_TABLE[] = { {"passinvalid", luaPassInvalid}, {"resetinvalid",luaResetInvalid}, {"stats", luaLogPktStats}, @@ -67,7 +67,7 @@ int CcsdsPacketParser::luaCreate (lua_State* L) try { /* Get Parameters */ - CcsdsParserModule* _parser = (CcsdsParserModule*)getLuaObject(L, 1, CcsdsParserModule::OBJECT_TYPE); + CcsdsParserModule* _parser = dynamic_cast(getLuaObject(L, 1, CcsdsParserModule::OBJECT_TYPE)); const char* type_str = getLuaString(L, 2); const char* inq_name = getLuaString(L, 3); const char* outq_name = getLuaString(L, 4, true, NULL); @@ -85,7 +85,7 @@ int CcsdsPacketParser::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -98,7 +98,7 @@ int CcsdsPacketParser::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ CcsdsPacketParser::CcsdsPacketParser(lua_State* L, CcsdsParserModule* _parser, CcsdsPacket::type_t _type, const char* inq_name, const char* outq_name, const char* statq_name): - MsgProcessor(L, inq_name, LuaMetaName, LuaMetaTable) + MsgProcessor(L, inq_name, LUA_META_NAME, LUA_META_TABLE) { assert(_parser); assert(inq_name); @@ -187,7 +187,7 @@ int CcsdsPacketParser::luaPassInvalid (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool pass_invalid = getLuaBoolean(L, 2); @@ -217,7 +217,7 @@ int CcsdsPacketParser::luaResetInvalid (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool reset_invalid = getLuaBoolean(L, 2); @@ -248,7 +248,7 @@ int CcsdsPacketParser::luaLogPktStats (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ long apid = getLuaInteger(L, 2); @@ -328,7 +328,7 @@ int CcsdsPacketParser::luaFilterPkt (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool enable = getLuaBoolean(L, 2); @@ -376,7 +376,7 @@ int CcsdsPacketParser::luaClearApidStats (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ int apid = getLuaInteger(L, 2); @@ -420,7 +420,7 @@ int CcsdsPacketParser::luaStripHdrOnPost (lua_State* L) try { /* Get Self */ - CcsdsPacketParser* lua_obj = (CcsdsPacketParser*)getLuaSelf(L, 1); + CcsdsPacketParser* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool strip_hdr = getLuaBoolean(L, 2); @@ -590,16 +590,17 @@ bool CcsdsPacketParser::processMsg (unsigned char* msg, int bytes) *----------------------------------------------------------------------------*/ void* CcsdsPacketParser::telemetry_thread (void* parm) { - double now = 0.0, last = 0.0, elapsed = 0.0; + double now = 0.0; + double elapsed = 0.0; - CcsdsPacketParser* parser = (CcsdsPacketParser*)parm; + CcsdsPacketParser* parser = static_cast(parm); while(parser->telemetryActive) { OsApi::sleep(parser->telemetryWaitSeconds); /* Calculate Elapsed Time */ - last = now; + double last = now; now = TimeLib::latchtime(); if(last == 0.0) continue; // skip first cycle elapsed = now - last; diff --git a/packages/ccsds/CcsdsPacketParser.h b/packages/ccsds/CcsdsPacketParser.h index f198d9652..3f90eff72 100644 --- a/packages/ccsds/CcsdsPacketParser.h +++ b/packages/ccsds/CcsdsPacketParser.h @@ -54,8 +54,8 @@ class CcsdsPacketParser: public MsgProcessor * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const unsigned int IGNORE_LENGTH = 0; static const unsigned int MAX_ALLOWED_PKT_LENGTH = 0xFFFF; diff --git a/packages/ccsds/CcsdsPacketizer.cpp b/packages/ccsds/CcsdsPacketizer.cpp index 185fbcb79..e2d4e8a89 100644 --- a/packages/ccsds/CcsdsPacketizer.cpp +++ b/packages/ccsds/CcsdsPacketizer.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsPacketizer::LuaMetaName = "CcsdsPacketizer"; -const struct luaL_Reg CcsdsPacketizer::LuaMetaTable[] = { +const char* CcsdsPacketizer::LUA_META_NAME = "CcsdsPacketizer"; +const struct luaL_Reg CcsdsPacketizer::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -69,7 +69,7 @@ int CcsdsPacketizer::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -82,7 +82,7 @@ int CcsdsPacketizer::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ CcsdsPacketizer::CcsdsPacketizer(lua_State* L, const char* inq_name, const char* outq_name, int _pkttype, uint16_t _apid, uint8_t _fc, uint16_t _len): - MsgProcessor(L, inq_name, LuaMetaName, LuaMetaTable) + MsgProcessor(L, inq_name, LUA_META_NAME, LUA_META_TABLE) { pktType = _pkttype; apid = _apid; diff --git a/packages/ccsds/CcsdsPacketizer.h b/packages/ccsds/CcsdsPacketizer.h index 30be17e66..83703cdef 100644 --- a/packages/ccsds/CcsdsPacketizer.h +++ b/packages/ccsds/CcsdsPacketizer.h @@ -53,8 +53,8 @@ class CcsdsPacketizer: public MsgProcessor * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const uint16_t DEFAULT_MAX_PACKET_SIZE = 2048; static const int TLM_PKT = 0; @@ -91,7 +91,7 @@ class CcsdsPacketizer: public MsgProcessor CcsdsPacketizer (lua_State* L, const char* inq_name, const char* outq_name, int _pkttype, uint16_t _apid, uint8_t _fc, uint16_t _len=DEFAULT_MAX_PACKET_SIZE); ~CcsdsPacketizer (void); - bool processMsg (unsigned char* msg, int bytes); // OVERLOAD + bool processMsg (unsigned char* msg, int bytes) override; }; diff --git a/packages/ccsds/CcsdsParserAOSFrameModule.cpp b/packages/ccsds/CcsdsParserAOSFrameModule.cpp index 43dcff2c9..c3ec4f914 100644 --- a/packages/ccsds/CcsdsParserAOSFrameModule.cpp +++ b/packages/ccsds/CcsdsParserAOSFrameModule.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsParserAOSFrameModule::LuaMetaName = "CcsdsParserAOSFrameModule"; -const struct luaL_Reg CcsdsParserAOSFrameModule::LuaMetaTable[] = { +const char* CcsdsParserAOSFrameModule::LUA_META_NAME = "CcsdsParserAOSFrameModule"; +const struct luaL_Reg CcsdsParserAOSFrameModule::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -110,7 +110,7 @@ int CcsdsParserAOSFrameModule::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -400,7 +400,7 @@ void CcsdsParserAOSFrameModule::gotoInitState(bool reset) * Constructor *----------------------------------------------------------------------------*/ CcsdsParserAOSFrameModule::CcsdsParserAOSFrameModule(lua_State* L, int scid, int vcid, int strip_size, uint8_t* sync_marker, int sync_size, int sync_offset, int fixed_size, int header_size, int trailer_size): - CcsdsParserModule(L, LuaMetaName, LuaMetaTable) + CcsdsParserModule(L, LUA_META_NAME, LUA_META_TABLE) { SpacecraftId = scid; VirtualChannel = vcid; @@ -426,7 +426,10 @@ CcsdsParserAOSFrameModule::CcsdsParserAOSFrameModule(lua_State* L, int scid, int inSync = true; - gotoInitState(true); + mpduOffset = 0; + frameCRC = 0; + + CcsdsParserAOSFrameModule::gotoInitState(true); } /*---------------------------------------------------------------------------- diff --git a/packages/ccsds/CcsdsParserAOSFrameModule.h b/packages/ccsds/CcsdsParserAOSFrameModule.h index 5fb6a7646..d41bfdbe4 100644 --- a/packages/ccsds/CcsdsParserAOSFrameModule.h +++ b/packages/ccsds/CcsdsParserAOSFrameModule.h @@ -53,8 +53,8 @@ class CcsdsParserAOSFrameModule: public CcsdsParserModule *--------------------------------------------------------------------*/ static int luaCreate (lua_State* L); - int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt); // returns number of bytes consumed - void gotoInitState (bool reset); + int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt) override; // returns number of bytes consumed + void gotoInitState (bool reset) override; protected: @@ -77,8 +77,8 @@ class CcsdsParserAOSFrameModule: public CcsdsParserModule static const int FRAME_COUNTER_UNSET = -2; static const int FRAME_MPDU_CONTINUE = 0xFFFF; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types diff --git a/packages/ccsds/CcsdsParserModule.cpp b/packages/ccsds/CcsdsParserModule.cpp index dc8f42e88..48501357a 100644 --- a/packages/ccsds/CcsdsParserModule.cpp +++ b/packages/ccsds/CcsdsParserModule.cpp @@ -41,8 +41,8 @@ ******************************************************************************/ const char* CcsdsParserModule::OBJECT_TYPE = "CcsdsParserModule"; -const char* CcsdsParserModule::LuaMetaName = "CcsdsParserModule"; -const struct luaL_Reg CcsdsParserModule::LuaMetaTable[] = { +const char* CcsdsParserModule::LUA_META_NAME = "CcsdsParserModule"; +const struct luaL_Reg CcsdsParserModule::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -62,7 +62,7 @@ int CcsdsParserModule::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -75,9 +75,9 @@ int CcsdsParserModule::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ CcsdsParserModule::CcsdsParserModule(lua_State* L): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { - gotoInitState(true); + CcsdsParserModule::gotoInitState(true); } /*---------------------------------------------------------------------------- @@ -86,7 +86,7 @@ CcsdsParserModule::CcsdsParserModule(lua_State* L): CcsdsParserModule::CcsdsParserModule(lua_State* L, const char* meta_name, const struct luaL_Reg meta_table[]): LuaObject(L, OBJECT_TYPE, meta_name, meta_table) { - gotoInitState(true); + CcsdsParserModule::gotoInitState(true); } /*---------------------------------------------------------------------------- diff --git a/packages/ccsds/CcsdsParserModule.h b/packages/ccsds/CcsdsParserModule.h index 3510a74d5..e53e80c1d 100644 --- a/packages/ccsds/CcsdsParserModule.h +++ b/packages/ccsds/CcsdsParserModule.h @@ -70,9 +70,9 @@ class CcsdsParserModule: public LuaObject * Methods *--------------------------------------------------------------------*/ - CcsdsParserModule (lua_State* L); - CcsdsParserModule (lua_State* L, const char* meta_name, const struct luaL_Reg meta_table[]); - ~CcsdsParserModule (void); + explicit CcsdsParserModule (lua_State* L); + CcsdsParserModule (lua_State* L, const char* meta_name, const struct luaL_Reg meta_table[]); + ~CcsdsParserModule (void); private: @@ -80,8 +80,8 @@ class CcsdsParserModule: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; }; #endif /* __ccsds_parser_module__ */ diff --git a/packages/ccsds/CcsdsParserStripModule.cpp b/packages/ccsds/CcsdsParserStripModule.cpp index 3fe192d12..8ecde1916 100644 --- a/packages/ccsds/CcsdsParserStripModule.cpp +++ b/packages/ccsds/CcsdsParserStripModule.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsParserStripModule::LuaMetaName = "CcsdsParserStripModule"; -const struct luaL_Reg CcsdsParserStripModule::LuaMetaTable[] = { +const char* CcsdsParserStripModule::LUA_META_NAME = "CcsdsParserStripModule"; +const struct luaL_Reg CcsdsParserStripModule::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -64,7 +64,7 @@ int CcsdsParserStripModule::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -150,10 +150,10 @@ void CcsdsParserStripModule::gotoInitState(bool reset) * Constructor *----------------------------------------------------------------------------*/ CcsdsParserStripModule::CcsdsParserStripModule(lua_State* L, int header_size): - CcsdsParserModule(L, LuaMetaName, LuaMetaTable), + CcsdsParserModule(L, LUA_META_NAME, LUA_META_TABLE), HDR_SIZE(header_size) { - gotoInitState(true); + CcsdsParserStripModule::gotoInitState(true); } /*---------------------------------------------------------------------------- diff --git a/packages/ccsds/CcsdsParserStripModule.h b/packages/ccsds/CcsdsParserStripModule.h index 199dda5e0..ceaa39dd4 100644 --- a/packages/ccsds/CcsdsParserStripModule.h +++ b/packages/ccsds/CcsdsParserStripModule.h @@ -53,8 +53,8 @@ class CcsdsParserStripModule: public CcsdsParserModule *--------------------------------------------------------------------*/ static int luaCreate (lua_State* L); - int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt); // returns number of bytes consumed - void gotoInitState (bool reset); + int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt) override; // returns number of bytes consumed + void gotoInitState (bool reset) override; private: @@ -62,8 +62,8 @@ class CcsdsParserStripModule: public CcsdsParserModule * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types diff --git a/packages/ccsds/CcsdsParserZFrameModule.cpp b/packages/ccsds/CcsdsParserZFrameModule.cpp index 6e5dba3ae..38d7489a8 100644 --- a/packages/ccsds/CcsdsParserZFrameModule.cpp +++ b/packages/ccsds/CcsdsParserZFrameModule.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsParserZFrameModule::LuaMetaName = "CcsdsParserZFrameModule"; -const struct luaL_Reg CcsdsParserZFrameModule::LuaMetaTable[] = { +const char* CcsdsParserZFrameModule::LUA_META_NAME = "CcsdsParserZFrameModule"; +const struct luaL_Reg CcsdsParserZFrameModule::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -64,7 +64,7 @@ int CcsdsParserZFrameModule::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -86,10 +86,6 @@ int CcsdsParserZFrameModule::parseBuffer (unsigned char* buffer, int bytes, Ccsd if(state == FRAME_Z) { - /* Synchronization Data for Start of Frame */ - const char* frame_sync = "CCSD3ZA00001"; - #define FRAME_SYNC_SIZE 12 // size of above string - /* Copy into Frame Buffer */ int cpylen = MIN(frameZBytes, bytes_left); memcpy(&frameBuffer[frameIndex], &parse_buffer[parse_index], cpylen); @@ -100,6 +96,10 @@ int CcsdsParserZFrameModule::parseBuffer (unsigned char* buffer, int bytes, Ccsd /* Pull off Z header */ if(frameZBytes == 0) { + /* Synchronization Data for Start of Frame */ + const char* frame_sync = "CCSD3ZA00001"; + #define FRAME_SYNC_SIZE 12 // size of above string + /* Compare Sync Mark */ if(!StringLib::match(frame_sync, frameBuffer, FRAME_SYNC_SIZE)) { @@ -271,10 +271,10 @@ void CcsdsParserZFrameModule::gotoInitState(bool reset) * Constructor *----------------------------------------------------------------------------*/ CcsdsParserZFrameModule::CcsdsParserZFrameModule(lua_State* L, bool file): - CcsdsParserModule(L, LuaMetaName, LuaMetaTable) + CcsdsParserModule(L, LUA_META_NAME, LUA_META_TABLE) { frameFile = file; - gotoInitState(true); + CcsdsParserZFrameModule::gotoInitState(true); } /*---------------------------------------------------------------------------- diff --git a/packages/ccsds/CcsdsParserZFrameModule.h b/packages/ccsds/CcsdsParserZFrameModule.h index 49c4e1776..366a38fab 100644 --- a/packages/ccsds/CcsdsParserZFrameModule.h +++ b/packages/ccsds/CcsdsParserZFrameModule.h @@ -53,8 +53,8 @@ class CcsdsParserZFrameModule: public CcsdsParserModule *--------------------------------------------------------------------*/ static int luaCreate (lua_State* L); - int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt); // returns number of bytes consumed - void gotoInitState (bool reset); + int parseBuffer (unsigned char* buffer, int bytes, CcsdsPacket* pkt) override; // returns number of bytes consumed + void gotoInitState (bool reset) override; private: @@ -67,8 +67,8 @@ class CcsdsParserZFrameModule: public CcsdsParserModule static const unsigned int FRAME_FANN_SIZE = 58; static const unsigned int FRAME_CXXX_SIZE = 20; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types diff --git a/packages/ccsds/CcsdsPayloadDispatch.cpp b/packages/ccsds/CcsdsPayloadDispatch.cpp index e8846e553..916388d70 100644 --- a/packages/ccsds/CcsdsPayloadDispatch.cpp +++ b/packages/ccsds/CcsdsPayloadDispatch.cpp @@ -41,8 +41,8 @@ * STATIC DATA ******************************************************************************/ -const char* CcsdsPayloadDispatch::LuaMetaName = "CcsdsPayloadDispatch"; -const struct luaL_Reg CcsdsPayloadDispatch::LuaMetaTable[] = { +const char* CcsdsPayloadDispatch::LUA_META_NAME = "CcsdsPayloadDispatch"; +const struct luaL_Reg CcsdsPayloadDispatch::LUA_META_TABLE[] = { {"forward", luaForwardPacket}, {"checklen", luaCheckLength}, {"checkcs", luaCheckChecksum}, @@ -65,7 +65,7 @@ int CcsdsPayloadDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -140,7 +140,7 @@ bool CcsdsPayloadDispatch::processRecord(RecordObject* record, okey_t key, recVe * Constructor *----------------------------------------------------------------------------*/ CcsdsPayloadDispatch::CcsdsPayloadDispatch(lua_State* L): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { memset(outQ, 0, sizeof(outQ)); checkLength = false; @@ -173,13 +173,13 @@ void CcsdsPayloadDispatch::setPublisher (int apid, const char* qname) { try { - pub = qLookUp[qname]; + pub = qLookUp[qname].pub; } catch(RunTimeException& e) { (void)e; - pub = new Publisher(qname); - qLookUp.add(qname, pub); + pub_t pub_lookup = { .pub = new Publisher(qname) }; + qLookUp.add(qname, pub_lookup); } } @@ -223,7 +223,7 @@ int CcsdsPayloadDispatch::luaForwardPacket(lua_State* L) try { /* Get Self */ - CcsdsPayloadDispatch* lua_obj = (CcsdsPayloadDispatch*)getLuaSelf(L, 1); + CcsdsPayloadDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ long apid = getLuaInteger(L, 1); @@ -268,7 +268,7 @@ int CcsdsPayloadDispatch::luaCheckLength(lua_State* L) try { /* Get Self */ - CcsdsPayloadDispatch* lua_obj = (CcsdsPayloadDispatch*)getLuaSelf(L, 1); + CcsdsPayloadDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool enable = getLuaBoolean(L, 2); @@ -298,7 +298,7 @@ int CcsdsPayloadDispatch::luaCheckChecksum(lua_State* L) try { /* Get Self */ - CcsdsPayloadDispatch* lua_obj = (CcsdsPayloadDispatch*)getLuaSelf(L, 1); + CcsdsPayloadDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool enable = getLuaBoolean(L, 2); diff --git a/packages/ccsds/CcsdsPayloadDispatch.h b/packages/ccsds/CcsdsPayloadDispatch.h index 909f0c89f..29edadb03 100644 --- a/packages/ccsds/CcsdsPayloadDispatch.h +++ b/packages/ccsds/CcsdsPayloadDispatch.h @@ -55,8 +55,8 @@ class CcsdsPayloadDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -67,11 +67,19 @@ class CcsdsPayloadDispatch: public DispatchObject private: + /*-------------------------------------------------------------------- + * Types + *--------------------------------------------------------------------*/ + + typedef struct { + Publisher* pub; + } pub_t; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - Dictionary qLookUp; // qLookUp[qname] ==> Publisher* , this prevents multiple publishers to same queue + Dictionary qLookUp; // qLookUp[qname] ==> Publisher* , this prevents multiple publishers to same queue Publisher* outQ[CCSDS_NUM_APIDS]; Mutex qMut; bool checkLength; @@ -81,7 +89,7 @@ class CcsdsPayloadDispatch: public DispatchObject * Methods *--------------------------------------------------------------------*/ - CcsdsPayloadDispatch (lua_State* L); + explicit CcsdsPayloadDispatch (lua_State* L); ~CcsdsPayloadDispatch (void); void setPublisher (int apid, const char* qname); diff --git a/packages/ccsds/CcsdsRecord.cpp b/packages/ccsds/CcsdsRecord.cpp index f90256a3b..fa0886e48 100644 --- a/packages/ccsds/CcsdsRecord.cpp +++ b/packages/ccsds/CcsdsRecord.cpp @@ -40,7 +40,7 @@ * CCSDS RECORD: STATIC DATA ******************************************************************************/ -MgDictionary CcsdsRecord::pktDefs; +CcsdsRecord::PktDefDictionary CcsdsRecord::pktDefs; CcsdsRecord::pktDef_t* CcsdsRecord::pktCrossRefs[PKT_CROSS_REF_TBL_SIZE]; Mutex CcsdsRecord::pktMut; @@ -307,6 +307,7 @@ RecordObject::recordDefErr_t CcsdsRecord::defineTelemetry(const char* rec_type, *----------------------------------------------------------------------------*/ CcsdsRecord::CcsdsRecord(void): RecordObject() { + pktDef = NULL; } /*---------------------------------------------------------------------------- diff --git a/packages/ccsds/CcsdsRecord.h b/packages/ccsds/CcsdsRecord.h index 1d1dbf60b..40540a8b2 100644 --- a/packages/ccsds/CcsdsRecord.h +++ b/packages/ccsds/CcsdsRecord.h @@ -70,12 +70,12 @@ class CcsdsRecord: public RecordObject * Methods *--------------------------------------------------------------------*/ - CcsdsRecord (const char* rec_type); + explicit CcsdsRecord (const char* rec_type); CcsdsRecord (unsigned char* buffer, int size); /* Overloaded Methods */ - bool deserialize (unsigned char* buffer, int size); - int serialize (unsigned char** buffer, serialMode_t mode=ALLOCATE, int size=0); + bool deserialize (unsigned char* buffer, int size) override; + int serialize (unsigned char** buffer, serialMode_t mode=ALLOCATE, int size=0) override; /* Regular Methods */ pktType_t getPktType (void); @@ -102,11 +102,13 @@ class CcsdsRecord: public RecordObject int size; } pktDef_t; + typedef Dictionary PktDefDictionary; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static MgDictionary pktDefs; + static PktDefDictionary pktDefs; static pktDef_t* pktCrossRefs[PKT_CROSS_REF_TBL_SIZE]; // FC[17:11], APID[10:0] static Mutex pktMut; diff --git a/packages/ccsds/CcsdsRecordDispatcher.cpp b/packages/ccsds/CcsdsRecordDispatcher.cpp index 11b83953b..c6274bb06 100644 --- a/packages/ccsds/CcsdsRecordDispatcher.cpp +++ b/packages/ccsds/CcsdsRecordDispatcher.cpp @@ -62,7 +62,7 @@ int CcsdsRecordDispatcher::luaCreate (lua_State* L) /* Set Key Mode */ keyMode_t key_mode = str2mode(key_mode_str); const char* key_field = NULL; - calcFunc_t key_func = NULL; + calcFunc_f key_func = NULL; if(key_mode == INVALID_KEY_MODE) { throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid key mode specified: %s", key_mode_str); @@ -74,7 +74,7 @@ int CcsdsRecordDispatcher::luaCreate (lua_State* L) else if(key_mode == CALCULATED_KEY_MODE) { const char* key_func_str = getLuaString(L, 4); - key_func = keyCalcFunctions[key_func_str]; + key_func = keyCalcFunctions[key_func_str].calc; } /* Create Record Dispatcher */ @@ -82,7 +82,7 @@ int CcsdsRecordDispatcher::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -94,7 +94,7 @@ int CcsdsRecordDispatcher::luaCreate (lua_State* L) /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -CcsdsRecordDispatcher::CcsdsRecordDispatcher(lua_State* L, const char* inputq_name, keyMode_t key_mode, const char* key_field, calcFunc_t key_func, int num_threads): +CcsdsRecordDispatcher::CcsdsRecordDispatcher(lua_State* L, const char* inputq_name, keyMode_t key_mode, const char* key_field, calcFunc_f key_func, int num_threads): RecordDispatcher(L, inputq_name, key_mode, key_field, key_func, num_threads, MsgQ::SUBSCRIBER_OF_CONFIDENCE) { } diff --git a/packages/ccsds/CcsdsRecordDispatcher.h b/packages/ccsds/CcsdsRecordDispatcher.h index d08e7e3b3..acec29cd1 100644 --- a/packages/ccsds/CcsdsRecordDispatcher.h +++ b/packages/ccsds/CcsdsRecordDispatcher.h @@ -58,10 +58,10 @@ class CcsdsRecordDispatcher: public RecordDispatcher * Methods *--------------------------------------------------------------------*/ - CcsdsRecordDispatcher (lua_State* L, const char* inputq_name, keyMode_t key_mode, const char* key_field, calcFunc_t key_func, int num_threads); + CcsdsRecordDispatcher (lua_State* L, const char* inputq_name, keyMode_t key_mode, const char* key_field, calcFunc_f key_func, int num_threads); ~CcsdsRecordDispatcher (void); - RecordObject* createRecord (unsigned char* buffer, int size); + RecordObject* createRecord (unsigned char* buffer, int size) override; }; #endif /* __ccsds_record_dispatcher__ */ diff --git a/packages/core/Asset.cpp b/packages/core/Asset.cpp index 31cb4dc2f..8e3669a76 100644 --- a/packages/core/Asset.cpp +++ b/packages/core/Asset.cpp @@ -46,8 +46,8 @@ ******************************************************************************/ const char* Asset::OBJECT_TYPE = "Asset"; -const char* Asset::LuaMetaName = "Asset"; -const struct luaL_Reg Asset::LuaMetaTable[] = { +const char* Asset::LUA_META_NAME = "Asset"; +const struct luaL_Reg Asset::LUA_META_TABLE[] = { {"info", luaInfo}, {"load", luaLoad}, {NULL, NULL} @@ -60,8 +60,6 @@ Dictionary Asset::ioDrivers; * VOID IO DRIVER CLASS ******************************************************************************/ -const char* Asset::IODriver::FORMAT = "nil"; - /*---------------------------------------------------------------------------- * create *----------------------------------------------------------------------------*/ @@ -120,68 +118,41 @@ int Asset::luaCreate (lua_State* L) _attributes.endpoint = getLuaString(L, 7, true, NULL); /* Get IO Driver */ - io_driver_t _io_driver = NULL; + io_driver_t _driver; + bool found = false; ioDriverMut.lock(); { - ioDrivers.find(_attributes.driver, &_io_driver); + found = ioDrivers.find(_attributes.driver, &_driver); } ioDriverMut.unlock(); /* Check Driver */ - if(_io_driver == NULL) + if(!found) { mlog(CRITICAL, "Failed to find I/O driver for %s, using default driver", _attributes.driver); - _io_driver = Asset::IODriver::create; // set it to the default + _driver.factory = Asset::IODriver::create; // set it to the default } /* Return Asset Object */ - return createLuaObject(L, new Asset(L, _attributes, _io_driver)); + return createLuaObject(L, new Asset(L, _attributes, _driver)); } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } -/*---------------------------------------------------------------------------- - * pythonCreate - *----------------------------------------------------------------------------*/ -Asset* Asset::pythonCreate (const char* name, const char* identity, const char* driver, const char* path, const char* index, const char* region, const char* endpoint) -{ - attributes_t _attributes; - - /* Get Parameters */ - _attributes.name = name; - _attributes.identity = identity; - _attributes.driver = driver; - _attributes.path = path; - _attributes.index = index; - _attributes.region = region; - _attributes.endpoint = endpoint; - - /* Get IO Driver */ - io_driver_t _io_driver = NULL; - ioDriverMut.lock(); - { - ioDrivers.find(_attributes.driver, &_io_driver); - } - ioDriverMut.unlock(); - - /* Return Asset Object */ - if(_io_driver == NULL) return NULL; - else return new Asset(NULL, _attributes, _io_driver); -} - /*---------------------------------------------------------------------------- * registerDriver *----------------------------------------------------------------------------*/ -bool Asset::registerDriver (const char* _format, io_driver_t driver) +bool Asset::registerDriver (const char* _format, io_driver_f factory) { bool status; ioDriverMut.lock(); { + io_driver_t driver = { .factory = factory }; status = ioDrivers.add(_format, driver); } ioDriverMut.unlock(); @@ -194,8 +165,8 @@ bool Asset::registerDriver (const char* _format, io_driver_t driver) *----------------------------------------------------------------------------*/ Asset::IODriver* Asset::createDriver (const char* resource) const { - if(io_driver) return io_driver(this, resource); - else return NULL; + if(driver.factory) return driver.factory(this, resource); + return NULL; } /*---------------------------------------------------------------------------- @@ -203,13 +174,13 @@ Asset::IODriver* Asset::createDriver (const char* resource) const *----------------------------------------------------------------------------*/ Asset::~Asset (void) { - if(attributes.name) delete [] attributes.name; - if(attributes.identity) delete [] attributes.identity; - if(attributes.driver) delete [] attributes.driver; - if(attributes.path) delete [] attributes.path; - if(attributes.index) delete [] attributes.index; - if(attributes.region) delete [] attributes.region; - if(attributes.endpoint) delete [] attributes.endpoint; + delete [] attributes.name; + delete [] attributes.identity; + delete [] attributes.driver; + delete [] attributes.path; + delete [] attributes.index; + delete [] attributes.region; + delete [] attributes.endpoint; } /*---------------------------------------------------------------------------- @@ -295,8 +266,10 @@ const char* Asset::getEndpoint (void) const /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -Asset::Asset (lua_State* L, attributes_t _attributes, io_driver_t _io_driver): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) +Asset::Asset (lua_State* L, attributes_t _attributes, const io_driver_t& _driver): + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), + driver(_driver), + resources(ASSET_STARTING_RESOURCES_PER_INDEX) { attributes.name = StringLib::duplicate(_attributes.name); attributes.identity = StringLib::duplicate(_attributes.identity); @@ -305,7 +278,6 @@ Asset::Asset (lua_State* L, attributes_t _attributes, io_driver_t _io_driver): attributes.index = StringLib::duplicate(_attributes.index); attributes.region = StringLib::duplicate(_attributes.region); attributes.endpoint = StringLib::duplicate(_attributes.endpoint); - io_driver = _io_driver; } /*---------------------------------------------------------------------------- @@ -318,7 +290,7 @@ int Asset::luaInfo (lua_State* L) try { /* Get Self */ - Asset* lua_obj = (Asset*)getLuaSelf(L, 1); + Asset* lua_obj = dynamic_cast(getLuaSelf(L, 1)); attributes_t* attr = &lua_obj->attributes; /* Push Info */ @@ -352,7 +324,7 @@ int Asset::luaLoad (lua_State* L) try { /* Get Self */ - Asset* lua_obj = (Asset*)getLuaSelf(L, 1); + Asset* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Resource */ const char* resource_name = getLuaString(L, 2); diff --git a/packages/core/Asset.h b/packages/core/Asset.h index 57263bff1..0dfb4d63a 100644 --- a/packages/core/Asset.h +++ b/packages/core/Asset.h @@ -67,7 +67,6 @@ class Asset: public LuaObject class IODriver { public: - static const char* FORMAT; static IODriver* create (const Asset* _asset, const char* resource); IODriver (void); virtual ~IODriver (void); @@ -90,15 +89,18 @@ class Asset: public LuaObject Dictionary attributes{ASSET_STARTING_ATTRIBUTES_PER_RESOURCE}; } resource_t; - typedef IODriver* (*io_driver_t) (const Asset* _asset, const char* resource); + typedef IODriver* (*io_driver_f) (const Asset* _asset, const char* resource); + + typedef struct { + io_driver_f factory; + } io_driver_t; /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ static int luaCreate (lua_State* L); - static Asset* pythonCreate (const char* name, const char* identity, const char* driver, const char* path, const char* index, const char* region, const char* endpoint); - static bool registerDriver (const char* _format, io_driver_t driver); + static bool registerDriver (const char* _format, io_driver_f factory); IODriver* createDriver (const char* resource) const; @@ -122,8 +124,8 @@ class Asset: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Typedefs @@ -147,15 +149,15 @@ class Asset: public LuaObject static Dictionary ioDrivers; attributes_t attributes; - io_driver_t io_driver; + io_driver_t driver; - List resources; + List resources; /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ - Asset (lua_State* L, attributes_t _attributes, io_driver_t _io_driver); + Asset (lua_State* L, attributes_t _attributes, const io_driver_t& _io_driver); static int luaInfo (lua_State* L); static int luaLoad (lua_State* L); diff --git a/packages/core/AssetIndex.h b/packages/core/AssetIndex.h index ec240d800..310bfb662 100644 --- a/packages/core/AssetIndex.h +++ b/packages/core/AssetIndex.h @@ -365,13 +365,15 @@ void AssetIndex::buildtree (node_t* root, int* maxdepth) if(root_size >= threshold) { /* Split Node */ - T lspan, rspan; + T lspan; + T rspan; split(root, lspan, rspan); node_t* lnode = newnode(lspan); node_t* rnode = newnode(rspan); /* Split Resources on Both Leaves */ - int lcnt = 0, rcnt = 0; + int lcnt = 0; + int rcnt = 0; for(int j = 0; j < root_size; j++) { int resource_index = root->ril->get(j); @@ -454,11 +456,13 @@ void AssetIndex::updatenode (int i, node_t** node, int* maxdepth) if(node_size >= threshold) { /* Split Node */ - T lspan, rspan; + T lspan; + T rspan; split(curr, lspan, rspan); /* Preview Split Resources on Both Leaves */ - int lcnt = 0, rcnt = 0; + int lcnt = 0; + int rcnt = 0; for(int j = 0; j < node_size; j++) { int resource_index = curr->ril->get(j); @@ -659,7 +663,7 @@ void AssetIndex::deletenode (node_t* node) node_t* right = node->right; /* Delete Node */ - if(node->ril) delete node->ril; + delete node->ril; delete node; /* Recurse */ diff --git a/packages/core/CMakeLists.txt b/packages/core/CMakeLists.txt index f13cd89c9..59b89b63d 100644 --- a/packages/core/CMakeLists.txt +++ b/packages/core/CMakeLists.txt @@ -48,6 +48,7 @@ target_sources (slideruleLib ${CMAKE_CURRENT_LIST_DIR}/MsgProcessor.cpp ${CMAKE_CURRENT_LIST_DIR}/MsgQ.cpp ${CMAKE_CURRENT_LIST_DIR}/PublisherDispatch.cpp + ${CMAKE_CURRENT_LIST_DIR}/PublishMonitor.cpp ${CMAKE_CURRENT_LIST_DIR}/RecordObject.cpp ${CMAKE_CURRENT_LIST_DIR}/RecordDispatcher.cpp ${CMAKE_CURRENT_LIST_DIR}/ReportDispatch.cpp @@ -107,6 +108,7 @@ install ( ${CMAKE_CURRENT_LIST_DIR}/MsgQ.h ${CMAKE_CURRENT_LIST_DIR}/Ordering.h ${CMAKE_CURRENT_LIST_DIR}/PublisherDispatch.h + ${CMAKE_CURRENT_LIST_DIR}/PublishMonitor.h ${CMAKE_CURRENT_LIST_DIR}/RecordObject.h ${CMAKE_CURRENT_LIST_DIR}/RecordDispatcher.h ${CMAKE_CURRENT_LIST_DIR}/ReportDispatch.h diff --git a/packages/core/CaptureDispatch.cpp b/packages/core/CaptureDispatch.cpp index 1d66f75ac..fcec44a1d 100644 --- a/packages/core/CaptureDispatch.cpp +++ b/packages/core/CaptureDispatch.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CaptureDispatch::LuaMetaName = "CaptureDispatch"; -const struct luaL_Reg CaptureDispatch::LuaMetaTable[] = { +const char* CaptureDispatch::LUA_META_NAME = "CaptureDispatch"; +const struct luaL_Reg CaptureDispatch::LUA_META_TABLE[] = { {"capture", luaCapture}, {"clear", luaClear}, {"remove", luaRemove}, @@ -67,7 +67,7 @@ int CaptureDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -80,8 +80,7 @@ int CaptureDispatch::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ CaptureDispatch::CaptureDispatch (lua_State* L, const char* outq_name): - DispatchObject(L, LuaMetaName, LuaMetaTable) - + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { outQ = NULL; if(outq_name) outQ = new Publisher(outq_name); @@ -92,7 +91,7 @@ CaptureDispatch::CaptureDispatch (lua_State* L, const char* outq_name): *----------------------------------------------------------------------------*/ CaptureDispatch::~CaptureDispatch (void) { - if(outQ) delete outQ; + delete outQ; } /*---------------------------------------------------------------------------- @@ -103,7 +102,7 @@ void CaptureDispatch::freeCaptureEntry (void* obj, void* parm) (void)parm; if(obj) { - capture_t* entry = (capture_t*)obj; + capture_t* entry = static_cast(obj); delete entry; } } @@ -165,7 +164,7 @@ int CaptureDispatch::luaCapture (lua_State* L) try { /* Get Self */ - CaptureDispatch* lua_obj = (CaptureDispatch*)getLuaSelf(L, 1); + CaptureDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool filter = false; @@ -227,7 +226,7 @@ int CaptureDispatch::luaClear (lua_State* L) try { /* Get Self */ - CaptureDispatch* lua_obj = (CaptureDispatch*)getLuaSelf(L, 1); + CaptureDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Clear All Captures */ lua_obj->capMut.lock(); @@ -258,7 +257,7 @@ int CaptureDispatch::luaRemove (lua_State* L) try { /* Get Self */ - CaptureDispatch* lua_obj = (CaptureDispatch*)getLuaSelf(L, 1); + CaptureDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* field_str = getLuaString(L, 2); diff --git a/packages/core/CaptureDispatch.h b/packages/core/CaptureDispatch.h index 3efdb3fdb..bde7e9995 100644 --- a/packages/core/CaptureDispatch.h +++ b/packages/core/CaptureDispatch.h @@ -54,8 +54,8 @@ class CaptureDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -83,14 +83,14 @@ class CaptureDispatch: public DispatchObject field_name = StringLib::duplicate(_field_str); timeout = _timeout; } ~capture_t(void) - { if(field_name) delete [] field_name; } + { delete [] field_name; } }; /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - MgList captures; + List captures; Mutex capMut; Publisher* outQ; diff --git a/packages/core/ClusterSocket.cpp b/packages/core/ClusterSocket.cpp index 2f34a30fc..4c8033c19 100644 --- a/packages/core/ClusterSocket.cpp +++ b/packages/core/ClusterSocket.cpp @@ -136,7 +136,7 @@ ClusterSocket::~ClusterSocket(void) delete [] sockqname; delete pubsockq; - if(subsockq) delete subsockq; + delete subsockq; /* * If connector thread exits before lost connection is detected @@ -152,8 +152,6 @@ ClusterSocket::~ClusterSocket(void) while (fd != (int)INVALID_KEY) { SockLib::sockclose(fd); - if(readCon->payload) delete [] readCon->payload; - if(readCon) delete readCon; fd = read_connections.next( &readCon ); } @@ -161,7 +159,6 @@ ClusterSocket::~ClusterSocket(void) while (fd != (int)INVALID_KEY) { SockLib::sockclose(fd); - if(writeCon) delete writeCon; fd = write_connections.next( &writeCon ); } } @@ -196,18 +193,17 @@ int ClusterSocket::writeBuffer(const void *buf, int len, int timeout) { return TIMEOUT_RC; } - else if(len <= MAX_MSG_SIZE) + + if(len <= MAX_MSG_SIZE) { int status = pubsockq->postCopy(buf, len, timeout); - if(status > 0) return status; - else if(status == MsgQ::STATE_NO_SUBSCRIBERS) return len; - else if(status == MsgQ::STATE_TIMEOUT) return TIMEOUT_RC; - else return SOCK_ERR_RC; - } - else - { - return PARM_ERR_RC; + if(status > 0) return status; + if(status == MsgQ::STATE_NO_SUBSCRIBERS) return len; + if(status == MsgQ::STATE_TIMEOUT) return TIMEOUT_RC; + return SOCK_ERR_RC; } + + return PARM_ERR_RC; } /*---------------------------------------------------------------------------- @@ -221,14 +217,11 @@ int ClusterSocket::readBuffer(void *buf, int len, int timeout) if(buf && subsockq) { int bytes = subsockq->receiveCopy(buf, len, timeout); - if(bytes > 0) return bytes; - else if(bytes == MsgQ::STATE_TIMEOUT) return TIMEOUT_RC; - else return SOCK_ERR_RC; - } - else - { - return PARM_ERR_RC; + if(bytes > 0) return bytes; + if(bytes == MsgQ::STATE_TIMEOUT) return TIMEOUT_RC; + return SOCK_ERR_RC; } + return PARM_ERR_RC; } /*---------------------------------------------------------------------------- @@ -236,12 +229,12 @@ int ClusterSocket::readBuffer(void *buf, int len, int timeout) *----------------------------------------------------------------------------*/ void* ClusterSocket::connectionThread(void* parm) { - ClusterSocket* s = (ClusterSocket*)parm; + ClusterSocket* s = static_cast(parm); int status = 0; - if(s->is_server) SockLib::startserver (s->getIpAddr(), s->getPort(), MAX_NUM_CONNECTIONS, pollHandler, activeHandler, &s->connecting, (void*)s); - else SockLib::startclient (s->getIpAddr(), s->getPort(), MAX_NUM_CONNECTIONS, pollHandler, activeHandler, &s->connecting, (void*)s); + if(s->is_server) status = SockLib::startserver (s->getIpAddr(), s->getPort(), MAX_NUM_CONNECTIONS, pollHandler, activeHandler, &s->connecting, (void*)s); + else status = SockLib::startclient (s->getIpAddr(), s->getPort(), MAX_NUM_CONNECTIONS, pollHandler, activeHandler, &s->connecting, (void*)s); if(status < 0) mlog(CRITICAL, "Failed to establish cluster %s socket on %s:%d (%d)", s->is_server ? "server" : "client", s->getIpAddr(), s->getPort(), status); @@ -257,7 +250,7 @@ int ClusterSocket::pollHandler(int fd, short* events, void* parm) { (void)fd; - ClusterSocket* s = (ClusterSocket*)parm; + ClusterSocket* s = static_cast(parm); /* Set Polling Flags */ *events = IO_READ_FLAG; @@ -291,7 +284,7 @@ int ClusterSocket::pollHandler(int fd, short* events, void* parm) *----------------------------------------------------------------------------*/ int ClusterSocket::activeHandler(int fd, int flags, void* parm) { - ClusterSocket* s = (ClusterSocket*)parm; + ClusterSocket* s = static_cast(parm); int rc = 0; @@ -466,7 +459,7 @@ int ClusterSocket::onWrite(int fd) spin_block = false; /* Dereference If Payload Fully Sent */ - if(connection->payload_left <= 0) + if(connection->payload_left == 0) { connection->subconnq->dereference(connection->payload_ref); } @@ -596,11 +589,9 @@ int ClusterSocket::onConnect(int fd) { /* Populate Read Connection Structure */ read_connection_t* connection = new read_connection_t; - memset(connection, 0, sizeof(read_connection_t)); - connection->payload_index = -MSG_HDR_SIZE; /* Add to Read Connections */ - if(!read_connections.add(fd, connection, false)) + if(!read_connections.add(fd, connection, true)) { mlog(CRITICAL, "Cluster socket failed to register file descriptor for read connection due to duplicate entry"); delete connection; @@ -609,9 +600,7 @@ int ClusterSocket::onConnect(int fd) } else if(role == WRITER) { - write_connection_t* connection = new write_connection_t; - memset(connection, 0, sizeof(write_connection_t)); - connection->meter = METER_SEND_THRESH; + write_connection_t* connection = new write_connection_t(protocol == BUS); /* Initialize Subscriber for Connection */ if(protocol == BUS) @@ -624,10 +613,9 @@ int ClusterSocket::onConnect(int fd) } /* Add to Write Connections */ - if(!write_connections.add(fd, connection, false)) + if(!write_connections.add(fd, connection, true)) { mlog(CRITICAL, "Cluster socket failed to register file descriptor for write connection due to duplicate entry"); - if(role == WRITER && protocol == BUS && connection->subconnq) delete connection->subconnq; delete connection; status = -1; } @@ -653,10 +641,7 @@ int ClusterSocket::onDisconnect(int fd) { if(role == READER) { - read_connection_t* connection = read_connections[fd]; - if(connection->payload) delete [] connection->payload; - delete connection; - if(!read_connections.remove(fd)) + if(!read_connections.remove(fd)) // frees connection memory { mlog(CRITICAL, "Cluster socket on %s:%d failed to remove connection information for reader file descriptor %d", getIpAddr(), getPort(), fd); status = -1; @@ -664,10 +649,7 @@ int ClusterSocket::onDisconnect(int fd) } if(role == WRITER) { - write_connection_t* connection = write_connections[fd]; - if(protocol == BUS && connection->subconnq) delete connection->subconnq; - delete connection; - if(!write_connections.remove(fd)) + if(!write_connections.remove(fd)) // frees connection memory { mlog(CRITICAL, "Cluster socket on %s:%d failed to remove connection information for writer file descriptor %d", getIpAddr(), getPort(), fd); status = -1; @@ -690,6 +672,6 @@ int ClusterSocket::onDisconnect(int fd) uint8_t ClusterSocket::qMeter(void) { int depth = pubsockq->getDepth(); - if(depth) return (uint8_t)((pubsockq->getCount() * 255) / depth); - else return 0; + if(depth) return (uint8_t)((pubsockq->getCount() * 255) / depth); + return 0; } diff --git a/packages/core/ClusterSocket.h b/packages/core/ClusterSocket.h index 62a19bd2c..6a33a57ea 100644 --- a/packages/core/ClusterSocket.h +++ b/packages/core/ClusterSocket.h @@ -94,7 +94,7 @@ class ClusterSocket: public TcpSocket * Types *--------------------------------------------------------------------*/ - typedef struct + typedef struct ReadConnection { int64_t prev; // time uint8_t* payload; // dynamically allocated @@ -103,10 +103,25 @@ class ClusterSocket: public TcpSocket int32_t buffer_index; // signed for comparisons int32_t buffer_size; // returned from receive call uint8_t buffer[MSG_BUFFER_SIZE]; + ReadConnection(void) + { + prev = 0; + payload = NULL; + payload_size = 0; + payload_index = -MSG_HDR_SIZE; + buffer_index = 0; + buffer_size = 0; + memset(buffer, 0, MSG_BUFFER_SIZE); + } + ~ReadConnection(void) + { + delete [] payload; + } } read_connection_t; - typedef struct + typedef struct WriteConnection { + bool delete_q; Subscriber* subconnq; Subscriber::msgRef_t payload_ref; uint32_t payload_left; @@ -114,6 +129,21 @@ class ClusterSocket: public TcpSocket uint32_t buffer_index; uint8_t buffer[MSG_BUFFER_SIZE]; uint8_t meter; + explicit WriteConnection(bool _delete_q) + { + delete_q = _delete_q; + subconnq = NULL; + memset(&payload_ref, 0, sizeof(payload_ref)); + payload_left = 0; + bytes_processed = 0; + buffer_index = 0; + memset(buffer, 0, MSG_BUFFER_SIZE); + meter = METER_SEND_THRESH; + } + ~WriteConnection(void) + { + if(delete_q) delete subconnq; + } } write_connection_t; /*-------------------------------------------------------------------- diff --git a/packages/core/ContainerRecord.cpp b/packages/core/ContainerRecord.cpp index 459c670d5..3730dea8c 100644 --- a/packages/core/ContainerRecord.cpp +++ b/packages/core/ContainerRecord.cpp @@ -80,7 +80,7 @@ ContainerRecord::ContainerRecord(int rec_cnt, int size): { recsContained = 0; recsOffset = hdrSize(rec_cnt); - container = (rec_t*)recordData; + container = reinterpret_cast(recordData); container->rec_cnt = rec_cnt; container->start_of_recs = recsOffset; } @@ -116,9 +116,6 @@ bool ContainerRecord::addRecord(RecordObject& record, int size) return true; } - else - { - return false; - } + return false; } diff --git a/packages/core/CsvDispatch.cpp b/packages/core/CsvDispatch.cpp index 9f37482b0..b3cb71075 100644 --- a/packages/core/CsvDispatch.cpp +++ b/packages/core/CsvDispatch.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* CsvDispatch::LuaMetaName = "CsvDispatch"; -const struct luaL_Reg CsvDispatch::LuaMetaTable[] = { +const char* CsvDispatch::LUA_META_NAME = "CsvDispatch"; +const struct luaL_Reg CsvDispatch::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -87,7 +87,7 @@ int CsvDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -102,7 +102,7 @@ int CsvDispatch::luaCreate (lua_State* L) * Note: object takes ownership of columns pointer and must free memory *----------------------------------------------------------------------------*/ CsvDispatch::CsvDispatch (lua_State* L, const char* outq_name, const char** _columns, int _num_columns): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { assert(_columns); diff --git a/packages/core/CsvDispatch.h b/packages/core/CsvDispatch.h index e79f281bd..2efae1eb9 100644 --- a/packages/core/CsvDispatch.h +++ b/packages/core/CsvDispatch.h @@ -52,8 +52,8 @@ class CsvDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/DeviceIO.cpp b/packages/core/DeviceIO.cpp index 2a2d3faf4..27fe462a0 100644 --- a/packages/core/DeviceIO.cpp +++ b/packages/core/DeviceIO.cpp @@ -47,8 +47,8 @@ ******************************************************************************/ const char* DeviceIO::OBJECT_TYPE = "DeviceIO"; -const char* DeviceIO::LuaMetaName = "DeviceReader"; -const struct luaL_Reg DeviceIO::LuaMetaTable[] = { +const char* DeviceIO::LUA_META_NAME = "DeviceReader"; +const struct luaL_Reg DeviceIO::LUA_META_TABLE[] = { {"stats", luaLogPktStats}, {"wait", luaWaitOnConnect}, {"block", luaConfigBlock}, @@ -64,7 +64,7 @@ const struct luaL_Reg DeviceIO::LuaMetaTable[] = { * Constructor *----------------------------------------------------------------------------*/ DeviceIO::DeviceIO(lua_State* L, DeviceObject* _device): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(_device); @@ -104,7 +104,7 @@ int DeviceIO::luaLogPktStats(lua_State* L) try { /* Get Self */ - DeviceIO* lua_obj = (DeviceIO*)getLuaSelf(L, 1); + DeviceIO* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Event Level */ event_level_t lvl = (event_level_t)getLuaInteger(L, 2, true, INVALID_EVENT_LEVEL); @@ -145,7 +145,7 @@ int DeviceIO::luaWaitOnConnect(lua_State* L) try { /* Get Self */ - DeviceIO* lua_obj = (DeviceIO*)getLuaSelf(L, 1); + DeviceIO* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ long timeout_seconds = getLuaInteger(L, 2, true, 5); @@ -192,7 +192,7 @@ int DeviceIO::luaConfigBlock(lua_State* L) try { /* Get Self */ - DeviceIO* lua_obj = (DeviceIO*)getLuaSelf(L, 1); + DeviceIO* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Block Value */ if(lua_isboolean(L, 2)) @@ -233,7 +233,7 @@ int DeviceIO::luaDieOnDisconnect(lua_State* L) try { /* Get Self */ - DeviceIO* lua_obj = (DeviceIO*)getLuaSelf(L, 1); + DeviceIO* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ bool enable = getLuaBoolean(L, 2); diff --git a/packages/core/DeviceIO.h b/packages/core/DeviceIO.h index f8fa3e26b..3b6be0c8d 100644 --- a/packages/core/DeviceIO.h +++ b/packages/core/DeviceIO.h @@ -55,8 +55,8 @@ class DeviceIO: public LuaObject *--------------------------------------------------------------------*/ static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; protected: @@ -73,7 +73,6 @@ class DeviceIO: public LuaObject int bytesDropped; int packetsProcessed; int packetsDropped; - int deviceListIndex; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/DeviceObject.cpp b/packages/core/DeviceObject.cpp index 0f6d32eed..037f23997 100644 --- a/packages/core/DeviceObject.cpp +++ b/packages/core/DeviceObject.cpp @@ -43,13 +43,13 @@ * STATIC DATA ******************************************************************************/ -Ordering DeviceObject::deviceList; -Mutex DeviceObject::deviceListMut; -okey_t DeviceObject::currentListKey = 0; +Ordering DeviceObject::deviceList; +Mutex DeviceObject::deviceListMut; +okey_t DeviceObject::currentListKey = 0; const char* DeviceObject::OBJECT_TYPE = "DeviceObject"; -const char* DeviceObject::LuaMetaName = "DeviceObject"; -const struct luaL_Reg DeviceObject::LuaMetaTable[] = { +const char* DeviceObject::LUA_META_NAME = "DeviceObject"; +const struct luaL_Reg DeviceObject::LUA_META_TABLE[] = { {"send", luaSend}, {"receive", luaReceive}, {"config", luaConfig}, @@ -66,14 +66,14 @@ const struct luaL_Reg DeviceObject::LuaMetaTable[] = { * Constructor *----------------------------------------------------------------------------*/ DeviceObject::DeviceObject (lua_State* L, role_t _role): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), role(_role) { /* Add Device to List */ deviceListMut.lock(); { - DeviceObject* this_device = this; - deviceList.add(currentListKey, this_device); + device_t device = { .device_obj = this }; + deviceList.add(currentListKey, device); deviceListKey = currentListKey++; } deviceListMut.unlock(); @@ -99,20 +99,20 @@ DeviceObject::~DeviceObject (void) char* DeviceObject::getDeviceList(void) { #define DEV_STR_SIZE 64 - char devstr[DEV_STR_SIZE]; char* liststr; deviceListMut.lock(); { + char devstr[DEV_STR_SIZE]; int liststrlen = DEV_STR_SIZE * deviceList.length() + 1; liststr = new char[liststrlen]; liststr[0] = '\0'; - DeviceObject* dev; + device_t dev; okey_t key = deviceList.first(&dev); while(key != INVALID_KEY) { - StringLib::format(devstr, DEV_STR_SIZE, "%c %s\n", dev->isConnected(0) ? 'C' : 'D', dev->getConfig()); + StringLib::format(devstr, DEV_STR_SIZE, "%c %s\n", dev.device_obj->isConnected(0) ? 'C' : 'D', dev.device_obj->getConfig()); StringLib::concat(liststr, devstr, liststrlen); key = deviceList.next(&dev); } @@ -144,7 +144,7 @@ int DeviceObject::luaSend (lua_State* L) try { /* Get Self */ - DeviceObject* dev = (DeviceObject*)getLuaSelf(L, 1); + DeviceObject* dev = dynamic_cast(getLuaSelf(L, 1)); /* Send Data */ size_t str_len = 0; @@ -173,7 +173,7 @@ int DeviceObject::luaReceive (lua_State* L) try { /* Get Self */ - DeviceObject* dev = (DeviceObject*)getLuaSelf(L, 1); + DeviceObject* dev = dynamic_cast(getLuaSelf(L, 1)); /* Receive Data */ int io_maxsize = OsApi::getIOMaxsize(); @@ -204,7 +204,7 @@ int DeviceObject::luaConfig (lua_State* L) try { /* Get Self */ - DeviceObject* dev = (DeviceObject*)getLuaSelf(L, 1); + DeviceObject* dev = dynamic_cast(getLuaSelf(L, 1)); /* Get Configuration */ const char* config = dev->getConfig(); @@ -232,7 +232,7 @@ int DeviceObject::luaIsConnected (lua_State* L) try { /* Get Self */ - DeviceObject* dev = (DeviceObject*)getLuaSelf(L, 1); + DeviceObject* dev = dynamic_cast(getLuaSelf(L, 1)); /* Set Status */ status = dev->isConnected(1); @@ -256,7 +256,7 @@ int DeviceObject::luaClose (lua_State* L) try { /* Get Self */ - DeviceObject* dev = (DeviceObject*)getLuaSelf(L, 1); + DeviceObject* dev = dynamic_cast(getLuaSelf(L, 1)); /* Close Connection */ dev->closeConnection(); diff --git a/packages/core/DeviceObject.h b/packages/core/DeviceObject.h index 390a03c81..105422bd5 100644 --- a/packages/core/DeviceObject.h +++ b/packages/core/DeviceObject.h @@ -92,18 +92,26 @@ class DeviceObject: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; + + /*-------------------------------------------------------------------- + * Types + *--------------------------------------------------------------------*/ + + typedef struct { + DeviceObject* device_obj; + } device_t; /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static Ordering deviceList; - static Mutex deviceListMut; - static okey_t currentListKey; + static Ordering deviceList; + static Mutex deviceListMut; + static okey_t currentListKey; - okey_t deviceListKey; + okey_t deviceListKey; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/DeviceReader.cpp b/packages/core/DeviceReader.cpp index 66ca6fd02..bc489b75a 100644 --- a/packages/core/DeviceReader.cpp +++ b/packages/core/DeviceReader.cpp @@ -51,7 +51,7 @@ int DeviceReader::luaCreate (lua_State* L) try { /* Get Parameters */ - _device = (DeviceObject*)getLuaObject(L, 1, DeviceObject::OBJECT_TYPE); + _device = dynamic_cast(getLuaObject(L, 1, DeviceObject::OBJECT_TYPE)); const char* q_name = getLuaString(L, 2, true, NULL); /* Return DeviceReader Object */ @@ -60,7 +60,7 @@ int DeviceReader::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(_device) _device->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -94,10 +94,10 @@ DeviceReader::~DeviceReader(void) /* Stop Thread */ ioActive = false; - if(ioThread) delete ioThread; + delete ioThread; /* Delete Output Queue */ - if(outq) delete outq; + delete outq; /* Release Device */ device->releaseLuaObject(); @@ -109,7 +109,7 @@ DeviceReader::~DeviceReader(void) void* DeviceReader::readerThread (void* parm) { assert(parm != NULL); - DeviceReader* dr = (DeviceReader*)parm; + DeviceReader* dr = static_cast(parm); int io_maxsize = OsApi::getIOMaxsize(); unsigned char* buf = new unsigned char [io_maxsize]; diff --git a/packages/core/DeviceWriter.cpp b/packages/core/DeviceWriter.cpp index 66e17b61f..aa59169b6 100644 --- a/packages/core/DeviceWriter.cpp +++ b/packages/core/DeviceWriter.cpp @@ -51,7 +51,7 @@ int DeviceWriter::luaCreate (lua_State* L) try { /* Get Parameters */ - _device = (DeviceObject*)getLuaObject(L, 1, DeviceObject::OBJECT_TYPE); + _device = dynamic_cast(getLuaObject(L, 1, DeviceObject::OBJECT_TYPE)); const char* q_name = getLuaString(L, 2, true, NULL); /* Return DeviceReader Object */ @@ -60,7 +60,7 @@ int DeviceWriter::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(_device) _device->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -94,10 +94,10 @@ DeviceWriter::~DeviceWriter(void) /* Stop Thread */ ioActive = false; - if(ioThread) delete ioThread; + delete ioThread; /* Delete Input Stream */ - if(inq) delete inq; + delete inq; /* Release Device */ device->releaseLuaObject(); @@ -109,7 +109,7 @@ DeviceWriter::~DeviceWriter(void) void* DeviceWriter::writerThread (void* parm) { assert(parm != NULL); - DeviceWriter* dw = (DeviceWriter*)parm; + DeviceWriter* dw = static_cast(parm); /* Read Loop */ while(dw->ioActive) diff --git a/packages/core/Dictionary.h b/packages/core/Dictionary.h index d4d28791f..6af77b9b0 100644 --- a/packages/core/Dictionary.h +++ b/packages/core/Dictionary.h @@ -73,7 +73,7 @@ class Dictionary class Iterator { public: - Iterator (const Dictionary& d); + explicit Iterator (const Dictionary& d); ~Iterator (void); kv_t operator[] (int index); const int length; @@ -88,9 +88,9 @@ class Dictionary *--------------------------------------------------------------------*/ Dictionary (int hash_size=DEFAULT_HASH_TABLE_SIZE, double hash_load=DEFAULT_HASH_TABLE_LOAD); - virtual ~Dictionary (void); + ~Dictionary (void); - bool add (const char* key, T& data, bool unique=false); + bool add (const char* key, const T& data, bool unique=false); T& get (const char* key) const; bool find (const char* key, T* data=NULL) const; bool remove (const char* key); @@ -140,22 +140,9 @@ class Dictionary unsigned int hashKey (const char* key) const; // returns unconstrained hash unsigned int getNode (const char* key) const; // returns index into hash table - void addNode (const char* key, T& data, unsigned int hash, bool rehashed=false); - virtual void freeNode (unsigned int hash_index); -}; + void addNode (const char* key, const T& data, unsigned int hash, bool rehashed=false); + void freeNode (unsigned int hash_index); -/****************************************************************************** - * MANAGED DICTIONARY TEMPLATE - ******************************************************************************/ - -template -class MgDictionary: public Dictionary -{ - public: - MgDictionary (int hash_size=Dictionary::DEFAULT_HASH_TABLE_SIZE, double hash_load=Dictionary::DEFAULT_HASH_TABLE_LOAD); - ~MgDictionary (void); - private: - void freeNode (unsigned int hash_index); }; /****************************************************************************** @@ -210,10 +197,8 @@ typename Dictionary::kv_t Dictionary::Iterator::operator[](int index) return Dictionary::kv_t(source.hashTable[table_index].key, source.hashTable[table_index].data); } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "Dictionary::Iterator index out of range"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "Dictionary::Iterator index out of range"); } /****************************************************************************** @@ -233,9 +218,9 @@ const double Dictionary::DEFAULT_HASH_TABLE_LOAD = 0.75; template Dictionary::Dictionary(int hash_size, double hash_load) { - assert(hash_size > 0); + assert(hash_size >= 0); - hashSize = hash_size; + hashSize = hash_size == 0 ? DEFAULT_HASH_TABLE_SIZE : hash_size; if(hash_load <= 0.0 || hash_load > 1.0) { @@ -270,7 +255,7 @@ Dictionary::~Dictionary(void) * if not unique then old data is automatically deleted and overwritten *----------------------------------------------------------------------------*/ template -bool Dictionary::add(const char* key, T& data, bool unique) +bool Dictionary::add(const char* key, const T& data, bool unique) { assert(key); @@ -319,7 +304,7 @@ bool Dictionary::add(const char* key, T& data, bool unique) } /* Add Node */ - if(status == true) + if(status) { addNode(key, data, hashKey(key)); numEntries++; @@ -350,7 +335,7 @@ T& Dictionary::get(const char* key) const { unsigned int index = getNode(key); if(index != NULL_INDEX) return hashTable[index].data; - else throw RunTimeException(CRITICAL, RTE_ERROR, "key <%s> not found", key); + throw RunTimeException(CRITICAL, RTE_ERROR, "key <%s> not found", key); } /*---------------------------------------------------------------------------- @@ -473,7 +458,7 @@ int Dictionary::getMaxChain(void) const template int Dictionary::getKeys (char*** keys) const { - if (numEntries <= 0) return 0; + if (numEntries == 0) return 0; *keys = new char* [numEntries]; for(unsigned int i = 0, j = 0; i < hashSize; i++) @@ -607,8 +592,13 @@ const char* Dictionary::last (T* data) template Dictionary& Dictionary::operator=(const Dictionary& other) { - /* Clear Existing Dictionary */ + /* Check Self Assignment */ + if(this == &other) return *this; + + /* Clear Hash */ clear(); + + /* Free Hash */ delete [] hashTable; /* Copy Other Dictionary */ @@ -659,7 +649,7 @@ template unsigned int Dictionary::hashKey(const char *key) const { const char* ptr = key; - int h = 0; + long h = 0; while(*ptr != '\0') { @@ -684,6 +674,8 @@ unsigned int Dictionary::hashKey(const char *key) const template unsigned int Dictionary::getNode(const char* key) const { + assert(hashSize); + /* Check Pointer */ if(key != NULL) { @@ -702,7 +694,8 @@ unsigned int Dictionary::getNode(const char* key) const index = hashTable[index].next; break; } - else if(key[i] == '\0') + + if(key[i] == '\0') { /* If there is no difference AND key is at null, return match */ return index; @@ -718,8 +711,10 @@ unsigned int Dictionary::getNode(const char* key) const * addNode *----------------------------------------------------------------------------*/ template -void Dictionary::addNode (const char* key, T& data, unsigned int hash, bool rehashed) +void Dictionary::addNode (const char* key, const T& data, unsigned int hash, bool rehashed) { + assert(hashSize); + /* Constrain the Hash */ unsigned int curr_index = hash % hashSize; @@ -830,45 +825,16 @@ void Dictionary::addNode (const char* key, T& data, unsigned int hash, bool r * freeNode *----------------------------------------------------------------------------*/ template -void Dictionary::freeNode(unsigned int hash_index) -{ - (void)hash_index; -} - -/****************************************************************************** - * MANAGED DICTIONARY METHODS - ******************************************************************************/ +void dictionaryDeleteIfPointer(const T& t) { (void)t; } -/*---------------------------------------------------------------------------- - * Constructor - *----------------------------------------------------------------------------*/ -template -MgDictionary::MgDictionary(int hash_size, double hash_load): Dictionary(hash_size, hash_load) -{ -} +template +void dictionaryDeleteIfPointer(T* t) { delete t; } -/*---------------------------------------------------------------------------- - * Destructor - *----------------------------------------------------------------------------*/ -template -MgDictionary::~MgDictionary(void) +template +void Dictionary::freeNode(unsigned int hash_index) { - /* This call is needed here because the data in the hash table - * must be cleared in the context of the freeNode method below - * which belongs to MgDictionary. The Dictionary destructor - * will clear the hash table using its own freeNode method which - * does not call the destructor for the objects. */ - Dictionary::clear(); + dictionaryDeleteIfPointer(hashTable[hash_index].data); } -/*---------------------------------------------------------------------------- - * freeNode - *----------------------------------------------------------------------------*/ -template -void MgDictionary::freeNode(unsigned int hash_index) -{ - if(!is_array) delete Dictionary::hashTable[hash_index].data; - else delete [] Dictionary::hashTable[hash_index].data; -} #endif /* __dictionary__ */ diff --git a/packages/core/DispatchObject.h b/packages/core/DispatchObject.h index 8878a239d..052edd55e 100644 --- a/packages/core/DispatchObject.h +++ b/packages/core/DispatchObject.h @@ -40,9 +40,6 @@ #include "RecordObject.h" #include "OsApi.h" -#include -using std::vector; - /****************************************************************************** * DISPATCH OBJECT (PURE VIRTUAL) ******************************************************************************/ diff --git a/packages/core/EndpointObject.cpp b/packages/core/EndpointObject.cpp index c4e5d95d2..dd3d0e944 100644 --- a/packages/core/EndpointObject.cpp +++ b/packages/core/EndpointObject.cpp @@ -68,19 +68,9 @@ EndpointObject::Request::Request (const char* _id): *----------------------------------------------------------------------------*/ EndpointObject::Request::~Request (void) { - /* Clear Out Headers */ - const char* header; - const char* key = headers.first(&header); - while(key != NULL) - { - delete [] header; - key = headers.next(&header); - } - - /* Free Allocate Members */ - if(body) delete [] body; - if(resource) delete [] resource; - if(path) delete [] path; + delete [] body; + delete [] resource; + delete [] path; delete [] id; } @@ -108,16 +98,16 @@ EndpointObject::~EndpointObject (void) *----------------------------------------------------------------------------*/ EndpointObject::verb_t EndpointObject::str2verb (const char* str) { - if(StringLib::match(str, "GET")) return GET; - else if(StringLib::match(str, "HEAD")) return HEAD; - else if(StringLib::match(str, "POST")) return POST; - else if(StringLib::match(str, "PUT")) return PUT; - else if(StringLib::match(str, "DELETE")) return DELETE; - else if(StringLib::match(str, "TRACE")) return TRACE; - else if(StringLib::match(str, "OPTIONS")) return OPTIONS; - else if(StringLib::match(str, "CONNECT")) return CONNECT; - else if(StringLib::match(str, "RAW")) return RAW; - else return UNRECOGNIZED; + if(StringLib::match(str, "GET")) return GET; + if(StringLib::match(str, "HEAD")) return HEAD; + if(StringLib::match(str, "POST")) return POST; + if(StringLib::match(str, "PUT")) return PUT; + if(StringLib::match(str, "DELETE")) return DELETE; + if(StringLib::match(str, "TRACE")) return TRACE; + if(StringLib::match(str, "OPTIONS")) return OPTIONS; + if(StringLib::match(str, "CONNECT")) return CONNECT; + if(StringLib::match(str, "RAW")) return RAW; + return UNRECOGNIZED; } /*---------------------------------------------------------------------------- @@ -145,13 +135,13 @@ const char* EndpointObject::verb2str (verb_t verb) *----------------------------------------------------------------------------*/ EndpointObject::code_t EndpointObject::str2code (const char* str) { - if(StringLib::match(str, "OK")) return OK; - else if(StringLib::match(str, "Bad Request")) return Bad_Request; - else if(StringLib::match(str, "Not Found")) return Not_Found; - else if(StringLib::match(str, "Method Not Allowed")) return Method_Not_Allowed; - else if(StringLib::match(str, "Request Timeout")) return Request_Timeout; - else if(StringLib::match(str, "Method Not Implemented")) return Method_Not_Implemented; - else return Bad_Request; + if(StringLib::match(str, "OK")) return OK; + if(StringLib::match(str, "Bad Request")) return Bad_Request; + if(StringLib::match(str, "Not Found")) return Not_Found; + if(StringLib::match(str, "Method Not Allowed")) return Method_Not_Allowed; + if(StringLib::match(str, "Request Timeout")) return Request_Timeout; + if(StringLib::match(str, "Method Not Implemented")) return Method_Not_Implemented; + return Bad_Request; } /*---------------------------------------------------------------------------- diff --git a/packages/core/EndpointObject.h b/packages/core/EndpointObject.h index e5e50404f..35d16d8d2 100644 --- a/packages/core/EndpointObject.h +++ b/packages/core/EndpointObject.h @@ -92,6 +92,12 @@ class EndpointObject: public LuaObject STREAMING = 1 } rsptype_t; + /*-------------------------------------------------------------------- + * Typedefs + *--------------------------------------------------------------------*/ + + typedef Dictionary HeaderDictionary; + /*-------------------------------------------------------------------- * Request Subclass *--------------------------------------------------------------------*/ @@ -100,16 +106,16 @@ class EndpointObject: public LuaObject { public: - const char* path; - const char* resource; - verb_t verb; - Dictionary headers; - uint8_t* body; - long length; // of body - uint32_t trace_id; - const char* id; // must be unique + const char* path; + const char* resource; + verb_t verb; + HeaderDictionary headers; + uint8_t* body; + long length; // of body + uint32_t trace_id; + const char* id; // must be unique - Request (const char* _id); + explicit Request (const char* _id); ~Request (void); }; diff --git a/packages/core/EventLib.cpp b/packages/core/EventLib.cpp index 9dd2eda3b..d48ec1097 100644 --- a/packages/core/EventLib.cpp +++ b/packages/core/EventLib.cpp @@ -83,10 +83,6 @@ event_level_t EventLib::log_level; event_level_t EventLib::trace_level; event_level_t EventLib::metric_level; -Mutex EventLib::metric_mut; -Dictionary*> EventLib::metric_categories(MAX_METRICS, 1.0); -List EventLib::metric_vals; - /****************************************************************************** * PUBLIC METHODS ******************************************************************************/ @@ -119,25 +115,6 @@ void EventLib::deinit (void) { /* Cleanup Output Q */ delete outq; - - /* Clean Up Metrics */ - metric_mut.lock(); - { - Dictionary* ids = NULL; - const char* category = metric_categories.first(&ids); - while(category != NULL) - { - delete ids; - category = metric_categories.next(&ids); - } - - for(int m = 0; m < metric_vals.length(); m++) - { - delete [] metric_vals[m].name; - delete [] metric_vals[m].category; - } - } - metric_mut.unlock(); } /*---------------------------------------------------------------------------- @@ -217,7 +194,7 @@ const char* EventLib::type2str (type_t type) /*---------------------------------------------------------------------------- * subtype2str *----------------------------------------------------------------------------*/ -const char* EventLib::subtype2str (subtype_t subtype) +const char* EventLib::subtype2str (metric_subtype_t subtype) { switch(subtype) { @@ -313,7 +290,6 @@ uint32_t EventLib::grabId (void) return (uint32_t)(unsigned long long)Thread::getGlobal(trace_key); } - /*---------------------------------------------------------------------------- * logMsg *----------------------------------------------------------------------------*/ @@ -353,145 +329,21 @@ void EventLib::logMsg(const char* file_name, unsigned int line_number, event_lev sendEvent(&event, attr_size); } -/*---------------------------------------------------------------------------- - * registerMetric - *----------------------------------------------------------------------------*/ -int32_t EventLib::registerMetric (const char* category, subtype_t subtype, const char* name_fmt, ...) -{ - assert(category); - - int32_t metric_id = INVALID_METRIC; - - /* Build Metric Name */ - char name_buf[MAX_ATTR_SIZE]; - va_list args; - va_start(args, name_fmt); - int vlen = vsnprintf(name_buf, MAX_ATTR_SIZE - 1, name_fmt, args); - int attr_size = MAX(MIN(vlen + 1, MAX_ATTR_SIZE), 1); - name_buf[attr_size - 1] = '\0'; - va_end(args); - - /* Regsiter Metric */ - metric_mut.lock(); - { - /* Get Metric Category Dictionary */ - Dictionary* ids; - if(metric_categories.find(category)) - { - ids = metric_categories[category]; - } - else - { - ids = new Dictionary(MAX_METRICS, 1.0); - if(!metric_categories.add(category, ids, true)) - { - mlog(WARNING, "Failed to add attribute to metrics: %s", category); - } - } - - /* Create Metric */ - metric_t metric; - metric.value = 0.0; - metric.subtype = subtype; - metric.name = StringLib::duplicate(name_buf); - metric.category = StringLib::duplicate(category); - metric.id = metric_vals.length(); - metric_vals.add(metric); - - /* Register Metric */ - if(ids->add(metric.name, metric.id, true)) - { - metric_id = metric.id; - } - else try // getting existing metric - { - metric_id = ids->get(metric.name); - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to register metric %s", metric.name); - } - } - metric_mut.unlock(); - - /* Return Metric Id */ - return metric_id; -} - -/*---------------------------------------------------------------------------- - * updateMetric - *----------------------------------------------------------------------------*/ -void EventLib::updateMetric (int32_t id, double value) -{ - metric_mut.lock(); - { - try - { - metric_t& metric = metric_vals[id]; - metric.value = value; - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to update metric %d: %s", id, e.what()); - } - } - metric_mut.unlock(); -} - -/*---------------------------------------------------------------------------- - * incrementMetric - *----------------------------------------------------------------------------*/ -void EventLib::incrementMetric (int32_t id, double value) -{ - metric_mut.lock(); - { - try - { - metric_t& metric = metric_vals[id]; - metric.value += value; - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to increment metric %d: %s", id, e.what()); - } - } - metric_mut.unlock(); -} - /*---------------------------------------------------------------------------- * generateMetric *----------------------------------------------------------------------------*/ -void EventLib::generateMetric (int32_t id, event_level_t lvl) +void EventLib::generateMetric (event_level_t lvl, const char* name, metric_subtype_t subtype, double value) { event_t event; - metric_t metric; /* Return Here If Nothing to Do */ if(lvl < metric_level) return; - /* Get Metric */ - metric_mut.lock(); - { - try - { - metric = metric_vals[id]; - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to generate metric %d: %s", id, e.what()); - metric.id = INVALID_METRIC; - } - } - metric_mut.unlock(); - - /* Check for Valid Metric */ - if (metric.id == INVALID_METRIC) return; - /* Initialize Log Message */ event.systime = TimeLib::gpstime(); event.tid = Thread::getId(); - event.id = metric.id; - event.parent = metric.subtype; + event.id = subtype; + event.parent = ORIGIN; event.flags = 0; event.type = METRIC; event.level = lvl; @@ -499,64 +351,15 @@ void EventLib::generateMetric (int32_t id, event_level_t lvl) /* Copy IP Address */ StringLib::copy(event.ipv4, SockLib::sockipv4(), SockLib::IPV4_STR_LEN); - /* Copy Name and Attribute */ - StringLib::copy(event.name, metric.name, MAX_NAME_SIZE); - StringLib::copy(event.attr, metric.category, MAX_ATTR_SIZE); + /* Populate Name and Populate Attribute */ + StringLib::copy(event.name, name, MAX_NAME_SIZE); + StringLib::formats(event.attr, MAX_ATTR_SIZE, "%lf", value); /* Post Metric */ - int attr_size = StringLib::size(metric.category) + 1; + int attr_size = StringLib::size(event.attr) + 1; sendEvent(&event, attr_size); } -/*---------------------------------------------------------------------------- - * iterateMetric - *----------------------------------------------------------------------------*/ -void EventLib::_iterateMetric (Dictionary* ids, metric_func_t cb, void* parm) -{ - int32_t id; - int i = 0; - const char* name = ids->first(&id); - while(name != NULL) - { - metric_t metric = metric_vals[id]; - cb(metric, i++, parm); - name = ids->next(&id); - } -} - -void EventLib::iterateMetric (const char* category, metric_func_t cb, void* parm) -{ - assert(cb); - - metric_mut.lock(); - { - try - { - if(category) - { - Dictionary* ids = metric_categories[category]; - _iterateMetric(ids, cb, parm); - } - else // all categories - { - /// need mutex - Dictionary* ids; - const char* next_category = metric_categories.first(&ids); - while(next_category != NULL) - { - _iterateMetric(ids, cb, parm); - next_category = metric_categories.next(&ids); - } - } - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to iterate metrics for %s: %s", category, e.what()); - } - } - metric_mut.unlock(); -} - /*---------------------------------------------------------------------------- * sendEvent *----------------------------------------------------------------------------*/ diff --git a/packages/core/EventLib.h b/packages/core/EventLib.h index 3d4f7e96c..646a0f311 100644 --- a/packages/core/EventLib.h +++ b/packages/core/EventLib.h @@ -56,9 +56,6 @@ #define stop_trace(lvl,id,...) {(void)lvl; (void)id;} #endif -#define update_metric(lvl, id, val) {EventLib::updateMetric(id, val); EventLib::generateMetric(id, lvl);} -#define increment_metric(lvl, id) {EventLib::incrementMetric(id); EventLib::generateMetric(id, lvl);} - /****************************************************************************** * EVENT LIBRARY CLASS ******************************************************************************/ @@ -109,17 +106,7 @@ class EventLib typedef enum { COUNTER = 0, GAUGE = 1 - } subtype_t; - - typedef struct { - int32_t id; - subtype_t subtype; - const char* name; - const char* category; - double value; - } metric_t; - - typedef void (*metric_func_t) (const metric_t& metric, int32_t index, void* parm); + } metric_subtype_t; /*-------------------------------------------------------------------- * Methods @@ -133,7 +120,7 @@ class EventLib static const char* lvl2str (event_level_t lvl); static const char* lvl2str_lc (event_level_t lvl); static const char* type2str (type_t type); - static const char* subtype2str (subtype_t subtype); + static const char* subtype2str (metric_subtype_t subtype); static uint32_t startTrace (uint32_t parent, const char* name, event_level_t lvl, const char* attr_fmt, ...) VARG_CHECK(printf, 4, 5); static void stopTrace (uint32_t id, event_level_t lvl); @@ -142,11 +129,7 @@ class EventLib static void logMsg (const char* file_name, unsigned int line_number, event_level_t lvl, const char* msg_fmt, ...) VARG_CHECK(printf, 4, 5); - static int32_t registerMetric (const char* category, subtype_t subtype, const char* name_fmt, ...) VARG_CHECK(printf, 3, 4); - static void updateMetric (int32_t id, double value); // for gauges - static void incrementMetric (int32_t id, double value=1.0); // for counters - static void generateMetric (int32_t id, event_level_t lvl); - static void iterateMetric (const char* category, metric_func_t cb, void* parm); + static void generateMetric (event_level_t lvl, const char* name, metric_subtype_t subtype, double value); private: @@ -155,7 +138,6 @@ class EventLib *--------------------------------------------------------------------*/ static int sendEvent (event_t* event, int attr_size); - static void _iterateMetric (Dictionary* ids, metric_func_t cb, void* parm); /*-------------------------------------------------------------------- * Data @@ -167,10 +149,6 @@ class EventLib static event_level_t log_level; static event_level_t trace_level; static event_level_t metric_level; - - static Mutex metric_mut; - static Dictionary*> metric_categories; - static List metric_vals; }; #endif /* __eventlib__ */ diff --git a/packages/core/File.cpp b/packages/core/File.cpp index 19bcc9a1e..4b9e3cfd5 100644 --- a/packages/core/File.cpp +++ b/packages/core/File.cpp @@ -152,11 +152,11 @@ File::File (lua_State* L, const char* _filename, type_t _type, role_t _role, io_ *----------------------------------------------------------------------------*/ File::~File (void) { - if(filename) delete [] filename; - if(config) delete [] config; - for(int i = 0; i < numFiles; i++) if(fileList[i]) delete [] fileList[i]; - if(fileList) delete [] fileList; - closeConnection(); + delete [] filename; + delete [] config; + for(int i = 0; i < numFiles; i++) delete [] fileList[i]; + delete [] fileList; + File::closeConnection(); } /*---------------------------------------------------------------------------- @@ -164,22 +164,10 @@ File::~File (void) *----------------------------------------------------------------------------*/ bool File::isConnected (int num_open) { - if(fp == NULL) return false; - - if(role == READER) - { - if(currFile+1 >= num_open) return true; - else return false; - } - else if(role == WRITER) - { - if(fileCount >= num_open) return true; - else return false; - } - else - { - return false; - } + if(fp == NULL) return false; + if(role == READER) return (currFile+1 >= num_open); + if(role == WRITER) return (fileCount >= num_open); + return false; } /*---------------------------------------------------------------------------- @@ -224,23 +212,19 @@ int File::writeBuffer (const void* buf, int len, int timeout) if(fp == NULL || ((fileBytesWritten > maxFileSize) && (maxFileSize != INFINITE_FILE_MAX_SIZE))) { fileBytesWritten = 0; - if(openNewFileForWriting() == false) + if(!openNewFileForWriting()) { return INVALID_RC; } - else + + /* Write File Header */ + int hdr_bytes = writeFileHeader(); + if(hdr_bytes < 0) { - /* Write File Header */ - int hdr_bytes = writeFileHeader(); - if(hdr_bytes < 0) - { - return hdr_bytes; - } - else - { - fileBytesWritten += hdr_bytes; - } + return hdr_bytes; } + + fileBytesWritten += hdr_bytes; } /* Write Buffer */ @@ -262,10 +246,7 @@ int File::writeBuffer (const void* buf, int len, int timeout) bytes_written = ret; break; } - else - { - bytes_written += ret; - } + bytes_written += ret; } /* Append New Line */ @@ -317,7 +298,8 @@ int File::readBuffer (void* buf, int len, int timeout) { return ACC_ERR_RC; } - else if(currFile >= numFiles) + + if(currFile >= numFiles) { return SHUTDOWN_RC; } @@ -342,10 +324,8 @@ int File::readBuffer (void* buf, int len, int timeout) mlog(CRITICAL, "Unable to open file %s: %s", fileList[currFile], strerror(errno)); return INVALID_RC; } - else - { - mlog(INFO, "Opened file %s", fileList[currFile]); - } + + mlog(INFO, "Opened file %s", fileList[currFile]); } /* Read File */ @@ -366,38 +346,36 @@ int File::readBuffer (void* buf, int len, int timeout) /* Read Next Packet */ unsigned char* pkt_buffer = (unsigned char*)buf; char b[5] = {'0', 'x', '\0', '\0', '\0'}; - int ch = EOF; int n = 0; while(recv_bytes < len) { - ch = getc(fp); + int ch = getc(fp); if(ch == '\n') { break; } - else if(ch == EOF) + + if(ch == EOF) { currFile++; fclose(fp); fp = NULL; break; } - else + + b[2 + (n++ % 2)] = (char)ch; + if(n % 2 == 0) { - b[2 + (n++ % 2)] = (char)ch; - if(n % 2 == 0) + char *endptr; + errno = 0; + unsigned long result = strtoul(b, &endptr, 0); + if( (endptr == b) || + ((result == ULONG_MAX || result == 0) && errno == ERANGE) ) { - char *endptr; - errno = 0; - unsigned long result = strtoul(b, &endptr, 0); - if( (endptr == b) || - ((result == ULONG_MAX || result == 0) && errno == ERANGE) ) - { - mlog(CRITICAL, "Read invalid data from file designated as an ASCII HEXDUMP: %s", b); - return INVALID_RC; - } - pkt_buffer[recv_bytes++] = (unsigned char)result; + mlog(CRITICAL, "Read invalid data from file designated as an ASCII HEXDUMP: %s", b); + return INVALID_RC; } + pkt_buffer[recv_bytes++] = (unsigned char)result; } } } @@ -459,11 +437,11 @@ File::io_t File::getIO (void) *----------------------------------------------------------------------------*/ File::type_t File::str2type (const char* str) { - if(StringLib::match(str, "BINARY")) return BINARY; - else if(StringLib::match(str, "ASCII")) return ASCII; - else if(StringLib::match(str, "TEXT")) return TEXT; - else if(StringLib::match(str, "FIFO")) return FIFO; - else return INVALID_TYPE; + if(StringLib::match(str, "BINARY")) return BINARY; + if(StringLib::match(str, "ASCII")) return ASCII; + if(StringLib::match(str, "TEXT")) return TEXT; + if(StringLib::match(str, "FIFO")) return FIFO; + return INVALID_TYPE; } /*---------------------------------------------------------------------------- @@ -471,11 +449,11 @@ File::type_t File::str2type (const char* str) *----------------------------------------------------------------------------*/ const char* File::type2str (type_t _type) { - if(_type == BINARY) return "BINARY"; - else if(_type == ASCII) return "ASCII"; - else if(_type == TEXT) return "TEXT"; - else if(_type == FIFO) return "FIFO"; - else return "INVALID"; + if(_type == BINARY) return "BINARY"; + if(_type == ASCII) return "ASCII"; + if(_type == TEXT) return "TEXT"; + if(_type == FIFO) return "FIFO"; + return "INVALID"; } /*---------------------------------------------------------------------------- @@ -483,9 +461,9 @@ const char* File::type2str (type_t _type) *----------------------------------------------------------------------------*/ File::io_t File::str2io (const char* str) { - if(StringLib::match(str, "FLUSHED")) return FLUSHED; - else if(StringLib::match(str, "CACHED")) return CACHED; - else return INVALID_IO; + if(StringLib::match(str, "FLUSHED")) return FLUSHED; + if(StringLib::match(str, "CACHED")) return CACHED; + return INVALID_IO; } /*---------------------------------------------------------------------------- @@ -493,9 +471,9 @@ File::io_t File::str2io (const char* str) *----------------------------------------------------------------------------*/ const char* File::io2str (io_t _io) { - if(_io == FLUSHED) return "FLUSHED"; - else if(_io == CACHED) return "CACHED"; - else return "INVALID"; + if(_io == FLUSHED) return "FLUSHED"; + if(_io == CACHED) return "CACHED"; + return "INVALID"; } /*---------------------------------------------------------------------------- @@ -513,7 +491,8 @@ bool File::openNewFileForWriting(void) fp = stdout; return true; } - else if(StringLib::match(filename, "STDERR") || StringLib::match(filename, "stderr")) + + if(StringLib::match(filename, "STDERR") || StringLib::match(filename, "stderr")) { fp = stderr; return true; @@ -523,7 +502,7 @@ bool File::openNewFileForWriting(void) if(fp != NULL) fclose(fp); /* Create Active File Name */ - int slen = FILENAME_MAX_CHARS; + int slen; if(fileCount == 1) slen = snprintf(activeFile, FILENAME_MAX_CHARS - 1, "%s", filename); else slen = snprintf(activeFile, FILENAME_MAX_CHARS - 1, "%s.%ld", filename, fileCount); int len = MIN(slen, FILENAME_MAX_CHARS - 1); diff --git a/packages/core/FileIODriver.cpp b/packages/core/FileIODriver.cpp index dd26cdc13..589a70c0f 100644 --- a/packages/core/FileIODriver.cpp +++ b/packages/core/FileIODriver.cpp @@ -76,8 +76,8 @@ int64_t FileIODriver::ioRead (uint8_t* data, int64_t size, uint64_t pos) FileIODriver::FileIODriver (const Asset* _asset, const char* resource): asset(_asset) { - SafeString filepath("%s/%s", asset->getPath(), resource); - ioFile = fopen(filepath.str(), "r"); + FString filepath("%s/%s", asset->getPath(), resource); + ioFile = fopen(filepath.c_str(), "r"); if(ioFile == NULL) { throw RunTimeException(CRITICAL, RTE_ERROR, "failed to open resource"); diff --git a/packages/core/FileIODriver.h b/packages/core/FileIODriver.h index 3230347d9..c0528f5f1 100644 --- a/packages/core/FileIODriver.h +++ b/packages/core/FileIODriver.h @@ -58,7 +58,7 @@ class FileIODriver: Asset::IODriver *--------------------------------------------------------------------*/ static IODriver* create (const Asset* _asset, const char* resource); - int64_t ioRead (uint8_t* data, int64_t size, uint64_t pos); + int64_t ioRead (uint8_t* data, int64_t size, uint64_t pos) override; private: diff --git a/packages/core/HttpClient.cpp b/packages/core/HttpClient.cpp index 56f99e705..84b51e1c3 100644 --- a/packages/core/HttpClient.cpp +++ b/packages/core/HttpClient.cpp @@ -45,8 +45,8 @@ ******************************************************************************/ const char* HttpClient::OBJECT_TYPE = "HttpClient"; -const char* HttpClient::LuaMetaName = "HttpClient"; -const struct luaL_Reg HttpClient::LuaMetaTable[] = { +const char* HttpClient::LUA_META_NAME = "HttpClient"; +const struct luaL_Reg HttpClient::LUA_META_TABLE[] = { {"request", luaRequest}, {"connected", luaConnected}, {NULL, NULL} @@ -87,7 +87,7 @@ int HttpClient::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ HttpClient::HttpClient(lua_State* L, const char* _ip_addr, int _port): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { active = true; ipAddr = StringLib::duplicate(_ip_addr); @@ -103,7 +103,7 @@ HttpClient::HttpClient(lua_State* L, const char* _ip_addr, int _port): * Constructor *----------------------------------------------------------------------------*/ HttpClient::HttpClient(lua_State* L, const char* url): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { // Initial Settings active = false; @@ -158,10 +158,10 @@ HttpClient::HttpClient(lua_State* L, const char* url): HttpClient::~HttpClient(void) { active = false; - if(requestPid) delete requestPid; - if(requestPub) delete requestPub; - if(ipAddr) delete [] ipAddr; - if(sock) delete sock; + delete requestPid; + delete requestPub; + delete [] ipAddr; + delete sock; delete [] rqstBuf; delete [] rspsBuf; } @@ -172,37 +172,36 @@ HttpClient::~HttpClient(void) HttpClient::rsps_t HttpClient::request (EndpointObject::verb_t verb, const char* resource, const char* data, bool keep_alive, Publisher* outq, int timeout) { uint32_t trace_id = start_trace(INFO, traceId, "http_client", "{\"verb\": \"%s\", \"resource\": \"%s\"}", EndpointObject::verb2str(verb), resource); + if(sock->isConnected() && makeRequest(verb, resource, data, keep_alive, trace_id)) { rsps_t rsps = parseResponse(outq, timeout, trace_id); stop_trace(INFO, trace_id); return rsps; } - else - { - rsps_t rsps = { - .code = EndpointObject::Service_Unavailable, - .response = NULL, - .size = 0 - }; - stop_trace(INFO, trace_id); - return rsps; - } + + rsps_t rsps = { + .code = EndpointObject::Service_Unavailable, + .response = NULL, + .size = 0 + }; + stop_trace(INFO, trace_id); + return rsps; } /*---------------------------------------------------------------------------- * getIpAddr *----------------------------------------------------------------------------*/ -const char* HttpClient::getIpAddr (void) +const char* HttpClient::getIpAddr (void) const { - if(ipAddr) return ipAddr; - else return "0.0.0.0"; + if(ipAddr) return ipAddr; + return "0.0.0.0"; } /*---------------------------------------------------------------------------- * getPort *----------------------------------------------------------------------------*/ -int HttpClient::getPort (void) +int HttpClient::getPort (void) const { return port; } @@ -225,10 +224,10 @@ bool HttpClient::makeRequest (EndpointObject::verb_t verb, const char* resource, uint32_t trace_id = start_trace(INFO, parent_trace_id, "make_request", "%s", "{}"); bool status = true; - int rqst_len = 0; - try { + int rqst_len = 0; + /* Calculate Content Length */ int content_length = 0; if(data) @@ -248,7 +247,7 @@ bool HttpClient::makeRequest (EndpointObject::verb_t verb, const char* resource, if(verb != EndpointObject::RAW) { /* Build Request Header */ - SafeString rqst_hdr("%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: sliderule/%s\r\nAccept: */*\r\n%sContent-Length: %d\r\n\r\n", + FString rqst_hdr("%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: sliderule/%s\r\nAccept: */*\r\n%sContent-Length: %d\r\n\r\n", EndpointObject::verb2str(verb), resource, getIpAddr(), @@ -261,7 +260,7 @@ bool HttpClient::makeRequest (EndpointObject::verb_t verb, const char* resource, rqst_len = content_length + hdr_len; if(rqst_len <= MAX_RQST_BUF_LEN) { - memcpy(rqstBuf, rqst_hdr.str(), hdr_len); + memcpy(rqstBuf, rqst_hdr.c_str(), hdr_len); if(data) memcpy(&rqstBuf[hdr_len], data, content_length); } else @@ -324,22 +323,22 @@ HttpClient::rsps_t HttpClient::parseResponse (Publisher* outq, int timeout, int3 .size = MAX_UNBOUNDED_RSPS }; - int header_num = 0; - int rsps_index = 0; - int rsps_buf_index = 0; - long content_remaining = MAX_UNBOUNDED_RSPS; - long chunk_remaining = 0; - bool unbounded_content = true; - bool chunk_encoding = false; - bool chunk_header_complete = false; - bool chunk_payload_complete = false; - bool chunk_trailer_complete = false; - bool headers_complete = false; - bool response_complete = false; - /* Process Response */ try { + int header_num = 0; + int rsps_index = 0; + int rsps_buf_index = 0; + long content_remaining = MAX_UNBOUNDED_RSPS; + long chunk_remaining = 0; + bool unbounded_content = true; + bool chunk_encoding = false; + bool chunk_header_complete = false; + bool chunk_payload_complete = false; + bool chunk_trailer_complete = false; + bool headers_complete = false; + bool response_complete = false; + while(active && !response_complete) { int bytes_read = sock->readBuffer(&rspsBuf[rsps_buf_index], MAX_RSPS_BUF_LEN-rsps_buf_index, timeout); @@ -407,7 +406,6 @@ HttpClient::rsps_t HttpClient::parseResponse (Publisher* outq, int timeout, int3 else if(line_term < 0) // end of headers reached { line_start += 2; // move past header delimeter - line_term = line_start; headers_complete = true; } else // header line not complete (line_term == 0) @@ -550,7 +548,6 @@ HttpClient::rsps_t HttpClient::parseResponse (Publisher* outq, int timeout, int3 chunk_trailer_complete = true; chunk_header_complete = false; line_start += 2; - line_term = line_start; } else if(line_term > 0) // chunk invalid { @@ -727,7 +724,7 @@ const char* HttpClient::parseChunkHeaderLine (int start, int term) *----------------------------------------------------------------------------*/ void* HttpClient::requestThread(void* parm) { - HttpClient* client = (HttpClient*)parm; + HttpClient* client = static_cast(parm); Subscriber* request_sub = new Subscriber(*(client->requestPub)); while(client->active) @@ -771,7 +768,7 @@ int HttpClient::luaRequest (lua_State* L) try { /* Get Self */ - HttpClient* lua_obj = (HttpClient*)getLuaSelf(L, 1); + HttpClient* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* verb_str = getLuaString(L, 2); @@ -847,7 +844,7 @@ int HttpClient::luaConnected (lua_State* L) try { /* Get Self */ - HttpClient* lua_obj = (HttpClient*)getLuaSelf(L, 1); + HttpClient* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Determine Connection Status */ if(lua_obj->sock) diff --git a/packages/core/HttpClient.h b/packages/core/HttpClient.h index 6a359bea8..5302d8b0f 100644 --- a/packages/core/HttpClient.h +++ b/packages/core/HttpClient.h @@ -65,8 +65,8 @@ class HttpClient: public LuaObject static const int MAX_DIGITS = 10; static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Typedefs @@ -89,8 +89,8 @@ class HttpClient: public LuaObject ~HttpClient (void); rsps_t request (EndpointObject::verb_t verb, const char* resource, const char* data, bool keep_alive, Publisher* outq, int timeout=SYS_TIMEOUT); - const char* getIpAddr (void); - int getPort (void); + const char* getIpAddr (void) const; + int getPort (void) const; private: @@ -132,7 +132,7 @@ class HttpClient: public LuaObject * Methods *--------------------------------------------------------------------*/ - TcpSocket* initializeSocket (const char* _ip_addr, int _port); + static TcpSocket* initializeSocket (const char* _ip_addr, int _port); bool makeRequest (EndpointObject::verb_t verb, const char* resource, const char* data, bool keep_alive, int32_t parent_trace_id); rsps_t parseResponse (Publisher* outq, int timeout, int32_t parent_trace_id); long parseLine (int start, int end); diff --git a/packages/core/HttpServer.cpp b/packages/core/HttpServer.cpp index 00a734a1a..24ec93d74 100644 --- a/packages/core/HttpServer.cpp +++ b/packages/core/HttpServer.cpp @@ -42,13 +42,10 @@ * STATIC DATA ******************************************************************************/ -const char* HttpServer::DURATION_METRIC = "duration"; - const char* HttpServer::OBJECT_TYPE = "HttpServer"; -const char* HttpServer::LuaMetaName = "HttpServer"; -const struct luaL_Reg HttpServer::LuaMetaTable[] = { +const char* HttpServer::LUA_META_NAME = "HttpServer"; +const struct luaL_Reg HttpServer::LUA_META_TABLE[] = { {"attach", luaAttach}, - {"metric", luaMetric}, {"untilup", luaUntilUp}, {NULL, NULL} }; @@ -91,7 +88,7 @@ int HttpServer::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ HttpServer::HttpServer(lua_State* L, const char* _ip_addr, int _port, int max_connections): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), connections(max_connections) { ipAddr = StringLib::duplicate(_ip_addr); @@ -111,85 +108,98 @@ HttpServer::~HttpServer(void) { active = false; delete listenerPid; - - if(ipAddr) delete [] ipAddr; - - EndpointObject* endpoint; - const char* key = routeTable.first(&endpoint); - while(key != NULL) - { - endpoint->releaseLuaObject(); - key = routeTable.next(&endpoint); - } - - connection_t* connection = NULL; - int fd = connections.first(&connection); - while(fd != (int)INVALID_KEY) - { - deinitConnection(connection); - delete connection; - fd = connections.next(&connection); - } + delete [] ipAddr; } /*---------------------------------------------------------------------------- * getIpAddr *----------------------------------------------------------------------------*/ -const char* HttpServer::getIpAddr (void) +const char* HttpServer::getIpAddr (void) const { - if(ipAddr) return ipAddr; - else return "0.0.0.0"; + if(ipAddr) return ipAddr; + return "0.0.0.0"; } /*---------------------------------------------------------------------------- * getPort *----------------------------------------------------------------------------*/ -int HttpServer::getPort (void) +int HttpServer::getPort (void) const { return port; } /*---------------------------------------------------------------------------- - * initConnection + * Connection Constructor *----------------------------------------------------------------------------*/ -void HttpServer::initConnection (connection_t* connection) +HttpServer::Connection::Connection (const char* _name) { - long cnt = requestId++; - memset(&connection->rsps_state, 0, sizeof(rsps_state_t)); - connection->start_time = TimeLib::latchtime(); - connection->keep_alive = false; - connection->id = new char [REQUEST_ID_LEN]; - StringLib::format(connection->id, REQUEST_ID_LEN, "%s.%ld", getName(), cnt); - connection->trace_id = start_trace(DEBUG, ORIGIN, "http_server", "{\"rqst_id\":\"%s\"}", connection->id); - connection->rsps_state.rspq = new Subscriber(connection->id); - connection->request = new EndpointObject::Request(connection->id); - connection->request->trace_id = connection->trace_id; + initialize(_name); + memset(&rqst_state, 0, sizeof(rqst_state_t)); +} + +/*---------------------------------------------------------------------------- + * Connection Copy Constructor + *----------------------------------------------------------------------------*/ +HttpServer::Connection::Connection (const Connection& other) +{ + initialize(other.name); + memcpy(&rqst_state, &other.rqst_state, sizeof(rqst_state_t)); } /*---------------------------------------------------------------------------- - * deinitConnection + * Connection Destructor *----------------------------------------------------------------------------*/ -void HttpServer::deinitConnection (connection_t* connection) +HttpServer::Connection::~Connection (void) { /* Free Stream Buffer */ - if(connection->rsps_state.stream_buf) delete [] connection->rsps_state.stream_buf; + delete [] rsps_state.stream_buf; /* Free Message Queue */ - if(connection->rsps_state.ref_status > 0) + if(rsps_state.ref_status > 0) { - connection->rsps_state.rspq->dereference(connection->rsps_state.ref); - connection->rsps_state.ref_status = 0; + rsps_state.rspq->dereference(rsps_state.ref); + rsps_state.ref_status = 0; } - delete connection->rsps_state.rspq; + delete rsps_state.rspq; /* Free Id */ - delete [] connection->id; + delete [] id; + delete [] name; /* Request freed only if present, o/w memory owned by EndpointObject */ - if(connection->request) delete connection->request; + delete request; /* Stop Trace */ - stop_trace(DEBUG, connection->trace_id); + stop_trace(DEBUG, trace_id); +} + +/*---------------------------------------------------------------------------- + * Connection Initialization + *----------------------------------------------------------------------------*/ +void HttpServer::Connection::initialize (const char* _name) +{ + /* Initialize Response State Variables */ + memset(&rsps_state, 0, sizeof(rsps_state_t)); + response_type = EndpointObject::INVALID; + + /* Default Keep Alive to False */ + keep_alive = false; + + /* Create Unique ID for Request */ + name = StringLib::duplicate(_name); + id = new char [REQUEST_ID_LEN]; + long cnt = requestId++; + StringLib::format(id, REQUEST_ID_LEN, "%s.%ld", name, cnt); + + /* Start Trace */ + trace_id = start_trace(DEBUG, ORIGIN, "http_server", "{\"rqst_id\":\"%s\"}", id); + + /* Subscribe to Response Q (data return by endpoint) */ + rsps_state.rspq = new Subscriber(id); + + /* Create Request */ + request = new EndpointObject::Request(id); + request->trace_id = trace_id; } /*---------------------------------------------------------------------------- @@ -199,9 +209,6 @@ void HttpServer::deinitConnection (connection_t* connection) *----------------------------------------------------------------------------*/ void HttpServer::extractPath (const char* url, const char** path, const char** resource) { - const char* src; - char* dst; - *path = NULL; *resource = NULL; @@ -213,8 +220,8 @@ void HttpServer::extractPath (const char* url, const char** path, const char** r { /* Get Endpoint */ int path_len = second_slash - first_slash + 1; // this includes null terminator and slash - dst = new char[path_len]; - src = first_slash ; // include the slash + char* dst = new char[path_len]; + const char* src = first_slash ; // include the slash *path = dst; while(src < second_slash) *dst++ = *src++; *dst = '\0'; @@ -242,15 +249,15 @@ bool HttpServer::processHttpHeader (char* buf, EndpointObject::Request* request) bool status = true; /* Parse Request */ - SafeString http_header("%s", buf); - List* header_list = http_header.split('\r'); + string http_header(buf); + List* header_list = StringLib::split(http_header.c_str(), http_header.length(), '\r'); /* Parse Request Line */ try { - List* request_line = (*header_list)[0].split(' '); - const char* verb_str = (*request_line)[0].str(); - const char* url_str = (*request_line)[1].str(); + List* request_line = StringLib::split((*header_list)[0]->c_str(), (*header_list)[0]->length(), ' '); + const char* verb_str = (*request_line)[0]->c_str(); + const char* url_str = (*request_line)[1]->c_str(); /* Get Verb */ request->verb = EndpointObject::str2verb(verb_str); @@ -275,17 +282,17 @@ bool HttpServer::processHttpHeader (char* buf, EndpointObject::Request* request) for(int h = 1; h < header_list->length(); h++) { /* Create Key/Value Pairs */ - List* keyvalue_list = (*header_list)[h].split(':'); + List* keyvalue_list = StringLib::split((*header_list)[h]->c_str(), (*header_list)[h]->length(), ':'); try { - char* key = (char*)(*keyvalue_list)[0].str(); - const char* value = (*keyvalue_list)[1].str(true); + char* key = (char*)(*keyvalue_list)[0]->c_str(); + string* value = new string(*(*keyvalue_list)[1]); StringLib::convertLower(key); - request->headers.add(key, value, true); + if(!request->headers.add(key, value, true)) delete value; } catch(const RunTimeException& e) { - mlog(e.level(), "Invalid header in http request: %s: %s", (*header_list)[h].str(), e.what()); + mlog(e.level(), "Invalid header in http request: %s: %s", (*header_list)[h]->c_str(), e.what()); } delete keyvalue_list; } @@ -302,7 +309,7 @@ bool HttpServer::processHttpHeader (char* buf, EndpointObject::Request* request) *----------------------------------------------------------------------------*/ void* HttpServer::listenerThread(void* parm) { - HttpServer* s = (HttpServer*)parm; + HttpServer* s = static_cast(parm); while(s->active) { @@ -332,10 +339,10 @@ void* HttpServer::listenerThread(void* parm) *----------------------------------------------------------------------------*/ int HttpServer::pollHandler(int fd, short* events, void* parm) { - HttpServer* s = (HttpServer*)parm; + HttpServer* s = static_cast(parm); /* Get Connection */ - connection_t* connection = s->connections[fd]; + Connection* connection = s->connections[fd]; rsps_state_t* state = &connection->rsps_state; /* Set Read Polling Flag (if request is ready) */ @@ -356,7 +363,7 @@ int HttpServer::pollHandler(int fd, short* events, void* parm) *----------------------------------------------------------------------------*/ int HttpServer::activeHandler(int fd, int flags, void* parm) { - HttpServer* s = (HttpServer*)parm; + HttpServer* s = static_cast(parm); int rc = 0; @@ -377,7 +384,7 @@ int HttpServer::activeHandler(int fd, int flags, void* parm) int HttpServer::onRead(int fd) { int status = 0; - connection_t* connection = connections[fd]; + Connection* connection = connections[fd]; rqst_state_t* state = &connection->rqst_state; uint32_t trace_id = start_trace(DEBUG, connection->trace_id, "on_read", "%s", "{}"); @@ -435,7 +442,7 @@ int HttpServer::onRead(int fd) /* Get Content Length */ try { - if(StringLib::str2long(connection->request->headers["content-length"], &connection->request->length)) + if(StringLib::str2long(connection->request->headers["content-length"]->c_str(), &connection->request->length)) { /* Allocate and Prepopulate Request Body */ connection->request->body = new uint8_t[connection->request->length + 1]; @@ -446,7 +453,7 @@ int HttpServer::onRead(int fd) } else { - mlog(CRITICAL, "Invalid Content-Length header: %s", connection->request->headers["content-length"]); + mlog(CRITICAL, "Invalid Content-Length header: %s", connection->request->headers["content-length"]->c_str()); status = INVALID_RC; // will close socket } } @@ -458,7 +465,7 @@ int HttpServer::onRead(int fd) /* Get Keep Alive Setting */ try { - if(StringLib::match(connection->request->headers["connection"], "keep-alive")) + if(StringLib::match(connection->request->headers["connection"]->c_str(), "keep-alive")) { connection->keep_alive = true; } @@ -484,18 +491,19 @@ int HttpServer::onRead(int fd) if(state->header_complete && (state->body_size >= connection->request->length) && (status >= 0)) { /* Handle Request */ + const char* path = connection->request->path; try { - EndpointObject* endpoint = routeTable[connection->request->path]; + EndpointObject* endpoint = routeTable[path]->route; connection->response_type = endpoint->handleRequest(connection->request); connection->request = NULL; // no longer owned by HttpServer, owned by EndpointObject - memset(&connection->rqst_state, 0, sizeof(rqst_state_t)); } catch(const RunTimeException& e) { - mlog(e.level(), "No attached endpoint at %s: %s", connection->request->path, e.what()); + mlog(e.level(), "No attached endpoint at %s: %s", path, e.what()); status = INVALID_RC; // will close socket } + memset(&connection->rqst_state, 0, sizeof(rqst_state_t)); } } else @@ -518,24 +526,24 @@ int HttpServer::onRead(int fd) int HttpServer::onWrite(int fd) { int status = 0; - connection_t* connection = connections[fd]; + Connection* connection = connections[fd]; rsps_state_t* state = &connection->rsps_state; uint32_t trace_id = start_trace(DEBUG, connection->trace_id, "on_write", "%s", "{}"); - bool ref_complete = false; - - uint8_t* buffer; - int bytes_left; - + /* If Something to Send */ if(state->ref_status > 0) { + bool ref_complete = false; + uint8_t* buffer; + int bytes_left; + if(state->header_sent && connection->response_type == EndpointObject::STREAMING) /* Setup Streaming */ { /* Allocate Streaming Buffer (if necessary) */ if(state->ref.size + STREAM_OVERHEAD_SIZE > state->stream_mem_size) { /* Delete Old Buffer */ - if(state->stream_buf) delete [] state->stream_buf; + delete [] state->stream_buf; /* Allocate New Buffer */ state->stream_mem_size = state->ref.size + STREAM_OVERHEAD_SIZE; @@ -637,9 +645,18 @@ int HttpServer::onWrite(int fd) /* Check for Keep Alive */ if(state->response_complete && connection->keep_alive) { - deinitConnection(connection); - initConnection(connection); - status = 0; // will keep socket open + Connection* new_connection = new Connection(*connection); + bool rc = connections.add(fd, new_connection, false); // deletes old connection + if(rc) + { + status = 0; // will keep socket open + } + else + { + mlog(CRITICAL, "Failed to keep connection open due to table error"); + status = INVALID_RC; // will close socket + delete new_connection; // free memory that would otherwise be leaked + } } } @@ -656,7 +673,7 @@ int HttpServer::onWrite(int fd) *----------------------------------------------------------------------------*/ int HttpServer::onAlive(int fd) { - connection_t* connection = connections[fd]; + Connection* connection = connections[fd]; rsps_state_t* state = &connection->rsps_state; if(!state->response_complete && state->ref_status <= 0) @@ -677,15 +694,12 @@ int HttpServer::onConnect(int fd) int status = 0; /* Create and Initialize New Request */ - connection_t* connection = new connection_t; - initConnection(connection); - memset(&connection->rqst_state, 0, sizeof(rqst_state_t)); + Connection* connection = new Connection(getName()); /* Register Connection */ - if(!connections.add(fd, connection, false)) + if(!connections.add(fd, connection, true)) { mlog(CRITICAL, "HTTP server at %s failed to register connection due to duplicate entry", connection->id); - deinitConnection(connection); delete connection; status = INVALID_RC; } @@ -702,23 +716,10 @@ int HttpServer::onDisconnect(int fd) { int status = 0; - connection_t* connection = connections[fd]; - - /* Update Metrics */ - if(metricId != EventLib::INVALID_METRIC) - { - double duration = TimeLib::latchtime() - connection->start_time; - EventLib::incrementMetric(metricId, duration); - } + Connection* connection = connections[fd]; /* Remove Connection */ - if(connections.remove(fd)) - { - /* Free Connection */ - deinitConnection(connection); - delete connection; - } - else + if(!connections.remove(fd)) { mlog(CRITICAL, "HTTP server at %s failed to release connection", connection->id); status = INVALID_RC; @@ -737,14 +738,16 @@ int HttpServer::luaAttach (lua_State* L) try { /* Get Self */ - HttpServer* lua_obj = (HttpServer*)getLuaSelf(L, 1); + HttpServer* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ - EndpointObject* endpoint = (EndpointObject*)getLuaObject(L, 2, EndpointObject::OBJECT_TYPE); + EndpointObject* endpoint = dynamic_cast(getLuaObject(L, 2, EndpointObject::OBJECT_TYPE)); const char* url = getLuaString(L, 3); /* Add Route to Table */ - status = lua_obj->routeTable.add(url, endpoint, true); + RouteEntry* entry = new RouteEntry(endpoint); + status = lua_obj->routeTable.add(url, entry, true); + if(!status) delete entry; } catch(const RunTimeException& e) { @@ -755,42 +758,6 @@ int HttpServer::luaAttach (lua_State* L) return returnLuaStatus(L, status); } -/*---------------------------------------------------------------------------- - * luaMetric - :metric() - * - * Note: NOT thread safe, must be called before first request - *----------------------------------------------------------------------------*/ -int HttpServer::luaMetric (lua_State* L) -{ - bool status = false; - - try - { - /* Get Self */ - HttpServer* lua_obj = (HttpServer*)getLuaSelf(L, 1); - - /* Get Object Name */ - const char* obj_name = lua_obj->getName(); - - /* Register Metrics */ - lua_obj->metricId = EventLib::registerMetric(obj_name, EventLib::COUNTER, "%s", DURATION_METRIC); - if(lua_obj->metricId == EventLib::INVALID_METRIC) - { - throw RunTimeException(ERROR, RTE_ERROR, "Registry failed for %s.%s", obj_name, DURATION_METRIC); - } - - /* Set return Status */ - status = true; - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Error creating metric: %s", e.what()); - } - - /* Return Status */ - return returnLuaStatus(L, status); -} - /*---------------------------------------------------------------------------- * luaUntilUp - :untilup() *----------------------------------------------------------------------------*/ @@ -801,7 +768,7 @@ int HttpServer::luaUntilUp (lua_State* L) try { /* Get Self */ - HttpServer* lua_obj = (HttpServer*)getLuaSelf(L, 1); + HttpServer* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ int timeout = getLuaInteger(L, 2, true, IO_PEND); @@ -811,7 +778,7 @@ int HttpServer::luaUntilUp (lua_State* L) { status = lua_obj->listening; if(status) break; - else if(timeout > 0) timeout--; + if(timeout > 0) timeout--; OsApi::performIOTimeout(); } while((timeout == IO_PEND) || (timeout > 0)); diff --git a/packages/core/HttpServer.h b/packages/core/HttpServer.h index cb727b60b..2d8540af6 100644 --- a/packages/core/HttpServer.h +++ b/packages/core/HttpServer.h @@ -64,11 +64,9 @@ class HttpServer: public LuaObject static const int DEFAULT_MAX_CONNECTIONS = 256; static const int STREAM_OVERHEAD_SIZE = 128; // chunk size, record size, and line breaks - static const char* DURATION_METRIC; - static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -79,8 +77,8 @@ class HttpServer: public LuaObject HttpServer (lua_State* L, const char* _ip_addr, int _port, int max_connections); ~HttpServer (void); - const char* getIpAddr (void); - int getPort (void); + const char* getIpAddr (void) const; + int getPort (void) const; private: @@ -109,16 +107,31 @@ class HttpServer: public LuaObject int stream_mem_size; } rsps_state_t; - typedef struct { + struct Connection { + explicit Connection(const char* _name); + explicit Connection(const Connection& other); + ~Connection(void); + void initialize (const char* _name); + const char* name; char* id; uint32_t trace_id; rqst_state_t rqst_state; rsps_state_t rsps_state; - double start_time; bool keep_alive; EndpointObject::rsptype_t response_type; EndpointObject::Request* request; - } connection_t; + }; + + struct RouteEntry { + RouteEntry(EndpointObject* _route=NULL) { route = _route; } + ~RouteEntry(void) { route->releaseLuaObject(); } + RouteEntry& operator= (const RouteEntry& other) { + if (this == &other) return *this; + route = other.route; + return *this; + } + EndpointObject* route; + }; /*-------------------------------------------------------------------- * Data @@ -129,9 +142,9 @@ class HttpServer: public LuaObject bool active; bool listening; Thread* listenerPid; - Table connections; + Table connections; - Dictionary routeTable; + Dictionary routeTable; char* ipAddr; int port; @@ -142,10 +155,8 @@ class HttpServer: public LuaObject * Methods *--------------------------------------------------------------------*/ - void initConnection (connection_t* connection); - void deinitConnection (connection_t* connection); - void extractPath (const char* url, const char** path, const char** resource); - bool processHttpHeader (char* buf, EndpointObject::Request* request); + static void extractPath (const char* url, const char** path, const char** resource); + static bool processHttpHeader (char* buf, EndpointObject::Request* request); static void* listenerThread (void* parm); static int pollHandler (int fd, short* events, void* parm); diff --git a/packages/core/IntervalIndex.cpp b/packages/core/IntervalIndex.cpp index 2da08cf10..ce0afa77d 100644 --- a/packages/core/IntervalIndex.cpp +++ b/packages/core/IntervalIndex.cpp @@ -43,8 +43,8 @@ * STATIC DATA ******************************************************************************/ -const char* IntervalIndex::LuaMetaName = "IntervalIndex"; -const struct luaL_Reg IntervalIndex::LuaMetaTable[] = { +const char* IntervalIndex::LUA_META_NAME = "IntervalIndex"; +const struct luaL_Reg IntervalIndex::LUA_META_TABLE[] = { {"add", luaAdd}, {"query", luaQuery}, {"display", luaDisplay}, @@ -63,7 +63,7 @@ int IntervalIndex::luaCreate (lua_State* L) try { /* Get Asset Directory */ - Asset* _asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + Asset* _asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* _fieldname0 = getLuaString(L, 2); const char* _fieldname1 = getLuaString(L, 3); int _threshold = getLuaInteger(L, 4, true, DEFAULT_THRESHOLD); @@ -73,7 +73,7 @@ int IntervalIndex::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -82,7 +82,7 @@ int IntervalIndex::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ IntervalIndex::IntervalIndex(lua_State* L, Asset*_asset, const char* _fieldname0, const char* _fieldname1, int _threshold): - AssetIndex(L, *_asset, LuaMetaName, LuaMetaTable, _threshold) + AssetIndex(L, *_asset, LUA_META_NAME, LUA_META_TABLE, _threshold) { assert(_fieldname0); assert(_fieldname1); @@ -142,8 +142,7 @@ bool IntervalIndex::isleft (node_t* node, const intervalspan_t& span) double right_val = node->right->span.t0; double split_val = (left_val + right_val) / 2.0; - if(span.t0 <= split_val) return true; - else return false; + return (span.t0 <= split_val); } /*---------------------------------------------------------------------------- @@ -158,8 +157,7 @@ bool IntervalIndex::isright (node_t* node, const intervalspan_t& span) double right_val = node->right->span.t0; double split_val = (left_val + right_val) / 2.0; - if(span.t1 >= split_val) return true; - else return false; + return (span.t1 >= split_val); } /*---------------------------------------------------------------------------- @@ -233,8 +231,8 @@ intervalspan_t IntervalIndex::luatable2span (lua_State* L, int parm) if(provided) { - if(StringLib::match(fieldname0, key)) span.t0 = value; - else if(StringLib::match(fieldname1, key)) span.t1 = value; + if (StringLib::match(fieldname0, key)) span.t0 = value; + else if(StringLib::match(fieldname1, key)) span.t1 = value; } lua_pop(L, 1); // removes 'value'; keeps 'key' for next iteration diff --git a/packages/core/IntervalIndex.h b/packages/core/IntervalIndex.h index 378c3c9e0..bc9f75642 100644 --- a/packages/core/IntervalIndex.h +++ b/packages/core/IntervalIndex.h @@ -78,8 +78,8 @@ class IntervalIndex: public AssetIndex * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Data diff --git a/packages/core/LimitDispatch.cpp b/packages/core/LimitDispatch.cpp index 1890e37b6..ec7d961da 100644 --- a/packages/core/LimitDispatch.cpp +++ b/packages/core/LimitDispatch.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* LimitDispatch::LuaMetaName = "LimitDispatch"; -const struct luaL_Reg LimitDispatch::LuaMetaTable[] = { +const char* LimitDispatch::LUA_META_NAME = "LimitDispatch"; +const struct luaL_Reg LimitDispatch::LUA_META_TABLE[] = { {"setloglvl", luaSetLogLevel}, {"gmtdisplay", luaGMTDisplay}, {NULL, NULL} @@ -76,7 +76,7 @@ int LimitDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -88,8 +88,8 @@ int LimitDispatch::luaCreate (lua_State* L) /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -LimitDispatch::LimitDispatch (lua_State* L, LimitRecord::limit_t _limit, const char* deepq_name, const char* limitq_name): - DispatchObject(L, LuaMetaName, LuaMetaTable) +LimitDispatch::LimitDispatch (lua_State* L, const LimitRecord::limit_t& _limit, const char* deepq_name, const char* limitq_name): + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { LimitRecord::defineRecord(LimitRecord::rec_type, "TYPE", sizeof(LimitRecord::limit_t), LimitRecord::rec_def, LimitRecord::rec_elem); @@ -116,8 +116,8 @@ LimitDispatch::LimitDispatch (lua_State* L, LimitRecord::limit_t _limit, const c *----------------------------------------------------------------------------*/ LimitDispatch::~LimitDispatch(void) { - if(limitQ) delete limitQ; - if(deepQ) delete deepQ; + delete limitQ; + delete deepQ; } /*---------------------------------------------------------------------------- @@ -188,7 +188,7 @@ bool LimitDispatch::processRecord (RecordObject* record, okey_t key, recVec_t* r } } } - else if(inError == false) + else if(!inError) { inError = true; mlog(WARNING, "Failed to find field %s in record %s", limit.field_name, record->getRecordType()); @@ -208,7 +208,7 @@ int LimitDispatch::luaSetLogLevel(lua_State* L) try { /* Get Self */ - LimitDispatch* lua_obj = (LimitDispatch*)getLuaSelf(L, 1); + LimitDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ event_level_t lvl = (event_level_t)getLuaInteger(L, 2); @@ -238,7 +238,7 @@ int LimitDispatch::luaGMTDisplay(lua_State* L) try { /* Get Self */ - LimitDispatch* lua_obj = (LimitDispatch*)getLuaSelf(L, 1); + LimitDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Configure Display */ lua_obj->gmtDisplay = getLuaBoolean(L, 2, false, false, &status); diff --git a/packages/core/LimitDispatch.h b/packages/core/LimitDispatch.h index 3c4da71ce..14b395ae7 100644 --- a/packages/core/LimitDispatch.h +++ b/packages/core/LimitDispatch.h @@ -57,8 +57,8 @@ class LimitDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -83,7 +83,7 @@ class LimitDispatch: public DispatchObject * Methods *--------------------------------------------------------------------*/ - LimitDispatch (lua_State* L, LimitRecord::limit_t _limit, const char* deepq_name, const char* limitq_name); + LimitDispatch (lua_State* L, const LimitRecord::limit_t& _limit, const char* deepq_name, const char* limitq_name); ~LimitDispatch (void); /* overridden methods */ diff --git a/packages/core/LimitRecord.cpp b/packages/core/LimitRecord.cpp index 0d52c9564..338da8a59 100644 --- a/packages/core/LimitRecord.cpp +++ b/packages/core/LimitRecord.cpp @@ -62,15 +62,15 @@ int LimitRecord::rec_elem = sizeof(LimitRecord::rec_def) / sizeof(RecordObject:: *----------------------------------------------------------------------------*/ LimitRecord::LimitRecord(void): RecordObject(rec_type) { - limit = (limit_t*)recordData; + limit = reinterpret_cast(recordData); } /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -LimitRecord::LimitRecord(limit_t _limit): RecordObject(rec_type) +LimitRecord::LimitRecord(const limit_t& _limit): RecordObject(rec_type) { - limit = (limit_t*)recordData; + limit = reinterpret_cast(recordData); *limit = _limit; } diff --git a/packages/core/LimitRecord.h b/packages/core/LimitRecord.h index 11c42d09b..2a9f0fc5a 100644 --- a/packages/core/LimitRecord.h +++ b/packages/core/LimitRecord.h @@ -70,7 +70,7 @@ class LimitRecord: public RecordObject static int rec_elem; LimitRecord(void); - LimitRecord(limit_t _limit); + explicit LimitRecord(const limit_t& _limit); ~LimitRecord(void); }; diff --git a/packages/core/List.h b/packages/core/List.h index 1247b1591..4ac0b064a 100644 --- a/packages/core/List.h +++ b/packages/core/List.h @@ -42,9 +42,17 @@ * LIST TEMPLATE ******************************************************************************/ -template +template class List { + public: + + /*-------------------------------------------------------------------- + * Constants + *--------------------------------------------------------------------*/ + + static const int DEFAULT_LIST_BLOCK_SIZE = 32; + protected: /*-------------------------------------------------------------------- @@ -52,7 +60,7 @@ class List *--------------------------------------------------------------------*/ typedef struct list_block_t { - T data[LIST_BLOCK_SIZE]; + T* data; int offset; struct list_block_t* next; } list_node_t; @@ -66,10 +74,11 @@ class List class Iterator { public: - Iterator (const List& l); + explicit Iterator (const List& l); ~Iterator (void); const T& operator[] (int index) const; const int length; + const int blockSize; private: const list_node_t** blocks; }; @@ -78,16 +87,16 @@ class List * Methods *--------------------------------------------------------------------*/ - List (void); + List (int list_block_size=DEFAULT_LIST_BLOCK_SIZE); List (const List& l1); - virtual ~List (void); + ~List (void); int add (const T& data); bool remove (int index); T& get (int index); - bool set (int index, T& data, bool with_delete=true); + bool set (int index, const T& data, bool with_delete=true); int length (void) const; - bool isempty (void) const; + bool empty (void) const; void clear (void); void sort (void); @@ -105,6 +114,7 @@ class List int len; list_node_t* prevnode; int prevblock; + int listBlockSize; /*-------------------------------------------------------------------- * Methods @@ -113,25 +123,11 @@ class List void initialize (void); void copy (const List& l1); list_node_t* newNode (void); - virtual void freeNode (typename List::list_node_t* node, int index); + void freeNode (typename List::list_node_t* node, int index); void quicksort (T* array, int start, int end); int quicksortpartition (T* array, int start, int end); }; -/****************************************************************************** - * MANAGED LIST TEMPLATE - ******************************************************************************/ - -template -class MgList: public List -{ - public: - MgList (void); - ~MgList (void); - private: - void freeNode (typename List::list_node_t* node, int index); -}; - /****************************************************************************** * ITERATOR METHODS ******************************************************************************/ @@ -139,14 +135,15 @@ class MgList: public List /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -template -List::Iterator::Iterator(const List& l): - length(l.len) +template +List::Iterator::Iterator(const List& l): + length(l.len), + blockSize(l.listBlockSize) { - int num_blocks = (length + (LIST_BLOCK_SIZE - 1)) / LIST_BLOCK_SIZE; - blocks = new const List::list_node_t* [num_blocks]; + int num_blocks = (length + (blockSize - 1)) / blockSize; + blocks = new const List::list_node_t* [num_blocks]; - const List::list_node_t* curr_block = &l.head; + const List::list_node_t* curr_block = &l.head; for(int b = 0; b < num_blocks; b++) { assert(curr_block); @@ -158,8 +155,8 @@ List::Iterator::Iterator(const List& l): /*---------------------------------------------------------------------------- * Destructor *----------------------------------------------------------------------------*/ -template -List::Iterator::~Iterator(void) +template +List::Iterator::~Iterator(void) { delete [] blocks; } @@ -167,20 +164,18 @@ List::Iterator::~Iterator(void) /*---------------------------------------------------------------------------- * [] *----------------------------------------------------------------------------*/ -template -const T& List::Iterator::operator[](int index) const +template +const T& List::Iterator::operator[](int index) const { if( (index < length) && (index >= 0) ) { - int node_block = index / LIST_BLOCK_SIZE; - int node_offset = index % LIST_BLOCK_SIZE; - const List::list_node_t* block = blocks[node_block]; + int node_block = index / blockSize; + int node_offset = index % blockSize; + const List::list_node_t* block = blocks[node_block]; return block->data[node_offset]; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "List::Iterator index out of range"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "List::Iterator index out of range"); } @@ -191,18 +186,24 @@ const T& List::Iterator::operator[](int index) const /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -template -List::List(void) +template +List::List(int list_block_size): + listBlockSize(list_block_size) { + assert(listBlockSize >= 0); + listBlockSize = listBlockSize == 0 ? DEFAULT_LIST_BLOCK_SIZE : listBlockSize; + head.data = new T [listBlockSize]; initialize(); } /*---------------------------------------------------------------------------- * Copy Constructor *----------------------------------------------------------------------------*/ -template -List::List(const List& l1) +template +List::List(const List& l1) { + listBlockSize = l1.listBlockSize; + head.data = new T [listBlockSize]; initialize(); copy(l1); } @@ -210,20 +211,21 @@ List::List(const List& l1) /*---------------------------------------------------------------------------- * Destructor *----------------------------------------------------------------------------*/ -template -List::~List(void) +template +List::~List(void) { clear(); + delete [] head.data; } /*---------------------------------------------------------------------------- * add *----------------------------------------------------------------------------*/ -template -int List::add(const T& data) +template +int List::add(const T& data) { /* Check if Current Node is Full */ - if(tail->offset >= LIST_BLOCK_SIZE) + if(tail->offset >= listBlockSize) { tail->next = newNode(); tail = tail->next; @@ -241,13 +243,13 @@ int List::add(const T& data) /*---------------------------------------------------------------------------- * remove *----------------------------------------------------------------------------*/ -template -bool List::remove(int index) +template +bool List::remove(int index) { if( (index < len) && (index >= 0) ) { - int node_block = index / LIST_BLOCK_SIZE; - int node_offset = index % LIST_BLOCK_SIZE; + int node_block = index / listBlockSize; + int node_offset = index % listBlockSize; list_node_t* curr = &head; list_node_t* prev = NULL; for(int i = 0; i < node_block; i++) @@ -272,6 +274,7 @@ bool List::remove(int index) /* Current Block Is Empty */ if(prev) // check that current block isn't head { + delete [] prev->next->data; delete prev->next; prev->next = NULL; } @@ -281,24 +284,25 @@ bool List::remove(int index) { /* Shift for Each Block */ int start_offset = node_offset; - int curr_offset = index; + int curr_index = index; while(curr != NULL) { /* Shift Current Block */ - for(int i = start_offset; (i < LIST_BLOCK_SIZE - 1) && (curr_offset < len - 1); i++) + for(int i = start_offset; (i < listBlockSize - 1) && (curr_index < len - 1); i++) { curr->data[i] = curr->data[i + 1]; - curr_offset++; + curr_index++; } /* Shift Last Item */ - if(curr_offset < (len - 1) && curr->next != NULL) + if(curr_index < (len - 1) && curr->next != NULL) { - curr->data[LIST_BLOCK_SIZE - 1] = curr->next->data[0]; - curr_offset++; - if(curr_offset >= (len - 1)) + curr->data[listBlockSize - 1] = curr->next->data[0]; + curr_index++; + if(curr_index >= (len - 1)) { /* Next Block Is Empty */ + delete [] curr->next->data; delete curr->next; curr->next = NULL; } @@ -318,7 +322,7 @@ bool List::remove(int index) len--; /* Recalculate the Tail */ - int tail_block = len / LIST_BLOCK_SIZE; + int tail_block = len / listBlockSize; tail = &head; for (int i = 0; i < tail_block; i++) { assert(tail); tail = tail->next; } @@ -332,13 +336,13 @@ bool List::remove(int index) /*---------------------------------------------------------------------------- * get *----------------------------------------------------------------------------*/ -template -T& List::get(int index) +template +T& List::get(int index) { if( (index < len) && (index >= 0) ) { - int node_block = index / LIST_BLOCK_SIZE; - int node_offset = index % LIST_BLOCK_SIZE; + int node_block = index / listBlockSize; + int node_offset = index % listBlockSize; list_node_t* curr = &head; if(node_block == prevblock) @@ -362,10 +366,8 @@ T& List::get(int index) assert(curr); return curr->data[node_offset]; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "List::get index out of range"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "List::get index out of range"); } /*---------------------------------------------------------------------------- @@ -374,13 +376,13 @@ T& List::get(int index) * with_delete which is defaulted to true, can be set to false for times when * the list is reordered in place and the caller wants control over deallocation *----------------------------------------------------------------------------*/ -template -bool List::set(int index, T& data, bool with_delete) +template +bool List::set(int index, const T& data, bool with_delete) { if( (index < len) && (index >= 0) ) { - int node_block = index / LIST_BLOCK_SIZE; - int node_offset = index % LIST_BLOCK_SIZE; + int node_block = index / listBlockSize; + int node_offset = index % listBlockSize; list_node_t* curr = &head; if(node_block == prevblock) @@ -406,26 +408,24 @@ bool List::set(int index, T& data, bool with_delete) return true; } - else - { - return false; - } + + return false; } /*---------------------------------------------------------------------------- * length *----------------------------------------------------------------------------*/ -template -int List::length(void) const +template +int List::length(void) const { return len; } /*---------------------------------------------------------------------------- - * isempty + * empty *----------------------------------------------------------------------------*/ -template -bool List::isempty(void) const +template +bool List::empty(void) const { return (len == 0); } @@ -433,8 +433,8 @@ bool List::isempty(void) const /*---------------------------------------------------------------------------- * clear *----------------------------------------------------------------------------*/ -template -void List::clear(void) +template +void List::clear(void) { /* Delete Head */ for(int i = 0; i < head.offset; i++) freeNode(&head, i); @@ -447,6 +447,7 @@ void List::clear(void) curr->offset = 0; list_node_t* prev = curr; curr = curr->next; + delete [] prev->data; delete prev; } @@ -458,8 +459,8 @@ void List::clear(void) /*---------------------------------------------------------------------------- * sort *----------------------------------------------------------------------------*/ -template -void List::sort(void) +template +void List::sort(void) { /* Allocate Array */ T* array = new T[len]; @@ -470,7 +471,7 @@ void List::sort(void) int index = 0; while(items_remaining > 0) { - int items_to_copy = MIN(items_remaining, LIST_BLOCK_SIZE); + int items_to_copy = MIN(items_remaining, listBlockSize); for(int i = 0; i < items_to_copy; i++) { array[index++] = curr->data[i]; @@ -488,7 +489,7 @@ void List::sort(void) index = 0; while(items_remaining > 0) { - int items_to_copy = MIN(items_remaining, LIST_BLOCK_SIZE); + int items_to_copy = MIN(items_remaining, listBlockSize); for(int i = 0; i < items_to_copy; i++) { curr->data[i] = array[index++]; @@ -504,8 +505,8 @@ void List::sort(void) /*---------------------------------------------------------------------------- * [] *----------------------------------------------------------------------------*/ -template -T& List::operator[](int index) +template +T& List::operator[](int index) { return get(index); } @@ -513,9 +514,11 @@ T& List::operator[](int index) /*---------------------------------------------------------------------------- * = *----------------------------------------------------------------------------*/ -template -List& List::operator= (const List& l1) +template +List& List::operator= (const List& l1) { + if(this == &l1) return *this; + listBlockSize = l1.listBlockSize; clear(); copy(l1); return *this; @@ -524,8 +527,8 @@ List& List::operator= (const List -void List::initialize(void) +template +void List::initialize(void) { head.offset = 0; head.next = NULL; @@ -538,8 +541,8 @@ void List::initialize(void) /*---------------------------------------------------------------------------- * = *----------------------------------------------------------------------------*/ -template -void List::copy(const List& l1) +template +void List::copy(const List& l1) { const list_node_t* curr = &l1.head; while(curr) @@ -555,10 +558,11 @@ void List::copy(const List& l1) /*---------------------------------------------------------------------------- * newNode *----------------------------------------------------------------------------*/ -template -typename List::list_node_t* List::newNode(void) +template +typename List::list_node_t* List::newNode(void) { list_node_t* node = new list_node_t; + node->data = new T [listBlockSize]; node->next = NULL; node->offset = 0; return node; @@ -567,18 +571,23 @@ typename List::list_node_t* List::newNod /*---------------------------------------------------------------------------- * freeNode *----------------------------------------------------------------------------*/ -template -void List::freeNode(typename List::list_node_t* node, int index) +template +static void listDeleteIfPointer(const T& t) { (void)t; } + +template +static void listDeleteIfPointer(T* t) { delete t; } + +template +void List::freeNode(typename List::list_node_t* node, int index) { - (void)node; - (void)index; + listDeleteIfPointer(node->data[index]); } /*---------------------------------------------------------------------------- * quicksort *----------------------------------------------------------------------------*/ -template -void List::quicksort(T* array, int start, int end) +template +void List::quicksort(T* array, int start, int end) { if(start < end) { @@ -591,8 +600,8 @@ void List::quicksort(T* array, int start, int end) /*---------------------------------------------------------------------------- * quicksortpartition *----------------------------------------------------------------------------*/ -template -int List::quicksortpartition(T* array, int start, int end) +template +int List::quicksortpartition(T* array, int start, int end) { double pivot = array[(start + end) / 2]; @@ -610,35 +619,4 @@ int List::quicksortpartition(T* array, int start, int end) } } -/****************************************************************************** - * MANAGED LIST METHODS - ******************************************************************************/ - -/*---------------------------------------------------------------------------- - * Constructor - *----------------------------------------------------------------------------*/ -template -MgList::MgList(void): List() -{ -} - -/*---------------------------------------------------------------------------- - * Destructor - *----------------------------------------------------------------------------*/ -template -MgList::~MgList(void) -{ - List::clear(); -} - -/*---------------------------------------------------------------------------- - * freeNode - *----------------------------------------------------------------------------*/ -template -void MgList::freeNode(typename List::list_node_t* node, int index) -{ - if(!is_array) delete node->data[index]; - else delete [] node->data[index]; -} - #endif /* __list__ */ diff --git a/packages/core/LuaEndpoint.cpp b/packages/core/LuaEndpoint.cpp index 5a789dbae..b2a7d7815 100644 --- a/packages/core/LuaEndpoint.cpp +++ b/packages/core/LuaEndpoint.cpp @@ -40,9 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* LuaEndpoint::LuaMetaName = "LuaEndpoint"; -const struct luaL_Reg LuaEndpoint::LuaMetaTable[] = { - {"metric", luaMetric}, +const char* LuaEndpoint::LUA_META_NAME = "LuaEndpoint"; +const struct luaL_Reg LuaEndpoint::LUA_META_TABLE[] = { {"auth", luaAuth}, {NULL, NULL} }; @@ -57,22 +56,19 @@ const RecordObject::fieldDef_t LuaEndpoint::EndpointExceptionRecDef[] = { const double LuaEndpoint::DEFAULT_NORMAL_REQUEST_MEMORY_THRESHOLD = 1.0; const double LuaEndpoint::DEFAULT_STREAM_REQUEST_MEMORY_THRESHOLD = 1.0; -SafeString LuaEndpoint::serverHead("sliderule/%s", LIBID); +FString LuaEndpoint::serverHead("sliderule/%s", LIBID); const char* LuaEndpoint::LUA_RESPONSE_QUEUE = "rspq"; const char* LuaEndpoint::LUA_REQUEST_ID = "rqstid"; -const char* LuaEndpoint::UNREGISTERED_ENDPOINT = "untracked"; -const char* LuaEndpoint::HITS_METRIC = "hits"; -int32_t LuaEndpoint::totalMetricId = EventLib::INVALID_METRIC; /****************************************************************************** * AUTHENTICATOR SUBCLASS ******************************************************************************/ const char* LuaEndpoint::Authenticator::OBJECT_TYPE = "Authenticator"; -const char* LuaEndpoint::Authenticator::LuaMetaName = "Authenticator"; -const struct luaL_Reg LuaEndpoint::Authenticator::LuaMetaTable[] = { +const char* LuaEndpoint::Authenticator::LUA_META_NAME = "Authenticator"; +const struct luaL_Reg LuaEndpoint::Authenticator::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -80,7 +76,7 @@ const struct luaL_Reg LuaEndpoint::Authenticator::LuaMetaTable[] = { * Constructor *----------------------------------------------------------------------------*/ LuaEndpoint::Authenticator::Authenticator(lua_State* L): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { } @@ -98,22 +94,9 @@ LuaEndpoint::Authenticator::~Authenticator(void) /*---------------------------------------------------------------------------- * init *----------------------------------------------------------------------------*/ -bool LuaEndpoint::init (void) +void LuaEndpoint::init (void) { - bool status = true; - - /* Register Metric */ - totalMetricId = EventLib::registerMetric(LuaEndpoint::LuaMetaName, EventLib::COUNTER, "%s.%s", UNREGISTERED_ENDPOINT, HITS_METRIC); - if(totalMetricId == EventLib::INVALID_METRIC) - { - mlog(ERROR, "Registry failed for %s.%s", UNREGISTERED_ENDPOINT, HITS_METRIC); - status = false; - } - - /* Register Record Definition */ RECDEF(EndpointExceptionRecType, EndpointExceptionRecDef, sizeof(response_exception_t), "code"); - - return status; } /*---------------------------------------------------------------------------- @@ -133,7 +116,7 @@ int LuaEndpoint::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -169,8 +152,7 @@ void LuaEndpoint::generateExceptionStatus (int code, event_level_t level, Publis * Constructor *----------------------------------------------------------------------------*/ LuaEndpoint::LuaEndpoint(lua_State* L, double normal_mem_thresh, double stream_mem_thresh, event_level_t lvl): - EndpointObject(L, LuaMetaName, LuaMetaTable), - metricIds(INITIAL_NUM_ENDPOINTS), + EndpointObject(L, LUA_META_NAME, LUA_META_TABLE), normalRequestMemoryThreshold(normal_mem_thresh), streamRequestMemoryThreshold(stream_mem_thresh), logLevel(lvl), @@ -192,7 +174,7 @@ void* LuaEndpoint::requestThread (void* parm) { EndpointObject::info_t* info = (EndpointObject::info_t*)parm; EndpointObject::Request* request = info->request; - LuaEndpoint* lua_endpoint = (LuaEndpoint*)info->endpoint; + LuaEndpoint* lua_endpoint = dynamic_cast(info->endpoint); /* Get Request Script */ const char* script_pathname = LuaEngine::sanitize(request->resource); @@ -203,13 +185,6 @@ void* LuaEndpoint::requestThread (void* parm) /* Log Request */ mlog(lua_endpoint->logLevel, "%s %s: %s", verb2str(request->verb), request->resource, request->body); - /* Update Metrics */ - int32_t metric_id = lua_endpoint->getMetricId(request->resource); - if(metric_id != EventLib::INVALID_METRIC) - { - increment_metric(DEBUG, metric_id); - } - /* Create Publisher */ Publisher* rspq = new Publisher(request->id); @@ -220,10 +195,10 @@ void* LuaEndpoint::requestThread (void* parm) char* bearer_token = NULL; /* Extract Bearer Token */ - const char* auth_hdr = NULL; + string* auth_hdr; if(request->headers.find("Authorization", &auth_hdr)) { - bearer_token = StringLib::find(auth_hdr, ' '); + bearer_token = StringLib::find(auth_hdr->c_str(), ' '); if(bearer_token) bearer_token += 1; } @@ -281,14 +256,14 @@ EndpointObject::rsptype_t LuaEndpoint::handleRequest (Request* request) Thread pid(requestThread, info, false); /* Return Response Type */ - if(request->verb == POST) return STREAMING; - else return NORMAL; + if(request->verb == POST) return STREAMING; + return NORMAL; } /*---------------------------------------------------------------------------- * normalResponse *----------------------------------------------------------------------------*/ -void LuaEndpoint::normalResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) +void LuaEndpoint::normalResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) const { char header[MAX_HDR_SIZE]; double mem; @@ -310,7 +285,7 @@ void LuaEndpoint::normalResponse (const char* scriptpath, Request* request, Publ if(result) { int result_length = StringLib::size(result, MAX_SOURCED_RESPONSE_SIZE); - int header_length = buildheader(header, OK, "text/plain", result_length, NULL, serverHead.str()); + int header_length = buildheader(header, OK, "text/plain", result_length, NULL, serverHead.c_str()); rspq->postCopy(header, header_length); rspq->postCopy(result, result_length); } @@ -335,13 +310,13 @@ void LuaEndpoint::normalResponse (const char* scriptpath, Request* request, Publ } /* Clean Up */ - if(engine) delete engine; + delete engine; } /*---------------------------------------------------------------------------- * streamResponse *----------------------------------------------------------------------------*/ -void LuaEndpoint::streamResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) +void LuaEndpoint::streamResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) const { char header[MAX_HDR_SIZE]; double mem; @@ -353,7 +328,7 @@ void LuaEndpoint::streamResponse (const char* scriptpath, Request* request, Publ ((mem = OsApi::memusage()) < streamRequestMemoryThreshold) ) { /* Send Header */ - int header_length = buildheader(header, OK, "application/octet-stream", 0, "chunked", serverHead.str()); + int header_length = buildheader(header, OK, "application/octet-stream", 0, "chunked", serverHead.c_str()); rspq->postCopy(header, header_length); /* Create Engine */ @@ -376,80 +351,7 @@ void LuaEndpoint::streamResponse (const char* scriptpath, Request* request, Publ } /* Clean Up */ - if(engine) delete engine; -} - -/*---------------------------------------------------------------------------- - * getMetricId - *----------------------------------------------------------------------------*/ -int32_t LuaEndpoint::getMetricId (const char* endpoint) -{ - int32_t metric_id = EventLib::INVALID_METRIC; - - try - { - metric_id = metricIds[endpoint]; - } - catch (const RunTimeException& e1) - { - (void)e1; - - try - { - metric_id = metricIds[UNREGISTERED_ENDPOINT]; - } - catch(const RunTimeException& e2) - { - (void)e2; - } - } - - return metric_id; -} - -/*---------------------------------------------------------------------------- - * luaMetric - :metric() - * - * Note: NOT thread safe, must be called prior to attaching endpoint to server - *----------------------------------------------------------------------------*/ -int LuaEndpoint::luaMetric (lua_State* L) -{ - bool status = false; - - try - { - /* Get Self */ - LuaEndpoint* lua_obj = (LuaEndpoint*)getLuaSelf(L, 1); - - /* Get Endpoint Name */ - const char* endpoint_name = getLuaString(L, 2); - - /* Get Object Name */ - const char* obj_name = lua_obj->getName(); - - /* Register Metrics */ - int32_t id = EventLib::registerMetric(obj_name, EventLib::COUNTER, "%s.%s", endpoint_name, HITS_METRIC); - if(id == EventLib::INVALID_METRIC) - { - throw RunTimeException(ERROR, RTE_ERROR, "Registry failed for %s.%s", obj_name, endpoint_name); - } - - /* Add to Metric Ids */ - if(!lua_obj->metricIds.add(endpoint_name, id, true)) - { - throw RunTimeException(ERROR, RTE_ERROR, "Could not associate metric id to endpoint"); - } - - /* Set return Status */ - status = true; - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Error creating metric: %s", e.what()); - } - - /* Return Status */ - return returnLuaStatus(L, status); + delete engine; } /*---------------------------------------------------------------------------- @@ -464,10 +366,10 @@ int LuaEndpoint::luaAuth (lua_State* L) try { /* Get Self */ - LuaEndpoint* lua_obj = (LuaEndpoint*)getLuaSelf(L, 1); + LuaEndpoint* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Authenticator */ - Authenticator* auth = (Authenticator*)getLuaObject(L, 2, LuaEndpoint::Authenticator::OBJECT_TYPE); + Authenticator* auth = dynamic_cast(getLuaObject(L, 2, LuaEndpoint::Authenticator::OBJECT_TYPE)); /* Set Authenticator */ lua_obj->authenticator = auth; diff --git a/packages/core/LuaEndpoint.h b/packages/core/LuaEndpoint.h index 5f9089c2a..b00f10a86 100644 --- a/packages/core/LuaEndpoint.h +++ b/packages/core/LuaEndpoint.h @@ -56,8 +56,8 @@ class LuaEndpoint: public EndpointObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const char* EndpointExceptionRecType; static const RecordObject::fieldDef_t EndpointExceptionRecDef[]; @@ -67,12 +67,9 @@ class LuaEndpoint: public EndpointObject static const int MAX_SOURCED_RESPONSE_SIZE = 0x8000000; // 128M static const int MAX_RESPONSE_TIME_MS = 5000; - static const int INITIAL_NUM_ENDPOINTS = 32; static const int MAX_EXCEPTION_TEXT_SIZE = 256; static const char* LUA_RESPONSE_QUEUE; static const char* LUA_REQUEST_ID; - static const char* UNREGISTERED_ENDPOINT; - static const char* HITS_METRIC; /*-------------------------------------------------------------------- * Typedefs @@ -93,8 +90,8 @@ class LuaEndpoint: public EndpointObject { public: static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; Authenticator(lua_State* L); virtual ~Authenticator(void); @@ -106,13 +103,13 @@ class LuaEndpoint: public EndpointObject * Data *--------------------------------------------------------------------*/ - static SafeString serverHead; + static FString serverHead; /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ - static bool init (void); + static void init (void); static int luaCreate (lua_State* L); static void generateExceptionStatus (int code, event_level_t level, Publisher* outq, bool* active, const char* errmsg, ...) VARG_CHECK(printf, 5, 6); @@ -129,20 +126,15 @@ class LuaEndpoint: public EndpointObject rsptype_t handleRequest (Request* request) override; - void normalResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id); - void streamResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id); + void normalResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) const; + void streamResponse (const char* scriptpath, Request* request, Publisher* rspq, uint32_t trace_id) const; - int32_t getMetricId (const char* endpoint); - - static int luaMetric (lua_State* L); static int luaAuth (lua_State* L); /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static int32_t totalMetricId; - Dictionary metricIds; double normalRequestMemoryThreshold; double streamRequestMemoryThreshold; event_level_t logLevel; diff --git a/packages/core/LuaEngine.cpp b/packages/core/LuaEngine.cpp index 83cb88095..123a10713 100644 --- a/packages/core/LuaEngine.cpp +++ b/packages/core/LuaEngine.cpp @@ -35,6 +35,7 @@ #include "LuaEngine.h" #include "core.h" +#include /****************************************************************************** * STATIC DATA @@ -129,7 +130,7 @@ LuaEngine::LuaEngine(const char* script, const char* arg, uint32_t trace_id, lua LuaEngine::~LuaEngine(void) { engineActive = false; - if(engineThread) delete engineThread; + delete engineThread; /* Close Lua State */ lua_close(L); @@ -137,8 +138,8 @@ LuaEngine::~LuaEngine(void) /* Free Engine Resources */ if(dInfo) { - if(dInfo->script) delete [] dInfo->script; - if(dInfo->arg) delete [] dInfo->arg; + delete [] dInfo->script; + delete [] dInfo->arg; delete dInfo; } @@ -174,8 +175,8 @@ void LuaEngine::deinit(void) int num_pkgs = pkgInitTable.length(); for(int i = 0; i < num_pkgs; i++) { - if(pkgInitTable[i].pkg_name) delete [] pkgInitTable[i].pkg_name; - if(pkgInitTable[i].pkg_version) delete [] pkgInitTable[i].pkg_version; + delete [] pkgInitTable[i].pkg_name; + delete [] pkgInitTable[i].pkg_version; } } pkgInitTableMutex.unlock(); @@ -186,7 +187,7 @@ void LuaEngine::deinit(void) int num_libs = libInitTable.length(); for(int i = 0; i < num_libs ; i++) { - if(libInitTable[i].lib_name) delete [] libInitTable[i].lib_name; + delete [] libInitTable[i].lib_name; } } libInitTableMutex.unlock(); @@ -364,11 +365,11 @@ void LuaEngine::showStack (lua_State* l, const char* prefix) *----------------------------------------------------------------------------*/ const char* LuaEngine::sanitize (const char* filename) { - SafeString delimeter("%c", PATH_DELIMETER); - SafeString safe_filename("%s", filename); - safe_filename.replace(delimeter.str(), "_"); - SafeString safe_pathname("%s%c%s%c%s.lua", CONFDIR, PATH_DELIMETER, "api", PATH_DELIMETER, safe_filename.str()); - return safe_pathname.str(true); + char* safe_filename = StringLib::duplicate(filename); + StringLib::replace(safe_filename, PATH_DELIMETER, '_'); + FString safe_pathname("%s%c%s%c%s.lua", CONFDIR, PATH_DELIMETER, "api", PATH_DELIMETER, safe_filename); + delete [] safe_filename; + return safe_pathname.c_str(true); } /*---------------------------------------------------------------------------- @@ -379,7 +380,7 @@ void LuaEngine::abortHook (lua_State *L, lua_Debug *ar) (void)ar; lua_pushstring(L, LUA_SELFKEY); lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */ - LuaEngine* li = (LuaEngine*)lua_touserdata(L, -1); + LuaEngine* li = static_cast(lua_touserdata(L, -1)); if(!li) { luaL_error(L, "Unable to access Lua engine - aborting!"); @@ -395,7 +396,7 @@ void LuaEngine::abortHook (lua_State *L, lua_Debug *ar) /*---------------------------------------------------------------------------- * getEngineId *----------------------------------------------------------------------------*/ -uint64_t LuaEngine::getEngineId(void) +uint64_t LuaEngine::getEngineId(void) const { return engineId; } @@ -438,7 +439,7 @@ bool LuaEngine::executeEngine(int timeout_ms) /*---------------------------------------------------------------------------- * isActive *----------------------------------------------------------------------------*/ -bool LuaEngine::isActive(void) +bool LuaEngine::isActive(void) const { return engineActive; } @@ -530,10 +531,8 @@ const char* LuaEngine::getResult (void) { return lua_tostring(L, 1); } - else - { - return NULL; - } + + return NULL; } /****************************************************************************** @@ -665,11 +664,11 @@ lua_State* LuaEngine::createState(luaStepHook hook) lua_setglobal(l, LUA_CONFDIR); /* Set Starting Lua Path */ - SafeString lpath("%s/?.lua;%s/api/?.lua", CONFDIR, CONFDIR); + FString lpath("%s/?.lua;%s/api/?.lua", CONFDIR, CONFDIR); lua_getglobal(l, "package" ); lua_getfield(l, -1, "path" ); // get field "path" from table at top of stack (-1) lua_pop(l, 1 ); // get rid of the string on the stack we just pushed on line 5 - lua_pushstring(l, lpath.str(false)); // push the new one + lua_pushstring(l, lpath.c_str()); // push the new one lua_setfield(l, -2, "path" ); // set the field "path" in table at -2 with value at top of stack lua_pop(l, 1 ); // get rid of package table from top of stack @@ -770,7 +769,7 @@ int LuaEngine::readlinecb(void) { if(lua_readline_interpreter) { - if(lua_readline_interpreter->engineActive == false) + if(!lua_readline_interpreter->engineActive) { /* Push control-d onto input buffer * ... this is used for interactive mode to terminate @@ -797,10 +796,7 @@ int LuaEngine::msghandler (lua_State* l) { return 1; /* that is the message */ } - else - { - msg = lua_pushfstring(l, "(error object is a %s value)", luaL_typename(l, 1)); - } + msg = lua_pushfstring(l, "(error object is a %s value)", luaL_typename(l, 1)); } luaL_traceback(l, l, msg, 1); /* append a standard traceback */ return 1; /* return the traceback */ @@ -1002,7 +998,8 @@ int LuaEngine::handlescript (const char* fname) int status = luaL_loadfile(L, fname); if (status == LUA_OK) { - int i, n; + int i; + int n; if (lua_getglobal(L, "arg") != LUA_TTABLE) { luaL_error(L, "'arg' is not a table"); @@ -1083,7 +1080,7 @@ int LuaEngine::pmain (lua_State *L) /* retrieve LuaEngine object from registry */ lua_pushstring(L, LUA_SELFKEY); lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */ - LuaEngine* li = (LuaEngine*)lua_touserdata(L, -1); + LuaEngine* li = static_cast(lua_touserdata(L, -1)); if(!li) { mlog(CRITICAL, "Unable to access lua interpreter"); diff --git a/packages/core/LuaEngine.h b/packages/core/LuaEngine.h index 502eb721a..e3e51dd64 100644 --- a/packages/core/LuaEngine.h +++ b/packages/core/LuaEngine.h @@ -105,9 +105,9 @@ class LuaEngine static const char* sanitize (const char* filename); static void abortHook (lua_State* L, lua_Debug *ar); - uint64_t getEngineId (void); + uint64_t getEngineId (void) const; bool executeEngine (int timeout_ms); - bool isActive (void); + bool isActive (void) const; void setBoolean (const char* name, bool val); void setInteger (const char* name, long val); void setNumber (const char* name, double val); @@ -196,7 +196,7 @@ class LuaEngine void lprint (void); void doREPL (void); int handlescript (const char* fname); - int collectargs (char** argv, int* first); + static int collectargs (char** argv, int* first); static int pmain (lua_State *L); }; diff --git a/packages/core/LuaLibraryMsg.cpp b/packages/core/LuaLibraryMsg.cpp index c99d5ef9a..d2cc4f786 100644 --- a/packages/core/LuaLibraryMsg.cpp +++ b/packages/core/LuaLibraryMsg.cpp @@ -191,7 +191,7 @@ RecordObject* LuaLibraryMsg::populateRecord (const char* population_string) } catch (const RunTimeException& e) { - if(record) delete record; + delete record; mlog(ERROR, "could not locate record definition for %s: %s", population_string, e.what()); } @@ -219,7 +219,7 @@ RecordObject* LuaLibraryMsg::associateRecord (const char* recclass, unsigned cha } catch (const RunTimeException& e) { - if(record) delete record; + delete record; mlog(ERROR, "could not locate record definition for %s: %s", recclass, e.what()); } @@ -359,10 +359,8 @@ int LuaLibraryMsg::lmsg_datatype(lua_State* L) lua_pushstring(L, datatypestr); return 1; } - else - { - return luaL_error(L, "invalid data type specified"); - } + + return luaL_error(L, "invalid data type specified"); } /*---------------------------------------------------------------------------- @@ -470,9 +468,9 @@ int LuaLibraryMsg::lmsg_sendlog (lua_State* L) /* Get Message */ size_t attr_size = 0; const char* attr = lua_tolstring(L, 3, &attr_size); - if(attr_size <= 0) + if(attr_size == 0) { - mlog(CRITICAL, "Invalid length of message: %ld", attr_size); + mlog(CRITICAL, "Invalid length of message: %lu", attr_size); return 0; } @@ -715,7 +713,8 @@ int LuaLibraryMsg::lmsg_gettype (lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } @@ -740,13 +739,14 @@ int LuaLibraryMsg::lmsg_getfieldvalue (lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } RecordObject::field_t field = rec_data->rec->getField(fldname); - RecordObject::valType_t valtype = rec_data->rec->getValueType(field); + RecordObject::valType_t valtype = RecordObject::getValueType(field); if(valtype == RecordObject::TEXT) { @@ -785,13 +785,14 @@ int LuaLibraryMsg::lmsg_setfieldvalue (lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } RecordObject::field_t field = rec_data->rec->getField(fldname); - RecordObject::valType_t valtype = rec_data->rec->getValueType(field); + RecordObject::valType_t valtype = RecordObject::getValueType(field); if(valtype == RecordObject::TEXT) { const char* val = lua_tostring(L, 3); @@ -826,7 +827,8 @@ int LuaLibraryMsg::lmsg_serialize(lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } @@ -849,7 +851,8 @@ int LuaLibraryMsg::lmsg_deserialize(lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } @@ -873,7 +876,8 @@ int LuaLibraryMsg::lmsg_tabulate(lua_State* L) { return luaL_error(L, "invalid record"); } - else if(rec_data->rec == NULL) + + if(rec_data->rec == NULL) { return luaL_error(L, "record does not exist"); } @@ -889,7 +893,7 @@ int LuaLibraryMsg::lmsg_tabulate(lua_State* L) for(int i = 0; i < numfields; i++) { RecordObject::field_t field = rec_data->rec->getField(fieldnames[i]); - switch(rec_data->rec->getValueType(field)) + switch(RecordObject::getValueType(field)) { case RecordObject::TEXT: { @@ -1007,7 +1011,7 @@ int LuaLibraryMsg::lmsg_detabulate(lua_State* L) { RecordObject::field_t field = record->getField(fieldnames[i]); lua_getfield(L, 1, fieldnames[i]); - switch(record->getValueType(field)) + switch(RecordObject::getValueType(field)) { case RecordObject::TEXT: { @@ -1101,8 +1105,8 @@ int LuaLibraryMsg::lmsg_deleterec (lua_State* L) recUserData_t* rec_data = (recUserData_t*)luaL_checkudata(L, 1, LUA_RECMETANAME); if(rec_data) { - if(rec_data->record_str) delete [] rec_data->record_str; - if(rec_data->rec) delete rec_data->rec; + delete [] rec_data->record_str; + delete rec_data->rec; } return 0; } diff --git a/packages/core/LuaLibrarySys.cpp b/packages/core/LuaLibrarySys.cpp index 33982e13e..b57fd8658 100644 --- a/packages/core/LuaLibrarySys.cpp +++ b/packages/core/LuaLibrarySys.cpp @@ -98,7 +98,7 @@ int LuaLibrarySys::lsys_version (lua_State* L) int64_t launch_time_gps = TimeLib::sys2gpstime(OsApi::getLaunchTime()); TimeLib::gmt_time_t timeinfo = TimeLib::gps2gmttime(launch_time_gps); TimeLib::date_t dateinfo = TimeLib::gmt2date(timeinfo); - SafeString timestr("%04d-%02d-%02dT%02d:%02d:%02dZ", timeinfo.year, dateinfo.month, dateinfo.day, timeinfo.hour, timeinfo.minute, timeinfo.second); + FString timestr("%04d-%02d-%02dT%02d:%02d:%02dZ", timeinfo.year, dateinfo.month, dateinfo.day, timeinfo.hour, timeinfo.minute, timeinfo.second); int64_t duration = TimeLib::gpstime() - launch_time_gps; const char** pkg_list = LuaEngine::getPkgList(); @@ -106,7 +106,7 @@ int LuaLibrarySys::lsys_version (lua_State* L) print2term("SlideRule Version: %s\n", LIBID); print2term("Build Information: %s\n", BUILDINFO); print2term("Environment Version: %s\n", OsApi::getEnvVersion()); - print2term("Launch Time: %s\n", timestr.str()); + print2term("Launch Time: %s\n", timestr.c_str()); print2term("Duration: %.2lf days\n", (double)duration / 1000.0 / 60.0 / 60.0 / 24.0); // milliseconds / seconds / minutes / hours print2term("Packages: [ "); if(pkg_list) @@ -125,7 +125,7 @@ int LuaLibrarySys::lsys_version (lua_State* L) lua_pushstring(L, LIBID); lua_pushstring(L, BUILDINFO); lua_pushstring(L, OsApi::getEnvVersion()); - lua_pushstring(L, timestr.str()); + lua_pushstring(L, timestr.c_str()); lua_pushinteger(L, duration); lua_newtable(L); if(pkg_list) @@ -228,47 +228,13 @@ int LuaLibrarySys::lsys_log (lua_State* L) } /*---------------------------------------------------------------------------- - * lsys_metric - .metric() --> table of metric values + * lsys_metric - .metric(<...) *----------------------------------------------------------------------------*/ -static void populate_metric_table (const EventLib::metric_t& metric, int32_t index, void* parm) -{ - (void)index; - - lua_State* L = (lua_State*)parm; - SafeString metric_full_name("%s.%s", metric.category, metric.name); - - lua_pushstring(L, metric_full_name.str()); - lua_newtable(L); - { - lua_pushstring(L, "value"); - lua_pushnumber(L, metric.value); - lua_settable(L, -3); - - lua_pushstring(L, "type"); - lua_pushstring(L, EventLib::subtype2str(metric.subtype)); - lua_settable(L, -3); - } - lua_settable(L, -3); -} - int LuaLibrarySys::lsys_metric (lua_State* L) +//TODO: need to create a metric like the log function { - /* Get Category Parameter */ - const char* category = NULL; - if(lua_isstring(L, 1)) // query category - { - category = lua_tostring(L, 1); - } - else if(!lua_isnil(L, 1) && lua_gettop(L) > 0) - { - mlog(CRITICAL, "Invalid parameter supplied to metric, must be nil or string (i.e. metric(\"mycategory\"))"); - return 0; - } - - /* Populate Metric Table */ - lua_newtable(L); - EventLib::iterateMetric(category, populate_metric_table, L); - return 1; + (void)L; + return 0; } /*---------------------------------------------------------------------------- @@ -422,11 +388,10 @@ int LuaLibrarySys::lsys_getiosize (lua_State* L) int LuaLibrarySys::lsys_seteventlvl (lua_State* L) { bool status = false; - int type_mask = 0; if(lua_isnumber(L, 1)) { - type_mask = lua_tonumber(L, 1); + int type_mask = lua_tonumber(L, 1); if(lua_isnumber(L, 2)) { event_level_t lvl = (event_level_t)lua_tonumber(L, 2); @@ -518,10 +483,8 @@ int LuaLibrarySys::lsys_cwd (lua_State* L) lua_pushstring(L, cwd); return 1; } - else - { - return 0; - } + + return 0; } /*---------------------------------------------------------------------------- diff --git a/packages/core/LuaLibraryTime.cpp b/packages/core/LuaLibraryTime.cpp index c835936f2..ab7d9146e 100644 --- a/packages/core/LuaLibraryTime.cpp +++ b/packages/core/LuaLibraryTime.cpp @@ -178,29 +178,25 @@ int LuaLibraryTime::ltime_gmt2gps (lua_State* L) { return luaL_error(L, "expecting 5 arguments"); } - else - { - TimeLib::gmt_time_t gmt; - gmt.year = (int)lua_tonumber(L, 1); /* get argument 1 */ - gmt.doy = (int)lua_tonumber(L, 2); /* get argument 2 */ - gmt.hour = (int)lua_tonumber(L, 3); /* get argument 3 */ - gmt.minute = (int)lua_tonumber(L, 4); /* get argument 4 */ - gmt.second = (int)lua_tonumber(L, 5); /* get argument 5 */ - gmt.millisecond = (int)lua_tonumber(L, 5) - gmt.second; /* fractional part */ - int64_t ms = TimeLib::gmt2gpstime(gmt); - lua_pushnumber(L, (lua_Number)ms); /* push "ms" as result */ - return 1; /* one result */ - } - } - else // string - { - const char* gmt = lua_tostring(L, 1); /* get argument 1 */ - if(!gmt) return luaL_error(L, "invalid string passed to gmt2gps function"); - int64_t ms = TimeLib::str2gpstime(gmt); + TimeLib::gmt_time_t gmt; + gmt.year = (int)lua_tonumber(L, 1); /* get argument 1 */ + gmt.doy = (int)lua_tonumber(L, 2); /* get argument 2 */ + gmt.hour = (int)lua_tonumber(L, 3); /* get argument 3 */ + gmt.minute = (int)lua_tonumber(L, 4); /* get argument 4 */ + gmt.second = (int)lua_tonumber(L, 5); /* get argument 5 */ + gmt.millisecond = (int)lua_tonumber(L, 5) - gmt.second; /* fractional part */ + int64_t ms = TimeLib::gmt2gpstime(gmt); lua_pushnumber(L, (lua_Number)ms); /* push "ms" as result */ return 1; /* one result */ } + + const char* gmt = lua_tostring(L, 1); /* get argument 1 */ + if(!gmt) return luaL_error(L, "invalid string passed to gmt2gps function"); + + int64_t ms = TimeLib::str2gpstime(gmt); + lua_pushnumber(L, (lua_Number)ms); /* push "ms" as result */ + return 1; /* one result */ } /*---------------------------------------------------------------------------- diff --git a/packages/core/LuaObject.cpp b/packages/core/LuaObject.cpp index deb52e97a..69e4c2385 100644 --- a/packages/core/LuaObject.cpp +++ b/packages/core/LuaObject.cpp @@ -44,7 +44,7 @@ ******************************************************************************/ const char* LuaObject::BASE_OBJECT_TYPE = "LuaObject"; -Dictionary LuaObject::globalObjects; +Dictionary LuaObject::globalObjects; Mutex LuaObject::globalMut; /****************************************************************************** @@ -54,19 +54,19 @@ Mutex LuaObject::globalMut; /*---------------------------------------------------------------------------- * getType *----------------------------------------------------------------------------*/ -const char* LuaObject::getType (void) +const char* LuaObject::getType (void) const { - if(ObjectType) return ObjectType; - else return ""; + if(ObjectType) return ObjectType; + return ""; } /*---------------------------------------------------------------------------- * getName *----------------------------------------------------------------------------*/ -const char* LuaObject::getName (void) +const char* LuaObject::getName (void) const { - if(ObjectName) return ObjectName; - else return ""; + if(ObjectName) return ObjectName; + return ""; } /*---------------------------------------------------------------------------- @@ -93,7 +93,7 @@ int LuaObject::luaGetByName(lua_State* L) verbose = getLuaBoolean(L, 2, true, true); /* Get Self */ - lua_obj = globalObjects.get(name); + lua_obj = globalObjects.get(name).lua_obj; /* Return Lua Object */ associateMetaTable(L, lua_obj->LuaMetaName, lua_obj->LuaMetaTable); @@ -123,14 +123,13 @@ long LuaObject::getLuaInteger (lua_State* L, int parm, bool optional, long dfltv if(provided) *provided = true; return lua_tointeger(L, parm); } - else if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) + + if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) { return dfltval; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "must supply an integer for parameter #%d", parm); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "must supply an integer for parameter #%d", parm); } /*---------------------------------------------------------------------------- @@ -145,14 +144,13 @@ double LuaObject::getLuaFloat (lua_State* L, int parm, bool optional, double dfl if(provided) *provided = true; return lua_tonumber(L, parm); } - else if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) + + if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) { return dfltval; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a floating point number for parameter #%d", parm); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a floating point number for parameter #%d", parm); } /*---------------------------------------------------------------------------- @@ -167,14 +165,13 @@ bool LuaObject::getLuaBoolean (lua_State* L, int parm, bool optional, bool dfltv if(provided) *provided = true; return lua_toboolean(L, parm); } - else if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) + + if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) { return dfltval; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a boolean for parameter #%d", parm); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a boolean for parameter #%d", parm); } /*---------------------------------------------------------------------------- @@ -189,14 +186,13 @@ const char* LuaObject::getLuaString (lua_State* L, int parm, bool optional, cons if(provided) *provided = true; return lua_tostring(L, parm); } - else if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) + + if(optional && ((lua_gettop(L) < parm) || lua_isnil(L, parm))) { return dfltval; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a string for parameter #%d", parm); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "must supply a string for parameter #%d", parm); } /*---------------------------------------------------------------------------- @@ -233,7 +229,7 @@ LuaObject* LuaObject::getLuaObjectByName (const char* name, const char* object_t { try { - LuaObject* obj = globalObjects.get(name); + LuaObject* obj = globalObjects.get(name).lua_obj; if(StringLib::match(obj->getType(), object_type)) { lua_obj = obj; @@ -271,6 +267,7 @@ bool LuaObject::releaseLuaObject (void) /* Delete THIS Object */ if(is_delete_pending) { + if(userData) userData->luaObj = NULL; delete this; } @@ -289,13 +286,13 @@ LuaObject::LuaObject (lua_State* L, const char* object_type, const char* meta_na ObjectName(NULL), LuaMetaName(meta_name), LuaMetaTable(meta_table), - LuaState(L) + LuaState(L), + referenceCount(0), + userData(NULL), + objComplete(false) { uint32_t engine_trace_id = ORIGIN; - referenceCount = 0; - objComplete = false; - if(LuaState) { /* Trace from Lua Engine */ @@ -333,7 +330,7 @@ LuaObject::~LuaObject (void) } /*---------------------------------------------------------------------------- - * luaDelete + * luaDelete - called only by the garbage collector *----------------------------------------------------------------------------*/ int LuaObject::luaDelete (lua_State* L) { @@ -357,6 +354,7 @@ int LuaObject::luaDelete (lua_State* L) else { mlog(DEBUG, "Delaying delete on referenced object %s/%s <%d>", lua_obj->getType(), lua_obj->getName(), count); + lua_obj->userData = NULL; // user data is now out of scope } } else @@ -380,17 +378,61 @@ int LuaObject::luaDelete (lua_State* L) return 0; } +/*---------------------------------------------------------------------------- + * luaDestroy - called explicitly by scripts + *----------------------------------------------------------------------------*/ +int LuaObject::luaDestroy (lua_State* L) +{ + try + { + luaUserData_t* user_data = (luaUserData_t*)lua_touserdata(L, 1); + if(user_data) + { + LuaObject* lua_obj = user_data->luaObj; + if(lua_obj) + { + int count = lua_obj->referenceCount--; + mlog(DEBUG, "Destroying object %s/%s <%d>", lua_obj->getType(), lua_obj->getName(), count); + + if(lua_obj->referenceCount == 0) + { + /* Delete Object */ + delete lua_obj; + user_data->luaObj = NULL; + } + else + { + mlog(DEBUG, "Delaying destroy on referenced object %s/%s <%d>", lua_obj->getType(), lua_obj->getName(), count); + } + } + else + { + throw RunTimeException(CRITICAL, RTE_ERROR, "Attempting to destroy lua object that has already been deleted"); + } + } + else + { + throw RunTimeException(CRITICAL, RTE_ERROR, "unable to retrieve user data"); + } + } + catch(const RunTimeException& e) + { + mlog(e.level(), "Error destroying object: %s", e.what()); + } + + return 0; +} /*---------------------------------------------------------------------------- * luaName *----------------------------------------------------------------------------*/ int LuaObject::luaName(lua_State* L) { - bool status = false; - try { - /* Get Self */ + bool status = false; + + /* Get Self */ LuaObject* lua_obj = getLuaSelf(L, 1); /* Get Name */ @@ -403,7 +445,8 @@ int LuaObject::luaName(lua_State* L) if(!lua_obj->ObjectName) { /* Register Name */ - if(globalObjects.add(name, lua_obj, true)) + global_object_t global_object = { .lua_obj = lua_obj }; + if(globalObjects.add(name, global_object, true)) { /* Associate Name */ lua_obj->ObjectName = StringLib::duplicate(name); @@ -508,7 +551,7 @@ void LuaObject::associateMetaTable (lua_State* L, const char* meta_name, const s LuaEngine::setAttrFunc(L, "name", luaName); LuaEngine::setAttrFunc(L, "getbyname", luaGetByName); LuaEngine::setAttrFunc(L, "waiton", luaWaitOn); - LuaEngine::setAttrFunc(L, "destroy", luaDelete); + LuaEngine::setAttrFunc(L, "destroy", luaDestroy); LuaEngine::setAttrFunc(L, "__gc", luaDelete); } } @@ -521,8 +564,8 @@ void LuaObject::associateMetaTable (lua_State* L, const char* meta_name, const s int LuaObject::createLuaObject (lua_State* L, LuaObject* lua_obj) { /* Create Lua User Data Object */ - luaUserData_t* user_data = (luaUserData_t*)lua_newuserdata(L, sizeof(luaUserData_t)); - if(!user_data) + lua_obj->userData = (luaUserData_t*)lua_newuserdata(L, sizeof(luaUserData_t)); + if(!lua_obj->userData) { throw RunTimeException(CRITICAL, RTE_ERROR, "failed to allocate new user data"); } @@ -531,7 +574,7 @@ int LuaObject::createLuaObject (lua_State* L, LuaObject* lua_obj) lua_obj->referenceCount++; /* Return User Data to Lua */ - user_data->luaObj = lua_obj; + lua_obj->userData->luaObj = lua_obj; luaL_getmetatable(L, lua_obj->LuaMetaName); lua_setmetatable(L, -2); return 1; @@ -582,20 +625,14 @@ LuaObject* LuaObject::getLuaSelf (lua_State* L, int parm) { return user_data->luaObj; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "object method called from inconsistent type <%s>", user_data->luaObj->LuaMetaName); - } - } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "object method called on emtpy object"); + + throw RunTimeException(CRITICAL, RTE_ERROR, "object method called from inconsistent type <%s>", user_data->luaObj->LuaMetaName); } + + throw RunTimeException(CRITICAL, RTE_ERROR, "object method called on emtpy object"); } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "calling object method from something not an object"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "calling object method from something not an object"); } /*---------------------------------------------------------------------------- @@ -603,9 +640,9 @@ LuaObject* LuaObject::getLuaSelf (lua_State* L, int parm) *----------------------------------------------------------------------------*/ void LuaObject::referenceLuaObject (LuaObject* lua_obj) { - lua_obj->globalMut.lock(); + globalMut.lock(); { lua_obj->referenceCount++; } - lua_obj->globalMut.unlock(); + globalMut.unlock(); } diff --git a/packages/core/LuaObject.h b/packages/core/LuaObject.h index add5102ff..4d47c85eb 100644 --- a/packages/core/LuaObject.h +++ b/packages/core/LuaObject.h @@ -85,8 +85,8 @@ class LuaObject virtual ~LuaObject (void); - const char* getType (void); - const char* getName (void); + const char* getType (void) const; + const char* getName (void) const; static int luaGetByName (lua_State* L); static int getLuaNumParms (lua_State* L); @@ -138,19 +138,29 @@ class LuaObject /* Meta Table Functions */ static int luaDelete (lua_State* L); + static int luaDestroy (lua_State* L); static int luaName (lua_State* L); static int luaWaitOn (lua_State* L); + /*-------------------------------------------------------------------- + * Types + *--------------------------------------------------------------------*/ + + typedef struct { + LuaObject* lua_obj; + } global_object_t; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static Dictionary globalObjects; - static Mutex globalMut; + static Dictionary globalObjects; + static Mutex globalMut; - std::atomic referenceCount; - Cond objSignal; - bool objComplete; + std::atomic referenceCount; + luaUserData_t* userData; + Cond objSignal; + bool objComplete; }; #endif /* __lua_object__ */ diff --git a/packages/core/LuaScript.cpp b/packages/core/LuaScript.cpp index 587bc3b97..2d5cb0090 100644 --- a/packages/core/LuaScript.cpp +++ b/packages/core/LuaScript.cpp @@ -43,8 +43,8 @@ ******************************************************************************/ const char* LuaScript::OBJECT_TYPE = "LuaScript"; -const char* LuaScript::LuaMetaName = "LuaScript"; -const struct luaL_Reg LuaScript::LuaMetaTable[] = { +const char* LuaScript::LUA_META_NAME = "LuaScript"; +const struct luaL_Reg LuaScript::LUA_META_TABLE[] = { {"active", luaActive}, {"result", luaResult}, {NULL, NULL} @@ -79,17 +79,17 @@ int LuaScript::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ LuaScript::LuaScript(lua_State* L, const char* script, const char* arg): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(script); /* Sanitize */ if(script[0] != ' ' && script[0] != '/') { - SafeString safe_filename("%s", script); - safe_filename.replace("..", "_"); - SafeString safe_pathname("%s%c%s.lua", CONFDIR, PATH_DELIMETER, safe_filename.str()); - engine = new LuaEngine(safe_pathname.str(), arg, traceId, LuaEngine::abortHook, false); + const char* safe_filename = StringLib::replace(script, "..", "_"); + FString safe_pathname("%s%c%s.lua", CONFDIR, PATH_DELIMETER, safe_filename); + engine = new LuaEngine(safe_pathname.c_str(), arg, traceId, LuaEngine::abortHook, false); + delete [] safe_filename; } else { @@ -102,7 +102,7 @@ LuaScript::LuaScript(lua_State* L, const char* script, const char* arg): *----------------------------------------------------------------------------*/ LuaScript::~LuaScript(void) { - if(engine) delete engine; + delete engine; } /*---------------------------------------------------------------------------- @@ -113,7 +113,7 @@ int LuaScript::luaActive (lua_State* L) try { /* Get Self */ - LuaScript* lua_obj = (LuaScript*)getLuaSelf(L, 1); + LuaScript* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Check Engine */ if(lua_obj->engine) @@ -121,10 +121,8 @@ int LuaScript::luaActive (lua_State* L) /* Return Is Active */ return returnLuaStatus(L, lua_obj->engine->isActive()); } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "engine does not exist"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "engine does not exist"); } catch(const RunTimeException& e) { @@ -141,7 +139,7 @@ int LuaScript::luaResult (lua_State* L) try { /* Get Self */ - LuaScript* lua_obj = (LuaScript*)getLuaSelf(L, 1); + LuaScript* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Check Engine */ if(lua_obj->engine) @@ -153,10 +151,8 @@ int LuaScript::luaResult (lua_State* L) lua_pushstring(L, result); return returnLuaStatus(L, true, 2); } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "engine does not exist"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "engine does not exist"); } catch(const RunTimeException& e) { diff --git a/packages/core/LuaScript.h b/packages/core/LuaScript.h index 780f5e359..d9abf0de8 100644 --- a/packages/core/LuaScript.h +++ b/packages/core/LuaScript.h @@ -59,8 +59,8 @@ class LuaScript: public LuaObject *--------------------------------------------------------------------*/ static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/MathLib.cpp b/packages/core/MathLib.cpp index cf87fca21..23fcb153c 100644 --- a/packages/core/MathLib.cpp +++ b/packages/core/MathLib.cpp @@ -71,7 +71,7 @@ const int MathLib::B64INDEX[256] = /*---------------------------------------------------------------------------- * FFT *----------------------------------------------------------------------------*/ -double MathLib::FFT(double result[], int input[], unsigned long size) +double MathLib::FFT(double result[], const int input[], unsigned long size) { static complex_t frequency_spectrum[MAXFREQSPEC]; double maxvalue = 0.0; @@ -111,7 +111,7 @@ double MathLib::FFT(double result[], int input[], unsigned long size) /*---------------------------------------------------------------------------- * coord2point *----------------------------------------------------------------------------*/ -MathLib::point_t MathLib::coord2point (const coord_t c, proj_t projection) +MathLib::point_t MathLib::coord2point (coord_t c, proj_t projection) { point_t p; @@ -121,7 +121,8 @@ MathLib::point_t MathLib::coord2point (const coord_t c, proj_t projection) if(projection == NORTH_POLAR || projection == SOUTH_POLAR) { - double r = 0.0, o = 0.0; + double r = 0.0; + double o = 0.0; /* Calculate r */ if(projection == NORTH_POLAR) @@ -162,11 +163,12 @@ MathLib::point_t MathLib::coord2point (const coord_t c, proj_t projection) /*---------------------------------------------------------------------------- * point2coord *----------------------------------------------------------------------------*/ -MathLib::coord_t MathLib::point2coord (const point_t p, proj_t projection) +MathLib::coord_t MathLib::point2coord (point_t p, proj_t projection) { coord_t c; - double lonrad = 0.0, latrad = 90.0; + double lonrad = 0.0; + double latrad = 90.0; if(projection == NORTH_POLAR || projection == SOUTH_POLAR) { @@ -281,12 +283,13 @@ bool MathLib::inpoly (point_t* poly, int len, point_t point) * Author: polfosol * License: assumed to be CC BY-SA 3.0 *----------------------------------------------------------------------------*/ -const std::string MathLib::b64encode(const void* data, const size_t &len) +std::string MathLib::b64encode(const void* data, const size_t &len) { std::string result((len + 2) / 3 * 4, '='); unsigned char *p = (unsigned char*) data; char *str = &result[0]; - size_t j = 0, pad = len % 3; + size_t j = 0; + size_t pad = len % 3; const size_t last = len - pad; for (size_t i = 0; i < last; i += 3) @@ -314,14 +317,14 @@ const std::string MathLib::b64encode(const void* data, const size_t &len) * Author: polfosol * License: assumed to be CC BY-SA 3.0 *----------------------------------------------------------------------------*/ -const std::string MathLib::b64decode(const void* data, const size_t &len) +std::string MathLib::b64decode(const void* data, const size_t &len) { if (len == 0) return ""; unsigned char *p = (unsigned char*) data; - size_t j = 0, - pad1 = len % 4 || p[len - 1] == '=', - pad2 = pad1 && (len % 4 > 2 || p[len - 2] != '='); + size_t j = 0; + size_t pad1 = len % 4 || p[len - 1] == '='; + size_t pad2 = pad1 && (len % 4 > 2 || p[len - 2] != '='); const size_t last = (len - pad1) / 4 << 2; std::string result(last / 4 * 3 + pad1 + pad2, '\0'); unsigned char *str = (unsigned char*) &result[0]; @@ -376,8 +379,10 @@ void MathLib::swapComplex(complex_t *a, complex_t *b) *----------------------------------------------------------------------------*/ void MathLib::bitReverse(complex_t data[], unsigned long size) { - unsigned long steps[LOG2DATASIZE], s; - unsigned long i,j,k; + unsigned long steps[LOG2DATASIZE]; + unsigned long s; + unsigned long i; + unsigned long j; // Calculate Steps // steps[0] = size / 2; @@ -398,7 +403,7 @@ void MathLib::bitReverse(complex_t data[], unsigned long size) // Calculate Step Size // s = 0; - k = i; + unsigned long k = i; while(k % 2 != 0) // trying to find first zero in binary representation { k >>= 1; @@ -422,15 +427,15 @@ void MathLib::freqCorrelation(complex_t data[], unsigned long size, int isign) { unsigned long halfperiod; // half period of frequency unsigned long offset; // offset within halfperiod - unsigned long i,j; // sample indices - double theta; + unsigned long i; // sample indices + unsigned long j; // sample indices complex_t temp; complex_t w; complex_t wp; for(halfperiod = 1; halfperiod < size; halfperiod *= 2) { - theta = isign * (M_PI / halfperiod); + double theta = isign * (M_PI / halfperiod); wp.r = -2.0 * pow(sin(0.5 * theta),2); wp.i = sin(theta); diff --git a/packages/core/MathLib.h b/packages/core/MathLib.h index 8c66e4247..2afc6c6c0 100644 --- a/packages/core/MathLib.h +++ b/packages/core/MathLib.h @@ -81,13 +81,13 @@ class MathLib * Methods *--------------------------------------------------------------------*/ - static double FFT (double result[], int data[], unsigned long size); - static point_t coord2point (const coord_t c, proj_t projection); - static coord_t point2coord (const point_t p, proj_t projection); + static double FFT (double result[], const int input[], unsigned long size); + static point_t coord2point (coord_t c, proj_t projection); + static coord_t point2coord (point_t p, proj_t projection); static bool inpoly (point_t* poly, int len, point_t point); - static const std::string b64encode(const void* data, const size_t &len); - static const std::string b64decode(const void* data, const size_t &len); + static std::string b64encode(const void* data, const size_t &len); + static std::string b64decode(const void* data, const size_t &len); private: diff --git a/packages/core/MetricDispatch.cpp b/packages/core/MetricDispatch.cpp index 2f6bfde3e..61f3abf66 100644 --- a/packages/core/MetricDispatch.cpp +++ b/packages/core/MetricDispatch.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* MetricDispatch::LuaMetaName = "MetricDispatch"; -const struct luaL_Reg MetricDispatch::LuaMetaTable[] = { +const char* MetricDispatch::LUA_META_NAME = "MetricDispatch"; +const struct luaL_Reg MetricDispatch::LUA_META_TABLE[] = { {"pbsource", luaPlaybackSource}, {"pbtext", luaPlaybackText}, {"pbname", luaPlaybackName}, @@ -84,7 +84,7 @@ int MetricDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -97,7 +97,7 @@ int MetricDispatch::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ MetricDispatch::MetricDispatch(lua_State* L, const char* _data_field, const char* outq_name, List* _id_filter): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { /* Define Metric Record */ RecordObject::defineRecord(MetricRecord::rec_type, NULL, sizeof(MetricRecord::metric_t), MetricRecord::rec_def, MetricRecord::rec_elem); @@ -122,10 +122,10 @@ MetricDispatch::MetricDispatch(lua_State* L, const char* _data_field, const char *----------------------------------------------------------------------------*/ MetricDispatch::~MetricDispatch(void) { - if(dataField) delete [] dataField; - if(idFilter) delete idFilter; - if(fieldFilter) delete fieldFilter; - if(outQ) delete outQ; + delete [] dataField; + delete idFilter; + delete fieldFilter; + delete outQ; } /*---------------------------------------------------------------------------- @@ -200,7 +200,7 @@ bool MetricDispatch::processRecord (RecordObject* record, okey_t key, recVec_t* while(enabled && field_name) { RecordObject::field_t field = record->getField(field_name); - RecordObject::valType_t field_type = record->getValueType(field); + RecordObject::valType_t field_type = RecordObject::getValueType(field); if((field_type == RecordObject::INTEGER) && (filter_value->lvalue != record->getValueInteger(field))) { enabled = filter_value->enable; @@ -236,14 +236,16 @@ bool MetricDispatch::processRecord (RecordObject* record, okey_t key, recVec_t* if(playbackSource) size = record->serialize(&src, RecordObject::ALLOCATE); // allocates memory here /* Playback Text */ - const char* text = NULL; char valbuf[RecordObject::MAX_VAL_STR_SIZE]; - if(playbackText) text = record->getValueText(data_field, valbuf); + char* text = &valbuf[0]; + if(playbackText) record->getValueText(data_field, valbuf); + else text = NULL; /* Playback Name */ - const char* name = NULL; - char nambuf[MAX_STR_SIZE]; - if(playbackName) name = StringLib::format(nambuf, MAX_STR_SIZE, "%s.%s", record->getRecordType(), dataField); + char namebuf[MAX_STR_SIZE]; + char* name = &namebuf[0]; + if(playbackName) StringLib::format(namebuf, MAX_STR_SIZE, "%s.%s", record->getRecordType(), dataField); + else name = NULL; /* Playback Value */ double value = record->getValueReal(data_field); @@ -284,7 +286,7 @@ int MetricDispatch::luaPlaybackSource(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Configure Playback Source */ lua_obj->playbackSource = getLuaBoolean(L, 2, false, false, &status); @@ -308,7 +310,7 @@ int MetricDispatch::luaPlaybackText(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Configure Playback Source */ lua_obj->playbackText = getLuaBoolean(L, 2, false, false, &status); @@ -332,7 +334,7 @@ int MetricDispatch::luaPlaybackName(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Configure Playback Source */ lua_obj->playbackName = getLuaBoolean(L, 2, false, false, &status); @@ -356,7 +358,7 @@ int MetricDispatch::luaSetKeyOffset(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Offset String */ const char* offset_str = getLuaString(L, 2); @@ -397,7 +399,7 @@ int MetricDispatch::luaSetKeyRange(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Offset String */ const char* min_str = getLuaString(L, 2); @@ -463,7 +465,7 @@ int MetricDispatch::luaAddFilter(lua_State* L) try { /* Get Self */ - MetricDispatch* lua_obj = (MetricDispatch*)getLuaSelf(L, 1); + MetricDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* field_name = getLuaString(L, 2); @@ -482,7 +484,7 @@ int MetricDispatch::luaAddFilter(lua_State* L) /* Create Dictionary if Necessary */ if(lua_obj->fieldFilter == NULL) { - lua_obj->fieldFilter = new MgDictionary(FIELD_FILTER_DICT_SIZE); + lua_obj->fieldFilter = new Dictionary(FIELD_FILTER_DICT_SIZE); } /* Add Field Filter */ diff --git a/packages/core/MetricDispatch.h b/packages/core/MetricDispatch.h index 24e30f888..e2208e848 100644 --- a/packages/core/MetricDispatch.h +++ b/packages/core/MetricDispatch.h @@ -54,8 +54,8 @@ class MetricDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -97,7 +97,7 @@ class MetricDispatch: public DispatchObject ~fieldValue_t(void) { - if(svalue) delete [] svalue; + delete [] svalue; } }; @@ -105,19 +105,19 @@ class MetricDispatch: public DispatchObject * Data *--------------------------------------------------------------------*/ - const char* dataField; // value of metric - List* idFilter; // id of record, not data or key - MgDictionary* fieldFilter; // more computationally intensive filter, matches field to value - Publisher* outQ; // output queue metrics are posted to + const char* dataField; // value of metric + List* idFilter; // id of record, not data or key + Dictionary* fieldFilter; // more computationally intensive filter, matches field to value + Publisher* outQ; // output queue metrics are posted to - bool playbackSource; - bool playbackText; - bool playbackName; - okey_t keyOffset; - okey_t minKey; - okey_t maxKey; + bool playbackSource; + bool playbackText; + bool playbackName; + okey_t keyOffset; + okey_t minKey; + okey_t maxKey; - Mutex metricMutex; + Mutex metricMutex; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/MetricRecord.cpp b/packages/core/MetricRecord.cpp index 4b6e6d3db..09a064d0d 100644 --- a/packages/core/MetricRecord.cpp +++ b/packages/core/MetricRecord.cpp @@ -61,7 +61,7 @@ MetricRecord::MetricRecord(okey_t _index, double _value, const char* _text, cons RecordObject(rec_type, calcRecordSize(_text, _name, _src_size)) { /* Populate Initial Metric */ - metric = (metric_t*)recordData; + metric = reinterpret_cast(recordData); metric->index = _index; metric->value = _value; metric->text_offset = 0; diff --git a/packages/core/Monitor.cpp b/packages/core/Monitor.cpp index 433a34779..160d7758c 100644 --- a/packages/core/Monitor.cpp +++ b/packages/core/Monitor.cpp @@ -42,8 +42,8 @@ * STATIC DATA ******************************************************************************/ -const char* Monitor::LuaMetaName = "Monitor"; -const struct luaL_Reg Monitor::LuaMetaTable[] = { +const char* Monitor::LUA_META_NAME = "Monitor"; +const struct luaL_Reg Monitor::LUA_META_TABLE[] = { {"config", luaConfig}, {"tail", luaTail}, {"cat", luaCat}, @@ -55,7 +55,7 @@ const struct luaL_Reg Monitor::LuaMetaTable[] = { ******************************************************************************/ /*---------------------------------------------------------------------------- - * luaCreate - create([], [], [], []) + * luaCreate - create([], [], []) *----------------------------------------------------------------------------*/ int Monitor::luaCreate (lua_State* L) { @@ -65,27 +65,34 @@ int Monitor::luaCreate (lua_State* L) uint8_t type_mask = (uint8_t)getLuaInteger(L, 1, true, (long)EventLib::LOG); event_level_t level = (event_level_t)getLuaInteger(L, 2, true, CRITICAL); format_t format = (format_t)getLuaInteger(L, 3, true, RECORD); - const char* outq_name = getLuaString(L, 4, true, NULL); /* Return Dispatch Object */ - return createLuaObject(L, new Monitor(L, type_mask, level, format, outq_name)); + return createLuaObject(L, new Monitor(L, type_mask, level, format)); } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } /****************************************************************************** - * PRIVATE METHODS + * PROTECTED METHODS ******************************************************************************/ +/*---------------------------------------------------------------------------- + * processEvent + *----------------------------------------------------------------------------*/ +void Monitor::processEvent(const unsigned char* event_buf_ptr, int event_size) +{ + fwrite(event_buf_ptr, 1, event_size, stdout); +} + /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -Monitor::Monitor(lua_State* L, uint8_t type_mask, event_level_t level, format_t format, const char* outq_name): - DispatchObject(L, LuaMetaName, LuaMetaTable) +Monitor::Monitor(lua_State* L, uint8_t type_mask, event_level_t level, format_t format): + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { /* Initialize Event Monitor */ eventTypeMask = type_mask; @@ -94,10 +101,6 @@ Monitor::Monitor(lua_State* L, uint8_t type_mask, event_level_t level, format_t eventTailArray = NULL; eventTailSize = 0; eventTailIndex = 0; - - /* Initialize Output Q */ - if(outq_name) outQ = new Publisher(outq_name); - else outQ = NULL; } /*---------------------------------------------------------------------------- @@ -105,10 +108,13 @@ Monitor::Monitor(lua_State* L, uint8_t type_mask, event_level_t level, format_t *----------------------------------------------------------------------------*/ Monitor::~Monitor(void) { - if(outQ) delete outQ; - if(eventTailArray) delete [] eventTailArray; + delete [] eventTailArray; } +/****************************************************************************** + * PRIVATE METHODS + ******************************************************************************/ + /*---------------------------------------------------------------------------- * processRecord *----------------------------------------------------------------------------*/ @@ -119,6 +125,7 @@ bool Monitor::processRecord (RecordObject* record, okey_t key, recVec_t* records int event_size; char event_buffer[MAX_EVENT_SIZE]; + unsigned char* event_buf_ptr = (unsigned char*)&event_buffer[0]; /* Pull Out Log Message */ EventLib::event_t* event = (EventLib::event_t*)record->getRecordData(); @@ -130,46 +137,39 @@ bool Monitor::processRecord (RecordObject* record, okey_t key, recVec_t* records return true; } - /* Process Event */ + /* Format Event */ if(outputFormat == RECORD) { - /* Post Event as Record */ - unsigned char* buffer; // reference to serial buffer - int size = record->serialize(&buffer, RecordObject::REFERENCE); - if(outQ) outQ->postCopy(buffer, size, IO_CHECK); + event_size = record->serialize(&event_buf_ptr, RecordObject::REFERENCE); + event_size = MIN(event_size, MAX_EVENT_SIZE); + } + else if(outputFormat == CLOUD) + { + event_size = cloudOutput(event, event_buffer); + } + else if(outputFormat == TEXT) + { + event_size = textOutput(event, event_buffer); + } + else if(outputFormat == JSON) + { + event_size = jsonOutput(event, event_buffer); } else { - /* Format Event */ - if(outputFormat == CLOUD) - { - event_size = cloudOutput(event, event_buffer); - } - else if(outputFormat == TEXT) - { - event_size = textOutput(event, event_buffer); - } - else if(outputFormat == JSON) - { - event_size = jsonOutput(event, event_buffer); - } - else - { - return false; - } - - /* Post Event */ - if(outQ) outQ->postCopy(event_buffer, event_size, IO_CHECK); - else fwrite(event_buffer, 1, event_size, stdout); + return false; + } - /* (Optionally) Tail Event */ - if(eventTailArray) - { - memcpy(&eventTailArray[eventTailIndex * MAX_EVENT_SIZE], event_buffer, event_size); - eventTailIndex = (eventTailIndex + 1) % eventTailSize; - } + /* (Optionally) Tail Event */ + if(eventTailArray) + { + memcpy(&eventTailArray[eventTailIndex * MAX_EVENT_SIZE], event_buf_ptr, event_size); + eventTailIndex = (eventTailIndex + 1) % eventTailSize; } + /* Post Event */ + processEvent(event_buf_ptr, event_size); + /* Return Success */ return true; } @@ -224,7 +224,7 @@ int Monitor::jsonOutput (EventLib::event_t* event, char* event_buffer) } /* Return Size of Message */ - return msg - event_buffer + 1;; + return msg - event_buffer + 1; } /*---------------------------------------------------------------------------- @@ -254,7 +254,7 @@ int Monitor::luaConfig (lua_State* L) try { /* Get Self */ - Monitor* lua_obj = (Monitor*)getLuaSelf(L, 1); + Monitor* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Set Type Mask */ uint8_t type_mask = getLuaInteger(L, 2, true, 0, &provided); @@ -294,7 +294,7 @@ int Monitor::luaTail (lua_State* L) try { /* Get Self */ - Monitor* lua_obj = (Monitor*)getLuaSelf(L, 1); + Monitor* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Tail Size */ int tail_size = getLuaInteger(L, 2); @@ -339,7 +339,7 @@ int Monitor::luaCat (lua_State* L) try { /* Get Self */ - Monitor* lua_obj = (Monitor*)getLuaSelf(L, 1); + Monitor* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Mode */ cat_mode_t mode = (cat_mode_t)getLuaInteger(L, 2, true, TERM); diff --git a/packages/core/Monitor.h b/packages/core/Monitor.h index fb79a0d02..722907b14 100644 --- a/packages/core/Monitor.h +++ b/packages/core/Monitor.h @@ -54,8 +54,8 @@ class Monitor: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Typedefs @@ -78,7 +78,17 @@ class Monitor: public DispatchObject * Methods *--------------------------------------------------------------------*/ - static int luaCreate (lua_State* L); + static int luaCreate (lua_State* L); + + protected: + + /*-------------------------------------------------------------------- + * Methods + *--------------------------------------------------------------------*/ + + virtual void processEvent (const unsigned char* event_buf_ptr, int event_size); + Monitor (lua_State* L, uint8_t type_mask, event_level_t level, format_t format); + ~Monitor (void); private: @@ -93,14 +103,12 @@ class Monitor: public DispatchObject * Methods *--------------------------------------------------------------------*/ - Monitor (lua_State* L, uint8_t type_mask, event_level_t level, format_t format, const char* outq_name); - ~Monitor (void); bool processRecord (RecordObject* record, okey_t key, recVec_t* records) override; - int textOutput (EventLib::event_t* event, char* event_buffer); - int jsonOutput (EventLib::event_t* event, char* event_buffer); - int cloudOutput (EventLib::event_t* event, char* event_buffer); + static int textOutput (EventLib::event_t* event, char* event_buffer); + static int jsonOutput (EventLib::event_t* event, char* event_buffer); + static int cloudOutput (EventLib::event_t* event, char* event_buffer); static int luaConfig (lua_State* L); static int luaTail (lua_State* L); @@ -113,7 +121,6 @@ class Monitor: public DispatchObject uint8_t eventTypeMask; event_level_t eventLevel; format_t outputFormat; - Publisher* outQ; char* eventTailArray; // [][MAX_EVENT_SIZE] int eventTailSize; int eventTailIndex; diff --git a/packages/core/MsgBridge.cpp b/packages/core/MsgBridge.cpp index dc8ae83d5..574a32387 100644 --- a/packages/core/MsgBridge.cpp +++ b/packages/core/MsgBridge.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* MsgBridge::LuaMetaName = "MsgBridge"; -const struct luaL_Reg MsgBridge::LuaMetaTable[] = { +const char* MsgBridge::LUA_META_NAME = "MsgBridge"; +const struct luaL_Reg MsgBridge::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -65,7 +65,7 @@ int MsgBridge::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -78,7 +78,7 @@ int MsgBridge::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ MsgBridge::MsgBridge(lua_State* L, const char* inputq_name, const char* outputq_name): - LuaObject(L, BASE_OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, BASE_OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(inputq_name); assert(outputq_name); @@ -112,7 +112,7 @@ MsgBridge::~MsgBridge(void) *----------------------------------------------------------------------------*/ void* MsgBridge::bridgeThread(void* parm) { - MsgBridge* bridge = (MsgBridge*)parm; + MsgBridge* bridge = static_cast(parm); /* Loop Forever */ while(bridge->active) diff --git a/packages/core/MsgBridge.h b/packages/core/MsgBridge.h index 3c12daa42..41cbf7912 100644 --- a/packages/core/MsgBridge.h +++ b/packages/core/MsgBridge.h @@ -60,8 +60,8 @@ class MsgBridge: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/MsgProcessor.cpp b/packages/core/MsgProcessor.cpp index 79dd82963..9856fbffa 100644 --- a/packages/core/MsgProcessor.cpp +++ b/packages/core/MsgProcessor.cpp @@ -98,7 +98,7 @@ bool MsgProcessor::handleTimeout(void) /*---------------------------------------------------------------------------- * isActive *----------------------------------------------------------------------------*/ -bool MsgProcessor::isActive(void) +bool MsgProcessor::isActive(void) const { return processorActive; } @@ -106,18 +106,11 @@ bool MsgProcessor::isActive(void) /*---------------------------------------------------------------------------- * isFull *----------------------------------------------------------------------------*/ -bool MsgProcessor::isFull(void) +bool MsgProcessor::isFull(void) const { int pkts_in_q = inQ->getCount(); int space_in_q = inQ->getDepth(); - if (pkts_in_q > 0 && pkts_in_q == space_in_q) - { - return true; - } - else - { - return false; - } + return (pkts_in_q > 0 && pkts_in_q == space_in_q); } /*---------------------------------------------------------------------------- @@ -157,11 +150,11 @@ void* MsgProcessor::processorThread(void* parm) { assert(parm); - MsgProcessor* processor = (MsgProcessor*)parm; + MsgProcessor* processor = static_cast(parm); bool self_delete = false; /* Initialize Processing */ - if(processor->initProcessing() != true) + if(!processor->initProcessing()) { self_delete = true; } @@ -219,7 +212,7 @@ int MsgProcessor::luaDrain (lua_State* L) try { /* Get Self */ - MsgProcessor* lua_obj = (MsgProcessor*)getLuaSelf(L, 1); + MsgProcessor* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Drain Queue */ lua_obj->inQ->drain(); diff --git a/packages/core/MsgProcessor.h b/packages/core/MsgProcessor.h index 76b2b9cf7..9cd3084b5 100644 --- a/packages/core/MsgProcessor.h +++ b/packages/core/MsgProcessor.h @@ -68,8 +68,8 @@ class MsgProcessor: public LuaObject virtual bool deinitProcessing (void); // ...that would be undesirable to put in a constructor / destructor virtual bool handleTimeout (void); - bool isActive (void); - bool isFull (void); + bool isActive (void) const; + bool isFull (void) const; void flush (void); void stop (void); void start (void); diff --git a/packages/core/MsgQ.cpp b/packages/core/MsgQ.cpp index 6720b06ed..bdb91e59c 100644 --- a/packages/core/MsgQ.cpp +++ b/packages/core/MsgQ.cpp @@ -45,7 +45,7 @@ ******************************************************************************/ int MsgQ::StandardQueueDepth = MsgQ::CFG_DEPTH_INFINITY; -Dictionary MsgQ::queues; +Dictionary MsgQ::queues; Mutex MsgQ::listmut; /****************************************************************************** @@ -62,7 +62,7 @@ MsgQ::MsgQ(const char* name, MsgQ::free_func_t free_func, int depth, int data_si { try { - msgQ = queues[name]; // exception thrown here if name is null or not found + msgQ = queues[name].queue; // exception thrown here if name is null or not found msgQ->attachments++; // if found, then another attachment is made // set free function to support publishers later establishing a // free function on a queue created by a subscriber @@ -103,7 +103,8 @@ MsgQ::MsgQ(const char* name, MsgQ::free_func_t free_func, int depth, int data_si } // Register message queue with non-null name - if(msgQ->name) queues.add(msgQ->name, msgQ); + global_queue_t global_queue = { .queue = msgQ }; + if(msgQ->name) queues.add(msgQ->name, global_queue); } } listmut.unlock(); @@ -143,7 +144,7 @@ MsgQ::~MsgQ() /* Free message queue resources */ delete msgQ->locknblock; - if(msgQ->name) delete [] msgQ->name; + delete [] msgQ->name; delete [] msgQ->free_block_stack; delete [] msgQ->subscriber_type; delete [] msgQ->curr_nodes; @@ -204,14 +205,8 @@ bool MsgQ::isFull(void) { return false; } - else if(msgQ->len >= msgQ->depth) - { - return true; - } - else - { - return false; - } + + return (msgQ->len >= msgQ->depth); } /*---------------------------------------------------------------------------- @@ -231,15 +226,15 @@ void MsgQ::init(void) *----------------------------------------------------------------------------*/ void MsgQ::deinit(void) { - message_queue_t* curr_q = NULL; + global_queue_t curr_q; const char* curr_name = queues.first(&curr_q); while(curr_name) { - delete [] curr_q->name; - delete [] curr_q->free_block_stack; - delete [] curr_q->subscriber_type; - delete [] curr_q->curr_nodes; - delete curr_q; + delete [] curr_q.queue->name; + delete [] curr_q.queue->free_block_stack; + delete [] curr_q.queue->subscriber_type; + delete [] curr_q.queue->curr_nodes; + delete curr_q.queue; curr_name = queues.next(&curr_q); } } @@ -266,15 +261,15 @@ int MsgQ::numQ(void) int MsgQ::listQ(queueDisplay_t* list, int list_size) { int j = 0; - message_queue_t* curr_q = NULL; + global_queue_t curr_q; const char* curr_name = queues.first(&curr_q); while(curr_name) { if(j >= list_size) break; - list[j].name = curr_q->name; - list[j].len = curr_q->len; - list[j].subscriptions = curr_q->subscriptions; - switch(curr_q->state) + list[j].name = curr_q.queue->name; + list[j].len = curr_q.queue->len; + list[j].subscriptions = curr_q.queue->subscriptions; + switch(curr_q.queue->state) { case STATE_OKAY : list[j].state = "OKAY"; break; case STATE_TIMEOUT : list[j].state = "TIMEOUT"; break; @@ -300,10 +295,8 @@ bool MsgQ::setStdQDepth(int depth) StandardQueueDepth = depth; return true; } - else - { - return false; - } + + return false; } /****************************************************************************** @@ -357,8 +350,8 @@ int Publisher::postRef(void* data, int size, int timeout) int Publisher::postCopy(const void* data, int size, int timeout) { int status = post((void*)data, ((unsigned int)size) | MSGQ_COPYQ_MASK, NULL, 0, timeout); - if(status == STATE_OKAY) return size; - else return status; + if(status == STATE_OKAY) return size; + return status; } /*---------------------------------------------------------------------------- @@ -381,8 +374,8 @@ int Publisher::postCopy(const void* data, int size, const void* secondary_data, int status = post((void*)data, ((unsigned int)size) | MSGQ_COPYQ_MASK, (void*)secondary_data, secondary_size, timeout); - if(status == STATE_OKAY) return size + secondary_size; - else return status; + if(status == STATE_OKAY) return size + secondary_size; + return status; } /*---------------------------------------------------------------------------- @@ -410,8 +403,8 @@ int Publisher::postString(const char* format_string, ...) /* Post the String */ int status = post(str, ((unsigned int)slen) | MSGQ_COPYQ_MASK, NULL, 0, IO_CHECK); - if(status == STATE_OKAY) return slen; - else return status; + if(status == STATE_OKAY) return slen; + return status; } /*---------------------------------------------------------------------------- @@ -576,8 +569,6 @@ Subscriber::Subscriber(const MsgQ& existing_q, subscriber_type_t type): MsgQ(exi *----------------------------------------------------------------------------*/ Subscriber::~Subscriber() { - bool space_reclaimed = false; - msgQ->locknblock->lock(); { /* Dereference All Nodes */ @@ -587,7 +578,7 @@ Subscriber::~Subscriber() node->refs--; node = node->next; } - space_reclaimed = reclaim_nodes(true); + bool space_reclaimed = reclaim_nodes(true); /* Clean up Remaining Free Blocks */ if(msgQ->subscriptions == 1) @@ -677,8 +668,7 @@ void Subscriber::drain(bool with_delete) *----------------------------------------------------------------------------*/ bool Subscriber::isEmpty(void) { - if(msgQ->curr_nodes[id] == NULL) return true; - else return false; + return (msgQ->curr_nodes[id] == NULL); } /*---------------------------------------------------------------------------- @@ -723,8 +713,8 @@ int Subscriber::receiveCopy(void* data, int size, int timeout) msgRef_t ref; ref.data = data; int status = receive(ref, size, timeout, true); - if(status == STATE_OKAY) return ref.size; - else return status; + if(status == STATE_OKAY) return ref.size; + return status; } /*---------------------------------------------------------------------------- @@ -736,8 +726,6 @@ int Subscriber::receiveCopy(void* data, int size, int timeout) *----------------------------------------------------------------------------*/ int Subscriber::receive(msgRef_t& ref, int size, int timeout, bool copy) { - bool space_reclaimed = false; - /* initialize reference structure */ ref.state = STATE_OKAY; ref.size = size; @@ -746,6 +734,8 @@ int Subscriber::receive(msgRef_t& ref, int size, int timeout, bool copy) /* receive data */ msgQ->locknblock->lock(); { + bool space_reclaimed = false; + /* check state of queue */ if(timeout != IO_CHECK) { @@ -774,7 +764,7 @@ int Subscriber::receive(msgRef_t& ref, int size, int timeout, bool copy) int node_size = node->mask & ~MSGQ_COPYQ_MASK; /* perform dequeue */ - if(copy == false) + if(!copy) { ref.data = node->data; ref.size = node_size; diff --git a/packages/core/MsgQ.h b/packages/core/MsgQ.h index af8111d50..2b323cfc2 100644 --- a/packages/core/MsgQ.h +++ b/packages/core/MsgQ.h @@ -94,8 +94,8 @@ class MsgQ * Methods *--------------------------------------------------------------------*/ - MsgQ (const char* name, free_func_t free_func=NULL, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); - MsgQ (const MsgQ& existing_q, free_func_t free_func=NULL); + explicit MsgQ (const char* name, free_func_t free_func=NULL, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); + explicit MsgQ (const MsgQ& existing_q, free_func_t free_func=NULL); ~MsgQ (void); int getCount (void); @@ -119,7 +119,7 @@ class MsgQ *--------------------------------------------------------------------*/ static const int MSGQ_DEFAULT_SUBSCRIBERS = 2; - static const unsigned int MSGQ_COPYQ_MASK = 1 << ((sizeof(unsigned int) * 8) - 1); + static const unsigned int MSGQ_COPYQ_MASK = 1U << ((sizeof(unsigned int) * 8) - 1); /*-------------------------------------------------------------------- * Types @@ -161,12 +161,16 @@ class MsgQ int free_blocks; // current number of blocks of free_block_stack } message_queue_t; + typedef struct { + message_queue_t* queue; + } global_queue_t; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ static int StandardQueueDepth; - static Dictionary queues; + static Dictionary queues; static Mutex listmut; message_queue_t* msgQ; @@ -182,21 +186,21 @@ class Publisher: public MsgQ static const int MAX_POSTED_STR = 1024; - Publisher (const char* name, MsgQ::free_func_t free_func=defaultFree, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); - Publisher (const MsgQ& existing_q, MsgQ::free_func_t free_func=defaultFree); - ~Publisher (void); + explicit Publisher (const char* name, MsgQ::free_func_t free_func=defaultFree, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); + explicit Publisher (const MsgQ& existing_q, MsgQ::free_func_t free_func=defaultFree); + ~Publisher (void); - int postRef (void* data, int size, int timeout=IO_CHECK); - int postCopy (const void* data, int size, int timeout=IO_CHECK); - int postCopy (const void* data, int size, const void* secondary_data, int secondary_size, int timeout=IO_CHECK); - int postString (const char* format_string, ...) VARG_CHECK(printf, 2, 3); // "this" is 1 + int postRef (void* data, int size, int timeout=IO_CHECK); + int postCopy (const void* data, int size, int timeout=IO_CHECK); + int postCopy (const void* data, int size, const void* secondary_data, int secondary_size, int timeout=IO_CHECK); + int postString (const char* format_string, ...) VARG_CHECK(printf, 2, 3); // "this" is 1 - static void defaultFree (void* obj, void* parm); + static void defaultFree (void* obj, void* parm); private: - int post (void* data, unsigned int mask, void* secondary_data, unsigned int secondary_size, int timeout); + int post (void* data, unsigned int mask, void* secondary_data, unsigned int secondary_size, int timeout); }; @@ -215,25 +219,25 @@ class Subscriber: public MsgQ void* _handle; } msgRef_t; - Subscriber (const char* name, subscriber_type_t type=SUBSCRIBER_OF_CONFIDENCE, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); - Subscriber (const MsgQ& existing_q, subscriber_type_t type=SUBSCRIBER_OF_CONFIDENCE); - ~Subscriber (void); + explicit Subscriber (const char* name, subscriber_type_t type=SUBSCRIBER_OF_CONFIDENCE, int depth=CFG_DEPTH_STANDARD, int data_size=CFG_SIZE_INFINITY); + explicit Subscriber (const MsgQ& existing_q, subscriber_type_t type=SUBSCRIBER_OF_CONFIDENCE); + ~Subscriber (void); - bool dereference (msgRef_t& ref, bool with_delete=true); - void drain (bool with_delete=true); - bool isEmpty (void); - void* getData (void* _handle, int* size=NULL); + bool dereference (msgRef_t& ref, bool with_delete=true); + void drain (bool with_delete=true); + bool isEmpty (void); + static void* getData (void* _handle, int* size=NULL); - int receiveRef (msgRef_t& ref, int timeout); - int receiveCopy (void* data, int size, int timeout); + int receiveRef (msgRef_t& ref, int timeout); + int receiveCopy (void* data, int size, int timeout); private: - int id; // index into current node table + int id; // index into current node table - int receive (msgRef_t& ref, int size, int timeout, bool copy=false); - bool reclaim_nodes (bool delete_data); - void init_subscriber (subscriber_type_t type); + int receive (msgRef_t& ref, int size, int timeout, bool copy=false); + bool reclaim_nodes (bool delete_data); + void init_subscriber (subscriber_type_t type); }; #endif /* __msgq__ */ diff --git a/packages/core/Ordering.h b/packages/core/Ordering.h index 7d0812cf3..8c48c7801 100644 --- a/packages/core/Ordering.h +++ b/packages/core/Ordering.h @@ -84,7 +84,7 @@ class Ordering class Iterator { public: - Iterator (const Ordering& o); + explicit Iterator (const Ordering& o); ~Iterator (void); kv_t operator[] (int index) const; const int length; @@ -98,13 +98,13 @@ class Ordering *--------------------------------------------------------------------*/ Ordering (typename Ordering::postFunc_t post_func=NULL, void* post_parm=NULL, K max_list_size=INFINITE_LIST_SIZE); - virtual ~Ordering (void); + ~Ordering (void); bool add (K key, const T& data, bool unique=false); T& get (K key, searchMode_t smode=EXACT_MATCH); bool remove (K key, searchMode_t smode=EXACT_MATCH); - long length (void); - bool isempty (void); + long length (void) const; + bool empty (void) const; void flush (void); void clear (void); @@ -148,21 +148,7 @@ class Ordering bool setMaxListSize (long _max_list_size); bool addNode (K key, const T& data, bool unique); void postNode (sorted_node_t* node); - virtual void freeNode (sorted_node_t* node); -}; - -/****************************************************************************** - * MANAGED ORDERING TEMPLATE - ******************************************************************************/ - -template -class MgOrdering: public Ordering -{ - public: - MgOrdering (typename Ordering::postFunc_t post_func=NULL, void* post_parm=NULL, K max_list_size=Ordering::INFINITE_LIST_SIZE); - ~MgOrdering (void); - private: - void freeNode (typename Ordering::sorted_node_t* node); + void freeNode (sorted_node_t* node); }; /****************************************************************************** @@ -211,10 +197,8 @@ typename Ordering::kv_t Ordering::Iterator::operator[](int index) cons Ordering::kv_t pair(keys[index], *values[index]); return pair; } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "Ordering::Iterator index out of range"); - } + + throw RunTimeException(CRITICAL, RTE_ERROR, "Ordering::Iterator index out of range"); } /****************************************************************************** @@ -306,8 +290,8 @@ T& Ordering::get(K key, searchMode_t smode) } } - if (found) return curr->data; - else throw RunTimeException(CRITICAL, RTE_ERROR, "key not found"); + if(found) return curr->data; + throw RunTimeException(CRITICAL, RTE_ERROR, "key not found"); } /*---------------------------------------------------------------------------- @@ -373,26 +357,24 @@ bool Ordering::remove(K key, searchMode_t smode) /* return success */ return true; } - else - { - return false; - } + + return false; } /*---------------------------------------------------------------------------- * length *----------------------------------------------------------------------------*/ template -long Ordering::length(void) +long Ordering::length(void) const { return len; } /*---------------------------------------------------------------------------- - * isempty + * empty *----------------------------------------------------------------------------*/ template -bool Ordering::isempty(void) +bool Ordering::empty(void) const { return (len == 0); } @@ -700,48 +682,22 @@ void Ordering::postNode(sorted_node_t* node) { int status = 0; if(postFunc) status = postFunc(&(node->data), sizeof(T), postParm); - if (status <= 0) freeNode(node); + if(status <= 0) freeNode(node); } /*---------------------------------------------------------------------------- * freeNode *----------------------------------------------------------------------------*/ -template -void Ordering::freeNode(sorted_node_t* node) -{ - (void)node; -} - -/****************************************************************************** - MANAGED ORDERING METHODS - ******************************************************************************/ - -/*---------------------------------------------------------------------------- - * Constructor - *----------------------------------------------------------------------------*/ -template -MgOrdering::MgOrdering(typename Ordering::postFunc_t post_func, void* post_parm, K max_list_size): - Ordering(post_func, post_parm, max_list_size) -{ -} +template +void orderingDeleteIfPointer(const T& t) { (void)t; } -/*---------------------------------------------------------------------------- - * Destructor - *----------------------------------------------------------------------------*/ -template -MgOrdering::~MgOrdering(void) -{ - Ordering::clear(); -} +template +void orderingDeleteIfPointer(T* t) { delete t; } -/*---------------------------------------------------------------------------- - * freeNode - *----------------------------------------------------------------------------*/ -template -void MgOrdering::freeNode(typename Ordering::sorted_node_t* node) +template +void Ordering::freeNode(sorted_node_t* node) { - if(!is_array) delete node->data; - else delete [] node->data; + orderingDeleteIfPointer(node->data); } #endif /* __ordering__ */ diff --git a/packages/core/PointIndex.cpp b/packages/core/PointIndex.cpp index c85d5b64c..6aad7ca27 100644 --- a/packages/core/PointIndex.cpp +++ b/packages/core/PointIndex.cpp @@ -43,8 +43,8 @@ * STATIC DATA ******************************************************************************/ -const char* PointIndex::LuaMetaName = "PointIndex"; -const struct luaL_Reg PointIndex::LuaMetaTable[] = { +const char* PointIndex::LUA_META_NAME = "PointIndex"; +const struct luaL_Reg PointIndex::LUA_META_TABLE[] = { {"add", luaAdd}, {"query", luaQuery}, {"display", luaDisplay}, @@ -63,7 +63,7 @@ int PointIndex::luaCreate (lua_State* L) try { /* Get Asset Directory */ - Asset* _asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + Asset* _asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* _fieldname = getLuaString(L, 2); int _threshold = getLuaInteger(L, 3, true, DEFAULT_THRESHOLD); @@ -72,7 +72,7 @@ int PointIndex::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -81,7 +81,7 @@ int PointIndex::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ PointIndex::PointIndex(lua_State* L, Asset* _asset, const char* _fieldname, int _threshold): - AssetIndex(L, *_asset, LuaMetaName, LuaMetaTable, _threshold) + AssetIndex(L, *_asset, LUA_META_NAME, LUA_META_TABLE, _threshold) { assert(_fieldname); diff --git a/packages/core/PointIndex.h b/packages/core/PointIndex.h index 24c31ddc9..76d47bcf4 100644 --- a/packages/core/PointIndex.h +++ b/packages/core/PointIndex.h @@ -78,8 +78,8 @@ class PointIndex: public AssetIndex * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Data diff --git a/targets/binding-python/pyPlugin.cpp b/packages/core/PublishMonitor.cpp similarity index 60% rename from targets/binding-python/pyPlugin.cpp rename to packages/core/PublishMonitor.cpp index 69f27188e..51c4efb9c 100644 --- a/targets/binding-python/pyPlugin.cpp +++ b/packages/core/PublishMonitor.cpp @@ -33,67 +33,68 @@ * INCLUDES ******************************************************************************/ -#include -#include -#include -#include -#include "StringLib.h" -#include "pyPlugin.h" +#include "PublishMonitor.h" +#include "Monitor.h" +#include "EventLib.h" +#include "TimeLib.h" +#include "RecordObject.h" /****************************************************************************** - * NAMESPACES + * PUBLIC METHODS ******************************************************************************/ -namespace py = pybind11; +/*---------------------------------------------------------------------------- + * luaCreate - create([], [], [], ) + *----------------------------------------------------------------------------*/ +int PublishMonitor::luaCreate (lua_State* L) +{ + try + { + /* Get Parmeters */ + uint8_t type_mask = (uint8_t)getLuaInteger(L, 1, true, (long)EventLib::LOG); + event_level_t level = (event_level_t)getLuaInteger(L, 2, true, CRITICAL); + format_t format = (format_t)getLuaInteger(L, 3, true, RECORD); + const char* outq_name = getLuaString(L, 4, true, NULL); + + /* Return Dispatch Object */ + return createLuaObject(L, new PublishMonitor(L, type_mask, level, format, outq_name)); + } + catch(const RunTimeException& e) + { + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); + return returnLuaStatus(L, false); + } +} /****************************************************************************** - * TYPEDEFS + * PROTECTED METHODS ******************************************************************************/ -typedef void (*init_f) (void); +/*---------------------------------------------------------------------------- + * processEvent + *----------------------------------------------------------------------------*/ +void PublishMonitor::processEvent(const unsigned char* event_buf_ptr, int event_size) +{ + outQ->postCopy(event_buf_ptr, event_size, IO_CHECK); +} /****************************************************************************** - * pyPlugin Class + * PRIVATE METHODS ******************************************************************************/ -/*-------------------------------------------------------------------- +/*---------------------------------------------------------------------------- * Constructor - *--------------------------------------------------------------------*/ -pyPlugin::pyPlugin (const std::string &_plugin) + *----------------------------------------------------------------------------*/ +PublishMonitor::PublishMonitor(lua_State* L, uint8_t type_mask, event_level_t level, format_t format, const char* outq_name): + Monitor(L, type_mask, level, format) { - /* Get Plugin Name */ - char plugin_buf[MAX_STR_SIZE]; - StringLib::copy(plugin_buf, _plugin.c_str(), _plugin.length()); - char* plugin_name = StringLib::find(plugin_buf, '/', false) + 1; - char* plugin_ext = StringLib::find(plugin_buf, '.', true); - *plugin_ext = '\0'; - - /* Load Plugin */ - void* plugin = dlopen(_plugin.c_str(), RTLD_NOW); - if(plugin) - { - /* Call plugin initialization function */ - char init_func[MAX_STR_SIZE]; - StringLib::format(init_func, MAX_STR_SIZE, "init%s", plugin_name); - init_f init = (init_f)dlsym(plugin, init_func); - if(init) - { - init(); - } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "cannot find initialization function %s: %s\n", init_func, dlerror()); - } - } - else - { - throw RunTimeException(CRITICAL, RTE_ERROR, "cannot load %s: %s\n", plugin_name, dlerror()); - } + outQ = new Publisher(outq_name); } -/*-------------------------------------------------------------------- +/*---------------------------------------------------------------------------- * Destructor - *--------------------------------------------------------------------*/ -pyPlugin::~pyPlugin (void) + *----------------------------------------------------------------------------*/ +PublishMonitor::~PublishMonitor(void) { + delete outQ; } diff --git a/targets/binding-python/pyLogger.h b/packages/core/PublishMonitor.h similarity index 61% rename from targets/binding-python/pyLogger.h rename to packages/core/PublishMonitor.h index aeaacd643..14c3fa5d7 100644 --- a/targets/binding-python/pyLogger.h +++ b/packages/core/PublishMonitor.h @@ -29,42 +29,55 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __py_logger__ -#define __py_logger__ +#ifndef __publish_monitor__ +#define __publish_monitor__ /****************************************************************************** * INCLUDES ******************************************************************************/ -#include -#include "OsApi.h" #include "MsgQ.h" +#include "Monitor.h" +#include "RecordObject.h" +#include "OsApi.h" +#include "EventLib.h" /****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyLogger Class + * PUBLISH MONITOR CLASS ******************************************************************************/ -class pyLogger +class PublishMonitor: public Monitor { public: - pyLogger (const long level); - ~pyLogger (void); - const char* log (const std::string msg, const long level); + /*-------------------------------------------------------------------- + * Methods + *--------------------------------------------------------------------*/ + + static int luaCreate (lua_State* L); + + protected: + + /*-------------------------------------------------------------------- + * Methods + *--------------------------------------------------------------------*/ + + void processEvent (const unsigned char* event_buf_ptr, int event_size) override; private: - static void* loggerThread (void* parm); + /*-------------------------------------------------------------------- + * Methods + *--------------------------------------------------------------------*/ + + PublishMonitor (lua_State* L, uint8_t type_mask, event_level_t level, format_t format, const char* outq_name); + ~PublishMonitor (void); + + /*-------------------------------------------------------------------- + * Data + *--------------------------------------------------------------------*/ - bool active; - Thread* pid; - Subscriber* inQ; + Publisher* outQ; }; -#endif /* __py_logger__ */ \ No newline at end of file +#endif /* __publish_monitor__ */ diff --git a/packages/core/PublisherDispatch.cpp b/packages/core/PublisherDispatch.cpp index 328cd1fef..c601a6a59 100644 --- a/packages/core/PublisherDispatch.cpp +++ b/packages/core/PublisherDispatch.cpp @@ -40,8 +40,8 @@ * STATIC DATA ******************************************************************************/ -const char* PublisherDispatch::LuaMetaName = "PublisherDispatch"; -const struct luaL_Reg PublisherDispatch::LuaMetaTable[] = { +const char* PublisherDispatch::LUA_META_NAME = "PublisherDispatch"; +const struct luaL_Reg PublisherDispatch::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -64,7 +64,7 @@ int PublisherDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -77,7 +77,7 @@ int PublisherDispatch::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ PublisherDispatch::PublisherDispatch(lua_State* L, const char* recq_name): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { assert(recq_name); @@ -101,6 +101,6 @@ bool PublisherDispatch::processRecord(RecordObject* record, okey_t key, recVec_t (void)records; unsigned char* buffer; // reference to serial buffer int size = record->serialize(&buffer, RecordObject::REFERENCE); - if(size > 0) return (pubQ->postCopy(buffer, size) > 0); - else return false; + if(size > 0) return (pubQ->postCopy(buffer, size) > 0); + return false; } diff --git a/packages/core/PublisherDispatch.h b/packages/core/PublisherDispatch.h index c5e604b6d..9d45c3235 100644 --- a/packages/core/PublisherDispatch.h +++ b/packages/core/PublisherDispatch.h @@ -52,8 +52,8 @@ class PublisherDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/RecordDispatcher.cpp b/packages/core/RecordDispatcher.cpp index 744900eff..d7db73dc8 100644 --- a/packages/core/RecordDispatcher.cpp +++ b/packages/core/RecordDispatcher.cpp @@ -42,8 +42,8 @@ Dictionary RecordDispatcher::keyCalcFunctions; -const char* RecordDispatcher::LuaMetaName = "RecordDispatcher"; -const struct luaL_Reg RecordDispatcher::LuaMetaTable[] = { +const char* RecordDispatcher::LUA_META_NAME = "RecordDispatcher"; +const struct luaL_Reg RecordDispatcher::LUA_META_TABLE[] = { {"run", luaRun}, {"attach", luaAttachDispatch}, {"clear", luaClearError}, @@ -77,19 +77,20 @@ int RecordDispatcher::luaCreate (lua_State* L) /* Set Key Mode */ keyMode_t key_mode = str2mode(key_mode_str); const char* key_field = NULL; - calcFunc_t key_func = NULL; + calcFunc_f key_func = NULL; if(key_mode == INVALID_KEY_MODE) { throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid key mode specified: %s", key_mode_str); } - else if(key_mode == FIELD_KEY_MODE) + + if(key_mode == FIELD_KEY_MODE) { key_field = getLuaString(L, 4); } else if(key_mode == CALCULATED_KEY_MODE) { const char* key_func_str = getLuaString(L, 4); - key_func = keyCalcFunctions[key_func_str]; + key_func = keyCalcFunctions[key_func_str].calc; } /* Set Subscriber Type */ @@ -100,7 +101,7 @@ int RecordDispatcher::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -110,10 +111,10 @@ int RecordDispatcher::luaCreate (lua_State* L) *----------------------------------------------------------------------------*/ RecordDispatcher::keyMode_t RecordDispatcher::str2mode(const char* str) { - if(StringLib::match(str, "FIELD_KEY")) return FIELD_KEY_MODE; - else if(StringLib::match(str, "RECEIPT_KEY")) return RECEIPT_KEY_MODE; - else if(StringLib::match(str, "CALCULATED_KEY")) return CALCULATED_KEY_MODE; - else return INVALID_KEY_MODE; + if(StringLib::match(str, "FIELD_KEY")) return FIELD_KEY_MODE; + if(StringLib::match(str, "RECEIPT_KEY")) return RECEIPT_KEY_MODE; + if(StringLib::match(str, "CALCULATED_KEY")) return CALCULATED_KEY_MODE; + return INVALID_KEY_MODE; } /*---------------------------------------------------------------------------- @@ -133,9 +134,10 @@ const char* RecordDispatcher::mode2str(keyMode_t mode) /*---------------------------------------------------------------------------- * addKeyCalcFunc *----------------------------------------------------------------------------*/ -bool RecordDispatcher::addKeyCalcFunc(const char* calc_name, calcFunc_t func) +bool RecordDispatcher::addKeyCalcFunc(const char* calc_name, calcFunc_f calc_func) { - return keyCalcFunctions.add(calc_name, func); + calcFunc_t calc = { .calc = calc_func }; + return keyCalcFunctions.add(calc_name, calc); } /****************************************************************************** @@ -146,9 +148,9 @@ bool RecordDispatcher::addKeyCalcFunc(const char* calc_name, calcFunc_t func) * Constructor *----------------------------------------------------------------------------*/ RecordDispatcher::RecordDispatcher( lua_State* L, const char* inputq_name, - keyMode_t key_mode, const char* key_field, calcFunc_t key_func, + keyMode_t key_mode, const char* key_field, calcFunc_f key_func, int num_threads, MsgQ::subscriber_type_t type): - LuaObject(L, BASE_OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, BASE_OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(inputq_name); assert(num_threads > 0); @@ -180,13 +182,13 @@ RecordDispatcher::~RecordDispatcher(void) dispatcherActive = false; for(int i = 0; i < numThreads; i++) { - if (threadPool[i]) delete threadPool[i]; + delete threadPool[i]; } delete [] threadPool; delete inQ; - if (keyField) delete [] keyField; + delete [] keyField; dispatch_t dispatch; const char* key = dispatchTable.first(&dispatch); @@ -219,7 +221,7 @@ int RecordDispatcher::luaRun(lua_State* L) try { /* Get Self */ - RecordDispatcher* lua_obj = (RecordDispatcher*)getLuaSelf(L, 1); + RecordDispatcher* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Start Threads */ lua_obj->dispatcherActive = true; @@ -250,11 +252,11 @@ int RecordDispatcher::luaAttachDispatch(lua_State* L) try { /* Get Self */ - RecordDispatcher* lua_obj = (RecordDispatcher*)getLuaSelf(L, 1); + RecordDispatcher* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ int num_parms = getLuaNumParms(L); - DispatchObject* dispatch = (DispatchObject*)getLuaObject(L, 2, DispatchObject::OBJECT_TYPE); + DispatchObject* dispatch = dynamic_cast(getLuaObject(L, 2, DispatchObject::OBJECT_TYPE)); /* Check if Active */ if(lua_obj->dispatcherActive) @@ -265,7 +267,7 @@ int RecordDispatcher::luaAttachDispatch(lua_State* L) /* Attach Dispatches */ for(int p = 3; p <= num_parms; p++) { - List new_dispatch_list; + vector new_dispatch_list; /* Build Record Type */ const char* rec_type = getLuaString(L, p); @@ -287,7 +289,7 @@ int RecordDispatcher::luaAttachDispatch(lua_State* L) /* Copy Dispatches Over to New List */ for(int d = 0; d < old_dispatch.size; d++) { - new_dispatch_list.add(old_dispatch.list[d]); + new_dispatch_list.push_back(old_dispatch.list[d]); } /* Remove Old Dispatch List */ @@ -300,10 +302,10 @@ int RecordDispatcher::luaAttachDispatch(lua_State* L) } /* Attach Dispatch */ - new_dispatch_list.add(dispatch); + new_dispatch_list.push_back(dispatch); /* Create New Dispatch Table Entry */ - dispatch_t new_dispatch = { NULL, new_dispatch_list.length() }; + dispatch_t new_dispatch = { NULL, static_cast(new_dispatch_list.size()) }; new_dispatch.list = new DispatchObject* [new_dispatch.size]; for(int d = 0; d < new_dispatch.size; d++) { @@ -319,7 +321,7 @@ int RecordDispatcher::luaAttachDispatch(lua_State* L) } /* Add Dispatch to List */ - lua_obj->dispatchList.add(dispatch); + lua_obj->dispatchList.push_back(dispatch); /* Set Success */ status = true; @@ -343,7 +345,7 @@ int RecordDispatcher::luaClearError(lua_State* L) try { /* Get Self */ - RecordDispatcher* lua_obj = (RecordDispatcher*)getLuaSelf(L, 1); + RecordDispatcher* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Clear Errors */ lua_obj->recError = false; @@ -370,7 +372,7 @@ int RecordDispatcher::luaDrain (lua_State* L) try { /* Get Self */ - RecordDispatcher* lua_obj = (RecordDispatcher*)getLuaSelf(L, 1); + RecordDispatcher* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Clear Errors */ lua_obj->inQ->drain(); @@ -397,7 +399,7 @@ int RecordDispatcher::luaAbortOnTimeout (lua_State* L) try { /* Get Self */ - RecordDispatcher* lua_obj = (RecordDispatcher*)getLuaSelf(L, 1); + RecordDispatcher* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Abort On Timeout */ lua_obj->abortOnTimeout = true; @@ -423,7 +425,7 @@ int RecordDispatcher::luaAbortOnTimeout (lua_State* L) *----------------------------------------------------------------------------*/ void* RecordDispatcher::dispatcherThread(void* parm) { - RecordDispatcher* dispatcher = (RecordDispatcher*)parm; + RecordDispatcher* dispatcher = static_cast(parm); /* Loop Forever */ while(dispatcher->dispatcherActive) @@ -481,7 +483,7 @@ void* RecordDispatcher::dispatcherThread(void* parm) else if(recv_status == MsgQ::STATE_TIMEOUT) { /* Signal Timeout to Dispatches */ - int num_dispatches = dispatcher->dispatchList.length(); + int num_dispatches = dispatcher->dispatchList.size(); for(int d = 0; d < num_dispatches; d++) { DispatchObject* dis = dispatcher->dispatchList[d]; diff --git a/packages/core/RecordDispatcher.h b/packages/core/RecordDispatcher.h index 0bfffcde0..3bddb840a 100644 --- a/packages/core/RecordDispatcher.h +++ b/packages/core/RecordDispatcher.h @@ -56,7 +56,11 @@ class RecordDispatcher: public LuaObject * Types *--------------------------------------------------------------------*/ - typedef okey_t (*calcFunc_t) (unsigned char* buffer, int size); + typedef okey_t (*calcFunc_f) (unsigned char* buffer, int size); + + typedef struct { + calcFunc_f calc; + } calcFunc_t; typedef enum { FIELD_KEY_MODE = 0, @@ -79,7 +83,7 @@ class RecordDispatcher: public LuaObject static keyMode_t str2mode (const char* str); static const char* mode2str (keyMode_t mode); - static bool addKeyCalcFunc (const char* calc_name, calcFunc_t func); + static bool addKeyCalcFunc (const char* calc_name, calcFunc_f calc_func); protected: @@ -87,8 +91,8 @@ class RecordDispatcher: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Data @@ -101,7 +105,7 @@ class RecordDispatcher: public LuaObject *--------------------------------------------------------------------*/ RecordDispatcher (lua_State* L, const char* inputq_name, - keyMode_t key_mode, const char* key_field, calcFunc_t key_func, + keyMode_t key_mode, const char* key_field, calcFunc_f key_func, int num_threads, MsgQ::subscriber_type_t type); virtual ~RecordDispatcher (void); virtual RecordObject* createRecord (unsigned char* buffer, int size); @@ -134,13 +138,13 @@ class RecordDispatcher: public LuaObject int threadsComplete; Mutex threadMut; Subscriber* inQ; - List dispatchList; // for processTimeout + vector dispatchList; // for processTimeout Dictionary dispatchTable; // for processRecord Mutex dispatchMutex; keyMode_t keyMode; // determines key of metric okey_t keyRecCnt; // used with RECEIPT_KEY_MODE const char* keyField; // used with FIELD_KEY_MODE - calcFunc_t keyFunc; // used with CALCULATED_KEY_MODE + calcFunc_f keyFunc; // used with CALCULATED_KEY_MODE bool recError; /*-------------------------------------------------------------------- diff --git a/packages/core/RecordObject.cpp b/packages/core/RecordObject.cpp index 8ea2605fa..8454e71ed 100644 --- a/packages/core/RecordObject.cpp +++ b/packages/core/RecordObject.cpp @@ -51,7 +51,7 @@ * STATIC DATA ******************************************************************************/ -MgDictionary RecordObject::definitions; +Dictionary RecordObject::definitions; Mutex RecordObject::defMut; const char* RecordObject::DEFAULT_DOUBLE_FORMAT = "%.6lf"; @@ -98,7 +98,7 @@ RecordObject::Field::Field(RecordObject& _rec, fieldType_t _type, int _offset, i /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -RecordObject::Field::Field(RecordObject& _rec, field_t _field, int _element): +RecordObject::Field::Field(RecordObject& _rec, const field_t& _field, int _element): record(_rec), field(_field), element(_element) @@ -178,7 +178,7 @@ long RecordObject::Field::getValueInteger(void) *----------------------------------------------------------------------------*/ RecordObject::valType_t RecordObject::Field::getValueType(void) { - return record.getValueType(field); + return RecordObject::getValueType(field); } /****************************************************************************** @@ -305,7 +305,8 @@ bool RecordObject::deserialize(unsigned char* buffer, int size) { return false; // buffer passed in too large } - else if(size < def->type_size) + + if(size < def->type_size) { return false; // buffer not large enough to populate type string } @@ -329,15 +330,15 @@ int RecordObject::serialize(unsigned char** buffer, serialMode_t mode, int size) if(size > 0) { int hdrsize = sizeof(rec_hdr_t) + OsApi::swaps(rechdr->type_size); - bufsize = hdrsize + size; - datasize = bufsize - hdrsize; + datasize = size; + bufsize = hdrsize + datasize; } /* Allocate or Copy Buffer */ if (mode == ALLOCATE) { *buffer = new unsigned char[bufsize]; - uint32_t bytes_to_copy = MIN(bufsize, memoryAllocated); + int bytes_to_copy = MIN(bufsize, memoryAllocated); memcpy(*buffer, recordMemory, bytes_to_copy); } else if (mode == REFERENCE) @@ -352,7 +353,7 @@ int RecordObject::serialize(unsigned char** buffer, serialMode_t mode, int size) else // if (mode == COPY) { assert(*buffer); - uint32_t bytes_to_copy = MIN(bufsize, memoryAllocated); + int bytes_to_copy = MIN(bufsize, memoryAllocated); memcpy(*buffer, recordMemory, bytes_to_copy); } @@ -370,7 +371,7 @@ int RecordObject::serialize(unsigned char** buffer, serialMode_t mode, int size) /*---------------------------------------------------------------------------- * post *----------------------------------------------------------------------------*/ -bool RecordObject::post(Publisher* outq, int size, bool* active, bool verbose) +bool RecordObject::post(Publisher* outq, int size, const bool* active, bool verbose) { bool status = true; @@ -397,7 +398,7 @@ bool RecordObject::post(Publisher* outq, int size, bool* active, bool verbose) /*---------------------------------------------------------------------------- * isRecordType *----------------------------------------------------------------------------*/ -bool RecordObject::isRecordType(const char* rec_type) +bool RecordObject::isRecordType(const char* rec_type) const { return (StringLib::match(rec_type, recordDefinition->type_name)); } @@ -405,7 +406,7 @@ bool RecordObject::isRecordType(const char* rec_type) /*---------------------------------------------------------------------------- * getRecordType *----------------------------------------------------------------------------*/ -const char* RecordObject::getRecordType(void) +const char* RecordObject::getRecordType(void) const { return recordDefinition->type_name; } @@ -431,7 +432,7 @@ long RecordObject::getRecordId(void) /*---------------------------------------------------------------------------- * getRecordData *----------------------------------------------------------------------------*/ -unsigned char* RecordObject::getRecordData(void) +unsigned char* RecordObject::getRecordData(void) const { return recordData; } @@ -439,7 +440,7 @@ unsigned char* RecordObject::getRecordData(void) /*---------------------------------------------------------------------------- * getRecordTypeSize *----------------------------------------------------------------------------*/ -int RecordObject::getRecordTypeSize(void) +int RecordObject::getRecordTypeSize(void) const { return recordDefinition->type_size; } @@ -447,7 +448,7 @@ int RecordObject::getRecordTypeSize(void) /*---------------------------------------------------------------------------- * getRecordDataSize *----------------------------------------------------------------------------*/ -int RecordObject::getRecordDataSize(void) +int RecordObject::getRecordDataSize(void) const { return recordDefinition->data_size; } @@ -455,7 +456,7 @@ int RecordObject::getRecordDataSize(void) /*---------------------------------------------------------------------------- * getAllocatedMemory *----------------------------------------------------------------------------*/ -int RecordObject::getAllocatedMemory(void) +int RecordObject::getAllocatedMemory(void) const { return memoryAllocated; } @@ -463,7 +464,7 @@ int RecordObject::getAllocatedMemory(void) /*---------------------------------------------------------------------------- * getAllocatedDataSize *----------------------------------------------------------------------------*/ -int RecordObject::getAllocatedDataSize(void) +int RecordObject::getAllocatedDataSize(void) const { return memoryAllocated - (sizeof(rec_hdr_t) + recordDefinition->type_size); } @@ -528,7 +529,7 @@ void RecordObject::setIdField (const char* id_field) { defMut.lock(); { - if(recordDefinition->id_field) delete [] recordDefinition->id_field; + delete [] recordDefinition->id_field; recordDefinition->id_field = StringLib::duplicate(id_field); } defMut.unlock(); @@ -559,10 +560,7 @@ RecordObject::field_t RecordObject::getField(const char* field_name) { return parseImmediateField(field_name); } - else - { - return getUserField(recordDefinition, field_name); - } + return getUserField(recordDefinition, field_name); } /*---------------------------------------------------------------------------- @@ -586,7 +584,7 @@ void RecordObject::setValueText(const field_t& f, const char* val, int element) { field_t ptr_field = getPointedToField(f, false, element); if(val == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Cannot null existing pointer!"); - else setValueText(ptr_field, val); + setValueText(ptr_field, val); } else if(val_type == TEXT) { @@ -631,10 +629,11 @@ void RecordObject::setValueText(const field_t& f, const char* val, int element) /*---------------------------------------------------------------------------- * setValueReal *----------------------------------------------------------------------------*/ -void RecordObject::setValueReal(const field_t& f, const double val, int element) +void RecordObject::setValueReal(const field_t& f, double val, int element) { if(f.elements > 0 && element > 0 && element >= f.elements) throw RunTimeException(CRITICAL, RTE_ERROR, "Out of range access"); uint32_t elem_offset = TOBYTES(f.offset) + (element * FIELD_TYPE_BYTES[f.type]); + type_cast_t* cast = reinterpret_cast(recordData + elem_offset); if(f.flags & POINTER) { @@ -645,18 +644,18 @@ void RecordObject::setValueReal(const field_t& f, const double val, int element) { switch(f.type) { - case INT8: *(int8_t*) (recordData + elem_offset) = (int8_t)val; break; - case INT16: *(int16_t*) (recordData + elem_offset) = (int16_t)val; break; - case INT32: *(int32_t*) (recordData + elem_offset) = (int32_t)val; break; - case INT64: *(int64_t*) (recordData + elem_offset) = (int64_t)val; break; - case UINT8: *(uint8_t*) (recordData + elem_offset) = (uint8_t)val; break; - case UINT16: *(uint16_t*)(recordData + elem_offset) = (uint16_t)val; break; - case UINT32: *(uint32_t*)(recordData + elem_offset) = (uint32_t)val; break; - case UINT64: *(uint64_t*)(recordData + elem_offset) = (uint64_t)val; break; + case INT8: cast->int8_val = (int8_t)val; break; + case INT16: cast->int16_val = (int16_t)val; break; + case INT32: cast->int32_val = (int32_t)val; break; + case INT64: cast->int64_val = (int64_t)val; break; + case UINT8: cast->uint8_val = (uint8_t)val; break; + case UINT16: cast->uint16_val = (uint16_t)val; break; + case UINT32: cast->uint32_val = (uint32_t)val; break; + case UINT64: cast->uint64_val = (uint64_t)val; break; case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; - case FLOAT: *(float*) (recordData + elem_offset) = (float)val; break; - case DOUBLE: *(double*)(recordData + elem_offset) = val; break; - case TIME8: *(int64_t*)(recordData + elem_offset) = (int64_t)val; break; + case FLOAT: cast->float_val = (float)val; break; + case DOUBLE: cast->double_val = val; break; + case TIME8: cast->int64_val = (int64_t)val; break; case STRING: StringLib::format((char*)(recordData + elem_offset), f.elements, DEFAULT_DOUBLE_FORMAT, val); break; default: break; @@ -666,17 +665,18 @@ void RecordObject::setValueReal(const field_t& f, const double val, int element) { switch(f.type) { - case INT8: *(int8_t*) (recordData + elem_offset) = (int8_t)val; break; - case INT16: *(int16_t*) (recordData + elem_offset) = OsApi::swaps((int16_t)val); break; - case INT32: *(int32_t*) (recordData + elem_offset) = OsApi::swapl((int32_t)val); break; - case INT64: *(int64_t*) (recordData + elem_offset) = OsApi::swapll((int64_t)val); break; - case UINT8: *(uint8_t*) (recordData + elem_offset) = (uint8_t)val; break; - case UINT16: *(uint16_t*)(recordData + elem_offset) = OsApi::swaps((uint16_t)val); break; - case UINT32: *(uint32_t*)(recordData + elem_offset) = OsApi::swapl((uint32_t)val); break; - case UINT64: *(uint64_t*)(recordData + elem_offset) = OsApi::swapll((uint64_t)val); break; - case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; - case FLOAT: *(float*) (recordData + elem_offset) = OsApi::swapf((float)val); break; - case DOUBLE: *(uint64_t*)(recordData + elem_offset) = OsApi::swapll((uint64_t)val); break; + case INT8: cast->int8_val = (int8_t)val; break; + case INT16: cast->int16_val = OsApi::swaps((int16_t)val); break; + case INT32: cast->int32_val = OsApi::swapl((int32_t)val); break; + case INT64: cast->int64_val = OsApi::swapll((int64_t)val); break; + case UINT8: cast->uint8_val = (uint8_t)val; break; + case UINT16: cast->uint16_val = OsApi::swaps((uint16_t)val); break; + case UINT32: cast->uint32_val = OsApi::swapl((uint32_t)val); break; + case UINT64: cast->uint64_val = OsApi::swapll((uint64_t)val);break; + case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; + case FLOAT: cast->float_val = OsApi::swapf((float)val); break; + case DOUBLE: cast->double_val = OsApi::swapf((double)val); break; + case TIME8 : cast->int64_val = OsApi::swapll((uint64_t)val);break; case STRING: StringLib::format((char*)(recordData + elem_offset), f.elements, DEFAULT_DOUBLE_FORMAT, val); break; default: break; @@ -687,10 +687,11 @@ void RecordObject::setValueReal(const field_t& f, const double val, int element) /*---------------------------------------------------------------------------- * setValueInteger *----------------------------------------------------------------------------*/ -void RecordObject::setValueInteger(const field_t& f, const long val, int element) +void RecordObject::setValueInteger(const field_t& f, long val, int element) { if(f.elements > 0 && element > 0 && element >= f.elements) throw RunTimeException(CRITICAL, RTE_ERROR, "Out of range access"); uint32_t elem_offset = TOBYTES(f.offset) + (element * FIELD_TYPE_BYTES[f.type]); + type_cast_t* cast = reinterpret_cast(recordData + elem_offset); if(f.flags & POINTER) { @@ -701,18 +702,18 @@ void RecordObject::setValueInteger(const field_t& f, const long val, int element { switch(f.type) { - case INT8: *(int8_t*) (recordData + elem_offset) = (int8_t)val; break; - case INT16: *(int16_t*) (recordData + elem_offset) = (int16_t)val; break; - case INT32: *(int32_t*) (recordData + elem_offset) = (int32_t)val; break; - case INT64: *(int64_t*) (recordData + elem_offset) = (int64_t)val; break; - case UINT8: *(uint8_t*) (recordData + elem_offset) = (uint8_t)val; break; - case UINT16: *(uint16_t*)(recordData + elem_offset) = (uint16_t)val; break; - case UINT32: *(uint32_t*)(recordData + elem_offset) = (uint32_t)val; break; - case UINT64: *(uint64_t*)(recordData + elem_offset) = (uint64_t)val; break; - case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; - case FLOAT: *(float*) (recordData + elem_offset) = (float)val; break; - case DOUBLE: *(double*)(recordData + elem_offset) = val; break; - case TIME8: *(int64_t*)(recordData + elem_offset) = (int64_t)val; break; + case INT8: cast->int8_val = (int8_t)val; break; + case INT16: cast->int16_val = (int16_t)val; break; + case INT32: cast->int32_val = (int32_t)val; break; + case INT64: cast->int64_val = (int64_t)val; break; + case UINT8: cast->uint8_val = (uint8_t)val; break; + case UINT16: cast->uint16_val = (uint16_t)val; break; + case UINT32: cast->uint32_val = (uint32_t)val; break; + case UINT64: cast->uint64_val = (uint64_t)val; break; + case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; + case FLOAT: cast->float_val = (float)val; break; + case DOUBLE: cast->double_val = val; break; + case TIME8: cast->int64_val = (int64_t)val; break; case STRING: StringLib::format((char*)(recordData + elem_offset), f.elements, DEFAULT_LONG_FORMAT, val); break; default: break; @@ -722,18 +723,18 @@ void RecordObject::setValueInteger(const field_t& f, const long val, int element { switch(f.type) { - case INT8: *(int8_t*) (recordData + elem_offset) = (int8_t)val; break; - case INT16: *(int16_t*) (recordData + elem_offset) = OsApi::swaps((int16_t)val); break; - case INT32: *(int32_t*) (recordData + elem_offset) = OsApi::swapl((int32_t)val); break; - case INT64: *(int64_t*)(recordData + elem_offset) = OsApi::swapll((int64_t)val); break; - case UINT8: *(uint8_t*) (recordData + elem_offset) = (uint8_t)val; break; - case UINT16: *(uint16_t*)(recordData + elem_offset) = OsApi::swaps((uint16_t)val); break; - case UINT32: *(uint32_t*)(recordData + elem_offset) = OsApi::swapl((uint32_t)val); break; - case UINT64: *(uint64_t*)(recordData + elem_offset) = OsApi::swapll((uint64_t)val); break; - case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; - case FLOAT: *(float*) (recordData + elem_offset) = OsApi::swapf((float)val); break; - case DOUBLE: *(double*)(recordData + elem_offset) = OsApi::swaplf((double)val); break; - case TIME8: *(int64_t*)(recordData + elem_offset) = OsApi::swapll((int64_t)val); break; + case INT8: cast->int8_val = (int8_t)val; break; + case INT16: cast->int16_val = OsApi::swaps((int16_t)val); break; + case INT32: cast->int32_val = OsApi::swapl((int32_t)val); break; + case INT64: cast->int64_val = OsApi::swapll((int64_t)val); break; + case UINT8: cast->uint8_val = (uint8_t)val; break; + case UINT16: cast->uint16_val = OsApi::swaps((uint16_t)val); break; + case UINT32: cast->uint32_val = OsApi::swapl((uint32_t)val); break; + case UINT64: cast->uint64_val = OsApi::swapll((uint64_t)val); break; + case BITFIELD: packBitField(recordData, f.offset, f.elements, (long)val); break; + case FLOAT: cast->float_val = OsApi::swapf((float)val); break; + case DOUBLE: cast->double_val = OsApi::swaplf((double)val); break; + case TIME8: cast->int64_val = OsApi::swapll((int64_t)val); break; case STRING: StringLib::format((char*)(recordData + elem_offset), f.elements, DEFAULT_LONG_FORMAT, val); break; default: break; @@ -758,10 +759,11 @@ const char* RecordObject::getValueText(const field_t& f, char* valbuf, int eleme if(f.flags & POINTER) { field_t ptr_field = getPointedToField(f, true, element); - if(ptr_field.offset == 0) return NULL; - else return getValueText(ptr_field, valbuf); + if(ptr_field.offset == 0) return NULL; + return getValueText(ptr_field, valbuf); } - else if(val_type == TEXT) + + if(val_type == TEXT) { char* str = (char*)(recordData + TOBYTES(f.offset)); if(valbuf) @@ -770,26 +772,26 @@ const char* RecordObject::getValueText(const field_t& f, char* valbuf, int eleme { return StringLib::copy(valbuf, str, f.elements); } - else // variable length + + // variable length + int memory_left = MIN(MAX_VAL_STR_SIZE, memoryAllocated - recordDefinition->type_size - TOBYTES(f.offset)); + if(memory_left > 1) { - int memory_left = MIN(MAX_VAL_STR_SIZE, memoryAllocated - recordDefinition->type_size - TOBYTES(f.offset)); - if(memory_left > 1) - { - return StringLib::copy(valbuf, str, memory_left); - } + return StringLib::copy(valbuf, str, memory_left); } } - else // valbuf not supplied - { - return str; - } + + // valbuf not supplied + return str; } - else if(val_type == INTEGER && valbuf) + + if(val_type == INTEGER && valbuf) { long val = getValueInteger(f); return StringLib::format(valbuf, MAX_VAL_STR_SIZE, DEFAULT_LONG_FORMAT, val); } - else if(val_type == REAL && valbuf) + + if(val_type == REAL && valbuf) { double val = getValueReal(f); return StringLib::format(valbuf, MAX_VAL_STR_SIZE, DEFAULT_DOUBLE_FORMAT, val); @@ -805,49 +807,50 @@ double RecordObject::getValueReal(const field_t& f, int element) { if(f.elements > 0 && element > 0 && element >= f.elements) throw RunTimeException(CRITICAL, RTE_ERROR, "Out of range access"); uint32_t elem_offset = TOBYTES(f.offset) + (element * FIELD_TYPE_BYTES[f.type]); + type_cast_t* cast = reinterpret_cast(recordData + elem_offset); if(f.flags & POINTER) { field_t ptr_field = getPointedToField(f, false, element); return getValueReal(ptr_field, 0); } - else if(NATIVE_FLAGS == (f.flags & BIGENDIAN)) + + if(NATIVE_FLAGS == (f.flags & BIGENDIAN)) { switch(f.type) { - case INT8: return (double)*(int8_t*) (recordData + elem_offset); - case INT16: return (double)*(int16_t*) (recordData + elem_offset); - case INT32: return (double)*(int32_t*) (recordData + elem_offset); - case INT64: return (double)*(int64_t*) (recordData + elem_offset); - case UINT8: return (double)*(uint8_t*) (recordData + elem_offset); - case UINT16: return (double)*(uint16_t*)(recordData + elem_offset); - case UINT32: return (double)*(uint32_t*)(recordData + elem_offset); - case UINT64: return (double)*(uint64_t*)(recordData + elem_offset); + case INT8: return (double)cast->int8_val; + case INT16: return (double)cast->int16_val; + case INT32: return (double)cast->int32_val; + case INT64: return (double)cast->int64_val; + case UINT8: return (double)cast->uint8_val; + case UINT16: return (double)cast->uint16_val; + case UINT32: return (double)cast->uint32_val; + case UINT64: return (double)cast->uint64_val; case BITFIELD: return (double)unpackBitField(recordData, f.offset, f.elements); - case FLOAT: return (double)*(float*) (recordData + elem_offset); - case DOUBLE: return *(double*)(recordData + elem_offset); - case TIME8: return (double)*(int64_t*)(recordData + elem_offset); + case FLOAT: return (double)cast->float_val; + case DOUBLE: return (double)cast->double_val; + case TIME8: return (double)cast->int64_val; default: return 0.0; } } - else // Swap + + // Swap + switch(f.type) { - switch(f.type) - { - case INT8: return (double) *(int8_t*) (recordData + elem_offset); - case INT16: return (double)OsApi::swaps (*(int16_t*) (recordData + elem_offset)); - case INT32: return (double)OsApi::swapl (*(int32_t*) (recordData + elem_offset)); - case INT64: return (double)OsApi::swapll(*(int64_t*) (recordData + elem_offset)); - case UINT8: return (double) *(uint8_t*) (recordData + elem_offset); - case UINT16: return (double)OsApi::swaps (*(uint16_t*)(recordData + elem_offset)); - case UINT32: return (double)OsApi::swapl (*(uint32_t*)(recordData + elem_offset)); - case UINT64: return (double)OsApi::swapll(*(uint64_t*)(recordData + elem_offset)); - case BITFIELD: return (double)unpackBitField(recordData, f.offset, f.elements); - case FLOAT: return (double)OsApi::swapf (*(float*) (recordData + elem_offset)); - case DOUBLE: return (double)OsApi::swaplf(*(double*)(recordData + elem_offset)); - case TIME8: return (double)OsApi::swapll(*(int64_t*)(recordData + elem_offset)); - default: return 0.0; - } + case INT8: return (double) cast->int8_val; + case INT16: return (double)OsApi::swaps (cast->int16_val); + case INT32: return (double)OsApi::swapl (cast->int32_val); + case INT64: return (double)OsApi::swapll(cast->int64_val); + case UINT8: return (double) cast->uint8_val; + case UINT16: return (double)OsApi::swaps (cast->uint16_val); + case UINT32: return (double)OsApi::swapl (cast->uint32_val); + case UINT64: return (double)OsApi::swapll(cast->uint64_val); + case BITFIELD: return (double)unpackBitField(recordData, f.offset, f.elements); + case FLOAT: return (double)OsApi::swapf (cast->float_val); + case DOUBLE: return (double)OsApi::swaplf(cast->double_val); + case TIME8: return (double)OsApi::swapll(cast->int64_val); + default: return 0.0; } } @@ -858,49 +861,51 @@ long RecordObject::getValueInteger(const field_t& f, int element) { if(f.elements > 0 && element > 0 && element >= f.elements) throw RunTimeException(CRITICAL, RTE_ERROR, "Out of range access"); uint32_t elem_offset = TOBYTES(f.offset) + (element * FIELD_TYPE_BYTES[f.type]); + type_cast_t* cast = reinterpret_cast(recordData + elem_offset); if(f.flags & POINTER) { field_t ptr_field = getPointedToField(f, false, element); return getValueInteger(ptr_field, 0); } - else if(NATIVE_FLAGS == (f.flags & BIGENDIAN)) + + // Native + if(NATIVE_FLAGS == (f.flags & BIGENDIAN)) { switch(f.type) { - case INT8: return (long)*(int8_t*) (recordData + elem_offset); - case INT16: return (long)*(int16_t*) (recordData + elem_offset); - case INT32: return (long)*(int32_t*) (recordData + elem_offset); - case INT64: return (long)*(int64_t*) (recordData + elem_offset); - case UINT8: return (long)*(uint8_t*) (recordData + elem_offset); - case UINT16: return (long)*(uint16_t*)(recordData + elem_offset); - case UINT32: return (long)*(uint32_t*)(recordData + elem_offset); - case UINT64: return (long)*(uint64_t*)(recordData + elem_offset); + case INT8: return (long)cast->int8_val; + case INT16: return (long)cast->int16_val; + case INT32: return (long)cast->int32_val; + case INT64: return (long)cast->int64_val; + case UINT8: return (long)cast->uint8_val; + case UINT16: return (long)cast->uint16_val; + case UINT32: return (long)cast->uint32_val; + case UINT64: return (long)cast->uint64_val; case BITFIELD: return (long)unpackBitField(recordData, f.offset, f.elements); - case FLOAT: return (long)*(float*) (recordData + elem_offset); - case DOUBLE: return (long)*(double*)(recordData + elem_offset); - case TIME8: return (long)*(int64_t*)(recordData + elem_offset); + case FLOAT: return (long)cast->float_val; + case DOUBLE: return (long)cast->double_val; + case TIME8: return (long)cast->int64_val; default: return 0; } } - else // Swap + + // Swap + switch(f.type) { - switch(f.type) - { - case INT8: return (long) *(int8_t*) (recordData + elem_offset); - case INT16: return (long)OsApi::swaps (*(int16_t*) (recordData + elem_offset)); - case INT32: return (long)OsApi::swapl (*(int32_t*) (recordData + elem_offset)); - case INT64: return (long)OsApi::swapll(*(int64_t*) (recordData + elem_offset)); - case UINT8: return (long) *(uint8_t*) (recordData + elem_offset); - case UINT16: return (long)OsApi::swaps (*(uint16_t*)(recordData + elem_offset)); - case UINT32: return (long)OsApi::swapl (*(uint32_t*)(recordData + elem_offset)); - case UINT64: return (long)OsApi::swapll(*(uint64_t*)(recordData + elem_offset)); - case BITFIELD: return (long)unpackBitField(recordData, f.offset, f.elements); - case FLOAT: return (long)OsApi::swapf (*(float*) (recordData + elem_offset)); - case DOUBLE: return (long)OsApi::swaplf(*(double*)(recordData + elem_offset)); - case TIME8: return (long)OsApi::swapll(*(int64_t*)(recordData + elem_offset)); - default: return 0; - } + case INT8: return (long) cast->int8_val; + case INT16: return (long)OsApi::swaps (cast->int16_val); + case INT32: return (long)OsApi::swapl (cast->int32_val); + case INT64: return (long)OsApi::swapll(cast->int64_val); + case UINT8: return (long) cast->uint8_val; + case UINT16: return (long)OsApi::swaps (cast->uint16_val); + case UINT32: return (long)OsApi::swapl (cast->uint32_val); + case UINT64: return (long)OsApi::swapll(cast->uint64_val); + case BITFIELD: return (long)unpackBitField(recordData, f.offset, f.elements); + case FLOAT: return (long)OsApi::swapf (cast->float_val); + case DOUBLE: return (long)OsApi::swaplf(cast->double_val); + case TIME8: return (long)OsApi::swapll(cast->int64_val); + default: return 0; } } @@ -963,8 +968,7 @@ RecordObject::recordDefErr_t RecordObject::defineField(const char* rec_type, con *----------------------------------------------------------------------------*/ bool RecordObject::isRecord(const char* rec_type) { - if(getDefinition(rec_type) != NULL) return true; - else return false; + return (getDefinition(rec_type) != NULL); } /*---------------------------------------------------------------------------- @@ -1073,7 +1077,7 @@ Dictionary* RecordObject::getRecordFields (const char* re * * Allocates no memory, returns size of type *----------------------------------------------------------------------------*/ -int RecordObject::parseSerial(unsigned char* buffer, int size, const char** rec_type, const unsigned char** rec_data) +int RecordObject::parseSerial(const unsigned char* buffer, int size, const char** rec_type, const unsigned char** rec_data) { if(rec_type) *rec_type = NULL; if(rec_data) *rec_data = NULL; @@ -1100,11 +1104,10 @@ int RecordObject::parseSerial(unsigned char* buffer, int size, const char** rec_ unsigned int RecordObject::str2flags (const char* str) { unsigned int flags = NATIVE_FLAGS; - SafeString flagss("%s", str); - List* flaglist = flagss.split('|'); + List* flaglist = StringLib::split(str, strlen(str), '|'); for(int i = 0; i < flaglist->length(); i++) { - const char* flag = (*flaglist)[i].str(false); + const char* flag = (*flaglist)[i]->c_str(); if(StringLib::match(flag, "NATIVE")) flags = NATIVE_FLAGS; else if(StringLib::match(flag, "LE")) flags &= ~BIGENDIAN; else if(StringLib::match(flag, "BE")) flags |= BIGENDIAN; @@ -1121,14 +1124,14 @@ unsigned int RecordObject::str2flags (const char* str) *----------------------------------------------------------------------------*/ const char* RecordObject::flags2str (unsigned int flags) { - SafeString flagss; + string flagss; if(flags & BIGENDIAN) flagss += "BE"; else flagss += "LE"; if(flags & POINTER) flagss += "|PTR"; - return flagss.str(true); + return StringLib::duplicate(flagss.c_str()); } /*---------------------------------------------------------------------------- @@ -1136,39 +1139,39 @@ const char* RecordObject::flags2str (unsigned int flags) *----------------------------------------------------------------------------*/ RecordObject::fieldType_t RecordObject::str2ft (const char* str) { - if(StringLib::match(str, "INT8")) return INT8; - else if(StringLib::match(str, "INT16")) return INT16; - else if(StringLib::match(str, "INT32")) return INT32; - else if(StringLib::match(str, "INT64")) return INT64; - else if(StringLib::match(str, "UINT8")) return UINT8; - else if(StringLib::match(str, "UINT16")) return UINT16; - else if(StringLib::match(str, "UINT32")) return UINT32; - else if(StringLib::match(str, "UINT64")) return UINT64; - else if(StringLib::match(str, "BITFIELD")) return BITFIELD; - else if(StringLib::match(str, "FLOAT")) return FLOAT; - else if(StringLib::match(str, "DOUBLE")) return DOUBLE; - else if(StringLib::match(str, "TIME8")) return TIME8; - else if(StringLib::match(str, "STRING")) return STRING; - else if(StringLib::match(str, "USER")) return USER; - else if(StringLib::match(str, "INT16BE")) return INT16; - else if(StringLib::match(str, "INT32BE")) return INT32; - else if(StringLib::match(str, "INT64BE")) return INT64; - else if(StringLib::match(str, "UINT16BE")) return UINT16; - else if(StringLib::match(str, "UINT32BE")) return UINT32; - else if(StringLib::match(str, "UINT64BE")) return UINT64; - else if(StringLib::match(str, "FLOATBE")) return FLOAT; - else if(StringLib::match(str, "DOUBLEBE")) return DOUBLE; - else if(StringLib::match(str, "TIME8BE")) return TIME8; - else if(StringLib::match(str, "INT16LE")) return INT16; - else if(StringLib::match(str, "INT32LE")) return INT32; - else if(StringLib::match(str, "INT64LE")) return INT64; - else if(StringLib::match(str, "UINT16LE")) return UINT16; - else if(StringLib::match(str, "UINT32LE")) return UINT32; - else if(StringLib::match(str, "UINT64LE")) return UINT64; - else if(StringLib::match(str, "FLOATLE")) return FLOAT; - else if(StringLib::match(str, "DOUBLELE")) return DOUBLE; - else if(StringLib::match(str, "TIME8LE")) return TIME8; - else return INVALID_FIELD; + if(StringLib::match(str, "INT8")) return INT8; + if(StringLib::match(str, "INT16")) return INT16; + if(StringLib::match(str, "INT32")) return INT32; + if(StringLib::match(str, "INT64")) return INT64; + if(StringLib::match(str, "UINT8")) return UINT8; + if(StringLib::match(str, "UINT16")) return UINT16; + if(StringLib::match(str, "UINT32")) return UINT32; + if(StringLib::match(str, "UINT64")) return UINT64; + if(StringLib::match(str, "BITFIELD")) return BITFIELD; + if(StringLib::match(str, "FLOAT")) return FLOAT; + if(StringLib::match(str, "DOUBLE")) return DOUBLE; + if(StringLib::match(str, "TIME8")) return TIME8; + if(StringLib::match(str, "STRING")) return STRING; + if(StringLib::match(str, "USER")) return USER; + if(StringLib::match(str, "INT16BE")) return INT16; + if(StringLib::match(str, "INT32BE")) return INT32; + if(StringLib::match(str, "INT64BE")) return INT64; + if(StringLib::match(str, "UINT16BE")) return UINT16; + if(StringLib::match(str, "UINT32BE")) return UINT32; + if(StringLib::match(str, "UINT64BE")) return UINT64; + if(StringLib::match(str, "FLOATBE")) return FLOAT; + if(StringLib::match(str, "DOUBLEBE")) return DOUBLE; + if(StringLib::match(str, "TIME8BE")) return TIME8; + if(StringLib::match(str, "INT16LE")) return INT16; + if(StringLib::match(str, "INT32LE")) return INT32; + if(StringLib::match(str, "INT64LE")) return INT64; + if(StringLib::match(str, "UINT16LE")) return UINT16; + if(StringLib::match(str, "UINT32LE")) return UINT32; + if(StringLib::match(str, "UINT64LE")) return UINT64; + if(StringLib::match(str, "FLOATLE")) return FLOAT; + if(StringLib::match(str, "DOUBLELE")) return DOUBLE; + if(StringLib::match(str, "TIME8LE")) return TIME8; + return INVALID_FIELD; } /*---------------------------------------------------------------------------- @@ -1178,40 +1181,40 @@ bool RecordObject::str2be (const char* str) { #define _IS_BIGENDIAN ((NATIVE_FLAGS & BIGENDIAN) == BIGENDIAN) - if(StringLib::match(str, "BE")) return true; - else if(StringLib::match(str, "LE")) return false; - else if(StringLib::match(str, "INT8")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "INT16")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "INT32")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "INT64")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "UINT8")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "UINT16")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "UINT32")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "UINT64")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "BITFIELD")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "FLOAT")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "DOUBLE")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "TIME8")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "STRING")) return _IS_BIGENDIAN; - else if(StringLib::match(str, "INT16BE")) return true; - else if(StringLib::match(str, "INT32BE")) return true; - else if(StringLib::match(str, "INT64BE")) return true; - else if(StringLib::match(str, "UINT16BE")) return true; - else if(StringLib::match(str, "UINT32BE")) return true; - else if(StringLib::match(str, "UINT64BE")) return true; - else if(StringLib::match(str, "FLOATBE")) return true; - else if(StringLib::match(str, "DOUBLEBE")) return true; - else if(StringLib::match(str, "TIME8BE")) return true; - else if(StringLib::match(str, "INT16LE")) return false; - else if(StringLib::match(str, "INT32LE")) return false; - else if(StringLib::match(str, "INT64LE")) return false; - else if(StringLib::match(str, "UINT16LE")) return false; - else if(StringLib::match(str, "UINT32LE")) return false; - else if(StringLib::match(str, "UINT64LE")) return false; - else if(StringLib::match(str, "FLOATLE")) return false; - else if(StringLib::match(str, "DOUBLELE")) return false; - else if(StringLib::match(str, "TIME8LE")) return false; - else return _IS_BIGENDIAN; // default native + if(StringLib::match(str, "BE")) return true; + if(StringLib::match(str, "LE")) return false; + if(StringLib::match(str, "INT8")) return _IS_BIGENDIAN; + if(StringLib::match(str, "INT16")) return _IS_BIGENDIAN; + if(StringLib::match(str, "INT32")) return _IS_BIGENDIAN; + if(StringLib::match(str, "INT64")) return _IS_BIGENDIAN; + if(StringLib::match(str, "UINT8")) return _IS_BIGENDIAN; + if(StringLib::match(str, "UINT16")) return _IS_BIGENDIAN; + if(StringLib::match(str, "UINT32")) return _IS_BIGENDIAN; + if(StringLib::match(str, "UINT64")) return _IS_BIGENDIAN; + if(StringLib::match(str, "BITFIELD")) return _IS_BIGENDIAN; + if(StringLib::match(str, "FLOAT")) return _IS_BIGENDIAN; + if(StringLib::match(str, "DOUBLE")) return _IS_BIGENDIAN; + if(StringLib::match(str, "TIME8")) return _IS_BIGENDIAN; + if(StringLib::match(str, "STRING")) return _IS_BIGENDIAN; + if(StringLib::match(str, "INT16BE")) return true; + if(StringLib::match(str, "INT32BE")) return true; + if(StringLib::match(str, "INT64BE")) return true; + if(StringLib::match(str, "UINT16BE")) return true; + if(StringLib::match(str, "UINT32BE")) return true; + if(StringLib::match(str, "UINT64BE")) return true; + if(StringLib::match(str, "FLOATBE")) return true; + if(StringLib::match(str, "DOUBLEBE")) return true; + if(StringLib::match(str, "TIME8BE")) return true; + if(StringLib::match(str, "INT16LE")) return false; + if(StringLib::match(str, "INT32LE")) return false; + if(StringLib::match(str, "INT64LE")) return false; + if(StringLib::match(str, "UINT16LE")) return false; + if(StringLib::match(str, "UINT32LE")) return false; + if(StringLib::match(str, "UINT64LE")) return false; + if(StringLib::match(str, "FLOATLE")) return false; + if(StringLib::match(str, "DOUBLELE")) return false; + if(StringLib::match(str, "TIME8LE")) return false; + return _IS_BIGENDIAN; // default native } /*---------------------------------------------------------------------------- @@ -1258,7 +1261,7 @@ const char* RecordObject::vt2str (valType_t vt) * * TODO only supports big endian representation *----------------------------------------------------------------------------*/ -unsigned long RecordObject::unpackBitField (unsigned char* buf, int bit_offset, int bit_length) +unsigned long RecordObject::unpackBitField (const unsigned char* buf, int bit_offset, int bit_length) { /* Setup Parameters */ int bits_left = bit_length; @@ -1446,7 +1449,7 @@ RecordObject::field_t RecordObject::getPointedToField(field_t f, bool allow_null { throw RunTimeException(CRITICAL, RTE_ERROR, "Attempted to dereference null pointer field!"); } - else if(f.offset > ((memoryAllocated - recordDefinition->type_size) * 8)) + if(f.offset > ((memoryAllocated - recordDefinition->type_size) * 8)) { // Note that this check is only performed when memory has been allocated // this means that for a RecordInterface access to the record memory goes unchecked @@ -1621,7 +1624,7 @@ RecordObject::recordDefErr_t RecordObject::addField(definition_t* def, const cha /* Check Definition */ if(!def) return NOTFOUND_DEF; - else if(!field_name) return FIELDERR_DEF; + if(!field_name) return FIELDERR_DEF; /* Initialize Parameters */ recordDefErr_t status = FIELDERR_DEF; @@ -1676,7 +1679,7 @@ RecordObject::definition_t* RecordObject::getDefinition(unsigned char* buffer, i { /* Check Parameters */ if(buffer == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Null buffer used to retrieve record definition"); - else if(size <= (int)sizeof(rec_hdr_t)) throw RunTimeException(CRITICAL, RTE_ERROR, "Buffer too small to retrieve record definition"); + if(size <= (int)sizeof(rec_hdr_t)) throw RunTimeException(CRITICAL, RTE_ERROR, "Buffer too small to retrieve record definition"); /* Get Record Definitions */ char* rec_type = (char*)&buffer[sizeof(rec_hdr_t)]; diff --git a/packages/core/RecordObject.h b/packages/core/RecordObject.h index e97fe7302..a0db73807 100644 --- a/packages/core/RecordObject.h +++ b/packages/core/RecordObject.h @@ -125,7 +125,7 @@ class RecordObject int32_t offset; // bits for BITFIELD, bytes for everything else int32_t elements; const char* exttype; - unsigned int flags; + uint64_t flags; } fieldDef_t; typedef enum { @@ -137,6 +137,19 @@ class RecordObject REGERR_DEF = -5 } recordDefErr_t; + typedef union { + int8_t int8_val; + int16_t int16_val; + int32_t int32_val; + int64_t int64_val; + uint8_t uint8_val; + uint16_t uint16_val; + uint32_t uint32_val; + uint64_t uint64_val; + float float_val; + double double_val; + } type_cast_t; + /*-------------------------------------------------------------------- * Constants *--------------------------------------------------------------------*/ @@ -164,11 +177,11 @@ class RecordObject public: Field (RecordObject& _rec, fieldType_t _type, int _offset, int _elements, unsigned int _flags=0, int _element=0); - Field (RecordObject& _rec, field_t _field, int _element=0); + Field (RecordObject& _rec, const field_t& _field, int _element=0); Field (const Field& f); ~Field (void); - Field& operator= (const char* const rhs); + Field& operator= (const char* rhs); Field& operator= (double const& rhs); Field& operator= (long const& rhs); @@ -188,24 +201,24 @@ class RecordObject * Methods *--------------------------------------------------------------------*/ - RecordObject (const char* rec_type, int allocated_memory=0, bool clear=true); // must include the record type - RecordObject (unsigned char* buffer, int size); + explicit RecordObject (const char* rec_type, int allocated_memory=0, bool clear=true); // must include the record type + explicit RecordObject (unsigned char* buffer, int size); virtual ~RecordObject (void); /* Overloaded Methods */ virtual bool deserialize (unsigned char* buffer, int size); virtual int serialize (unsigned char** buffer, serialMode_t mode=ALLOCATE, int size=0); - bool post (Publisher* outq, int size=0, bool* active=NULL, bool verbose=true); + bool post (Publisher* outq, int size=0, const bool* active=NULL, bool verbose=true); /* Attribute Methods */ - bool isRecordType (const char* rec_type); - const char* getRecordType (void); // used to identify type of records (used for parsing) + bool isRecordType (const char* rec_type) const; + const char* getRecordType (void) const; // used to identify type of records (used for parsing) long getRecordId (void); // used to identify records of the same type (used for filtering)) - unsigned char* getRecordData (void); - int getRecordTypeSize (void); - int getRecordDataSize (void); - int getAllocatedMemory (void); - int getAllocatedDataSize(void); + unsigned char* getRecordData (void) const; + int getRecordTypeSize (void) const; + int getRecordDataSize (void) const; + int getAllocatedMemory (void) const; + int getAllocatedDataSize(void) const; Field* createRecordField (const char* field_name); /* Get/Set Methods */ @@ -216,8 +229,8 @@ class RecordObject field_t getField (const char* field_name); Field field (const char* field_name); void setValueText (const field_t& field, const char* val, int element=0); - void setValueReal (const field_t& field, const double val, int element=0); - void setValueInteger (const field_t& field, const long val, int element=0); + void setValueReal (const field_t& field, double val, int element=0); + void setValueInteger (const field_t& field, long val, int element=0); const char* getValueText (const field_t& field, char* valbuf=NULL, int element=0); double getValueReal (const field_t& field, int element=0); long getValueInteger (const field_t& field, int element=0); @@ -238,14 +251,14 @@ class RecordObject static int getRecordMaxFields (const char* rec_type); static int getRecordFields (const char* rec_type, char*** field_names, field_t*** fields); static Dictionary* getRecordFields (const char* rec_type); - static int parseSerial (unsigned char* buffer, int size, const char** rec_type, const unsigned char** rec_data); + static int parseSerial (const unsigned char* buffer, int size, const char** rec_type, const unsigned char** rec_data); static unsigned int str2flags (const char* str); static const char* flags2str (unsigned int flags); static fieldType_t str2ft (const char* str); static bool str2be (const char* str); static const char* ft2str (fieldType_t ft); static const char* vt2str (valType_t vt); - static unsigned long unpackBitField (unsigned char* buf, int bit_offset, int bit_length); + static unsigned long unpackBitField (const unsigned char* buf, int bit_offset, int bit_length); static void packBitField (unsigned char* buf, int bit_offset, int bit_length, long val); static field_t parseImmediateField (const char* str); @@ -284,15 +297,15 @@ class RecordObject data_size = _data_size; record_size = sizeof(rec_hdr_t) + type_size + _data_size; } ~definition_t(void) - { if(type_name) delete [] type_name; - if(id_field) delete [] id_field; } + { delete [] type_name; + delete [] id_field; } }; /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - static MgDictionary definitions; + static Dictionary definitions; static Mutex defMut; definition_t* recordDefinition; diff --git a/packages/core/ReportDispatch.cpp b/packages/core/ReportDispatch.cpp index 947b30e09..69ce3e146 100644 --- a/packages/core/ReportDispatch.cpp +++ b/packages/core/ReportDispatch.cpp @@ -47,8 +47,8 @@ * STATIC DATA ******************************************************************************/ -const char* ReportDispatch::LuaMetaName = "ReportDispatch"; -const struct luaL_Reg ReportDispatch::LuaMetaTable[] = { +const char* ReportDispatch::LUA_META_NAME = "ReportDispatch"; +const struct luaL_Reg ReportDispatch::LUA_META_TABLE[] = { {"idxdisplay", luaSetIndexDisplay}, {"flushrow", luaFlushRow}, {NULL, NULL} @@ -115,12 +115,12 @@ int ReportDispatch::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); num_results = returnLuaStatus(L, false); } /* Clean Up and Return */ - if(columns) delete [] columns; + delete [] columns; return num_results; } @@ -133,9 +133,9 @@ int ReportDispatch::luaCreate (lua_State* L) *----------------------------------------------------------------------------*/ ReportDispatch::format_t ReportDispatch::str2format (const char* str) { - if(StringLib::match(str, "CSV")) return CSV; - else if(StringLib::match(str, "JSON")) return JSON; - else return INVALID_FORMAT; + if(StringLib::match(str, "CSV")) return CSV; + if(StringLib::match(str, "JSON")) return JSON; + return INVALID_FORMAT; } /*---------------------------------------------------------------------------- @@ -143,9 +143,9 @@ ReportDispatch::format_t ReportDispatch::str2format (const char* str) *----------------------------------------------------------------------------*/ const char* ReportDispatch::format2str (format_t _format) { - if(_format == CSV) return "CSV"; - else if(_format == JSON) return "JSON"; - else return "INVALID"; + if(_format == CSV) return "CSV"; + if(_format == JSON) return "JSON"; + return "INVALID"; } /*---------------------------------------------------------------------------- @@ -153,9 +153,9 @@ const char* ReportDispatch::format2str (format_t _format) *----------------------------------------------------------------------------*/ ReportDispatch::indexDisplay_t ReportDispatch::str2display(const char* str) { - if(StringLib::match(str, "INT")) return INT_DISPLAY; - else if(StringLib::match(str, "GMT")) return GMT_DISPLAY; - else return INVALID_DISPLAY; + if(StringLib::match(str, "INT")) return INT_DISPLAY; + if(StringLib::match(str, "GMT")) return GMT_DISPLAY; + return INVALID_DISPLAY; } /*---------------------------------------------------------------------------- @@ -163,9 +163,9 @@ ReportDispatch::indexDisplay_t ReportDispatch::str2display(const char* str) *----------------------------------------------------------------------------*/ const char* ReportDispatch::display2str(indexDisplay_t _display) { - if(_display == INT_DISPLAY) return "INT"; - else if(_display == GMT_DISPLAY) return "GMT"; - else return "INVALID"; + if(_display == INT_DISPLAY) return "INT"; + if(_display == GMT_DISPLAY) return "GMT"; + return "INVALID"; } /****************************************************************************** @@ -178,7 +178,7 @@ const char* ReportDispatch::display2str(indexDisplay_t _display) ReportDispatch::ReportFile::ReportFile(lua_State* L, const char* _filename, format_t _format): File(L, _filename, File::TEXT, File::WRITER, File::FLUSHED), format(_format), - values(Dictionary::DEFAULT_HASH_TABLE_SIZE, Dictionary::DEFAULT_HASH_TABLE_LOAD) + index(0) { headerInProgress = false; indexDisplay = INT_DISPLAY; @@ -194,7 +194,7 @@ int ReportDispatch::ReportFile::writeFileHeader (void) if(format == CSV) { /* Build Header String */ - SafeString header("Index"); + string header("Index"); const char* column = values.first(NULL); while(column) { @@ -206,7 +206,7 @@ int ReportDispatch::ReportFile::writeFileHeader (void) /* Write Header String */ headerInProgress = true; - int status = File::writeBuffer(header.str(false), header.length()); + int status = File::writeBuffer(header.c_str(), header.length()); headerInProgress = false; return status; } @@ -238,45 +238,46 @@ int ReportDispatch::ReportFile::writeFileData (void) } /* Build Row String and Clear Values */ - SafeString row; + string row; row += index_str; - const char* value = NULL; + string* value; const char* column = values.first(&value); while(column) { row += ","; - if(value) row += value; - const char* space = StringLib::duplicate(REPORT_SPACE); - values.add(column, space); + if(value) row += *value; + string* space = new string(REPORT_SPACE); + if(!values.add(column, space)) delete space; column = values.next(&value); } row += "\n"; /* Write Row String */ - return File::writeBuffer(row.str(false), row.length()); + return File::writeBuffer(row.c_str(), row.length()); } - else if(format == JSON) + + if(format == JSON) { /* Build JSON String */ - SafeString json("{\n"); - const char* value = NULL; + string json("{\n"); + string* value; const char* column = values.first(&value); while(column) { json += "\t\""; json += column; json += "\": \""; - if(value) json += value; + if(value) json += *value; json += "\""; - const char* space = StringLib::duplicate(REPORT_SPACE); - values.add(column, space); + string* space = new string(REPORT_SPACE); + if(!values.add(column, space)) delete space; column = values.next(&value); if(column) json += ",\n"; else json += "\n}"; } /* Write Row String */ - return File::writeBuffer(json.str(false), json.length()); + return File::writeBuffer(json.c_str(), json.length()); } return 0; @@ -290,7 +291,7 @@ int ReportDispatch::ReportFile::writeFileData (void) * Constructor - ReportDispatch *----------------------------------------------------------------------------*/ ReportDispatch::ReportDispatch (lua_State* L, const char* _filename, format_t _format, int buffer, const char** columns, int num_columns): - DispatchObject(L, LuaMetaName, LuaMetaTable), + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE), report(L ,_filename, _format) { /* Define Metric Record */ @@ -303,7 +304,7 @@ ReportDispatch::ReportDispatch (lua_State* L, const char* _filename, format_t _f reportError = true; /* Initialize Entry Ordering */ - if(buffer > 0) entries = new MgOrdering(ReportDispatch::postEntry, this, buffer); + if(buffer > 0) entries = new EntryOrdering(ReportDispatch::postEntry, this, buffer); else entries = NULL; /* Populate Fixed Header If Provided */ @@ -312,7 +313,7 @@ ReportDispatch::ReportDispatch (lua_State* L, const char* _filename, format_t _f fixedHeader = true; for(int i = 0; i < num_columns; i++) { - const char* space = StringLib::duplicate(REPORT_SPACE); + string* space = new string(REPORT_SPACE); report.values.add(columns[i], space); } } @@ -323,7 +324,7 @@ ReportDispatch::ReportDispatch (lua_State* L, const char* _filename, format_t _f *----------------------------------------------------------------------------*/ ReportDispatch::~ReportDispatch (void) { - if(entries) delete entries; + delete entries; } /*---------------------------------------------------------------------------- @@ -381,12 +382,12 @@ bool ReportDispatch::processRecord (RecordObject* record, okey_t key, recVec_t* *----------------------------------------------------------------------------*/ int ReportDispatch::postEntry(void* data, int size, void* parm) { - ReportDispatch* dispatch = (ReportDispatch*)parm; + ReportDispatch* dispatch = static_cast(parm); int status = size; entry_t* entry = *(entry_t**)data; okey_t index = entry->index; const char* name = entry->name; - const char* value = StringLib::duplicate(entry->value); + string* value = new string(entry->value); /* Flush Row on New Index */ if(dispatch->lastIndex != index && dispatch->lastIndex != INVALID_KEY) @@ -399,17 +400,18 @@ int ReportDispatch::postEntry(void* data, int size, void* parm) dispatch->report.index = index; /* Update Value */ + bool value_added = false; if(dispatch->fixedHeader) { if(dispatch->report.values.find(name)) { - dispatch->report.values.add(name, value); + value_added = dispatch->report.values.add(name, value); } } else // dynamic header { int prev_num_values = dispatch->report.values.length(); - dispatch->report.values.add(name, value); + value_added = dispatch->report.values.add(name, value); if(dispatch->report.values.length() != prev_num_values) { dispatch->writeHeader = true; @@ -419,6 +421,9 @@ int ReportDispatch::postEntry(void* data, int size, void* parm) /* Set Error Reporting Back to True */ dispatch->reportError = true; + /* Remove Dangling Value */ + if(!value_added) delete value; + /* Free Entry and Return Status */ if(status > 0) delete entry; return status; @@ -467,7 +472,7 @@ int ReportDispatch::luaSetIndexDisplay(lua_State* L) try { /* Get Self */ - ReportDispatch* lua_obj = (ReportDispatch*)getLuaSelf(L, 1); + ReportDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* display_str = getLuaString(L, 2); @@ -506,7 +511,7 @@ int ReportDispatch::luaFlushRow(lua_State* L) try { /* Get Self */ - ReportDispatch* lua_obj = (ReportDispatch*)getLuaSelf(L, 1); + ReportDispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* scope_str = getLuaString(L, 2, true, "ROW", &flush_all); diff --git a/packages/core/ReportDispatch.h b/packages/core/ReportDispatch.h index dc5be9546..9a4838ee6 100644 --- a/packages/core/ReportDispatch.h +++ b/packages/core/ReportDispatch.h @@ -54,8 +54,8 @@ class ReportDispatch: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types @@ -79,7 +79,7 @@ class ReportDispatch: public DispatchObject static int luaCreate (lua_State* L); static format_t str2format (const char* str); - static const char* format2str (format_t _type); + static const char* format2str (format_t _format); static indexDisplay_t str2display (const char* str); static const char* display2str (indexDisplay_t _display); @@ -104,11 +104,18 @@ class ReportDispatch: public DispatchObject ~entry_t(void) { - if(name) delete [] name; - if(value) delete [] value; + delete [] name; + delete [] value; } }; + /*-------------------------------------------------------------------- + * Typedefs + *--------------------------------------------------------------------*/ + + typedef Dictionary ValueDictionary; + typedef Ordering EntryOrdering; + /*-------------------------------------------------------------------- * Report File Class *--------------------------------------------------------------------*/ @@ -123,7 +130,7 @@ class ReportDispatch: public DispatchObject static const int MAX_INDEX_STR_SIZE = 256; format_t format; - MgDictionary values; // indexed by data point names + ValueDictionary values; // indexed by data point names okey_t index; bool headerInProgress; indexDisplay_t indexDisplay; @@ -139,7 +146,7 @@ class ReportDispatch: public DispatchObject bool writeHeader; bool reportError; Mutex reportMut; - MgOrdering* entries; + EntryOrdering* entries; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/SpatialIndex.cpp b/packages/core/SpatialIndex.cpp index a3c200ab9..6e85703e8 100644 --- a/packages/core/SpatialIndex.cpp +++ b/packages/core/SpatialIndex.cpp @@ -48,8 +48,8 @@ * STATIC DATA ******************************************************************************/ -const char* SpatialIndex::LuaMetaName = "SpatialIndex"; -const struct luaL_Reg SpatialIndex::LuaMetaTable[] = { +const char* SpatialIndex::LUA_META_NAME = "SpatialIndex"; +const struct luaL_Reg SpatialIndex::LUA_META_TABLE[] = { {"add", luaAdd}, {"query", luaQuery}, {"display", luaDisplay}, @@ -73,7 +73,7 @@ int SpatialIndex::luaCreate (lua_State* L) try { /* Get Asset Directory */ - Asset* _asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + Asset* _asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); MathLib::proj_t _projection = (MathLib::proj_t)getLuaInteger(L, 2); int _threshold = getLuaInteger(L, 3, true, DEFAULT_THRESHOLD); @@ -82,7 +82,7 @@ int SpatialIndex::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -91,7 +91,7 @@ int SpatialIndex::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ SpatialIndex::SpatialIndex(lua_State* L, Asset* _asset, MathLib::proj_t _projection, int _threshold): - AssetIndex(L, *_asset, LuaMetaName, LuaMetaTable, _threshold) + AssetIndex(L, *_asset, LUA_META_NAME, LUA_META_TABLE, _threshold) { projection = _projection; @@ -114,7 +114,8 @@ void SpatialIndex::split (node_t* node, spatialspan_t& lspan, spatialspan_t& rsp projspan_t proj = project(node->span); /* Split Region */ - projspan_t lproj, rproj; + projspan_t lproj; + projspan_t rproj; if(node->depth % 2 == 0) // even depth { /* Split Across Radius */ @@ -168,17 +169,12 @@ bool SpatialIndex::isleft (node_t* node, const spatialspan_t& span) if(node->depth % 2 == 0) // even depth = Radius { double split_val = (lproj.p1.x + rproj.p0.x) / 2.0; - - if(sproj.p0.x <= split_val) return true; - else return false; + return (sproj.p0.x <= split_val); } - else // odd depth = Angle - { - double split_val = (lproj.p1.y + rproj.p0.y) / 2.0; - if(sproj.p0.y <= split_val) return true; - else return false; - } + // else odd depth = Angle + double split_val = (lproj.p1.y + rproj.p0.y) / 2.0; + return (sproj.p0.y <= split_val); } @@ -199,17 +195,12 @@ bool SpatialIndex::isright (node_t* node, const spatialspan_t& span) if(node->depth % 2 == 0) // even depth = Radius { double split_val = (lproj.p1.x + rproj.p0.x) / 2.0; - - if(sproj.p1.x >= split_val) return true; - else return false; + return (sproj.p1.x >= split_val); } - else // odd depth = Angle - { - double split_val = (lproj.p1.y + rproj.p0.y) / 2.0; - if(sproj.p1.y >= split_val) return true; - else return false; - } + // else odd depth = Angle + double split_val = (lproj.p1.y + rproj.p0.y) / 2.0; + return (sproj.p1.y >= split_val); } /*---------------------------------------------------------------------------- @@ -316,7 +307,7 @@ spatialspan_t SpatialIndex::luatable2span (lua_State* L, int parm) if(provided) { - if(StringLib::match("lat0", key)) span.c0.lat = value; + if (StringLib::match("lat0", key)) span.c0.lat = value; else if(StringLib::match("lon0", key)) span.c0.lon = value; else if(StringLib::match("lat1", key)) span.c1.lat = value; else if(StringLib::match("lon1", key)) span.c1.lon = value; @@ -383,7 +374,7 @@ int SpatialIndex::luaProject (lua_State* L) try { /* Get Self */ - SpatialIndex* lua_obj = (SpatialIndex*)getLuaSelf(L, 1); + SpatialIndex* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Spherical Coordinates */ MathLib::coord_t c; @@ -415,7 +406,7 @@ int SpatialIndex::luaSphere (lua_State* L) try { /* Get Self */ - SpatialIndex* lua_obj = (SpatialIndex*)getLuaSelf(L, 1); + SpatialIndex* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Polar Coordinates */ MathLib::point_t p; @@ -447,7 +438,7 @@ int SpatialIndex::luaSplit (lua_State* L) try { /* Get Self */ - SpatialIndex* lua_obj = (SpatialIndex*)getLuaSelf(L, 1); + SpatialIndex* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Spatial Span */ spatialspan_t span = lua_obj->luatable2span(L, 2); @@ -462,7 +453,8 @@ int SpatialIndex::luaSplit (lua_State* L) node.ril = NULL; /* Split Span */ - spatialspan_t lspan, rspan; + spatialspan_t lspan; + spatialspan_t rspan; lua_obj->split(&node, lspan, rspan); /* Return Spans */ @@ -497,7 +489,7 @@ int SpatialIndex::luaIntersect (lua_State* L) try { /* Get Self */ - SpatialIndex* lua_obj = (SpatialIndex*)getLuaSelf(L, 1); + SpatialIndex* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Spatial Spans */ spatialspan_t span1 = lua_obj->luatable2span(L, 2); @@ -527,7 +519,7 @@ int SpatialIndex::luaCombine (lua_State* L) try { /* Get Self */ - SpatialIndex* lua_obj = (SpatialIndex*)getLuaSelf(L, 1); + SpatialIndex* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Spatial Spans */ spatialspan_t span1 = lua_obj->luatable2span(L, 2); diff --git a/packages/core/SpatialIndex.h b/packages/core/SpatialIndex.h index 1134f79ab..46e6875ed 100644 --- a/packages/core/SpatialIndex.h +++ b/packages/core/SpatialIndex.h @@ -88,8 +88,8 @@ class SpatialIndex: public AssetIndex * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/core/StringLib.cpp b/packages/core/StringLib.cpp index e189f215d..e94ca529b 100644 --- a/packages/core/StringLib.cpp +++ b/packages/core/StringLib.cpp @@ -59,567 +59,73 @@ const int StringLib::B64INDEX[256] = }; /****************************************************************************** - * STRING PUBLIC METHODS + * FORMATTED STRING METHODS ******************************************************************************/ /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -SafeString::String(long _maxlen) -{ - if(_maxlen <= 0) maxlen = DEFAULT_STR_SIZE; - else maxlen = _maxlen; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = 1; -} - -/*---------------------------------------------------------------------------- - * Constructor - *----------------------------------------------------------------------------*/ -SafeString::String(const char* _str, ...) +StringLib::FormattedString::FormattedString(const char* _str, ...) { if(_str != NULL) { va_list args; va_start(args, _str); - len = vsnprintf(NULL, 0, _str, args) + 1; // get length + bufsize = vsnprintf(NULL, 0, _str, args) + 1; // get length va_end(args); - carray = new char[len]; // allocate memory - maxlen = len; + carray = new char[bufsize]; // allocate memory va_start(args, _str); vsprintf(carray, _str, args); // copy in formatted contents va_end(args); - carray[maxlen - 1] ='\0'; // null terminate - } - else - { - maxlen = DEFAULT_STR_SIZE; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = 1; - } -} - -/*---------------------------------------------------------------------------- - * Constructor (COPY) - *----------------------------------------------------------------------------*/ -SafeString::String(const SafeString& other) -{ - maxlen = other.maxlen; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = other.len; - StringLib::copy(carray, other.carray, len); -} - -/*---------------------------------------------------------------------------- - * Constructor (ENCODE) - *----------------------------------------------------------------------------*/ -SafeString::String (int base, unsigned char* buffer, int size) -{ - if(base == 64) - { - int encoded_len = size; - carray = StringLib::b64encode(buffer, &encoded_len); - maxlen = encoded_len; - len = encoded_len; + carray[bufsize - 1] ='\0'; // null terminate } else { - maxlen = DEFAULT_STR_SIZE; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = 1; + carray = new char[1]; + carray[0] = '\0'; + bufsize = 1; } } /*---------------------------------------------------------------------------- * Destructor *----------------------------------------------------------------------------*/ -SafeString::~String(void) +StringLib::FormattedString::~FormattedString(void) { delete [] carray; } /*---------------------------------------------------------------------------- - * getString + * c_str *----------------------------------------------------------------------------*/ -const char* SafeString::str(bool duplicate) +const char* StringLib::FormattedString::c_str(bool duplicate) { if(duplicate) { - char* new_str = new char[len]; - StringLib::copy(new_str, carray, len); + char* new_str = new char[bufsize]; + StringLib::copy(new_str, carray, bufsize); return new_str; } - else - { - return carray; - } -} - -/*---------------------------------------------------------------------------- - * length - number of non-null characters in string - *----------------------------------------------------------------------------*/ -long SafeString::length(void) -{ - return len - 1; // remove null terminator in length -} - -/*---------------------------------------------------------------------------- - * bytes - size of memory needed to store string (includes null terminator) - *----------------------------------------------------------------------------*/ -long SafeString::bytes(void) -{ - return len; -} - -/*---------------------------------------------------------------------------- - * appendChar - *----------------------------------------------------------------------------*/ -void SafeString::appendChar(char c) -{ - if(len >= maxlen) - { - maxlen *= 2; // optimization - char* new_str = new char[maxlen]; - memset(new_str, 0, maxlen); - StringLib::copy(new_str, carray, len); - delete [] carray; - carray = new_str; - } - - carray[len-1] = c; - carray[len] = '\0'; - len++; -} - -/*---------------------------------------------------------------------------- - * findChar - *----------------------------------------------------------------------------*/ -int SafeString::findChar (char c, int start) -{ - if(start >= 0) - { - for(int i = start; i < len; i++) - { - if(carray[i] == c) - { - return i; - } - } - } - - return -1; -} - -/*---------------------------------------------------------------------------- - * setChar - *----------------------------------------------------------------------------*/ -SafeString& SafeString::setChar (char c, int index) -{ - if(index >= 0 && index < len) - { - carray[index] = c; - } - return *this; -} - -/*---------------------------------------------------------------------------- - * replace - * - * replaces all occurrences - *----------------------------------------------------------------------------*/ -bool SafeString::replace(const char* oldtxt, const char* newtxt) -{ - bool status = false; - - int newtxtlen = (int)strlen(newtxt); - char* startptr = strstr(carray, oldtxt); - char* endptr = startptr + strlen(oldtxt); - - while(startptr != NULL) - { - status = true; - - maxlen += newtxtlen; - char* newstr = new char[maxlen]; - memset(newstr, 0, maxlen); - - memcpy(newstr, carray, (startptr - carray)); - memcpy(newstr + (startptr - carray), newtxt, newtxtlen); - memcpy(newstr + (startptr - carray) + newtxtlen, endptr, len - (endptr - carray)); - - delete [] carray; - carray = newstr; - - len = (int)strlen(carray) + 1; - - startptr = strstr(carray, oldtxt); - endptr = startptr + strlen(oldtxt); - } - - return status; -} - -/*---------------------------------------------------------------------------- - * inreplace - * - * replaces all occurrences in place - *----------------------------------------------------------------------------*/ -bool SafeString::inreplace (const char* oldtxt[], const char* newtxt[], int num_replacements) -{ - /* Check Number of Replacements */ - if(num_replacements > MAX_REPLACEMENTS) - { - return false; - } - - /* Get Delta Sizes for each Replacement */ - int replacement_size_delta[MAX_REPLACEMENTS]; - for(int r = 0; r < num_replacements; r++) - { - replacement_size_delta[r] = strlen(newtxt[r]) - strlen(oldtxt[r]); - } - - /* Count Number of Replacements */ - int replacement_count[MAX_REPLACEMENTS]; - for(int r = 0; r < num_replacements; r++) - { - replacement_count[r] = 0; - int i = 0; - while(i < (len - 1)) - { - int j = i, k = 0; - while((j < (len - 1)) && oldtxt[r][k] && (carray[j] == oldtxt[r][k])) - { - j++; - k++; - } - - if(oldtxt[r][k] == '\0') - { - replacement_count[r]++; - i = j; - } - else - { - i++; - } - } - } - - /* Calculate Size of New String */ - int total_size_delta = 0; - for(int r = 0; r < num_replacements; r++) - { - total_size_delta += replacement_size_delta[r] * replacement_count[r]; - } - - /* Set New Size */ - int new_size = len + total_size_delta; - if(new_size > 0) - { - len = new_size; - maxlen = new_size; - } - else - { - len = 1; - maxlen = 1; - carray[0] = '\0'; - return true; - } - - /* Allocate New String */ - char* newstr = new char [maxlen]; - - /* Populate New String */ - int orig_i = 0, new_i = 0; - while(carray[orig_i]) - { - /* For Each Possible Replacement */ - bool replacement = false; - for(int r = 0; r < num_replacements; r++) - { - /* Check for Match */ - int j = orig_i, k = 0; - while(carray[j] && oldtxt[r][k] && (carray[j] == oldtxt[r][k])) - { - j++; - k++; - } - - /* Replace Matched Text */ - if(oldtxt[r][k] == '\0') - { - int i = 0; - while(newtxt[r][i]) - { - newstr[new_i++] = newtxt[r][i++]; - } - orig_i = j; - replacement = true; - break; - } - } - - /* Copy Over and Advance String Indices */ - if(!replacement) - { - newstr[new_i++] = carray[orig_i++]; - } - } - - /* Terminate New String and Replace Existing String */ - newstr[new_i] = '\0'; - delete [] carray; - carray = newstr; - - return true; -} - -/*---------------------------------------------------------------------------- - * urlize - * - * ! # $ & ' ( ) * + - * %21 %23 %24 %26 %27 %28 %29 %2A %2B - * - * , / : ; = ? @ [ ] - * %2C %2F %3A %3B %3D %3F %40 %5B %5D - *----------------------------------------------------------------------------*/ -SafeString& SafeString::urlize(void) -{ - /* Allocate enough room to hold urlized string */ - if(maxlen < (len * 3)) - { - maxlen = len * 3; - } - - /* Setup pointers to new and old strings */ - char* alloc_str = new char [maxlen]; - char* new_str = alloc_str; - char* old_str = carray; - - /* Translate old string into new string */ - while(*old_str != '\0') - { - switch (*old_str) - { - case '!': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '1'; break; - case '#': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '3'; break; - case '$': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '4'; break; - case '&': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '6'; break; - case '\'': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '7'; break; - case '(': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '8'; break; - case ')': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '9'; break; - case '*': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'A'; break; - case '+': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'B'; break; - case ',': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'C'; break; - case '/': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'F'; break; - case ':': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'A'; break; - case ';': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'B'; break; - case '=': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'D'; break; - case '?': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'F'; break; - case '@': *(new_str++) = '%'; *(new_str++) = '4'; *(new_str++) = '0'; break; - case '[': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'B'; break; - case ']': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'D'; break; - default: *(new_str++) = *old_str; break; - } - old_str++; - } - *(new_str++) = '\0'; - - /* Calculate length of new string */ - len = new_str - alloc_str; - - /* Replace member string */ - delete [] carray; - carray = alloc_str; - - /* Return Self */ - return *this; -} - -/*---------------------------------------------------------------------------- - * split - *----------------------------------------------------------------------------*/ -List* SafeString::split(char separator, bool strip) -{ - List* tokens = new List; - - char token[MAX_STR_SIZE]; - int i = 0; - - while(i < len && carray[i] != '\0') - { - /* Create Token */ - int t = 0; - while( (i < len) && (carray[i] != '\0') && (carray[i] == separator) ) i++; // find first character - while( (i < len) && (carray[i] != '\0') && (carray[i] != separator) && (t < (MAX_STR_SIZE - 1))) token[t++] = carray[i++]; // copy characters in - token[t++] = '\0'; - - /* Strip Leading and Trailing Spaces */ - int s1 = 0, s2 = t-1; - if(strip) - { - while( (s1 < t) && isspace(token[s1]) ) s1++; - while( (s2 > s1) && isspace(token[s2]) ) s2--; - token[++s2] = '\0'; - } - - /* Add Token to List */ - SafeString ss("%s", &token[s1]); - if(ss.length() > 0) tokens->add(ss); - } - - return tokens; -} - -/*---------------------------------------------------------------------------- - * operator[] - *----------------------------------------------------------------------------*/ -char SafeString::operator[](int index) -{ - if(index >= 0 && index < len) - { - return carray[index]; - } - else - { - return '\0'; - } -} - -/*---------------------------------------------------------------------------- - * operator+= - *----------------------------------------------------------------------------*/ -SafeString& SafeString::operator+=(const SafeString& rhs) -{ - if((len + rhs.len) < (maxlen - 1)) - { - StringLib::concat(carray, rhs.carray, maxlen); - len += rhs.len; - } - else - { - maxlen += rhs.maxlen; - char* new_str = new char[maxlen]; - memset(new_str, 0, maxlen); - StringLib::copy(new_str, carray, maxlen); - StringLib::concat(new_str, rhs.carray, maxlen); - len = (int)strlen(new_str) + 1; - delete [] carray; - carray = new_str; - } - - return *this; -} - -/*---------------------------------------------------------------------------- - * operator+= - *----------------------------------------------------------------------------*/ -SafeString& SafeString::operator+=(const char* rstr) -{ - int rlen = (int)strlen(rstr); - - if((len + rlen) < (maxlen - 1)) - { - StringLib::concat(carray, rstr, maxlen); - len += rlen; - } - else - { - maxlen += rlen + 1; - maxlen *= 2; // optimization - char* new_str = new char[maxlen]; - memset(new_str, 0, maxlen); - StringLib::copy(new_str, carray, maxlen); - StringLib::concat(new_str, rstr, maxlen); - len = (int)strlen(new_str) + 1; - delete [] carray; - carray = new_str; - } - - return *this; -} - -/*---------------------------------------------------------------------------- - * operator= - *----------------------------------------------------------------------------*/ -SafeString& SafeString::operator=(const SafeString& rhs) -{ - if(maxlen < rhs.len) - { - delete [] carray; - maxlen = rhs.maxlen; - carray = new char[maxlen]; - } - StringLib::copy(carray, rhs.carray, rhs.len); - len = rhs.len; - - return *this; + return carray; } /*---------------------------------------------------------------------------- - * operator= - *----------------------------------------------------------------------------*/ -SafeString& SafeString::operator=(const char* rstr) -{ - if(rstr) - { - int rlen = (int)strlen(rstr); - if(rlen <= 0) - { - carray[0] = '\0'; - len = 1; - } - else if(maxlen < rlen) - { - delete [] carray; - maxlen = rlen; - carray = new char[maxlen]; - } - - StringLib::copy(carray, rstr, rlen); - len = rlen + 1; - } - else - { - delete [] carray; - maxlen = DEFAULT_STR_SIZE; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = 1; - } - - return *this; -} - -/*---------------------------------------------------------------------------- - * operator+ + * length - number of non-null characters in string *----------------------------------------------------------------------------*/ -SafeString operator+(SafeString lhs, const SafeString& rhs) +long StringLib::FormattedString::length(void) const { - lhs += rhs; - return lhs; + return bufsize - 1; // remove null terminator in length } /*---------------------------------------------------------------------------- - * reset + * size - alias for length *----------------------------------------------------------------------------*/ -void SafeString::reset(void) +long StringLib::FormattedString::size(void) const { - delete [] carray; - maxlen = DEFAULT_STR_SIZE; - carray = new char[maxlen]; - memset(carray, 0, maxlen); - len = 1; + return length(); } - /****************************************************************************** * PUBLIC METHODS ******************************************************************************/ @@ -717,19 +223,19 @@ int StringLib::formats(char* dststr, int size, const char* _format, ...) /*---------------------------------------------------------------------------- * copy *----------------------------------------------------------------------------*/ -char* StringLib::copy(char* str1, const char* str2, int _size) +char* StringLib::copy(char* dst, const char* src, int _size) { - if(str1 && str2 && (_size > 0)) + if(dst && src && (_size > 0)) { - char* nptr = (char*)memccpy(str1, str2, 0, _size); - if(!nptr) str1[_size - 1] = '\0'; + char* nptr = (char*)memccpy(dst, src, 0, _size); + if(!nptr) dst[_size - 1] = '\0'; } - else if(str1 && (_size > 0)) + else if(dst && (_size > 0)) { - str1[0] = '\0'; + dst[0] = '\0'; } - return str1; + return dst; } /*---------------------------------------------------------------------------- @@ -761,10 +267,10 @@ char* StringLib::find(const char* big, const char* little, int len) * * assumes that str is null terminated *----------------------------------------------------------------------------*/ -char* StringLib::find(const char* str, const char c, bool first) +char* StringLib::find(const char* str, char c, bool first) { - if(first) return (char*)strchr(str, c); - else return (char*)strrchr(str, c); + if(first) return (char*)strchr(str, c); + return (char*)strrchr(str, c); } /*---------------------------------------------------------------------------- @@ -788,32 +294,37 @@ bool StringLib::match(const char* str1, const char* str2, int len) /*---------------------------------------------------------------------------- * split *----------------------------------------------------------------------------*/ -StringLib::TokenList* StringLib::split(const char* str, int len, char separator, bool strip) +List* StringLib::split(const char* str, int len, char separator, bool strip) { - TokenList* tokens = new TokenList; + List* tokens = new List; int i = 0; while(i < len && str[i] != '\0') { - /* Create Token */ - char* token = new char[MAX_STR_SIZE]; + char token[MAX_STR_SIZE]; int t = 0; + + /* Create Token */ while( (i < len) && (str[i] != '\0') && (str[i] == separator) ) i++; // find first character while( (i < len) && (str[i] != '\0') && (str[i] != separator) && (t < (MAX_STR_SIZE - 1))) token[t++] = str[i++]; // copy characters in token[t++] = '\0'; /* Strip Leading and Trailing Spaces */ - int s1 = 0, s2 = t-1; + int s1 = 0; if(strip) { + int s2 = t-1; while( (s1 < t) && isspace(token[s1]) ) s1++; while( (s2 > s1) && isspace(token[s2]) ) s2--; token[++s2] = '\0'; } /* Add Token to List */ - if(t > 1) tokens->add(token); - else delete [] token; + if(t > 1) + { + string* s = new string(&token[s1]); + tokens->add(s); + } } return tokens; @@ -904,7 +415,9 @@ char* StringLib::convertLower(char* dst, char* src) *----------------------------------------------------------------------------*/ int StringLib::tokenizeLine(const char* str1, int str_size, char separator, int numtokens, char tokens[][MAX_STR_SIZE]) { - int t = 0, i = 0, j = 0; + int t = 0; + int i = 0; + int j = 0; if(str1 == NULL || tokens == NULL) return 0; @@ -950,7 +463,8 @@ int StringLib::tokenizeLine(const char* str1, int str_size, char separator, int *----------------------------------------------------------------------------*/ int StringLib::getLine(char* str, int* ret_len, int max_str_size, FILE* fptr) { - int c = 0, i = 0; + int c = 0; + int i = 0; if (str == NULL || max_str_size < 1) return 0; @@ -968,7 +482,7 @@ int StringLib::getLine(char* str, int* ret_len, int max_str_size, FILE* fptr) } if (c != EOF) return 0; - else return -1; + return -1; } /*---------------------------------------------------------------------------- @@ -1100,10 +614,8 @@ char* StringLib::checkNullStr (const char* str) { return NULL; } - else - { - return (char*)str; - } + + return (char*)str; } /*---------------------------------------------------------------------------- @@ -1125,7 +637,8 @@ char* StringLib::b64encode(const void* data, int* size) str[encoded_len - 2] = '='; unsigned char *p = (unsigned char*) data; - size_t j = 0, pad = len % 3; + size_t j = 0; + size_t pad = len % 3; const size_t last = len - pad; for (size_t i = 0; i < last; i += 3) @@ -1164,9 +677,9 @@ unsigned char* StringLib::b64decode(const void* data, int* size) if (len == 0) return (unsigned char*)""; unsigned char *p = (unsigned char*) data; - size_t j = 0, - pad1 = len % 4 || p[len - 1] == '=', - pad2 = pad1 && (len % 4 > 2 || p[len - 2] != '='); + size_t j = 0; + size_t pad1 = len % 4 || p[len - 1] == '='; + size_t pad2 = pad1 && (len % 4 > 2 || p[len - 2] != '='); const size_t last = (len - pad1) / 4 << 2; int decoded_len = last / 4 * 3 + pad1 + pad2; @@ -1245,3 +758,209 @@ int StringLib::printify (char* buffer, int size) buffer[size - 1] = '\0'; return replacements; } + +/*---------------------------------------------------------------------------- + * replace + * + * replaces all occurrences of a character + *----------------------------------------------------------------------------*/ +int StringLib::replace(char* str, char oldchar, char newchar) +{ + int num_replacements = 0; + int len = strlen(str); + for(int i = 0; i < len; i++) + { + if(str[i] == oldchar) + { + str[i] = newchar; + num_replacements++; + } + } + return num_replacements; +} + +/*---------------------------------------------------------------------------- + * replace + * + * replaces all occurrences of a single substring + *----------------------------------------------------------------------------*/ +char* StringLib::replace(const char* str, const char* oldtxt, const char* newtxt) +{ + const char* oldtxt_array[1] = { oldtxt }; + const char* newtxt_array[1] = { newtxt }; + return StringLib::replace(str, oldtxt_array, newtxt_array, 1); +} + +/*---------------------------------------------------------------------------- + * replace + * + * replaces all occurrences of multiple substrings + *----------------------------------------------------------------------------*/ +char* StringLib::replace (const char* str, const char* oldtxt[], const char* newtxt[], int num_replacements) +{ + /* Initialize Return String */ + char* new_str = NULL; + + /* Get Size of String */ + int bytes = (int)strlen(str) + 1; + + /* Check Number of Replacements */ + if(num_replacements > MAX_NUM_REPLACEMENTS) + { + return new_str; + } + + /* Get Delta Sizes for each Replacement */ + int replacement_size_delta[MAX_NUM_REPLACEMENTS]; + for(int r = 0; r < num_replacements; r++) + { + replacement_size_delta[r] = strlen(newtxt[r]) - strlen(oldtxt[r]); + } + + /* Count Number of Replacements */ + int replacement_count[MAX_NUM_REPLACEMENTS]; + for(int r = 0; r < num_replacements; r++) + { + replacement_count[r] = 0; + int i = 0; + while(i < (bytes - 1)) + { + int j = i; + int k = 0; + while((j < (bytes - 1)) && oldtxt[r][k] && (str[j] == oldtxt[r][k])) + { + j++; + k++; + } + + if(oldtxt[r][k] == '\0') + { + replacement_count[r]++; + i = j; + } + else + { + i++; + } + } + } + + /* Calculate Size of New String */ + int total_size_delta = 0; + for(int r = 0; r < num_replacements; r++) + { + total_size_delta += replacement_size_delta[r] * replacement_count[r]; + } + + /* Set New Size */ + int new_size = bytes + total_size_delta; + + /* Check if String is Empty */ + if(new_size == 0) + { + new_str = new char [1]; + new_str[0] = '\0'; + return new_str; + } + + /* Allocate New String */ + new_str = new char [new_size]; + + /* Populate New String */ + int orig_i = 0; + int new_i = 0; + while(str[orig_i]) + { + /* For Each Possible Replacement */ + bool replacement = false; + for(int r = 0; r < num_replacements; r++) + { + /* Check for Match */ + int j = orig_i; + int k = 0; + while(str[j] && oldtxt[r][k] && (str[j] == oldtxt[r][k])) + { + j++; + k++; + } + + /* Replace Matched Text */ + if(oldtxt[r][k] == '\0') + { + int i = 0; + while(newtxt[r][i]) + { + new_str[new_i++] = newtxt[r][i++]; + } + orig_i = j; + replacement = true; + break; + } + } + + /* Copy Over and Advance String Indices */ + if(!replacement) + { + new_str[new_i++] = str[orig_i++]; + } + } + + /* Terminate New String */ + new_str[new_i] = '\0'; + + /* Return New String */ + return new_str; +} + +/*---------------------------------------------------------------------------- + * urlize + * + * ! # $ & ' ( ) * + + * %21 %23 %24 %26 %27 %28 %29 %2A %2B + * + * , / : ; = ? @ [ ] + * %2C %2F %3A %3B %3D %3F %40 %5B %5D + *----------------------------------------------------------------------------*/ +char* StringLib::urlize(const char* str) +{ + /* Get Size of Strings */ + int bytes = strlen(str) + 1; + int new_size = bytes * 3; + + /* Setup pointers to new and old strings */ + char* alloc_str = new char [new_size]; + char* new_str = alloc_str; + const char* old_str = str; + + /* Translate old string into new string */ + while(*old_str != '\0') + { + switch (*old_str) + { + case '!': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '1'; break; + case '#': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '3'; break; + case '$': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '4'; break; + case '&': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '6'; break; + case '\'': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '7'; break; + case '(': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '8'; break; + case ')': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '9'; break; + case '*': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'A'; break; + case '+': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'B'; break; + case ',': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'C'; break; + case '/': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'F'; break; + case ':': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'A'; break; + case ';': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'B'; break; + case '=': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'D'; break; + case '?': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'F'; break; + case '@': *(new_str++) = '%'; *(new_str++) = '4'; *(new_str++) = '0'; break; + case '[': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'B'; break; + case ']': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'D'; break; + default: *(new_str++) = *old_str; break; + } + old_str++; + } + *(new_str++) = '\0'; + + /* Return Self */ + return alloc_str; +} diff --git a/packages/core/StringLib.h b/packages/core/StringLib.h index d86405708..f77c8e851 100644 --- a/packages/core/StringLib.h +++ b/packages/core/StringLib.h @@ -47,53 +47,23 @@ class StringLib { public: - /*-------------------------------------------------------------------- - * String (subclass) - *--------------------------------------------------------------------*/ - - class String + class FormattedString { public: - static const long DEFAULT_STR_SIZE = 64; - static const int MAX_REPLACEMENTS = 16; - - String (long _maxlen=DEFAULT_STR_SIZE); - String (const char* _str, ...) VARG_CHECK(printf, 2, 3); - String (const String& other); - String (int base, unsigned char* buffer, int size); - ~String (void); - - const char* str (bool duplicate = false); - long length (void); - long bytes (void); - void appendChar (char c); - int findChar (char c, int start=0); - String& setChar (char c, int index); - bool replace (const char* oldtxt, const char* newtxt); - bool inreplace (const char* oldtxt[], const char* newtxt[], int num_replacements); - String& urlize (void); - List* split (char separator, bool strip=true); - char operator[] (int index); - String& operator+= (const String& rhs); - String& operator+= (const char* rstr); - String& operator= (const String& rhs); - String& operator= (const char* rstr); - void reset (void); + FormattedString (const char* _str, ...) VARG_CHECK(printf, 2, 3); + ~FormattedString (void); + + const char* c_str (bool duplicate = false); + long length (void) const; + long size (void) const; private: char* carray; - long len; - long maxlen; + long bufsize; }; - - /*-------------------------------------------------------------------- - * Typedefs - *--------------------------------------------------------------------*/ - - typedef MgList TokenList; - + /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ @@ -105,14 +75,14 @@ class StringLib static int formats (char* dststr, int size, const char* _format, ...) VARG_CHECK(printf, 3, 4); static char* copy (char* dst, const char* src, int _size); static char* find (const char* big, const char* little, int len=MAX_STR_SIZE); - static char* find (const char* str, const char c, bool first=true); + static char* find (const char* str, char c, bool first=true); static int size (const char* str, int len=MAX_STR_SIZE); static bool match (const char* str1, const char* str2, int len=MAX_STR_SIZE); - static TokenList* split (const char* str, int len, char separator, bool strip); + static List* split (const char* str, int len, char separator, bool strip=true); static void convertUpper (char* str); - static char* convertUpper (char* src, char* dst); + static char* convertUpper (char* dst, char* src); static void convertLower (char* str); - static char* convertLower (char* src, char* dst); + static char* convertLower (char* dst, char* src); static int tokenizeLine (const char* str, int str_size, char separator, int numtokens, char tokens[][MAX_STR_SIZE]); static int getLine (char* str, int* ret_len, int max_str_size, FILE* fptr); static bool str2bool (const char* str, bool* val); @@ -126,6 +96,10 @@ class StringLib static unsigned char* b64decode (const void* data, int* size); static char* b16encode (const void* data, int size, bool lower_case, char* dst=NULL); static int printify (char* buffer, int size); + static int replace (char* str, char oldchar, char newchar); + static char* replace (const char* str, const char* oldtxt, const char* newtxt); + static char* replace (const char* str, const char* oldtxt[], const char* newtxt[], int num_replacements); + static char* urlize (const char* str); private: @@ -133,6 +107,7 @@ class StringLib * Constants *--------------------------------------------------------------------*/ + static const int MAX_NUM_REPLACEMENTS = 16; static const char* B64CHARS; static const int B64INDEX[256]; }; @@ -141,7 +116,6 @@ class StringLib * Syntax Sugar *----------------------------------------------------------------------------*/ -typedef StringLib::String SafeString; -SafeString operator+ (SafeString lhs, const SafeString& rhs); +typedef StringLib::FormattedString FString; #endif /* __string_lib__ */ diff --git a/packages/core/Table.h b/packages/core/Table.h index 6b34973dd..d1756e894 100644 --- a/packages/core/Table.h +++ b/packages/core/Table.h @@ -76,7 +76,7 @@ class Table virtual ~Table (void); - bool add (K key, T& data, bool overwrite=false, bool with_delete=true); + bool add (K key, T& data, bool unique); T& get (K key, match_t match=MATCH_EXACTLY, bool resort=false); bool find (K key, match_t match, T* data, bool resort=false); bool remove (K key); @@ -115,35 +115,21 @@ class Table hash_func_t hash; node_t* table; K size; - K num_entries; - K oldest_entry; - K newest_entry; - K current_entry; - K open_entry; + K numEntries; + K oldestEntry; + K newestEntry; + K currentEntry; + K openEntry; /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ static K identity (K key); - bool writeNode (K index, K key, T& data); - bool overwriteNode (K index, K key, T& data, bool with_delete); + bool writeNode (K index, K key, const T& data); + bool overwriteNode (K index, K key, const T& data); void makeNewest (K index); - virtual void freeNode (K index); -}; - -/****************************************************************************** - * MANAGED TABLE TEMPLATE - ******************************************************************************/ - -template -class MgTable: public Table -{ - public: - MgTable (K table_size=Table::DEFAULT_TABLE_SIZE, typename Table::hash_func_t _hash=Table::identity); - ~MgTable (void); - private: - void freeNode (K index) override; + void freeNode (K index); }; /****************************************************************************** @@ -191,12 +177,12 @@ Table::~Table(void) * Note - mid-function returns *----------------------------------------------------------------------------*/ template -bool Table::add(K key, T& data, bool overwrite, bool with_delete) +bool Table::add(K key, T& data, bool unique) { K curr_index = hash(key) % size; /* Add Entry to Hash */ - if(table[curr_index].occupied == false) + if(!table[curr_index].occupied) { /* Remove Index from Open List */ K next_index = table[curr_index].next; @@ -205,7 +191,7 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) if(prev_index != (K)INVALID_KEY) table[prev_index].next = next_index; /* Update Open Entry if Collision on Head */ - if(open_entry == curr_index) open_entry = next_index; + if(openEntry == curr_index) openEntry = next_index; /* Populate Index */ writeNode(curr_index, key, data); @@ -215,8 +201,8 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) /* Check Current Slot for Duplicate */ if(table[curr_index].key == key) { - if(overwrite) return overwriteNode(curr_index, key, data, with_delete); - else return false; + if(!unique) return overwriteNode(curr_index, key, data); + return false; } /* Transverse to End of Chain */ @@ -227,8 +213,8 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) /* Check Slot for Duplicate */ if(table[scan_index].key == key) { - if(overwrite) return overwriteNode(scan_index, key, data, with_delete); - else return false; + if(!unique) return overwriteNode(scan_index, key, data); + return false; } /* Go To Next Slot */ @@ -237,7 +223,7 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) } /* Find First Open Hash Slot */ - K open_index = open_entry; + K open_index = openEntry; if(open_index == (K)INVALID_KEY) { /* Hash Full */ @@ -245,8 +231,8 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) } /* Move Open Entry to Next Open Index */ - open_entry = table[open_entry].next; - if(open_entry != (K)INVALID_KEY) table[open_entry].prev = (K)INVALID_KEY; + openEntry = table[openEntry].next; + if(openEntry != (K)INVALID_KEY) table[openEntry].prev = (K)INVALID_KEY; /* Insert Node */ if(table[curr_index].prev == (K)INVALID_KEY) /* End of Chain Insertion (chain == 1) */ @@ -274,17 +260,17 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) if(before_index != (K)INVALID_KEY) table[before_index].after = open_index; /* Update Oldest Entry */ - if(oldest_entry == curr_index) + if(oldestEntry == curr_index) { - oldest_entry = open_index; - table[oldest_entry].before = (K)INVALID_KEY; + oldestEntry = open_index; + table[oldestEntry].before = (K)INVALID_KEY; } /* Update Newest Entry */ - if(newest_entry == curr_index) + if(newestEntry == curr_index) { - newest_entry = open_index; - table[newest_entry].after = (K)INVALID_KEY; + newestEntry = open_index; + table[newestEntry].after = (K)INVALID_KEY; } /* Add Entry to Current Slot */ @@ -293,7 +279,7 @@ bool Table::add(K key, T& data, bool overwrite, bool with_delete) } /* New Entry Added */ - num_entries++; + numEntries++; /* Return Success */ return true; @@ -315,11 +301,11 @@ T& Table::get(K key, match_t match, bool resort) if(table[curr_index].key == key) { /* equivalent key is always nearest */ - best_delta = (K)0; best_index = curr_index; break; } - else if(match == MATCH_NEAREST_UNDER) + + if(match == MATCH_NEAREST_UNDER) { if(table[curr_index].key < key) { @@ -393,7 +379,7 @@ bool Table::remove(K key) /* Find Node to Remove */ while(curr_index != (K)INVALID_KEY) { - if(table[curr_index].occupied == false) /* end of chain */ + if(!table[curr_index].occupied) /* end of chain */ { curr_index = (K)INVALID_KEY; } @@ -423,8 +409,8 @@ bool Table::remove(K key) if(before_index != (K)INVALID_KEY) table[before_index].after = after_index; /* Update Newest and Oldest Entry */ - if(curr_index == newest_entry) newest_entry = before_index; - if(curr_index == oldest_entry) oldest_entry = after_index; + if(curr_index == newestEntry) newestEntry = before_index; + if(curr_index == oldestEntry) oldestEntry = after_index; /* Remove End of Chain */ K end_index = curr_index; @@ -452,8 +438,8 @@ bool Table::remove(K key) if(before_index != (K)INVALID_KEY) table[before_index].after = curr_index; /* Update Newest and Oldest Entry */ - if(end_index == newest_entry) newest_entry = curr_index; - if(end_index == oldest_entry) oldest_entry = curr_index; + if(end_index == newestEntry) newestEntry = curr_index; + if(end_index == oldestEntry) oldestEntry = curr_index; } /* Remove End of Chain */ @@ -466,11 +452,11 @@ bool Table::remove(K key) /* Add to Open List */ table[open_index].prev = (K)INVALID_KEY; - table[open_index].next = open_entry; - open_entry = open_index; + table[open_index].next = openEntry; + openEntry = open_index; /* Update Statistics */ - num_entries--; + numEntries--; /* Return Success */ return true; @@ -482,7 +468,7 @@ bool Table::remove(K key) template long Table::length(void) const { - return num_entries; + return numEntries; } /*---------------------------------------------------------------------------- @@ -491,7 +477,7 @@ long Table::length(void) const template bool Table::isfull(void) const { - return num_entries >= size; + return numEntries >= size; } /*---------------------------------------------------------------------------- @@ -504,7 +490,7 @@ void Table::clear(void) for(K i = 0; i < size; i++) { /* Free Data */ - if(table[i].occupied == true) + if(table[i].occupied) { freeNode(i); } @@ -519,13 +505,13 @@ void Table::clear(void) } /* Initialize Hash Attributes */ - num_entries = 0; - oldest_entry = (K)INVALID_KEY; - newest_entry = (K)INVALID_KEY; - current_entry = (K)INVALID_KEY; + numEntries = 0; + oldestEntry = (K)INVALID_KEY; + newestEntry = (K)INVALID_KEY; + currentEntry = (K)INVALID_KEY; /* Build Open List */ - open_entry = (K)0; + openEntry = (K)0; for(K i = 0; i < size; i++) { table[i].prev = i - 1; @@ -541,12 +527,12 @@ void Table::clear(void) template K Table::first(T* data) { - current_entry = oldest_entry; - if(current_entry != (K)INVALID_KEY) + currentEntry = oldestEntry; + if(currentEntry != (K)INVALID_KEY) { - assert(table[current_entry].occupied); - if(data) *data = table[current_entry].data; - return table[current_entry].key; + assert(table[currentEntry].occupied); + if(data) *data = table[currentEntry].data; + return table[currentEntry].key; } return (K)INVALID_KEY; @@ -558,14 +544,14 @@ K Table::first(T* data) template K Table::next(T* data) { - if(current_entry != (K)INVALID_KEY) + if(currentEntry != (K)INVALID_KEY) { - current_entry = table[current_entry].after; - if(current_entry != (K)INVALID_KEY) + currentEntry = table[currentEntry].after; + if(currentEntry != (K)INVALID_KEY) { - assert(table[current_entry].occupied); - if(data) *data = table[current_entry].data; - return table[current_entry].key; + assert(table[currentEntry].occupied); + if(data) *data = table[currentEntry].data; + return table[currentEntry].key; } } @@ -578,12 +564,12 @@ K Table::next(T* data) template K Table::last(T* data) { - current_entry = newest_entry; - if(current_entry != (K)INVALID_KEY) + currentEntry = newestEntry; + if(currentEntry != (K)INVALID_KEY) { - assert(table[current_entry].occupied); - if(data) *data = table[current_entry].data; - return table[current_entry].key; + assert(table[currentEntry].occupied); + if(data) *data = table[currentEntry].data; + return table[currentEntry].key; } return (K)INVALID_KEY; @@ -595,14 +581,14 @@ K Table::last(T* data) template K Table::prev(T* data) { - if(current_entry != (K)INVALID_KEY) + if(currentEntry != (K)INVALID_KEY) { - current_entry = table[current_entry].before; - if(current_entry != (K)INVALID_KEY) + currentEntry = table[currentEntry].before; + if(currentEntry != (K)INVALID_KEY) { - assert(table[current_entry].occupied); - if(data) *data = table[current_entry].data; - return table[current_entry].key; + assert(table[currentEntry].occupied); + if(data) *data = table[currentEntry].data; + return table[currentEntry].key; } } @@ -615,6 +601,12 @@ K Table::prev(T* data) template Table& Table::operator=(const Table& other) { + /* check for self assignment */ + if(this == &other) return *this; + + /* set hash function */ + hash = other.hash; + /* clear existing table */ clear(); // calls freeNode needed for managed tables delete [] table; @@ -664,7 +656,7 @@ K Table::identity(K key) * writeNode *----------------------------------------------------------------------------*/ template -bool Table::writeNode(K index, K key, T& data) +bool Table::writeNode(K index, K key, const T& data) { table[index].occupied = true; table[index].data = data; @@ -672,20 +664,20 @@ bool Table::writeNode(K index, K key, T& data) table[index].next = (K)INVALID_KEY; table[index].prev = (K)INVALID_KEY; table[index].after = (K)INVALID_KEY; - table[index].before = newest_entry; + table[index].before = newestEntry; /* Update Time Order */ - if(oldest_entry == (K)INVALID_KEY) + if(oldestEntry == (K)INVALID_KEY) { /* First Entry */ - oldest_entry = index; - newest_entry = index; + oldestEntry = index; + newestEntry = index; } else { /* Not First Entry */ - table[newest_entry].after = index; - newest_entry = index; + table[newestEntry].after = index; + newestEntry = index; } /* Return Success */ @@ -696,13 +688,10 @@ bool Table::writeNode(K index, K key, T& data) * overwriteNode *----------------------------------------------------------------------------*/ template -bool Table::overwriteNode(K index, K key, T& data, bool with_delete) +bool Table::overwriteNode(K index, K key, const T& data) { /* Delete Entry being Overritten (if requested) */ - if(with_delete) - { - freeNode(index); - } + freeNode(index); /* Set Data */ table[index].key = key; @@ -728,61 +717,34 @@ void Table::makeNewest(K index) if(after_index != (K)INVALID_KEY) table[after_index].before = before_index; /* Check if Overwriting Oldest/Newest */ - if(index == oldest_entry) oldest_entry = after_index; - if(index == newest_entry) newest_entry = before_index; + if(index == oldestEntry) oldestEntry = after_index; + if(index == newestEntry) newestEntry = before_index; /* Set Current Entry as Newest */ - K oldest_index = oldest_entry; - K newest_index = newest_entry; + K oldest_index = oldestEntry; + K newest_index = newestEntry; table[index].after = (K)INVALID_KEY; table[index].before = newest_index; - newest_entry = index; + newestEntry = index; /* Update Newest/Oldest */ if(newest_index != (K)INVALID_KEY) table[newest_index].after = index; - if(oldest_index == (K)INVALID_KEY) oldest_entry = index; + if(oldest_index == (K)INVALID_KEY) oldestEntry = index; } /*---------------------------------------------------------------------------- * freeNode *----------------------------------------------------------------------------*/ -template -void Table::freeNode(K index) -{ - (void)index; -} - -/****************************************************************************** - MANAGED ORDERING METHODS - ******************************************************************************/ - -/*---------------------------------------------------------------------------- - * Constructor - *----------------------------------------------------------------------------*/ -template -MgTable::MgTable(K table_size, typename Table::hash_func_t _hash): - Table(table_size, _hash) -{ -} +template +void tableDeleteIfPointer(const T& t) { (void)t; } -/*---------------------------------------------------------------------------- - * Destructor - *----------------------------------------------------------------------------*/ -template -MgTable::~MgTable(void) -{ - /* clearing table required to free nodes */ - Table::clear(); -} +template +void tableDeleteIfPointer(T* t) { delete t; } -/*---------------------------------------------------------------------------- - * freeNode - *----------------------------------------------------------------------------*/ -template -void MgTable::freeNode(K index) +template +void Table::freeNode(K index) { - if(!is_array) delete Table::table[index].data; - else delete [] Table::table[index].data; + tableDeleteIfPointer(table[index].data); } #endif /* __table__ */ diff --git a/packages/core/TcpSocket.cpp b/packages/core/TcpSocket.cpp index 363d43c11..0a36cd06f 100644 --- a/packages/core/TcpSocket.cpp +++ b/packages/core/TcpSocket.cpp @@ -161,10 +161,10 @@ TcpSocket::~TcpSocket(void) { /* Kill Listener... so it doesn't automatically reconnect */ alive = false; - if(connector) delete connector; - closeConnection(); - if(ip_addr) delete [] ip_addr; - if(config) delete [] config; + delete connector; + TcpSocket::closeConnection(); + delete [] ip_addr; + delete [] config; } /*---------------------------------------------------------------------------- @@ -173,9 +173,7 @@ TcpSocket::~TcpSocket(void) bool TcpSocket::isConnected(int num_connections) { (void)num_connections; - - if(sock < 0) return false; - else return true; + return (sock >= 0); } /*---------------------------------------------------------------------------- @@ -277,7 +275,7 @@ const char* TcpSocket::getConfig (void) /*---------------------------------------------------------------------------- * getIpAddr *----------------------------------------------------------------------------*/ -const char* TcpSocket::getIpAddr (void) +const char* TcpSocket::getIpAddr (void) const { return ip_addr; } @@ -285,7 +283,7 @@ const char* TcpSocket::getIpAddr (void) /*---------------------------------------------------------------------------- * getPort *----------------------------------------------------------------------------*/ -int TcpSocket::getPort (void) +int TcpSocket::getPort (void) const { return port; } @@ -299,7 +297,7 @@ int TcpSocket::getPort (void) *----------------------------------------------------------------------------*/ void* TcpSocket::connectionThread(void* parm) { - TcpSocket* socket = (TcpSocket*)parm; + TcpSocket* socket = static_cast(parm); socket->sock = INVALID_RC; bool connected_once = false; diff --git a/packages/core/TcpSocket.h b/packages/core/TcpSocket.h index c5f661489..71f42eb7c 100644 --- a/packages/core/TcpSocket.h +++ b/packages/core/TcpSocket.h @@ -64,8 +64,8 @@ class TcpSocket: public DeviceObject virtual int getUniqueId (void) override; virtual const char* getConfig (void) override; - const char* getIpAddr (void); - int getPort (void); + const char* getIpAddr (void) const; + int getPort (void) const; private: diff --git a/packages/core/TimeLib.cpp b/packages/core/TimeLib.cpp index 0cf00c813..6c4c12ec4 100644 --- a/packages/core/TimeLib.cpp +++ b/packages/core/TimeLib.cpp @@ -124,8 +124,8 @@ void TimeLib::init(void) *----------------------------------------------------------------------------*/ void TimeLib::deinit(void) { - if(heartBeat) delete heartBeat; - if(leapSeconds) delete [] leapSeconds; + delete heartBeat; + delete [] leapSeconds; } /*---------------------------------------------------------------------------- @@ -246,7 +246,7 @@ TimeLib::gmt_time_t TimeLib::cds2gmttime(int days, int msecs) gps_days += (int)(gps_msecs / TIME_MILLISECS_IN_A_DAY); gps_msecs = gps_msecs % TIME_MILLISECS_IN_A_DAY; } - else if(gps_msecs < 0) + else // if(gps_msecs < 0) { gps_days -= (int)(((-gps_msecs) / TIME_MILLISECS_IN_A_DAY) + 1); gps_msecs = TIME_MILLISECS_IN_A_DAY - ((-gps_msecs) % TIME_MILLISECS_IN_A_DAY); @@ -331,7 +331,9 @@ TimeLib::date_t TimeLib::gmt2date (const gmt_time_t& gmt_time) TimeLib::date_t date; /* Determine Month */ - int month = 1, day = 0, preceding_day = 0; + int month = 1; + int day = 0; + int preceding_day = 0; while(month <= MONTHS_IN_YEAR) { /* Accumulate Days */ @@ -599,23 +601,22 @@ int64_t TimeLib::str2gpstime (const char* time_str) } } - /* Check Success and Return GMT Structure */ - if(status == false) + /* Check for Failures */ + if(!status) { mlog(CRITICAL, "Unable to parse supplied time string: %s", time_str); return 0; } - else - { - gmt_time_t gmt_time; - gmt_time.year = year; - gmt_time.doy = doy; - gmt_time.hour = hour; - gmt_time.minute = minute; - gmt_time.second = (int)second; - gmt_time.millisecond = (int)(((long)(second * 1000))%1000); - return gmt2gpstime(gmt_time); - } + + /* Return GMT Structure */ + gmt_time_t gmt_time; + gmt_time.year = year; + gmt_time.doy = doy; + gmt_time.hour = hour; + gmt_time.minute = minute; + gmt_time.second = (int)second; + gmt_time.millisecond = (int)(((long)(second * 1000))%1000); + return gmt2gpstime(gmt_time); } /*---------------------------------------------------------------------------- @@ -694,10 +695,8 @@ const char* TimeLib::getmonthname (int month) { return MonthNames[month_index]; } - else - { - return NULL; - } + + return NULL; } @@ -804,11 +803,11 @@ void TimeLib::parsenistfile(void) List ntp_leap_seconds; /* Read contents of file and store in temporary array */ - SafeString leap_second_file_name; + string leap_second_file_name; leap_second_file_name += CONFDIR; - leap_second_file_name.appendChar(PATH_DELIMETER); + leap_second_file_name += PATH_DELIMETER_STR; leap_second_file_name += NIST_LIST_FILENAME; - FILE* fd = fopen( leap_second_file_name.str(), "r" ); + FILE* fd = fopen( leap_second_file_name.c_str(), "r" ); if( fd != NULL ) { char line[MAX_STR_SIZE]; diff --git a/packages/core/TimeLib.h b/packages/core/TimeLib.h index 274b92885..10f0ac92a 100644 --- a/packages/core/TimeLib.h +++ b/packages/core/TimeLib.h @@ -175,10 +175,10 @@ class TimeLib static void heartbeat (void); static void parsenistfile (void); - static inline int64_t GPS_TO_SYS (int64_t gpsnow) { return (((gpsnow) + 315964800000LL) * 1000); } // IN: milliseconds, OUT: microseconds - static inline int64_t SYS_TO_GPS (int64_t sysnow) { return (((sysnow) - 315964800000000LL) / 1000); } // IN: microseconds, OUT: milliseconds - static inline int64_t NTP_TO_SYS (int64_t ntpnow) { return (((ntpnow) - 2208988800LL)); } // IN: seconds, OUT: seconds - static inline double GPS_TO_SYS_EX (double gps_secs) { return (((gps_secs) + 315964800.0)); } // IN: seconds, OUT: seconds + static int64_t GPS_TO_SYS (int64_t gpsnow) { return (((gpsnow) + 315964800000LL) * 1000); } // IN: milliseconds, OUT: microseconds + static int64_t SYS_TO_GPS (int64_t sysnow) { return (((sysnow) - 315964800000000LL) / 1000); } // IN: microseconds, OUT: milliseconds + static int64_t NTP_TO_SYS (int64_t ntpnow) { return (((ntpnow) - 2208988800LL)); } // IN: seconds, OUT: seconds + static double GPS_TO_SYS_EX (double gps_secs) { return (((gps_secs) + 315964800.0)); } // IN: seconds, OUT: seconds }; #endif /* __time_lib__ */ diff --git a/packages/core/Uart.cpp b/packages/core/Uart.cpp index b8f540a48..b2dbce315 100644 --- a/packages/core/Uart.cpp +++ b/packages/core/Uart.cpp @@ -87,8 +87,8 @@ Uart::Uart (lua_State* L, const char* _device, int _baud, parity_t _parity): *----------------------------------------------------------------------------*/ Uart::~Uart (void) { - if(config) delete [] config; - closeConnection(); + delete [] config; + Uart::closeConnection(); } /*---------------------------------------------------------------------------- @@ -148,6 +148,6 @@ int Uart::getUniqueId (void) *----------------------------------------------------------------------------*/ const char* Uart::getConfig (void) { - if(config) return config; - else return "null"; + if(config) return config; + return "null"; } diff --git a/packages/core/UdpSocket.cpp b/packages/core/UdpSocket.cpp index be9cc46dd..c24d07f09 100644 --- a/packages/core/UdpSocket.cpp +++ b/packages/core/UdpSocket.cpp @@ -109,9 +109,9 @@ UdpSocket::UdpSocket(lua_State* L, const char* _ip_addr, int _port, bool _server *----------------------------------------------------------------------------*/ UdpSocket::~UdpSocket(void) { - closeConnection(); - if(ip_addr) delete [] ip_addr; - if(config) delete [] config; + UdpSocket::closeConnection(); + delete [] ip_addr; + delete [] config; } /*---------------------------------------------------------------------------- @@ -120,9 +120,7 @@ UdpSocket::~UdpSocket(void) bool UdpSocket::isConnected(int num_connections) { (void)num_connections; - - if(sock < 0) return false; - else return true; + return (sock >= 0); } /*---------------------------------------------------------------------------- @@ -171,7 +169,7 @@ const char* UdpSocket::getConfig (void) /*---------------------------------------------------------------------------- * getIpAddr *----------------------------------------------------------------------------*/ -const char* UdpSocket::getIpAddr (void) +const char* UdpSocket::getIpAddr (void) const { return ip_addr; } @@ -179,7 +177,7 @@ const char* UdpSocket::getIpAddr (void) /*---------------------------------------------------------------------------- * getPort *----------------------------------------------------------------------------*/ -int UdpSocket::getPort (void) +int UdpSocket::getPort (void) const { return port; } diff --git a/packages/core/UdpSocket.h b/packages/core/UdpSocket.h index 35288c9d9..033c46f24 100644 --- a/packages/core/UdpSocket.h +++ b/packages/core/UdpSocket.h @@ -63,8 +63,8 @@ class UdpSocket: public DeviceObject int getUniqueId (void) override; const char* getConfig (void) override; - const char* getIpAddr (void); - int getPort (void); + const char* getIpAddr (void) const; + int getPort (void) const; private: diff --git a/packages/core/core.cpp b/packages/core/core.cpp index edf76eeb2..135e87bc8 100644 --- a/packages/core/core.cpp +++ b/packages/core/core.cpp @@ -75,6 +75,7 @@ static int core_open (lua_State *L) {"getbyname", LuaObject::luaGetByName}, {"script", LuaScript::luaCreate}, {"monitor", Monitor::luaCreate}, + {"pmonitor", PublishMonitor::luaCreate}, {"cluster", ClusterSocket::luaCreate}, {"file", File::luaCreate}, {"tcp", TcpSocket::luaCreate}, @@ -171,7 +172,7 @@ void initcore (void) ContainerRecord::init(); /* Register IO Drivers */ - Asset::registerDriver(Asset::IODriver::FORMAT, Asset::IODriver::create); + Asset::registerDriver("nil", Asset::IODriver::create); Asset::registerDriver(FileIODriver::FORMAT, FileIODriver::create); /* Initialize Modules */ diff --git a/packages/core/core.h b/packages/core/core.h index 85e38d90b..0ad85250d 100644 --- a/packages/core/core.h +++ b/packages/core/core.h @@ -76,6 +76,7 @@ #include "MsgQ.h" #include "Ordering.h" #include "PublisherDispatch.h" +#include "PublishMonitor.h" #include "RecordObject.h" #include "RecordDispatcher.h" #include "ReportDispatch.h" diff --git a/packages/geo/GdalRaster.cpp b/packages/geo/GdalRaster.cpp index 15d95f7a3..58a245d42 100644 --- a/packages/geo/GdalRaster.cpp +++ b/packages/geo/GdalRaster.cpp @@ -209,15 +209,12 @@ RasterSubset* GdalRaster::subsetAOI(OGRPolygon* poly) * 'ulx uly lrx lry' for pixel extent */ - bool trace = false; - /* For debug tracing serialize all subset threads or debug messages will make no sense */ #define SUBSET_DEBUG_TRACE 0 #if SUBSET_DEBUG_TRACE static Mutex mutex; mutex.lock(); - trace = true; #warning Runing with serialized subsetAOI (very slow!!!) mlog(CRITICAL, "Runing with serialized subsetAOI (very slow!!!)"); #endif @@ -234,7 +231,7 @@ RasterSubset* GdalRaster::subsetAOI(OGRPolygon* poly) OGREnvelope env; poly->getEnvelope(&env); - if(trace) mlog(DEBUG, "geo aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", env.MinX, env.MinY, env.MaxX, env.MaxY); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "geo aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", env.MinX, env.MinY, env.MaxX, env.MaxY); /* Project AOI to map/raster coordinates */ if(!transf->Transform(1, &env.MinX, &env.MinY)) @@ -246,13 +243,13 @@ RasterSubset* GdalRaster::subsetAOI(OGRPolygon* poly) double aoi_maxx = std::max(env.MinX, env.MaxX); double aoi_miny = std::min(env.MinY, env.MaxY); double aoi_maxy = std::max(env.MinY, env.MaxY); - if(trace) mlog(DEBUG, "map aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", aoi_minx, aoi_miny, aoi_maxx, aoi_maxy); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "map aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", aoi_minx, aoi_miny, aoi_maxx, aoi_maxy); double raster_minx = bbox.lon_min; double raster_miny = bbox.lat_min; double raster_maxx = bbox.lon_max; double raster_maxy = bbox.lat_max; - if(trace) mlog(DEBUG, "map raster: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", raster_minx, raster_miny, raster_maxx, raster_maxy); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "map raster: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", raster_minx, raster_miny, raster_maxx, raster_maxy); /* * Check for AOI to be outside of raster bounds (no intersect at all) @@ -274,38 +271,42 @@ RasterSubset* GdalRaster::subsetAOI(OGRPolygon* poly) /* Adjust AOI to the raster */ if(aoi_minx < raster_minx) { - if(trace) mlog(DEBUG, "Clipped aoi_minx %.04lf to raster_minx %.04lf", aoi_minx, raster_minx); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "Clipped aoi_minx %.04lf to raster_minx %.04lf", aoi_minx, raster_minx); aoi_minx = raster_minx; } if(aoi_miny < raster_miny) { - if(trace) mlog(DEBUG, "Clipped aoi_miny %.04lf to raster_miny %.04lf", aoi_miny, raster_miny); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "Clipped aoi_miny %.04lf to raster_miny %.04lf", aoi_miny, raster_miny); aoi_miny = raster_miny; } if(aoi_maxx > raster_maxx) { - if(trace) mlog(DEBUG, "Clipped aoi_maxx %.04lf to raster_maxx %.04lf", aoi_maxx, raster_maxx); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "Clipped aoi_maxx %.04lf to raster_maxx %.04lf", aoi_maxx, raster_maxx); aoi_maxx = raster_maxx; } if(aoi_maxy > raster_maxy) { - if(trace) mlog(DEBUG, "Clipped aoi_maxy %.04lf to raster_maxy %.04lf", aoi_maxy, raster_maxy); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "Clipped aoi_maxy %.04lf to raster_maxy %.04lf", aoi_maxy, raster_maxy); aoi_maxy = raster_maxy; } - if(trace) mlog(DEBUG, "map aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", aoi_minx, aoi_miny, aoi_maxx, aoi_maxy); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "map aoi: (%13.04lf, %13.04lf) (%13.04lf, %13.04lf)", aoi_minx, aoi_miny, aoi_maxx, aoi_maxy); /* Get AOI pixel corners: upper left, lower right */ - int ulx, uly, lrx, lry; + int ulx; + int uly; + int lrx; + int lry; map2pixel(aoi_minx, aoi_maxy, ulx, uly); map2pixel(aoi_maxx, aoi_miny, lrx, lry); - if(trace) mlog(DEBUG, "pixel aoi: (%13d, %13d) (%13d, %13d)", ulx, uly, lrx, lry); + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "pixel aoi: (%13d, %13d) (%13d, %13d)", ulx, uly, lrx, lry); int64_t cols2read = lrx - ulx; int64_t rows2read = lry - uly; /* Sanity check for GCC optimizer 'bug'. Raster's top left corner pixel must be (0, 0) */ - int raster_ulx, raster_uly; + int raster_ulx; + int raster_uly; map2pixel(raster_minx, raster_maxy, raster_ulx, raster_uly); if(raster_ulx != 0 || raster_uly != 0) { @@ -357,7 +358,7 @@ RasterSubset* GdalRaster::subsetAOI(OGRPolygon* poly) throw RunTimeException(CRITICAL, RTE_ERROR, "RasterIO call failed: %d", err); } - if(trace) mlog(DEBUG, "read %ld bytes (%.1fMB), pixel_ulx: %d, pixel_uly: %d, map_ulx: %.2lf, map_uly: %.2lf, cols2read: %ld, rows2read: %ld, datatype %s\n", + if(SUBSET_DEBUG_TRACE) mlog(DEBUG, "read %ld bytes (%.1fMB), pixel_ulx: %d, pixel_uly: %d, map_ulx: %.2lf, map_uly: %.2lf, cols2read: %ld, rows2read: %ld, datatype %s\n", subset->size, (float)subset->size/(1024*1024), ulx, uly, subset->map_ulx, subset->map_uly, subset->cols, subset->rows, GDALGetDataTypeName(dtype)); } else @@ -473,7 +474,8 @@ void GdalRaster::readPixel(const OGRPoint* poi, RasterSample* sample) /* Use fast method recomended by GDAL docs to read individual pixel */ try { - int x, y; + int x; + int y; map2pixel(poi, x, y); // mlog(DEBUG, "%dP, %dL\n", x, y); @@ -608,8 +610,10 @@ void GdalRaster::resamplePixel(const OGRPoint* poi, RasterSample* sample) { try { - int windowSize, offset; - int x, y; + int windowSize; + int offset; + int x; + int y; map2pixel(poi, x, y); /* If zero radius provided, use defaul kernels for each sampling algorithm */ @@ -679,7 +683,8 @@ void GdalRaster::computeZonalStats(const OGRPoint* poi, RasterSample* sample) try { - int x, y; + int x; + int y; map2pixel(poi, x, y); int windowSize = radiusInPixels * 2 + 1; // Odd window size around pixel @@ -785,11 +790,11 @@ void GdalRaster::computeZonalStats(const OGRPoint* poi, RasterSample* sample) catch(const RunTimeException& e) { mlog(e.level(), "Error computing zonal stats: %s", e.what()); - if(samplesArray) delete[] samplesArray; + delete[] samplesArray; throw; } - if(samplesArray) delete[] samplesArray; + delete[] samplesArray; } /*---------------------------------------------------------------------------- @@ -846,7 +851,7 @@ void GdalRaster::createTransform(void) /* Limit to area of interest if AOI was set */ bbox_t* aoi = &parms->aoi_bbox; - bool useaoi = (aoi->lon_min == aoi->lon_max) || (aoi->lat_min == aoi->lat_max) ? false : true; + bool useaoi = !((aoi->lon_min == aoi->lon_max) || (aoi->lat_min == aoi->lat_max)); if(useaoi) { if(!options.SetAreaOfInterest(aoi->lon_min, aoi->lat_min, aoi->lon_max, aoi->lat_max)) @@ -868,7 +873,7 @@ void GdalRaster::createTransform(void) /*---------------------------------------------------------------------------- * radius2pixels *----------------------------------------------------------------------------*/ -int GdalRaster::radius2pixels(int _radius) +int GdalRaster::radius2pixels(int _radius) const { /* * Code supports only rasters with units in meters (cellSize and radius must be in meters). diff --git a/packages/geo/GdalRaster.h b/packages/geo/GdalRaster.h index 82efeb2ac..1a0719416 100644 --- a/packages/geo/GdalRaster.h +++ b/packages/geo/GdalRaster.h @@ -106,12 +106,12 @@ class GdalRaster void open (void); RasterSample* samplePOI (OGRPoint* poi); RasterSubset* subsetAOI (OGRPolygon* poly); - const std::string& getFileName (void) { return fileName;} - int getRows (void) { return ysize; } - int getCols (void) { return xsize; } - const bbox_t& getBbox (void) { return bbox; } - double getCellSize (void) { return cellSize; } - uint32_t getSSerror (void) { return ssError; } + const std::string& getFileName (void) const { return fileName;} + int getRows (void) const { return ysize; } + int getCols (void) const { return xsize; } + const bbox_t& getBbox (void) const { return bbox; } + double getCellSize (void) const { return cellSize; } + uint32_t getSSerror (void) const { return ssError; } /*-------------------------------------------------------------------- * Static Methods @@ -161,15 +161,15 @@ class GdalRaster void computeZonalStats (const OGRPoint* poi, RasterSample* sample); inline bool nodataCheck (RasterSample* sample); void createTransform (void); - int radius2pixels (int _radius); - inline bool containsWindow (int x, int y, int maxx, int maxy, int windowSize); + int radius2pixels (int _radius) const; + static inline bool containsWindow (int x, int y, int maxx, int maxy, int windowSize); inline void readRasterWithRetry (int x, int y, int xsize, int ysize, void* data, int dataXsize, int dataYsize, GDALRasterIOExtraArg* args); void map2pixel (double mapx, double mapy, int& x, int& y); void map2pixel (const OGRPoint* poi, int& x, int& y) { map2pixel(poi->getX(), poi->getY(), x, y); } void pixel2map (int x, int y, double& mapx, double& mapy); - bool s3sleep(void) {std::this_thread::sleep_for(std::chrono::milliseconds(50)); return true; } + static bool s3sleep(void) {std::this_thread::sleep_for(std::chrono::milliseconds(50)); return true; } }; #endif /* __gdal_raster__ */ diff --git a/packages/geo/GeoIndexedRaster.cpp b/packages/geo/GeoIndexedRaster.cpp index 03bf5e76c..7c3bd0d98 100644 --- a/packages/geo/GeoIndexedRaster.cpp +++ b/packages/geo/GeoIndexedRaster.cpp @@ -54,6 +54,37 @@ const char* GeoIndexedRaster::VALUE_TAG = "Value"; * PUBLIC METHODS ******************************************************************************/ +/*---------------------------------------------------------------------------- + * Reader Constructor + *----------------------------------------------------------------------------*/ +GeoIndexedRaster::Reader::Reader (GeoIndexedRaster* raster): + obj(raster), + geo(NULL), + entry(NULL), + sync(NUM_SYNC_SIGNALS), + run(true) +{ + thread = new Thread(GeoIndexedRaster::readingThread, this); +} + +/*---------------------------------------------------------------------------- + * Reader Destructor + *----------------------------------------------------------------------------*/ +GeoIndexedRaster::Reader::~Reader (void) +{ + sync.lock(); + { + run = false; /* Set run flag to false */ + sync.signal(DATA_TO_SAMPLE, Cond::NOTIFY_ONE); + } + sync.unlock(); + + delete thread; /* delete thread waits on thread to join */ + + /* geometry geo is cloned not 'newed' on GDAL heap. Use this call to free it */ + if(geo) OGR_G_DestroyGeometry(geo); +} + /*---------------------------------------------------------------------------- * init *----------------------------------------------------------------------------*/ @@ -85,7 +116,7 @@ uint32_t GeoIndexedRaster::getSamples(OGRGeometry* geo, int64_t gps, std::vector if(sample(geo, gps)) { /* Populate Return Vector of Samples (slist) */ - Ordering::Iterator iter(groupList); + GroupOrdering::Iterator iter(groupList); for(int i = 0; i < iter.length; i++) { const rasters_group_t* rgroup = iter[i].value; @@ -142,7 +173,7 @@ uint32_t GeoIndexedRaster::getSubsets(OGRGeometry* geo, int64_t gps, std::vector if(sample(geo, gps)) { /* Populate Return Vector of Subsets (slist) */ - Ordering::Iterator iter(groupList); + GroupOrdering::Iterator iter(groupList); for(int i = 0; i < iter.length; i++) { const rasters_group_t* rgroup = iter[i].value; @@ -164,29 +195,6 @@ uint32_t GeoIndexedRaster::getSubsets(OGRGeometry* geo, int64_t gps, std::vector *----------------------------------------------------------------------------*/ GeoIndexedRaster::~GeoIndexedRaster(void) { - /* Terminate all reader threads */ - List::Iterator reader_iter(readers); - for(int i = 0; i < reader_iter.length; i++) - { - reader_t* reader = readers[i]; - if(reader->thread != NULL) - { - reader->sync->lock(); - { - reader->run = false; /* Set run flag to false */ - reader->sync->signal(DATA_TO_SAMPLE, Cond::NOTIFY_ONE); - } - reader->sync->unlock(); - - delete reader->thread; /* delete thread waits on thread to join */ - delete reader->sync; - - /* geometry geo is cloned not 'newed' on GDAL heap. Use this call to free it */ - if(reader->geo) OGR_G_DestroyGeometry(reader->geo); - delete reader; - } - } - emptyFeaturesList(); } @@ -202,7 +210,9 @@ GeoIndexedRaster::GeoIndexedRaster(lua_State *L, GeoParms* _parms, GdalRaster::o cache (MAX_READER_THREADS), ssError (SS_NO_ERRORS), crscb (cb), - bbox {0, 0, 0, 0} + bbox {0, 0, 0, 0}, + rows (0), + cols (0) { /* Add Lua Functions */ LuaEngine::setAttrFunc(L, "dim", luaDimensions); @@ -303,7 +313,7 @@ uint32_t GeoIndexedRaster::getGroupFlags(const rasters_group_t* rgroup) *----------------------------------------------------------------------------*/ double GeoIndexedRaster::getGmtDate(const OGRFeature* feature, const char* field, TimeLib::gmt_time_t& gmtDate) { - bzero(&gmtDate, sizeof(TimeLib::gmt_time_t)); + memset(&gmtDate, 0, sizeof(TimeLib::gmt_time_t)); int i = feature->GetFieldIndex(field); if(i == -1) @@ -312,8 +322,13 @@ double GeoIndexedRaster::getGmtDate(const OGRFeature* feature, const char* field return 0; } - double gpstime = 0, seconds; - int year, month, day, hour, minute; + double gpstime = 0; + double seconds; + int year; + int month; + int day; + int hour; + int minute; /* * Raster's datetime in geojson index file should be properly formated GMT date time string in ISO8601 format. @@ -349,7 +364,7 @@ bool GeoIndexedRaster::openGeoIndex(const OGRGeometry* geo) getIndexFile(geo, newFile); /* Trying to open the same file? */ - if(!featuresList.isempty() && newFile == indexFile) + if(!featuresList.empty() && newFile == indexFile) return true; GDALDataset* dset = NULL; @@ -374,7 +389,7 @@ bool GeoIndexedRaster::openGeoIndex(const OGRGeometry* geo) while(OGRFeature* feature = layer->GetNextFeature()) { OGRFeature* fp = feature->Clone(); - featuresList.add(fp); + featuresList.push_back(fp); OGRFeature::DestroyFeature(feature); } @@ -397,7 +412,7 @@ bool GeoIndexedRaster::openGeoIndex(const OGRGeometry* geo) } GDALClose((GDALDatasetH)dset); - mlog(DEBUG, "Loaded %d index file features/rasters from: %s", featuresList.length(), newFile.c_str()); + mlog(DEBUG, "Loaded %lu index file features/rasters from: %s", featuresList.size(), newFile.c_str()); } catch (const RunTimeException &e) { @@ -428,15 +443,15 @@ void GeoIndexedRaster::sampleRasters(OGRGeometry* geo) while(key != NULL) { reader_t* reader = readers[i++]; - reader->sync->lock(); + reader->sync.lock(); { reader->entry = item; if(reader->geo) OGR_G_DestroyGeometry(reader->geo); reader->geo = geo->clone(); - reader->sync->signal(DATA_TO_SAMPLE, Cond::NOTIFY_ONE); + reader->sync.signal(DATA_TO_SAMPLE, Cond::NOTIFY_ONE); signaledReaders++; } - reader->sync->unlock(); + reader->sync.unlock(); key = cache.next(&item); } @@ -444,12 +459,12 @@ void GeoIndexedRaster::sampleRasters(OGRGeometry* geo) for(int j = 0; j < signaledReaders; j++) { reader_t* reader = readers[j]; - reader->sync->lock(); + reader->sync.lock(); { while(reader->entry != NULL) - reader->sync->wait(DATA_SAMPLED, SYS_TIMEOUT); + reader->sync.wait(DATA_SAMPLED, SYS_TIMEOUT); } - reader->sync->unlock(); + reader->sync.unlock(); } } @@ -486,9 +501,9 @@ bool GeoIndexedRaster::sample(OGRGeometry* geo, int64_t gps) *----------------------------------------------------------------------------*/ void GeoIndexedRaster::emptyFeaturesList(void) { - if(featuresList.isempty()) return; + if(featuresList.empty()) return; - for(int i = 0; i < featuresList.length(); i++) + for(unsigned i = 0; i < featuresList.size(); i++) { OGRFeature* feature = featuresList[i]; OGRFeature::DestroyFeature(feature); @@ -511,7 +526,7 @@ int GeoIndexedRaster::luaDimensions(lua_State *L) try { /* Get Self */ - GeoIndexedRaster *lua_obj = (GeoIndexedRaster *)getLuaSelf(L, 1); + GeoIndexedRaster *lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Return dimensions of index vector file */ lua_pushinteger(L, lua_obj->rows); @@ -541,7 +556,7 @@ int GeoIndexedRaster::luaBoundingBox(lua_State *L) try { /* Get Self */ - GeoIndexedRaster *lua_obj = (GeoIndexedRaster *)getLuaSelf(L, 1); + GeoIndexedRaster *lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Return bbox of index vector file */ lua_pushnumber(L, lua_obj->bbox.lon_min); @@ -600,13 +615,13 @@ void* GeoIndexedRaster::readingThread(void *param) while(reader->run) { - reader->sync->lock(); + reader->sync.lock(); { /* Wait for raster to work on */ while((reader->entry == NULL) && reader->run) - reader->sync->wait(DATA_TO_SAMPLE, SYS_TIMEOUT); + reader->sync.wait(DATA_TO_SAMPLE, SYS_TIMEOUT); } - reader->sync->unlock(); + reader->sync.unlock(); cacheitem_t* entry = reader->entry; if(entry != NULL) @@ -617,12 +632,12 @@ void* GeoIndexedRaster::readingThread(void *param) entry->subset = entry->raster->subsetAOI((OGRPolygon*)reader->geo); entry->enabled = false; /* raster samples/subsetted */ - reader->sync->lock(); + reader->sync.lock(); { reader->entry = NULL; /* Done with this raster */ - reader->sync->signal(DATA_SAMPLED, Cond::NOTIFY_ONE); + reader->sync.signal(DATA_SAMPLED, Cond::NOTIFY_ONE); } - reader->sync->unlock(); + reader->sync.unlock(); } } @@ -643,13 +658,7 @@ void GeoIndexedRaster::createThreads(void) for(int i = 0; i < newThreadsCnt; i++) { - reader_t* r = new reader_t; - r->obj = this; - r->geo = NULL; - r->entry = NULL; - r->run = true; - r->sync = new Cond(NUM_SYNC_SIGNALS); - r->thread = new Thread(readingThread, r); + Reader* r = new Reader(this); readers.add(r); } assert(readers.length() == threadsNeeded); @@ -661,7 +670,7 @@ void GeoIndexedRaster::createThreads(void) bool GeoIndexedRaster::updateCache(void) { /* Cache contains items/rasters from previous sample run */ - Ordering::Iterator group_iter(groupList); + GroupOrdering::Iterator group_iter(groupList); for(int i = 0; i < group_iter.length; i++) { const rasters_group_t* rgroup = group_iter[i].value; @@ -683,7 +692,8 @@ bool GeoIndexedRaster::updateCache(void) rinfo.dataIsElevation, crscb); item->sample = NULL; item->subset = NULL; - cache.add(key, item); + bool status = cache.add(key, item); + assert(status); (void)status; // cannot fail; prevents linter warnings } /* Mark as Enabled */ @@ -734,7 +744,7 @@ bool GeoIndexedRaster::filterRasters(int64_t gps) /* URL and temporal filter - remove the whole raster group if one of rasters needs to be filtered out */ if(parms->url_substring || parms->filter_time ) { - Ordering::Iterator group_iter(groupList); + GroupOrdering::Iterator group_iter(groupList); for(int i = 0; i < group_iter.length; i++) { const rasters_group_t* rgroup = group_iter[i].value; @@ -788,7 +798,7 @@ bool GeoIndexedRaster::filterRasters(int64_t gps) int64_t minDelta = abs(std::numeric_limits::max() - closestGps); /* Find raster group with the closest time */ - Ordering::Iterator group_iter(groupList); + GroupOrdering::Iterator group_iter(groupList); for(int i = 0; i < group_iter.length; i++) { const rasters_group_t* rgroup = group_iter[i].value; diff --git a/packages/geo/GeoIndexedRaster.h b/packages/geo/GeoIndexedRaster.h index 0429db419..5c121a25e 100644 --- a/packages/geo/GeoIndexedRaster.h +++ b/packages/geo/GeoIndexedRaster.h @@ -75,24 +75,25 @@ class GeoIndexedRaster: public RasterObject int64_t gpsTime; } rasters_group_t; - typedef struct cacheitem { + typedef struct CacheItem { bool enabled; RasterSample* sample; RasterSubset* subset; GdalRaster* raster; - ~cacheitem(void) {delete raster;} + ~CacheItem(void) {delete raster;} } cacheitem_t; - typedef struct { - GeoIndexedRaster* obj; - OGRGeometry* geo; - Thread* thread; - cacheitem_t* entry; - Cond* sync; - bool run; + typedef struct Reader { + GeoIndexedRaster* obj; + OGRGeometry* geo; + Thread* thread; + cacheitem_t* entry; + Cond sync; + bool run; + explicit Reader(GeoIndexedRaster* raster); + ~Reader(void); } reader_t; - /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ @@ -113,7 +114,7 @@ class GeoIndexedRaster: public RasterObject virtual void getGroupSamples (const rasters_group_t* rgroup, std::vector& slist, uint32_t flags); virtual void getGroupSubsets (const rasters_group_t* rgroup, std::vector& slist); uint32_t getGroupFlags (const rasters_group_t* rgroup); - double getGmtDate (const OGRFeature* feature, const char* field, TimeLib::gmt_time_t& gmtDate); + static double getGmtDate (const OGRFeature* feature, const char* field, TimeLib::gmt_time_t& gmtDate); virtual bool openGeoIndex (const OGRGeometry* geo); virtual void getIndexFile (const OGRGeometry* geo, std::string& file) = 0; virtual bool findRasters (const OGRGeometry* geo) = 0; @@ -121,16 +122,23 @@ class GeoIndexedRaster: public RasterObject bool sample (OGRGeometry* geo, int64_t gps); void emptyFeaturesList (void); + /*-------------------------------------------------------------------- + * Types + *--------------------------------------------------------------------*/ + + typedef Ordering GroupOrdering; + typedef Dictionary CacheDictionary; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - Mutex samplingMutex; - MgOrdering groupList; - MgDictionary cache; - List featuresList; - OGRPolygon geoIndexPoly; - uint32_t ssError; + Mutex samplingMutex; + GroupOrdering groupList; + CacheDictionary cache; + vector featuresList; + OGRPolygon geoIndexPoly; + uint32_t ssError; private: @@ -158,18 +166,15 @@ class GeoIndexedRaster: public RasterObject * Methods *--------------------------------------------------------------------*/ - static int luaDimensions(lua_State* L); - static int luaBoundingBox(lua_State* L); - static int luaCellSize(lua_State* L); + static int luaDimensions (lua_State* L); + static int luaBoundingBox (lua_State* L); + static int luaCellSize (lua_State* L); - static void* readingThread (void *param); + static void* readingThread (void *param); - void createThreads (void); - bool updateCache (void); - bool filterRasters (int64_t gps); + void createThreads (void); + bool updateCache (void); + bool filterRasters (int64_t gps); }; - - - #endif /* __geo_indexed_raster__ */ diff --git a/packages/geo/GeoJsonRaster.cpp b/packages/geo/GeoJsonRaster.cpp index cbb50d7aa..26393123c 100644 --- a/packages/geo/GeoJsonRaster.cpp +++ b/packages/geo/GeoJsonRaster.cpp @@ -106,10 +106,14 @@ bool GeoJsonRaster::includes(double lon, double lat, double height) getSamples(&poi, 0, slist); int sampleCnt = slist.size(); - if( sampleCnt == 0 ) return false; + if( sampleCnt == 0 ) return false; // no need to delete anything if( sampleCnt > 1 ) mlog(ERROR, "Multiple samples returned for lon: %.2lf, lat: %.2lf, using first sample", lon, lat); - return (static_cast(slist[0]->value) == RASTER_PIXEL_ON); + bool pixel_on = static_cast(slist[0]->value) == RASTER_PIXEL_ON; + + for(auto sample: slist) delete sample; + + return pixel_on; } /*---------------------------------------------------------------------------- diff --git a/packages/geo/GeoParms.cpp b/packages/geo/GeoParms.cpp index a61bdb903..f0fbe4447 100644 --- a/packages/geo/GeoParms.cpp +++ b/packages/geo/GeoParms.cpp @@ -69,8 +69,8 @@ const char* GeoParms::MODE_ALGO = "Mode"; const char* GeoParms::GAUSS_ALGO = "Gauss"; const char* GeoParms::OBJECT_TYPE = "GeoParms"; -const char* GeoParms::LuaMetaName = "GeoParms"; -const struct luaL_Reg GeoParms::LuaMetaTable[] = { +const char* GeoParms::LUA_META_NAME = "GeoParms"; +const struct luaL_Reg GeoParms::LUA_META_TABLE[] = { {"name", luaAssetName}, {"region", luaAssetRegion}, {"keyspace", luaSetKeySpace}, @@ -99,7 +99,7 @@ int GeoParms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -108,7 +108,7 @@ int GeoParms::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ GeoParms::GeoParms (lua_State* L, int index, bool asset_required): - LuaObject (L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject (L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), sampling_algo (GRIORA_NearestNeighbour), sampling_radius (0), zonal_stats (false), @@ -120,6 +120,7 @@ GeoParms::GeoParms (lua_State* L, int index, bool asset_required): proj_pipeline (NULL), aoi_bbox {0, 0, 0, 0}, catalog (NULL), + bands (8), asset_name (NULL), asset (NULL), key_space (0) @@ -261,7 +262,7 @@ GeoParms::GeoParms (lua_State* L, int index, bool asset_required): asset_name = StringLib::duplicate(LuaObject::getLuaString(L, -1, true, NULL)); if(asset_name) { - asset = (Asset*)LuaObject::getLuaObjectByName(asset_name, Asset::OBJECT_TYPE); + asset = dynamic_cast(LuaObject::getLuaObjectByName(asset_name, Asset::OBJECT_TYPE)); if(!asset && asset_required) throw RunTimeException(CRITICAL, RTE_ERROR, "Unable to find asset %s", asset_name); mlog(DEBUG, "Setting %s to %s", ASSET, asset_name); } @@ -289,7 +290,6 @@ GeoParms::~GeoParms (void) cleanup(); } - /*---------------------------------------------------------------------------- * cleanup *----------------------------------------------------------------------------*/ @@ -331,16 +331,16 @@ void GeoParms::cleanup (void) *----------------------------------------------------------------------------*/ GDALRIOResampleAlg GeoParms::str2algo (const char* str) { - if (!str) return GRIORA_NearestNeighbour; - else if (StringLib::match(str, NEARESTNEIGHBOUR_ALGO)) return GRIORA_NearestNeighbour; - else if (StringLib::match(str, BILINEAR_ALGO)) return GRIORA_Bilinear; - else if (StringLib::match(str, CUBIC_ALGO)) return GRIORA_Cubic; - else if (StringLib::match(str, CUBICSPLINE_ALGO)) return GRIORA_CubicSpline; - else if (StringLib::match(str, LANCZOS_ALGO)) return GRIORA_Lanczos; - else if (StringLib::match(str, AVERAGE_ALGO)) return GRIORA_Average; - else if (StringLib::match(str, MODE_ALGO)) return GRIORA_Mode; - else if (StringLib::match(str, GAUSS_ALGO)) return GRIORA_Gauss; - else throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid sampling algorithm: %s:", str); + if(!str) return GRIORA_NearestNeighbour; + if(StringLib::match(str, NEARESTNEIGHBOUR_ALGO)) return GRIORA_NearestNeighbour; + if(StringLib::match(str, BILINEAR_ALGO)) return GRIORA_Bilinear; + if(StringLib::match(str, CUBIC_ALGO)) return GRIORA_Cubic; + if(StringLib::match(str, CUBICSPLINE_ALGO)) return GRIORA_CubicSpline; + if(StringLib::match(str, LANCZOS_ALGO)) return GRIORA_Lanczos; + if(StringLib::match(str, AVERAGE_ALGO)) return GRIORA_Average; + if(StringLib::match(str, MODE_ALGO)) return GRIORA_Mode; + if(StringLib::match(str, GAUSS_ALGO)) return GRIORA_Gauss; + throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid sampling algorithm: %s:", str); } /*---------------------------------------------------------------------------- @@ -362,7 +362,7 @@ void GeoParms::getLuaBands (lua_State* L, int index, bool* provided) { /* Add band */ lua_rawgeti(L, index, i+1); - const char* band_str = StringLib::duplicate(LuaObject::getLuaString(L, -1)); + string band_str(LuaObject::getLuaString(L, -1)); bands.add(band_str); lua_pop(L, 1); } @@ -372,7 +372,7 @@ void GeoParms::getLuaBands (lua_State* L, int index, bool* provided) if(provided) *provided = true; /* Add band */ - const char* band_str = StringLib::duplicate(LuaObject::getLuaString(L, -1)); + string band_str(LuaObject::getLuaString(L, -1)); bands.add(band_str); } else if(!lua_isnil(L, index)) @@ -435,7 +435,7 @@ int GeoParms::luaAssetName (lua_State* L) { try { - GeoParms* lua_obj = (GeoParms*)getLuaSelf(L, 1); + GeoParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); if(lua_obj->asset_name) lua_pushstring(L, lua_obj->asset_name); else lua_pushnil(L); return 1; @@ -453,7 +453,7 @@ int GeoParms::luaAssetRegion (lua_State* L) { try { - GeoParms* lua_obj = (GeoParms*)getLuaSelf(L, 1); + GeoParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); if(lua_obj->asset) lua_pushstring(L, lua_obj->asset->getRegion()); else lua_pushnil(L); return 1; @@ -471,7 +471,7 @@ int GeoParms::luaSetKeySpace (lua_State* L) { try { - GeoParms* lua_obj = (GeoParms*)getLuaSelf(L, 1); + GeoParms* lua_obj = dynamic_cast(getLuaSelf(L, 1)); uint64_t key_space = (uint64_t)getLuaInteger(L, 2); lua_obj->key_space = key_space; diff --git a/packages/geo/GeoParms.h b/packages/geo/GeoParms.h index e7b2f4c66..74a58192e 100644 --- a/packages/geo/GeoParms.h +++ b/packages/geo/GeoParms.h @@ -102,14 +102,14 @@ class GeoParms: public LuaObject static const char* ZONALSTATS_ALGO; static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Typedefs *--------------------------------------------------------------------*/ - typedef MgList band_list_t; + typedef List band_list_t; typedef struct { double lon_min; @@ -155,14 +155,14 @@ class GeoParms: public LuaObject * Methods *--------------------------------------------------------------------*/ - void cleanup (void); - GDALRIOResampleAlg str2algo (const char* str); - void getLuaBands (lua_State* L, int index, bool* provided); - void getAoiBbox (lua_State* L, int index, bool* provided); + void cleanup (void); + static GDALRIOResampleAlg str2algo (const char* str); + void getLuaBands (lua_State* L, int index, bool* provided); + void getAoiBbox (lua_State* L, int index, bool* provided); - static int luaAssetName (lua_State* L); - static int luaAssetRegion (lua_State* L); - static int luaSetKeySpace (lua_State* L); + static int luaAssetName (lua_State* L); + static int luaAssetRegion (lua_State* L); + static int luaSetKeySpace (lua_State* L); }; #endif /* __geo_parms__ */ diff --git a/packages/geo/GeoRaster.cpp b/packages/geo/GeoRaster.cpp index 19a383473..60511b60c 100644 --- a/packages/geo/GeoRaster.cpp +++ b/packages/geo/GeoRaster.cpp @@ -139,7 +139,7 @@ int GeoRaster::luaDimensions(lua_State *L) try { /* Get Self */ - GeoRaster *lua_obj = (GeoRaster *)getLuaSelf(L, 1); + GeoRaster *lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Set Return Values */ lua_pushinteger(L, lua_obj->raster.getRows()); @@ -169,7 +169,7 @@ int GeoRaster::luaBoundingBox(lua_State *L) try { /* Get Self */ - GeoRaster *lua_obj = (GeoRaster *)getLuaSelf(L, 1); + GeoRaster *lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Set Return Values */ GdalRaster::bbox_t bbox = lua_obj->raster.getBbox(); @@ -202,7 +202,7 @@ int GeoRaster::luaCellSize(lua_State *L) try { /* Get Self */ - GeoRaster *lua_obj = (GeoRaster *)getLuaSelf(L, 1); + GeoRaster *lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Set Return Values */ lua_pushnumber(L, lua_obj->raster.getCellSize()); diff --git a/packages/geo/GeoRaster.h b/packages/geo/GeoRaster.h index 152569609..03a1bb99f 100644 --- a/packages/geo/GeoRaster.h +++ b/packages/geo/GeoRaster.h @@ -63,7 +63,7 @@ class GeoRaster: public RasterObject GeoRaster (lua_State* L, GeoParms* _parms, const std::string& _fileName, double _gpsTime, bool dataIsElevation, GdalRaster::overrideCRS_t cb=NULL); - const std::string getFileName(void) + std::string getFileName(void) { return raster.getFileName(); } diff --git a/packages/geo/GeoUserRaster.cpp b/packages/geo/GeoUserRaster.cpp index 0d893a576..a63145bb1 100644 --- a/packages/geo/GeoUserRaster.cpp +++ b/packages/geo/GeoUserRaster.cpp @@ -58,13 +58,16 @@ const char* GeoUserRaster::ELEVATION_KEY = "elevation"; *----------------------------------------------------------------------------*/ int GeoUserRaster::luaCreate (lua_State* L) { + GeoUserRaster* gur = NULL; try { - return createLuaObject(L, create(L, 1)); + gur = create( L, 1); + return createLuaObject(L, gur); } catch(const RunTimeException& e) { mlog(e.level(), "Error creating GeoUserRaster: %s", e.what()); + delete gur; return returnLuaStatus(L, false); } } @@ -120,6 +123,7 @@ GeoUserRaster* GeoUserRaster::create (lua_State* L, int index) GeoUserRaster::~GeoUserRaster(void) { VSIUnlink(rasterFileName.c_str()); + free(data); } /****************************************************************************** @@ -130,7 +134,8 @@ GeoUserRaster::~GeoUserRaster(void) * Constructor *----------------------------------------------------------------------------*/ GeoUserRaster::GeoUserRaster(lua_State *L, GeoParms* _parms, const char *file, long filelength, double gps, bool iselevation): - GeoRaster(L, _parms, std::string("/vsimem/userraster/" + GdalRaster::getUUID() + ".tif"), gps, iselevation ) + GeoRaster(L, _parms, std::string("/vsimem/userraster/" + GdalRaster::getUUID() + ".tif"), gps, iselevation ), + data(NULL) { if(file == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid file pointer (NULL)"); @@ -143,17 +148,17 @@ GeoUserRaster::GeoUserRaster(lua_State *L, GeoParms* _parms, const char *file, l rasterFileName = getFileName(); /* Make a copy of the raster data and pass the ownership to the VSIFile */ - GByte* data = (GByte*)malloc(filelength); + data = (GByte*)malloc(filelength); memcpy(data, file, filelength); /* Load user raster to vsimem */ - bool takeOwnership = true; + bool takeOwnership = false; VSILFILE* fp = VSIFileFromMemBuffer(rasterFileName.c_str(), data, (vsi_l_offset)filelength, takeOwnership); CHECKPTR(fp); VSIFCloseL(fp); } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating GeoJsonRaster: %s", e.what()); + mlog(e.level(), "Error creating GeoUserRaster: %s", e.what()); } } \ No newline at end of file diff --git a/packages/geo/GeoUserRaster.h b/packages/geo/GeoUserRaster.h index a5288a5c3..424fe6640 100644 --- a/packages/geo/GeoUserRaster.h +++ b/packages/geo/GeoUserRaster.h @@ -71,7 +71,7 @@ class GeoUserRaster: public GeoRaster * Methods *--------------------------------------------------------------------*/ - GeoUserRaster(lua_State* L, GeoParms* _parms, const char* image, long imagelength, double gps, bool iselevation); + GeoUserRaster(lua_State* L, GeoParms* _parms, const char* file, long filelength, double gps, bool iselevation); private: @@ -80,6 +80,7 @@ class GeoUserRaster: public GeoRaster *--------------------------------------------------------------------*/ std::string rasterFileName; + GByte* data; }; #endif /* __geouser_raster__ */ diff --git a/packages/geo/RasterObject.cpp b/packages/geo/RasterObject.cpp index ffffb8fc2..21462bf8e 100644 --- a/packages/geo/RasterObject.cpp +++ b/packages/geo/RasterObject.cpp @@ -50,8 +50,8 @@ ******************************************************************************/ const char* RasterObject::OBJECT_TYPE = "RasterObject"; -const char* RasterObject::LuaMetaName = "RasterObject"; -const struct luaL_Reg RasterObject::LuaMetaTable[] = { +const char* RasterObject::LUA_META_NAME = "RasterObject"; +const struct luaL_Reg RasterObject::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -85,22 +85,23 @@ int RasterObject::luaCreate( lua_State* L ) try { /* Get Parameters */ - _parms = (GeoParms*)getLuaObject(L, 1, GeoParms::OBJECT_TYPE); + _parms = dynamic_cast(getLuaObject(L, 1, GeoParms::OBJECT_TYPE)); if(_parms == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Failed to create GeoParms object"); /* Get Factory */ - factory_t _create = NULL; + factory_t factory; + bool found = false; factoryMut.lock(); { - factories.find(_parms->asset_name, &_create); + found = factories.find(_parms->asset_name, &factory); } factoryMut.unlock(); /* Check Factory */ - if(_create == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Failed to find registered raster for %s", _parms->asset_name); + if(!found) throw RunTimeException(CRITICAL, RTE_ERROR, "Failed to find registered raster for %s", _parms->asset_name); /* Create Raster */ - RasterObject* _raster = _create(L, _parms); + RasterObject* _raster = factory.create(L, _parms); if(_raster == NULL) throw RunTimeException(CRITICAL, RTE_ERROR, "Failed to create raster of type: %s", _parms->asset_name); /* Return Object */ @@ -109,7 +110,7 @@ int RasterObject::luaCreate( lua_State* L ) catch(const RunTimeException& e) { if(_parms) _parms->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -117,13 +118,14 @@ int RasterObject::luaCreate( lua_State* L ) /*---------------------------------------------------------------------------- * registerDriver *----------------------------------------------------------------------------*/ -bool RasterObject::registerRaster (const char* _name, factory_t create) +bool RasterObject::registerRaster (const char* _name, factory_f create) { bool status; factoryMut.lock(); { - status = factories.add(_name, create); + factory_t factory = { .create = create }; + status = factories.add(_name, factory); } factoryMut.unlock(); @@ -147,7 +149,7 @@ RasterObject::~RasterObject(void) * Constructor *----------------------------------------------------------------------------*/ RasterObject::RasterObject(lua_State *L, GeoParms* _parms): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), parms(_parms) { /* Add Lua Functions */ @@ -185,7 +187,7 @@ int RasterObject::luaSamples(lua_State *L) try { /* Get Self */ - lua_obj = (RasterObject*)getLuaSelf(L, 1); + lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Coordinates */ double lon = getLuaFloat(L, 2); @@ -216,7 +218,7 @@ int RasterObject::luaSamples(lua_State *L) num_ret++; /* Populate samples */ - if(listvalid && slist.size() > 0) + if(listvalid && !slist.empty()) { for(uint32_t i = 0; i < slist.size(); i++) { @@ -267,7 +269,7 @@ int RasterObject::luaSamples(lua_State *L) /* Free samples */ for (const RasterSample* sample : slist) - if (sample) delete sample; + delete sample; /* Return Errors and Table of Samples */ lua_pushinteger(L, err); @@ -289,7 +291,7 @@ int RasterObject::luaSubset(lua_State *L) try { /* Get Self */ - lua_obj = (RasterObject*)getLuaSelf(L, 1); + lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get extent */ double lon_min = getLuaFloat(L, 2); @@ -327,7 +329,7 @@ int RasterObject::luaSubset(lua_State *L) num_ret++; /* Populate subsets */ - if(listvalid && slist.size() > 0) + if(listvalid && !slist.empty()) { for(uint32_t i = 0; i < slist.size(); i++) { @@ -378,7 +380,7 @@ int RasterObject::luaSubset(lua_State *L) /* Free subsets */ for (const RasterSubset* subset : slist) - if (subset) delete subset; + delete subset; /* Return Errors and Table of Samples */ lua_pushinteger(L, err); diff --git a/packages/geo/RasterObject.h b/packages/geo/RasterObject.h index 9f0bc84e9..fda21b9c3 100644 --- a/packages/geo/RasterObject.h +++ b/packages/geo/RasterObject.h @@ -56,14 +56,18 @@ class RasterObject: public LuaObject *--------------------------------------------------------------------*/ static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Typedefs *--------------------------------------------------------------------*/ - typedef RasterObject* (*factory_t) (lua_State* L, GeoParms* _parms); + typedef RasterObject* (*factory_f) (lua_State* L, GeoParms* _parms); + + typedef struct { + factory_f create; + } factory_t; /*-------------------------------------------------------------------- * Methods @@ -72,7 +76,7 @@ class RasterObject: public LuaObject static void init (void); static void deinit (void); static int luaCreate (lua_State* L); - static bool registerRaster (const char* _name, factory_t create); + static bool registerRaster (const char* _name, factory_f create); virtual uint32_t getSamples (OGRGeometry* geo, int64_t gps, std::vector& slist, void* param=NULL) = 0; virtual uint32_t getSubsets (OGRGeometry* geo, int64_t gps, std::vector& slist, void* param=NULL) = 0; virtual ~RasterObject (void); diff --git a/packages/geo/RasterSampler.cpp b/packages/geo/RasterSampler.cpp index 507285819..91778b8f1 100644 --- a/packages/geo/RasterSampler.cpp +++ b/packages/geo/RasterSampler.cpp @@ -42,8 +42,8 @@ * STATIC DATA ******************************************************************************/ -const char* RasterSampler::LuaMetaName = "RasterSampler"; -const struct luaL_Reg RasterSampler::LuaMetaTable[] = { +const char* RasterSampler::LUA_META_NAME = "RasterSampler"; +const struct luaL_Reg RasterSampler::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -105,7 +105,7 @@ int RasterSampler::luaCreate (lua_State* L) try { /* Get Parameters */ - _raster = (RasterObject*)getLuaObject(L, 1, RasterObject::OBJECT_TYPE); + _raster = dynamic_cast(getLuaObject(L, 1, RasterObject::OBJECT_TYPE)); const char* raster_key = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); const char* rec_type = getLuaString(L, 4); @@ -121,7 +121,7 @@ int RasterSampler::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(_raster) _raster->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -156,7 +156,7 @@ RasterSampler::RasterSampler (lua_State* L, RasterObject* _raster, const char* r const char* outq_name, const char* rec_type, const char* index_key, const char* lon_key, const char* lat_key, const char* time_key, const char* height_key): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { assert(_raster); assert(outq_name); @@ -239,7 +239,7 @@ RasterSampler::~RasterSampler(void) { raster->releaseLuaObject(); delete outQ; - if(rasterKey) delete [] rasterKey; + delete [] rasterKey; } /*---------------------------------------------------------------------------- diff --git a/packages/geo/RasterSampler.h b/packages/geo/RasterSampler.h index 24d8cd227..9cf9bbf1f 100644 --- a/packages/geo/RasterSampler.h +++ b/packages/geo/RasterSampler.h @@ -56,8 +56,8 @@ class RasterSampler: public DispatchObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const char* rsSampleRecType; static const RecordObject::fieldDef_t rsSampleRecDef[]; diff --git a/packages/geo/RasterSubset.cpp b/packages/geo/RasterSubset.cpp index 2ccbc32d9..29a40a725 100644 --- a/packages/geo/RasterSubset.cpp +++ b/packages/geo/RasterSubset.cpp @@ -106,5 +106,5 @@ RasterSubset::~RasterSubset( void ) poolsize += size; } mutex.unlock(); - if(data) delete [] data; + delete [] data; } diff --git a/packages/geo/geo.cpp b/packages/geo/geo.cpp index 14db0d30a..adc329aaa 100644 --- a/packages/geo/geo.cpp +++ b/packages/geo/geo.cpp @@ -82,7 +82,8 @@ void test_projlib(void) PJ *G2P = proj_create_crs_to_crs_from_pj(C, G, P, A, options); /* Longitude and latitude of Copenhagen, in degrees. */ - double lon = 12.0, lat = 55.0; + double lon = 12.0; + double lat = 55.0; /* Prepare the input */ PJ_COORD c_in; diff --git a/packages/h5/H5Array.h b/packages/h5/H5Array.h index a447111d6..171cd9ae2 100644 --- a/packages/h5/H5Array.h +++ b/packages/h5/H5Array.h @@ -58,7 +58,7 @@ class H5Array virtual ~H5Array (void); bool trim (long offset); - T& operator[] (long index); + T& operator[] (long index) const; bool join (int timeout, bool throw_exception); /*-------------------------------------------------------------------- @@ -109,8 +109,8 @@ H5Array::H5Array(const Asset* asset, const char* resource, const char* datase template H5Array::~H5Array(void) { - if(h5f) delete h5f; - if(name) delete [] name; + delete h5f; + delete [] name; } /*---------------------------------------------------------------------------- @@ -125,10 +125,8 @@ bool H5Array::trim(long offset) size = size - offset; return true; } - else - { - return false; - } + + return false; } /*---------------------------------------------------------------------------- @@ -137,7 +135,7 @@ bool H5Array::trim(long offset) * Note: intentionally left unsafe for performance reasons *----------------------------------------------------------------------------*/ template -T& H5Array::operator[](long index) +T& H5Array::operator[](long index) const { return pointer[index]; } @@ -157,7 +155,15 @@ bool H5Array::join(int timeout, bool throw_exception) { status = true; size = h5f->info.elements; - data = (T*)h5f->info.data; + /* + * There is no way to do this in a portable "safe" way. The code + * below works because our target architectures are x86_64 and aarch64. + * The data pointed to by info.data is new'ed and therefore guaranteed + * to be aligned to a 16 byte boundary. The calling code is responsible + * for knowing what the data being read out of the h5 file is and + * providing the correct type to the template. + */ + data = reinterpret_cast(h5f->info.data); pointer = data; } else diff --git a/packages/h5/H5Coro.cpp b/packages/h5/H5Coro.cpp index 6bad94544..407d9d6bc 100644 --- a/packages/h5/H5Coro.cpp +++ b/packages/h5/H5Coro.cpp @@ -87,7 +87,7 @@ H5Future::H5Future (void) H5Future::~H5Future (void) { wait(IO_PEND); - if(info.data) delete [] info.data; + delete [] info.data; } /*---------------------------------------------------------------------------- @@ -104,8 +104,8 @@ H5Future::rc_t H5Future::wait (int timeout) sync.wait(0, timeout); } - if (!complete) rc = TIMEOUT; - else if (!valid) rc = INVALID; + if (!valid) rc = INVALID; + else if (!complete) rc = TIMEOUT; else rc = COMPLETE; } sync.unlock(); @@ -293,14 +293,14 @@ H5FileBuffer::H5FileBuffer (info_t* info, io_context_t* context, const Asset* as } /* Add Entry to Repository */ - metaRepo.add(meta_key, metaData, true); + metaRepo.add(meta_key, metaData, false); } metaMutex.unlock(); } catch(const RunTimeException& e) { /* Clean Up Data Allocations */ - if(info->data) delete [] info->data; + delete [] info->data; info->data= NULL; info->datasize = 0; @@ -326,15 +326,12 @@ H5FileBuffer::~H5FileBuffer (void) void H5FileBuffer::tearDown (void) { /* Close I/O Resources */ - if(ioDriver) - { - delete ioDriver; - } + delete ioDriver; /* Delete Local Context */ if(ioContextLocal) { - if(ioContext) delete ioContext; + delete ioContext; } /* Delete Dataset Strings */ @@ -342,8 +339,8 @@ void H5FileBuffer::tearDown (void) delete [] datasetPrint; /* Delete Chunk Buffer */ - if(dataChunkBuffer) delete [] dataChunkBuffer; - if(dataChunkFilterBuffer) delete [] dataChunkFilterBuffer; + delete [] dataChunkBuffer; + delete [] dataChunkFilterBuffer; } /*---------------------------------------------------------------------------- @@ -475,7 +472,7 @@ void H5FileBuffer::ioRequest (uint64_t* pos, int64_t size, uint8_t* buffer, int6 } /* Add Cache Entry */ - if(!cache->add(file_position, entry)) + if(!cache->add(file_position, entry, true)) { /* Free Previously Allocated Entry * should only fail to add if the cache line was @@ -626,7 +623,7 @@ void H5FileBuffer::readDataset (info_t* info) { throw RunTimeException(CRITICAL, RTE_ERROR, "missing data type information"); } - else if(metaData.ndims < 0) + if(metaData.ndims < 0) { throw RunTimeException(CRITICAL, RTE_ERROR, "missing data dimension information"); } @@ -713,7 +710,7 @@ void H5FileBuffer::readDataset (info_t* info) { throw RunTimeException(CRITICAL, RTE_ERROR, "data not allocated in contiguous layout"); } - else if(metaData.size != 0 && metaData.size < ((int64_t)buffer_offset + buffer_size)) + if(metaData.size != 0 && metaData.size < ((int64_t)buffer_offset + buffer_size)) { throw RunTimeException(CRITICAL, RTE_ERROR, "read exceeds available data: %ld != %ld", (long)metaData.size, (long)buffer_size); } @@ -745,7 +742,7 @@ void H5FileBuffer::readDataset (info_t* info) { throw RunTimeException(CRITICAL, RTE_ERROR, "chunk element size does not match data element size: %d != %d", metaData.elementsize, metaData.typesize); } - else if(metaData.chunkelements <= 0) + if(metaData.chunkelements == 0) { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid number of chunk elements: %ld", (long)metaData.chunkelements); } @@ -850,12 +847,12 @@ void H5FileBuffer::readDataset (info_t* info) { dimi[ci--] = 0; if(ci < 0) break; - else dimi[ci]++; + dimi[ci]++; } /* Check Exit Condition */ if(ci < 0) break; - else ci = FLAT_NDIMS - 1; + ci = FLAT_NDIMS - 1; } /* Replace Buffer */ @@ -1070,6 +1067,23 @@ int H5FileBuffer::readFractalHeap (msg_type_t msg_type, uint64_t pos, uint8_t hd print2term("Address of Root Block: 0x%lx\n", (unsigned long)root_blk_addr); print2term("Current # of Rows in Root Indirect Block: %lu\n", (unsigned long)curr_num_rows); } + else + { + (void)heap_obj_id_len; + (void)max_size_mg_obj; + (void)next_huge_obj_id; + (void)btree_addr_huge_obj; + (void)free_space_mg_blks; + (void)addr_free_space_mg; + (void)mg_space; + (void)alloc_mg_space; + (void)dblk_alloc_iter; + (void)huge_obj_size; + (void)huge_objs; + (void)tiny_obj_size; + (void)tiny_objs; + (void)start_num_rows; + } /* Read Filter Information */ if(io_filter_len > 0) @@ -1512,7 +1526,7 @@ int H5FileBuffer::readBTreeV1 (uint64_t pos, uint8_t* buffer, uint64_t buffer_si { throw RunTimeException(CRITICAL, RTE_ERROR, "no bytes of chunk data to read: %ld, %lu", (long)chunk_bytes, (unsigned long)chunk_index); } - else if((buffer_index + chunk_bytes) > buffer_size) + if((buffer_index + chunk_bytes) > buffer_size) { chunk_bytes = buffer_size - buffer_index; } @@ -1520,9 +1534,9 @@ int H5FileBuffer::readBTreeV1 (uint64_t pos, uint8_t* buffer, uint64_t buffer_si /* Display Info */ if(H5_VERBOSE && H5_EXTRA_DEBUG) { - print2term("Chunk Offset: %ld (%ld)\n", (unsigned long)chunk_offset, (unsigned long)(chunk_offset/metaData.typesize)); - print2term("Buffer Index: %ld (%ld)\n", (unsigned long)buffer_index, (unsigned long)(buffer_index/metaData.typesize)); - print2term("Chunk Bytes: %ld (%ld)\n", (unsigned long)chunk_bytes, (unsigned long)(chunk_bytes/metaData.typesize)); + print2term("Chunk Offset: %lu (%lu)\n", (unsigned long)chunk_offset, (unsigned long)(chunk_offset/metaData.typesize)); + print2term("Buffer Index: %lu (%lu)\n", (unsigned long)buffer_index, (unsigned long)(buffer_index/metaData.typesize)); + print2term("Chunk Bytes: %lu (%lu)\n", (unsigned long)chunk_bytes, (unsigned long)(chunk_bytes/metaData.typesize)); } /* Read Chunk */ @@ -1569,7 +1583,7 @@ int H5FileBuffer::readBTreeV1 (uint64_t pos, uint8_t* buffer, uint64_t buffer_si { throw RunTimeException(CRITICAL, RTE_ERROR, "shuffle filter unsupported on uncompressed chunk"); } - else if(dataChunkBufferSize != curr_node.chunk_size) + if(dataChunkBufferSize != curr_node.chunk_size) { throw RunTimeException(CRITICAL, RTE_ERROR, "mismatch in chunk size: %lu, %lu", (unsigned long)curr_node.chunk_size, (unsigned long)dataChunkBufferSize); } @@ -1613,7 +1627,7 @@ H5FileBuffer::btree_node_t H5FileBuffer::readBTreeNodeV1 (int ndims, uint64_t* p { throw RunTimeException(CRITICAL, RTE_ERROR, "key did not include a trailing zero: %lu", trailing_zero); } - else if(H5_VERBOSE && H5_EXTRA_DEBUG) + if(H5_VERBOSE && H5_EXTRA_DEBUG) { print2term("Trailing Zero: %d\n", (int)trailing_zero); } @@ -1697,7 +1711,7 @@ int H5FileBuffer::readSymbolTable (uint64_t pos, uint64_t heap_data_addr, int dl } /* Process Link */ - if(dlvl < datasetPath.length()) + if(dlvl < static_cast(datasetPath.size())) { if(StringLib::match((const char*)link_name, datasetPath[dlvl])) { @@ -2142,29 +2156,41 @@ int H5FileBuffer::readLinkInfoMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) /* Read Maximum Creation Index (number of elements in group) */ if(flags & MAX_CREATE_PRESENT_BIT) { - uint64_t max_create_index = readField(8, &pos); if(H5_VERBOSE) { + uint64_t max_create_index = readField(8, &pos); print2term("Maximum Creation Index: %lu\n", (unsigned long)max_create_index); } + else + { + pos += 8; + } } /* Read Heap and Name Offsets */ uint64_t heap_address = readField(metaData.offsetsize, &pos); - uint64_t name_index = readField(metaData.offsetsize, &pos); if(H5_VERBOSE) { + uint64_t name_index = readField(metaData.offsetsize, &pos); print2term("Heap Address: %lX\n", (unsigned long)heap_address); print2term("Name Index: %lX\n", (unsigned long)name_index); } + else + { + pos += metaData.offsetsize; + } if(flags & CREATE_ORDER_PRESENT_BIT) { - uint64_t create_order_index = readField(metaData.offsetsize, &pos); if(H5_VERBOSE) { + uint64_t create_order_index = readField(metaData.offsetsize, &pos); print2term("Creation Order Index: %lX\n", (unsigned long)create_order_index); } + else + { + pos += metaData.offsetsize; + } } /* Follow Heap Address if Provided */ @@ -2484,20 +2510,28 @@ int H5FileBuffer::readLinkMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) /* Read Creation Order */ if(flags & CREATE_ORDER_PRESENT_BIT) { - uint64_t create_order = readField(8, &pos); if(H5_VERBOSE) { + uint64_t create_order = readField(8, &pos); print2term("Creation Order: %lX\n", (unsigned long)create_order); } + else + { + pos += 8; + } } /* Read Character Set */ if(flags & CHAR_SET_PRESENT_BIT) { - uint8_t char_set = readField(1, &pos); if(H5_VERBOSE) { - print2term("Character Set: %lu\n", (unsigned long)char_set); + uint8_t char_set = readField(1, &pos); + print2term("Character Set: %lu\n", (unsigned long)char_set); + } + else + { + pos += 1; } } @@ -2531,7 +2565,7 @@ int H5FileBuffer::readLinkMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) print2term("Hard Link - Object Header Address: 0x%lx\n", object_header_addr); } - if(dlvl < datasetPath.length()) + if(dlvl < static_cast(datasetPath.size())) { if(StringLib::match((const char*)link_name, datasetPath[dlvl])) { @@ -2808,7 +2842,7 @@ int H5FileBuffer::readAttributeMsg (uint64_t pos, uint8_t hdr_flags, int dlvl, u { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid attribute version: %d", (int)version); } - else if(reserved0 != 0) + if(reserved0 != 0) { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid reserved field: %d", (int)reserved0); } @@ -2859,15 +2893,13 @@ int H5FileBuffer::readAttributeMsg (uint64_t pos, uint8_t hdr_flags, int dlvl, u } /* Shortcut Out if Not Desired Attribute */ - if( ((dlvl + 1) != datasetPath.length()) || + if( ((dlvl + 1) != static_cast(datasetPath.size())) || !StringLib::match((const char*)attr_name, datasetPath[dlvl]) ) { return size; } - else - { - highestDataLevel = dlvl + 1; - } + + highestDataLevel = dlvl + 1; /* Read Datatype Message */ int datatype_bytes_read = readDatatypeMsg(pos, hdr_flags, dlvl); @@ -2875,11 +2907,9 @@ int H5FileBuffer::readAttributeMsg (uint64_t pos, uint8_t hdr_flags, int dlvl, u { throw RunTimeException(CRITICAL, RTE_ERROR, "failed to read expected bytes for datatype message: %d > %d\n", (int)datatype_bytes_read, (int)datatype_size); } - else - { - pos += datatype_bytes_read; - pos += (8 - (datatype_bytes_read % 8)) % 8; // align to next 8-byte boundary - } + + pos += datatype_bytes_read; + pos += (8 - (datatype_bytes_read % 8)) % 8; // align to next 8-byte boundary /* Read Dataspace Message */ int dataspace_bytes_read = readDataspaceMsg(pos, hdr_flags, dlvl); @@ -2887,11 +2917,9 @@ int H5FileBuffer::readAttributeMsg (uint64_t pos, uint8_t hdr_flags, int dlvl, u { throw RunTimeException(CRITICAL, RTE_ERROR, "failed to read expected bytes for dataspace message: %d > %d\n", (int)dataspace_bytes_read, (int)dataspace_size); } - else - { - pos += dataspace_bytes_read; - pos += (8 - (dataspace_bytes_read % 8)) % 8; // align to next 8-byte boundary - } + + pos += dataspace_bytes_read; + pos += (8 - (dataspace_bytes_read % 8)) % 8; // align to next 8-byte boundary /* Calculate Meta Data */ metaData.layout = CONTIGUOUS_LAYOUT; @@ -2938,29 +2966,41 @@ int H5FileBuffer::readAttributeInfoMsg (uint64_t pos, uint8_t hdr_flags, int dlv /* Read Maximum Creation Index (number of elements in group) */ if(flags & MAX_CREATE_PRESENT_BIT) { - uint16_t max_create_index = readField(2, &pos); if(H5_VERBOSE) { + uint16_t max_create_index = readField(2, &pos); print2term("Maximum Creation Index: %u\n", (unsigned short)max_create_index); } + else + { + pos += 2; + } } /* Read Heap and Name Offsets */ uint64_t heap_address = readField(metaData.offsetsize, &pos); - uint64_t name_index = readField(metaData.offsetsize, &pos); if(H5_VERBOSE) { + uint64_t name_index = readField(metaData.offsetsize, &pos); print2term("Heap Address: %lX\n", (unsigned long)heap_address); print2term("Name Index: %lX\n", (unsigned long)name_index); } + else + { + pos += metaData.offsetsize; + } if(flags & CREATE_ORDER_PRESENT_BIT) { - uint64_t create_order_index = readField(metaData.offsetsize, &pos); if(H5_VERBOSE) { + uint64_t create_order_index = readField(metaData.offsetsize, &pos); print2term("Creation Order Index: %lX\n", (unsigned long)create_order_index); } + else + { + pos += metaData.offsetsize; + } } /* Follow Heap Address if Provided */ @@ -3109,11 +3149,9 @@ int H5FileBuffer::readSymbolTableMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) { break; } - else - { - pos += 2 + (2 * metaData.offsetsize) + metaData.lengthsize; // skip entries used, sibling addresses, and first key - pos = readField(metaData.offsetsize, &pos); // read and go to first child - } + + pos += 2 + (2 * metaData.offsetsize) + metaData.lengthsize; // skip entries used, sibling addresses, and first key + pos = readField(metaData.offsetsize, &pos); // read and go to first child } /* Traverse Children Left to Right */ @@ -3128,7 +3166,7 @@ int H5FileBuffer::readSymbolTableMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) print2term("Entries Used: %d\n", (int)entries_used); print2term("Left Sibling: 0x%lx\n", (unsigned long)left_sibling); print2term("Right Sibling: 0x%lx\n", (unsigned long)right_sibling); - print2term("First Key: %ld\n", (unsigned long)key0); + print2term("First Key: %lu\n", (unsigned long)key0); } /* Loop Through Entries in Current Node */ @@ -3145,10 +3183,7 @@ int H5FileBuffer::readSymbolTableMsg (uint64_t pos, uint8_t hdr_flags, int dlvl) { break; } - else - { - pos = right_sibling; - } + pos = right_sibling; /* Read Header Info */ if(!H5_ERROR_CHECKING) @@ -3196,7 +3231,7 @@ void H5FileBuffer::parseDataset (void) /* Build Path to Dataset */ while(true) { - datasetPath.add(gptr); // add group to dataset path + datasetPath.push_back(gptr); // add group to dataset path char* nptr = StringLib::find(gptr, '/'); // look for next group marker if(nptr == NULL) break; // if not found, then exit *nptr = '\0'; // terminate group string @@ -3207,7 +3242,7 @@ void H5FileBuffer::parseDataset (void) { print2term("\n----------------\n"); print2term("Dataset: "); - for(int g = 0; g < datasetPath.length(); g++) + for(unsigned g = 0; g < datasetPath.size(); g++) { print2term("/%s", datasetPath[g]); } @@ -3311,7 +3346,7 @@ int H5FileBuffer::inflateChunk (uint8_t* input, uint32_t input_size, uint8_t* ou /*---------------------------------------------------------------------------- * shuffleChunk *----------------------------------------------------------------------------*/ -int H5FileBuffer::shuffleChunk (uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_offset, uint32_t output_size, int type_size) +int H5FileBuffer::shuffleChunk (const uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_offset, uint32_t output_size, int type_size) { if(H5_ERROR_CHECKING) { @@ -3434,11 +3469,11 @@ void H5Coro::deinit (void) { delete readerPids[t]; } - if(readerPids) delete [] readerPids; - if(rqstSub) delete rqstSub; + delete [] readerPids; + delete rqstSub; } - if(rqstPub) delete rqstPub; + delete rqstPub; } /*---------------------------------------------------------------------------- @@ -3663,7 +3698,7 @@ bool H5Coro::traverse (const Asset* asset, const char* resource, int max_depth, H5FileBuffer h5file(&data_info, NULL, asset, resource, start_group, 0, 0); /* Free Data */ - if(data_info.data) delete [] data_info.data; + delete [] data_info.data; } catch (const RunTimeException& e) { @@ -3702,10 +3737,8 @@ H5Future* H5Coro::readp (const Asset* asset, const char* resource, const char* d delete rqst.h5f; return NULL; } - else - { - return rqst.h5f; - } + + return rqst.h5f; } /*---------------------------------------------------------------------------- diff --git a/packages/h5/H5Coro.h b/packages/h5/H5Coro.h index cdeda7d25..a82d10003 100644 --- a/packages/h5/H5Coro.h +++ b/packages/h5/H5Coro.h @@ -326,7 +326,7 @@ class H5FileBuffer void tearDown (void); void ioRequest (uint64_t* pos, int64_t size, uint8_t* buffer, int64_t hint, bool cache); - bool ioCheckCache (uint64_t pos, int64_t size, cache_t* cache, uint64_t line_mask, cache_entry_t* entry); + static bool ioCheckCache (uint64_t pos, int64_t size, cache_t* cache, uint64_t line_mask, cache_entry_t* entry); static uint64_t ioHashL1 (uint64_t key); static uint64_t ioHashL2 (uint64_t key); @@ -361,11 +361,11 @@ class H5FileBuffer int readAttributeInfoMsg (uint64_t pos, uint8_t hdr_flags, int dlvl); void parseDataset (void); - const char* type2str (data_type_t datatype); - const char* layout2str (layout_t layout); - int highestBit (uint64_t value); - int inflateChunk (uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_size); - int shuffleChunk (uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_offset, uint32_t output_size, int type_size); + static const char* type2str (data_type_t datatype); + static const char* layout2str (layout_t layout); + static int highestBit (uint64_t value); + static int inflateChunk (uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_size); + static int shuffleChunk (const uint8_t* input, uint32_t input_size, uint8_t* output, uint32_t output_offset, uint32_t output_size, int type_size); static uint64_t metaGetKey (const char* url); static void metaGetUrl (char* url, const char* resource, const char* dataset); @@ -381,7 +381,7 @@ class H5FileBuffer /* Class Data */ const char* datasetName; // holds buffer of dataset name that datasetPath points back into const char* datasetPrint; // holds untouched dataset name string used for displaying the name - List datasetPath; + vector datasetPath; uint64_t datasetStartRow; int datasetNumRows; bool errorChecking; diff --git a/packages/h5/H5DArray.cpp b/packages/h5/H5DArray.cpp index 3a730cf41..98b227379 100644 --- a/packages/h5/H5DArray.cpp +++ b/packages/h5/H5DArray.cpp @@ -63,14 +63,14 @@ H5DArray::H5DArray(const Asset* asset, const char* resource, const char* dataset *----------------------------------------------------------------------------*/ H5DArray::~H5DArray(void) { - if(h5f) delete h5f; - if(name) delete [] name; + delete h5f; + delete [] name; } /*---------------------------------------------------------------------------- * join *----------------------------------------------------------------------------*/ -bool H5DArray::join(int timeout, bool throw_exception) +bool H5DArray::join(int timeout, bool throw_exception) const { bool status; @@ -110,7 +110,7 @@ bool H5DArray::join(int timeout, bool throw_exception) /*---------------------------------------------------------------------------- * numElements *----------------------------------------------------------------------------*/ -int H5DArray::numElements (void) +int H5DArray::numElements (void) const { return h5f->info.elements; } @@ -118,7 +118,7 @@ int H5DArray::numElements (void) /*---------------------------------------------------------------------------- * elementSize *----------------------------------------------------------------------------*/ -int H5DArray::elementSize (void) +int H5DArray::elementSize (void) const { return h5f->info.typesize; } @@ -126,7 +126,7 @@ int H5DArray::elementSize (void) /*---------------------------------------------------------------------------- * elementType *----------------------------------------------------------------------------*/ -H5DArray::type_t H5DArray::elementType (void) +H5DArray::type_t H5DArray::elementType (void) const { return h5f->info.datatype; } @@ -134,7 +134,7 @@ H5DArray::type_t H5DArray::elementType (void) /*---------------------------------------------------------------------------- * serialize *----------------------------------------------------------------------------*/ -uint64_t H5DArray::serialize (uint8_t* buffer, int32_t start_element, uint32_t num_elements) +uint64_t H5DArray::serialize (uint8_t* buffer, int32_t start_element, uint32_t num_elements) const { /* Serialize Elements of Array */ if(h5f->info.typesize == 8) diff --git a/packages/h5/H5DArray.h b/packages/h5/H5DArray.h index 8dda3de63..49a1a5638 100644 --- a/packages/h5/H5DArray.h +++ b/packages/h5/H5DArray.h @@ -63,12 +63,12 @@ class H5DArray H5DArray (const Asset* asset, const char* resource, const char* dataset, H5Coro::context_t* context=NULL, long col=0, long startrow=0, long numrows=H5Coro::ALL_ROWS); virtual ~H5DArray (void); - bool join (int timeout, bool throw_exception); + bool join (int timeout, bool throw_exception) const; - int numElements (void); - int elementSize (void); - type_t elementType (void); - uint64_t serialize (uint8_t* buffer, int32_t start_element, uint32_t num_elements); + int numElements (void) const; + int elementSize (void) const; + type_t elementType (void) const; + uint64_t serialize (uint8_t* buffer, int32_t start_element, uint32_t num_elements) const; /*-------------------------------------------------------------------- * Data diff --git a/packages/h5/H5DatasetDevice.cpp b/packages/h5/H5DatasetDevice.cpp index 3022ab88d..416f3fcfe 100644 --- a/packages/h5/H5DatasetDevice.cpp +++ b/packages/h5/H5DatasetDevice.cpp @@ -63,7 +63,7 @@ int H5DatasetDevice::luaCreate (lua_State* L) { /* Get Parameters */ int _role = (int)getLuaInteger(L, 1); - _asset = (Asset*)getLuaObject(L, 2, Asset::OBJECT_TYPE); + _asset = dynamic_cast(getLuaObject(L, 2, Asset::OBJECT_TYPE)); const char* _resource = getLuaString(L, 3); const char* dataset_name = getLuaString(L, 4); long id = getLuaInteger(L, 5, true, 0); @@ -110,7 +110,7 @@ H5DatasetDevice::H5DatasetDevice (lua_State* L, role_t _role, Asset* _asset, con /* Set Record */ recObj = new RecordObject(recType); - recData = (h5dataset_t*)recObj->getRecordData(); + recData = reinterpret_cast(recObj->getRecordData()); /* Initialize Attributes to Zero */ dataBuffer = NULL; @@ -157,11 +157,11 @@ H5DatasetDevice::H5DatasetDevice (lua_State* L, role_t _role, Asset* _asset, con *----------------------------------------------------------------------------*/ H5DatasetDevice::~H5DatasetDevice (void) { - closeConnection(); + H5DatasetDevice::closeConnection(); delete recObj; - if(config) delete [] config; - if(dataName) delete [] dataName; - if(resource) delete [] resource; + delete [] config; + delete [] dataName; + delete [] resource; asset->releaseLuaObject(); } @@ -181,7 +181,7 @@ bool H5DatasetDevice::isConnected (int num_open) void H5DatasetDevice::closeConnection (void) { connected = false; - if(dataBuffer) delete [] dataBuffer; + delete [] dataBuffer; dataBuffer = NULL; } diff --git a/packages/h5/H5DatasetDevice.h b/packages/h5/H5DatasetDevice.h index 3fd813607..affd5a6e0 100644 --- a/packages/h5/H5DatasetDevice.h +++ b/packages/h5/H5DatasetDevice.h @@ -101,12 +101,12 @@ class H5DatasetDevice: public DeviceObject RecordObject::valType_t datatype, long col, long startrow, long numrows); ~H5DatasetDevice (void); - bool isConnected (int num_open=0); // is the file open - void closeConnection (void); // close the file - int writeBuffer (const void* buf, int len, int timeout=SYS_TIMEOUT); - int readBuffer (void* buf, int len, int timeout=SYS_TIMEOUT); - int getUniqueId (void); // returns file descriptor - const char* getConfig (void); // returns filename with attribute list + bool isConnected (int num_open=0) override; // is the file open + void closeConnection (void) override; // close the file + int writeBuffer (const void* buf, int len, int timeout=SYS_TIMEOUT) override; + int readBuffer (void* buf, int len, int timeout=SYS_TIMEOUT) override; + int getUniqueId (void) override; // returns file descriptor + const char* getConfig (void) override; // returns filename with attribute list }; #endif /* __h5_dataset__ */ diff --git a/packages/h5/H5File.cpp b/packages/h5/H5File.cpp index cedbf8e7d..a0cd0ae78 100644 --- a/packages/h5/H5File.cpp +++ b/packages/h5/H5File.cpp @@ -40,9 +40,9 @@ * STATIC DATA ******************************************************************************/ -const char* H5File::ObjectType = "H5File"; -const char* H5File::LuaMetaName = "H5File"; -const struct luaL_Reg H5File::LuaMetaTable[] = { +const char* H5File::OBJECT_TYPE = "H5File"; +const char* H5File::LUA_META_NAME = "H5File"; +const struct luaL_Reg H5File::LUA_META_TABLE[] = { {"read", luaRead}, {"dir", luaTraverse}, {"inspect", luaInspect}, @@ -74,7 +74,7 @@ int H5File::luaCreate(lua_State* L) try { /* Get Parameters */ - _asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + _asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* _resource = getLuaString(L, 2); /* Return File Device Object */ @@ -100,7 +100,7 @@ void H5File::init (void) * Constructor *----------------------------------------------------------------------------*/ H5File::H5File (lua_State* L, Asset* _asset, const char* _resource): - LuaObject(L, ObjectType, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { asset = _asset; resource = StringLib::duplicate(_resource); @@ -111,7 +111,7 @@ H5File::H5File (lua_State* L, Asset* _asset, const char* _resource): *----------------------------------------------------------------------------*/ H5File::~H5File (void) { - if(resource) delete [] resource; + delete [] resource; asset->releaseLuaObject(); } @@ -178,19 +178,17 @@ void* H5File::readThread (void* parm) int H5File::luaRead (lua_State* L) { bool status = true; - - int self_index = 1; - int tbl_index = 2; - int outq_index = 3; - - List pids; const char* outq_name = NULL; H5File* lua_obj = NULL; try { + int self_index = 1; + int tbl_index = 2; + int outq_index = 3; + /* Get Self */ - lua_obj = (H5File*)getLuaSelf(L, self_index); + lua_obj = dynamic_cast(getLuaSelf(L, self_index)); /* Get Output Queue */ outq_name = getLuaString(L, outq_index); @@ -199,10 +197,18 @@ int H5File::luaRead (lua_State* L) int num_datasets = lua_rawlen(L, tbl_index); if(lua_istable(L, tbl_index) && num_datasets > 0) { + /* Allocate List of Threads + * they will go out of scope at the end of this if block; + * when that happens, each thread will join as it is deleted + * automatically by the List object */ + List pids(num_datasets); + for(int i = 0; i < num_datasets; i++) { const char* dataset; - long col, startrow, numrows; + long col; + long startrow; + long numrows; RecordObject::valType_t valtype; /* Get Dataset Entry */ @@ -254,29 +260,19 @@ int H5File::luaRead (lua_State* L) { throw RunTimeException(CRITICAL, RTE_ERROR, "expecting list of datasets"); } - } - catch(const RunTimeException& e) - { - mlog(e.level(), "Failed to read resource: %s", e.what()); - status = false; - } - - /* Clean Up and Terminate */ - if(lua_obj && outq_name) - { - /* Wait for Threads to Complete */ - for(int i = 0; i < pids.length(); i++) - { - delete pids[i]; // performs join - } /* Status Complete */ - mlog(INFO, "Finished reading %d datasets from %s", pids.length(), lua_obj->asset->getName()); + mlog(INFO, "Finished reading %d datasets from %s", num_datasets, lua_obj->asset->getName()); /* Terminate Data */ Publisher outQ(outq_name); outQ.postCopy("", 0); } + catch(const RunTimeException& e) + { + mlog(e.level(), "Failed to read resource: %s", e.what()); + status = false; + } /* Return Status */ return returnLuaStatus(L, status); @@ -292,7 +288,7 @@ int H5File::luaTraverse (lua_State* L) try { /* Get Self */ - H5File* lua_obj = (H5File*)getLuaSelf(L, 1); + H5File* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ uint32_t max_depth = getLuaInteger(L, 2, true, 32); @@ -320,7 +316,7 @@ int H5File::luaInspect (lua_State* L) try { /* Get Self */ - H5File* lua_obj = (H5File*)getLuaSelf(L, 1); + H5File* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* dataset_name = getLuaString(L, 2); diff --git a/packages/h5/H5File.h b/packages/h5/H5File.h index 4d1a9fca4..63c7f6b1c 100644 --- a/packages/h5/H5File.h +++ b/packages/h5/H5File.h @@ -56,9 +56,9 @@ class H5File: public LuaObject static const int MAX_NAME_STR = H5CORO_MAXIMUM_NAME_SIZE; - static const char* ObjectType; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* OBJECT_TYPE; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const char* recType; static const RecordObject::fieldDef_t recDef[]; diff --git a/packages/legacy/CcsdsFileWriter.h b/packages/legacy/CcsdsFileWriter.h index 82f0fd69f..2e64ce152 100644 --- a/packages/legacy/CcsdsFileWriter.h +++ b/packages/legacy/CcsdsFileWriter.h @@ -104,7 +104,7 @@ class CcsdsFileWriter: public CcsdsMsgProcessor virtual int writeMsg (void* msg, int size, bool with_header=false); virtual bool isBinary (void); - bool processMsg (unsigned char* msg, int bytes); // OVERLOAD + bool processMsg (unsigned char* msg, int bytes) override; int flushCmd (int argc, char argv[][MAX_CMD_SIZE]); }; diff --git a/packages/legacy/CcsdsFrameStripper.h b/packages/legacy/CcsdsFrameStripper.h index 870124680..dd74d0a98 100644 --- a/packages/legacy/CcsdsFrameStripper.h +++ b/packages/legacy/CcsdsFrameStripper.h @@ -95,7 +95,7 @@ class CcsdsFrameStripper: public CcsdsMsgProcessor CcsdsFrameStripper (CommandProcessor* cmd_proc, const char* obj_name, const char* inq_name, const char* outq_name, uint8_t* sync_marker, int sync_size, int strip_size, int frame_size); virtual ~CcsdsFrameStripper (void); - bool processMsg (unsigned char* msg, int bytes); // OVERLOAD + bool processMsg (unsigned char* msg, int bytes) override; }; #endif /* __ccsds_frame_stripper__ */ diff --git a/packages/legacy/CcsdsMsgProcessor.cpp b/packages/legacy/CcsdsMsgProcessor.cpp index 019bd1d68..b5acd371b 100644 --- a/packages/legacy/CcsdsMsgProcessor.cpp +++ b/packages/legacy/CcsdsMsgProcessor.cpp @@ -156,7 +156,7 @@ void* CcsdsMsgProcessor::processorThread(void* parm) { assert(parm); - CcsdsMsgProcessor* processor = (CcsdsMsgProcessor*)parm; + CcsdsMsgProcessor* processor = static_cast(parm); bool self_delete = false; /* Initialize Processing */ diff --git a/packages/legacy/CcsdsPacketProcessor.cpp b/packages/legacy/CcsdsPacketProcessor.cpp index 2f24d5716..f357c4d02 100644 --- a/packages/legacy/CcsdsPacketProcessor.cpp +++ b/packages/legacy/CcsdsPacketProcessor.cpp @@ -349,7 +349,7 @@ int CcsdsPacketProcessor::regApidProcCmd(int argc, char argv[][MAX_CMD_SIZE]) const char* proc_obj_name = argv[1]; /* Set Processor */ - CcsdsProcessorModule* processor = (CcsdsProcessorModule*)cmdProc->getObject(proc_obj_name, "CcsdsProcessorModule"); + CcsdsProcessorModule* processor = dynamic_cast(cmdProc->getObject(proc_obj_name, "CcsdsProcessorModule")); if(processor == NULL) { mlog(CRITICAL, "Unable to find processor module %s", proc_obj_name); @@ -423,10 +423,6 @@ void* CcsdsPacketProcessor::workerThread (void* parm) } /* Delete Packets */ - for(int s = 0; s < worker->segments->length(); s++) - { - delete worker->segments->get(s); // deletes malloc'ed CcsdsPacket in processMsg - } delete worker->segments; // deletes malloc'ed List in processMsg worker->segments = NULL; // informs resetProcessing() that segments has been freed diff --git a/packages/legacy/CcsdsPacketProcessor.h b/packages/legacy/CcsdsPacketProcessor.h index b45e42373..5cb16c77e 100644 --- a/packages/legacy/CcsdsPacketProcessor.h +++ b/packages/legacy/CcsdsPacketProcessor.h @@ -133,8 +133,8 @@ class CcsdsPacketProcessor: public CcsdsMsgProcessor static void* workerThread (void* parm); - bool processMsg (unsigned char* msg, int bytes); // OVERLOAD - bool handleTimeout (void); // OVERLOAD + bool processMsg (unsigned char* msg, int bytes) override; + bool handleTimeout (void) override; bool resetProcessing (void); static void freeWorker (void* obj, void* parm); diff --git a/packages/legacy/CcsdsProcessorModule.cpp b/packages/legacy/CcsdsProcessorModule.cpp index 1aaab23d3..5d28e78c2 100644 --- a/packages/legacy/CcsdsProcessorModule.cpp +++ b/packages/legacy/CcsdsProcessorModule.cpp @@ -87,15 +87,23 @@ double CcsdsProcessorModule::parseFlt(unsigned char* ptr, int size) { if(size == 4) { - uint32_t ival = parseInt(ptr, size); - float* fval = (float*)&ival; - return (double)*fval; + typedef union { + uint32_t ival; + float fval; + } float_cast_t; + float_cast_t cast; + cast.ival = parseInt(ptr, size); + return static_cast(cast.fval); } else if(size == 8) { - uint64_t ival = parseInt(ptr, size); - double* dval = (double*)&ival; - return *dval; + typedef union { + uint64_t lval; + double dval; + } double_cast_t; + double_cast_t cast; + cast.lval = parseInt(ptr, size); + return cast.dval; } else { diff --git a/packages/legacy/CcsdsPublisherProcessorModule.h b/packages/legacy/CcsdsPublisherProcessorModule.h index 2e64f9c88..c1d4aeb3d 100644 --- a/packages/legacy/CcsdsPublisherProcessorModule.h +++ b/packages/legacy/CcsdsPublisherProcessorModule.h @@ -74,7 +74,7 @@ class CcsdsPublisherProcessorModule: public CcsdsProcessorModule CcsdsPublisherProcessorModule (CommandProcessor* cmd_proc, const char* obj_name, const char* pubq_name); ~CcsdsPublisherProcessorModule (void); - bool processSegments (List& segments, int numpkts); + bool processSegments (List& segments, int numpkts) override; int concatSegmentsCmd (int argc, char argv[][MAX_CMD_SIZE]); int checkLengthCmd (int argc, char argv[][MAX_CMD_SIZE]); diff --git a/packages/legacy/CcsdsRecordFileWriter.h b/packages/legacy/CcsdsRecordFileWriter.h index 66c51becc..78192f428 100644 --- a/packages/legacy/CcsdsRecordFileWriter.h +++ b/packages/legacy/CcsdsRecordFileWriter.h @@ -61,7 +61,7 @@ class CcsdsRecordFileWriter: public CcsdsFileWriter CcsdsRecordFileWriter (CommandProcessor* cmd_proc, const char* name, const char* _prefix, const char* inq_name, const char** _bound_fields, int _num_bound_fields, unsigned int _max_file_size=FILE_MAX_SIZE); ~CcsdsRecordFileWriter (void); - virtual int writeMsg (void* msg, int size, bool with_header=false); + virtual int writeMsg (void* msg, int size, bool with_header=false) override; virtual RecordObject* createRecord (unsigned char* buffer, int size); virtual const char* createPrependStr (unsigned char* buffer, int size); diff --git a/packages/legacy/CfsInterface.cpp b/packages/legacy/CfsInterface.cpp index b6fc3b639..4663472c8 100644 --- a/packages/legacy/CfsInterface.cpp +++ b/packages/legacy/CfsInterface.cpp @@ -214,7 +214,7 @@ CfsInterface::~CfsInterface(void) *----------------------------------------------------------------------------*/ void* CfsInterface::telemetryThread (void* parm) { - CfsInterface* interface = (CfsInterface*)parm; + CfsInterface* interface = static_cast(parm); unsigned char* buffer = new unsigned char[CCSDS_MAX_SPACE_PACKET_SIZE]; while(interface->interfaceActive) @@ -284,7 +284,7 @@ void* CfsInterface::telemetryThread (void* parm) *----------------------------------------------------------------------------*/ void* CfsInterface::commandThread (void* parm) { - CfsInterface* interface = (CfsInterface*)parm; + CfsInterface* interface = static_cast(parm); unsigned char buffer[CCSDS_MAX_SPACE_PACKET_SIZE]; while(interface->interfaceActive) diff --git a/packages/legacy/CommandProcessor.cpp b/packages/legacy/CommandProcessor.cpp index 952522e9b..8cee46e0f 100644 --- a/packages/legacy/CommandProcessor.cpp +++ b/packages/legacy/CommandProcessor.cpp @@ -215,7 +215,7 @@ bool CommandProcessor::executeScript (const char* script_name) } /* Build Command List */ - MgList script_cmds; + vector script_cmds; while(true) { char line[MAX_CMD_SIZE]; @@ -231,7 +231,7 @@ bool CommandProcessor::executeScript (const char* script_name) else if((line[0] != '\n') && line[0] != '\0') { const char* script_cmd = StringLib::duplicate(line); - script_cmds.add(script_cmd); + script_cmds.push_back(script_cmd); } } else @@ -241,9 +241,10 @@ bool CommandProcessor::executeScript (const char* script_name) } /* Post All Commands */ - for(int i = 0; i < script_cmds.length(); i++) + for(unsigned i = 0; i < script_cmds.size(); i++) { postCommand("%s", script_cmds[i]); + delete [] script_cmds[i]; } /* Close Script and Return */ @@ -440,7 +441,7 @@ int CommandProcessor::getCurrentValue(const char* obj_name, const char* key, voi *----------------------------------------------------------------------------*/ void* CommandProcessor::cmdProcThread (void* parm) { - CommandProcessor* cp = (CommandProcessor*)parm; + CommandProcessor* cp = static_cast(parm); char* cmdstr = new char[MAX_CMD_SIZE]; char* pristr = new char[MAX_CMD_SIZE]; @@ -889,8 +890,6 @@ int CommandProcessor::abortCmd (int argc, char argv[][MAX_CMD_SIZE]) *----------------------------------------------------------------------------*/ int CommandProcessor::newCmd (int argc, char argv[][MAX_CMD_SIZE]) { - int minargs = 2; - /* Pull Out Parameters */ const char* class_name = argv[0]; const char* obj_name = argv[1]; @@ -904,6 +903,8 @@ int CommandProcessor::newCmd (int argc, char argv[][MAX_CMD_SIZE]) try { + int minargs = 2; + /* Look Up Handler */ handle_entry_t* handle = handlers[class_name]; @@ -1236,7 +1237,7 @@ int CommandProcessor::exportDefinitionCmd (int argc, char argv[][MAX_CMD_SIZE]) { (void)argc; - int status = 0, post_status = 0; + int status = 0; const char* rec_type = argv[0]; const char* qname = StringLib::StringLib::checkNullStr(argv[1]); @@ -1258,7 +1259,7 @@ int CommandProcessor::exportDefinitionCmd (int argc, char argv[][MAX_CMD_SIZE]) const char* id_field = RecordObject::getRecordIdField(rectypes[i]); int data_size = RecordObject::getRecordDataSize(rectypes[i]); int max_fields = RecordObject::getRecordMaxFields(rectypes[i]); - post_status = cmdq_out->postString("DEFINE %s %s %d %d\n", rectypes[i], id_field != NULL ? id_field : "NA", data_size, max_fields); + int post_status = cmdq_out->postString("DEFINE %s %s %d %d\n", rectypes[i], id_field != NULL ? id_field : "NA", data_size, max_fields); if(post_status <= 0) { mlog(CRITICAL, "Failed to post definition for %s on stream %s", rectypes[i], qname); @@ -1295,7 +1296,7 @@ int CommandProcessor::exportDefinitionCmd (int argc, char argv[][MAX_CMD_SIZE]) const char* id_field = RecordObject::getRecordIdField(rec_type); int data_size = RecordObject::getRecordDataSize(rec_type); int max_fields = RecordObject::getRecordMaxFields(rec_type); - post_status = cmdq_out->postString("DEFINE %s %s %d %d\n", rec_type, id_field != NULL ? id_field : "NA", data_size, max_fields); + int post_status = cmdq_out->postString("DEFINE %s %s %d %d\n", rec_type, id_field != NULL ? id_field : "NA", data_size, max_fields); if(post_status <= 0) { mlog(CRITICAL, "Failed to post definition for %s on stream %s", rec_type, qname); diff --git a/packages/legacy/CommandProcessor.h b/packages/legacy/CommandProcessor.h index 1dcf17f59..967bf10e2 100644 --- a/packages/legacy/CommandProcessor.h +++ b/packages/legacy/CommandProcessor.h @@ -71,7 +71,7 @@ class CommandProcessor: public CommandableObject * Methods *--------------------------------------------------------------------*/ - CommandProcessor (const char* cmdq_name); + explicit CommandProcessor (const char* cmdq_name); ~CommandProcessor (void); bool postCommand (const char* cmdstr, ...) VARG_CHECK(printf, 2, 3); // "this" is 1 @@ -140,13 +140,17 @@ class CommandProcessor: public CommandableObject permanent = _permanent; } }; + // Dictionaries // + typedef Dictionary HandleDictionary; + typedef Dictionary CvtDictionary; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ static const int MAX_KEY_NAME = 256; - MgDictionary handlers; + HandleDictionary handlers; Subscriber* cmdq_subscriber; Publisher* cmdq_publisher; @@ -160,7 +164,7 @@ class CommandProcessor: public CommandableObject Dictionary objects; List lockedObjects; - MgDictionary currentValueTable; + CvtDictionary currentValueTable; Cond cvtCond; double stopwatch_time; diff --git a/packages/legacy/CommandableObject.cpp b/packages/legacy/CommandableObject.cpp index 3af1b6363..8fbc47f9a 100644 --- a/packages/legacy/CommandableObject.cpp +++ b/packages/legacy/CommandableObject.cpp @@ -101,7 +101,7 @@ int CommandableObject::getCommands(char*** cmd_names, char*** cmd_descs) *cmd_descs = new char* [numcmds]; for(int i = 0; i < numcmds; i++) { - obj_cmd_entry_t* cmd = (obj_cmd_entry_t*)commands[(*cmd_names)[i]]; + obj_cmd_entry_t* cmd = commands[(*cmd_names)[i]]; (*cmd_descs)[i] = StringLib::duplicate(cmd->desc); } return numcmds; diff --git a/packages/legacy/CommandableObject.h b/packages/legacy/CommandableObject.h index b02d4a148..9f91b16f2 100644 --- a/packages/legacy/CommandableObject.h +++ b/packages/legacy/CommandableObject.h @@ -114,15 +114,16 @@ class CommandableObject ~obj_cmd_entry_t(void) { if(desc) delete [] desc; } }; - + + typedef Dictionary CmdDictionary; /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ - const char* objName; - const char* objType; - MgDictionary commands; - CommandProcessor* cmdProc; + const char* objName; + const char* objType; + CmdDictionary commands; + CommandProcessor* cmdProc; }; #endif /* __commandable_object__ */ diff --git a/packages/legacy/CosmosInterface.cpp b/packages/legacy/CosmosInterface.cpp index 5359b98ee..72a66856b 100644 --- a/packages/legacy/CosmosInterface.cpp +++ b/packages/legacy/CosmosInterface.cpp @@ -180,7 +180,7 @@ void* CosmosInterface::listenerThread (void* parm) { assert(parm != NULL); - listener_t* l = (listener_t*)parm; + listener_t* l = static_cast(parm); int status = SockLib::startserver(l->ip_addr, l->port, l->ci->maxConnections, pollHandler, l->handler, &l->ci->interfaceActive, (void*)l->ci); if(status < 0) @@ -213,7 +213,7 @@ int CosmosInterface::pollHandler(int fd, short* events, void* parm) *----------------------------------------------------------------------------*/ int CosmosInterface::tlmActiveHandler(int fd, int flags, void* parm) { - CosmosInterface* ci = (CosmosInterface*)parm; + CosmosInterface* ci = static_cast(parm); if(flags & IO_CONNECT_FLAG) { @@ -243,7 +243,7 @@ int CosmosInterface::tlmActiveHandler(int fd, int flags, void* parm) *----------------------------------------------------------------------------*/ int CosmosInterface::cmdActiveHandler(int fd, int flags, void* parm) { - CosmosInterface* ci = (CosmosInterface*)parm; + CosmosInterface* ci = static_cast(parm); if(flags & IO_CONNECT_FLAG) { @@ -271,7 +271,7 @@ int CosmosInterface::cmdActiveHandler(int fd, int flags, void* parm) *----------------------------------------------------------------------------*/ void* CosmosInterface::telemetryThread (void* parm) { - tlm_t* rqst = (tlm_t*)parm; + tlm_t* rqst = static_cast(parm); CosmosInterface* ci = rqst->ci; unsigned char* buffer = new unsigned char[MAX_PACKET_SIZE + HEADER_SIZE]; @@ -319,7 +319,7 @@ void* CosmosInterface::telemetryThread (void* parm) *----------------------------------------------------------------------------*/ void* CosmosInterface::commandThread (void* parm) { - cmd_t* c = (cmd_t*)parm; + cmd_t* c = static_cast(parm); unsigned char header_buf[HEADER_SIZE]; int header_index = 0; int packet_index = 0; diff --git a/packages/legacy/CosmosInterface.h b/packages/legacy/CosmosInterface.h index 0f412beeb..84fcf262b 100644 --- a/packages/legacy/CosmosInterface.h +++ b/packages/legacy/CosmosInterface.h @@ -124,6 +124,9 @@ class CosmosInterface: public CommandableObject if(pid) delete pid; } }; + typedef Ordering TlmOrdering; + typedef Ordering CmdOrdering; + /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ @@ -134,14 +137,14 @@ class CosmosInterface: public CommandableObject // telemetry connections Thread* tlmListenerPid; listener_t tlmListener; - MgOrdering tlmConnections; + TlmOrdering tlmConnections; Mutex tlmConnMut; const char* tlmQName; // command connections Thread* cmdListenerPid; listener_t cmdListener; - MgOrdering cmdConnections; + CmdOrdering cmdConnections; Mutex cmdConnMut; const char* cmdQName; diff --git a/packages/legacy/LuaInterpreter.cpp b/packages/legacy/LuaInterpreter.cpp index 93450a6ce..afaebda6a 100644 --- a/packages/legacy/LuaInterpreter.cpp +++ b/packages/legacy/LuaInterpreter.cpp @@ -90,7 +90,7 @@ void LuaInterpreter::abortHook (lua_State *L, lua_Debug *ar) /* Check if Interpreter still Active - in which case don't abort */ lua_pushstring(L, LuaEngine::LUA_SELFKEY); lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */ - LuaEngine* li = (LuaEngine*)lua_touserdata(L, -1); + LuaEngine* li = static_cast(lua_touserdata(L, -1)); if(li) abort = !li->isActive(); /* If Aborting */ diff --git a/packages/legacy/LuaLibraryCmd.cpp b/packages/legacy/LuaLibraryCmd.cpp index 309a77216..de46dfb8b 100644 --- a/packages/legacy/LuaLibraryCmd.cpp +++ b/packages/legacy/LuaLibraryCmd.cpp @@ -90,7 +90,7 @@ int LuaLibraryCmd::lcmd_exec (lua_State* L) /* Get Lua Engine Object */ lua_pushstring(L, LuaEngine::LUA_SELFKEY); lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */ - LuaEngine* li = (LuaEngine*)lua_touserdata(L, -1); + LuaEngine* li = static_cast(lua_touserdata(L, -1)); if(li) { /* Get Key */ diff --git a/packages/legacy/UT_Dictionary.cpp b/packages/legacy/UT_Dictionary.cpp index 708b96b34..743287fd0 100644 --- a/packages/legacy/UT_Dictionary.cpp +++ b/packages/legacy/UT_Dictionary.cpp @@ -74,17 +74,6 @@ UT_Dictionary::UT_Dictionary(CommandProcessor* cmd_proc, const char* obj_name): *----------------------------------------------------------------------------*/ UT_Dictionary::~UT_Dictionary(void) { - List* wordlist; - const char* wordset_name = wordsets.first(&wordlist); - while(wordset_name != NULL) - { - for(int w = 0; w < wordlist->length(); w++) - { - delete wordlist->get(w); - } - delete wordlist; - wordset_name = wordsets.next(&wordlist); - } } /*---------------------------------------------------------------------------- @@ -108,11 +97,11 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) /* Get Word List */ const char* wordset_name = argv[0]; - List* wordlist_ptr; + vector* wordlist_ptr; try { - wordlist_ptr = (List*)wordsets[wordset_name]; - if(wordlist_ptr->length() <= 0) + wordlist_ptr = wordsets[wordset_name]; + if(wordlist_ptr->empty()) { print2term("[%d] ERROR: word set %s is empty!\n", __LINE__, wordset_name); return -1; @@ -125,16 +114,16 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } /* Get Number of Words */ - List& wordset = *wordlist_ptr; - int numwords = wordset.length(); + vector& wordset = *wordlist_ptr; + int numwords = static_cast(wordset.size()); /* Set Entries */ for(int i = 0; i < numwords; i++) { seq = i; - if(!d1.add(wordset[i]->str(), seq)) + if(!d1.add(wordset[i].c_str(), seq)) { - print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i].c_str()); failure = true; } } @@ -142,9 +131,9 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) /* Find Entries */ for(int i = 0; i < numwords; i++) { - if(!d1.find(wordset[i]->str())) + if(!d1.find(wordset[i].c_str())) { - print2term("[%d] ERROR: failed to find %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: failed to find %s\n", __LINE__, wordset[i].c_str()); failure = true; } } @@ -154,16 +143,16 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) { try { - long data = d1.get(wordset[i]->str()); + long data = d1.get(wordset[i].c_str()); if(data != i) { - print2term("[%d] ERROR: failed to read back value, %ld != %d, for word: %s\n", __LINE__, data, i, wordset[i]->str()); + print2term("[%d] ERROR: failed to read back value, %ld != %d, for word: %s\n", __LINE__, data, i, wordset[i].c_str()); failure = true; } } catch(RunTimeException& e) { - print2term("[%d] ERROR: failed to get %s: %s\n", __LINE__, wordset[i]->str(), e.what()); + print2term("[%d] ERROR: failed to get %s: %s\n", __LINE__, wordset[i].c_str(), e.what()); failure = true; } } @@ -193,7 +182,7 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) const char** true_list = new const char* [numwords]; for(int i = 0; i < numwords; i++) { - true_list[i] = wordset[i]->str(); + true_list[i] = wordset[i].c_str(); } for(int i = 0; i < numwords; i++) @@ -215,7 +204,7 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } if(!found) { - print2term("[%d] ERROR: failed to retrieve the correct key, %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: failed to retrieve the correct key, %s\n", __LINE__, wordset[i].c_str()); failure = true; } @@ -229,9 +218,9 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) /* Remove Entries */ for(int i = 0; i < numwords; i++) { - if(d1.remove(wordset[i]->str()) != true) + if(d1.remove(wordset[i].c_str()) != true) { - print2term("[%d] ERROR: failed to remove %s, %d\n", __LINE__, wordset[i]->str(), i); + print2term("[%d] ERROR: failed to remove %s, %d\n", __LINE__, wordset[i].c_str(), i); failure = true; } } @@ -251,9 +240,9 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) for(int i = 0; i < numwords; i++) { seq = i; - if(!d1.add(wordset[i]->str(), seq)) + if(!d1.add(wordset[i].c_str(), seq)) { - print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i].c_str()); failure = true; } } @@ -264,9 +253,9 @@ int UT_Dictionary::functionalUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) /* Find Entries - Should Not Find Them */ for(int i = 0; i < numwords; i++) { - if(d1.find(wordset[i]->str())) + if(d1.find(wordset[i].c_str())) { - print2term("[%d] ERROR: found entry that should have been cleared %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: found entry that should have been cleared %s\n", __LINE__, wordset[i].c_str()); failure = true; } } @@ -300,16 +289,15 @@ int UT_Dictionary::iteratorUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) (void)argc; Dictionary d1; - long seq, sum; bool failure=false; /* Get Word List */ const char* wordset_name = argv[0]; - List* wordlist_ptr; + vector* wordlist_ptr; try { - wordlist_ptr = (List*)wordsets[wordset_name]; - if(wordlist_ptr->length() <= 0) + wordlist_ptr = wordsets[wordset_name]; + if(wordlist_ptr->empty()) { print2term("[%d] ERROR: word set %s is empty!\n", __LINE__, wordset_name); return -1; @@ -322,18 +310,18 @@ int UT_Dictionary::iteratorUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } /* Get Word Set */ - List& wordset = *wordlist_ptr; - int numwords = wordset.length(); + vector& wordset = *wordlist_ptr; + int numwords = static_cast(wordset.size()); /* Set Entries */ - sum = 0; + long sum = 0; for(int i = 0; i < numwords; i++) { - seq = i; + long seq = i; sum += i; - if(!d1.add(wordset[i]->str(), seq)) + if(!d1.add(wordset[i].c_str(), seq)) { - print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i]->str()); + print2term("[%d] ERROR: failed to add %s\n", __LINE__, wordset[i].c_str()); failure = true; } } @@ -442,16 +430,15 @@ int UT_Dictionary::addWordSetCmd (int argc, char argv[][MAX_CMD_SIZE]) *----------------------------------------------------------------------------*/ int UT_Dictionary::createWordSet (const char* name, const char* filename) { - List* wordlist = new List(); - FILE* wordfile = fopen(filename, "r"); if(wordfile == NULL) { print2term("[%d] ERROR: Unable to open word list file: %s\n", __LINE__, filename); - delete wordlist; return -1; } + vector* wordlist = new vector; + while(true) { char line[MAX_STR_SIZE]; @@ -459,8 +446,8 @@ int UT_Dictionary::createWordSet (const char* name, const char* filename) { if((line[0] != '\n') && line[0] != '\0') { - SafeString* word = new SafeString("%s", line); - wordlist->add(word); + string word(line); + wordlist->push_back(word); } } else @@ -473,7 +460,7 @@ int UT_Dictionary::createWordSet (const char* name, const char* filename) if(wordsets.add(name, wordlist, true)) { - return wordlist->length(); + return wordlist->size(); } else { diff --git a/packages/legacy/UT_Dictionary.h b/packages/legacy/UT_Dictionary.h index 8a7aff4e6..a3a44d8c0 100644 --- a/packages/legacy/UT_Dictionary.h +++ b/packages/legacy/UT_Dictionary.h @@ -64,7 +64,7 @@ class UT_Dictionary: public CommandableObject * Data *--------------------------------------------------------------------*/ - Dictionary*> wordsets; + Dictionary*> wordsets; /*-------------------------------------------------------------------- * Methods diff --git a/packages/legacy/UT_List.cpp b/packages/legacy/UT_List.cpp index 1cdf6315c..c5c4082c8 100644 --- a/packages/legacy/UT_List.cpp +++ b/packages/legacy/UT_List.cpp @@ -69,7 +69,8 @@ CommandableObject* UT_List::createObject(CommandProcessor* cmd_proc, const char* * Constructor - *----------------------------------------------------------------------------*/ UT_List::UT_List(CommandProcessor* cmd_proc, const char* obj_name): - CommandableObject(cmd_proc, obj_name, TYPE) + CommandableObject(cmd_proc, obj_name, TYPE), + failures(0) { /* Register Commands */ registerCommand("ADD_REMOVE", (cmdFunc_t)&UT_List::testAddRemove, 0, ""); @@ -136,7 +137,7 @@ int UT_List::testAddRemove(int argc, char argv[][MAX_CMD_SIZE]) (void)argv; failures = 0; - List mylist; + List mylist(10); // add initial set for(int i = 0; i < 75; i++) @@ -188,7 +189,7 @@ int UT_List::testDuplicates(int argc, char argv[][MAX_CMD_SIZE]) (void)argv; failures = 0; - List mylist; + List mylist(10); // add initial set for(int i = 0; i < 20; i++) @@ -222,19 +223,19 @@ int UT_List::testSort(int argc, char argv[][MAX_CMD_SIZE]) failures = 0; // in order - List mylist1; + List mylist1(10); for(int i = 0; i < 20; i++) mylist1.add(i); mylist1.sort(); for(int i = 0; i < 20; i++) ut_assert(mylist1[i] == i, "failed to sort %d\n", i); // reverse order - List mylist2; + List mylist2(10); for(int i = 0; i < 20; i++) mylist2.add(20 - i); mylist2.sort(); for(int i = 0; i < 20; i++) ut_assert(mylist2[i] == (i + 1), "failed to sort %d\n", i + 1); // random order - List mylist3; + List mylist3(10); mylist3.add(19); mylist3.add(1); mylist3.add(2); diff --git a/packages/legacy/UT_MsgQ.cpp b/packages/legacy/UT_MsgQ.cpp index 2ef7b40a3..bc6c7b603 100644 --- a/packages/legacy/UT_MsgQ.cpp +++ b/packages/legacy/UT_MsgQ.cpp @@ -281,8 +281,6 @@ int UT_MsgQ::subscribeUnsubscribeUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE *----------------------------------------------------------------------------*/ int UT_MsgQ::performanceUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) { - clock_t start, end, total_start, total_end; - double pub_time, sub_time, total_time; long depth = 500000; long size = 1000; bool failure = false; @@ -319,7 +317,7 @@ int UT_MsgQ::performanceUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) { perf_thread_t* RAW = new perf_thread_t[numsubs]; - total_start = clock(); + clock_t total_start = clock(); /* Kick-off Subscribers */ Thread** t = new Thread* [numsubs]; @@ -334,7 +332,7 @@ int UT_MsgQ::performanceUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } /* Publish Packets */ - start = clock(); + clock_t start = clock(); unsigned char* pkt = new unsigned char [size]; for(int i = 0; i < depth; i++) { @@ -351,8 +349,8 @@ int UT_MsgQ::performanceUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } } delete [] pkt; - end = clock(); - pub_time = ((double) (end - start)) / CLOCKS_PER_SEC; + clock_t end = clock(); + double pub_time = ((double) (end - start)) / CLOCKS_PER_SEC; /* Start Subscribers */ start = clock(); @@ -369,10 +367,10 @@ int UT_MsgQ::performanceUnitTestCmd (int argc, char argv[][MAX_CMD_SIZE]) } delete [] t; end = clock(); - sub_time = ((double) (end - start)) / CLOCKS_PER_SEC; + double sub_time = ((double) (end - start)) / CLOCKS_PER_SEC; - total_end = clock(); - total_time = ((double) (total_end - total_start)) / CLOCKS_PER_SEC; + clock_t total_end = clock(); + double total_time = ((double) (total_end - total_start)) / CLOCKS_PER_SEC; /* Print Results */ print2term("%ld, %ld, %d, %lf, %lf, %lf\n", depth, size, numsubs, pub_time, sub_time, total_time); diff --git a/packages/legacy/UT_Ordering.cpp b/packages/legacy/UT_Ordering.cpp index a71de8b60..f7f0c5d01 100644 --- a/packages/legacy/UT_Ordering.cpp +++ b/packages/legacy/UT_Ordering.cpp @@ -75,7 +75,8 @@ CommandableObject* UT_Ordering::createObject(CommandProcessor* cmd_proc, const c * Constructor - *----------------------------------------------------------------------------*/ UT_Ordering::UT_Ordering(CommandProcessor* cmd_proc, const char* obj_name): - CommandableObject(cmd_proc, obj_name, TYPE) + CommandableObject(cmd_proc, obj_name, TYPE), + failures(0) { /* Register Commands */ registerCommand("ADD_REMOVE", (cmdFunc_t)&UT_Ordering::testAddRemove, 0, ""); diff --git a/packages/legacy/UT_String.cpp b/packages/legacy/UT_String.cpp index 66e3e26ad..78511990e 100644 --- a/packages/legacy/UT_String.cpp +++ b/packages/legacy/UT_String.cpp @@ -69,7 +69,8 @@ CommandableObject* UT_String::createObject(CommandProcessor* cmd_proc, const cha * Constructor - *----------------------------------------------------------------------------*/ UT_String::UT_String(CommandProcessor* cmd_proc, const char* obj_name): - CommandableObject(cmd_proc, obj_name, TYPE) + CommandableObject(cmd_proc, obj_name, TYPE), + failures(0) { /* Register Commands */ registerCommand("REPLACEMENT", (cmdFunc_t)&UT_String::testReplace, 0, ""); @@ -136,21 +137,20 @@ int UT_String::testReplace(int argc, char argv[][MAX_CMD_SIZE]) failures = 0; // 1) Replace Single Character - SafeString test1("Hello World"); - test1.replace("o", "X"); - ut_assert(StringLib::match(test1.str(), "HellX WXrld"), "Failed single character test: %s", test1.str()); - + char* test1 = StringLib::replace("Hello World", "o", "X"); + ut_assert(StringLib::match(test1, "HellX WXrld"), "Failed single character test: %s", test1); + delete [] test1; // 2) Replace String - SafeString test2("Hello World"); - test2.replace("ello", "eal"); - ut_assert(StringLib::match(test2.str(), "Heal World"), "Failed to replace string: %s", test2.str()); + char* test2 = StringLib::replace("Hello World", "ello", "eal"); + ut_assert(StringLib::match(test2, "Heal World"), "Failed to replace string: %s", test2); + delete [] test2; // 3) Replace Strings - SafeString test3("This is a long $1 and I am $2 sure if this $1 will work or $2"); const char* oldtxt[2] = { "$1", "$2" }; const char* newtxt[2] = { "sentence", "not" }; - test3.inreplace(oldtxt, newtxt, 2); - ut_assert(StringLib::match(test3.str(), "This is a long sentence and I am not sure if this sentence will work or not"), "Failed multiple replacements: %s", test3.str()); + char* test3 = StringLib::replace("This is a long $1 and I am $2 sure if this $1 will work or $2", oldtxt, newtxt, 2); + ut_assert(StringLib::match(test3, "This is a long sentence and I am not sure if this sentence will work or not"), "Failed multiple replacements: %s", test3); + delete test3; // return success or failure return failures == 0 ? 0 : -1; diff --git a/packages/legacy/UT_Table.cpp b/packages/legacy/UT_Table.cpp index 94e1bc8af..fd8ac7ce6 100644 --- a/packages/legacy/UT_Table.cpp +++ b/packages/legacy/UT_Table.cpp @@ -69,7 +69,8 @@ CommandableObject* UT_Table::createObject(CommandProcessor* cmd_proc, const char * Constructor - *----------------------------------------------------------------------------*/ UT_Table::UT_Table(CommandProcessor* cmd_proc, const char* obj_name): - CommandableObject(cmd_proc, obj_name, TYPE) + CommandableObject(cmd_proc, obj_name, TYPE), + failures(0) { /* Register Commands */ registerCommand("ADD_REMOVE", (cmdFunc_t)&UT_Table::testAddRemove, 0, ""); @@ -148,7 +149,7 @@ int UT_Table::testAddRemove(int argc, char argv[][MAX_CMD_SIZE]) /* Add Initial Set */ for(key = 0; key < size; key++) { - ut_assert(mytable.add(key, key, false), "Failed to add entry %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add entry %d\n", key); } /* Check Size */ @@ -190,7 +191,7 @@ int UT_Table::testChaining(int argc, char argv[][MAX_CMD_SIZE]) for(int i = 0; i < size; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false), "Failed to add entry %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add entry %d\n", key); } /* Transverse Set */ @@ -217,7 +218,8 @@ int UT_Table::testRemoving(int argc, char argv[][MAX_CMD_SIZE]) (void)argc; (void)argv; - int key, data; + int key; + int data; int size = 16; Table mytable(size); int test_data[16] = {0, 16, 32, 1, 17, 33, 2, 18, 34, 3, 4, 5, 6, 7, 8, 9}; @@ -230,7 +232,7 @@ int UT_Table::testRemoving(int argc, char argv[][MAX_CMD_SIZE]) for(int i = 0; i < size; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false), "Failed to add entry %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add entry %d\n", key); } /* Transverse Set */ @@ -268,40 +270,40 @@ int UT_Table::testDuplicates(int argc, char argv[][MAX_CMD_SIZE]) for(int i = 0; i < 9; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false), "Failed to add key %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add key %d\n", key); } /* Add Duplicate Set */ for(int i = 0; i < 9; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false) == false, "Failed to reject duplicate key %d\n", key); + ut_assert(mytable.add(key, key, true) == false, "Failed to reject duplicate key %d\n", key); } /* Overwrite Duplicate Set */ for(int i = 0; i < 9; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, true), "Failed to overwrite duplicate key %d\n", key); + ut_assert(mytable.add(key, key, false), "Failed to overwrite duplicate key %d\n", key); } /* Add Rest of Set */ for(int i = 9; i < size; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false), "Failed to add key %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add key %d\n", key); } /* Overwrite Entire Duplicate Set */ for(int i = 0; i < size; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, true), "Failed to overwrite duplicate key %d\n", key); + ut_assert(mytable.add(key, key, false), "Failed to overwrite duplicate key %d\n", key); } /* Attempt to Add to Full Hash */ key = 35; - ut_assert(mytable.add(key, key, true) == false, "Failed to detect full table\n"); + ut_assert(mytable.add(key, key, false) == false, "Failed to detect full table\n"); /* Check Size */ ut_assert(mytable.length() == size, "Failed to rget size of table\n"); @@ -328,42 +330,42 @@ int UT_Table::testFullTable(int argc, char argv[][MAX_CMD_SIZE]) for(int i = 0; i < size; i++) { key = test_data[i]; - ut_assert(mytable.add(key, key, false), "Failed to add key %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add key %d\n", key); } /* Fail to Add on Full Table */ - key = 0; ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table, %d\n", key); - key = 8; ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table, %d\n", key); - key = 9; ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table, %d\n", key); + key = 0; ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table, %d\n", key); + key = 8; ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table, %d\n", key); + key = 9; ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table, %d\n", key); /* Fail to Add on Changing Full Table */ for(key = 0; key < size; key++) { - ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table %d\n", key); + ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table %d\n", key); ut_assert(mytable.remove(key), "Failed to remove key %d\n", key); - ut_assert(mytable.add(key, key, false), "Failed to add key %d\n", key); + ut_assert(mytable.add(key, key, true), "Failed to add key %d\n", key); int new1_key = key + size; - ut_assert(mytable.add(new1_key, new1_key, false) == false, "Failed to error on adding key to full table %d\n", new1_key); + ut_assert(mytable.add(new1_key, new1_key, true) == false, "Failed to error on adding key to full table %d\n", new1_key); int new2_key = key + size + 1; - ut_assert(mytable.add(new2_key, new2_key, false) == false, "Failed to error on adding key to full table %d\n", new2_key); + ut_assert(mytable.add(new2_key, new2_key, true) == false, "Failed to error on adding key to full table %d\n", new2_key); } /* Fail to Add on Overwritten Full Table */ for(key = 0; key < size; key++) { - ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table %d\n", key); - ut_assert(mytable.add(key, key, true), "Failed to overwrite key %d\n", key); + ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table %d\n", key); + ut_assert(mytable.add(key, key, false), "Failed to overwrite key %d\n", key); - ut_assert(mytable.add(key, key, false) == false, "Failed to error on adding key to full table %d\n", key); + ut_assert(mytable.add(key, key, true) == false, "Failed to error on adding key to full table %d\n", key); int new1_key = key + size; - ut_assert(mytable.add(new1_key, new1_key, false) == false, "Failed to error on adding key to full table %d\n", new1_key); + ut_assert(mytable.add(new1_key, new1_key, true) == false, "Failed to error on adding key to full table %d\n", new1_key); int new2_key = key + size + 1; - ut_assert(mytable.add(new2_key, new2_key, false) == false, "Failed to error on adding key to full table %d\n", new2_key); + ut_assert(mytable.add(new2_key, new2_key, true) == false, "Failed to error on adding key to full table %d\n", new2_key); } return failures == 0 ? 0 : -1; @@ -422,7 +424,6 @@ int UT_Table::testStress(int argc, char argv[][MAX_CMD_SIZE]) int data_order[64]; int test_cycles = 65536; int key_range = 0xFFFFFFFF; - int num_added = 0; Table mytable(size); failures = 0; @@ -434,13 +435,13 @@ int UT_Table::testStress(int argc, char argv[][MAX_CMD_SIZE]) for(int j = 0; j < test_cycles; j++) { /* Reset Test */ - num_added = 0; + int num_added = 0; /* Load Hash */ for(int i = 0; i < size; i++) { key = rand() % key_range; - if(mytable.add(key, key, false)) + if(mytable.add(key, key, true)) { data_order[num_added++] = key; } diff --git a/packages/legacy/legacy.cpp b/packages/legacy/legacy.cpp index 98d517d96..978d01841 100644 --- a/packages/legacy/legacy.cpp +++ b/packages/legacy/legacy.cpp @@ -45,7 +45,7 @@ struct CCSDS: public CommandableObject { static const char* NAME; static const int DEFAULT_MAX_FIELDS = 256; - CCSDS(CommandProcessor* cmd_proc): CommandableObject(cmd_proc, NAME, NAME) + explicit CCSDS(CommandProcessor* cmd_proc): CommandableObject(cmd_proc, NAME, NAME) { registerCommand("DEFINE_TELEMETRY", (cmdFunc_t)&CCSDS::defineTelemetryCmd, 5, " "); registerCommand("DEFINE_COMMAND", (cmdFunc_t)&CCSDS::defineCommandCmd, 6, " "); diff --git a/plugins/icesat2/plugin/PluginMetrics.cpp b/packages/netsvc/AoiMetrics.cpp similarity index 87% rename from plugins/icesat2/plugin/PluginMetrics.cpp rename to packages/netsvc/AoiMetrics.cpp index dde99076e..85cfea8a8 100644 --- a/plugins/icesat2/plugin/PluginMetrics.cpp +++ b/packages/netsvc/AoiMetrics.cpp @@ -34,19 +34,14 @@ ******************************************************************************/ #include "core.h" -#include "Icesat2Parms.h" -#include "PluginMetrics.h" +#include "NetsvcParms.h" +#include "AoiMetrics.h" /****************************************************************************** * STATIC DATA ******************************************************************************/ -const char* PluginMetrics::CATEGORY = "icesat2"; -const char* PluginMetrics::REGION_METRIC = "hits"; - -int32_t PluginMetrics::regionMetricIds[NUM_REGIONS]; - -PluginMetrics::region_t continental_us = { +AoiMetrics::region_t continental_us = { .name = "continental_us", .proj = MathLib::PLATE_CARREE, .coords = { @@ -63,7 +58,7 @@ PluginMetrics::region_t continental_us = { .num_points = 8 }; -PluginMetrics::region_t alaska = { +AoiMetrics::region_t alaska = { .name = "alaska", .proj = MathLib::NORTH_POLAR, .coords = { @@ -80,7 +75,7 @@ PluginMetrics::region_t alaska = { .num_points = 8 }; -PluginMetrics::region_t canada = { +AoiMetrics::region_t canada = { .name = "canada", .proj = MathLib::NORTH_POLAR, .coords = { @@ -99,7 +94,7 @@ PluginMetrics::region_t canada = { .num_points = 10 }; -PluginMetrics::region_t greenland = { +AoiMetrics::region_t greenland = { .name = "greenland", .proj = MathLib::NORTH_POLAR, .coords = { @@ -115,7 +110,7 @@ PluginMetrics::region_t greenland = { .num_points = 7 }; -PluginMetrics::region_t central_america = { +AoiMetrics::region_t central_america = { .name = "central_america", .proj = MathLib::PLATE_CARREE, .coords = { @@ -132,7 +127,7 @@ PluginMetrics::region_t central_america = { .num_points = 8 }; -PluginMetrics::region_t south_america = { +AoiMetrics::region_t south_america = { .name = "south_america", .proj = MathLib::PLATE_CARREE, .coords = { @@ -148,7 +143,7 @@ PluginMetrics::region_t south_america = { .num_points = 7 }; -PluginMetrics::region_t africa = { +AoiMetrics::region_t africa = { .name = "africa", .proj = MathLib::PLATE_CARREE, .coords = { @@ -166,7 +161,7 @@ PluginMetrics::region_t africa = { .num_points = 9 }; -PluginMetrics::region_t middle_east = { +AoiMetrics::region_t middle_east = { .name = "middle_east", .proj = MathLib::PLATE_CARREE, .coords = { @@ -180,7 +175,7 @@ PluginMetrics::region_t middle_east = { .num_points = 5 }; -PluginMetrics::region_t europe = { +AoiMetrics::region_t europe = { .name = "europe", .proj = MathLib::PLATE_CARREE, .coords = { @@ -195,7 +190,7 @@ PluginMetrics::region_t europe = { .num_points = 6 }; -PluginMetrics::region_t north_asia = { +AoiMetrics::region_t north_asia = { .name = "north_asia", .proj = MathLib::NORTH_POLAR, .coords = { @@ -212,7 +207,7 @@ PluginMetrics::region_t north_asia = { .num_points = 8 }; -PluginMetrics::region_t south_asia = { +AoiMetrics::region_t south_asia = { .name = "south_asia", .proj = MathLib::PLATE_CARREE, .coords = { @@ -227,7 +222,7 @@ PluginMetrics::region_t south_asia = { .num_points = 6 }; -PluginMetrics::region_t oceania = { +AoiMetrics::region_t oceania = { .name = "oceania", .proj = MathLib::PLATE_CARREE, .coords = { @@ -243,7 +238,7 @@ PluginMetrics::region_t oceania = { .num_points = 7 }; -PluginMetrics::region_t antarctica = { +AoiMetrics::region_t antarctica = { .name = "antarctica", .proj = MathLib::SOUTH_POLAR, .coords = { @@ -255,7 +250,7 @@ PluginMetrics::region_t antarctica = { .num_points = 3 }; -PluginMetrics::region_t unknown_region = { +AoiMetrics::region_t unknown_region = { .name = "unknown_region", .proj = MathLib::PLATE_CARREE, .coords = {}, @@ -264,13 +259,13 @@ PluginMetrics::region_t unknown_region = { }; /****************************************************************************** - * PUBLIC METHODS + * METHODS ******************************************************************************/ /*---------------------------------------------------------------------------- * region2str *----------------------------------------------------------------------------*/ -bool PluginMetrics::init (void) +bool AoiMetrics::init (void) { bool status = true; @@ -284,54 +279,21 @@ bool PluginMetrics::init (void) { region->points[p] = MathLib::coord2point(region->coords[p], region->proj); } - - /* Register Metric */ - regionMetricIds[r] = EventLib::registerMetric(CATEGORY, EventLib::COUNTER, "%s.%s", region->name, REGION_METRIC); - if(regionMetricIds[r] == EventLib::INVALID_METRIC) - { - mlog(ERROR, "Registry failed for %s.%s", region->name, REGION_METRIC); - status = false; - } } return status; } -/*---------------------------------------------------------------------------- - * region2str - *----------------------------------------------------------------------------*/ -PluginMetrics::region_t* PluginMetrics::region2struct (regions_t region) -{ - switch(region) - { - case REGION_CONTINENTAL_US: return &continental_us; - case REGION_ALASKA: return &alaska; - case REGION_CANADA: return &canada; - case REGION_GREENLAND: return &greenland; - case REGION_CENTRAL_AMERICA: return ¢ral_america; - case REGION_SOUTH_AMERICA: return &south_america; - case REGION_AFRICA: return &africa; - case REGION_MIDDLE_EAST: return &middle_east; - case REGION_EUROPE: return &europe; - case REGION_NORTH_ASIA: return &north_asia; - case REGION_SOUTH_ASIA: return &south_asia; - case REGION_OCEANIA: return &oceania; - case REGION_ANTARCTICA: return &antarctica; - case REGION_UNKNOWN: return &unknown_region; - default: return &unknown_region; - } -} /*---------------------------------------------------------------------------- * setRegion *----------------------------------------------------------------------------*/ -bool PluginMetrics::setRegion (Icesat2Parms* parms) +AoiMetrics::regions_t AoiMetrics::setRegion (NetsvcParms* parms) { + regions_t region_found = REGION_UNKNOWN; if(parms->polygon.length() > 0) { MathLib::coord_t coord = parms->polygon[0]; - regions_t region_found = REGION_UNKNOWN; - if(coord.lat > -60) { /* Check Non-Antartica Regions */ @@ -349,21 +311,39 @@ bool PluginMetrics::setRegion (Icesat2Parms* parms) /* Set Region to Antartica */ region_found = REGION_ANTARCTICA; } - - /* Increment Metric for Region */ - EventLib::incrementMetric(regionMetricIds[region_found]); - return true; } - else + return region_found; +} + +/*---------------------------------------------------------------------------- + * region2str + *----------------------------------------------------------------------------*/ +AoiMetrics::region_t* AoiMetrics::region2struct (regions_t region) +{ + switch(region) { - return false; + case REGION_CONTINENTAL_US: return &continental_us; + case REGION_ALASKA: return &alaska; + case REGION_CANADA: return &canada; + case REGION_GREENLAND: return &greenland; + case REGION_CENTRAL_AMERICA: return ¢ral_america; + case REGION_SOUTH_AMERICA: return &south_america; + case REGION_AFRICA: return &africa; + case REGION_MIDDLE_EAST: return &middle_east; + case REGION_EUROPE: return &europe; + case REGION_NORTH_ASIA: return &north_asia; + case REGION_SOUTH_ASIA: return &south_asia; + case REGION_OCEANIA: return &oceania; + case REGION_ANTARCTICA: return &antarctica; + case REGION_UNKNOWN: return &unknown_region; + default: return &unknown_region; } } /*---------------------------------------------------------------------------- * checkRegion *----------------------------------------------------------------------------*/ -bool PluginMetrics::checkRegion (MathLib::coord_t coord, regions_t r) +bool AoiMetrics::checkRegion (MathLib::coord_t coord, regions_t r) { region_t* region = region2struct(r); MathLib::point_t point = MathLib::coord2point(coord, region->proj); diff --git a/plugins/icesat2/plugin/PluginMetrics.h b/packages/netsvc/AoiMetrics.h similarity index 87% rename from plugins/icesat2/plugin/PluginMetrics.h rename to packages/netsvc/AoiMetrics.h index 53bf4d798..9d37fea79 100644 --- a/plugins/icesat2/plugin/PluginMetrics.h +++ b/packages/netsvc/AoiMetrics.h @@ -29,21 +29,22 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __plugin_metrics__ -#define __plugin_metrics__ +#ifndef __aoi_metrics__ +#define __aoi_metrics__ /****************************************************************************** * INCLUDES ******************************************************************************/ #include "OsApi.h" -#include "Icesat2Parms.h" +#include "MathLib.h" +#include "NetsvcParms.h" /****************************************************************************** * METRICS FOR PLUGIN ******************************************************************************/ -class PluginMetrics +class AoiMetrics { public: @@ -83,29 +84,21 @@ class PluginMetrics int num_points; } region_t; - /*-------------------------------------------------------------------- - * Constants - *--------------------------------------------------------------------*/ - - static const char* CATEGORY; - static const char* REGION_METRIC; - /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ static bool init (void); - static region_t* region2struct (regions_t region); - static bool setRegion (Icesat2Parms* parms); - static bool checkRegion (MathLib::coord_t coord, regions_t r); - + static regions_t setRegion (NetsvcParms* parms); + private: /*-------------------------------------------------------------------- - * Data + * Methods *--------------------------------------------------------------------*/ - static int32_t regionMetricIds[NUM_REGIONS]; + static region_t* region2struct (regions_t region); + static bool checkRegion (MathLib::coord_t coord, regions_t r); }; -#endif /* __plugin_metrics__ */ +#endif /* __aoi_metrics__ */ diff --git a/packages/netsvc/CMakeLists.txt b/packages/netsvc/CMakeLists.txt index cc4ca2e6c..e37c9dd74 100644 --- a/packages/netsvc/CMakeLists.txt +++ b/packages/netsvc/CMakeLists.txt @@ -18,6 +18,7 @@ if (CURL_FOUND AND RapidJSON_FOUND) target_sources(slideruleLib PRIVATE ${CMAKE_CURRENT_LIST_DIR}/netsvc.cpp + ${CMAKE_CURRENT_LIST_DIR}/AoiMetrics.cpp ${CMAKE_CURRENT_LIST_DIR}/CurlLib.cpp ${CMAKE_CURRENT_LIST_DIR}/EndpointProxy.cpp ${CMAKE_CURRENT_LIST_DIR}/OrchestratorLib.cpp @@ -34,6 +35,7 @@ if (CURL_FOUND AND RapidJSON_FOUND) install ( FILES ${CMAKE_CURRENT_LIST_DIR}/netsvc.h + ${CMAKE_CURRENT_LIST_DIR}/AoiMetrics.h ${CMAKE_CURRENT_LIST_DIR}/CurlLib.h ${CMAKE_CURRENT_LIST_DIR}/EndpointProxy.h ${CMAKE_CURRENT_LIST_DIR}/OrchestratorLib.h diff --git a/packages/netsvc/EndpointProxy.cpp b/packages/netsvc/EndpointProxy.cpp index 08f5067bb..1769ca160 100644 --- a/packages/netsvc/EndpointProxy.cpp +++ b/packages/netsvc/EndpointProxy.cpp @@ -48,8 +48,8 @@ const char* EndpointProxy::SERVICE = "sliderule"; const char* EndpointProxy::OBJECT_TYPE = "EndpointProxy"; -const char* EndpointProxy::LuaMetaName = "EndpointProxy"; -const struct luaL_Reg EndpointProxy::LuaMetaTable[] = { +const char* EndpointProxy::LUA_META_NAME = "EndpointProxy"; +const struct luaL_Reg EndpointProxy::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -105,12 +105,12 @@ int EndpointProxy::luaCreate (lua_State* L) /* Check Parameters */ if(_num_threads <= 0) throw RunTimeException(CRITICAL, RTE_ERROR, "Number of threads must be greater than zero"); - else if (_num_threads > MAX_PROXY_THREADS) throw RunTimeException(CRITICAL, RTE_ERROR, "Number of threads must be less than %d", MAX_PROXY_THREADS); + if (_num_threads > MAX_PROXY_THREADS) throw RunTimeException(CRITICAL, RTE_ERROR, "Number of threads must be less than %d", MAX_PROXY_THREADS); /* Return Endpoint Proxy Object */ EndpointProxy* ep = new EndpointProxy(L, _endpoint, _resources, _num_resources, _parameters, _timeout_secs, _outq_name, _send_terminator, _num_threads, _rqst_queue_depth); int retcnt = createLuaObject(L, ep); - if(_resources) delete [] _resources; + delete [] _resources; return retcnt; } catch(const RunTimeException& e) @@ -121,7 +121,7 @@ int EndpointProxy::luaCreate (lua_State* L) { delete [] _resources[i]; } - if (_resources) delete [] _resources; + delete [] _resources; return returnLuaStatus(L, false); } @@ -133,7 +133,7 @@ int EndpointProxy::luaCreate (lua_State* L) EndpointProxy::EndpointProxy (lua_State* L, const char* _endpoint, const char** _resources, int _num_resources, const char* _parameters, int _timeout_secs, const char* _outq_name, bool _send_terminator, int _num_threads, int _rqst_queue_depth): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(_resources); assert(_parameters); @@ -223,7 +223,7 @@ EndpointProxy::~EndpointProxy (void) *----------------------------------------------------------------------------*/ void* EndpointProxy::collatorThread (void* parm) { - EndpointProxy* proxy = (EndpointProxy*)parm; + EndpointProxy* proxy = reinterpret_cast(parm); int current_resource = 0; while(proxy->active && (proxy->outQ->getSubCnt() > 0) && (current_resource < proxy->numResources)) @@ -231,13 +231,13 @@ void* EndpointProxy::collatorThread (void* parm) /* Get Available Nodes */ int resources_to_process = proxy->numResources - current_resource; int num_nodes_to_request = MIN(resources_to_process, proxy->numProxyThreads); - OrchestratorLib::NodeList* nodes = OrchestratorLib::lock(SERVICE, num_nodes_to_request, proxy->timeout); + vector* nodes = OrchestratorLib::lock(SERVICE, num_nodes_to_request, proxy->timeout); if(nodes) { - for(int i = 0; i < nodes->length(); i++) + for(unsigned i = 0; i < nodes->size(); i++) { /* Populate Request */ - proxy->nodes[current_resource] = nodes->get(i); + proxy->nodes[current_resource] = nodes->at(i); /* Post Request to Proxy Threads */ int status = MsgQ::STATE_TIMEOUT; @@ -256,7 +256,7 @@ void* EndpointProxy::collatorThread (void* parm) } /* If No Nodes Available */ - if(nodes->length() <= 0) + if(nodes->empty()) { OsApi::sleep(0.20); // 5Hz } @@ -298,7 +298,7 @@ void* EndpointProxy::collatorThread (void* parm) *----------------------------------------------------------------------------*/ void* EndpointProxy::proxyThread (void* parm) { - EndpointProxy* proxy = (EndpointProxy*)parm; + EndpointProxy* proxy = reinterpret_cast(parm); while(proxy->active) { @@ -317,10 +317,10 @@ void* EndpointProxy::proxyThread (void* parm) { try { - SafeString path("/source/%s", proxy->endpoint); - SafeString data("{\"resource\": \"%s\", \"parms\": %s, \"timeout\": %d, \"shard\": %d}", resource, proxy->parameters, proxy->timeout, current_resource); + FString path("/source/%s", proxy->endpoint); + FString data("{\"resource\": \"%s\", \"parms\": %s, \"timeout\": %d, \"shard\": %d}", resource, proxy->parameters, proxy->timeout, current_resource); HttpClient client(NULL, node->member); - HttpClient::rsps_t rsps = client.request(EndpointObject::POST, path.str(), data.str(), false, proxy->outQ, proxy->timeout * 1000); + HttpClient::rsps_t rsps = client.request(EndpointObject::POST, path.c_str(), data.c_str(), false, proxy->outQ, proxy->timeout * 1000); if(rsps.code == EndpointObject::OK) valid = true; else throw RunTimeException(CRITICAL, RTE_ERROR, "Error code returned from request to %s: %d", node->member, (int)rsps.code); } diff --git a/packages/netsvc/EndpointProxy.h b/packages/netsvc/EndpointProxy.h index b6c27242e..3a600b52e 100644 --- a/packages/netsvc/EndpointProxy.h +++ b/packages/netsvc/EndpointProxy.h @@ -63,8 +63,8 @@ class EndpointProxy: public LuaObject static const char* SERVICE; static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/netsvc/NetsvcParms.cpp b/packages/netsvc/NetsvcParms.cpp index 750013164..9fbd805c7 100644 --- a/packages/netsvc/NetsvcParms.cpp +++ b/packages/netsvc/NetsvcParms.cpp @@ -52,8 +52,8 @@ const char* NetsvcParms::READ_TIMEOUT = "read-timeout"; const char* NetsvcParms::GLOBAL_TIMEOUT = "timeout"; const char* NetsvcParms::OBJECT_TYPE = "NetsvcParms"; -const char* NetsvcParms::LuaMetaName = "NetsvcParms"; -const struct luaL_Reg NetsvcParms::LuaMetaTable[] = { +const char* NetsvcParms::LUA_META_NAME = "NetsvcParms"; +const struct luaL_Reg NetsvcParms::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -79,7 +79,7 @@ int NetsvcParms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -92,7 +92,7 @@ int NetsvcParms::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ NetsvcParms::NetsvcParms(lua_State* L, int index): - LuaObject (L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject (L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), raster (NULL), rqst_timeout (DEFAULT_RQST_TIMEOUT), node_timeout (DEFAULT_NODE_TIMEOUT), @@ -164,9 +164,9 @@ NetsvcParms::~NetsvcParms (void) /*---------------------------------------------------------------------------- * cleanup *----------------------------------------------------------------------------*/ -void NetsvcParms::cleanup (void) +void NetsvcParms::cleanup (void) const { - if(raster) delete raster; + delete raster; } /*---------------------------------------------------------------------------- diff --git a/packages/netsvc/NetsvcParms.h b/packages/netsvc/NetsvcParms.h index 28d951465..f88da497c 100644 --- a/packages/netsvc/NetsvcParms.h +++ b/packages/netsvc/NetsvcParms.h @@ -68,8 +68,8 @@ class NetsvcParms: public LuaObject static const int DEFAULT_READ_TIMEOUT = 600; // seconds static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -95,7 +95,7 @@ class NetsvcParms: public LuaObject NetsvcParms (lua_State* L, int index); ~NetsvcParms (void); - void cleanup (void); + void cleanup (void) const; void get_lua_polygon (lua_State* L, int index, bool* provided); void get_lua_raster (lua_State* L, int index, bool* provided); }; diff --git a/packages/netsvc/OrchestratorLib.cpp b/packages/netsvc/OrchestratorLib.cpp index e1d56faf9..ec2c41d8e 100644 --- a/packages/netsvc/OrchestratorLib.cpp +++ b/packages/netsvc/OrchestratorLib.cpp @@ -62,7 +62,7 @@ void OrchestratorLib::init (void) *----------------------------------------------------------------------------*/ void OrchestratorLib::deinit (void) { - if(URL) delete [] URL; + delete [] URL; } /*---------------------------------------------------------------------------- @@ -73,9 +73,9 @@ bool OrchestratorLib::registerService (const char* service, int lifetime, const bool status = true; HttpClient orchestrator(NULL, URL); - SafeString rqst("{\"service\":\"%s\", \"lifetime\": %d, \"address\": \"%s\"}", service, lifetime, address); + FString rqst("{\"service\":\"%s\", \"lifetime\": %d, \"address\": \"%s\"}", service, lifetime, address); - HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/register", rqst.str(), false, NULL); + HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/register", rqst.c_str(), false, NULL); if(rsps.code == EndpointObject::OK) { try @@ -107,7 +107,7 @@ bool OrchestratorLib::registerService (const char* service, int lifetime, const status = false; } - if(rsps.response) delete [] rsps.response; + delete [] rsps.response; return status; } @@ -115,13 +115,13 @@ bool OrchestratorLib::registerService (const char* service, int lifetime, const /*---------------------------------------------------------------------------- * lock *----------------------------------------------------------------------------*/ -OrchestratorLib::NodeList* OrchestratorLib::lock (const char* service, int nodes_needed, int timeout_secs, bool verbose) +vector* OrchestratorLib::lock (const char* service, int nodes_needed, int timeout_secs, bool verbose) { - NodeList* nodes = NULL; + vector* nodes = NULL; HttpClient orchestrator(NULL, URL); - SafeString rqst("{\"service\":\"%s\", \"nodesNeeded\": %d, \"timeout\": %d}", service, nodes_needed, timeout_secs); + FString rqst("{\"service\":\"%s\", \"nodesNeeded\": %d, \"timeout\": %d}", service, nodes_needed, timeout_secs); - HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/lock", rqst.str(), false, NULL); + HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/lock", rqst.c_str(), false, NULL); if(rsps.code == EndpointObject::OK) { try @@ -133,13 +133,13 @@ OrchestratorLib::NodeList* OrchestratorLib::lock (const char* service, int nodes unsigned int num_transactions = json["transactions"].Size(); if(num_members == num_transactions) { - nodes = new NodeList; // allocate node list to be returned + nodes = new vector; // allocate node list to be returned for(rapidjson::SizeType i = 0; i < num_members; i++) { const char* name = json["members"][i].GetString(); double transaction = json["transactions"][i].GetDouble(); Node* node = new Node(name, transaction); - nodes->add(node); + nodes->push_back(node); } } else @@ -149,9 +149,9 @@ OrchestratorLib::NodeList* OrchestratorLib::lock (const char* service, int nodes if(verbose && nodes) { - for(int i = 0; i < nodes->length(); i++) + for(unsigned i = 0; i < nodes->size(); i++) { - mlog(INFO, "Locked - %s <%ld>", nodes->get(i)->member, nodes->get(i)->transaction); + mlog(INFO, "Locked - %s <%ld>", nodes->at(i)->member, nodes->at(i)->transaction); } } } @@ -160,9 +160,9 @@ OrchestratorLib::NodeList* OrchestratorLib::lock (const char* service, int nodes mlog(CRITICAL, "Failed process response to lock: %s", rsps.response); if(nodes) { - for(int i = 0; i < nodes->length(); i++) + for(unsigned i = 0; i < nodes->size(); i++) { - delete nodes->get(i); + delete nodes->at(i); } delete nodes; nodes = NULL; @@ -174,13 +174,13 @@ OrchestratorLib::NodeList* OrchestratorLib::lock (const char* service, int nodes mlog(CRITICAL, "Encountered HTTP error <%d> when locking nodes on %s", rsps.code, service); } - if(rsps.response) delete [] rsps.response; + delete [] rsps.response; return nodes; } /*---------------------------------------------------------------------------- - * lock + * unlock *----------------------------------------------------------------------------*/ bool OrchestratorLib::unlock (long transactions[], int num_transactions, bool verbose) { @@ -189,12 +189,13 @@ bool OrchestratorLib::unlock (long transactions[], int num_transactions, bool ve bool status = true; HttpClient orchestrator(NULL, URL); - SafeString rqst("{\"transactions\": [%ld", transactions[0]); - char txstrbuf[64]; - for(int t = 1; t < num_transactions; t++) rqst += StringLib::format(txstrbuf, 64, ",%ld", transactions[t]); + char strbuf[64]; + string rqst; + rqst += StringLib::format(strbuf, 64, "{\"transactions\": [%ld", transactions[0]); + for(int t = 1; t < num_transactions; t++) rqst += StringLib::format(strbuf, 64, ",%ld", transactions[t]); rqst += "]}"; - HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/unlock", rqst.str(), false, NULL); + HttpClient::rsps_t rsps = orchestrator.request(EndpointObject::POST, "/discovery/unlock", rqst.c_str(), false, NULL); if(rsps.code == EndpointObject::OK) { try @@ -221,7 +222,7 @@ bool OrchestratorLib::unlock (long transactions[], int num_transactions, bool ve status = false; } - if(rsps.response) delete [] rsps.response; + delete [] rsps.response; return status; } @@ -252,7 +253,7 @@ bool OrchestratorLib::health (void) } } - if(rsps.response) delete [] rsps.response; + delete [] rsps.response; return status; } @@ -266,7 +267,7 @@ int OrchestratorLib::luaUrl(lua_State* L) { const char* _url = LuaObject::getLuaString(L, 1); - if(URL) delete [] URL; + delete [] URL; URL = StringLib::duplicate(_url); } catch(const RunTimeException& e) @@ -310,7 +311,7 @@ int OrchestratorLib::luaRegisterService(lua_State* L) *----------------------------------------------------------------------------*/ int OrchestratorLib::luaLock(lua_State* L) { - NodeList* nodes = NULL; + vector* nodes = NULL; try { const char* service = LuaObject::getLuaString(L, 1); @@ -321,11 +322,11 @@ int OrchestratorLib::luaLock(lua_State* L) nodes = lock(service, nodes_needed, timeout_secs, verbose); lua_newtable(L); - for(int i = 0; i < nodes->length(); i++) + for(unsigned i = 0; i < nodes->size(); i++) { - SafeString txidstr("%ld", nodes->get(i)->transaction); - LuaEngine::setAttrStr(L, txidstr.str(), nodes->get(i)->member); - delete nodes->get(i); // free node after using it + FString txidstr("%ld", nodes->at(i)->transaction); + LuaEngine::setAttrStr(L, txidstr.c_str(), nodes->at(i)->member); + delete nodes->at(i); // free node after using it } } catch(const RunTimeException& e) @@ -334,7 +335,7 @@ int OrchestratorLib::luaLock(lua_State* L) lua_pushnil(L); } - if(nodes) delete nodes; + delete nodes; return 1; } diff --git a/packages/netsvc/OrchestratorLib.h b/packages/netsvc/OrchestratorLib.h index 1a463148a..e5de0d69b 100644 --- a/packages/netsvc/OrchestratorLib.h +++ b/packages/netsvc/OrchestratorLib.h @@ -65,8 +65,6 @@ class OrchestratorLib } }; - typedef List NodeList; - /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ @@ -75,7 +73,7 @@ class OrchestratorLib static void deinit (void); static bool registerService (const char* service, int lifetime, const char* address, bool verbose=false); - static NodeList* lock (const char* service, int nodes_needed, int timeout_secs, bool verbose=false); + static vector* lock (const char* service, int nodes_needed, int timeout_secs, bool verbose=false); static bool unlock (long transactions[], int num_transactions, bool verbose=false); static bool health (void); diff --git a/packages/netsvc/ProvisioningSystemLib.cpp b/packages/netsvc/ProvisioningSystemLib.cpp index 5bb97b59b..82e2e2167 100644 --- a/packages/netsvc/ProvisioningSystemLib.cpp +++ b/packages/netsvc/ProvisioningSystemLib.cpp @@ -48,7 +48,7 @@ * Local Functions *----------------------------------------------------------------------------*/ -size_t write2nothing(char* ptr, size_t size, size_t nmemb, void* userdata) +size_t write2nothing(const char* ptr, size_t size, size_t nmemb, void* userdata) { (void)ptr; (void)userdata; @@ -76,8 +76,8 @@ void ProvisioningSystemLib::init (void) *----------------------------------------------------------------------------*/ void ProvisioningSystemLib::deinit (void) { - if(URL) delete [] URL; - if(Organization) delete [] Organization; + delete [] URL; + delete [] Organization; } /*---------------------------------------------------------------------------- @@ -90,13 +90,13 @@ const char* ProvisioningSystemLib::login (const char* username, const char* pass try { /* Build API URL */ - SafeString url_str("%s/api/org_token/", URL); + FString url_str("%s/api/org_token/", URL); /* Build Bearer Token Header */ - SafeString hdr_str("Content-Type: application/json"); + FString hdr_str("Content-Type: application/json"); /* Initialize Request */ - SafeString data_str("{\"username\":\"%s\",\"password\":\"%s\",\"org_name\":\"%s\"}", username, password, organization); + FString data_str("{\"username\":\"%s\",\"password\":\"%s\",\"org_name\":\"%s\"}", username, password, organization); /* Initialize Response */ List rsps_set; @@ -106,17 +106,17 @@ const char* ProvisioningSystemLib::login (const char* username, const char* pass if(curl) { /* Set cURL Options */ - curl_easy_setopt(curl, CURLOPT_URL, url_str.str()); + curl_easy_setopt(curl, CURLOPT_URL, url_str.c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); // seconds curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L); // seconds - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data_str.str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data_str.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ProvisioningSystemLib::writeData); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &rsps_set); /* Set Content-Type Header */ struct curl_slist* headers = NULL; - headers = curl_slist_append(headers, hdr_str.str()); + headers = curl_slist_append(headers, hdr_str.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); /* Perform the request, res will get the return code */ @@ -166,7 +166,7 @@ const char* ProvisioningSystemLib::login (const char* username, const char* pass catch(const RunTimeException& e) { mlog(e.level(), "Error on login: %s", e.what()); - if(rsps) delete [] rsps; + delete [] rsps; rsps = NULL; } @@ -184,24 +184,24 @@ bool ProvisioningSystemLib::validate (const char* access_token, bool verbose) try { /* Build API URL */ - SafeString url_str("%s/api/membership_status/%s/", URL, Organization); + FString url_str("%s/api/membership_status/%s/", URL, Organization); /* Build Bearer Token Header */ - SafeString hdr_str("Authorization: Bearer %s", access_token); + FString hdr_str("Authorization: Bearer %s", access_token); /* Initialize cURL */ CURL* curl = curl_easy_init(); if(curl) { /* Set cURL Options */ - curl_easy_setopt(curl, CURLOPT_URL, url_str.str()); + curl_easy_setopt(curl, CURLOPT_URL, url_str.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write2nothing); /* Set Bearer Token Header */ struct curl_slist* headers = NULL; - headers = curl_slist_append(headers, hdr_str.str()); + headers = curl_slist_append(headers, hdr_str.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); /* Perform the request, res will get the return code */ @@ -251,7 +251,7 @@ int ProvisioningSystemLib::luaUrl(lua_State* L) { const char* _url = LuaObject::getLuaString(L, 1); - if(URL) delete [] URL; + delete [] URL; URL = StringLib::duplicate(_url); } catch(const RunTimeException& e) @@ -275,7 +275,7 @@ int ProvisioningSystemLib::luaSetOrganization(lua_State* L) { const char* _organization = LuaObject::getLuaString(L, 1); - if(Organization) delete [] Organization; + delete [] Organization; Organization = StringLib::duplicate(_organization); } catch(const RunTimeException& e) @@ -382,14 +382,13 @@ bool ProvisioningSystemLib::Authenticator::isValid (const char* token) { return true; // no authentication used for default organization name } - else if(token != NULL) + + if(token != NULL) { return ProvisioningSystemLib::validate(token); } - else - { - return false; - } + + return false; } /*---------------------------------------------------------------------------- diff --git a/packages/netsvc/ProvisioningSystemLib.h b/packages/netsvc/ProvisioningSystemLib.h index 955c4fd67..885b50103 100644 --- a/packages/netsvc/ProvisioningSystemLib.h +++ b/packages/netsvc/ProvisioningSystemLib.h @@ -93,8 +93,8 @@ class ProvisioningSystemLib { public: static int luaCreate (lua_State* L); - Authenticator(lua_State* L); - ~Authenticator(void); + explicit Authenticator(lua_State* L); + ~Authenticator(void) override; bool isValid(const char* token) override; }; }; diff --git a/packages/netsvc/netsvc.cpp b/packages/netsvc/netsvc.cpp index 712aa691f..b4e591573 100644 --- a/packages/netsvc/netsvc.cpp +++ b/packages/netsvc/netsvc.cpp @@ -88,6 +88,7 @@ extern "C" { void initnetsvc (void) { /* Initialize Modules */ + AoiMetrics::init(); CurlLib::init(); OrchestratorLib::init(); ProvisioningSystemLib::init(); diff --git a/packages/netsvc/netsvc.h b/packages/netsvc/netsvc.h index 89d0ac83d..26d1dcf53 100644 --- a/packages/netsvc/netsvc.h +++ b/packages/netsvc/netsvc.h @@ -36,6 +36,7 @@ * INCLUDES ******************************************************************************/ +#include "AoiMetrics.h" #include "CurlLib.h" #include "EndpointProxy.h" #include "OrchestratorLib.h" diff --git a/packages/pistache/PistacheClient.cpp b/packages/pistache/PistacheClient.cpp index a3230c48d..f58377ed0 100644 --- a/packages/pistache/PistacheClient.cpp +++ b/packages/pistache/PistacheClient.cpp @@ -43,8 +43,8 @@ using namespace Pistache; * STATIC DATA ******************************************************************************/ -const char* PistacheClient::LuaMetaName = "PistacheClient"; -const struct luaL_Reg PistacheClient::LuaMetaTable[] = { +const char* PistacheClient::LUA_META_NAME = "PistacheClient"; +const struct luaL_Reg PistacheClient::LUA_META_TABLE[] = { {"request", luaRequest}, {NULL, NULL} }; @@ -75,7 +75,7 @@ int PistacheClient::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -88,7 +88,7 @@ int PistacheClient::luaCreate (lua_State* L) * Constructor *----------------------------------------------------------------------------*/ PistacheClient::PistacheClient(lua_State* L, const char* outq_name, size_t num_threads): - LuaObject(L, BASE_OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, BASE_OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { /* Create Output Queue */ outQ = NULL; @@ -123,13 +123,12 @@ PistacheClient::~PistacheClient(void) int PistacheClient::luaRequest(lua_State* L) { bool status = false; - bool in_error = false; int num_obj_to_return = 1; try { /* Get Self */ - PistacheClient* lua_obj = (PistacheClient*)getLuaSelf(L, 1); + PistacheClient* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Action */ PistacheServer::verb_t action = PistacheServer::INVALID; @@ -176,7 +175,8 @@ int PistacheClient::luaRequest(lua_State* L) } else if(action == PistacheServer::POST) { - SafeString lua_result; + bool in_error = false; + string lua_result; auto resp = lua_obj->client.post(url).body(body).send(); resp.then( [&](Http::Response response) { @@ -224,7 +224,7 @@ int PistacheClient::luaRequest(lua_State* L) { if(lua_obj->requestSignal.wait(REQUEST_SIGNAL, timeout)) { - lua_pushlstring(L, lua_result.str(), lua_result.bytes()); + lua_pushlstring(L, lua_result.c_str(), lua_result.size() + 1); num_obj_to_return = 2; status = true; } diff --git a/packages/pistache/PistacheClient.h b/packages/pistache/PistacheClient.h index 3985bf484..3dc8dce25 100644 --- a/packages/pistache/PistacheClient.h +++ b/packages/pistache/PistacheClient.h @@ -57,8 +57,8 @@ class PistacheClient: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods diff --git a/packages/pistache/PistacheServer.cpp b/packages/pistache/PistacheServer.cpp index 54585ded7..685132418 100644 --- a/packages/pistache/PistacheServer.cpp +++ b/packages/pistache/PistacheServer.cpp @@ -44,13 +44,13 @@ using namespace Rest; * STATIC DATA ******************************************************************************/ -const char* PistacheServer::LuaMetaName = "PistacheServer"; -const struct luaL_Reg PistacheServer::LuaMetaTable[] = { +const char* PistacheServer::LUA_META_NAME = "PistacheServer"; +const struct luaL_Reg PistacheServer::LUA_META_TABLE[] = { {"route", luaRoute}, {NULL, NULL} }; -StringLib::String PistacheServer::serverHead("sliderule/%s", LIBID); +FString PistacheServer::serverHead("sliderule/%s", LIBID); const char* PistacheServer::RESPONSE_QUEUE = "rspq"; @@ -78,7 +78,7 @@ int PistacheServer::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -102,11 +102,10 @@ PistacheServer::verb_t PistacheServer::str2verb (const char* str) *----------------------------------------------------------------------------*/ const char* PistacheServer::sanitize (const char* filename) { - SafeString delimeter("%c", PATH_DELIMETER); - SafeString safe_filename("%s", filename); - safe_filename.replace(delimeter.str(), "_"); - SafeString safe_pathname("%s%c%s%c%s.lua", CONFDIR, PATH_DELIMETER, "api", PATH_DELIMETER, safe_filename.str()); - return safe_pathname.str(true); + const char* safe_filename = StringLib::replace(filename, PATH_DELIMETER_STR, "_"); + FString safe_pathname(0, "%s%c%s%c%s.lua", CONFDIR, PATH_DELIMETER, "api", PATH_DELIMETER, safe_filename); + delete [] safe_filename; + return safe_pathname.c_str(true); } /*---------------------------------------------------------------------------- @@ -130,7 +129,7 @@ long PistacheServer::getUniqueId (char id_str[REQUEST_ID_LEN]) * Constructor *----------------------------------------------------------------------------*/ PistacheServer::PistacheServer(lua_State* L, Address addr, size_t num_threads): - LuaObject(L, BASE_OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, BASE_OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), requestId(0), numThreads(num_threads), httpEndpoint(std::make_shared(addr)) @@ -181,7 +180,7 @@ void PistacheServer::echoHandler (const Rest::Request& request, Http::ResponseWr mlog(DEBUG, "request: %s at %s", id_str, request.resource().c_str()); /* Build Header */ - response.headers().add(serverHead.str()); + response.headers().add(serverHead.c_str()); response.headers().add(MIME(Text, Plain)); /* Send Response */ @@ -206,14 +205,14 @@ void PistacheServer::infoHandler (const Rest::Request& request, Http::ResponseWr mlog(DEBUG, "request: %s at %s", id_str, request.resource().c_str()); /* Build Header */ - response.headers().add(serverHead.str()); + response.headers().add(serverHead.c_str()); response.headers().add(MIME(Text, Plain)); /* Build Response */ - SafeString rsp("{\"apis\": [\"/echo\", \"/info\", \"/source/:name\", \"/engine/:name\"] }"); + FString rsp("{\"apis\": [\"/echo\", \"/info\", \"/source/:name\", \"/engine/:name\"] }"); /* Send Response */ - response.send(Http::Code::Ok, rsp.str()); + response.send(Http::Code::Ok, rsp.c_str()); /* Stop Trace */ stop_trace(CRITICAL, trace_id); @@ -237,7 +236,7 @@ void PistacheServer::sourceHandler (const Rest::Request& request, Http::Response mlog(DEBUG, "request: %s at %s", id_str, request.resource().c_str()); /* Build Header */ - response.headers().add(serverHead.str()); + response.headers().add(serverHead.c_str()); response.headers().add(MIME(Text, Plain)); /* Launch Engine */ @@ -289,7 +288,7 @@ void PistacheServer::engineHandler (const Rest::Request& request, Http::Response mlog(DEBUG, "request: %s at %s", id_str, request.resource().c_str()); /* Build Header */ - response.headers().add(serverHead.str()); + response.headers().add(serverHead.c_str()); response.headers().add(MIME(Application, OctetStream)); /* Create Engine */ @@ -347,7 +346,7 @@ void PistacheServer::engineHandler (const Rest::Request& request, Http::Response *----------------------------------------------------------------------------*/ void* PistacheServer::serverThread (void* parm) { - PistacheServer* server = (PistacheServer*)parm; + PistacheServer* server = static_cast(parm); try { @@ -372,7 +371,7 @@ int PistacheServer::luaRoute(lua_State* L) try { /* Get Self */ - PistacheServer* lua_obj = (PistacheServer*)getLuaSelf(L, 1); + PistacheServer* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Action */ verb_t action = INVALID; @@ -396,7 +395,7 @@ int PistacheServer::luaRoute(lua_State* L) const char* url = getLuaString(L, 3); /* Get Route Handler */ - RouteHandler* handler = (RouteHandler*)getLuaObject(L, 4, RouteHandler::OBJECT_TYPE); + RouteHandler* handler = dynamic_cast(getLuaObject(L, 4, RouteHandler::OBJECT_TYPE)); /* Set Route */ if(action == GET) diff --git a/packages/pistache/PistacheServer.h b/packages/pistache/PistacheServer.h index 1a3758e44..d9aa0295b 100644 --- a/packages/pistache/PistacheServer.h +++ b/packages/pistache/PistacheServer.h @@ -57,8 +57,8 @@ class PistacheServer: public LuaObject * Constants *--------------------------------------------------------------------*/ - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const int REQUEST_ID_LEN = MAX_STR_SIZE; static const int MAX_RESPONSE_TIME_MS = 5000; @@ -68,7 +68,7 @@ class PistacheServer: public LuaObject * Data *--------------------------------------------------------------------*/ - static StringLib::String serverHead; + static FString serverHead; /*-------------------------------------------------------------------- * Types diff --git a/packages/pistache/ProgressMessager.cpp b/packages/pistache/ProgressMessager.cpp index 9fa84b061..de49bed6c 100644 --- a/packages/pistache/ProgressMessager.cpp +++ b/packages/pistache/ProgressMessager.cpp @@ -47,8 +47,8 @@ RecordObject::fieldDef_t ProgressMessager::rec_def[] = }; const char* ProgressMessager::OBJECT_TYPE = "ProgressMessager"; -const char* ProgressMessager::LuaMetaName = "ProgressMessager"; -const struct luaL_Reg ProgressMessager::LuaMetaTable[] = { +const char* ProgressMessager::LUA_META_NAME = "ProgressMessager"; +const struct luaL_Reg ProgressMessager::LUA_META_TABLE[] = { {"post", luaPost}, {NULL, NULL} }; @@ -89,12 +89,12 @@ void ProgressMessager::init (void) * Constructor *----------------------------------------------------------------------------*/ ProgressMessager::ProgressMessager (lua_State* L, const char* rspq_name): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(rspq_name); rspQ = new Publisher(rspq_name); record = new RecordObject(rec_type); - progressMessage = (progress_message_t*)record->getRecordData(); + progressMessage = reinterpret_cast(record->getRecordData()); } @@ -117,7 +117,7 @@ int ProgressMessager::luaPost (lua_State* L) try { /* Get Self */ - ProgressMessager* lua_obj = (ProgressMessager*)getLuaSelf(L, 1); + ProgressMessager* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Parameters */ const char* message = getLuaString(L, 2); diff --git a/packages/pistache/ProgressMessager.h b/packages/pistache/ProgressMessager.h index afc5c9103..3bb2478a4 100644 --- a/packages/pistache/ProgressMessager.h +++ b/packages/pistache/ProgressMessager.h @@ -60,8 +60,8 @@ class ProgressMessager: public LuaObject static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types diff --git a/platforms/linux/Cond.cpp b/platforms/linux/Cond.cpp index 6dc611728..9008aac79 100644 --- a/platforms/linux/Cond.cpp +++ b/platforms/linux/Cond.cpp @@ -47,7 +47,7 @@ /*---------------------------------------------------------------------------- * Constructor *----------------------------------------------------------------------------*/ -Cond::Cond(int num_sigs): Mutex() +Cond::Cond(int num_sigs) { assert(num_sigs > 0); numSigs = num_sigs; @@ -119,6 +119,5 @@ bool Cond::wait(int sig, int timeout_ms) } /* Return Status */ - if(status == 0) return true; - else return false; + return (status == 0); } diff --git a/platforms/linux/OsApi.cpp b/platforms/linux/OsApi.cpp index f55e2f5bc..b71ca0f03 100644 --- a/platforms/linux/OsApi.cpp +++ b/platforms/linux/OsApi.cpp @@ -150,14 +150,13 @@ int64_t OsApi::timeres(int clkid) { return 1000000; // microseconds } - else if (clkid == CPU_CLK) + + if (clkid == CPU_CLK) { return 1000000; // microseconds } - else - { - return 0; - } + + return 0; } /*---------------------------------------------------------------------------- @@ -191,7 +190,7 @@ float OsApi::swapf(float val) { float rtrndata = 0.0; uint8_t* dataptr = (uint8_t*)&rtrndata; - uint32_t* tempf = (uint32_t*)&val; + uint32_t* tempf = (uint32_t*)(char*)&val; *(uint32_t*)(dataptr) = bswap_32(*tempf); return rtrndata; } @@ -203,7 +202,7 @@ double OsApi::swaplf(double val) { double rtrndata = 0.0; uint8_t* dataptr = (uint8_t*)&rtrndata; - uint64_t* tempd = (uint64_t*)&val; + uint64_t* tempd = (uint64_t*)(char*)&val; *(uint64_t*)(dataptr) = bswap_64(*tempd); return rtrndata; } @@ -224,7 +223,6 @@ double OsApi::memusage (void) const int BUFSIZE = 128; const char* mem_total_ptr = NULL; const char* mem_available_ptr = NULL; - int i = 0; char buffer[BUFSIZE]; char *endptr; @@ -237,7 +235,7 @@ double OsApi::memusage (void) buffer[bytes_read] = '\0'; /* Find MemTotal */ - i = 9; // start after colon + int i = 9; // start after colon while(buffer[i] == ' ') i++; // moves one past space mem_total_ptr = &buffer[i]; // mark start while(buffer[i] != ' ') i++; // stays at first space @@ -280,15 +278,11 @@ double OsApi::memusage (void) /* Calculate Memory Usage */ return 1.0 - ((double)mem_available / (double)mem_total); } - else - { - return 0.0; - } - } - else - { + return 0.0; } + + return 0.0; } /*---------------------------------------------------------------------------- @@ -314,7 +308,7 @@ void OsApi::print (const char* file_name, unsigned int line_number, const char* else { /* Default */ - printf("%s:%d %s\n", file_name, line_number, message); + printf("%s:%u %s\n", file_name, line_number, message); } } diff --git a/platforms/linux/OsApi.h b/platforms/linux/OsApi.h index 256d4eda8..4b5e6ba38 100644 --- a/platforms/linux/OsApi.h +++ b/platforms/linux/OsApi.h @@ -178,6 +178,20 @@ CompileTimeAssert(sizeof(bool)==1, TypeboolWrongSize); #include "SockLib.h" #include "TTYLib.h" +/****************************************************************************** + * Standard Template Classes + ******************************************************************************/ + +#include +#include +#include + +using std::shared_ptr; +using std::unique_ptr; +using std::make_shared; +using std::vector; +using std::string; + /****************************************************************************** * LIBRARY CLASS ******************************************************************************/ diff --git a/platforms/linux/Sem.cpp b/platforms/linux/Sem.cpp index 5cf359b57..e72b24d9c 100644 --- a/platforms/linux/Sem.cpp +++ b/platforms/linux/Sem.cpp @@ -115,6 +115,5 @@ bool Sem::take(int timeout_ms) } /* Return Status */ - if(status == 0) return true; - else return false; + return (status == 0); } diff --git a/platforms/linux/SockLib.cpp b/platforms/linux/SockLib.cpp index d6a0bc5b4..28cb5888c 100644 --- a/platforms/linux/SockLib.cpp +++ b/platforms/linux/SockLib.cpp @@ -112,7 +112,7 @@ void SockLib::init() else if(host != NULL) { uint32_t addr = ((struct in_addr*)host->h_addr_list[0])->s_addr; - snprintf(ipv4, IPV4_STR_LEN, "%d.%d.%d.%d", addr & 0xFF, (addr >> 8) & 0xFF, (addr >> 16) & 0xFF, (addr >> 24) & 0xFF); + snprintf(ipv4, IPV4_STR_LEN, "%u.%u.%u.%u", addr & 0xFF, (addr >> 8) & 0xFF, (addr >> 16) & 0xFF, (addr >> 24) & 0xFF); } } @@ -145,68 +145,67 @@ int SockLib::sockstream(const char* ip_addr, int port, bool is_server, bool* blo { return sock; } - else // server - { - int listen_socket = sock; - int server_socket = INVALID_RC; - - /* Make Socket a Listen Socket */ - if(listen(listen_socket, 1) != 0) - { - dlog("Failed to mark socket bound to %s:%d as a listen socket, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); - close(listen_socket); - return INVALID_RC; - } + + // server + int listen_socket = sock; + int server_socket = INVALID_RC; - do { - /* Build Poll Structure */ - struct pollfd polllist[1]; - polllist[0].fd = listen_socket; - polllist[0].events = POLLIN; - polllist[0].revents = 0; - - /* Poll Listener */ - int activity = 0; - do activity = poll(polllist, 1, SYS_TIMEOUT); - while(activity == -1 && (errno == EINTR || errno == EAGAIN)); + /* Make Socket a Listen Socket */ + if(listen(listen_socket, 1) != 0) + { + dlog("Failed to mark socket bound to %s:%d as a listen socket, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); + close(listen_socket); + return INVALID_RC; + } - /* Accept Connection */ - if((activity > 0) && (polllist[0].revents & POLLIN)) - { - server_socket = accept(listen_socket, NULL, NULL); - } - } while(server_socket == INVALID_RC && block && *block && !signal_exit); + do { + /* Build Poll Structure */ + struct pollfd polllist[1]; + polllist[0].fd = listen_socket; + polllist[0].events = POLLIN; + polllist[0].revents = 0; - /* Shutdown Listen Socket */ - shutdown(listen_socket, SHUT_RDWR); - close(listen_socket); + /* Poll Listener */ + int activity = 0; + do activity = poll(polllist, 1, SYS_TIMEOUT); + while(activity == -1 && (errno == EINTR || errno == EAGAIN)); - /* Check Acceptance */ - if(server_socket < 0) + /* Accept Connection */ + if((activity > 0) && (polllist[0].revents & POLLIN)) { - dlog("Failed to accept connection on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); - return INVALID_RC; + server_socket = accept(listen_socket, NULL, NULL); } + } while(server_socket == INVALID_RC && block && *block && !signal_exit); - /* Set Keep Alive on Socket */ - if(sockkeepalive(server_socket) < 0) - { - dlog("Failed to set keep alive on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); - sockclose(server_socket); - return INVALID_RC; - } + /* Shutdown Listen Socket */ + shutdown(listen_socket, SHUT_RDWR); + close(listen_socket); - /* Make Socket Non-Blocking */ - if(socknonblock(server_socket) < 0) - { - dlog("Failed to set non-blocking on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); - sockclose(server_socket); - return INVALID_RC; - } + /* Check Acceptance */ + if(server_socket < 0) + { + dlog("Failed to accept connection on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); + return INVALID_RC; + } - /* Return Server Socket */ - return server_socket; + /* Set Keep Alive on Socket */ + if(sockkeepalive(server_socket) < 0) + { + dlog("Failed to set keep alive on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); + sockclose(server_socket); + return INVALID_RC; } + + /* Make Socket Non-Blocking */ + if(socknonblock(server_socket) < 0) + { + dlog("Failed to set non-blocking on %s:%d, %s", ip_addr ? ip_addr : "0.0.0.0", port, strerror(errno)); + sockclose(server_socket); + return INVALID_RC; + } + + /* Return Server Socket */ + return server_socket; } /*---------------------------------------------------------------------------- @@ -232,10 +231,7 @@ int SockLib::sockdatagram(const char* ip_addr, int port, bool is_server, bool* b sockclose(sock); return INVALID_RC; } - else - { - dlog("Configured socket on %s:%d to receive multicast packets on %s", ip_addr, port, multicast_group); - } + dlog("Configured socket on %s:%d to receive multicast packets on %s", ip_addr, port, multicast_group); } else { @@ -259,7 +255,6 @@ int SockLib::sockdatagram(const char* ip_addr, int port, bool is_server, bool* b *----------------------------------------------------------------------------*/ int SockLib::socksend(int fd, const void* buf, int size, int timeout) { - int activity = 1; int revents = POLLOUT; int c = TIMEOUT_RC; @@ -272,6 +267,8 @@ int SockLib::socksend(int fd, const void* buf, int size, int timeout) if(timeout != IO_CHECK) { + int activity = 1; + /* Build Poll Structure */ struct pollfd polllist[1]; polllist[0].fd = fd; @@ -377,7 +374,8 @@ int SockLib::sockinfo(int fd, char** local_ipaddr, int* local_port, char** remot if(local_ipaddr) { *local_ipaddr = new char[16]; - strcpy(*local_ipaddr, inet_ntoa(local_addr.sin_addr)); + strncpy(*local_ipaddr, inet_ntoa(local_addr.sin_addr), 16); + (*local_ipaddr)[15] = '\0'; } /* Populate Local Port */ @@ -390,7 +388,8 @@ int SockLib::sockinfo(int fd, char** local_ipaddr, int* local_port, char** remot if(remote_ipaddr) { *remote_ipaddr = new char[16]; - strcpy(*remote_ipaddr, inet_ntoa(remote_addr.sin_addr)); + strncpy(*remote_ipaddr, inet_ntoa(remote_addr.sin_addr), 16); + (*remote_ipaddr)[15] = '\0'; } /* Populate Remote Port */ @@ -417,7 +416,7 @@ void SockLib::sockclose(int fd) /*---------------------------------------------------------------------------- * startserver *----------------------------------------------------------------------------*/ -int SockLib::startserver(const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, bool* active, void* parm, bool* listening) +int SockLib::startserver(const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, const bool* active, void* parm, bool* listening) { int status = 0; @@ -425,7 +424,6 @@ int SockLib::startserver(const char* ip_addr, int port, int max_num_connections, int num_sockets = 0; int max_num_sockets = max_num_connections + 1; // add in listener struct pollfd* polllist = new struct pollfd [max_num_sockets]; - int* flags = new int [max_num_sockets]; /* Create Listen Socket */ int listen_socket = sockcreate(SOCK_STREAM, ip_addr, port, true, NULL); @@ -639,7 +637,6 @@ int SockLib::startserver(const char* ip_addr, int port, int max_num_connections, /* Clean Up Allocated Memory */ delete [] polllist; - delete [] flags; /* Return Status */ return status; @@ -648,7 +645,7 @@ int SockLib::startserver(const char* ip_addr, int port, int max_num_connections, /*---------------------------------------------------------------------------- * startclient *----------------------------------------------------------------------------*/ -int SockLib::startclient(const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, bool* active, void* parm, bool* connected) +int SockLib::startclient(const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, const bool* active, void* parm, bool* connected) { /* Initialize Connection Variables */ bool _connected = false; @@ -698,10 +695,9 @@ int SockLib::startclient(const char* ip_addr, int port, int max_num_connections, dlog("Unable to create client socket on %s:%d", ip_addr ? ip_addr : "0.0.0.0", port); return -1; } - else // timeout - { - OsApi::performIOTimeout(); - } + + /* Timeout */ + OsApi::performIOTimeout(); } } @@ -778,9 +774,11 @@ const char* SockLib::sockipv4 (void) /*---------------------------------------------------------------------------- * sockcreate *----------------------------------------------------------------------------*/ -int SockLib::sockcreate(int type, const char* ip_addr, int port, bool is_server, bool* block) +int SockLib::sockcreate(int type, const char* ip_addr, int port, bool is_server, const bool* block) { - struct addrinfo hints, *result, *rp; + struct addrinfo hints; + struct addrinfo* result; + struct addrinfo* rp; int sock = INVALID_RC; int status = -1; // start with error condition char portstr[PORT_STR_LEN]; diff --git a/platforms/linux/SockLib.h b/platforms/linux/SockLib.h index ef19676ee..14157a66c 100644 --- a/platforms/linux/SockLib.h +++ b/platforms/linux/SockLib.h @@ -59,8 +59,8 @@ class SockLib static int sockrecv (int fd, void* buf, int size, int timeout); static int sockinfo (int fd, char** local_ipaddr, int* local_port, char** remote_ipaddr, int* remote_port); static void sockclose (int fd); - static int startserver (const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, bool* active, void* parm, bool* listening=NULL); - static int startclient (const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, bool* active, void* parm, bool* connected=NULL); + static int startserver (const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, const bool* active, void* parm, bool* listening=NULL); + static int startclient (const char* ip_addr, int port, int max_num_connections, onPollHandler_t on_poll, onActiveHandler_t on_act, const bool* active, void* parm, bool* connected=NULL); static const char* sockhost (void); static const char* sockipv4 (void); @@ -70,7 +70,7 @@ class SockLib static char local_host_name[HOST_STR_LEN]; static char ipv4[IPV4_STR_LEN]; - static int sockcreate (int type, const char* ip_addr, int port, bool is_server, bool* block); + static int sockcreate (int type, const char* ip_addr, int port, bool is_server, const bool* block); static int sockoptions (int socket_fd, bool reuse, bool tcp); static int sockkeepalive (int socket_fd, int idle=60, int cnt=12, int intvl=5); static int sockreuse (int socket_fd); diff --git a/platforms/linux/TTYLib.cpp b/platforms/linux/TTYLib.cpp index c8d8453af..6f9c95a3d 100644 --- a/platforms/linux/TTYLib.cpp +++ b/platforms/linux/TTYLib.cpp @@ -226,8 +226,8 @@ int TTYLib::ttywrite(int fd, const void* buf, int size, int timeout) else if(revents & POLLOUT) { int ret = write(fd, &cbuf[c], size - c); - if(ret > 0) c += ret; - else if(ret <= 0) c = TTY_ERR_RC; + if(ret > 0) c += ret; + else c = TTY_ERR_RC; } } diff --git a/plugins/atlas/CMakeLists.txt b/plugins/atlas/CMakeLists.txt index ab773ea08..0fb2bf166 100644 --- a/plugins/atlas/CMakeLists.txt +++ b/plugins/atlas/CMakeLists.txt @@ -1,15 +1,8 @@ # ATLAS SlideRule Plugin top-level CMake build script project (ATLAS LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) ################ # ATLAS Plugin # @@ -23,13 +16,6 @@ set_target_properties (atlas PROPERTIES PREFIX "") # Prerequisites # find_package (Lua "5.3") -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) - -# Set Environment Variables -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (atlas PUBLIC BINID="${TGTVER}") target_compile_definitions (atlas PUBLIC __gnu__) @@ -52,6 +38,7 @@ target_sources(atlas ${CMAKE_CURRENT_LIST_DIR}/plugin/CmdEchoProcessorModule.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/DiagLogProcessorModule.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/HstvsSimulator.cpp + ${CMAKE_CURRENT_LIST_DIR}/plugin/SafeString.cpp ) # Include Directories # diff --git a/plugins/atlas/plugin/ItosRecord.cpp b/plugins/atlas/plugin/ItosRecord.cpp index 950199ace..651352e02 100644 --- a/plugins/atlas/plugin/ItosRecord.cpp +++ b/plugins/atlas/plugin/ItosRecord.cpp @@ -82,7 +82,8 @@ void Record::addSubRecord(Record* record) *----------------------------------------------------------------------------*/ void Record::addValue(const char* value) { - subvalues.add(value); + SafeString str(value); + subvalues.add(str); } /*---------------------------------------------------------------------------- @@ -162,7 +163,7 @@ Record* Record::getSubRecord(int index) *----------------------------------------------------------------------------*/ const char* Record::getSubValue(int index) { - return subvalues[index]; + return subvalues[index].str(); } /*---------------------------------------------------------------------------- @@ -287,7 +288,8 @@ TypeConversion::~TypeConversion(void) *----------------------------------------------------------------------------*/ void TypeConversion::addEnumLookup(const char* enum_name, const char* value) { - lookup.add(enum_name, value); + SafeString* valstr = new SafeString(value); + lookup.add(enum_name, valstr); } /*---------------------------------------------------------------------------- @@ -297,7 +299,7 @@ const char* TypeConversion::getEnumValue(const char* enum_name) { try { - return lookup.get(enum_name); + return lookup[enum_name]->str(); } catch(RunTimeException& e) { diff --git a/plugins/atlas/plugin/ItosRecord.h b/plugins/atlas/plugin/ItosRecord.h index 17ac19163..8a7280a2c 100644 --- a/plugins/atlas/plugin/ItosRecord.h +++ b/plugins/atlas/plugin/ItosRecord.h @@ -100,7 +100,7 @@ namespace Itos const char* type; const char* name; List subrecords; - List subvalues; + List subvalues; const char* comment; }; @@ -154,7 +154,7 @@ namespace Itos type_conv_t type; const char* name; - Dictionary lookup; + Dictionary lookup; }; /************************************************* diff --git a/plugins/atlas/plugin/ItosRecordParser.cpp b/plugins/atlas/plugin/ItosRecordParser.cpp index 9e3a43a71..02f310d61 100644 --- a/plugins/atlas/plugin/ItosRecordParser.cpp +++ b/plugins/atlas/plugin/ItosRecordParser.cpp @@ -1055,7 +1055,7 @@ void ItosRecordParser::createMnemonics (void) mlog(INFO, "Generating definition for mnemonic: %s", mnem->getName()); /* Create Name List */ - List namelist; + List namelist; bool instantiated = false; char* tmpname = (char*)mnem->getName(); char* dotptr = strstr(tmpname, "."); @@ -1071,7 +1071,7 @@ void ItosRecordParser::createMnemonics (void) Record* instrec = instlist->get(i); char newname[Record::MAX_TOKEN_SIZE]; snprintf(newname, Record::MAX_TOKEN_SIZE, "%s.%s", instrec->getName(), dotptr + 1); - const char* instname = StringLib::duplicate(newname); + SafeString instname(newname); namelist.add(instname); } } @@ -1080,7 +1080,7 @@ void ItosRecordParser::createMnemonics (void) /* Not Instantiated */ if(!instantiated) { - const char* instname = mnem->getName(); + SafeString instname(mnem->getName()); namelist.add(instname); } @@ -1089,7 +1089,7 @@ void ItosRecordParser::createMnemonics (void) { /* Initialize Mnemonic Definition */ Mnemonic* def = new Mnemonic; - def->name = namelist[n]; + def->name = namelist[n].str(true); def->type = NULL; def->source = NULL; def->source_packet = NULL; @@ -1852,12 +1852,12 @@ void ItosRecordParser::generateReport(const char* reporttemplate, const char* su snprintf (timestr, 25, "%d:%d", timeinfo.year, timeinfo.doy); /* Generate Content */ - List pktptrs; + List pktptrs; SafeString pktreport(1000); for(int p = 0; p < packets.length(); p++) { Packet* packet = packets[p]; - const char* pkthtml = createPacketDetails(packet); + SafeString pkthtml(createPacketDetails(packet)); pktptrs.add(pkthtml); pktreport += pkthtml; } @@ -1928,7 +1928,7 @@ void ItosRecordParser::generateReport(const char* reporttemplate, const char* su /* Generate Packet Summary from Template */ for(int i = 0; i < pktptrs.length(); i++) { - const char* pkthtml = (const char*)pktptrs[i]; + const char* pkthtml = pktptrs[i].str(); const char* pktname = packets[i]->getName(); SafeString* pktsummary = readFile(summarytemplate); if(pktsummary == NULL) diff --git a/plugins/atlas/plugin/ItosRecordParser.h b/plugins/atlas/plugin/ItosRecordParser.h index 4ffbdf400..dcfa285b5 100644 --- a/plugins/atlas/plugin/ItosRecordParser.h +++ b/plugins/atlas/plugin/ItosRecordParser.h @@ -70,7 +70,7 @@ class ItosRecordParser: public CommandableObject MgDictionary dictionary; // key'ed database of all records - Dictionary*> instantiations; // given a system prototype name, gives list of instantiated system records + Dictionary*, false> instantiations; // given a system prototype name, gives list of instantiated system records MgList declarations; // zero-depth records in rec files MgList packets; // list of all the packet definitions: commands, telemetry diff --git a/plugins/atlas/plugin/SafeString.cpp b/plugins/atlas/plugin/SafeString.cpp new file mode 100644 index 000000000..16cca4a49 --- /dev/null +++ b/plugins/atlas/plugin/SafeString.cpp @@ -0,0 +1,619 @@ +/* + * Copyright (c) 2021, University of Washington + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the University of Washington nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS + * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************** + * INCLUDES + ******************************************************************************/ + +#include "SafeString.h" +#include "StringLib.h" +#include "OsApi.h" + +#include +#include +#include + + +/****************************************************************************** + * SAFE STRING PUBLIC METHODS + ******************************************************************************/ + +/*---------------------------------------------------------------------------- + * Constructor + *----------------------------------------------------------------------------*/ +SafeString::SafeString(long _maxlen) +{ + if(_maxlen <= 0) maxlen = DEFAULT_STR_SIZE; + else maxlen = _maxlen; + carray = new char[maxlen]; + carray[0] ='\0'; + len = 1; +} + +/*---------------------------------------------------------------------------- + * Constructor + *----------------------------------------------------------------------------*/ +SafeString::SafeString(long _maxlen, const char* _str, ...) +{ + if(_str != NULL) + { + va_list args; + va_start(args, _str); + len = vsnprintf(NULL, _maxlen, _str, args) + 1; // get length + va_end(args); + carray = new char[len]; // allocate memory + maxlen = len; + va_start(args, _str); + vsprintf(carray, _str, args); // copy in formatted contents + va_end(args); + carray[maxlen - 1] ='\0'; // null terminate + } + else + { + maxlen = DEFAULT_STR_SIZE; + carray = new char[maxlen]; + carray[0] = '\0'; + len = 1; + } +} + +/*---------------------------------------------------------------------------- + * Constructor + *----------------------------------------------------------------------------*/ +SafeString::SafeString(const char* _str) +{ + maxlen = strlen(_str) + 1; + carray = new char[maxlen]; + len = maxlen; + StringLib::copy(carray, _str, len); + carray[len - 1] = '\0'; +} + +/*---------------------------------------------------------------------------- + * Constructor (COPY) + *----------------------------------------------------------------------------*/ +SafeString::SafeString(const SafeString& other) +{ + maxlen = other.maxlen; + carray = new char[maxlen]; + len = other.len; + StringLib::copy(carray, other.carray, len); + carray[len - 1] = '\0'; +} + +/*---------------------------------------------------------------------------- + * Constructor (ENCODE) + *----------------------------------------------------------------------------*/ +SafeString::SafeString (int base, unsigned char* buffer, int size) +{ + if(base == 64) + { + int encoded_len = size; + carray = StringLib::b64encode(buffer, &encoded_len); + maxlen = encoded_len; + len = encoded_len; + } + else + { + maxlen = DEFAULT_STR_SIZE; + carray = new char[maxlen]; + memset(carray, 0, maxlen); + len = 1; + } +} + +/*---------------------------------------------------------------------------- + * Destructor + *----------------------------------------------------------------------------*/ +SafeString::~SafeString(void) +{ + delete [] carray; +} + +/*---------------------------------------------------------------------------- + * getString + *----------------------------------------------------------------------------*/ +const char* SafeString::str(bool duplicate) +{ + if(duplicate) + { + char* new_str = new char[len]; + StringLib::copy(new_str, carray, len); + return new_str; + } + + return carray; +} + +/*---------------------------------------------------------------------------- + * length - number of non-null characters in string + *----------------------------------------------------------------------------*/ +long SafeString::length(void) const +{ + return len - 1; // remove null terminator in length +} + +/*---------------------------------------------------------------------------- + * bytes - size of memory needed to store string (includes null terminator) + *----------------------------------------------------------------------------*/ +long SafeString::bytes(void) const +{ + return len; +} + +/*---------------------------------------------------------------------------- + * appendChar + *----------------------------------------------------------------------------*/ +void SafeString::appendChar(char c) +{ + if(len >= maxlen) + { + maxlen *= 2; // optimization + char* new_str = new char[maxlen]; + memset(new_str, 0, maxlen); + StringLib::copy(new_str, carray, len); + delete [] carray; + carray = new_str; + } + + carray[len-1] = c; + carray[len] = '\0'; + len++; +} + +/*---------------------------------------------------------------------------- + * findChar + *----------------------------------------------------------------------------*/ +int SafeString::findChar (char c, int start) +{ + if(start >= 0) + { + for(int i = start; i < len; i++) + { + if(carray[i] == c) + { + return i; + } + } + } + + return -1; +} + +/*---------------------------------------------------------------------------- + * setChar + *----------------------------------------------------------------------------*/ +SafeString& SafeString::setChar (char c, int index) +{ + if(index >= 0 && index < len) + { + carray[index] = c; + } + return *this; +} + +/*---------------------------------------------------------------------------- + * replace + * + * replaces all occurrences + *----------------------------------------------------------------------------*/ +bool SafeString::replace(const char* oldtxt, const char* newtxt) +{ + bool status = false; + + int newtxtlen = (int)strlen(newtxt); + char* startptr = strstr(carray, oldtxt); + char* endptr = startptr + strlen(oldtxt); + + while(startptr != NULL) + { + status = true; + + maxlen += newtxtlen; + char* newstr = new char[maxlen]; + memset(newstr, 0, maxlen); + + memcpy(newstr, carray, (startptr - carray)); + memcpy(newstr + (startptr - carray), newtxt, newtxtlen); + memcpy(newstr + (startptr - carray) + newtxtlen, endptr, len - (endptr - carray)); + + delete [] carray; + carray = newstr; + + len = (int)strlen(carray) + 1; + + startptr = strstr(carray, oldtxt); + endptr = startptr + strlen(oldtxt); + } + + return status; +} + +/*---------------------------------------------------------------------------- + * inreplace + * + * replaces all occurrences in place + *----------------------------------------------------------------------------*/ +bool SafeString::inreplace (const char* oldtxt[], const char* newtxt[], int num_replacements) +{ + /* Check Number of Replacements */ + if(num_replacements > MAX_REPLACEMENTS) + { + return false; + } + + /* Get Delta Sizes for each Replacement */ + int replacement_size_delta[MAX_REPLACEMENTS]; + for(int r = 0; r < num_replacements; r++) + { + replacement_size_delta[r] = strlen(newtxt[r]) - strlen(oldtxt[r]); + } + + /* Count Number of Replacements */ + int replacement_count[MAX_REPLACEMENTS]; + for(int r = 0; r < num_replacements; r++) + { + replacement_count[r] = 0; + int i = 0; + while(i < (len - 1)) + { + int j = i; + int k = 0; + while((j < (len - 1)) && oldtxt[r][k] && (carray[j] == oldtxt[r][k])) + { + j++; + k++; + } + + if(oldtxt[r][k] == '\0') + { + replacement_count[r]++; + i = j; + } + else + { + i++; + } + } + } + + /* Calculate Size of New String */ + int total_size_delta = 0; + for(int r = 0; r < num_replacements; r++) + { + total_size_delta += replacement_size_delta[r] * replacement_count[r]; + } + + /* Set New Size */ + int new_size = len + total_size_delta; + if(new_size > 0) + { + len = new_size; + maxlen = new_size; + } + else + { + len = 1; + maxlen = 1; + carray[0] = '\0'; + return true; + } + + /* Allocate New String */ + char* newstr = new char [maxlen]; + + /* Populate New String */ + int orig_i = 0; + int new_i = 0; + while(carray[orig_i]) + { + /* For Each Possible Replacement */ + bool replacement = false; + for(int r = 0; r < num_replacements; r++) + { + /* Check for Match */ + int j = orig_i; + int k = 0; + while(carray[j] && oldtxt[r][k] && (carray[j] == oldtxt[r][k])) + { + j++; + k++; + } + + /* Replace Matched Text */ + if(oldtxt[r][k] == '\0') + { + int i = 0; + while(newtxt[r][i]) + { + newstr[new_i++] = newtxt[r][i++]; + } + orig_i = j; + replacement = true; + break; + } + } + + /* Copy Over and Advance String Indices */ + if(!replacement) + { + newstr[new_i++] = carray[orig_i++]; + } + } + + /* Terminate New String and Replace Existing String */ + newstr[new_i] = '\0'; + delete [] carray; + carray = newstr; + + return true; +} + +/*---------------------------------------------------------------------------- + * urlize + * + * ! # $ & ' ( ) * + + * %21 %23 %24 %26 %27 %28 %29 %2A %2B + * + * , / : ; = ? @ [ ] + * %2C %2F %3A %3B %3D %3F %40 %5B %5D + *----------------------------------------------------------------------------*/ +SafeString& SafeString::urlize(void) +{ + /* Allocate enough room to hold urlized string */ + if(maxlen < (len * 3)) + { + maxlen = len * 3; + } + + /* Setup pointers to new and old strings */ + char* alloc_str = new char [maxlen]; + char* new_str = alloc_str; + char* old_str = carray; + + /* Translate old string into new string */ + while(*old_str != '\0') + { + switch (*old_str) + { + case '!': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '1'; break; + case '#': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '3'; break; + case '$': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '4'; break; + case '&': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '6'; break; + case '\'': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '7'; break; + case '(': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '8'; break; + case ')': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = '9'; break; + case '*': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'A'; break; + case '+': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'B'; break; + case ',': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'C'; break; + case '/': *(new_str++) = '%'; *(new_str++) = '2'; *(new_str++) = 'F'; break; + case ':': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'A'; break; + case ';': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'B'; break; + case '=': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'D'; break; + case '?': *(new_str++) = '%'; *(new_str++) = '3'; *(new_str++) = 'F'; break; + case '@': *(new_str++) = '%'; *(new_str++) = '4'; *(new_str++) = '0'; break; + case '[': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'B'; break; + case ']': *(new_str++) = '%'; *(new_str++) = '5'; *(new_str++) = 'D'; break; + default: *(new_str++) = *old_str; break; + } + old_str++; + } + *(new_str++) = '\0'; + + /* Calculate length of new string */ + len = new_str - alloc_str; + + /* Replace member string */ + delete [] carray; + carray = alloc_str; + + /* Return Self */ + return *this; +} + +/*---------------------------------------------------------------------------- + * split + *----------------------------------------------------------------------------*/ +List* SafeString::split(char separator, bool strip) +{ + List* tokens = new List; + + int i = 0; + while(i < length() && carray[i] != '\0') + { + char token[MAX_STR_SIZE]; + int t = 0; + + /* Create Token */ + while( (i < length()) && (carray[i] != '\0') && (carray[i] == separator) ) i++; // find first character + while( (i < length()) && (carray[i] != '\0') && (carray[i] != separator) && (t < (MAX_STR_SIZE - 1))) token[t++] = carray[i++]; // copy characters in + token[t++] = '\0'; + + /* Strip Leading and Trailing Spaces */ + int s1 = 0; + if(strip) + { + int s2 = t-1; + while( (s1 < t) && isspace(token[s1]) ) s1++; + while( (s2 > s1) && isspace(token[s2]) ) s2--; + token[++s2] = '\0'; + } + + /* Add Token to List */ + if(t > 1) + { + string* s = new string(&token[s1]); + tokens->add(s); + } + } + + return tokens; +} + +/*---------------------------------------------------------------------------- + * operator[] + *----------------------------------------------------------------------------*/ +char SafeString::operator[](int index) +{ + if(index >= 0 && index < len) + { + return carray[index]; + } + + return '\0'; +} + +/*---------------------------------------------------------------------------- + * operator+= + *----------------------------------------------------------------------------*/ +SafeString& SafeString::operator+=(const SafeString& rhs) +{ + if((len + rhs.len) < (maxlen - 1)) + { + StringLib::concat(carray, rhs.carray, maxlen); + len += rhs.len; + } + else + { + maxlen += rhs.maxlen; + char* new_str = new char[maxlen]; + memset(new_str, 0, maxlen); + StringLib::copy(new_str, carray, maxlen); + StringLib::concat(new_str, rhs.carray, maxlen); + len = (int)strlen(new_str) + 1; + delete [] carray; + carray = new_str; + } + + return *this; +} + +/*---------------------------------------------------------------------------- + * operator+= + *----------------------------------------------------------------------------*/ +SafeString& SafeString::operator+=(const char* rstr) +{ + int rlen = (int)strlen(rstr); + + if((len + rlen) < (maxlen - 1)) + { + StringLib::concat(carray, rstr, maxlen); + len += rlen; + } + else + { + maxlen += rlen + 1; + maxlen *= 2; // optimization + char* new_str = new char[maxlen]; + memset(new_str, 0, maxlen); + StringLib::copy(new_str, carray, maxlen); + StringLib::concat(new_str, rstr, maxlen); + len = (int)strlen(new_str) + 1; + delete [] carray; + carray = new_str; + } + + return *this; +} + +/*---------------------------------------------------------------------------- + * operator= + *----------------------------------------------------------------------------*/ +SafeString& SafeString::operator=(const SafeString& rhs) +{ + if(maxlen < rhs.len) + { + delete [] carray; + maxlen = rhs.maxlen; + carray = new char[maxlen]; + } + + StringLib::copy(carray, rhs.carray, rhs.len); + len = rhs.len; + + return *this; +} + +/*---------------------------------------------------------------------------- + * operator= + *----------------------------------------------------------------------------*/ +SafeString& SafeString::operator=(const char* rstr) +{ + if(rstr) + { + int rlen = (int)strlen(rstr); + if(rlen <= 0) + { + carray[0] = '\0'; + len = 1; + } + else if(maxlen < rlen) + { + delete [] carray; + maxlen = rlen; + carray = new char[maxlen]; + } + + StringLib::copy(carray, rstr, rlen); + len = rlen + 1; + } + else + { + delete [] carray; + maxlen = DEFAULT_STR_SIZE; + carray = new char[maxlen]; + memset(carray, 0, maxlen); + len = 1; + } + + return *this; +} + +/*---------------------------------------------------------------------------- + * operator+ + *----------------------------------------------------------------------------*/ +SafeString operator+(SafeString lhs, const SafeString& rhs) +{ + lhs += rhs; + return lhs; +} + +/*---------------------------------------------------------------------------- + * reset + *----------------------------------------------------------------------------*/ +void SafeString::reset(void) +{ + delete [] carray; + maxlen = DEFAULT_STR_SIZE; + carray = new char[maxlen]; + memset(carray, 0, maxlen); + len = 1; +} diff --git a/targets/binding-python/pyLua.h b/plugins/atlas/plugin/SafeString.h similarity index 54% rename from targets/binding-python/pyLua.h rename to plugins/atlas/plugin/SafeString.h index 7c8ed6e74..8a288b673 100644 --- a/targets/binding-python/pyLua.h +++ b/plugins/atlas/plugin/SafeString.h @@ -29,37 +29,56 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __py_lua__ -#define __py_lua__ +#ifndef __safe_string__ +#define __safe_string__ /****************************************************************************** * INCLUDES ******************************************************************************/ -#include -#include "LuaEngine.h" +#include "OsApi.h" +#include "List.h" /****************************************************************************** - * NAMESPACES + * SAFE STRING CLASS ******************************************************************************/ -namespace py = pybind11; - -/****************************************************************************** - * pyLua Class - ******************************************************************************/ - -class pyLua +class SafeString { public: - pyLua (const std::string &scriptpath, const std::string &scriptarg); - ~pyLua (void); - const char* result (void); + + static const long DEFAULT_STR_SIZE = 64; + static const int MAX_REPLACEMENTS = 16; + + SafeString (long _maxlen=DEFAULT_STR_SIZE); + SafeString (long _maxlen, const char* _str, ...) VARG_CHECK(printf, 3, 4); + explicit SafeString (const char* _str); + SafeString (const SafeString& other); + SafeString (int base, unsigned char* buffer, int size); + ~SafeString (void); + + const char* str (bool duplicate = false); + long length (void) const; + long bytes (void) const; + void appendChar (char c); + int findChar (char c, int start=0); + SafeString& setChar (char c, int index); + bool replace (const char* oldtxt, const char* newtxt); + bool inreplace (const char* oldtxt[], const char* newtxt[], int num_replacements); + SafeString& urlize (void); + List* split (char separator, bool strip=true); + char operator[] (int index); + SafeString& operator+= (const SafeString& rhs); + SafeString& operator+= (const char* rstr); + SafeString& operator= (const SafeString& rhs); + SafeString& operator= (const char* rstr); + void reset (void); private: - static const int MAX_RUNTIME_MS = 10000; // 10 seconds - LuaEngine* luaEngine; - const char* luaResult; + + char* carray; + long len; + long maxlen; }; -#endif /* __py_lua__ */ \ No newline at end of file +#endif /* __string_lib__ */ diff --git a/plugins/atlas/plugin/atlas.h b/plugins/atlas/plugin/atlas.h index b1d4ea188..1307af2e0 100644 --- a/plugins/atlas/plugin/atlas.h +++ b/plugins/atlas/plugin/atlas.h @@ -56,6 +56,7 @@ #include "CmdEchoProcessorModule.h" #include "DiagLogProcessorModule.h" #include "HstvsSimulator.h" +#include "SafeString.h" /****************************************************************************** * PROTOTYPES diff --git a/plugins/gedi/CMakeLists.txt b/plugins/gedi/CMakeLists.txt index 025fab6a7..c8270d206 100644 --- a/plugins/gedi/CMakeLists.txt +++ b/plugins/gedi/CMakeLists.txt @@ -1,21 +1,8 @@ # GEDI SlideRule Plugin top-level CMake build script project (GEDI LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) ############### # GEDI Plugin # @@ -30,16 +17,11 @@ set_target_properties (gedi PROPERTIES PREFIX "") find_package (Lua "5.3") find_package (GDAL) -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) +# Build Information # execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (gedi PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (gedi PUBLIC BINID="${TGTVER}") target_compile_options (gedi PUBLIC -Wall) # turn on "all" warnings diff --git a/plugins/gedi/plugin/FootprintReader.h b/plugins/gedi/plugin/FootprintReader.h index dc64541ee..0885832b1 100644 --- a/plugins/gedi/plugin/FootprintReader.h +++ b/plugins/gedi/plugin/FootprintReader.h @@ -65,8 +65,8 @@ class FootprintReader: public LuaObject static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types @@ -100,7 +100,7 @@ class FootprintReader: public LuaObject { public: - Region (info_t* info); + explicit Region (info_t* info); ~Region (void); void cleanup (void); @@ -161,10 +161,10 @@ template const char* FootprintReader::OBJECT_TYPE = "FootprintReader"; template -const char* FootprintReader::LuaMetaName = "FootprintReader"; +const char* FootprintReader::LUA_META_NAME = "FootprintReader"; template -const struct luaL_Reg FootprintReader::LuaMetaTable[] = { +const struct luaL_Reg FootprintReader::LUA_META_TABLE[] = { {"stats", luaStats}, {NULL, NULL} }; @@ -181,7 +181,7 @@ FootprintReader::FootprintReader ( lua_State* L, Asset* _asset, con const char* outq_name, GediParms* _parms, bool _send_terminator, const char* batch_rec_type, const char* lat_name, const char* lon_name, subset_func_t subsetter ): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), read_timeout_ms(_parms->read_timeout * 1000), batchRecord(batch_rec_type, sizeof(batch_t)) { @@ -305,8 +305,8 @@ FootprintReader::~FootprintReader (void) *----------------------------------------------------------------------------*/ template FootprintReader::Region::Region (info_t* info): - lat (info->reader->asset, info->reader->resource, SafeString("%s/%s", GediParms::beam2group(info->beam), info->reader->latName).str(), &info->reader->context), - lon (info->reader->asset, info->reader->resource, SafeString("%s/%s", GediParms::beam2group(info->beam), info->reader->lonName).str(), &info->reader->context), + lat (info->reader->asset, info->reader->resource, FString("%s/%s", GediParms::beam2group(info->beam), info->reader->latName).c_str(), &info->reader->context), + lon (info->reader->asset, info->reader->resource, FString("%s/%s", GediParms::beam2group(info->beam), info->reader->lonName).c_str(), &info->reader->context), inclusion_mask (NULL), inclusion_ptr (NULL) { @@ -359,7 +359,7 @@ FootprintReader::Region::~Region (void) template void FootprintReader::Region::cleanup (void) { - if(inclusion_mask) delete [] inclusion_mask; + delete [] inclusion_mask; } /*---------------------------------------------------------------------------- diff --git a/plugins/gedi/plugin/Gedi01bReader.cpp b/plugins/gedi/plugin/Gedi01bReader.cpp index c095b854a..16a64328d 100644 --- a/plugins/gedi/plugin/Gedi01bReader.cpp +++ b/plugins/gedi/plugin/Gedi01bReader.cpp @@ -82,10 +82,10 @@ int Gedi01bReader::luaCreate (lua_State* L) try { /* Get Parameters */ - asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* resource = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); - parms = (GediParms*)getLuaObject(L, 4, GediParms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 4, GediParms::OBJECT_TYPE)); bool send_terminator = getLuaBoolean(L, 5, true, true); /* Return Reader Object */ @@ -131,16 +131,16 @@ Gedi01bReader::~Gedi01bReader (void) * Gedi01b::Constructor *----------------------------------------------------------------------------*/ Gedi01bReader::Gedi01b::Gedi01b (info_t* info, Region& region): - shot_number (info->reader->asset, info->reader->resource, SafeString("%s/shot_number", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - delta_time (info->reader->asset, info->reader->resource, SafeString("%s/geolocation/delta_time", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - elev_bin0 (info->reader->asset, info->reader->resource, SafeString("%s/geolocation/elevation_bin0", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - elev_lastbin (info->reader->asset, info->reader->resource, SafeString("%s/geolocation/elevation_lastbin",GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - solar_elevation (info->reader->asset, info->reader->resource, SafeString("%s/geolocation/solar_elevation", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - degrade_flag (info->reader->asset, info->reader->resource, SafeString("%s/geolocation/degrade", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - tx_sample_count (info->reader->asset, info->reader->resource, SafeString("%s/tx_sample_count", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - tx_start_index (info->reader->asset, info->reader->resource, SafeString("%s/tx_sample_start_index", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - rx_sample_count (info->reader->asset, info->reader->resource, SafeString("%s/rx_sample_count", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - rx_start_index (info->reader->asset, info->reader->resource, SafeString("%s/rx_sample_start_index", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) + shot_number (info->reader->asset, info->reader->resource, FString("%s/shot_number", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + delta_time (info->reader->asset, info->reader->resource, FString("%s/geolocation/delta_time", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + elev_bin0 (info->reader->asset, info->reader->resource, FString("%s/geolocation/elevation_bin0", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + elev_lastbin (info->reader->asset, info->reader->resource, FString("%s/geolocation/elevation_lastbin",GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + solar_elevation (info->reader->asset, info->reader->resource, FString("%s/geolocation/solar_elevation", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + degrade_flag (info->reader->asset, info->reader->resource, FString("%s/geolocation/degrade", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + tx_sample_count (info->reader->asset, info->reader->resource, FString("%s/tx_sample_count", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + tx_start_index (info->reader->asset, info->reader->resource, FString("%s/tx_sample_start_index", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + rx_sample_count (info->reader->asset, info->reader->resource, FString("%s/rx_sample_count", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + rx_start_index (info->reader->asset, info->reader->resource, FString("%s/rx_sample_start_index", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) { /* Join Hardcoded Reads */ shot_number.join(info->reader->read_timeout_ms, true); @@ -169,7 +169,7 @@ void* Gedi01bReader::subsettingThread (void* parm) { /* Get Thread Info */ info_t* info = (info_t*)parm; - Gedi01bReader* reader = (Gedi01bReader*)info->reader; + Gedi01bReader* reader = static_cast(info->reader); GediParms* parms = reader->parms; stats_t local_stats = {0, 0, 0, 0, 0}; @@ -190,8 +190,8 @@ void* Gedi01bReader::subsettingThread (void* parm) long txN = gedi01b.tx_start_index[region.num_footprints - 1] - 1 + gedi01b.tx_sample_count[region.num_footprints - 1] - tx0; long rx0 = gedi01b.rx_start_index[0] - 1; long rxN = gedi01b.rx_start_index[region.num_footprints - 1] - 1 + gedi01b.rx_sample_count[region.num_footprints - 1] - rx0; - H5Array txwaveform(info->reader->asset, info->reader->resource, SafeString("%s/txwaveform", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, tx0, txN); - H5Array rxwaveform(info->reader->asset, info->reader->resource, SafeString("%s/rxwaveform", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, rx0, rxN); + H5Array txwaveform(info->reader->asset, info->reader->resource, FString("%s/txwaveform", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, tx0, txN); + H5Array rxwaveform(info->reader->asset, info->reader->resource, FString("%s/rxwaveform", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, rx0, rxN); txwaveform.join(info->reader->read_timeout_ms, true); rxwaveform.join(info->reader->read_timeout_ms, true); @@ -225,7 +225,7 @@ void* Gedi01bReader::subsettingThread (void* parm) /* Populate Entry in Batch Structure */ g01b_footprint_t* fp = &reader->batchData->footprint[reader->batchIndex]; fp->shot_number = gedi01b.shot_number[footprint]; - fp->time_ns = parms->deltatime2timestamp(gedi01b.delta_time[footprint]); + fp->time_ns = GediParms::deltatime2timestamp(gedi01b.delta_time[footprint]); fp->latitude = region.lat[footprint]; fp->longitude = region.lon[footprint]; fp->elevation_start = gedi01b.elev_bin0[footprint]; diff --git a/plugins/gedi/plugin/Gedi02aReader.cpp b/plugins/gedi/plugin/Gedi02aReader.cpp index 3ace06058..e6a9425af 100644 --- a/plugins/gedi/plugin/Gedi02aReader.cpp +++ b/plugins/gedi/plugin/Gedi02aReader.cpp @@ -79,10 +79,10 @@ int Gedi02aReader::luaCreate (lua_State* L) try { /* Get Parameters */ - asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* resource = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); - parms = (GediParms*)getLuaObject(L, 4, GediParms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 4, GediParms::OBJECT_TYPE)); bool send_terminator = getLuaBoolean(L, 5, true, true); /* Return Reader Object */ @@ -128,15 +128,15 @@ Gedi02aReader::~Gedi02aReader (void) * Gedi02a::Constructor *----------------------------------------------------------------------------*/ Gedi02aReader::Gedi02a::Gedi02a (info_t* info, Region& region): - shot_number (info->reader->asset, info->reader->resource, SafeString("%s/shot_number", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - delta_time (info->reader->asset, info->reader->resource, SafeString("%s/delta_time", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - elev_lowestmode (info->reader->asset, info->reader->resource, SafeString("%s/elev_lowestmode", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - elev_highestreturn (info->reader->asset, info->reader->resource, SafeString("%s/elev_highestreturn", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - solar_elevation (info->reader->asset, info->reader->resource, SafeString("%s/solar_elevation", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - sensitivity (info->reader->asset, info->reader->resource, SafeString("%s/sensitivity", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - degrade_flag (info->reader->asset, info->reader->resource, SafeString("%s/degrade_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - quality_flag (info->reader->asset, info->reader->resource, SafeString("%s/quality_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - surface_flag (info->reader->asset, info->reader->resource, SafeString("%s/surface_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) + shot_number (info->reader->asset, info->reader->resource, FString("%s/shot_number", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + delta_time (info->reader->asset, info->reader->resource, FString("%s/delta_time", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + elev_lowestmode (info->reader->asset, info->reader->resource, FString("%s/elev_lowestmode", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + elev_highestreturn (info->reader->asset, info->reader->resource, FString("%s/elev_highestreturn", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + solar_elevation (info->reader->asset, info->reader->resource, FString("%s/solar_elevation", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + sensitivity (info->reader->asset, info->reader->resource, FString("%s/sensitivity", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + degrade_flag (info->reader->asset, info->reader->resource, FString("%s/degrade_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + quality_flag (info->reader->asset, info->reader->resource, FString("%s/quality_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + surface_flag (info->reader->asset, info->reader->resource, FString("%s/surface_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) { /* Join Hardcoded Reads */ @@ -165,7 +165,7 @@ void* Gedi02aReader::subsettingThread (void* parm) { /* Get Thread Info */ info_t* info = (info_t*)parm; - Gedi02aReader* reader = (Gedi02aReader*)info->reader; + Gedi02aReader* reader = static_cast(info->reader); GediParms* parms = reader->parms; stats_t local_stats = {0, 0, 0, 0, 0}; @@ -231,7 +231,7 @@ void* Gedi02aReader::subsettingThread (void* parm) /* Populate Entry in Batch Structure */ g02a_footprint_t* fp = &reader->batchData->footprint[reader->batchIndex]; fp->shot_number = Gedi02a.shot_number[footprint]; - fp->time_ns = parms->deltatime2timestamp(Gedi02a.delta_time[footprint]); + fp->time_ns = GediParms::deltatime2timestamp(Gedi02a.delta_time[footprint]); fp->latitude = region.lat[footprint]; fp->longitude = region.lon[footprint]; fp->elevation_lowestmode = Gedi02a.elev_lowestmode[footprint]; diff --git a/plugins/gedi/plugin/Gedi03Raster.h b/plugins/gedi/plugin/Gedi03Raster.h index cbfcb6b00..591d63394 100644 --- a/plugins/gedi/plugin/Gedi03Raster.h +++ b/plugins/gedi/plugin/Gedi03Raster.h @@ -64,7 +64,7 @@ class Gedi03Raster: public GeoRaster Gedi03Raster(lua_State* L, GeoParms* _parms) : GeoRaster(L, _parms, - std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()).c_str(), + std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()), TimeLib::datetime2gps(2022, 1, 19), true /* Data is elevation */) {} }; diff --git a/plugins/gedi/plugin/Gedi04aReader.cpp b/plugins/gedi/plugin/Gedi04aReader.cpp index 0c9a93d6c..78270f5ae 100644 --- a/plugins/gedi/plugin/Gedi04aReader.cpp +++ b/plugins/gedi/plugin/Gedi04aReader.cpp @@ -80,10 +80,10 @@ int Gedi04aReader::luaCreate (lua_State* L) try { /* Get Parameters */ - asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* resource = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); - parms = (GediParms*)getLuaObject(L, 4, GediParms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 4, GediParms::OBJECT_TYPE)); bool send_terminator = getLuaBoolean(L, 5, true, true); /* Return Reader Object */ @@ -129,16 +129,16 @@ Gedi04aReader::~Gedi04aReader (void) * Gedi04a::Constructor *----------------------------------------------------------------------------*/ Gedi04aReader::Gedi04a::Gedi04a (info_t* info, Region& region): - shot_number (info->reader->asset, info->reader->resource, SafeString("%s/shot_number", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - delta_time (info->reader->asset, info->reader->resource, SafeString("%s/delta_time", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - agbd (info->reader->asset, info->reader->resource, SafeString("%s/agbd", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - elev_lowestmode (info->reader->asset, info->reader->resource, SafeString("%s/elev_lowestmode", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - solar_elevation (info->reader->asset, info->reader->resource, SafeString("%s/solar_elevation", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - sensitivity (info->reader->asset, info->reader->resource, SafeString("%s/sensitivity", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - degrade_flag (info->reader->asset, info->reader->resource, SafeString("%s/degrade_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - l2_quality_flag (info->reader->asset, info->reader->resource, SafeString("%s/l2_quality_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - l4_quality_flag (info->reader->asset, info->reader->resource, SafeString("%s/l4_quality_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), - surface_flag (info->reader->asset, info->reader->resource, SafeString("%s/surface_flag", GediParms::beam2group(info->beam)).str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) + shot_number (info->reader->asset, info->reader->resource, FString("%s/shot_number", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + delta_time (info->reader->asset, info->reader->resource, FString("%s/delta_time", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + agbd (info->reader->asset, info->reader->resource, FString("%s/agbd", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + elev_lowestmode (info->reader->asset, info->reader->resource, FString("%s/elev_lowestmode", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + solar_elevation (info->reader->asset, info->reader->resource, FString("%s/solar_elevation", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + sensitivity (info->reader->asset, info->reader->resource, FString("%s/sensitivity", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + degrade_flag (info->reader->asset, info->reader->resource, FString("%s/degrade_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + l2_quality_flag (info->reader->asset, info->reader->resource, FString("%s/l2_quality_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + l4_quality_flag (info->reader->asset, info->reader->resource, FString("%s/l4_quality_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints), + surface_flag (info->reader->asset, info->reader->resource, FString("%s/surface_flag", GediParms::beam2group(info->beam)).c_str(), &info->reader->context, 0, region.first_footprint, region.num_footprints) { /* Join Hardcoded Reads */ @@ -168,7 +168,7 @@ void* Gedi04aReader::subsettingThread (void* parm) { /* Get Thread Info */ info_t* info = (info_t*)parm; - Gedi04aReader* reader = (Gedi04aReader*)info->reader; + Gedi04aReader* reader = static_cast(info->reader); GediParms* parms = reader->parms; stats_t local_stats = {0, 0, 0, 0, 0}; @@ -244,7 +244,7 @@ void* Gedi04aReader::subsettingThread (void* parm) /* Populate Entry in Batch Structure */ g04a_footprint_t* fp = &reader->batchData->footprint[reader->batchIndex]; fp->shot_number = gedi04a.shot_number[footprint]; - fp->time_ns = parms->deltatime2timestamp(gedi04a.delta_time[footprint]); + fp->time_ns = GediParms::deltatime2timestamp(gedi04a.delta_time[footprint]); fp->latitude = region.lat[footprint]; fp->longitude = region.lon[footprint]; fp->agbd = gedi04a.agbd[footprint]; diff --git a/plugins/gedi/plugin/Gedi04bRaster.h b/plugins/gedi/plugin/Gedi04bRaster.h index b1f55efe6..121034e37 100644 --- a/plugins/gedi/plugin/Gedi04bRaster.h +++ b/plugins/gedi/plugin/Gedi04bRaster.h @@ -63,7 +63,7 @@ class Gedi04bRaster: public GeoRaster Gedi04bRaster(lua_State *L, GeoParms* _parms) : GeoRaster(L, _parms, - std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()).c_str(), + std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()), TimeLib::datetime2gps(2021, 8, 4), true /* Data is elevation */) {} }; diff --git a/plugins/gedi/plugin/GediParms.cpp b/plugins/gedi/plugin/GediParms.cpp index d6c9ca64a..34bc77d75 100644 --- a/plugins/gedi/plugin/GediParms.cpp +++ b/plugins/gedi/plugin/GediParms.cpp @@ -71,7 +71,7 @@ int GediParms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -100,15 +100,15 @@ const char* GediParms::beam2group (int beam) *----------------------------------------------------------------------------*/ int GediParms::group2beam (const char* group) { - if (StringLib::match(group, "BEAM0000")) return BEAM0000; - else if (StringLib::match(group, "BEAM0001")) return BEAM0001; - else if (StringLib::match(group, "BEAM0010")) return BEAM0010; - else if (StringLib::match(group, "BEAM0011")) return BEAM0011; - else if (StringLib::match(group, "BEAM0101")) return BEAM0101; - else if (StringLib::match(group, "BEAM0110")) return BEAM0110; - else if (StringLib::match(group, "BEAM1000")) return BEAM1000; - else if (StringLib::match(group, "BEAM1011")) return BEAM1011; - else return UNKNOWN_BEAM; + if(StringLib::match(group, "BEAM0000")) return BEAM0000; + if(StringLib::match(group, "BEAM0001")) return BEAM0001; + if(StringLib::match(group, "BEAM0010")) return BEAM0010; + if(StringLib::match(group, "BEAM0011")) return BEAM0011; + if(StringLib::match(group, "BEAM0101")) return BEAM0101; + if(StringLib::match(group, "BEAM0110")) return BEAM0110; + if(StringLib::match(group, "BEAM1000")) return BEAM1000; + if(StringLib::match(group, "BEAM1011")) return BEAM1011; + return UNKNOWN_BEAM; } /*---------------------------------------------------------------------------- @@ -239,11 +239,9 @@ bool GediParms::set_beam(int beam) mlog(DEBUG, "Selecting beam %d", beam); return true; } - else - { - mlog(ERROR, "Invalid beam: %d", beam); - return false; - } + + mlog(ERROR, "Invalid beam: %d", beam); + return false; } /*---------------------------------------------------------------------------- diff --git a/plugins/icesat2/CMakeLists.txt b/plugins/icesat2/CMakeLists.txt index 0e27ab1c6..5b6733aae 100644 --- a/plugins/icesat2/CMakeLists.txt +++ b/plugins/icesat2/CMakeLists.txt @@ -1,21 +1,8 @@ # ICESat-2 SlideRule Plugin top-level CMake build script project (ICESAT2 LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) ################### # ICESat-2 Plugin # @@ -30,16 +17,11 @@ set_target_properties (icesat2 PROPERTIES PREFIX "") find_package (Lua "5.3") find_package (GDAL) -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) +# Build Information # execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (icesat2 PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (icesat2 PUBLIC BINID="${TGTVER}") target_compile_options (icesat2 PUBLIC -Wall) # turn on "all" warnings @@ -67,7 +49,6 @@ target_sources(icesat2 ${CMAKE_CURRENT_LIST_DIR}/plugin/GTDArray.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/Icesat2Parms.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/MeritRaster.cpp - ${CMAKE_CURRENT_LIST_DIR}/plugin/PluginMetrics.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/UT_Atl03Reader.cpp ${CMAKE_CURRENT_LIST_DIR}/plugin/UT_Atl06Dispatch.cpp ) @@ -110,7 +91,6 @@ install ( ${CMAKE_CURRENT_LIST_DIR}/plugin/GTDArray.h ${CMAKE_CURRENT_LIST_DIR}/plugin/Icesat2Parms.h ${CMAKE_CURRENT_LIST_DIR}/plugin/MeritRaster.h - ${CMAKE_CURRENT_LIST_DIR}/plugin/PluginMetrics.h ${CMAKE_CURRENT_LIST_DIR}/plugin/UT_Atl03Reader.h ${CMAKE_CURRENT_LIST_DIR}/plugin/UT_Atl06Dispatch.h DESTINATION diff --git a/plugins/icesat2/plugin/Atl03Indexer.cpp b/plugins/icesat2/plugin/Atl03Indexer.cpp index 5af0e765a..ffcda14d7 100644 --- a/plugins/icesat2/plugin/Atl03Indexer.cpp +++ b/plugins/icesat2/plugin/Atl03Indexer.cpp @@ -53,8 +53,8 @@ const RecordObject::fieldDef_t Atl03Indexer::recDef[] = { {"rgt", RecordObject::UINT32, offsetof(index_t, rgt), 1, NULL, NATIVE_FLAGS}, }; const char* Atl03Indexer::OBJECT_TYPE = "Atl03Indexer"; -const char* Atl03Indexer::LuaMetaName = "Atl03Indexer"; -const struct luaL_Reg Atl03Indexer::LuaMetaTable[] = { +const char* Atl03Indexer::LUA_META_NAME = "Atl03Indexer"; +const struct luaL_Reg Atl03Indexer::LUA_META_TABLE[] = { {"stats", luaStats}, {NULL, NULL} }; @@ -68,25 +68,25 @@ const struct luaL_Reg Atl03Indexer::LuaMetaTable[] = { *----------------------------------------------------------------------------*/ int Atl03Indexer::luaCreate (lua_State* L) { - List* _resources = NULL; + List* _resources = NULL; Asset* _asset = NULL; try { /* Get URL */ - _asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + _asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); int tblindex = 2; const char* outq_name = getLuaString(L, 3); int num_threads = getLuaInteger(L, 4, true, DEFAULT_NUM_THREADS); /* Build Resource Table */ - _resources = new List(); if(lua_type(L, tblindex) == LUA_TTABLE) { int size = lua_rawlen(L, tblindex); + _resources = new List(size); for(int e = 0; e < size; e++) { lua_rawgeti(L, tblindex, e + 1); - const char* name = StringLib::duplicate(getLuaString(L, -1)); + string name(getLuaString(L, -1)); _resources->add(name); lua_pop(L, 1); } @@ -105,7 +105,7 @@ int Atl03Indexer::luaCreate (lua_State* L) } /* Clean Up Resources Not Used Since Failed to Create Indexer */ - if(_resources) freeResources(_resources); + if(_resources) delete _resources; /* Release Asset Since Failed to Create Indexer */ if(_asset) _asset->releaseLuaObject(); @@ -128,8 +128,8 @@ void Atl03Indexer::init (void) * Note: object takes ownership of _resources list as well as pointers to urls * (const char*) inside the list; responsible for freeing both *----------------------------------------------------------------------------*/ -Atl03Indexer::Atl03Indexer (lua_State* L, Asset* _asset, List* _resources, const char* outq_name, int num_threads): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable) +Atl03Indexer::Atl03Indexer (lua_State* L, Asset* _asset, List* _resources, const char* outq_name, int num_threads): + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE) { assert(outq_name); assert(_resources); @@ -185,7 +185,7 @@ Atl03Indexer::~Atl03Indexer (void) delete outQ; /* Clean Up Resource List */ - freeResources(resources); + delete resources; /* Release Asset */ asset->releaseLuaObject(); @@ -197,8 +197,7 @@ Atl03Indexer::~Atl03Indexer (void) void* Atl03Indexer::indexerThread (void* parm) { /* Get Thread Info */ - Atl03Indexer* indexer = (Atl03Indexer*)parm; - bool complete = false; + Atl03Indexer* indexer = reinterpret_cast(parm); /* Start Trace */ uint32_t trace_id = start_trace(CRITICAL, indexer->traceId, "atl03_indexer", "{\"tag\":\"%s\"}", indexer->getName()); @@ -213,6 +212,7 @@ void* Atl03Indexer::indexerThread (void* parm) try { + bool complete = false; while(!complete) { const char* resource_name = NULL; @@ -222,7 +222,7 @@ void* Atl03Indexer::indexerThread (void* parm) { if(indexer->resourceEntry < indexer->resources->length()) { - resource_name = indexer->resources->get(indexer->resourceEntry); + resource_name = indexer->resources->get(indexer->resourceEntry).c_str(); indexer->resourceEntry++; } else @@ -298,7 +298,7 @@ void* Atl03Indexer::indexerThread (void* parm) } /* Free Context */ - if(context) delete context; + delete context; /* Count Completion */ indexer->threadMut.lock(); @@ -320,18 +320,6 @@ void* Atl03Indexer::indexerThread (void* parm) return NULL; } -/*---------------------------------------------------------------------------- - * freeResources - *----------------------------------------------------------------------------*/ -void Atl03Indexer::freeResources (List* _resources) -{ - for(int i = 0; i < _resources->length(); i++) - { - delete [] _resources->get(i); - } - delete _resources; -} - /*---------------------------------------------------------------------------- * luaStats *----------------------------------------------------------------------------*/ @@ -343,7 +331,7 @@ int Atl03Indexer::luaStats (lua_State* L) try { /* Get Self */ - Atl03Indexer* lua_obj = (Atl03Indexer*)getLuaSelf(L, 1); + Atl03Indexer* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Create Statistics Table */ lua_newtable(L); @@ -357,7 +345,7 @@ int Atl03Indexer::luaStats (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error configuring %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error configuring %s: %s", LUA_META_NAME, e.what()); } /* Return Status */ diff --git a/plugins/icesat2/plugin/Atl03Indexer.h b/plugins/icesat2/plugin/Atl03Indexer.h index 1e10ced8f..0621bd450 100644 --- a/plugins/icesat2/plugin/Atl03Indexer.h +++ b/plugins/icesat2/plugin/Atl03Indexer.h @@ -79,8 +79,8 @@ class Atl03Indexer: public LuaObject static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Methods @@ -95,27 +95,26 @@ class Atl03Indexer: public LuaObject * Data *--------------------------------------------------------------------*/ - bool active; - Thread** indexerPid; - Mutex threadMut; - int threadCount; - int numComplete; - Publisher* outQ; - index_t indexRec; - List* resources; - int resourceEntry; - Mutex resourceMut; - Asset* asset; + bool active; + Thread** indexerPid; + Mutex threadMut; + int threadCount; + int numComplete; + Publisher* outQ; + index_t indexRec; + List* resources; + int resourceEntry; + Mutex resourceMut; + Asset* asset; /*-------------------------------------------------------------------- * Methods *--------------------------------------------------------------------*/ - Atl03Indexer (lua_State* L, Asset* _asset, List* _resources, const char* outq_name, int num_threads); + Atl03Indexer (lua_State* L, Asset* _asset, List* _resources, const char* outq_name, int num_threads); ~Atl03Indexer (void); static void* indexerThread (void* parm); - static void freeResources (List* _resources); static int luaStats (lua_State* L); }; diff --git a/plugins/icesat2/plugin/Atl03Reader.cpp b/plugins/icesat2/plugin/Atl03Reader.cpp index 96629877f..45a450695 100644 --- a/plugins/icesat2/plugin/Atl03Reader.cpp +++ b/plugins/icesat2/plugin/Atl03Reader.cpp @@ -90,8 +90,8 @@ const RecordObject::fieldDef_t Atl03Reader::ancRecDef[] = { const double Atl03Reader::ATL03_SEGMENT_LENGTH = 20.0; // meters const char* Atl03Reader::OBJECT_TYPE = "Atl03Reader"; -const char* Atl03Reader::LuaMetaName = "Atl03Reader"; -const struct luaL_Reg Atl03Reader::LuaMetaTable[] = { +const char* Atl03Reader::LUA_META_NAME = "Atl03Reader"; +const struct luaL_Reg Atl03Reader::LUA_META_TABLE[] = { {"parms", luaParms}, {"stats", luaStats}, {NULL, NULL} @@ -194,10 +194,10 @@ int Atl03Reader::luaCreate (lua_State* L) try { /* Get Parameters */ - asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* resource = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); - parms = (Icesat2Parms*)getLuaObject(L, 4, Icesat2Parms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 4, Icesat2Parms::OBJECT_TYPE)); bool send_terminator = getLuaBoolean(L, 5, true, true); /* Return Reader Object */ @@ -226,7 +226,7 @@ void Atl03Reader::init (void) * Constructor *----------------------------------------------------------------------------*/ Atl03Reader::Atl03Reader (lua_State* L, Asset* _asset, const char* _resource, const char* outq_name, Icesat2Parms* _parms, bool _send_terminator): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), read_timeout_ms(_parms->read_timeout * 1000) { assert(_asset); @@ -243,9 +243,8 @@ Atl03Reader::Atl03Reader (lua_State* L, Asset* _asset, const char* _resource, co parms = _parms; /* Generate ATL08 Resource Name */ - SafeString atl08_resource("%s", resource); - atl08_resource.setChar('8', 4); - resource08 = atl08_resource.str(true); + resource08 = StringLib::duplicate(resource); + resource08[4] = '8'; /* Create Publisher */ outQ = new Publisher(outq_name); @@ -269,9 +268,6 @@ Atl03Reader::Atl03Reader (lua_State* L, Asset* _asset, const char* _resource, co /* Read Global Resource Information */ try { - /* Set Metrics */ - PluginMetrics::setRegion(parms); - /* Parse Globals (throws) */ parseResource(resource, start_rgt, start_cycle, start_region); @@ -339,9 +335,9 @@ Atl03Reader::~Atl03Reader (void) * Region::Constructor *----------------------------------------------------------------------------*/ Atl03Reader::Region::Region (info_t* info): - segment_lat (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/reference_photon_lat").str(), &info->reader->context), - segment_lon (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/reference_photon_lon").str(), &info->reader->context), - segment_ph_cnt (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/segment_ph_cnt").str(), &info->reader->context), + segment_lat (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/reference_photon_lat").c_str(), &info->reader->context), + segment_lon (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/reference_photon_lon").c_str(), &info->reader->context), + segment_ph_cnt (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/segment_ph_cnt").c_str(), &info->reader->context), inclusion_mask {NULL}, inclusion_ptr {NULL} { @@ -443,7 +439,6 @@ void Atl03Reader::Region::polyregion (void) { /* Find First Segment In Polygon */ bool first_segment_found = false; - bool last_segment_found = false; int segment = 0; while(segment < segment_ph_cnt.size) { @@ -478,20 +473,16 @@ void Atl03Reader::Region::polyregion (void) first_photon += segment_ph_cnt[segment]; } } - else if(!last_segment_found) + else { /* If Coordinate Is NOT In Polygon */ if(!inclusion && segment_ph_cnt[segment] != 0) { - /* Set Last Segment */ - last_segment_found = true; break; // full extent found! } - else - { - /* Update Photon Index */ - num_photons += segment_ph_cnt[segment]; - } + + /* Update Photon Index */ + num_photons += segment_ph_cnt[segment]; } /* Bump Segment */ @@ -591,23 +582,23 @@ void Atl03Reader::Region::rasterregion (info_t* info) /*---------------------------------------------------------------------------- * Atl03Data::Constructor *----------------------------------------------------------------------------*/ -Atl03Reader::Atl03Data::Atl03Data (info_t* info, Region& region): - sc_orient (info->reader->asset, info->reader->resource, "/orbit_info/sc_orient", &info->reader->context), - velocity_sc (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/velocity_sc").str(), &info->reader->context, H5Coro::ALL_COLS, region.first_segment, region.num_segments), - segment_delta_time (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/delta_time").str(), &info->reader->context, 0, region.first_segment, region.num_segments), - segment_id (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/segment_id").str(), &info->reader->context, 0, region.first_segment, region.num_segments), - segment_dist_x (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/segment_dist_x").str(), &info->reader->context, 0, region.first_segment, region.num_segments), - solar_elevation (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "geolocation/solar_elevation").str(), &info->reader->context, 0, region.first_segment, region.num_segments), - dist_ph_along (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/dist_ph_along").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - dist_ph_across (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/dist_ph_across").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - h_ph (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/h_ph").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - signal_conf_ph (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/signal_conf_ph").str(), &info->reader->context, info->reader->parms->surface_type, region.first_photon, region.num_photons), - quality_ph (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/quality_ph").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - lat_ph (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/lat_ph").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - lon_ph (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/lon_ph").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - delta_time (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "heights/delta_time").str(), &info->reader->context, 0, region.first_photon, region.num_photons), - bckgrd_delta_time (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "bckgrd_atlas/delta_time").str(), &info->reader->context), - bckgrd_rate (info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, "bckgrd_atlas/bckgrd_rate").str(), &info->reader->context), +Atl03Reader::Atl03Data::Atl03Data (info_t* info, const Region& region): + sc_orient (info->reader->asset, info->reader->resource, "/orbit_info/sc_orient", &info->reader->context), + velocity_sc (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/velocity_sc").c_str(), &info->reader->context, H5Coro::ALL_COLS, region.first_segment, region.num_segments), + segment_delta_time (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/delta_time").c_str(), &info->reader->context, 0, region.first_segment, region.num_segments), + segment_id (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/segment_id").c_str(), &info->reader->context, 0, region.first_segment, region.num_segments), + segment_dist_x (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/segment_dist_x").c_str(), &info->reader->context, 0, region.first_segment, region.num_segments), + solar_elevation (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "geolocation/solar_elevation").c_str(), &info->reader->context, 0, region.first_segment, region.num_segments), + dist_ph_along (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/dist_ph_along").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + dist_ph_across (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/dist_ph_across").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + h_ph (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/h_ph").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + signal_conf_ph (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/signal_conf_ph").c_str(), &info->reader->context, info->reader->parms->surface_type, region.first_photon, region.num_photons), + quality_ph (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/quality_ph").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + lat_ph (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/lat_ph").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + lon_ph (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/lon_ph").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + delta_time (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "heights/delta_time").c_str(), &info->reader->context, 0, region.first_photon, region.num_photons), + bckgrd_delta_time (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "bckgrd_atlas/delta_time").c_str(), &info->reader->context), + bckgrd_rate (info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, "bckgrd_atlas/bckgrd_rate").c_str(), &info->reader->context), anc_geo_data (Icesat2Parms::EXPECTED_NUM_FIELDS), anc_ph_data (Icesat2Parms::EXPECTED_NUM_FIELDS) { @@ -619,7 +610,7 @@ Atl03Reader::Atl03Data::Atl03Data (info_t* info, Region& region): { for(int i = 0; i < geo_fields->length(); i++) { - const char* field_name = (*geo_fields)[i].str(); + const char* field_name = (*geo_fields)[i].c_str(); const char* group_name = "geolocation"; if( (field_name[0] == 't' && field_name[1] == 'i' && field_name[2] == 'd') || (field_name[0] == 'g' && field_name[1] == 'e' && field_name[2] == 'o') || @@ -628,9 +619,11 @@ Atl03Reader::Atl03Data::Atl03Data (info_t* info, Region& region): { group_name = "geophys_corr"; } - SafeString dataset_name("%s/%s", group_name, field_name); - H5DArray* array = new H5DArray(info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, dataset_name.str()).str(), &info->reader->context, 0, region.first_segment, region.num_segments); - anc_geo_data.add(field_name, array); + FString dataset_name("%s/%s", group_name, field_name); + H5DArray* array = new H5DArray(info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, dataset_name.c_str()).c_str(), &info->reader->context, 0, region.first_segment, region.num_segments); + bool status = anc_geo_data.add(field_name, array); + if(!status) delete array; + assert(status); // the dictionary add should never fail } } @@ -639,10 +632,12 @@ Atl03Reader::Atl03Data::Atl03Data (info_t* info, Region& region): { for(int i = 0; i < photon_fields->length(); i++) { - const char* field_name = (*photon_fields)[i].str(); - SafeString dataset_name("heights/%s", field_name); - H5DArray* array = new H5DArray(info->reader->asset, info->reader->resource, SafeString("%s/%s", info->prefix, dataset_name.str()).str(), &info->reader->context, 0, region.first_photon, region.num_photons); - anc_ph_data.add(field_name, array); + const char* field_name = (*photon_fields)[i].c_str(); + FString dataset_name("heights/%s", field_name); + H5DArray* array = new H5DArray(info->reader->asset, info->reader->resource, FString("%s/%s", info->prefix, dataset_name.c_str()).c_str(), &info->reader->context, 0, region.first_photon, region.num_photons); + bool status = anc_ph_data.add(field_name, array); + if(!status) delete array; + assert(status); // the dictionary add should never fail } } @@ -706,13 +701,13 @@ Atl03Reader::Atl08Class::Atl08Class (info_t* info): relief {NULL}, landcover {NULL}, snowcover {NULL}, - atl08_segment_id (enabled ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "signal_photons/ph_segment_id").str(), &info->reader->context08), - atl08_pc_indx (enabled ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "signal_photons/classed_pc_indx").str(), &info->reader->context08), - atl08_pc_flag (enabled ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "signal_photons/classed_pc_flag").str(), &info->reader->context08), - atl08_ph_h (phoreal ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "signal_photons/ph_h").str(), &info->reader->context08), - segment_id_beg (phoreal ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "land_segments/segment_id_beg").str(), &info->reader->context08), - segment_landcover (phoreal ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "land_segments/segment_landcover").str(), &info->reader->context08), - segment_snowcover (phoreal ? info->reader->asset : NULL, info->reader->resource08, SafeString("%s/%s", info->prefix, "land_segments/segment_snowcover").str(), &info->reader->context08) + atl08_segment_id (enabled ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "signal_photons/ph_segment_id").c_str(), &info->reader->context08), + atl08_pc_indx (enabled ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "signal_photons/classed_pc_indx").c_str(), &info->reader->context08), + atl08_pc_flag (enabled ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "signal_photons/classed_pc_flag").c_str(), &info->reader->context08), + atl08_ph_h (phoreal ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "signal_photons/ph_h").c_str(), &info->reader->context08), + segment_id_beg (phoreal ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "land_segments/segment_id_beg").c_str(), &info->reader->context08), + segment_landcover (phoreal ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "land_segments/segment_landcover").c_str(), &info->reader->context08), + segment_snowcover (phoreal ? info->reader->asset : NULL, info->reader->resource08, FString("%s/%s", info->prefix, "land_segments/segment_snowcover").c_str(), &info->reader->context08) { } @@ -721,16 +716,16 @@ Atl03Reader::Atl08Class::Atl08Class (info_t* info): *----------------------------------------------------------------------------*/ Atl03Reader::Atl08Class::~Atl08Class (void) { - if(classification) delete [] classification; - if(relief) delete [] relief; - if(landcover) delete [] landcover; - if(snowcover) delete [] snowcover; + delete [] classification; + delete [] relief; + delete [] landcover; + delete [] snowcover; } /*---------------------------------------------------------------------------- * Atl08Class::classify *----------------------------------------------------------------------------*/ -void Atl03Reader::Atl08Class::classify (info_t* info, Region& region, Atl03Data& atl03) +void Atl03Reader::Atl08Class::classify (info_t* info, const Region& region, const Atl03Data& atl03) { /* Do Nothing If Not Enabled */ if(!info->reader->parms->stages[Icesat2Parms::STAGE_ATL08]) @@ -864,7 +859,7 @@ void Atl03Reader::Atl08Class::classify (info_t* info, Region& region, Atl03Data& /*---------------------------------------------------------------------------- * Atl08Class::operator[] *----------------------------------------------------------------------------*/ -uint8_t Atl03Reader::Atl08Class::operator[] (int index) +uint8_t Atl03Reader::Atl08Class::operator[] (int index) const { return classification[index]; } @@ -872,7 +867,7 @@ uint8_t Atl03Reader::Atl08Class::operator[] (int index) /*---------------------------------------------------------------------------- * YapcScore::Constructor *----------------------------------------------------------------------------*/ -Atl03Reader::YapcScore::YapcScore (info_t* info, Region& region, Atl03Data& atl03): +Atl03Reader::YapcScore::YapcScore (info_t* info, const Region& region, const Atl03Data& atl03): score {NULL} { /* Do Nothing If Not Enabled */ @@ -901,13 +896,13 @@ Atl03Reader::YapcScore::YapcScore (info_t* info, Region& region, Atl03Data& atl0 *----------------------------------------------------------------------------*/ Atl03Reader::YapcScore::~YapcScore (void) { - if(score) delete [] score; + delete [] score; } /*---------------------------------------------------------------------------- * yapcV2 *----------------------------------------------------------------------------*/ -void Atl03Reader::YapcScore::yapcV2 (info_t* info, Region& region, Atl03Data& atl03) +void Atl03Reader::YapcScore::yapcV2 (info_t* info, const Region& region, const Atl03Data& atl03) { /* YAPC Hard-Coded Parameters */ const double MAXIMUM_HSPREAD = 15000.0; // meters @@ -1078,7 +1073,7 @@ void Atl03Reader::YapcScore::yapcV2 (info_t* info, Region& region, Atl03Data& at /*---------------------------------------------------------------------------- * yapcV3 *----------------------------------------------------------------------------*/ -void Atl03Reader::YapcScore::yapcV3 (info_t* info, Region& region, Atl03Data& atl03) +void Atl03Reader::YapcScore::yapcV3 (info_t* info, const Region& region, const Atl03Data& atl03) { /* YAPC Parameters */ Icesat2Parms::yapc_t* settings = &info->reader->parms->yapc; @@ -1208,7 +1203,7 @@ void Atl03Reader::YapcScore::yapcV3 (info_t* info, Region& region, Atl03Data& at /*---------------------------------------------------------------------------- * YapcScore::operator[] *----------------------------------------------------------------------------*/ -uint8_t Atl03Reader::YapcScore::operator[] (int index) +uint8_t Atl03Reader::YapcScore::operator[] (int index) const { return score[index]; } @@ -1216,7 +1211,7 @@ uint8_t Atl03Reader::YapcScore::operator[] (int index) /*---------------------------------------------------------------------------- * TrackState::Constructor *----------------------------------------------------------------------------*/ -Atl03Reader::TrackState::TrackState (Atl03Data& atl03) +Atl03Reader::TrackState::TrackState (const Atl03Data& atl03) { ph_in = 0; seg_in = 0; @@ -1229,6 +1224,7 @@ Atl03Reader::TrackState::TrackState (Atl03Data& atl03) bckgrd_in = 0; extent_segment = 0; extent_valid = true; + extent_length = 0.0; } /*---------------------------------------------------------------------------- @@ -1248,7 +1244,6 @@ void* Atl03Reader::subsettingThread (void* parm) Atl03Reader* reader = info->reader; Icesat2Parms* parms = reader->parms; stats_t local_stats = {0, 0, 0, 0, 0}; - uint32_t extent_counter = 0; List* segment_indices = NULL; // used for ancillary data List* photon_indices = NULL; // used for ancillary data @@ -1257,7 +1252,7 @@ void* Atl03Reader::subsettingThread (void* parm) EventLib::stashId (trace_id); // set thread specific trace id for H5Coro try - { + { /* Start Reading ATL08 Data */ Atl08Class atl08(info); @@ -1283,6 +1278,9 @@ void* Atl03Reader::subsettingThread (void* parm) state.extent_length = parms->extent_length; if(parms->dist_in_seg) state.extent_length *= ATL03_SEGMENT_LENGTH; + /* Initialize Extent Counter */ + uint32_t extent_counter = 0; + /* Traverse All Photons In Dataset */ while(reader->active && !state.track_complete) { @@ -1361,7 +1359,7 @@ void* Atl03Reader::subsettingThread (void* parm) { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid atl03 signal confidence: %d", atl03_cnf); } - else if(!parms->atl03_cnf[atl03_cnf + Icesat2Parms::SIGNAL_CONF_OFFSET]) + if(!parms->atl03_cnf[atl03_cnf + Icesat2Parms::SIGNAL_CONF_OFFSET]) { break; } @@ -1372,7 +1370,7 @@ void* Atl03Reader::subsettingThread (void* parm) { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid atl03 photon quality: %d", quality_ph); } - else if(!parms->quality_ph[quality_ph]) + if(!parms->quality_ph[quality_ph]) { break; } @@ -1386,7 +1384,7 @@ void* Atl03Reader::subsettingThread (void* parm) { throw RunTimeException(CRITICAL, RTE_ERROR, "invalid atl08 classification: %d", atl08_class); } - else if(!parms->atl08_class[atl08_class]) + if(!parms->atl08_class[atl08_class]) { break; } @@ -1416,7 +1414,7 @@ void* Atl03Reader::subsettingThread (void* parm) float relief = 0.0; uint8_t landcover_flag = Atl08Class::INVALID_FLAG; uint8_t snowcover_flag = Atl08Class::INVALID_FLAG; - if(parms->stages[Icesat2Parms::STAGE_PHOREAL]) + if(atl08.phoreal) { /* Set Relief */ if(!parms->phoreal.use_abs_h) @@ -1435,7 +1433,7 @@ void* Atl03Reader::subsettingThread (void* parm) /* Add Photon to Extent */ photon_t ph = { - .time_ns = parms->deltatime2timestamp(atl03.delta_time[current_photon]), + .time_ns = Icesat2Parms::deltatime2timestamp(atl03.delta_time[current_photon]), .latitude = atl03.lat_ph[current_photon], .longitude = atl03.lon_ph[current_photon], .x_atc = (float)(x_atc - (state.extent_length / 2.0)), @@ -1541,8 +1539,8 @@ void* Atl03Reader::subsettingThread (void* parm) { int rec_total_size = 0; reader->generateExtentRecord(extent_id, info, state, atl03, rec_list, rec_total_size); - reader->generateAncillaryRecords(extent_id, parms->atl03_ph_fields, atl03.anc_ph_data, PHOTON_ANC_TYPE, photon_indices, rec_list, rec_total_size); - reader->generateAncillaryRecords(extent_id, parms->atl03_geo_fields, atl03.anc_geo_data, EXTENT_ANC_TYPE, segment_indices, rec_list, rec_total_size); + Atl03Reader::generateAncillaryRecords(extent_id, parms->atl03_ph_fields, atl03.anc_ph_data, PHOTON_ANC_TYPE, photon_indices, rec_list, rec_total_size); + Atl03Reader::generateAncillaryRecords(extent_id, parms->atl03_geo_fields, atl03.anc_geo_data, EXTENT_ANC_TYPE, segment_indices, rec_list, rec_total_size); /* Send Records */ if(rec_list.size() == 1) @@ -1611,8 +1609,8 @@ void* Atl03Reader::subsettingThread (void* parm) reader->threadMut.unlock(); /* Clean Up Indices */ - if(segment_indices) delete segment_indices; - if(photon_indices) delete photon_indices; + delete segment_indices; + delete photon_indices; /* Clean Up Info */ delete info; @@ -1627,7 +1625,7 @@ void* Atl03Reader::subsettingThread (void* parm) /*---------------------------------------------------------------------------- * calculateBackground *----------------------------------------------------------------------------*/ -double Atl03Reader::calculateBackground (TrackState& state, Atl03Data& atl03) +double Atl03Reader::calculateBackground (TrackState& state, const Atl03Data& atl03) { double background_rate = atl03.bckgrd_rate[atl03.bckgrd_rate.size - 1]; while(state.bckgrd_in < atl03.bckgrd_rate.size) @@ -1656,11 +1654,9 @@ double Atl03Reader::calculateBackground (TrackState& state, Atl03Data& atl03) } break; } - else - { - /* Go To Next Background Rate */ - state.bckgrd_in++; - } + + /* Go To Next Background Rate */ + state.bckgrd_in++; } return background_rate; } @@ -1668,7 +1664,7 @@ double Atl03Reader::calculateBackground (TrackState& state, Atl03Data& atl03) /*---------------------------------------------------------------------------- * calculateSegmentId *----------------------------------------------------------------------------*/ -uint32_t Atl03Reader::calculateSegmentId (TrackState& state, Atl03Data& atl03) +uint32_t Atl03Reader::calculateSegmentId (const TrackState& state, const Atl03Data& atl03) { /* Calculate Segment ID (attempt to arrive at closest ATL06 segment ID represented by extent) */ double atl06_segment_id = (double)atl03.segment_id[state.extent_segment]; // start with first segment in extent @@ -1689,7 +1685,7 @@ uint32_t Atl03Reader::calculateSegmentId (TrackState& state, Atl03Data& atl03) /*---------------------------------------------------------------------------- * generateExtentRecord *----------------------------------------------------------------------------*/ -void Atl03Reader::generateExtentRecord (uint64_t extent_id, info_t* info, TrackState& state, Atl03Data& atl03, vector& rec_list, int& total_size) +void Atl03Reader::generateExtentRecord (uint64_t extent_id, info_t* info, TrackState& state, const Atl03Data& atl03, vector& rec_list, int& total_size) { /* Calculate Extent Record Size */ int num_photons = state.extent_photons.length(); @@ -1734,14 +1730,14 @@ void Atl03Reader::generateExtentRecord (uint64_t extent_id, info_t* info, TrackS /*---------------------------------------------------------------------------- * generateAncillaryRecords *----------------------------------------------------------------------------*/ -void Atl03Reader::generateAncillaryRecords (uint64_t extent_id, Icesat2Parms::string_list_t* field_list, MgDictionary& field_dict, anc_type_t type, List* indices, vector& rec_list, int& total_size) +void Atl03Reader::generateAncillaryRecords (uint64_t extent_id, Icesat2Parms::string_list_t* field_list, H5DArrayDictionary& field_dict, anc_type_t type, List* indices, vector& rec_list, int& total_size) { if(field_list && indices->length() > 0) { for(int i = 0; i < field_list->length(); i++) { /* Get Data Array */ - H5DArray* array = field_dict[(*field_list)[i].str()]; + H5DArray* array = field_dict[(*field_list)[i].c_str()]; /* Create Ancillary Record */ int record_size = offsetof(anc_t, data) + @@ -1876,7 +1872,7 @@ int Atl03Reader::luaParms (lua_State* L) try { /* Get Self */ - lua_obj = (Atl03Reader*)getLuaSelf(L, 1); + lua_obj = dynamic_cast(getLuaSelf(L, 1)); } catch(const RunTimeException& e) { @@ -1926,7 +1922,7 @@ int Atl03Reader::luaStats (lua_State* L) try { /* Get Self */ - lua_obj = (Atl03Reader*)getLuaSelf(L, 1); + lua_obj = dynamic_cast(getLuaSelf(L, 1)); } catch(const RunTimeException& e) { diff --git a/plugins/icesat2/plugin/Atl03Reader.h b/plugins/icesat2/plugin/Atl03Reader.h index 6ea241946..5ddb36016 100644 --- a/plugins/icesat2/plugin/Atl03Reader.h +++ b/plugins/icesat2/plugin/Atl03Reader.h @@ -49,8 +49,6 @@ #include "H5DArray.h" #include "Icesat2Parms.h" -using std::vector; - /****************************************************************************** * ATL03 READER ******************************************************************************/ @@ -76,8 +74,8 @@ class Atl03Reader: public LuaObject static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types @@ -159,6 +157,8 @@ class Atl03Reader: public LuaObject * Types *--------------------------------------------------------------------*/ + typedef Dictionary H5DArrayDictionary; + typedef struct { Atl03Reader* reader; char prefix[7]; @@ -171,7 +171,7 @@ class Atl03Reader: public LuaObject { public: - Region (info_t* info); + explicit Region (info_t* info); ~Region (void); void cleanup (void); @@ -200,7 +200,7 @@ class Atl03Reader: public LuaObject { public: - Atl03Data (info_t* info, Region& region); + Atl03Data (info_t* info, const Region& region); ~Atl03Data (void); /* Read Data */ @@ -221,8 +221,8 @@ class Atl03Reader: public LuaObject H5Array bckgrd_delta_time; H5Array bckgrd_rate; - MgDictionary anc_geo_data; - MgDictionary anc_ph_data; + H5DArrayDictionary anc_geo_data; + H5DArrayDictionary anc_ph_data; }; /* Atl08 Classification Subclass */ @@ -235,15 +235,14 @@ class Atl03Reader: public LuaObject static const uint8_t INVALID_FLAG = 0xFF; /* Methods */ - Atl08Class (info_t* info); + explicit Atl08Class (info_t* info); ~Atl08Class (void); - void classify (info_t* info, Region& region, Atl03Data& atl03); - uint8_t operator[] (int index); + void classify (info_t* info, const Region& region, const Atl03Data& atl03); + uint8_t operator[] (int index) const; /* Class Data */ bool enabled; bool phoreal; - SafeString resource; /* Generated Data */ uint8_t* classification; // [num_photons] @@ -268,13 +267,13 @@ class Atl03Reader: public LuaObject { public: - YapcScore (info_t* info, Region& region, Atl03Data& atl03); + YapcScore (info_t* info, const Region& region, const Atl03Data& atl03); ~YapcScore (void); - void yapcV2 (info_t* info, Region& region, Atl03Data& atl03); - void yapcV3 (info_t* info, Region& region, Atl03Data& atl03); + void yapcV2 (info_t* info, const Region& region, const Atl03Data& atl03); + void yapcV3 (info_t* info, const Region& region, const Atl03Data& atl03); - uint8_t operator[] (int index); + uint8_t operator[] (int index) const; /* Generated Data */ uint8_t* score; // [num_photons] @@ -289,7 +288,7 @@ class Atl03Reader: public LuaObject int32_t seg_in; // segment index int32_t seg_ph; // current photon index in segment int32_t start_segment; // used to set start_distance - double start_distance; // distance to start of extent + double start_distance; // distance to start of extent (in meters from equator) double seg_distance; // distance to start of atl03 segment double start_seg_portion; // portion of segment extent is starting from bool track_complete; // flag when track processing has finished @@ -297,10 +296,10 @@ class Atl03Reader: public LuaObject List extent_photons; // list of individual photons in extent int32_t extent_segment; // current segment extent is pulling photons from bool extent_valid; // flag for validity of extent (atl06 checks) - double extent_length; + double extent_length; // custom length of the extent (in meters) - TrackState (Atl03Data& atl03); - ~TrackState (void); + explicit TrackState (const Atl03Data& atl03); + ~TrackState (void); }; /*-------------------------------------------------------------------- @@ -320,7 +319,7 @@ class Atl03Reader: public LuaObject int numComplete; Asset* asset; const char* resource; - const char* resource08; + char* resource08; bool sendTerminator; const int read_timeout_ms; Publisher* outQ; @@ -343,12 +342,12 @@ class Atl03Reader: public LuaObject static void* subsettingThread (void* parm); - double calculateBackground (TrackState& state, Atl03Data& atl03); - uint32_t calculateSegmentId (TrackState& state, Atl03Data& atl03); - void generateExtentRecord (uint64_t extent_id, info_t* info, TrackState& state, Atl03Data& atl03, vector& rec_list, int& total_size); - void generateAncillaryRecords (uint64_t extent_id, Icesat2Parms::string_list_t* field_list, MgDictionary& field_dict, anc_type_t type, List* indices, vector& rec_list, int& total_size); + static double calculateBackground (TrackState& state, const Atl03Data& atl03); + uint32_t calculateSegmentId (const TrackState& state, const Atl03Data& atl03); + void generateExtentRecord (uint64_t extent_id, info_t* info, TrackState& state, const Atl03Data& atl03, vector& rec_list, int& total_size); + static void generateAncillaryRecords (uint64_t extent_id, Icesat2Parms::string_list_t* field_list, H5DArrayDictionary& field_dict, anc_type_t type, List* indices, vector& rec_list, int& total_size); void postRecord (RecordObject& record, stats_t& local_stats); - void parseResource (const char* resource, int32_t& rgt, int32_t& cycle, int32_t& region); + static void parseResource (const char* resource, int32_t& rgt, int32_t& cycle, int32_t& region); static int luaParms (lua_State* L); static int luaStats (lua_State* L); diff --git a/plugins/icesat2/plugin/Atl06Dispatch.cpp b/plugins/icesat2/plugin/Atl06Dispatch.cpp index 4717206ed..c2134e948 100644 --- a/plugins/icesat2/plugin/Atl06Dispatch.cpp +++ b/plugins/icesat2/plugin/Atl06Dispatch.cpp @@ -124,8 +124,8 @@ const RecordObject::fieldDef_t Atl06Dispatch::ancRecDef[] = { }; /* Lua Functions */ -const char* Atl06Dispatch::LuaMetaName = "Atl06Dispatch"; -const struct luaL_Reg Atl06Dispatch::LuaMetaTable[] = { +const char* Atl06Dispatch::LUA_META_NAME = "Atl06Dispatch"; +const struct luaL_Reg Atl06Dispatch::LUA_META_TABLE[] = { {"stats", luaStats}, {NULL, NULL} }; @@ -144,7 +144,7 @@ int Atl06Dispatch::luaCreate (lua_State* L) { /* Get Parameters */ const char* outq_name = getLuaString(L, 1); - parms = (Icesat2Parms*)getLuaObject(L, 2, Icesat2Parms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 2, Icesat2Parms::OBJECT_TYPE)); /* Create ATL06 Dispatch */ return createLuaObject(L, new Atl06Dispatch(L, outq_name, parms)); @@ -152,7 +152,7 @@ int Atl06Dispatch::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(parms) parms->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -181,7 +181,7 @@ void Atl06Dispatch::init (void) * Constructor *----------------------------------------------------------------------------*/ Atl06Dispatch::Atl06Dispatch (lua_State* L, const char* outq_name, Icesat2Parms* _parms): - DispatchObject(L, LuaMetaName, LuaMetaTable), + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE), elevationRecord(atRecType, sizeof(atl06_t)) { assert(outq_name); @@ -195,7 +195,7 @@ Atl06Dispatch::Atl06Dispatch (lua_State* L, const char* outq_name, Icesat2Parms* * this extends the memory available past the one elevation provided in the * definition. */ - elevationRecordData = (atl06_t*)elevationRecord.getRecordData(); + elevationRecordData = reinterpret_cast(elevationRecord.getRecordData()); ancillaryTotalSize = 0; /* Initialize Publisher */ @@ -292,10 +292,7 @@ bool Atl06Dispatch::processRecord (RecordObject* record, okey_t key, recVec_t* r } /* Delete Photon Aray */ - if(result.photons) - { - delete [] result.photons; - } + delete [] result.photons; /* Bump Statistics */ stats.h5atl03_rec_cnt++; @@ -648,7 +645,7 @@ int Atl06Dispatch::luaStats (lua_State* L) try { /* Get Self */ - Atl06Dispatch* lua_obj = (Atl06Dispatch*)getLuaSelf(L, 1); + Atl06Dispatch* lua_obj = dynamic_cast(getLuaSelf(L, 1)); /* Get Clear Parameter */ bool with_clear = getLuaBoolean(L, 2, true, false); @@ -675,7 +672,7 @@ int Atl06Dispatch::luaStats (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error configuring %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error configuring %s: %s", LUA_META_NAME, e.what()); } /* Return Status */ @@ -770,17 +767,17 @@ Atl06Dispatch::lsf_t Atl06Dispatch::lsf (Atl03Reader::extent_t* extent, result_t } else /* Latitude, Longitude, GPS Time, Across Track Coordinate, Ancillary Fields */ { - double latitude = 0.0; - double longitude = 0.0; - double time_ns = 0.0; - double y_atc = 0.0; - if(size > 0) { + double latitude = 0.0; + double longitude = 0.0; + double time_ns = 0.0; + double y_atc = 0.0; + /* Check Need to Shift Longitudes assumes that there isn't a set of photons with longitudes that extend for more than 30 degrees */ - double shift_lon = false; + bool shift_lon = false; double first_lon = extent->photons[array[0].p].longitude; if(first_lon < -150.0 || first_lon > 150.0) { diff --git a/plugins/icesat2/plugin/Atl06Dispatch.h b/plugins/icesat2/plugin/Atl06Dispatch.h index 2d03662a5..911da78db 100644 --- a/plugins/icesat2/plugin/Atl06Dispatch.h +++ b/plugins/icesat2/plugin/Atl06Dispatch.h @@ -46,9 +46,6 @@ #include "Atl03Reader.h" #include "Icesat2Parms.h" -#include -using std::vector; - /****************************************************************************** * ATL06 DISPATCH CLASS ******************************************************************************/ @@ -84,8 +81,8 @@ class Atl06Dispatch: public DispatchObject static const char* ancRecType; static const RecordObject::fieldDef_t ancRecDef[]; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; /*-------------------------------------------------------------------- * Types diff --git a/plugins/icesat2/plugin/Atl08Dispatch.cpp b/plugins/icesat2/plugin/Atl08Dispatch.cpp index fbc6d0c0d..4ea29c425 100644 --- a/plugins/icesat2/plugin/Atl08Dispatch.cpp +++ b/plugins/icesat2/plugin/Atl08Dispatch.cpp @@ -87,8 +87,8 @@ const RecordObject::fieldDef_t Atl08Dispatch::waveRecDef[] = { /* Lua Functions */ -const char* Atl08Dispatch::LuaMetaName = "Atl08Dispatch"; -const struct luaL_Reg Atl08Dispatch::LuaMetaTable[] = { +const char* Atl08Dispatch::LUA_META_NAME = "Atl08Dispatch"; +const struct luaL_Reg Atl08Dispatch::LUA_META_TABLE[] = { {NULL, NULL} }; @@ -112,7 +112,7 @@ int Atl08Dispatch::luaCreate (lua_State* L) { /* Get Parameters */ const char* outq_name = getLuaString(L, 1); - parms = (Icesat2Parms*)getLuaObject(L, 2, Icesat2Parms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 2, Icesat2Parms::OBJECT_TYPE)); /* Create ATL06 Dispatch */ return createLuaObject(L, new Atl08Dispatch(L, outq_name, parms)); @@ -120,7 +120,7 @@ int Atl08Dispatch::luaCreate (lua_State* L) catch(const RunTimeException& e) { if(parms) parms->releaseLuaObject(); - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -149,7 +149,7 @@ void Atl08Dispatch::init (void) * Constructor *----------------------------------------------------------------------------*/ Atl08Dispatch::Atl08Dispatch (lua_State* L, const char* outq_name, Icesat2Parms* _parms): - DispatchObject(L, LuaMetaName, LuaMetaTable) + DispatchObject(L, LUA_META_NAME, LUA_META_TABLE) { assert(outq_name); assert(_parms); @@ -163,7 +163,7 @@ Atl08Dispatch::Atl08Dispatch (lua_State* L, const char* outq_name, Icesat2Parms* * definition. */ recObj = new RecordObject(batchRecType, sizeof(atl08_t)); - recData = (atl08_t*)recObj->getRecordData(); + recData = reinterpret_cast(recObj->getRecordData()); /* Initialize Publisher */ outQ = new Publisher(outq_name); @@ -191,13 +191,14 @@ bool Atl08Dispatch::processRecord (RecordObject* record, okey_t key, recVec_t* r Atl03Reader::extent_t* extent = (Atl03Reader::extent_t*)record->getRecordData(); /* Check Extent */ - if(extent->photon_count <= 0) + if(extent->photon_count == 0) { return true; } /* Initialize Results */ vegetation_t result; + result.pflags = 0; geolocateResult(extent, result); /* Execute Algorithm Stages */ @@ -266,10 +267,14 @@ void Atl08Dispatch::geolocateResult (Atl03Reader::extent_t* extent, vegetation_t else if(parms->phoreal.geoloc == Icesat2Parms::PHOREAL_CENTER) { /* Calculate Sums */ - double time_ns_min = DBL_MAX, time_ns_max = -DBL_MAX; - double latitude_min = DBL_MAX, latitude_max = -DBL_MAX; - double longitude_min = DBL_MAX, longitude_max = -DBL_MAX; - double x_atc_min = DBL_MAX, x_atc_max = -DBL_MAX; + double time_ns_min = DBL_MAX; + double time_ns_max = -DBL_MAX; + double latitude_min = DBL_MAX; + double latitude_max = -DBL_MAX; + double longitude_min = DBL_MAX; + double longitude_max = -DBL_MAX; + double x_atc_min = DBL_MAX; + double x_atc_max = -DBL_MAX; for(uint32_t i = 0; i < num_ph; i++) { if(ph[i].time_ns < time_ns_min) time_ns_min = ph[i].time_ns; @@ -328,6 +333,14 @@ void Atl08Dispatch::geolocateResult (Atl03Reader::extent_t* extent, vegetation_t result.x_atc = ((ph[center_ph].x_atc + ph[center_ph - 1].x_atc) / 2) + extent->segment_distance; } } + else // unexpected geolocation setting + { + result.time_ns = 0; + result.latitude = 0.0; + result.longitude = 0.0; + result.x_atc = extent->segment_distance; + } + /* Land and Snow Cover Flags */ if(num_ph == 0) @@ -383,7 +396,8 @@ void Atl08Dispatch::phorealAlgorithm (Atl03Reader::extent_t* extent, vegetation_ /* Create Ground and Vegetation Photon Index Arrays */ long* gnd_index = new long [gnd_cnt]; long* veg_index = new long [veg_cnt]; - long g = 0, v = 0; + long g = 0; + long v = 0; for(long i = 0; i < num_ph; i++) { if(isGround(&ph[i]) || parms->phoreal.use_abs_h) @@ -505,6 +519,7 @@ void Atl08Dispatch::phorealAlgorithm (Atl03Reader::extent_t* extent, vegetation_ result.h_te_median = h_te_median; /* Calculate Percentiles */ + if(veg_cnt > 0) { int b = 0; // bin index for(int p = 0; p < NUM_PERCENTILES; p++) @@ -532,6 +547,11 @@ void Atl08Dispatch::phorealAlgorithm (Atl03Reader::extent_t* extent, vegetation_ b++; } } + else // zero out results + { + memset(result.canopy_h_metrics, 0, sizeof(result.canopy_h_metrics)); + result.h_canopy = 0.0; + } /* Clean Up */ delete [] gnd_index; @@ -561,8 +581,7 @@ void Atl08Dispatch::postResult (vegetation_t* result) int bufsize = recObj->serialize(&buffer, RecordObject::REFERENCE, size); /* Post Record */ - int post_status = MsgQ::STATE_TIMEOUT; - while((post_status = outQ->postCopy(buffer, bufsize, SYS_TIMEOUT)) == MsgQ::STATE_TIMEOUT); + while(outQ->postCopy(buffer, bufsize, SYS_TIMEOUT) == MsgQ::STATE_TIMEOUT); /* Reset Batch Index */ batchIndex = 0; diff --git a/plugins/icesat2/plugin/Atl08Dispatch.h b/plugins/icesat2/plugin/Atl08Dispatch.h index aaecdf03a..26e02ea4f 100644 --- a/plugins/icesat2/plugin/Atl08Dispatch.h +++ b/plugins/icesat2/plugin/Atl08Dispatch.h @@ -73,8 +73,8 @@ class Atl08Dispatch: public DispatchObject static const char* waveRecType; static const RecordObject::fieldDef_t waveRecDef[]; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const double PercentileInterval[NUM_PERCENTILES]; @@ -166,12 +166,12 @@ class Atl08Dispatch: public DispatchObject * Inline Methods *--------------------------------------------------------------------*/ - inline bool isVegetation (Atl03Reader::photon_t* ph) + static bool isVegetation (Atl03Reader::photon_t* ph) { return (ph->atl08_class == Icesat2Parms::ATL08_CANOPY || ph->atl08_class == Icesat2Parms::ATL08_TOP_OF_CANOPY); } - inline bool isGround (Atl03Reader::photon_t* ph) + static bool isGround (Atl03Reader::photon_t* ph) { return (ph->atl08_class == Icesat2Parms::ATL08_GROUND); } diff --git a/plugins/icesat2/plugin/CumulusIODriver.cpp b/plugins/icesat2/plugin/CumulusIODriver.cpp index 158ccc1d7..a603c627f 100644 --- a/plugins/icesat2/plugin/CumulusIODriver.cpp +++ b/plugins/icesat2/plugin/CumulusIODriver.cpp @@ -87,12 +87,12 @@ CumulusIODriver::CumulusIODriver (const Asset* _asset, const char* resource): memcpy(&day[0], &date[6], 3); day[2] = '\0'; - SafeString resourcepath("%s/ATLAS/%s/%s/%s/%s/%s/%s", asset->getPath(), product, version, year, month, day, resource); + FString resourcepath("%s/ATLAS/%s/%s/%s/%s/%s/%s", asset->getPath(), product, version, year, month, day, resource); /* * Determine ioBucket and ioKey */ - ioBucket = (char*)resourcepath.str(true); + ioBucket = (char*)resourcepath.c_str(true); /* * Differentiate Bucket and Key diff --git a/plugins/icesat2/plugin/GTArray.h b/plugins/icesat2/plugin/GTArray.h index 45ade1111..ae51eb0ce 100644 --- a/plugins/icesat2/plugin/GTArray.h +++ b/plugins/icesat2/plugin/GTArray.h @@ -93,8 +93,8 @@ const long GTArray::DefaultNumRows[Icesat2Parms::NUM_PAIR_TRACKS] = {H5Coro:: *----------------------------------------------------------------------------*/ template GTArray::GTArray(const Asset* asset, const char* resource, int track, const char* gt_dataset, H5Coro::context_t* context, long col, const long* prt_startrow, const long* prt_numrows): - gt{ H5Array(asset, resource, SafeString("/gt%dl/%s", track, gt_dataset).str(), context, col, prt_startrow[Icesat2Parms::RPT_L], prt_numrows[Icesat2Parms::RPT_L]), - H5Array(asset, resource, SafeString("/gt%dr/%s", track, gt_dataset).str(), context, col, prt_startrow[Icesat2Parms::RPT_R], prt_numrows[Icesat2Parms::RPT_R]) } + gt{ H5Array(asset, resource, FString("/gt%dl/%s", track, gt_dataset).c_str(), context, col, prt_startrow[Icesat2Parms::RPT_L], prt_numrows[Icesat2Parms::RPT_L]), + H5Array(asset, resource, FString("/gt%dr/%s", track, gt_dataset).c_str(), context, col, prt_startrow[Icesat2Parms::RPT_R], prt_numrows[Icesat2Parms::RPT_R]) } { } @@ -122,7 +122,7 @@ template bool GTArray::trim(long* prt_offset) { if(!prt_offset) return false; - else return (gt[Icesat2Parms::RPT_L].trim(prt_offset[Icesat2Parms::RPT_L]) && gt[Icesat2Parms::RPT_R].trim(prt_offset[Icesat2Parms::RPT_R])); + return (gt[Icesat2Parms::RPT_L].trim(prt_offset[Icesat2Parms::RPT_L]) && gt[Icesat2Parms::RPT_R].trim(prt_offset[Icesat2Parms::RPT_R])); } /*---------------------------------------------------------------------------- diff --git a/plugins/icesat2/plugin/GTDArray.cpp b/plugins/icesat2/plugin/GTDArray.cpp index e851a2343..574a1c425 100644 --- a/plugins/icesat2/plugin/GTDArray.cpp +++ b/plugins/icesat2/plugin/GTDArray.cpp @@ -52,8 +52,8 @@ const long GTDArray::DefaultNumRows[Icesat2Parms::NUM_PAIR_TRACKS] = {H5Coro::AL * Constructor *----------------------------------------------------------------------------*/ GTDArray::GTDArray(const Asset* asset, const char* resource, int track, const char* gt_dataset, H5Coro::context_t* context, long col, const long* prt_startrow, const long* prt_numrows): - gt{ H5DArray(asset, resource, SafeString("/gt%dl/%s", track, gt_dataset).str(), context, col, prt_startrow[Icesat2Parms::RPT_L], prt_numrows[Icesat2Parms::RPT_L]), - H5DArray(asset, resource, SafeString("/gt%dr/%s", track, gt_dataset).str(), context, col, prt_startrow[Icesat2Parms::RPT_R], prt_numrows[Icesat2Parms::RPT_R]) } + gt{ H5DArray(asset, resource, FString("/gt%dl/%s", track, gt_dataset).c_str(), context, col, prt_startrow[Icesat2Parms::RPT_L], prt_numrows[Icesat2Parms::RPT_L]), + H5DArray(asset, resource, FString("/gt%dr/%s", track, gt_dataset).c_str(), context, col, prt_startrow[Icesat2Parms::RPT_R], prt_numrows[Icesat2Parms::RPT_R]) } { } diff --git a/plugins/icesat2/plugin/Icesat2Parms.cpp b/plugins/icesat2/plugin/Icesat2Parms.cpp index e091254b5..574220a61 100644 --- a/plugins/icesat2/plugin/Icesat2Parms.cpp +++ b/plugins/icesat2/plugin/Icesat2Parms.cpp @@ -95,7 +95,7 @@ int Icesat2Parms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -110,35 +110,35 @@ uint8_t Icesat2Parms::getSpotNumber(sc_orient_t sc_orient, track_t track, int pa if(track == RPT_1) { if(pair == Icesat2Parms::RPT_L) return SPOT_1; - else if(pair == Icesat2Parms::RPT_R) return SPOT_2; + if(pair == Icesat2Parms::RPT_R) return SPOT_2; } - else if(track == RPT_2) + if(track == RPT_2) { if(pair == Icesat2Parms::RPT_L) return SPOT_3; - else if(pair == Icesat2Parms::RPT_R) return SPOT_4; + if(pair == Icesat2Parms::RPT_R) return SPOT_4; } - else if(track == RPT_3) + if(track == RPT_3) { if(pair == Icesat2Parms::RPT_L) return SPOT_5; - else if(pair == Icesat2Parms::RPT_R) return SPOT_6; + if(pair == Icesat2Parms::RPT_R) return SPOT_6; } } - else if(sc_orient == SC_FORWARD) + if(sc_orient == SC_FORWARD) { if(track == RPT_1) { if(pair == Icesat2Parms::RPT_L) return SPOT_6; - else if(pair == Icesat2Parms::RPT_R) return SPOT_5; + if(pair == Icesat2Parms::RPT_R) return SPOT_5; } - else if(track == RPT_2) + if(track == RPT_2) { if(pair == Icesat2Parms::RPT_L) return SPOT_4; - else if(pair == Icesat2Parms::RPT_R) return SPOT_3; + if(pair == Icesat2Parms::RPT_R) return SPOT_3; } - else if(track == RPT_3) + if(track == RPT_3) { if(pair == Icesat2Parms::RPT_L) return SPOT_2; - else if(pair == Icesat2Parms::RPT_R) return SPOT_1; + if(pair == Icesat2Parms::RPT_R) return SPOT_1; } } @@ -155,35 +155,35 @@ uint8_t Icesat2Parms::getGroundTrack (sc_orient_t sc_orient, track_t track, int if(track == RPT_1) { if(pair == Icesat2Parms::RPT_L) return GT1L; - else if(pair == Icesat2Parms::RPT_R) return GT1R; + if(pair == Icesat2Parms::RPT_R) return GT1R; } - else if(track == RPT_2) + if(track == RPT_2) { if(pair == Icesat2Parms::RPT_L) return GT2L; - else if(pair == Icesat2Parms::RPT_R) return GT2R; + if(pair == Icesat2Parms::RPT_R) return GT2R; } - else if(track == RPT_3) + if(track == RPT_3) { if(pair == Icesat2Parms::RPT_L) return GT3L; - else if(pair == Icesat2Parms::RPT_R) return GT3R; + if(pair == Icesat2Parms::RPT_R) return GT3R; } } - else if(sc_orient == SC_FORWARD) + if(sc_orient == SC_FORWARD) { if(track == RPT_1) { if(pair == Icesat2Parms::RPT_L) return GT1L; - else if(pair == Icesat2Parms::RPT_R) return GT1R; + if(pair == Icesat2Parms::RPT_R) return GT1R; } - else if(track == RPT_2) + if(track == RPT_2) { if(pair == Icesat2Parms::RPT_L) return GT2L; - else if(pair == Icesat2Parms::RPT_R) return GT2R; + if(pair == Icesat2Parms::RPT_R) return GT2R; } - else if(track == RPT_3) + if(track == RPT_3) { if(pair == Icesat2Parms::RPT_L) return GT3L; - else if(pair == Icesat2Parms::RPT_R) return GT3R; + if(pair == Icesat2Parms::RPT_R) return GT3R; } } @@ -195,14 +195,14 @@ uint8_t Icesat2Parms::getGroundTrack (sc_orient_t sc_orient, track_t track, int *----------------------------------------------------------------------------*/ Icesat2Parms::signal_conf_t Icesat2Parms::str2atl03cnf (const char* confidence_str) { - if (StringLib::match(confidence_str, "atl03_tep") || StringLib::match(confidence_str, "tep")) return CNF_POSSIBLE_TEP; - else if(StringLib::match(confidence_str, "atl03_not_considered") || StringLib::match(confidence_str, "not_considered")) return CNF_NOT_CONSIDERED; - else if(StringLib::match(confidence_str, "atl03_background") || StringLib::match(confidence_str, "background")) return CNF_BACKGROUND; - else if(StringLib::match(confidence_str, "atl03_within_10m") || StringLib::match(confidence_str, "within_10m")) return CNF_WITHIN_10M; - else if(StringLib::match(confidence_str, "atl03_low") || StringLib::match(confidence_str, "low")) return CNF_SURFACE_LOW; - else if(StringLib::match(confidence_str, "atl03_medium") || StringLib::match(confidence_str, "medium")) return CNF_SURFACE_MEDIUM; - else if(StringLib::match(confidence_str, "atl03_high") || StringLib::match(confidence_str, "high")) return CNF_SURFACE_HIGH; - else return ATL03_INVALID_CONFIDENCE; + if(StringLib::match(confidence_str, "atl03_tep") || StringLib::match(confidence_str, "tep")) return CNF_POSSIBLE_TEP; + if(StringLib::match(confidence_str, "atl03_not_considered") || StringLib::match(confidence_str, "not_considered")) return CNF_NOT_CONSIDERED; + if(StringLib::match(confidence_str, "atl03_background") || StringLib::match(confidence_str, "background")) return CNF_BACKGROUND; + if(StringLib::match(confidence_str, "atl03_within_10m") || StringLib::match(confidence_str, "within_10m")) return CNF_WITHIN_10M; + if(StringLib::match(confidence_str, "atl03_low") || StringLib::match(confidence_str, "low")) return CNF_SURFACE_LOW; + if(StringLib::match(confidence_str, "atl03_medium") || StringLib::match(confidence_str, "medium")) return CNF_SURFACE_MEDIUM; + if(StringLib::match(confidence_str, "atl03_high") || StringLib::match(confidence_str, "high")) return CNF_SURFACE_HIGH; + return ATL03_INVALID_CONFIDENCE; } /*---------------------------------------------------------------------------- @@ -210,11 +210,11 @@ Icesat2Parms::signal_conf_t Icesat2Parms::str2atl03cnf (const char* confidence_s *----------------------------------------------------------------------------*/ Icesat2Parms::quality_ph_t Icesat2Parms::str2atl03quality (const char* quality_ph_str) { - if (StringLib::match(quality_ph_str, "atl03_quality_nominal") || StringLib::match(quality_ph_str, "nominal")) return QUALITY_NOMINAL; - else if(StringLib::match(quality_ph_str, "atl03_quality_afterpulse") || StringLib::match(quality_ph_str, "afterpulse")) return QUALITY_POSSIBLE_AFTERPULSE; - else if(StringLib::match(quality_ph_str, "atl03_quality_impulse_response") || StringLib::match(quality_ph_str, "impulse_response")) return QUALITY_POSSIBLE_IMPULSE_RESPONSE; - else if(StringLib::match(quality_ph_str, "atl03_quality_tep") || StringLib::match(quality_ph_str, "tep")) return QUALITY_POSSIBLE_TEP; - else return ATL03_INVALID_QUALITY; + if(StringLib::match(quality_ph_str, "atl03_quality_nominal") || StringLib::match(quality_ph_str, "nominal")) return QUALITY_NOMINAL; + if(StringLib::match(quality_ph_str, "atl03_quality_afterpulse") || StringLib::match(quality_ph_str, "afterpulse")) return QUALITY_POSSIBLE_AFTERPULSE; + if(StringLib::match(quality_ph_str, "atl03_quality_impulse_response") || StringLib::match(quality_ph_str, "impulse_response")) return QUALITY_POSSIBLE_IMPULSE_RESPONSE; + if(StringLib::match(quality_ph_str, "atl03_quality_tep") || StringLib::match(quality_ph_str, "tep")) return QUALITY_POSSIBLE_TEP; + return ATL03_INVALID_QUALITY; } /*---------------------------------------------------------------------------- @@ -222,12 +222,12 @@ Icesat2Parms::quality_ph_t Icesat2Parms::str2atl03quality (const char* quality_p *----------------------------------------------------------------------------*/ Icesat2Parms::atl08_classification_t Icesat2Parms::str2atl08class (const char* classifiction_str) { - if (StringLib::match(classifiction_str, "atl08_noise") || StringLib::match(classifiction_str, "noise")) return ATL08_NOISE; - else if(StringLib::match(classifiction_str, "atl08_ground") || StringLib::match(classifiction_str, "ground")) return ATL08_GROUND; - else if(StringLib::match(classifiction_str, "atl08_canopy") || StringLib::match(classifiction_str, "canopy")) return ATL08_CANOPY; - else if(StringLib::match(classifiction_str, "atl08_top_of_canopy") || StringLib::match(classifiction_str, "top_of_canopy")) return ATL08_TOP_OF_CANOPY; - else if(StringLib::match(classifiction_str, "atl08_unclassified") || StringLib::match(classifiction_str, "unclassified")) return ATL08_UNCLASSIFIED; - else return ATL08_INVALID_CLASSIFICATION; + if(StringLib::match(classifiction_str, "atl08_noise") || StringLib::match(classifiction_str, "noise")) return ATL08_NOISE; + if(StringLib::match(classifiction_str, "atl08_ground") || StringLib::match(classifiction_str, "ground")) return ATL08_GROUND; + if(StringLib::match(classifiction_str, "atl08_canopy") || StringLib::match(classifiction_str, "canopy")) return ATL08_CANOPY; + if(StringLib::match(classifiction_str, "atl08_top_of_canopy") || StringLib::match(classifiction_str, "top_of_canopy")) return ATL08_TOP_OF_CANOPY; + if(StringLib::match(classifiction_str, "atl08_unclassified") || StringLib::match(classifiction_str, "unclassified")) return ATL08_UNCLASSIFIED; + return ATL08_INVALID_CLASSIFICATION; } /*---------------------------------------------------------------------------- @@ -235,10 +235,10 @@ Icesat2Parms::atl08_classification_t Icesat2Parms::str2atl08class (const char* c *----------------------------------------------------------------------------*/ Icesat2Parms::phoreal_geoloc_t Icesat2Parms::str2geoloc (const char* fmt_str) { - if (StringLib::match(fmt_str, "mean")) return PHOREAL_MEAN; - else if(StringLib::match(fmt_str, "median")) return PHOREAL_MEDIAN; - else if(StringLib::match(fmt_str, "center")) return PHOREAL_CENTER; - else return PHOREAL_UNSUPPORTED; + if(StringLib::match(fmt_str, "mean")) return PHOREAL_MEAN; + if(StringLib::match(fmt_str, "median")) return PHOREAL_MEDIAN; + if(StringLib::match(fmt_str, "center")) return PHOREAL_CENTER; + return PHOREAL_UNSUPPORTED; } /*---------------------------------------------------------------------------- @@ -427,10 +427,10 @@ Icesat2Parms::~Icesat2Parms (void) /*---------------------------------------------------------------------------- * cleanup *----------------------------------------------------------------------------*/ -void Icesat2Parms::cleanup (void) +void Icesat2Parms::cleanup (void) const { - if(atl03_geo_fields) delete atl03_geo_fields; - if(atl03_ph_fields) delete atl03_ph_fields; + delete atl03_geo_fields; + delete atl03_ph_fields; } /*---------------------------------------------------------------------------- @@ -808,7 +808,7 @@ void Icesat2Parms::get_lua_string_list (lua_State* L, int index, string_list_t** if(num_strings > 0 && provided) { /* Allocate string list */ - *string_list = new string_list_t; + *string_list = new string_list_t(EXPECTED_NUM_FIELDS); *provided = true; } @@ -821,7 +821,7 @@ void Icesat2Parms::get_lua_string_list (lua_State* L, int index, string_list_t** if(lua_isstring(L, -1)) { const char* item_str = LuaObject::getLuaString(L, -1); - SafeString item("%s", item_str); + string item(item_str); (*string_list)->add(item); mlog(DEBUG, "Adding %s to list of strings", item_str); } diff --git a/plugins/icesat2/plugin/Icesat2Parms.h b/plugins/icesat2/plugin/Icesat2Parms.h index 416e4919f..0b26633ec 100644 --- a/plugins/icesat2/plugin/Icesat2Parms.h +++ b/plugins/icesat2/plugin/Icesat2Parms.h @@ -204,7 +204,7 @@ class Icesat2Parms: public NetsvcParms } phoreal_geoloc_t; /* List of Strings */ - typedef List string_list_t; + typedef List string_list_t; /* YAPC Settings */ typedef struct { @@ -271,12 +271,12 @@ class Icesat2Parms: public NetsvcParms Icesat2Parms (lua_State* L, int index); ~Icesat2Parms (void); - void cleanup (void); + void cleanup (void) const; void get_lua_atl03_cnf (lua_State* L, int index, bool* provided); void get_lua_atl03_quality (lua_State* L, int index, bool* provided); void get_lua_atl08_class (lua_State* L, int index, bool* provided); void get_lua_yapc (lua_State* L, int index, bool* provided); - void get_lua_string_list (lua_State* L, int index, string_list_t** string_list, bool* provided); + static void get_lua_string_list (lua_State* L, int index, string_list_t** string_list, bool* provided); void get_lua_phoreal (lua_State* L, int index, bool* provided); }; diff --git a/plugins/icesat2/plugin/MeritRaster.cpp b/plugins/icesat2/plugin/MeritRaster.cpp index aba856b14..42fe5f003 100644 --- a/plugins/icesat2/plugin/MeritRaster.cpp +++ b/plugins/icesat2/plugin/MeritRaster.cpp @@ -75,7 +75,7 @@ RasterObject* MeritRaster::create(lua_State* L, GeoParms* _parms) *----------------------------------------------------------------------------*/ MeritRaster::~MeritRaster(void) { - if(cache) delete [] cache; + delete [] cache; if(asset) asset->releaseLuaObject(); } @@ -105,7 +105,7 @@ MeritRaster::MeritRaster(lua_State *L, GeoParms* _parms): gpsTime = TimeLib::gmt2gpstime(gmt_date); /* Inintialize Asset */ - asset = (Asset*)LuaObject::getLuaObjectByName(ASSET_NAME, Asset::OBJECT_TYPE); + asset = dynamic_cast(LuaObject::getLuaObjectByName(ASSET_NAME, Asset::OBJECT_TYPE)); if(!asset) throw RunTimeException(CRITICAL, RTE_ERROR, "Unable to find asset %s", ASSET_NAME); } @@ -152,7 +152,7 @@ uint32_t MeritRaster::getSamples (OGRGeometry* geo, int64_t gps, std::vectorbands.length(); i++) { - const char* name = _parms->bands[i]; + const char* name = _parms->bands[i].c_str(); if( isValidL8Band(name) || isValidS2Band(name) || isValidAlgoName(name)) { if(!bandsDict.find(name, &returnBandSample)) @@ -111,9 +111,9 @@ LandsatHlsRaster::LandsatHlsRaster(lua_State *L, GeoParms* _parms): bandsDict.add(name, returnBandSample); } - if(strcasecmp(_parms->bands[i], "NDSI") == 0) ndsi = true; - if(strcasecmp(_parms->bands[i], "NDVI") == 0) ndvi = true; - if(strcasecmp(_parms->bands[i], "NDWI") == 0) ndwi = true; + if(strcasecmp(_parms->bands[i].c_str(), "NDSI") == 0) ndsi = true; + if(strcasecmp(_parms->bands[i].c_str(), "NDVI") == 0) ndvi = true; + if(strcasecmp(_parms->bands[i].c_str(), "NDWI") == 0) ndwi = true; } } @@ -169,7 +169,7 @@ bool LandsatHlsRaster::findRasters(const OGRGeometry* geo) { try { - for(int i = 0; i < featuresList.length(); i++) + for(unsigned i = 0; i < featuresList.size(); i++) { OGRFeature* feature = featuresList[i]; OGRGeometry *rastergeo = feature->GetGeometryRef(); @@ -255,7 +255,10 @@ void LandsatHlsRaster::getGroupSamples (const rasters_group_t* rgroup, std::vect throw RunTimeException(DEBUG, RTE_ERROR, "Could not find valid Landsat8/Sentinel2 groupId"); double invalid = -999999.0; - double green, red, nir08, swir16; + double green; + double red; + double nir08; + double swir16; green = red = nir08 = swir16 = invalid; /* Collect samples for all rasters */ diff --git a/plugins/landsat/plugin/LandsatHlsRaster.h b/plugins/landsat/plugin/LandsatHlsRaster.h index 04081fbc5..c9b0a4040 100644 --- a/plugins/landsat/plugin/LandsatHlsRaster.h +++ b/plugins/landsat/plugin/LandsatHlsRaster.h @@ -73,7 +73,6 @@ class LandsatHlsRaster: public GeoIndexedRaster static RasterObject* create(lua_State* L, GeoParms* _parms) { return new LandsatHlsRaster(L, _parms); } - protected: /*-------------------------------------------------------------------- @@ -84,24 +83,23 @@ class LandsatHlsRaster: public GeoIndexedRaster virtual ~LandsatHlsRaster (void); void getIndexFile (const OGRGeometry* geo, std::string& file) final; - bool findRasters (const OGRGeometry* geo); + bool findRasters (const OGRGeometry* geo) override; void getGroupSamples (const rasters_group_t* rgroup, std::vector& slist, uint32_t flags) final; - /*-------------------------------------------------------------------- - * Data - *--------------------------------------------------------------------*/ private: - bool validateBand (band_type_t type, const char* bandName); - inline bool isValidL8Band (const char* bandName) {return validateBand(LANDSAT8, bandName);} - inline bool isValidS2Band (const char* bandName) {return validateBand(SENTINEL2,bandName);} - inline bool isValidAlgoBand (const char* bandName) {return validateBand(ALGOBAND, bandName);} - inline bool isValidAlgoName (const char* bandName) {return validateBand(ALGONAME, bandName);} + static bool validateBand (band_type_t type, const char* bandName); + + static bool isValidL8Band (const char* bandName) {return validateBand(LANDSAT8, bandName);} + static bool isValidS2Band (const char* bandName) {return validateBand(SENTINEL2,bandName);} + static bool isValidAlgoBand (const char* bandName) {return validateBand(ALGOBAND, bandName);} + static bool isValidAlgoName (const char* bandName) {return validateBand(ALGONAME, bandName);} /*-------------------------------------------------------------------- * Data *--------------------------------------------------------------------*/ + std::string filePath; std::string indexFile; Dictionary bandsDict; diff --git a/plugins/opendata/CMakeLists.txt b/plugins/opendata/CMakeLists.txt index bd800766e..cbef12a3e 100644 --- a/plugins/opendata/CMakeLists.txt +++ b/plugins/opendata/CMakeLists.txt @@ -1,21 +1,8 @@ # OPENDATA SlideRule Plugin top-level CMake build script project (OPENDATA LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) #################### # OPENDATA Plugin # @@ -30,16 +17,11 @@ set_target_properties (opendata PROPERTIES PREFIX "") find_package (Lua "5.3") find_package (GDAL) -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) +# Build Information # execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (opendata PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (opendata PUBLIC BINID="${TGTVER}") target_compile_options (opendata PUBLIC -Wall) # turn on "all" warnings diff --git a/plugins/pgc/CMakeLists.txt b/plugins/pgc/CMakeLists.txt index d5763582a..2f5003a19 100644 --- a/plugins/pgc/CMakeLists.txt +++ b/plugins/pgc/CMakeLists.txt @@ -1,21 +1,8 @@ # PGC SlideRule Plugin top-level CMake build script project (PGC LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) ############## # PGC Plugin # @@ -31,15 +18,10 @@ find_package (Lua "5.3") find_package (GDAL) # Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (pgc PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (pgc PUBLIC BINID="${TGTVER}") target_compile_options (pgc PUBLIC -Wall) # turn on "all" warnings diff --git a/plugins/pgc/plugin/ArcticDemMosaicRaster.h b/plugins/pgc/plugin/ArcticDemMosaicRaster.h index c02441595..31a7f3d95 100644 --- a/plugins/pgc/plugin/ArcticDemMosaicRaster.h +++ b/plugins/pgc/plugin/ArcticDemMosaicRaster.h @@ -62,7 +62,7 @@ class ArcticDemMosaicRaster: public GeoRaster ArcticDemMosaicRaster(lua_State* L, GeoParms* _parms): GeoRaster(L, _parms, - std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()).c_str(), + std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()), TimeLib::datetime2gps(2023, 01, 18, 20, 23, 42), true, /* Data is elevation */ &overrideTargetCRS) {} diff --git a/plugins/pgc/plugin/PgcDemStripsRaster.cpp b/plugins/pgc/plugin/PgcDemStripsRaster.cpp index 50c8b8ca3..a0e18a81b 100644 --- a/plugins/pgc/plugin/PgcDemStripsRaster.cpp +++ b/plugins/pgc/plugin/PgcDemStripsRaster.cpp @@ -89,9 +89,9 @@ bool PgcDemStripsRaster::openGeoIndex(const OGRGeometry* geo) emptyFeaturesList(); - for(double ix = minx; ix < maxx; ix++ ) + for(long ix = minx; ix < maxx; ix++ ) { - for(double iy = miny; iy < maxy; iy++) + for(long iy = miny; iy < maxy; iy++) { std::string newFile; _getIndexFile(ix, iy, newFile); @@ -118,11 +118,11 @@ bool PgcDemStripsRaster::openGeoIndex(const OGRGeometry* geo) while(OGRFeature* feature = layer->GetNextFeature()) { OGRFeature* fp = feature->Clone(); - featuresList.add(fp); + featuresList.push_back(fp); OGRFeature::DestroyFeature(feature); } - mlog(DEBUG, "Loaded %d index file features/rasters from: %s", featuresList.length(), newFile.c_str()); + mlog(DEBUG, "Loaded %lu index file features/rasters from: %s", featuresList.size(), newFile.c_str()); GDALClose((GDALDatasetH)dset); } catch(const RunTimeException& e) @@ -133,7 +133,7 @@ bool PgcDemStripsRaster::openGeoIndex(const OGRGeometry* geo) } } - if(featuresList.isempty()) + if(featuresList.empty()) { /* All geocells were 'empty' */ geoIndexPoly.empty(); @@ -176,7 +176,7 @@ bool PgcDemStripsRaster::findRasters(const OGRGeometry* geo) std::vector dates = {"start_datetime", "end_datetime"}; try { - for(int i = 0; i < featuresList.length(); i++) + for(unsigned i = 0; i < featuresList.size(); i++) { OGRFeature* feature = featuresList[i]; OGRGeometry* rastergeo = feature->GetGeometryRef(); diff --git a/plugins/pgc/plugin/PgcWkt.cpp b/plugins/pgc/plugin/PgcWkt.cpp index fe1dd0655..1609fe956 100644 --- a/plugins/pgc/plugin/PgcWkt.cpp +++ b/plugins/pgc/plugin/PgcWkt.cpp @@ -41,8 +41,8 @@ #include "OsApi.h" -static std::string pgcArcticWkt2 = ""; -static std::string pgcRemaWkt2 = ""; +static std::string pgcArcticWkt2; +static std::string pgcRemaWkt2; static void loadWKtFile(std::string& str, const std::string& wktPath) { diff --git a/plugins/pgc/plugin/RemaDemMosaicRaster.h b/plugins/pgc/plugin/RemaDemMosaicRaster.h index cca451f4a..9cadd4bff 100644 --- a/plugins/pgc/plugin/RemaDemMosaicRaster.h +++ b/plugins/pgc/plugin/RemaDemMosaicRaster.h @@ -63,7 +63,7 @@ class RemaDemMosaicRaster: public GeoRaster RemaDemMosaicRaster(lua_State* L, GeoParms* _parms): GeoRaster(L, _parms, - std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()).c_str(), + std::string(_parms->asset->getPath()).append("/").append(_parms->asset->getIndex()), TimeLib::datetime2gps(2023, 02, 24, 18, 51, 44), true, /* Data is elevation */ &overrideTargetCRS) {} diff --git a/plugins/swot/CMakeLists.txt b/plugins/swot/CMakeLists.txt index 1e75e7c94..0220d1cef 100644 --- a/plugins/swot/CMakeLists.txt +++ b/plugins/swot/CMakeLists.txt @@ -1,21 +1,8 @@ # SWOT SlideRule Plugin top-level CMake build script project (SWOT LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) ############### # SWOT Plugin # @@ -30,16 +17,11 @@ set_target_properties (swot PROPERTIES PREFIX "") find_package (Lua "5.3") find_package (GDAL) -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) +# Build Information # execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (swot PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (swot PUBLIC BINID="${TGTVER}") target_compile_options (swot PUBLIC -Wall) # turn on "all" warnings diff --git a/plugins/swot/plugin/SwotL2Reader.cpp b/plugins/swot/plugin/SwotL2Reader.cpp index b623305cc..598639942 100644 --- a/plugins/swot/plugin/SwotL2Reader.cpp +++ b/plugins/swot/plugin/SwotL2Reader.cpp @@ -53,8 +53,8 @@ ******************************************************************************/ const char* SwotL2Reader::OBJECT_TYPE = "SwotL2Reader"; -const char* SwotL2Reader::LuaMetaName = "SwotL2Reader"; -const struct luaL_Reg SwotL2Reader::LuaMetaTable[] = { +const char* SwotL2Reader::LUA_META_NAME = "SwotL2Reader"; +const struct luaL_Reg SwotL2Reader::LUA_META_TABLE[] = { {"stats", luaStats}, {NULL, NULL} }; @@ -98,10 +98,10 @@ int SwotL2Reader::luaCreate (lua_State* L) try { /* Get Parameters */ - asset = (Asset*)getLuaObject(L, 1, Asset::OBJECT_TYPE); + asset = dynamic_cast(getLuaObject(L, 1, Asset::OBJECT_TYPE)); const char* resource = getLuaString(L, 2); const char* outq_name = getLuaString(L, 3); - parms = (SwotParms*)getLuaObject(L, 4, SwotParms::OBJECT_TYPE); + parms = dynamic_cast(getLuaObject(L, 4, SwotParms::OBJECT_TYPE)); bool send_terminator = getLuaBoolean(L, 5, true, true); /* Return Reader Object */ @@ -130,8 +130,7 @@ void SwotL2Reader::init (void) * Constructor *----------------------------------------------------------------------------*/ SwotL2Reader::SwotL2Reader (lua_State* L, Asset* _asset, const char* _resource, const char* outq_name, SwotParms* _parms, bool _send_terminator): - LuaObject(L, OBJECT_TYPE, LuaMetaName, LuaMetaTable), - context{}, + LuaObject(L, OBJECT_TYPE, LUA_META_NAME, LUA_META_TABLE), region(_asset, _resource, _parms, &context) { /* Initialize Reader */ @@ -171,7 +170,7 @@ SwotL2Reader::SwotL2Reader (lua_State* L, Asset* _asset, const char* _resource, { info_t* info = new info_t; info->reader = this; - info->variable_name = parms->variables[i].str(true); + info->variable_name = StringLib::duplicate(parms->variables[i].c_str()); varPid[i] = new Thread(varThread, info); } } @@ -195,10 +194,10 @@ SwotL2Reader::~SwotL2Reader (void) { active = false; - if(geoPid) delete geoPid; + delete geoPid; for(int i = 0; i < threadCount - 1; i++) { - if(varPid[i]) delete varPid[i]; + delete varPid[i]; } delete outQ; @@ -257,9 +256,9 @@ SwotL2Reader::Region::~Region (void) /*---------------------------------------------------------------------------- * Region::cleanup *----------------------------------------------------------------------------*/ -void SwotL2Reader::Region::cleanup (void) +void SwotL2Reader::Region::cleanup (void) const { - if(inclusion_mask) delete [] inclusion_mask; + delete [] inclusion_mask; } /*---------------------------------------------------------------------------- @@ -286,7 +285,7 @@ void SwotL2Reader::Region::polyregion (SwotParms* _parms) bool first_line_found = false; bool last_line_found = false; int line = 0; - while(line < lat.size) + while(line < lat.size && !last_line_found) { bool inclusion = false; @@ -307,11 +306,10 @@ void SwotL2Reader::Region::polyregion (SwotParms* _parms) first_line_found = true; first_line = line; } - else if(first_line_found && !last_line_found && !inclusion) + else if(first_line_found && !inclusion) { /* Set Last Line */ last_line_found = true; - break; // full extent found! } /* Bump Line */ @@ -321,7 +319,7 @@ void SwotL2Reader::Region::polyregion (SwotParms* _parms) /* Set Number of Segments */ if(first_line_found) { - num_lines = line - first_line; + num_lines = (line - 1) - first_line; } /* Delete Projected Polygon */ @@ -405,7 +403,7 @@ void SwotL2Reader::checkComplete (void) void* SwotL2Reader::geoThread (void* parm) { /* Get Thread Info */ - SwotL2Reader* reader = (SwotL2Reader*)parm; + SwotL2Reader* reader = static_cast(parm); /* Calculate Total Size of Record Data */ int total_size = offsetof(geo_rec_t, scan) + (sizeof(scan_rec_t) * reader->region.num_lines); @@ -449,7 +447,7 @@ void* SwotL2Reader::varThread (void* parm) { /* Get Thread Info */ info_t* info = (info_t*)parm; - SwotL2Reader* reader = (SwotL2Reader*)info->reader; + SwotL2Reader* reader = info->reader; stats_t local_stats = {0, 0, 0, 0, 0}; /* Initialize Results */ @@ -519,7 +517,7 @@ void* SwotL2Reader::varThread (void* parm) reader->checkComplete(); /* Clean Up */ - if(results.data) delete [] results.data; + delete [] results.data; delete [] info->variable_name; delete info; @@ -542,7 +540,7 @@ int SwotL2Reader::luaStats (lua_State* L) try { /* Get Self */ - lua_obj = (SwotL2Reader*)getLuaSelf(L, 1); + lua_obj = dynamic_cast(getLuaSelf(L, 1)); } catch(const RunTimeException& e) { diff --git a/plugins/swot/plugin/SwotL2Reader.h b/plugins/swot/plugin/SwotL2Reader.h index 23e84b31a..16f497f83 100644 --- a/plugins/swot/plugin/SwotL2Reader.h +++ b/plugins/swot/plugin/SwotL2Reader.h @@ -61,8 +61,8 @@ class SwotL2Reader: public LuaObject static const char* OBJECT_TYPE; - static const char* LuaMetaName; - static const struct luaL_Reg LuaMetaTable[]; + static const char* LUA_META_NAME; + static const struct luaL_Reg LUA_META_TABLE[]; static const char* varRecType; static const RecordObject::fieldDef_t varRecDef[]; @@ -133,7 +133,7 @@ class SwotL2Reader: public LuaObject Region (Asset* asset, const char* resource, SwotParms* _parms, H5Coro::context_t* context); ~Region (void); - void cleanup (void); + void cleanup (void) const; void polyregion (SwotParms* _parms); void rasterregion (SwotParms* _parms); diff --git a/plugins/swot/plugin/SwotParms.cpp b/plugins/swot/plugin/SwotParms.cpp index 19cfdfae1..770cfe653 100644 --- a/plugins/swot/plugin/SwotParms.cpp +++ b/plugins/swot/plugin/SwotParms.cpp @@ -65,7 +65,7 @@ int SwotParms::luaCreate (lua_State* L) } catch(const RunTimeException& e) { - mlog(e.level(), "Error creating %s: %s", LuaMetaName, e.what()); + mlog(e.level(), "Error creating %s: %s", LUA_META_NAME, e.what()); return returnLuaStatus(L, false); } } @@ -86,7 +86,8 @@ int64_t SwotParms::deltatime2timestamp (double delta_time) * Constructor *----------------------------------------------------------------------------*/ SwotParms::SwotParms(lua_State* L, int index): - NetsvcParms(L, index) + NetsvcParms(L, index), + variables(EXPECTED_NUM_FIELDS) { bool provided = false; @@ -146,7 +147,7 @@ void SwotParms::get_lua_string_list (lua_State* L, int index, string_list_t& str if(lua_isstring(L, -1)) { const char* item_str = LuaObject::getLuaString(L, -1); - SafeString item("%s", item_str); + string item(item_str); string_list.add(item); mlog(DEBUG, "Adding %s to list of strings", item_str); } diff --git a/plugins/swot/plugin/SwotParms.h b/plugins/swot/plugin/SwotParms.h index a242c1755..4c9c8b8f6 100644 --- a/plugins/swot/plugin/SwotParms.h +++ b/plugins/swot/plugin/SwotParms.h @@ -62,7 +62,7 @@ class SwotParms: public NetsvcParms * Typedefs *--------------------------------------------------------------------*/ - typedef List string_list_t; + typedef List string_list_t; /*-------------------------------------------------------------------- * Methods @@ -86,7 +86,7 @@ class SwotParms: public NetsvcParms SwotParms (lua_State* L, int index); ~SwotParms (void); void cleanup (void); - void get_lua_string_list (lua_State* L, int index, string_list_t& string_list, bool* provided); + static void get_lua_string_list (lua_State* L, int index, string_list_t& string_list, bool* provided); }; #endif /* __swot_parms__ */ diff --git a/plugins/usgs3dep/CMakeLists.txt b/plugins/usgs3dep/CMakeLists.txt index 31ecc83b1..776a00a3f 100644 --- a/plugins/usgs3dep/CMakeLists.txt +++ b/plugins/usgs3dep/CMakeLists.txt @@ -1,21 +1,8 @@ # usgs3dep SlideRule Plugin top-level CMake build script project (USGS3DEP LANGUAGES CXX) - -################# -# CMake Options # -################# - -set (CMAKE_LEGACY_CYGWIN_WIN32 0) # Squelch a warning when building on Win32/Cygwin cmake_minimum_required (VERSION 3.13.0) # The minimum CMake version is chosen to enable policy CMP0079 -cmake_policy(SET CMP0079 NEW) # add link library to target which is not built in this directory -cmake_policy(SET CMP0053 NEW) # simplified variable escape processing (recommended by cmake) - -################### -# Project Options # -################### - -option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +include(${CMAKE_SOURCE_DIR}/../../project-config.cmake) #################### # usgs3dep Plugin # @@ -30,16 +17,11 @@ set_target_properties (usgs3dep PROPERTIES PREFIX "") find_package (Lua "5.3") find_package (GDAL) -# Version Information # -file(STRINGS ${PROJECT_SOURCE_DIR}/../../version.txt TGTVER) +# Build Information # execute_process (COMMAND git --work-tree ${PROJECT_SOURCE_DIR}/../.. --git-dir ${PROJECT_SOURCE_DIR}/../../.git describe --abbrev --dirty --always --tags --long OUTPUT_VARIABLE BUILDINFO) string(REGEX REPLACE "\n$" "" BUILDINFO "${BUILDINFO}") target_compile_definitions (usgs3dep PUBLIC BUILDINFO="${BUILDINFO}") -# Set Environment Variables # -set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") -set (CONFDIR ${INSTALLDIR}/etc/sliderule) - # Compile Definitions # target_compile_definitions (usgs3dep PUBLIC BINID="${TGTVER}") target_compile_options (usgs3dep PUBLIC -Wall) # turn on "all" warnings diff --git a/plugins/usgs3dep/plugin/Usgs3dep1meterDemRaster.cpp b/plugins/usgs3dep/plugin/Usgs3dep1meterDemRaster.cpp index b9697cab8..ee05c1a38 100644 --- a/plugins/usgs3dep/plugin/Usgs3dep1meterDemRaster.cpp +++ b/plugins/usgs3dep/plugin/Usgs3dep1meterDemRaster.cpp @@ -97,7 +97,7 @@ bool Usgs3dep1meterDemRaster::findRasters(const OGRGeometry* geo) { try { - for(int i = 0; i < featuresList.length(); i++) + for(unsigned i = 0; i < featuresList.size(); i++) { OGRFeature* feature = featuresList[i]; OGRGeometry *rastergeo = feature->GetGeometryRef(); diff --git a/project-config.cmake b/project-config.cmake new file mode 100644 index 000000000..bdaa5c98a --- /dev/null +++ b/project-config.cmake @@ -0,0 +1,145 @@ +################# +# CMake Options # +################# + +# Squelch a warning when building on Win32/Cygwin +set (CMAKE_LEGACY_CYGWIN_WIN32 0) + +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(default_build_type "Release") + if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(default_build_type "Debug") + endif() + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) +endif() + +# Set a default platform +if(NOT CMAKE_BUILD_PLATFORM) + set(CMAKE_BUILD_PLATFORM "Linux" CACHE STRING "Choose the target platform." FORCE) +endif() + +# Configure static analysis +if(CMAKE_BUILD_TYPE MATCHES "Debug") + message(STATUS "Enabling static analysis") + + # clang-tidy + set (CLANG_TIDY_CHECKS + clang-analyzer-* + concurrency-* + misc-* + performance-* + portability-* + readability-* + -readability-braces-around-statements + -readability-implicit-bool-conversion + -readability-magic-numbers + -misc-non-private-member-variables-in-classes + ) + list(JOIN CLANG_TIDY_CHECKS_PARM "," CLANG_TIDY_CHECKS) + set (CMAKE_CXX_CLANG_TIDY + clang-tidy; + -header-filter=.; + -checks=${CLANG_TIDY_CHECKS_PARM}; +# -checks=clang-analyzer-*,concurrency-*,misc-*,performance-*,portability-*,readability-*,-readability-braces-around-statements,-readability-implicit-bool-conversion,-readability-magic-numbers,-misc-non-private-member-variables-in-classes; + -warnings-as-errors=*; + ) + + # cppcheck + find_program (CMAKE_CXX_CPPCHECK NAMES cppcheck) + list (APPEND CMAKE_CXX_CPPCHECK + "--quiet" + "--enable=all" + "--suppress=unmatchedSuppression" + "--suppress=unusedFunction" + "--suppress=missingInclude" + "--suppress=noOperatorEq" + "--suppress=noCopyConstructor" + "--suppress=unusedPrivateFunction" + "--suppress=memsetClassFloat" + "--suppress=useStlAlgorithm" + "--suppress=constParameter:*/Table.h" + "--suppress=constParameter:*/Ordering.h" + "--suppress=constParameter:*/List.h" + "--suppress=constParameter:*/Dictionary.h" + "--suppress=unreadVariable:*/TimeLib.cpp" + "--suppress=invalidPointerCast:*/H5Array.h" + "--error-exitcode=1" + "-DLLONG_MAX" + ) +endif() + +################### +# Project Options # +################### + +# Project Options # + +option (SHARED_LIBRARY "Create shared library instead of sliderule binary" OFF) +option (SERVER_APP "Create sliderule server binary" ON) + +# Library Options # + +option (ENABLE_COMPAT "Use C++11 for compatibility with older compilers" OFF) +option (ENABLE_ADDRESS_SANITIZER "Instrument code with AddressSanitizer for memory error detection" OFF) +option (ENABLE_TIME_HEARTBEAT "Instruct TimeLib to use a 1KHz heart beat timer to set millisecond time resolution" OFF) +option (ENABLE_CUSTOM_ALLOCATOR "Override new and delete operators globally for debug purposes" OFF) +option (ENABLE_H5CORO_ATTRIBUTE_SUPPORT "H5Coro will read and process attribute messages" OFF) +option (ENABLE_APACHE_ARROW_10_COMPAT "Use Apache Arrow 11 interface" OFF) +option (ENABLE_BEST_EFFORT_CONDA_ENV "Attempt to alleviate some issues with running in a conda environment") + +# Package Options # + +option (USE_ARROW_PACKAGE "Include the Apache Arrow package" OFF) +option (USE_AWS_PACKAGE "Include the AWS package" OFF) +option (USE_CCSDS_PACKAGE "Include the CCSDS package" ON) +option (USE_GEO_PACKAGE "Include the GEO package" OFF) +option (USE_H5_PACKAGE "Include the HDF5 package" ON) +option (USE_LEGACY_PACKAGE "Include the Legacy package" ON) +option (USE_NETSVC_PACKAGE "Include the Network Services package" OFF) +option (USE_PISTACHE_PACKAGE "Include the Pistache package" OFF) + +# Platform Options # + +option (ENABLE_TRACING "Instantiate trace points" OFF) +option (ENABLE_TERMINAL "Instantiate terminal messages" ON) + +# Version Information # + +file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/version.txt TGTVER) +string(REPLACE "v" "" LIBVER ${TGTVER}) + +# C++ Version # + +if(${ENABLE_COMPAT}) + set(CXX_VERSION 11) +else() + set(CXX_VERSION 17) # required if using pistache package +endif() + +# Platform # + +set_property(GLOBAL PROPERTY platform "") + +if(CMAKE_BUILD_PLATFORM MATCHES "Linux") + + # Prefer libraries installed in /usr/local + INCLUDE_DIRECTORIES(/usr/local/include) + LINK_DIRECTORIES(/usr/local/lib) + + # Set Environment Variables + set (INSTALLDIR /usr/local CACHE STRING "Installation directory for library and executables") + set (CONFDIR ${INSTALLDIR}/etc/sliderule) + set (INCDIR ${INSTALLDIR}/include/sliderule) + +elseif(CMAKE_BUILD_PLATFORM MATCHES "Windows") + + # Set Environment Variables + set (INSTALLDIR "C:\\Program Files\\SlideRule" CACHE STRING "Installation directory for library and executables") + set (CONFDIR ${INSTALLDIR}\etc\sliderule) + set (INCDIR ${INSTALLDIR}\include\sliderule) + +endif() + +set (RUNTIMEDIR ${CONFDIR} CACHE STRING "Runtime directory for plugins and configuration scripts") diff --git a/scripts/apps/server.lua b/scripts/apps/server.lua index 280812cf0..99c7f6379 100644 --- a/scripts/apps/server.lua +++ b/scripts/apps/server.lua @@ -2,25 +2,6 @@ local global = require("global") local asset = require("asset") local json = require("json") --------------------------------------------------- --- Functions --------------------------------------------------- - --- Returns All Available Endpoint Scripts -- -local function available_scripts() - local i = 0 - local scripts = {} - local pdir = io.popen('ls "' .. __confdir .. '/api"') - if pdir ~= nil then - for filename in pdir:lines() do - i = i + 1 - scripts[i] = filename - end - pdir:close() - end - return scripts -end - -------------------------------------------------- -- Process Arguments -------------------------------------------------- @@ -73,7 +54,7 @@ sys.setlvl(core.LOG | core.TRACE | core.METRIC, event_level) -- set level global local monitor = core.monitor(core.LOG, core.DEBUG, event_format):name("EventMonitor") -- monitor only logs monitor:tail(1024) -local dispatcher = core.dispatcher(core.EVENTQ):name("EventDispatcher") +local dispatcher = core.dispatcher(core.EVENTQ, 1):name("EventDispatcher") dispatcher:attach(monitor, "eventrec") dispatcher:run() @@ -107,13 +88,6 @@ end -- Configure Application Endpoints -- local source_endpoint = core.endpoint(normal_mem_thresh, stream_mem_thresh):name("SourceEndpoint") -for _,script in ipairs(available_scripts()) do - local s = script:find(".lua") - if s then - local metric_name = script:sub(0,s-1) - source_endpoint:metric(metric_name) - end -end -- Configure Provisioning System Authentication -- netsvc.psurl(ps_url) @@ -125,7 +99,6 @@ end -- Run Application HTTP Server -- local app_server = core.httpd(app_port):name("AppServer") -app_server:metric() -- register server metrics app_server:attach(source_endpoint, "/source") -------------------------------------------------- diff --git a/scripts/endpoints/event.lua b/scripts/endpoints/event.lua index 5dc1e3636..99e98c407 100644 --- a/scripts/endpoints/event.lua +++ b/scripts/endpoints/event.lua @@ -25,7 +25,7 @@ local duration = parm["duration"] or 0 -- Attach monitor to post event to response queue -- local userevents = core.dispatcher(core.EVENTQ) -userevents:attach(core.monitor(type, level, format, rspq), "eventrec") +userevents:attach(core.pmonitor(type, level, format, rspq), "eventrec") userevents:run() -- Bounds check duration diff --git a/scripts/extensions/console.lua b/scripts/extensions/console.lua index 84f2113a4..08a556982 100644 --- a/scripts/extensions/console.lua +++ b/scripts/extensions/console.lua @@ -1,7 +1,7 @@ local console_monitor = core.monitor(core.LOG, core.INFO, core.FMT_TEXT):name("console.monitor") console_monitor:tail(1024) -local console_dispatcher = core.dispatcher(core.EVENTQ):name("console.dispatcher") +local console_dispatcher = core.dispatcher(core.EVENTQ, 1):name("console.dispatcher") console_dispatcher:attach(console_monitor, "eventrec") console_dispatcher:run() diff --git a/scripts/selftests/credential_store.lua b/scripts/selftests/credential_store.lua index b984d55ea..284bf2072 100644 --- a/scripts/selftests/credential_store.lua +++ b/scripts/selftests/credential_store.lua @@ -15,20 +15,6 @@ runner.check(creds.secretAccessKey == "5678") runner.check(creds.sessionToken == "abcdefg") runner.check(creds.expiration == "2021-06-02 14:59:56+00:00") -print('\n------------------\nTest01: Credential Metrics\n------------------') - -endpoint = core.endpoint() -server = core.httpd(9081):attach(endpoint, "/source"):untilup() - -client = core.http("127.0.0.1", 9081) - -rsps = client:request("GET", "/source/version", "{}") -metrics = sys.metric("CredentialStore") -display2screen = json.encode(metrics) -print(display2screen) - -runner.check(metrics["CredentialStore.mycredentials:exp_gps"]["value"] == 1306681214000, "incorrect expiration time") - -- Clean Up -- server:destroy() diff --git a/scripts/selftests/geouser_raster.lua b/scripts/selftests/geouser_raster.lua index 4dbc33eb6..acaac7770 100644 --- a/scripts/selftests/geouser_raster.lua +++ b/scripts/selftests/geouser_raster.lua @@ -25,7 +25,7 @@ local encodedRaster = base64.encode( rasterfile ) local len = string.len(encodedRaster) local params = {data = encodedRaster, length = len, date = 0, elevation = true} -local robj = geo.userraster(params) +local robj = geo.userraster(params):name("userraster") runner.check(robj ~= nil) diff --git a/scripts/selftests/test_runner.lua b/scripts/selftests/test_runner.lua index de5da84cc..3e664df51 100644 --- a/scripts/selftests/test_runner.lua +++ b/scripts/selftests/test_runner.lua @@ -100,7 +100,6 @@ if __landsat__ then runner.script(landsat_td .. "landsat_reader.lua") end - -- Run usgs3dep Plugin Self Tests if __usgs3dep__ then local usg2dep_td = td .. "../../plugins/usgs3dep/selftests/" diff --git a/scripts/systests/coro.py b/scripts/systests/coro.py deleted file mode 100644 index 096341856..000000000 --- a/scripts/systests/coro.py +++ /dev/null @@ -1,153 +0,0 @@ -# python - -import sys -import srpybin - -############################################################################### -# DATA -############################################################################### - -# set resource parameters -resource0 = "UW_OSD.h5" -resource1 = "ATL06_20200714160647_02950802_003_01.h5" -resource2 = "ATL06_20181019065445_03150111_003_01.h5" -resource3 = "asdf.h5" -driver = "s3" -path = "sliderule/data/ATLAS" -region = "us-west-2" -endpoint = "https://s3.us-west-2.amazonaws.com" - -# expected small read -small_exp = [471, -1444, 1131, -258, 247] - -# expected big read -big_exp = [471, -1444, 1131, -258, 247] - -# expected single read -h_li_exp_1 = [3432.17578125, 3438.776611328125, 3451.01123046875, 3462.688232421875, 3473.559326171875] - -# expected parallel read -h_li_exp_2 = { '/gt1l/land_ice_segments/h_li': [3432.17578125, 3438.776611328125, 3451.01123046875, 3462.688232421875, 3473.559326171875], - '/gt2l/land_ice_segments/h_li': [3263.659912109375, 3258.362548828125, 3.4028234663852886e+38, 3233.031494140625, 3235.200927734375], - '/gt3l/land_ice_segments/h_li': [3043.489013671875, 3187.576171875, 3.4028234663852886e+38, 4205.04248046875, 2924.724365234375]} - -# expected negative read -bsnow_conf_exp_3 = [-1, -1, -1, -1, -1] - -############################################################################### -# UTILITY FUNCTIONS -############################################################################### - -def check_results(act, exp): - if type(exp) == dict: - for dataset in exp: - for i in range(len(exp[dataset])): - if exp[dataset][i] != act[dataset][i]: - return False - return True - else: - for i in range(len(exp)): - if exp[i] != act[i]: - return False - return True - -############################################################################### -# MAIN -############################################################################### - -if __name__ == '__main__': - - result = True - - ################### - # TESTSET 1 - ################### - - # Open Small ASDF H5 File # - asdf_small = srpybin.h5coro("asset1", resource0, "local", driver, "/data/ASDF", region, endpoint) - - # Run Meta Test # - meta = asdf_small.meta("/Waveforms/UW.OSD/UW.OSD..EHZ__2020-01-01T00:00:00__2020-01-01T05:13:04__raw_recording") - result = result and (meta['elements'] == 1878490) - result = result and (meta['typesize'] == 4) - result = result and (meta['datasize'] == 7513960) - result = result and (meta['datatype'] == 'INT32') - result = result and (meta['numcols'] == 1) - result = result and (meta['numrows'] == 1878490) - - # Read Data from Dataset # - v = asdf_small.read("/Waveforms/UW.OSD/UW.OSD..EHZ__2020-01-01T00:00:00__2020-01-01T05:13:04__raw_recording", 0, 57655, 5) - result = result and check_results(v, small_exp) - - # Read Attribute from Dataset # - a = asdf_small.read("/Waveforms/UW.OSD/UW.OSD..EHZ__2020-01-01T00:00:00__2020-01-01T05:13:04__raw_recording/sampling_rate") - result = result and (a[0] == 100.0) - - ################### - # TESTSET 2 - ################### - - # Open Large ASDF H5 File # - asdf_large = srpybin.h5coro("asset2", resource3, "local", driver, "/data/ASDF", region, endpoint) - - # Read Large Dataset from Small File Multiple Times # - v = asdf_large.read("/Waveforms/IM.I56H1/IM.I56H1..LWS__2020-12-29T00:00:00__2020-12-29T23:59:59__raw_recording", 0, 30000, 10) - v = asdf_large.read("/Waveforms/IM.I56H2/IM.I56H2..BDF__2020-01-26T00:00:00__2020-01-29T23:59:59__raw_recording", 0, 600000, 10) - v = asdf_large.read("/Waveforms/IM.I56H3/IM.I56H3..BDF__2020-07-14T20:58:20__2020-07-14T23:59:59__raw_recording", 0, 21000, 10) - v = asdf_large.read("/Waveforms/IM.I56H4/IM.I56H4..BDF__2020-01-01T00:00:00__2020-01-02T23:59:59__raw_recording", 0, 3450000, 10) - v = asdf_large.read("/Waveforms/IU.COR/IU.COR.30.LDO__2020-01-28T22:18:53__2020-01-29T23:59:59__raw_recording", 0, 14645, 10) - - ################### - # TESTSET 3 - ################### - - # Open ICESat-2 H5 File # - h5file1 = srpybin.h5coro("asset3", resource1, "iam-role", driver, path, region, endpoint) - - # Run Meta Test # - h_li_meta = h5file1.meta("/gt1l/land_ice_segments/h_li") - result = result and (h_li_meta['elements'] == 3563) - result = result and (h_li_meta['typesize'] == 4) - result = result and (h_li_meta['datasize'] == 14252) - result = result and (h_li_meta['datatype'] == 'FLOAT') - result = result and (h_li_meta['numcols'] == 1) - result = result and (h_li_meta['numrows'] == 3563) - - # Run Single and Parallel Tests # - for test in range(100000): - if test % 100 == 0: - sys.stdout.write(".") - sys.stdout.flush() - - # Perform Single Read # - h_li_1 = h5file1.read("/gt1l/land_ice_segments/h_li", 0, 19, 5) - result = result and check_results(h_li_1, h_li_exp_1) - - # Perform Parallel Read # - datasets = [["/gt1l/land_ice_segments/h_li", 0, 19, 5], - ["/gt2l/land_ice_segments/h_li", 0, 19, 5], - ["/gt3l/land_ice_segments/h_li", 0, 19, 5], - ["/gt2r/land_ice_segments/geophysical/bsnow_conf", 0, 19, 5]] - h_li_2 = h5file1.readp(datasets) - result = result and check_results(h_li_2, h_li_exp_2) - - # check result for early exit from loop - if not result: - break - - ################### - # TESTSET 4 - ################### - - # Open ICESat-2 H5 File # - h5file2 = srpybin.h5coro("asset4", resource2, "iam-role", driver, path, region, endpoint) - - # Run Negative Test # - bsnow_conf = h5file2.read("/gt2r/land_ice_segments/geophysical/bsnow_conf", 0, 19, 5) - result = result and check_results(bsnow_conf, bsnow_conf_exp_3) - - # Display Results # - if result: - print("\nPassed H5Coro Test") - else: - print("\nFailed H5Coro Test") diff --git a/targets/binding-python/CMakeLists.txt b/targets/binding-python/CMakeLists.txt deleted file mode 100644 index be4f538b8..000000000 --- a/targets/binding-python/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -# Find pybind11 Library -find_package(pybind11 REQUIRED) - -# Build Bindings -if (pybind11_FOUND) - - # PyBind11 Module - message (STATUS "Building srpybin Python bindings") - - pybind11_add_module(srpybin - ${CMAKE_CURRENT_LIST_DIR}/pyH5Coro.cpp - ${CMAKE_CURRENT_LIST_DIR}/pyLua.cpp - ${CMAKE_CURRENT_LIST_DIR}/pyLogger.cpp - ${CMAKE_CURRENT_LIST_DIR}/pyPlugin.cpp - ${CMAKE_CURRENT_LIST_DIR}/pyCredentialStore.cpp - ${CMAKE_CURRENT_LIST_DIR}/pyS3Cache.cpp - ${CMAKE_CURRENT_LIST_DIR}/init.cpp) - - target_include_directories (srpybin PRIVATE ${CMAKE_CURRENT_LIST_DIR}) - - target_link_libraries (srpybin PUBLIC -Wl,--whole-archive slideruleLib -Wl,--no-whole-archive) - - set_target_properties (srpybin PROPERTIES PREFIX "") - set_target_properties (srpybin PROPERTIES CXX_STANDARD ${CXX_VERSION}) - - install (TARGETS srpybin DESTINATION ${INSTALLDIR}/lib) - - # ICESat-2 Plugin # - message (STATUS "Including icesat2 plugin in python bindings") - target_compile_definitions (slideruleLib PUBLIC __icesat2__) - target_compile_definitions (slideruleLib PUBLIC BINID=LIBID) - target_sources(slideruleLib - PRIVATE - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/icesat2.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/Atl03Reader.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/Atl03Indexer.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/Atl06Dispatch.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/Atl08Dispatch.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/CumulusIODriver.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/GTDArray.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/Icesat2Parms.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/MeritRaster.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/PluginMetrics.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/UT_Atl03Reader.cpp - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin/UT_Atl06Dispatch.cpp - ) - target_include_directories (slideruleLib - PUBLIC - ${PROJECT_SOURCE_DIR}/plugins/icesat2/plugin - $ - ) - -else () - - message (FATAL_ERROR "Unable to build srpybin bindings... required libraries not found") - -endif () diff --git a/targets/binding-python/Dockerfile.arm b/targets/binding-python/Dockerfile.arm deleted file mode 100644 index 9467ce4b7..000000000 --- a/targets/binding-python/Dockerfile.arm +++ /dev/null @@ -1,46 +0,0 @@ -FROM continuumio/miniconda3 -MAINTAINER JP Swinski (jp.swinski@nasa.gov) - -# Install system dependencies -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive \ - apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - pkg-config \ - cmake \ - git \ - wget \ - libcurl4-openssl-dev \ - libtiff-dev \ - libsqlite3-dev \ - sqlite3 \ - && rm -rf /var/lib/apt/lists/* - -# instal proj9 gdal dependency -WORKDIR / -RUN wget http://download.osgeo.org/proj/proj-9.2.0.tar.gz -RUN tar xvfz proj-9.2.0.tar.gz -RUN mkdir -p /proj9/build -WORKDIR /proj9/build -RUN cmake /proj-9.2.0 -DCMAKE_BUILD_TYPE=Release -RUN make -j8 -RUN make install -RUN ldconfig - -# Environment -ENV PYTHONPATH=/usr/local/lib -RUN conda create --name srpy -SHELL ["conda", "run", "-n", "srpy", "/bin/bash", "-c"] - -# Install conda-managed dependencies -RUN conda install -c conda-forge -y lua openssl r-uuid libcurl Zlib gdal proj rapidjson pybind11 requests - -# Copy sliderule source repository -COPY sliderule /sliderule -WORKDIR /sliderule/targets/binding-python -RUN make config-conda && make && make install - -# Support interactive mode -WORKDIR /sliderule -ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "srpy", "python"] \ No newline at end of file diff --git a/targets/binding-python/Dockerfile.x86 b/targets/binding-python/Dockerfile.x86 deleted file mode 100644 index 4e4638662..000000000 --- a/targets/binding-python/Dockerfile.x86 +++ /dev/null @@ -1,30 +0,0 @@ -FROM continuumio/miniconda3 -MAINTAINER JP Swinski (jp.swinski@nasa.gov) - -# Install system dependencies -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive \ - apt-get install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - pkg-config \ - cmake \ - git \ - && rm -rf /var/lib/apt/lists/* - -# Environment -ENV PYTHONPATH=/usr/local/lib -RUN conda create --name srpy -SHELL ["conda", "run", "-n", "srpy", "/bin/bash", "-c"] - -# Install conda-managed dependencies -RUN conda install -c conda-forge -y lua openssl r-uuid libcurl Zlib gdal proj rapidjson pybind11 requests - -# Copy sliderule source repository -COPY sliderule /sliderule -WORKDIR /sliderule/targets/binding-python -RUN make config-conda && make && make install - -# Support interactive mode -WORKDIR /sliderule -ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "srpy", "python"] \ No newline at end of file diff --git a/targets/binding-python/Makefile b/targets/binding-python/Makefile deleted file mode 100644 index 7db6f569a..000000000 --- a/targets/binding-python/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -ROOT = $(shell pwd)/../.. -BUILD = $(ROOT)/build -STAGE = $(ROOT)/stage - -VERSION ?= latest -VERSION_TOKENS := $(subst ., ,$(lastword $(VERSION))) -MAJOR_VERSION := $(word 1,$(VERSION_TOKENS)) -ECR := 742127912612.dkr.ecr.us-west-2.amazonaws.com -ARCH = arm -DOCKEROPTS ?= -SCRIPT ?= - - -SLIDERULE_SOURCE_DIR = $(ROOT) -BINDINGS_BUILD_DIR = $(BUILD)/srpy -BINDINGS_STAGE_DIR ?= $(STAGE)/srpy -INSTALL_DIR ?= /usr/local/lib - -PYTHONCFG := -DPYTHON_BINDINGS=ON -PYTHONCFG += -DUSE_H5_PACKAGE=ON -PYTHONCFG += -DUSE_AWS_PACKAGE=ON -PYTHONCFG += -DUSE_LEGACY_PACKAGE=ON -PYTHONCFG += -DUSE_CCSDS_PACKAGE=ON -PYTHONCFG += -DUSE_GEO_PACKAGE=ON -PYTHONCFG += -DUSE_NETSVC_PACKAGE=ON -PYTHONCFG += -DENABLE_H5CORO_ATTRIBUTE_SUPPORT=ON -PYTHONCFG += -DH5CORO_THREAD_POOL_SIZE=0 -PYTHONCFG += -DH5CORO_MAXIMUM_NAME_SIZE=192 - -all: bindings - -prep: ## create temporary directories needed for build - mkdir -p $(BINDINGS_BUILD_DIR) - -config: prep ## configure make for python bindings (using system environent) - cd $(BINDINGS_BUILD_DIR); cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_BEST_EFFORT_CONDA_ENV=ON $(PYTHONCFG) -DINSTALLDIR=$(BINDINGS_STAGE_DIR) $(ROOT) - -config-conda: prep ## configure make for python bindings (using conda environment) - cd $(BINDINGS_BUILD_DIR); cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$(CONDA_PREFIX) $(PYTHONCFG) -DINSTALLDIR=$(BINDINGS_STAGE_DIR) $(ROOT) - -bindings: ## build the bindings - make -j4 -C $(BINDINGS_BUILD_DIR) - make -C $(BINDINGS_BUILD_DIR) install - -install: ## install bindings into system - cp $(BINDINGS_STAGE_DIR)/lib/srpybin.cpython* $(INSTALL_DIR) - chmod 644 $(INSTALL_DIR)/srpybin.cpython* - -bindings-docker: prep ## build docker container to run the bindings - mkdir -p $(BINDINGS_STAGE_DIR)/sliderule - rsync -a $(SLIDERULE_SOURCE_DIR) $(BINDINGS_STAGE_DIR)/sliderule --exclude build --exclude stage - cp Dockerfile.$(ARCH) $(BINDINGS_STAGE_DIR)/Dockerfile - cd $(BINDINGS_STAGE_DIR); docker build --progress=plain $(DOCKEROPTS) -t $(ECR)/srpy:latest . - docker tag $(ECR)/srpy:latest $(ECR)/srpy:$(VERSION) - docker tag $(ECR)/srpy:latest $(ECR)/srpy:$(MAJOR_VERSION) - -bindings-docker-run: ## run the docker container locally; needs VERSION - docker run -it --rm --name=python-bindings -v${HOME}:/root $(ECR)/srpy:$(VERSION) $(SCRIPT) - -systest: - make bindings-docker-run SCRIPT=/sliderule/scripts/systests/pybinding_gedi.py - -distclean: ## fully remove all non-version controlled files and directories - make -C $(SLIDERULE_SOURCE_DIR) distclean - -help: ## That's me! - @grep -E '^[a-zA-Z_-].+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/targets/binding-python/README.md b/targets/binding-python/README.md deleted file mode 100644 index 05daeb698..000000000 --- a/targets/binding-python/README.md +++ /dev/null @@ -1,291 +0,0 @@ -# binding-python - -Python bindings for the sliderule library. - ----------------------------------------------------------------------------- -## I. Building the Bindings - -When building the PYthon bindings for SlideRule, great attention needs to be paid to the environment that the bindings will ultimately run in. For instance, if you will be using these bindings from your system installation of Python, then you should use your system environment to configure and build the bindings. On the other hand, if you will be using these bindings from a Conda environment, then it is necessary to configure and build the bindings using that same Conda environment. When using a Conda environment, it is therefore necessary that all of the library dependencies required to build SlideRule are present in your environment. - -### Method 1 Prerequisites - System Build - -1. Development Environment -To setup a typical development environment on Ubuntu: -```bash -sudo apt install build-essential ca-certificates pkg-config cmake git -``` - -2. RapidJSON -RapidJSON is used to parse json responses from web services. To build and install: -```bash -git clone https://github.com/Tencent/rapidjson.git -cd rapidjson -mkdir -p build -cd build -cmake .. -make -j8 -sudo make install -``` - -3. Library Dependencies -The following packages are dependencies of the sliderule library and must be installed to build the code; on Ubuntu run: -```bash -sudo apt install libreadline-dev liblua5.3-dev libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libgdal-dev -``` - -4. pybind11 -```bash -sudo pip install "pybind11[global]" -``` -Note: make sure you are aware of where you are running `pip` from and which python environment it is associated with. The cmake files associated with this project assume that pybind11 is installed into the system folder `/usr/local`; on an Ubuntu system it may be necessary to replace `pip` with `usr/bin/pip3` in order to guarantee a system installation. - -### Method 2 Prerequisites - Conda Build - -1. Install miniconda; please refer to the online [instructions](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) provided by the Conda organization for installing, configuring, and activating a conda environment. - -2. Install the necessary libraries (note that this list may be incomplete or conflict with dependencies in your current environment). -```bash -conda install -c conda-forge lua readline openssl r-uuid libcurl Zlib gdal proj rapidjson pybind11 requests -``` - -### Build - -The Python bindings must be built for each target they are used on, and the resulting .so file must either be accessible from the **PYTHONPATH** or be installed into the current Python environment or copied to the same directory as the Python script being run. For example, type: `export PYTHONPATH=/usr/local/lib` to set the Python path to the system installation directory. - -To build the bindings locally: -1. `make config` -2. `make` -3. `sudo make install` - -To build the bindings locally using the active conda environment: -1. `make config-conda` -2. `make` -3. `sudo make install` - -The results are found in the `/usr/local/lib` directory: -* `srpybin.cpython-*.so` - the Python package - -To use the package from a Python script: -```Python -import srpybin -``` - ----------------------------------------------------------------------------- -## II. Reference - -| Module | Description | Source | -|:------:|:-----------:|:------:| -| [h5coro](#pyh5coro) | Wraps H5Coro C++ module to read H5 files | [pyH5Coro.h](./pyH5Coro.h) | -| [s3cache](#pys3cache) | Initializes S3 cache I/O driver | [pyS3Cache.h](./pyS3Cache.h) | -| [credentials](#pycredentialstore) | Credential manager for assets in S3 that require authentication | [pyCredentialStore.h](./pyCredentialStore.h) | -| [lua](#pylua) | Execute local lua scripts provided by SlideRule | [pyLua.h](./pyLua.h) | -| [logger](#pylogger) | Enable and issue SlideRule log messages | [pyLogger.h](./pyLogger.h) | - -### pyH5Coro - -The pyH5Coro module contained within the SlideRule Python bindings is a Python wrapper to the H5Coro C++ module. It is used to read H5 files directly from S3 in a Python script without downloading the file to a local file system. - -#### Creating a H5 File Object - -`srpybin.h5coro(asset, resource, format, path, region, endpoint)` - -* Creates an H5 file object that can be used to read datasets directly from S3 for that file. - -* Parameters - * __asset__: name of the asset (only meaningful if credentials are setup) - * __resource__: name of the H5 file - * __identity__: name of credential store to use to get credentials - * __driver__: type of access - * 'file': local file access - * 's3': direct access to S3 - * 's3cache': caches entire file locally from S3 before reading - * __path__: subfolder path in S3 bucket to get to H5 file - * __region__: AWS region (e.g. 'us-west-2') - * __endpoint__: AWS endpoint (e.g. 'https://s3.us-west-2.amazonaws.com') - -* Returns an object that can be used to read the H5 file - - -#### Reading Metadata from a Dataset - -`{h5file}.meta(dataset)` - -* Reads the metadata from a dataset - -* Parameters - * __dataset__: full path to dataset within H5 file - -* Returns a dictionary of metadata for the dataset - * __elements__: number of elements in the dataset - * __typesize__: size in bytes of each element - * __datasize__: size in bytes of entire dataset - * __datatype__: string providing the data type - * __numcols__: number of columns in the dataset - * __numros__: number of rows in the dataset - - -#### Reading a Dataset - -`{h5file}.read(dataset, column, start_row, number_of_rows)` - -* Reads a dataset - -* Parameters - * __dataset__: full path to dataset within H5 file - * __column__: the column of the dataset to read - * __start_row__: the starting row of the specified column to start the read from - * __number_of_rows__: the number of rows to read - -* Returns a list values - - -#### Reading a Dataset in Parallel - -`{h5file}.readp(datasets)` - -* Reads a dataset - -* Parameters - * __datasets__: a list of datasets to read, each specified as a list with the following values: - * dataset name - * column - * start row - * number of rows - -* Returns a dictionary of lists values, where each key in the dictionary is a dataset name and the corresponding list is the values read for that dataset - - -### pyS3Cache - -The pyS3Cache module is used to initialize the S3 cache I/O driver and is only necessary when the "s3cache" format is specified for an H5 read - -#### Initializing the S3Cache - -`srpybin.s3cache(cache_root, max_files)` - -* Initializes the S3 file cache - -* Parameters - * __cache_root__: local file system directory where the cache will be located - * __max_files__: maximum number of files to hold in the cache at any one time - - -### pyCredentialStore - -The pyCredentialStore module is used to manage AWS credentials. AWS credentials are associated with an asset, and then if that asset is specified in an H5 read, the credentials are used as a part of the read request to S3. AWS credentials consist of an "accessKeyId", "secretAccessKey", "sessionToken", and "expiration". - -#### Creating a Credential Manager - -`srpybin.credentials(asset)` - -* Creates a object to store and manage credentials for an asset - -* Parameters - * __asset__: name of the asset that the credentials will be associated with - -* Returns an object that can be used to provide and retrieve credentials - -#### Providing credentials - -`{credentialObj}.provide(credential)` - -* Associates the AWS credentials with the asset managed by the credential object - -* Parameters - * __credential__: dictionary containing the AWS credentials - * accessKeyId - * secretAccessKey - * sessionToken - * expiration - -#### Retrieve credentials - -`{credentialObj}.retrieve()` - -* Returns the AWS credentials for the asset managed by the credential object; only useful for debugging - - - -### pyLogger - -The pyLogger module is used to enable and generate SlideRule log messages. By default, log messages generated inside the SlideRule library are not displayed in the terminal. When a pyLogger object is created, it listens for log messages and displays them to the terminal. It also provides a mechanism for generating SlideRule log messages instead of simply printing to the terminal. - -#### Creating a Logger - -`srpybin.logger(level)` - -* Enables SlideRule log messages and creates an object that is able to generate SlideRule log messages - -* Parameters - * __level__: minimal criticality level of the log messages to be displayed - * srpybin.CRITICAL - * srpybin.ERROR - * srpybin.WARNING - * srpybin.INFO - * srpybin.DEBUG - -* Returns an object that can be used to generate new SlideRule log messages - -#### Issue Log Message - -`srpybin.critical(msg)` - -`srpybin.error(msg)` - -`srpybin.warning(msg)` - -`srpybin.info(msg)` - -`srpybin.debug(msg)` - -* Generate a SlideRule log message - -* Parameters - * __msg__: the message to be sent - ----------------------------------------------------------------------------- -## III. Example - -The following example reads three datasets from a GEDI granule residing in the ORNL DAAC's protected S3 bucket in US-West-2. - -```Python -# python - -import srpybin -import requests - -# setup logging -logger = srpybin.logger(srpybin.INFO) - -# parameters -asset = "ornldaac" -resource = "GEDI04_A_2019229131935_O03846_02_T03642_02_002_02_V002.h5" -driver = "s3" -path = "ornl-cumulus-prod-protected/gedi/GEDI_L4A_AGB_Density_V2_1/data" -region = "us-west-2" -endpoint = "https://s3.us-west-2.amazonaws.com" -start_footprint = 93000 -num_footprints = 1000 -# dataset, col, start_row, num_rows -datasets = [["/BEAM0000/lat_lowestmode", 0, start_footprint, num_footprints], - ["/BEAM0000/lon_lowestmode", 0, start_footprint, num_footprints], - ["/BEAM0000/agbd", 0, start_footprint, num_footprints]] - -# credentials -earthadata_s3 = "https://data.ornldaac.earthdata.nasa.gov/s3credentials" -rsps = requests.get(earthadata_s3) -rsps.raise_for_status() -s3credentials = rsps.json() -srcredentials = srpybin.credentials(asset) -srcredentials.provide({"accessKeyId": s3credentials['accessKeyId'], - "secretAccessKey": s3credentials['secretAccessKey'], - "sessionToken": s3credentials['sessionToken'], - "expiration": s3credentials["expiration"]}) - -# perform read -h5file = srpybin.h5coro(asset, resource, driver, path, region, endpoint) -data = h5file.readp(datasets) - -# display first 5 elements of agdb -print(data["/BEAM0000/agbd"][:5]) -``` diff --git a/targets/binding-python/init.cpp b/targets/binding-python/init.cpp deleted file mode 100644 index 64b5f329a..000000000 --- a/targets/binding-python/init.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - INCLUDES - ******************************************************************************/ - -#include "core.h" - -#ifdef __aws__ -#include "aws.h" -#endif - -#ifdef __ccsds__ -#include "ccsds.h" -#endif - -#ifdef __geo__ -#include "geo.h" -#endif - -#ifdef __h5__ -#include "h5.h" -#endif - -#ifdef __legacy__ -#include "legacy.h" -#endif - -#ifdef __netsvc__ -#include "netsvc.h" -#endif - -#ifdef __icesat2__ -#include "icesat2.h" -#endif - -#include -#include "pyH5Coro.h" -#include "pyLua.h" -#include "pyLogger.h" -#include "pyS3Cache.h" -#include "pyCredentialStore.h" -#include "pyPlugin.h" - -/****************************************************************************** - * Namespaces - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * Bindings - ******************************************************************************/ - -PYBIND11_MODULE(srpybin, m) -{ - initcore(); - - #ifdef __aws__ - initaws(); - #endif - - #ifdef __ccsds__ - initccsds(); - #endif - - #ifdef __geo__ - initgeo(); - #endif - - #ifdef __h5__ - inith5(); - #endif - - #ifdef __legacy__ - initlegacy(); - #endif - - #ifdef __netsvc__ - initnetsvc(); - #endif - - #ifdef __icesat2__ - initicesat2(); - #endif - - m.doc() = "Python bindings for SlideRule on-demand data processing framework"; - - py::class_(m, "h5coro") - - .def(py::init()) // endpoint - - .def("meta", &pyH5Coro::meta, "reads meta information for dataset from file", - py::arg("dataset"), - py::arg("col") = 0, - py::arg("startrow") = 0, - py::arg("numrows") = -1) - - .def("read", &pyH5Coro::read, "reads dataset from file", - py::arg("dataset"), - py::arg("col") = 0, - py::arg("startrow") = 0, - py::arg("numrows") = -1) - - .def("readp", &pyH5Coro::readp, "parallel read of datasets from file") - - .def("stat", &pyH5Coro::stat, "returns statistics"); - - py::class_(m, "s3cache") - - .def(py::init()); // _max_files - - py::class_(m, "credentials") - - .def(py::init()) // _asset - - .def("provide", &pyCredentialStore::provide, "provide credentials for an asset", - py::arg("credential")) - - .def("retrieve", &pyCredentialStore::retrieve, "retrieve credentials for an asset"); - - py::class_(m, "lua") - - .def(py::init()); // scriptarg - - py::class_(m, "plugin") - - .def(py::init()); // full path to plugin - - py::class_(m, "logger") - - .def(py::init()) - - .def("critical", &pyLogger::log, "generates critical log message", py::arg("msg"), py::arg("level") = (int)CRITICAL) - .def("error", &pyLogger::log, "generates error log message", py::arg("msg"), py::arg("level") = (int)ERROR) - .def("warning", &pyLogger::log, "generates warning log message", py::arg("msg"), py::arg("level") = (int)WARNING) - .def("info", &pyLogger::log, "generates info log message", py::arg("msg"), py::arg("level") = (int)INFO) - .def("debug", &pyLogger::log, "generates debug log message", py::arg("msg"), py::arg("level") = (int)DEBUG); - - m.attr("all") = (long)-1; - m.attr("CRITICAL") = (int)CRITICAL; - m.attr("ERROR") = (int)ERROR; - m.attr("WARNING") = (int)WARNING; - m.attr("INFO") = (int)INFO; - m.attr("DEBUG") = (int)DEBUG; - - // Register a callback function that is invoked when the BaseClass object is collected - py::cpp_function cleanup_callback( - [](py::handle weakref) { - - #ifdef __icesat2__ - deiniticesat2(); - #endif - - #ifdef __netsvc__ - deinitnetsvc(); - #endif - - #ifdef __legacy__ - deinitlegacy(); - #endif - - #ifdef __h5__ - deinith5(); - #endif - - #ifdef __geo__ - deinitgeo(); - #endif - - #ifdef __ccsds__ - deinitccsds(); - #endif - - #ifdef __aws__ - deinitaws(); - #endif - - deinitcore(); - - weakref.dec_ref(); // release weak reference - - /* - * This is a hack to avoid a coredump from exiting - * python when this module is loaded in a conda environment - * and the library was linked with a system environment. See - * makefile target `config-python-conda` for the preferred - * way to build bindings when using a conda environment. - */ - #ifdef BEST_EFFORT_CONDA_ENV - quick_exit(0); - #endif - } - ); - - // Create a weak reference with a cleanup callback and initially leak it - (void) py::weakref(m.attr("logger"), cleanup_callback).release(); -} diff --git a/targets/binding-python/pyCredentialStore.cpp b/targets/binding-python/pyCredentialStore.cpp deleted file mode 100644 index d799039f5..000000000 --- a/targets/binding-python/pyCredentialStore.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "StringLib.h" -#include "TimeLib.h" -#include "CredentialStore.h" -#include "pyCredentialStore.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyCredentialStore Class - ******************************************************************************/ - -/*-------------------------------------------------------------------- - * Constructor - *--------------------------------------------------------------------*/ -pyCredentialStore::pyCredentialStore (const std::string &_asset) -{ - asset = StringLib::duplicate(_asset.c_str()); -} - -/*-------------------------------------------------------------------- - * Destructor - *--------------------------------------------------------------------*/ -pyCredentialStore::~pyCredentialStore (void) -{ - if(asset) delete [] asset; -} - -/*-------------------------------------------------------------------- - * provide - *--------------------------------------------------------------------*/ -bool pyCredentialStore::provide (const py::dict& credentials) -{ - PyObject* accessKeyId = PyUnicode_AsEncodedString(PyObject_Repr(PyDict_GetItem(credentials.ptr(), py::str("accessKeyId").ptr())), "utf-8", "~E~"); - PyObject* secretAccessKey = PyUnicode_AsEncodedString(PyObject_Repr(PyDict_GetItem(credentials.ptr(), py::str("secretAccessKey").ptr())), "utf-8", "~E~"); - PyObject* sessionToken = PyUnicode_AsEncodedString(PyObject_Repr(PyDict_GetItem(credentials.ptr(), py::str("sessionToken").ptr())), "utf-8", "~E~"); - PyObject* expiration = PyUnicode_AsEncodedString(PyObject_Repr(PyDict_GetItem(credentials.ptr(), py::str("expiration").ptr())), "utf-8", "~E~"); - - SafeString _accessKeyId("%s", PyBytes_AS_STRING(accessKeyId)); - SafeString _secretAccessKey("%s", PyBytes_AS_STRING(secretAccessKey)); - SafeString _sessionToken("%s", PyBytes_AS_STRING(sessionToken)); - SafeString _expiration("%s", PyBytes_AS_STRING(expiration)); - - _accessKeyId.replace("'", ""); - _secretAccessKey.replace("'", ""); - _sessionToken.replace("'", ""); - _expiration.replace("'", ""); - - CredentialStore::Credential credential; - credential.provided = true; - credential.accessKeyId = _accessKeyId.str(true); - credential.secretAccessKey = _secretAccessKey.str(true); - credential.sessionToken = _sessionToken.str(true); - credential.expiration = _expiration.str(true); - credential.expirationGps = TimeLib::str2gpstime(credential.expiration); - - return CredentialStore::put(asset, credential); -} - -/*-------------------------------------------------------------------- - * provide - *--------------------------------------------------------------------*/ -py::dict pyCredentialStore::retrieve (void) -{ - py::dict results; - - CredentialStore::Credential credential = CredentialStore::get(asset); - - if(credential.provided) - { - results[py::str("accessKeyId")] = credential.accessKeyId; - results[py::str("secretAccessKey")] = credential.secretAccessKey; - results[py::str("sessionToken")] = credential.sessionToken; - results[py::str("expiration")] = credential.expiration; - } - - return results; -} \ No newline at end of file diff --git a/targets/binding-python/pyCredentialStore.h b/targets/binding-python/pyCredentialStore.h deleted file mode 100644 index e44213e0a..000000000 --- a/targets/binding-python/pyCredentialStore.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __py_credentialstore__ -#define __py_credentialstore__ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "CredentialStore.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyS3Cache Class - ******************************************************************************/ - -class pyCredentialStore -{ - public: - pyCredentialStore (const std::string &_asset); - ~pyCredentialStore (void); - - bool provide (const py::dict& credentials); - py::dict retrieve (void); - - private: - const char* asset; -}; - -#endif /* __py_credentialstore__ */ \ No newline at end of file diff --git a/targets/binding-python/pyH5Coro.cpp b/targets/binding-python/pyH5Coro.cpp deleted file mode 100644 index 3f13f06b0..000000000 --- a/targets/binding-python/pyH5Coro.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include - -#include "StringLib.h" -#include "RecordObject.h" -#include "H5Coro.h" -#include "Asset.h" -#include "pyH5Coro.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * Static - ******************************************************************************/ - -Mutex pyH5Coro::pyMut; - -/****************************************************************************** - * pyH5Coro Class - ******************************************************************************/ - -/*-------------------------------------------------------------------- - * Constructor - *--------------------------------------------------------------------*/ -pyH5Coro::pyH5Coro (const std::string &_asset, const std::string &_resource, const std::string &identity, const std::string &driver, const std::string &path, const std::string ®ion, const std::string &endpoint): - resource(_resource) -{ - asset = Asset::pythonCreate(_asset.c_str(), identity.c_str(), driver.c_str(), path.c_str(), NULL, region.c_str(), endpoint.c_str()); - if(asset == NULL) throw std::invalid_argument("failed to create asset, likely missing driver"); -} - -/*-------------------------------------------------------------------- - * Destructor - *--------------------------------------------------------------------*/ -pyH5Coro::~pyH5Coro (void) -{ - delete asset; -} - -/*-------------------------------------------------------------------- - * meta - *--------------------------------------------------------------------*/ -py::dict pyH5Coro::meta (const std::string &datasetname, long col, long startrow, long numrows) -{ - py::dict result; - - // workaround for binding to default argument value - if(numrows < 0) numrows = H5Coro::ALL_ROWS; - - // perform read of dataset - H5Coro::info_t info = H5Coro::read(asset, resource.c_str(), datasetname.c_str(), RecordObject::DYNAMIC, col, startrow, numrows, &context, true); - - // construct meta dictionary - result["elements"] = info.elements; - result["typesize"] = info.typesize; - result["datasize"] = info.datasize; - result["datatype"] = RecordObject::ft2str(info.datatype); - result["numcols"] = info.numcols; - result["numrows"] = info.numrows; - - // return dictionary - return result; -} - -/*-------------------------------------------------------------------- - * read - *--------------------------------------------------------------------*/ -py::list pyH5Coro::read (const std::string &datasetname, long col, long startrow, long numrows) -{ - py::list result; - - // workaround for binding to default argument value - if(numrows < 0) numrows = H5Coro::ALL_ROWS; - - // perform read of dataset - H5Coro::info_t info = H5Coro::read(asset, resource.c_str(), datasetname.c_str(), RecordObject::DYNAMIC, col, startrow, numrows, &context); - - // build dataset array - result = tolist(&info); - - // clean up data - if(info.data) delete [] info.data; - - // return list - return result; -} - -/*-------------------------------------------------------------------- - * readp - *--------------------------------------------------------------------*/ -const py::dict pyH5Coro::readp (const py::list& datasets) -{ - py::dict result; - List readers; - - // traverse list of datasets to read - for(auto entry : datasets) - { - // build request - read_rqst_t* rqst = new read_rqst_t; - rqst->dataset = py::cast(PyList_GetItem(entry.ptr(), 0)); - rqst->col = py::cast(PyList_GetItem(entry.ptr(), 1)); - rqst->startrow = py::cast(PyList_GetItem(entry.ptr(), 2)); - rqst->numrows = py::cast(PyList_GetItem(entry.ptr(), 3)); - rqst->file = this; - rqst->e_ptr = NULL; - - // workaround for binding to default argument value - if(rqst->numrows < 0) rqst->numrows = H5Coro::ALL_ROWS; - - // spawn thread - rqst->pid = new Thread(read_thread, rqst); - readers.add(rqst); - } - - // process results - for(int i = 0; i < readers.length(); i++) - { - // wait for read to complete - delete readers[i]->pid; - - // check for exceptions - if(readers[i]->e_ptr) - { - std::rethrow_exception(readers[i]->e_ptr); - } - - // populate result dictionary - pyMut.lock(); - { - py::str key(readers[i]->dataset); - result[key] = readers[i]->result; - } - pyMut.unlock(); - - // clean up data - if(readers[i]->info.data) delete [] readers[i]->info.data; - - // clean up request - delete readers[i]; - } - - // return result dictionary - return result; -} - -/*-------------------------------------------------------------------- - * stat - *--------------------------------------------------------------------*/ -py::dict pyH5Coro::stat (void) -{ - py::dict stats; - stats["pre_prefetch_request"] = context.pre_prefetch_request; - stats["post_prefetch_request"] = context.post_prefetch_request; - stats["cache_miss"] = context.cache_miss; - stats["l1_cache_replace"] = context.l1_cache_replace; - stats["l2_cache_replace"] = context.l2_cache_replace; - stats["bytes_read"] = context.bytes_read; - return stats; -} - -/*-------------------------------------------------------------------- - * tolist - *--------------------------------------------------------------------*/ -py::list pyH5Coro::tolist (H5Coro::info_t* info) -{ - py::list result; - - if(info->data) - { - if(info->datatype == RecordObject::DOUBLE) - { - double* data_ptr = (double*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::FLOAT) - { - float* data_ptr = (float*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::INT64) - { - int64_t* data_ptr = (int64_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::UINT64) - { - uint64_t* data_ptr = (uint64_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::INT32) - { - int32_t* data_ptr = (int32_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::UINT32) - { - uint32_t* data_ptr = (uint32_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::INT16) - { - int16_t* data_ptr = (int16_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::UINT16) - { - uint16_t* data_ptr = (uint16_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::INT8) - { - int8_t* data_ptr = (int8_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::UINT8) - { - uint8_t* data_ptr = (uint8_t*)info->data; - for(unsigned int i = 0; i < info->elements; i++) - { - result.append(data_ptr[i]); - } - } - else if(info->datatype == RecordObject::STRING) - { - char* data_ptr = (char*)info->data; - data_ptr[info->datasize - 1] = '\0'; - py::str data_str(data_ptr); - result.append(data_str); - } - } - - return result; -} - -/*-------------------------------------------------------------------- - * read_thread - *--------------------------------------------------------------------*/ -void* pyH5Coro::read_thread (void* parm) -{ - read_rqst_t* rqst = (read_rqst_t*)parm; - - try - { - // perform read of dataset - rqst->info = H5Coro::read(rqst->file->asset, rqst->file->resource.c_str(), rqst->dataset.c_str(), RecordObject::DYNAMIC, rqst->col, rqst->startrow, rqst->numrows, &rqst->file->context); - - // build dataset array - pyMut.lock(); - { - rqst->result = rqst->file->tolist(&rqst->info); - } - pyMut.unlock(); - } - catch(...) - { - rqst->e_ptr = std::current_exception(); - } - - // exit - return NULL; -} - diff --git a/targets/binding-python/pyH5Coro.h b/targets/binding-python/pyH5Coro.h deleted file mode 100644 index da21147c0..000000000 --- a/targets/binding-python/pyH5Coro.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __py_h5coro__ -#define __py_h5coro__ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include - -#include "H5Coro.h" -#include "RecordObject.h" -#include "Asset.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyH5Coro Class - ******************************************************************************/ - -class pyH5Coro -{ - public: - pyH5Coro (const std::string &_asset, const std::string &_resource, const std::string &identity, const std::string &driver, const std::string &path, const std::string ®ion, const std::string &endpoint); - ~pyH5Coro (void); - py::dict meta (const std::string &datasetname, long col, long startrow, long numrows); - py::list read (const std::string &datasetname, long col, long startrow, long numrows); - const py::dict readp (const py::list& datasets); - py::dict stat (void); - - private: - - typedef struct { - std::string dataset; - int col; - int startrow; - int numrows; - Thread* pid; - H5Coro::info_t info; - py::list result; - pyH5Coro* file; - std::exception_ptr e_ptr; - } read_rqst_t; - - - py::list tolist (H5Coro::info_t* info); - static void* read_thread (void* parm); - - static Mutex pyMut; - - std::string resource; - Asset* asset; - H5Coro::context_t context; -}; - -#endif /* __py_h5coro__ */ \ No newline at end of file diff --git a/targets/binding-python/pyLogger.cpp b/targets/binding-python/pyLogger.cpp deleted file mode 100644 index 00c15b7be..000000000 --- a/targets/binding-python/pyLogger.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "OsApi.h" -#include "core.h" -#include "pyLogger.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyLogger Class - ******************************************************************************/ - -/*-------------------------------------------------------------------- - * Constructor - *--------------------------------------------------------------------*/ -pyLogger::pyLogger (const long level) -{ - active = true; - inQ = new Subscriber("eventq"); - pid = new Thread(loggerThread, this); - EventLib::setLvl(EventLib::LOG, (event_level_t)level); -} - -/*-------------------------------------------------------------------- - * Destructor - *--------------------------------------------------------------------*/ -pyLogger::~pyLogger (void) -{ - active = false; - delete pid; - delete inQ; -} - -/*-------------------------------------------------------------------- - * log - *--------------------------------------------------------------------*/ -const char* pyLogger::log (const std::string msg, const long level) -{ - mlog((event_level_t)level, "%s", msg.c_str()); - return msg.c_str(); -} - -/****************************************************************************** - * PRIVATE METHODS - ******************************************************************************/ - -/*---------------------------------------------------------------------------- - * loggerThread - *----------------------------------------------------------------------------*/ -void* pyLogger::loggerThread(void* parm) -{ - pyLogger* logger = (pyLogger*)parm; - - /* Loop Forever */ - while(logger->active) - { - /* Receive Message */ - Subscriber::msgRef_t ref; - int recv_status = logger->inQ->receiveRef(ref, SYS_TIMEOUT); - if(recv_status > 0) - { - /* Log Message */ - if(ref.size > 0) - { - try - { - RecordInterface record((unsigned char*)ref.data, ref.size); - EventLib::event_t* event = (EventLib::event_t*)record.getRecordData(); - if(event->type == EventLib::LOG) - { - TimeLib::gmt_time_t gmt = TimeLib::gps2gmttime(event->systime); - TimeLib::date_t date = TimeLib::gmt2date(gmt); - print2term("[%d-%02d-%02dT%02d:%02d:%02dZ] %s\n", date.year, date.month, date.day, gmt.hour, gmt.minute, gmt.second, event->attr); - } - } - catch (const RunTimeException& e) - { - } - } - - /* Dereference Message */ - logger->inQ->dereference(ref); - } - else if(recv_status != MsgQ::STATE_TIMEOUT) - { - /* Break Out on Failure */ - print2term("Failed queue receive on %s with error %d", logger->inQ->getName(), recv_status); - logger->active = false; // breaks out of loop - } - } - - return NULL; -} diff --git a/targets/binding-python/pyLua.cpp b/targets/binding-python/pyLua.cpp deleted file mode 100644 index a6e449051..000000000 --- a/targets/binding-python/pyLua.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "core.h" -#include "pyLua.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyLua Class - ******************************************************************************/ - -/*-------------------------------------------------------------------- - * Constructor - *--------------------------------------------------------------------*/ -pyLua::pyLua (const std::string &scriptpath, const std::string &scriptarg) -{ - luaEngine = new LuaEngine(scriptpath.c_str(), scriptarg.c_str(), ORIGIN, NULL, true); - bool status = luaEngine->executeEngine(MAX_RUNTIME_MS); - if(status) luaResult = StringLib::duplicate(luaEngine->getResult()); - else luaResult = NULL; -} - -/*-------------------------------------------------------------------- - * Destructor - *--------------------------------------------------------------------*/ -pyLua::~pyLua (void) -{ - delete luaEngine; - if(luaResult) delete [] luaResult; -} - -/*-------------------------------------------------------------------- - * result - *--------------------------------------------------------------------*/ -const char* pyLua::result (void) -{ - if(luaResult) return luaResult; - else return ""; -} \ No newline at end of file diff --git a/targets/binding-python/pyPlugin.h b/targets/binding-python/pyPlugin.h deleted file mode 100644 index e46b58710..000000000 --- a/targets/binding-python/pyPlugin.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __py_plugin__ -#define __py_plugin__ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyS3Cache Class - ******************************************************************************/ - -class pyPlugin -{ - public: - pyPlugin (const std::string &_plugin); - ~pyPlugin (void); -}; - -#endif /* __py_plugin__ */ \ No newline at end of file diff --git a/targets/binding-python/pyS3Cache.cpp b/targets/binding-python/pyS3Cache.cpp deleted file mode 100644 index b8ccf6982..000000000 --- a/targets/binding-python/pyS3Cache.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "S3CacheIODriver.h" -#include "pyS3Cache.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyS3Cache Class - ******************************************************************************/ - -/*-------------------------------------------------------------------- - * Constructor - *--------------------------------------------------------------------*/ -pyS3Cache::pyS3Cache (const std::string &_cache_root, const int _max_files) -{ - S3CacheIODriver::createCache(_cache_root.c_str(), _max_files); -} - -/*-------------------------------------------------------------------- - * Destructor - *--------------------------------------------------------------------*/ -pyS3Cache::~pyS3Cache (void) -{ -} diff --git a/targets/binding-python/pyS3Cache.h b/targets/binding-python/pyS3Cache.h deleted file mode 100644 index 52ddb6056..000000000 --- a/targets/binding-python/pyS3Cache.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021, University of Washington - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the University of Washington nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS - * “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __py_s3cache__ -#define __py_s3cache__ - -/****************************************************************************** - * INCLUDES - ******************************************************************************/ - -#include -#include "S3CacheIODriver.h" - -/****************************************************************************** - * NAMESPACES - ******************************************************************************/ - -namespace py = pybind11; - -/****************************************************************************** - * pyS3Cache Class - ******************************************************************************/ - -class pyS3Cache -{ - public: - pyS3Cache (const std::string &_cache_root, const int _max_files); - ~pyS3Cache (void); -}; - -#endif /* __py_s3cache__ */ \ No newline at end of file diff --git a/targets/server-linux/SlideRule.cpp b/targets/server-linux/SlideRule.cpp index 0761e0f7c..3707ceb54 100644 --- a/targets/server-linux/SlideRule.cpp +++ b/targets/server-linux/SlideRule.cpp @@ -173,14 +173,13 @@ static void* signal_thread (void* parm) signal(SIGINT, console_quick_exit); break; } - else if(app_signal_abort) + + if(app_signal_abort) { break; // exit thread for clean up } - else - { - console_quick_exit(0); - } + + console_quick_exit(0); } return NULL; diff --git a/targets/slideruleearth-aws/Makefile b/targets/slideruleearth-aws/Makefile index 714c96411..12167bc25 100644 --- a/targets/slideruleearth-aws/Makefile +++ b/targets/slideruleearth-aws/Makefile @@ -64,24 +64,44 @@ DOCKER_PLATFORM ?= # linux/arm64 ARCH ?= $(shell arch) DOMAIN ?= testsliderule.org DOMAIN_ROOT = $(firstword $(subst ., ,$(DOMAIN))) -CLANG_VER = "-12" -CLANG_OPT = -DCMAKE_USER_MAKE_RULES_OVERRIDE=$(SLIDERULE_SOURCE_DIR)/platforms/linux/ClangOverrides.txt -D_CMAKE_TOOLCHAIN_PREFIX=llvm- MYIP ?= $(shell (ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$$/\1/p')) ENVVER = $(shell git --git-dir ../../.git --work-tree ../../.git describe --abbrev --dirty --always --tags --long) +USERCFG ?= + TEST ?= $(SLIDERULE_SOURCE_DIR)/scripts/selftests/test_runner.lua MOSAICS_PERFORMANCE_TEST ?= $(SLIDERULE_SOURCE_DIR)/plugins/pgc/systests/arcticdem_mosaic_perf.lua STRIPS_PERFORMANCE_TEST ?= $(SLIDERULE_SOURCE_DIR)/plugins/pgc/systests/arcticdem_strips_perf.lua SUBSET_PERFORMANCE_TEST ?= $(SLIDERULE_SOURCE_DIR)/scripts/systests/subset_perf_test.lua -USERCFG ?= -SLIDERULECFG := -DMAX_FREE_STACK_SIZE=1 -SLIDERULECFG += -DUSE_ARROW_PACKAGE=ON -SLIDERULECFG += -DUSE_AWS_PACKAGE=ON -SLIDERULECFG += -DUSE_H5_PACKAGE=ON -SLIDERULECFG += -DUSE_NETSVC_PACKAGE=ON -SLIDERULECFG += -DUSE_GEO_PACKAGE=ON -SLIDERULECFG += -DUSE_LEGACY_PACKAGE=OFF -SLIDERULECFG += -DUSE_CCSDS_PACKAGE=OFF -SLIDERULECFG += $(USERCFG) + +CLANG_VER = "-12" +CLANG_OPT = -DCMAKE_USER_MAKE_RULES_OVERRIDE=$(SLIDERULE_SOURCE_DIR)/platforms/linux/ClangOverrides.txt -D_CMAKE_TOOLCHAIN_PREFIX=llvm- +CLANG_CFG = export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) + +DEBUG_CFG := -DCMAKE_BUILD_TYPE=Debug +DEBUG_CFG += -DINSTALLDIR=$(SERVER_STAGE_DIR) +DEBUG_CFG += -DCMAKE_USER_MAKE_RULES_OVERRIDE=$(SLIDERULE_SOURCE_DIR)/platforms/linux/ClangOverrides.txt -D_CMAKE_TOOLCHAIN_PREFIX=llvm- +DEBUG_CFG += -DENABLE_ADDRESS_SANITIZER=ON +DEBUG_CFG += -DUSE_ARROW_PACKAGE=ON +DEBUG_CFG += -DUSE_AWS_PACKAGE=ON +DEBUG_CFG += -DUSE_CCSDS_PACKAGE=ON +DEBUG_CFG += -DUSE_GEO_PACKAGE=ON +DEBUG_CFG += -DUSE_H5_PACKAGE=ON +DEBUG_CFG += -DUSE_LEGACY_PACKAGE=ON +DEBUG_CFG += -DUSE_NETSVC_PACKAGE=ON +DEBUG_CFG += -DUSE_PISTACHE_PACKAGE=ON +DEBUG_CFG += $(USERCFG) + +RELEASE_CFG := -DCMAKE_BUILD_TYPE=Release +RELEASE_CFG += -DINSTALLDIR=$(SERVER_STAGE_DIR) +RELEASE_CFG += -DUSE_ARROW_PACKAGE=ON +RELEASE_CFG += -DUSE_AWS_PACKAGE=ON +RELEASE_CFG += -DUSE_GEO_PACKAGE=ON +RELEASE_CFG += -DUSE_H5_PACKAGE=ON +RELEASE_CFG += -DUSE_NETSVC_PACKAGE=ON +RELEASE_CFG += -DUSE_CCSDS_PACKAGE=OFF +RELEASE_CFG += -DUSE_LEGACY_PACKAGE=OFF +RELEASE_CFG += -DUSE_PISTACHE_PACKAGE=OFF +RELEASE_CFG += $(USERCFG) all: sliderule @@ -95,35 +115,25 @@ prep: ## create temporary directories needed for build mkdir -p $(OPENDATA_BUILD_DIR) mkdir -p $(SWOT_BUILD_DIR) -config-debug: prep ## configure the server for running locally with debug symbols - cd $(SLIDERULE_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug $(SLIDERULECFG) -DENABLE_TRACING=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR) - cd $(ICESAT2_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/icesat2 - cd $(PGC_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/pgc - cd $(LANDSAT_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/landsat - cd $(GEDI_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/gedi - cd $(USGS3DEP_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/usgs3dep - cd $(OPENDATA_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/opendata - cd $(SWOT_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/swot - -config-release: prep ## configure server to run release version locally (useful for using valgrind) - cd $(SLIDERULE_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release $(SLIDERULECFG) -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR) - cd $(ICESAT2_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/icesat2 - cd $(PGC_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/pgc - cd $(LANDSAT_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/landsat - cd $(GEDI_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/gedi - cd $(USGS3DEP_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/usgs3dep - cd $(OPENDATA_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/opendata - cd $(SWOT_BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/swot - -config-asan: prep ## configure server to run with address sanitizer locally - cd $(SLIDERULE_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON $(SLIDERULECFG) -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR) - cd $(ICESAT2_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/icesat2 - cd $(PGC_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/pgc - cd $(LANDSAT_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/landsat - cd $(GEDI_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/gedi - cd $(USGS3DEP_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/usgs3dep - cd $(OPENDATA_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/opendata - cd $(SWOT_BUILD_DIR) && export CC=clang$(CLANG_VER) && export CXX=clang++$(CLANG_VER) && cmake -DCMAKE_BUILD_TYPE=Debug $(CLANG_OPT) -DENABLE_ADDRESS_SANITIZER=ON -DINSTALLDIR=$(SERVER_STAGE_DIR) $(SLIDERULE_SOURCE_DIR)/plugins/swot +config-debug: prep ## configure the server for running locally with debug symbols, optimizations off, static analysis, and address sanitizer + cd $(SLIDERULE_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) -DMAX_FREE_STACK_SIZE=1 -DENABLE_TRACING=ON $(SLIDERULE_SOURCE_DIR) + cd $(ICESAT2_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/icesat2 + cd $(PGC_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/pgc + cd $(LANDSAT_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/landsat + cd $(GEDI_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/gedi + cd $(USGS3DEP_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/usgs3dep + cd $(OPENDATA_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/opendata + cd $(SWOT_BUILD_DIR) && $(CLANG_CFG) && cmake $(DEBUG_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/swot + +config-release: prep ## configure server to run a release version locally + cd $(SLIDERULE_BUILD_DIR) && cmake $(RELEASE_CFG) -DMAX_FREE_STACK_SIZE=1 $(SLIDERULE_SOURCE_DIR) + cd $(ICESAT2_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/icesat2 + cd $(PGC_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/pgc + cd $(LANDSAT_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/landsat + cd $(GEDI_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/gedi + cd $(USGS3DEP_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/usgs3dep + cd $(OPENDATA_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/opendata + cd $(SWOT_BUILD_DIR) && cmake $(RELEASE_CFG) $(SLIDERULE_SOURCE_DIR)/plugins/swot sliderule: ## build the server using the local configuration make -j4 -C $(SLIDERULE_BUILD_DIR)