From 656141f92d40193c7cddc7a5a5d54e9721bb2a99 Mon Sep 17 00:00:00 2001 From: runette Date: Tue, 31 Jan 2023 15:41:49 +0000 Subject: [PATCH 01/18] first pass --- source/pdal/pdalc_config.cpp | 3 + source/pdal/pdalc_config.h | 1 + source/pdal/pdalc_forward.h | 13 ++- source/pdal/pdalc_pipeline.cpp | 139 +++++++++++++++++---------------- source/pdal/pdalc_pipeline.h | 11 ++- 5 files changed, 93 insertions(+), 74 deletions(-) diff --git a/source/pdal/pdalc_config.cpp b/source/pdal/pdalc_config.cpp index 81514ba..e8b61d1 100644 --- a/source/pdal/pdalc_config.cpp +++ b/source/pdal/pdalc_config.cpp @@ -27,6 +27,7 @@ * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#define _CRT_SECURE_NO_WARNINGS #include "pdalc_config.h" #include @@ -36,6 +37,8 @@ #include #include + + namespace pdal { namespace capi diff --git a/source/pdal/pdalc_config.h b/source/pdal/pdalc_config.h index 8bb503f..7ecd3cd 100644 --- a/source/pdal/pdalc_config.h +++ b/source/pdal/pdalc_config.h @@ -32,6 +32,7 @@ #include "pdalc_forward.h" + /** * @file pdalc_config.h * Functions to retrieve PDAL version and configuration information. diff --git a/source/pdal/pdalc_forward.h b/source/pdal/pdalc_forward.h index 0c68b16..33e1388 100644 --- a/source/pdal/pdalc_forward.h +++ b/source/pdal/pdalc_forward.h @@ -53,7 +53,7 @@ namespace pdal { struct DimType; -class PipelineExecutor; +class PipelineManager; class PointView; class TriangularMesh; @@ -64,10 +64,19 @@ using MeshPtr = std::shared_ptr; namespace capi { class PointViewIterator; -using Pipeline = std::unique_ptr; using PointView = pdal::PointViewPtr; using TriangularMesh = pdal::MeshPtr; using DimTypeList = std::unique_ptr; + +struct Pipeline { + public: + + std::unique_ptr manager = std::make_unique(); + + bool m_executed = false; + std::stringstream logStream; + pdal::LogLevel logLevel; + }; } } diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index fd7dfe8..5070f17 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2019, Simverge Software LLC. All rights reserved. + * Copyright (c) 2019, Simverge Software LLC & Runette Software Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following @@ -26,15 +26,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ - +#define _CRT_SECURE_NO_WARNINGS #include "pdalc_pipeline.h" #include -#include - #include "pdalc_pointviewiterator.h" +#include +#include +#include + // TODO Address cause of std::min problems. See https://github.com/PDAL/CAPI/issues/4 #undef min @@ -46,46 +48,35 @@ extern "C" { PDALPipelinePtr PDALCreatePipeline(const char* json) { - PDALPipelinePtr pipeline = nullptr; - + PDALPipelinePtr pipeline = new Pipeline(); + Pipeline *ptr = reinterpret_cast(pipeline); + PipelineManager *manager = ptr->manager.get(); if (json && std::strlen(json) > 0) { - pdal::PipelineExecutor *executor = nullptr; - try { - pdal::PipelineExecutor stackpipe(json); - executor = new pdal::PipelineExecutor(json); + LogPtr log(Log::makeLog("capi pipeline", &ptr->logStream)); + manager->setLog(log); + + std::stringstream strm; + strm << json; + manager->readPipeline(strm); } catch (const std::exception &e) { printf("Could not create pipeline: %s\n%s\n", e.what(), json); - executor = nullptr; } - if (executor) + if (manager) { - bool valid = false; - try { - valid = executor->validate(); + manager->prepare(); } catch (const std::exception &e) { printf("Error while validating pipeline: %s\n%s\n", e.what(), json); } - - if (valid) - { - pipeline = new Pipeline(executor); - } - else - { - delete executor; - executor = NULL; - printf("The pipeline is invalid:\n%s\n", json); - } } } @@ -97,6 +88,7 @@ extern "C" if (pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); + ptr->manager.reset(); delete ptr; } } @@ -108,17 +100,18 @@ extern "C" if (pipeline && buffer && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - pdal::PipelineExecutor *executor = ptr->get(); + PipelineManager *manager = ptr->manager.get(); buffer[0] = '\0'; buffer[size - 1] = '\0'; - if (executor) + if (manager) { try { - std::string s = executor->getPipeline(); - std::strncpy(buffer, s.c_str(), size - 1); - result = std::min(s.length(), size); + std::stringstream strm; + pdal::PipelineWriter::writePipeline(manager->getStage(), strm); + std::strncpy(buffer, strm.str().c_str(), size - 1); + result = std::min(strm.str().length(), size); } catch (const std::exception &e) { @@ -138,17 +131,19 @@ extern "C" if (pipeline && metadata && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - pdal::PipelineExecutor *executor = ptr->get(); + PipelineManager *manager = ptr->manager.get(); metadata[0] = '\0'; metadata[size - 1] = '\0'; - if (executor) + if (manager) { try { - std::string s = executor->getMetadata(); - std::strncpy(metadata, s.c_str(), size); - result = std::min(s.length(), size); + std::stringstream strm; + MetadataNode root = manager->getMetadata().clone("metadata"); + pdal::Utils::toJSON(root, strm); + std::strncpy(metadata, strm.str().c_str(), size); + result = std::min(strm.str().length(), size); } catch (const std::exception &e) { @@ -167,17 +162,19 @@ extern "C" if (pipeline && schema && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - pdal::PipelineExecutor *executor = ptr->get(); + PipelineManager *manager = ptr->manager.get(); schema[0] = '\0'; schema[size - 1] = '\0'; - if (executor) + if (manager) { try { - std::string s = executor->getSchema(); - std::strncpy(schema, s.c_str(), size); - result = std::min(s.length(), size); + std::stringstream strm; + MetadataNode root = manager->pointTable().layout()->toMetadata().clone("schema"); + pdal::Utils::toJSON(root, strm); + std::strncpy(schema, strm.str().c_str(), size); + result = std::min(strm.str().length(), size); } catch (const std::exception &e) { @@ -196,15 +193,15 @@ extern "C" if (pipeline && log && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - pdal::PipelineExecutor *executor = ptr->get(); + PipelineManager *manager = ptr->manager.get(); log[0] = '\0'; log[size - 1] = '\0'; - if (executor) + if (manager) { try { - std::string s = executor->getLog(); + std::string s = ptr->logStream.str(); std::strncpy(log, s.c_str(), size); result = std::min(s.length(), size); } @@ -221,24 +218,31 @@ extern "C" void PDALSetPipelineLogLevel(PDALPipelinePtr pipeline, int level) { Pipeline *ptr = reinterpret_cast(pipeline); + PipelineManager *manager = ptr->manager.get(); - if (ptr && ptr->get()) + try + { + if (level < 0 || level > 8) + throw pdal_error("log level must be between 0 and 8!"); + + ptr->logLevel = static_cast(level); + pdal::LogPtr lptr = manager->log(); + lptr->setLevel(ptr->logLevel); + } + catch (const std::exception &e) { - try - { - ptr->get()->setLogLevel(level); - } - catch (const std::exception &e) - { - printf("Found error while setting log level: %s\n", e.what()); - } + printf("Found error while setting log level: %s\n", e.what()); } + } int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); - return (ptr && ptr->get()) ? ptr->get()->getLogLevel() : 0; + return (ptr && ptr->manager.get()) + ? static_cast( + ptr->manager.get()->log()->getLevel() + ) : 0; } int64_t PDALExecutePipeline(PDALPipelinePtr pipeline) @@ -246,11 +250,11 @@ extern "C" int64_t result = 0; Pipeline *ptr = reinterpret_cast(pipeline); - if (ptr && ptr->get()) + if (ptr) { try { - result = ptr->get()->execute(); + result = ptr->manager.get()->execute(); } catch (const std::exception &e) { @@ -266,11 +270,11 @@ extern "C" int64_t result = 0; Pipeline *ptr = reinterpret_cast(pipeline); - if (ptr && ptr->get()) + if (ptr) { try { - result = ptr->get()->validate(); + ptr->manager.get()->prepare(); } catch (const std::exception &e) { @@ -284,18 +288,14 @@ extern "C" PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); + PipelineManager *manager = ptr->manager.get(); pdal::capi::PointViewIterator *views = nullptr; - if (ptr && ptr->get()) + if (ptr) { try { - auto &v = ptr->get()->getManagerConst().views(); - - if (!v.empty()) - { - views = new pdal::capi::PointViewIterator(v); - } + views = new pdal::capi::PointViewIterator(manager->views()); } catch (const std::exception &e) { @@ -305,6 +305,9 @@ extern "C" return views; } -} -} -} +} /* extern c */ + + + +} /* capi */ +} /* pdal */ diff --git a/source/pdal/pdalc_pipeline.h b/source/pdal/pdalc_pipeline.h index d7657c0..497bd2f 100644 --- a/source/pdal/pdalc_pipeline.h +++ b/source/pdal/pdalc_pipeline.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2019, Simverge Software LLC. All rights reserved. + * Copyright (c) 2019, Simverge Software LLC & Runette Software. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following @@ -156,8 +156,11 @@ PDALC_API PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline); #ifdef __cplusplus -} -} -} +} /* extern C */ + + + +} /* capi*/ +} /* pdal*/ #endif /* _cplusplus */ #endif /* PDALC_PIPELINE_H */ \ No newline at end of file From d7e44d826179016306828acda21d2b26b79264a3 Mon Sep 17 00:00:00 2001 From: runette Date: Tue, 31 Jan 2023 15:58:14 +0000 Subject: [PATCH 02/18] first compiling --- source/pdal/pdalc_dimtype.cpp | 4 +++- source/pdal/pdalc_forward.h | 9 --------- source/pdal/pdalc_pipeline.cpp | 11 +++++++++++ source/pdal/pdalc_pipeline.h | 5 ++--- source/pdal/pdalc_pointview.cpp | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/source/pdal/pdalc_dimtype.cpp b/source/pdal/pdalc_dimtype.cpp index b1d782d..31eb58f 100644 --- a/source/pdal/pdalc_dimtype.cpp +++ b/source/pdal/pdalc_dimtype.cpp @@ -26,11 +26,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ - +#define _CRT_SECURE_NO_WARNINGS #include "pdal/pdalc_dimtype.h" #include + + namespace pdal { namespace capi diff --git a/source/pdal/pdalc_forward.h b/source/pdal/pdalc_forward.h index 33e1388..766b935 100644 --- a/source/pdal/pdalc_forward.h +++ b/source/pdal/pdalc_forward.h @@ -68,15 +68,6 @@ using PointView = pdal::PointViewPtr; using TriangularMesh = pdal::MeshPtr; using DimTypeList = std::unique_ptr; -struct Pipeline { - public: - - std::unique_ptr manager = std::make_unique(); - - bool m_executed = false; - std::stringstream logStream; - pdal::LogLevel logLevel; - }; } } diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 5070f17..2452b5f 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -44,8 +44,19 @@ namespace pdal { namespace capi { + extern "C" { + struct Pipeline { + public: + + std::unique_ptr manager = std::make_unique(); + + bool m_executed = false; + std::stringstream logStream; + pdal::LogLevel logLevel; + }; + PDALPipelinePtr PDALCreatePipeline(const char* json) { PDALPipelinePtr pipeline = new Pipeline(); diff --git a/source/pdal/pdalc_pipeline.h b/source/pdal/pdalc_pipeline.h index 497bd2f..62ecd13 100644 --- a/source/pdal/pdalc_pipeline.h +++ b/source/pdal/pdalc_pipeline.h @@ -32,6 +32,7 @@ #include "pdalc_forward.h" + /** * @file pdalc_pipeline.h * Functions to launch and inspect the results of a PDAL pipeline. @@ -45,6 +46,7 @@ namespace capi { extern "C" { + #else #include // for bool #include // for size_t @@ -157,9 +159,6 @@ PDALC_API PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline); #ifdef __cplusplus } /* extern C */ - - - } /* capi*/ } /* pdal*/ #endif /* _cplusplus */ diff --git a/source/pdal/pdalc_pointview.cpp b/source/pdal/pdalc_pointview.cpp index b83ae42..b06ea2e 100644 --- a/source/pdal/pdalc_pointview.cpp +++ b/source/pdal/pdalc_pointview.cpp @@ -26,7 +26,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ - +#define _CRT_SECURE_NO_WARNINGS #include "pdalc_pointview.h" #include From 93083148aac73db7e2bfcf85fa2bf8601900db8a Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 01:20:34 +0000 Subject: [PATCH 03/18] Update pdalc_pipeline.cpp --- source/pdal/pdalc_pipeline.cpp | 182 ++++++++++++++++----------------- 1 file changed, 86 insertions(+), 96 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 2452b5f..033a533 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -37,7 +37,6 @@ #include #include -// TODO Address cause of std::min problems. See https://github.com/PDAL/CAPI/issues/4 #undef min namespace pdal @@ -50,57 +49,55 @@ extern "C" struct Pipeline { public: - std::unique_ptr manager = std::make_unique(); + PipelineManagerPtr manager = std::make_unique(); bool m_executed = false; std::stringstream logStream; - pdal::LogLevel logLevel; }; PDALPipelinePtr PDALCreatePipeline(const char* json) { - PDALPipelinePtr pipeline = new Pipeline(); - Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); + Pipeline* pipeline = new Pipeline(); if (json && std::strlen(json) > 0) { try { - LogPtr log(Log::makeLog("capi pipeline", &ptr->logStream)); - manager->setLog(log); + std::stringstream* s = &pipeline->logStream; + LogPtr lptr(pdal::Log::makeLog("pdal capi", s, true)); + pipeline->manager->setLog(lptr); std::stringstream strm; strm << json; - manager->readPipeline(strm); + pipeline->manager->readPipeline(strm); } catch (const std::exception &e) { printf("Could not create pipeline: %s\n%s\n", e.what(), json); + delete pipeline; + return nullptr; } - if (manager) + try { - try - { - manager->prepare(); - } - catch (const std::exception &e) - { - printf("Error while validating pipeline: %s\n%s\n", e.what(), json); - } + pipeline->manager->prepare(); + } + catch (const std::exception &e) + { + printf("Error while validating pipeline: %s\n%s\n", e.what(), json); + delete pipeline; + return nullptr; } - } - return pipeline; + return pipeline; + } + return nullptr; } void PDALDisposePipeline(PDALPipelinePtr pipeline) { if (pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); - ptr->manager.reset(); - delete ptr; + delete pipeline; } } @@ -111,58 +108,54 @@ extern "C" if (pipeline && buffer && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); buffer[0] = '\0'; buffer[size - 1] = '\0'; - if (manager) + try + { + if ( ! ptr->m_executed) + throw pdal_error("Pipeline has not been executed!"); + + std::stringstream strm; + pdal::PipelineWriter::writePipeline(ptr->manager->getStage(), strm); + std::strncpy(buffer, strm.str().c_str(), size - 1); + result = std::min(strm.str().length(), size); + } + catch (const std::exception &e) { - try - { - std::stringstream strm; - pdal::PipelineWriter::writePipeline(manager->getStage(), strm); - std::strncpy(buffer, strm.str().c_str(), size - 1); - result = std::min(strm.str().length(), size); - } - catch (const std::exception &e) - { - printf("Found error while retrieving pipeline's string representation: %s\n", e.what()); - } + printf("Found error while retrieving pipeline's string representation: %s\n", e.what()); } - } - return result; } size_t PDALGetPipelineMetadata(PDALPipelinePtr pipeline, char *metadata, size_t size) { + std::cout << "get metadata starts"<< std::endl; size_t result = 0; if (pipeline && metadata && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); metadata[0] = '\0'; metadata[size - 1] = '\0'; - if (manager) + try + { + if ( ! ptr->m_executed) + throw pdal_error("Pipeline has not been executed!"); + + std::stringstream strm; + MetadataNode root = ptr->manager->getMetadata().clone("metadata"); + pdal::Utils::toJSON(root, strm); + std::strncpy(metadata, strm.str().c_str(), size); + result = std::min(strm.str().length(), size); + } + catch (const std::exception &e) { - try - { - std::stringstream strm; - MetadataNode root = manager->getMetadata().clone("metadata"); - pdal::Utils::toJSON(root, strm); - std::strncpy(metadata, strm.str().c_str(), size); - result = std::min(strm.str().length(), size); - } - catch (const std::exception &e) - { - printf("Found error while retrieving pipeline's metadata: %s\n", e.what()); - } + printf("Found error while retrieving pipeline's metadata: %s\n", e.what()); } } - return result; } @@ -173,27 +166,25 @@ extern "C" if (pipeline && schema && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); + schema[0] = '\0'; schema[size - 1] = '\0'; - if (manager) + try { - try - { - std::stringstream strm; - MetadataNode root = manager->pointTable().layout()->toMetadata().clone("schema"); - pdal::Utils::toJSON(root, strm); - std::strncpy(schema, strm.str().c_str(), size); - result = std::min(strm.str().length(), size); - } - catch (const std::exception &e) - { - printf("Found error while retrieving pipeline's schema: %s\n", e.what()); - } + std::stringstream strm; + MetadataNode meta = ptr->manager->pointTable().layout()->toMetadata(); + MetadataNode root = meta.clone("schema"); + pdal::Utils::toJSON(root, strm); + std::strncpy(schema, strm.str().c_str(), size); + result = std::min(strm.str().length(), size); + } + catch (const std::exception &e) + { + printf("Found error while retrieving pipeline's schema: %s\n", e.what()); } - } + } return result; } @@ -204,22 +195,18 @@ extern "C" if (pipeline && log && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); log[0] = '\0'; log[size - 1] = '\0'; - if (manager) + try { - try - { - std::string s = ptr->logStream.str(); - std::strncpy(log, s.c_str(), size); - result = std::min(s.length(), size); - } - catch (const std::exception &e) - { - printf("Found error while retrieving pipeline's log: %s\n", e.what()); - } + std::string s = ptr->logStream.str(); + std::strncpy(log, s.c_str(), size); + result = std::min(s.length(), size); + } + catch (const std::exception &e) + { + printf("Found error while retrieving pipeline's log: %s\n", e.what()); } } @@ -229,16 +216,14 @@ extern "C" void PDALSetPipelineLogLevel(PDALPipelinePtr pipeline, int level) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); try { if (level < 0 || level > 8) throw pdal_error("log level must be between 0 and 8!"); - ptr->logLevel = static_cast(level); - pdal::LogPtr lptr = manager->log(); - lptr->setLevel(ptr->logLevel); + pdal::LogPtr lptr = ptr->manager->log(); + lptr->setLevel(static_cast(level)); } catch (const std::exception &e) { @@ -250,10 +235,16 @@ extern "C" int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); - return (ptr && ptr->manager.get()) - ? static_cast( - ptr->manager.get()->log()->getLevel() - ) : 0; + try + { + return (ptr) + ? static_cast( + ptr->manager->log()->getLevel() + ) : 0; + } + catch (const std::exception &e) + {printf("Found error while getting log level: %s\n", e.what()); } + return 0; } int64_t PDALExecutePipeline(PDALPipelinePtr pipeline) @@ -265,48 +256,47 @@ extern "C" { try { - result = ptr->manager.get()->execute(); + result = ptr->manager->execute(); + ptr->m_executed = true; } catch (const std::exception &e) { printf("Found error while executing pipeline: %s", e.what()); } } - return result; } bool PDALValidatePipeline(PDALPipelinePtr pipeline) { - int64_t result = 0; Pipeline *ptr = reinterpret_cast(pipeline); if (ptr) { try { - ptr->manager.get()->prepare(); + ptr->manager->prepare(); + return true; } catch (const std::exception &e) { printf("Found error while validating pipeline: %s", e.what()); + return false; } } - - return result; + return false; } PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); - PipelineManager *manager = ptr->manager.get(); pdal::capi::PointViewIterator *views = nullptr; if (ptr) { try { - views = new pdal::capi::PointViewIterator(manager->views()); + views = new pdal::capi::PointViewIterator(ptr->manager->views()); } catch (const std::exception &e) { From 093eba52c674d351074c454b92d9ff10b31b6df4 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 01:49:30 +0000 Subject: [PATCH 04/18] astyle changes --- source/pdal/pdalc_pipeline.cpp | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 033a533..68716d2 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -46,13 +46,14 @@ namespace capi extern "C" { - struct Pipeline { - public: + struct Pipeline + { + public: - PipelineManagerPtr manager = std::make_unique(); + PipelineManagerPtr manager = std::make_unique(); - bool m_executed = false; - std::stringstream logStream; + bool m_executed = false; + std::stringstream logStream; }; PDALPipelinePtr PDALCreatePipeline(const char* json) @@ -113,9 +114,9 @@ extern "C" try { - if ( ! ptr->m_executed) + if (! ptr->m_executed) throw pdal_error("Pipeline has not been executed!"); - + std::stringstream strm; pdal::PipelineWriter::writePipeline(ptr->manager->getStage(), strm); std::strncpy(buffer, strm.str().c_str(), size - 1); @@ -142,9 +143,9 @@ extern "C" try { - if ( ! ptr->m_executed) + if (! ptr->m_executed) throw pdal_error("Pipeline has not been executed!"); - + std::stringstream strm; MetadataNode root = ptr->manager->getMetadata().clone("metadata"); pdal::Utils::toJSON(root, strm); @@ -217,8 +218,8 @@ extern "C" { Pipeline *ptr = reinterpret_cast(pipeline); - try - { + try + { if (level < 0 || level > 8) throw pdal_error("log level must be between 0 and 8!"); @@ -227,7 +228,7 @@ extern "C" } catch (const std::exception &e) { - printf("Found error while setting log level: %s\n", e.what()); + printf("Found error while setting log level: %s\n", e.what()); } } @@ -237,13 +238,15 @@ extern "C" Pipeline *ptr = reinterpret_cast(pipeline); try { - return (ptr) - ? static_cast( - ptr->manager->log()->getLevel() - ) : 0; + return (ptr) + ? static_cast( + ptr->manager->log()->getLevel() + ) : 0; } catch (const std::exception &e) - {printf("Found error while getting log level: %s\n", e.what()); } + { + printf("Found error while getting log level: %s\n", e.what()); + } return 0; } From 82409b20aa9232223efbdf6658a9260df661a0be Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 10:09:46 +0000 Subject: [PATCH 05/18] fix compile warnings --- source/pdal/pdalc_pipeline.cpp | 3 ++- tests/pdal/test_pdalc_config.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 68716d2..aa8530f 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -98,7 +98,8 @@ extern "C" { if (pipeline) { - delete pipeline; + Pipeline *ptr = reinterpret_cast(pipeline); + delete ptr; } } diff --git a/tests/pdal/test_pdalc_config.c b/tests/pdal/test_pdalc_config.c index fe2cc2a..b598a79 100644 --- a/tests/pdal/test_pdalc_config.c +++ b/tests/pdal/test_pdalc_config.c @@ -140,7 +140,7 @@ TEST testPDALVersionInfo(void) sha1[6] = '\0'; } - sprintf(expected + strlen(version), " (git-version: %s)", sha1); + snprintf(expected + strlen(version), " (git-version: %s)", sha1); char fullVersion[64]; size = PDALFullVersionString(fullVersion, 64); From e159fda08e3a692fbb3a0212cc7b7e181b609368 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 12:21:01 +0000 Subject: [PATCH 06/18] Update test_pdalc_config.c --- tests/pdal/test_pdalc_config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pdal/test_pdalc_config.c b/tests/pdal/test_pdalc_config.c index b598a79..5dd39ae 100644 --- a/tests/pdal/test_pdalc_config.c +++ b/tests/pdal/test_pdalc_config.c @@ -114,12 +114,12 @@ TEST testPDALVersionInfo(void) int patch = PDALVersionPatch(); - char expected[64]; - sprintf(expected, "%d.%d.%d", major, minor, patch); + char expected[128]; + snprintf(expected, "%d.%d.%d", major, minor, patch); - char version[64]; - size_t size = PDALVersionString(version, 64); - ASSERT(size > 0 && size <= 64); + char version[128]; + size_t size = PDALVersionString(version, 128); + ASSERT(size > 0 && size <= 128); ASSERT(version[0]); ASSERT_STR_EQ(expected, version); From 03c20ab8f36f5ac137953681983d7816b8f81528 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 12:25:42 +0000 Subject: [PATCH 07/18] Revert "Update test_pdalc_config.c" This reverts commit e159fda08e3a692fbb3a0212cc7b7e181b609368. --- tests/pdal/test_pdalc_config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pdal/test_pdalc_config.c b/tests/pdal/test_pdalc_config.c index 5dd39ae..b598a79 100644 --- a/tests/pdal/test_pdalc_config.c +++ b/tests/pdal/test_pdalc_config.c @@ -114,12 +114,12 @@ TEST testPDALVersionInfo(void) int patch = PDALVersionPatch(); - char expected[128]; - snprintf(expected, "%d.%d.%d", major, minor, patch); + char expected[64]; + sprintf(expected, "%d.%d.%d", major, minor, patch); - char version[128]; - size_t size = PDALVersionString(version, 128); - ASSERT(size > 0 && size <= 128); + char version[64]; + size_t size = PDALVersionString(version, 64); + ASSERT(size > 0 && size <= 64); ASSERT(version[0]); ASSERT_STR_EQ(expected, version); From ab9b97fe023aeca9f0b93bc5b96ec314c52611d7 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 12:27:53 +0000 Subject: [PATCH 08/18] Update test_pdalc_config.c --- tests/pdal/test_pdalc_config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/pdal/test_pdalc_config.c b/tests/pdal/test_pdalc_config.c index b598a79..1f12898 100644 --- a/tests/pdal/test_pdalc_config.c +++ b/tests/pdal/test_pdalc_config.c @@ -114,12 +114,12 @@ TEST testPDALVersionInfo(void) int patch = PDALVersionPatch(); - char expected[64]; + char expected[128]; sprintf(expected, "%d.%d.%d", major, minor, patch); - char version[64]; - size_t size = PDALVersionString(version, 64); - ASSERT(size > 0 && size <= 64); + char version[128]; + size_t size = PDALVersionString(version, 128); + ASSERT(size > 0 && size <= 128); ASSERT(version[0]); ASSERT_STR_EQ(expected, version); @@ -140,7 +140,7 @@ TEST testPDALVersionInfo(void) sha1[6] = '\0'; } - snprintf(expected + strlen(version), " (git-version: %s)", sha1); + sprintf(expected + strlen(version), " (git-version: %s)", sha1); char fullVersion[64]; size = PDALFullVersionString(fullVersion, 64); From 4e451bba3e64de6736d1686c1d493c248d7e1036 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 22:29:23 +0000 Subject: [PATCH 09/18] Added streaming interface --- source/pdal/pdalc_pipeline.cpp | 35 +++++++++++++++++++++++++++++ source/pdal/pdalc_pipeline.h | 16 +++++++++++++ tests/pdal/test_pdalc_pipeline.c.in | 26 +++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index aa8530f..3e98dba 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #undef min @@ -271,6 +272,40 @@ extern "C" return result; } + bool PDALExecutePipelineAsStream(PDALPipelinePtr pipeline) + { + Pipeline *ptr = reinterpret_cast(pipeline); + + if (ptr) + { + try + { + PipelineManager::ExecResult exec = ptr->manager->execute(ExecMode::Stream); + ptr->m_executed = true; + return true; + } + catch (const std::exception &e) + { + printf("Found error while executing pipeline: %s", e.what()); + return false; + } + } + return false; + } + + bool PDALPipelineIsStreamable(PDALPipelinePtr pipeline) + { + Pipeline *ptr = reinterpret_cast(pipeline); + + if (ptr) + { + return ptr->manager->pipelineStreamable(); + } + return false; + } + + + bool PDALValidatePipeline(PDALPipelinePtr pipeline) { Pipeline *ptr = reinterpret_cast(pipeline); diff --git a/source/pdal/pdalc_pipeline.h b/source/pdal/pdalc_pipeline.h index 62ecd13..e3a8971 100644 --- a/source/pdal/pdalc_pipeline.h +++ b/source/pdal/pdalc_pipeline.h @@ -136,6 +136,22 @@ PDALC_API int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline); */ PDALC_API int64_t PDALExecutePipeline(PDALPipelinePtr pipeline); +/** + * Executes a pipeline as a streamable pipeline. Will run as non-streamed pipeline if the pipeline is not streamable. + * + * @param pipeline The pipeline + * @return The total number of points produced by the pipeline + */ +PDALC_API bool PDALExecutePipelineAsStream(PDALPipelinePtr pipeline); + +/** + * Determines if a pipeline is streamable + * + * @param pipeline The pipeline + * @return Whether the pipeline is streamable + */ +PDALC_API bool PDALPipelineIsStreamable(PDALPipelinePtr pipeline); + /** * Validates a pipeline. * diff --git a/tests/pdal/test_pdalc_pipeline.c.in b/tests/pdal/test_pdalc_pipeline.c.in index 4215daf..114bd8e 100644 --- a/tests/pdal/test_pdalc_pipeline.c.in +++ b/tests/pdal/test_pdalc_pipeline.c.in @@ -344,6 +344,31 @@ TEST testPDALExecutePipeline(void) PASS(); } +TEST testPDALExecutePipelineStream(void) +{ + PDALPipelinePtr pipeline = PDALCreatePipeline(gPipelineJson); + ASSERT(pipeline); + + bool isStreamable = PDALPipelineIsStreamable(pipeline); + + ASSERT_EQ(isStreamable, true); + + bool result = PDALExecutePipelineAsStream(pipeline); + + ASSERT_EQ(result, true); + + result = PDALExecutePipelineAsStream(NULL); + + ASSERT_EQ(result, false); + + isStreamable = PDALPipelineIsStreamable(NULL); + + ASSERT_EQ(isStreamable, false); + + PDALDisposePipeline(pipeline); + PASS(); +} + TEST testPDALValidatePipeline(void) { bool valid = PDALValidatePipeline(NULL); @@ -369,6 +394,7 @@ GREATEST_SUITE(test_pdalc_pipeline) RUN_TEST(testPDALCreateAndDisposePipeline); RUN_TEST(testPDALExecutePipeline); + RUN_TEST(testPDALExecutePipelineStream); RUN_TEST(testPDALGetSetPipelineLog); RUN_TEST(testPDALGetPipelineAsString); RUN_TEST(testPDALGetPipelineMetadata); From 0093cdf1186909a95fe538847b580026bf0e3875 Mon Sep 17 00:00:00 2001 From: runette Date: Wed, 1 Feb 2023 22:48:44 +0000 Subject: [PATCH 10/18] documentation fixes --- source/pdal/pdalc_pipeline.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/pdal/pdalc_pipeline.h b/source/pdal/pdalc_pipeline.h index e3a8971..da76f70 100644 --- a/source/pdal/pdalc_pipeline.h +++ b/source/pdal/pdalc_pipeline.h @@ -140,7 +140,7 @@ PDALC_API int64_t PDALExecutePipeline(PDALPipelinePtr pipeline); * Executes a pipeline as a streamable pipeline. Will run as non-streamed pipeline if the pipeline is not streamable. * * @param pipeline The pipeline - * @return The total number of points produced by the pipeline + * @return true for success */ PDALC_API bool PDALExecutePipelineAsStream(PDALPipelinePtr pipeline); From 68995902348e3ce7069b3e24dab3349f9edea674 Mon Sep 17 00:00:00 2001 From: runette Date: Fri, 3 Feb 2023 13:34:41 +0000 Subject: [PATCH 11/18] remove lint --- source/pdal/pdalc_pipeline.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 3e98dba..9447d4e 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -134,7 +134,6 @@ extern "C" size_t PDALGetPipelineMetadata(PDALPipelinePtr pipeline, char *metadata, size_t size) { - std::cout << "get metadata starts"<< std::endl; size_t result = 0; if (pipeline && metadata && size > 0) From 8616cec2052299a0027480fe73eb2b782c869e6a Mon Sep 17 00:00:00 2001 From: runette Date: Fri, 3 Feb 2023 14:06:57 +0000 Subject: [PATCH 12/18] improved pointer handling --- source/pdal/pdalc_pipeline.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 9447d4e..1a0138d 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -59,7 +59,7 @@ extern "C" PDALPipelinePtr PDALCreatePipeline(const char* json) { - Pipeline* pipeline = new Pipeline(); + std::unique_ptr pipeline = std::make_unique(); if (json && std::strlen(json) > 0) { try @@ -75,7 +75,6 @@ extern "C" catch (const std::exception &e) { printf("Could not create pipeline: %s\n%s\n", e.what(), json); - delete pipeline; return nullptr; } @@ -86,11 +85,10 @@ extern "C" catch (const std::exception &e) { printf("Error while validating pipeline: %s\n%s\n", e.what(), json); - delete pipeline; return nullptr; } - return pipeline; + return pipeline.release(); } return nullptr; } From 47ebb453f049d9858b1c69138b4e03442b01ff18 Mon Sep 17 00:00:00 2001 From: runette Date: Fri, 3 Feb 2023 14:40:41 +0000 Subject: [PATCH 13/18] Update CHANGELOG.md --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e16368..453dd4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# Version 2.2.0 + +This is a major change to the underlying code to remove the deprecated `pdal::PipelineExecutor` and replace it with `pdal::PipelineManager`. + +This version also introduces the following non-breaking changes to the ABI: + +- Addition of the following method to allow the consuming app to tell if a pipeline is streamable: + +``` +bool PDALPipelineIsStreamable(PDALPipelinePtr pipeline) +``` + +- Addition of the following method to allow the consuming application to run a pipeline in streaming mode. If the pipeline is non-streamable it will be silently run in standard mode: + +``` +bool PDALExecutePipelineAsStream(PDALPipelinePtr pipeline) +``` + + # Version 2.1.1 Changes to allow compilation with PDAL 2.4.0 From 44994c3ca2f7a9d45c25e2a94d3f3772448d6e0a Mon Sep 17 00:00:00 2001 From: runette Date: Fri, 3 Feb 2023 16:26:05 +0000 Subject: [PATCH 14/18] improve readability after review --- source/pdal/pdalc_pipeline.cpp | 123 +++++++++++++++------------------ 1 file changed, 56 insertions(+), 67 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 1a0138d..fd417d0 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -215,10 +215,9 @@ extern "C" void PDALSetPipelineLogLevel(PDALPipelinePtr pipeline, int level) { - Pipeline *ptr = reinterpret_cast(pipeline); - try { + Pipeline *ptr = reinterpret_cast(pipeline); if (level < 0 || level > 8) throw pdal_error("log level must be between 0 and 8!"); @@ -229,14 +228,16 @@ extern "C" { printf("Found error while setting log level: %s\n", e.what()); } - } int PDALGetPipelineLogLevel(PDALPipelinePtr pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); + if (! pipeline) + return 0; + try { + Pipeline *ptr = reinterpret_cast(pipeline); return (ptr) ? static_cast( ptr->manager->log()->getLevel() @@ -251,100 +252,88 @@ extern "C" int64_t PDALExecutePipeline(PDALPipelinePtr pipeline) { - int64_t result = 0; - Pipeline *ptr = reinterpret_cast(pipeline); + if (! pipeline) + return 0; - if (ptr) + try { - try - { - result = ptr->manager->execute(); - ptr->m_executed = true; - } - catch (const std::exception &e) - { - printf("Found error while executing pipeline: %s", e.what()); - } + int64_t result; + Pipeline *ptr = reinterpret_cast(pipeline); + result = ptr->manager->execute(); + ptr->m_executed = true; + return result; + } + catch (const std::exception &e) + { + printf("Found error while executing pipeline: %s", e.what()); + return 0; } - return result; } bool PDALExecutePipelineAsStream(PDALPipelinePtr pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); + if (! pipeline) + return false; - if (ptr) + try { - try - { - PipelineManager::ExecResult exec = ptr->manager->execute(ExecMode::Stream); - ptr->m_executed = true; - return true; - } - catch (const std::exception &e) - { - printf("Found error while executing pipeline: %s", e.what()); - return false; - } + Pipeline *ptr = reinterpret_cast(pipeline); + PipelineManager::ExecResult exec = ptr->manager->execute(ExecMode::Stream); + ptr->m_executed = true; + return true; + } + catch (const std::exception &e) + { + printf("Found error while executing pipeline: %s", e.what()); + return false; } - return false; } bool PDALPipelineIsStreamable(PDALPipelinePtr pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); + if (! pipeline) + return false; - if (ptr) - { - return ptr->manager->pipelineStreamable(); - } - return false; + Pipeline *ptr = reinterpret_cast(pipeline); + return ptr->manager->pipelineStreamable(); } bool PDALValidatePipeline(PDALPipelinePtr pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); - - if (ptr) + if (! pipeline) + return false; + try { - try - { - ptr->manager->prepare(); - return true; - } - catch (const std::exception &e) - { - printf("Found error while validating pipeline: %s", e.what()); - return false; - } + Pipeline *ptr = reinterpret_cast(pipeline); + ptr->manager->prepare(); + return true; + } + catch (const std::exception &e) + { + printf("Found error while validating pipeline: %s", e.what()); + return false; } - return false; } PDALPointViewIteratorPtr PDALGetPointViews(PDALPipelinePtr pipeline) { - Pipeline *ptr = reinterpret_cast(pipeline); - pdal::capi::PointViewIterator *views = nullptr; + if (! pipeline) + return nullptr; - if (ptr) + try { - try - { - views = new pdal::capi::PointViewIterator(ptr->manager->views()); - } - catch (const std::exception &e) - { - printf("Found error while retrieving point views: %s\n", e.what()); - } + Pipeline *ptr = reinterpret_cast(pipeline); + return new pdal::capi::PointViewIterator(ptr->manager->views()); + } + catch (const std::exception &e) + { + printf("Found error while retrieving point views: %s\n", e.what()); + return nullptr; } - - return views; } -} /* extern c */ - - +} /* extern c */ } /* capi */ } /* pdal */ From 9bc256bddbc7862206e1073d6771f4a378603360 Mon Sep 17 00:00:00 2001 From: runette Date: Sat, 4 Feb 2023 10:33:16 +0000 Subject: [PATCH 15/18] fixup null terminated strings --- source/pdal/pdalc_pipeline.cpp | 46 ++++++++++++---------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index fd417d0..5f8255b 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -104,13 +104,9 @@ extern "C" size_t PDALGetPipelineAsString(PDALPipelinePtr pipeline, char *buffer, size_t size) { - size_t result = 0; - if (pipeline && buffer && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - buffer[0] = '\0'; - buffer[size - 1] = '\0'; try { @@ -119,26 +115,23 @@ extern "C" std::stringstream strm; pdal::PipelineWriter::writePipeline(ptr->manager->getStage(), strm); - std::strncpy(buffer, strm.str().c_str(), size - 1); - result = std::min(strm.str().length(), size); + strm.get(buffer, size); + return std::min(static_cast(strm.gcount()), size); } catch (const std::exception &e) { printf("Found error while retrieving pipeline's string representation: %s\n", e.what()); + return 0; } } - return result; + return 0; } size_t PDALGetPipelineMetadata(PDALPipelinePtr pipeline, char *metadata, size_t size) { - size_t result = 0; - if (pipeline && metadata && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - metadata[0] = '\0'; - metadata[size - 1] = '\0'; try { @@ -148,69 +141,62 @@ extern "C" std::stringstream strm; MetadataNode root = ptr->manager->getMetadata().clone("metadata"); pdal::Utils::toJSON(root, strm); - std::strncpy(metadata, strm.str().c_str(), size); - result = std::min(strm.str().length(), size); + strm.get(metadata, size); + return std::min(static_cast(strm.gcount()), size); } catch (const std::exception &e) { printf("Found error while retrieving pipeline's metadata: %s\n", e.what()); + return 0; } } - return result; + return 0; } size_t PDALGetPipelineSchema(PDALPipelinePtr pipeline, char *schema, size_t size) { - size_t result = 0; - if (pipeline && schema && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - schema[0] = '\0'; - schema[size - 1] = '\0'; - try { std::stringstream strm; MetadataNode meta = ptr->manager->pointTable().layout()->toMetadata(); MetadataNode root = meta.clone("schema"); pdal::Utils::toJSON(root, strm); - std::strncpy(schema, strm.str().c_str(), size); - result = std::min(strm.str().length(), size); + strm.get(schema, size); + return std::min(static_cast(strm.gcount()), size); } catch (const std::exception &e) { printf("Found error while retrieving pipeline's schema: %s\n", e.what()); + return 0; } } - return result; + return 0; } size_t PDALGetPipelineLog(PDALPipelinePtr pipeline, char *log, size_t size) { - size_t result = 0; - if (pipeline && log && size > 0) { Pipeline *ptr = reinterpret_cast(pipeline); - log[0] = '\0'; - log[size - 1] = '\0'; try { - std::string s = ptr->logStream.str(); - std::strncpy(log, s.c_str(), size); - result = std::min(s.length(), size); + ptr->logStream.get(log, size); + return std::min(static_cast(ptr->logStream.gcount()), size); } catch (const std::exception &e) { printf("Found error while retrieving pipeline's log: %s\n", e.what()); + return 0; } } - return result; + return 0; } void PDALSetPipelineLogLevel(PDALPipelinePtr pipeline, int level) From 445b4156003d22c01427d6b2970f6e92edd97411 Mon Sep 17 00:00:00 2001 From: runette Date: Sat, 4 Feb 2023 13:32:53 +0000 Subject: [PATCH 16/18] fixup null terminating strings 2 --- source/pdal/pdalc_pipeline.cpp | 18 +++++++++----- tests/pdal/test_pdalc_pipeline.c.in | 37 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 5f8255b..340c622 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -115,8 +115,10 @@ extern "C" std::stringstream strm; pdal::PipelineWriter::writePipeline(ptr->manager->getStage(), strm); - strm.get(buffer, size); - return std::min(static_cast(strm.gcount()), size); + std::string out = strm.str(); + if (out.length() > size - 1) out.resize(size - 1); + std::strncpy(buffer, out.c_str(), size); + return std::min(out.length() + 1, size); } catch (const std::exception &e) { @@ -141,8 +143,10 @@ extern "C" std::stringstream strm; MetadataNode root = ptr->manager->getMetadata().clone("metadata"); pdal::Utils::toJSON(root, strm); - strm.get(metadata, size); - return std::min(static_cast(strm.gcount()), size); + std::string out = strm.str(); + if (out.length() > size - 1) out.resize(size - 1); + std::strncpy(metadata, out.c_str(), size); + return std::min(out.length() + 1, size); } catch (const std::exception &e) { @@ -165,8 +169,10 @@ extern "C" MetadataNode meta = ptr->manager->pointTable().layout()->toMetadata(); MetadataNode root = meta.clone("schema"); pdal::Utils::toJSON(root, strm); - strm.get(schema, size); - return std::min(static_cast(strm.gcount()), size); + std::string out = strm.str(); + if (out.length() > size - 1) out.resize(size - 1); + std::strncpy(schema, out.c_str(), size); + return std::min(out.length() + 1, size); } catch (const std::exception &e) { diff --git a/tests/pdal/test_pdalc_pipeline.c.in b/tests/pdal/test_pdalc_pipeline.c.in index 114bd8e..61f0cf8 100644 --- a/tests/pdal/test_pdalc_pipeline.c.in +++ b/tests/pdal/test_pdalc_pipeline.c.in @@ -146,6 +146,23 @@ TEST testPDALGetPipelineAsString(void) FAILm("PDALGetPipelineMetadata generated a JSON string whose object name is not \"pipeline\""); } + char json10[10]; + size = PDALGetPipelineAsString(pipeline, json10, 10); + + if (size != 10 ) + { + PDALDisposePipeline(pipeline); + pipeline = NULL; + FAILm("PDALGetPipelineAsString truncation not working"); + } + + if (json[0] == '\0') + { + PDALDisposePipeline(pipeline); + pipeline = NULL; + FAILm("PDALGetPipelineAsString generated a JSON string whose first character is null"); + } + PDALDisposePipeline(pipeline); PASS(); } @@ -200,6 +217,16 @@ TEST testPDALGetPipelineMetadata(void) FAILm("PDALGetPipelineMetadata generated a JSON string whose object name is not \"schema\""); } + char json10[10]; + size = PDALGetPipelineMetadata(pipeline, json10, 10); + + if (size != 10 ) + { + PDALDisposePipeline(pipeline); + pipeline = NULL; + FAILm("PDALGetPipelineMetadata truncation not working"); + } + PDALDisposePipeline(pipeline); PASS(); } @@ -254,6 +281,16 @@ TEST testPDALGetPipelineSchema(void) FAILm("PDALGetPipelineSchema generated a JSON string whose object name is not \"schema\""); } + char json10[10]; + size = PDALGetPipelineSchema(pipeline, json10, 10); + + if (size != 10 ) + { + PDALDisposePipeline(pipeline); + pipeline = NULL; + FAILm("PDALGetPipelineSchema truncation not working"); + } + PDALDisposePipeline(pipeline); PASS(); } From 7c6bf38fdbf1d3628465219e4a334b8e24fa1c0d Mon Sep 17 00:00:00 2001 From: runette Date: Sat, 4 Feb 2023 17:06:40 +0000 Subject: [PATCH 17/18] strlen and fix schema --- source/pdal/pdalc_pipeline.cpp | 9 ++++++--- tests/pdal/test_pdalc_pipeline.c.in | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 340c622..3e20d7c 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -118,7 +118,7 @@ extern "C" std::string out = strm.str(); if (out.length() > size - 1) out.resize(size - 1); std::strncpy(buffer, out.c_str(), size); - return std::min(out.length() + 1, size); + return strlen(out.c_str()); } catch (const std::exception &e) { @@ -146,7 +146,7 @@ extern "C" std::string out = strm.str(); if (out.length() > size - 1) out.resize(size - 1); std::strncpy(metadata, out.c_str(), size); - return std::min(out.length() + 1, size); + return strlen(out.c_str()); } catch (const std::exception &e) { @@ -165,6 +165,9 @@ extern "C" try { + if (! ptr->m_executed) + throw pdal_error("Pipeline has not been executed!"); + std::stringstream strm; MetadataNode meta = ptr->manager->pointTable().layout()->toMetadata(); MetadataNode root = meta.clone("schema"); @@ -172,7 +175,7 @@ extern "C" std::string out = strm.str(); if (out.length() > size - 1) out.resize(size - 1); std::strncpy(schema, out.c_str(), size); - return std::min(out.length() + 1, size); + return strlen(out.c_str()); } catch (const std::exception &e) { diff --git a/tests/pdal/test_pdalc_pipeline.c.in b/tests/pdal/test_pdalc_pipeline.c.in index 61f0cf8..95ece45 100644 --- a/tests/pdal/test_pdalc_pipeline.c.in +++ b/tests/pdal/test_pdalc_pipeline.c.in @@ -149,7 +149,7 @@ TEST testPDALGetPipelineAsString(void) char json10[10]; size = PDALGetPipelineAsString(pipeline, json10, 10); - if (size != 10 ) + if (size != 9 ) { PDALDisposePipeline(pipeline); pipeline = NULL; @@ -220,7 +220,7 @@ TEST testPDALGetPipelineMetadata(void) char json10[10]; size = PDALGetPipelineMetadata(pipeline, json10, 10); - if (size != 10 ) + if (size != 9 ) { PDALDisposePipeline(pipeline); pipeline = NULL; @@ -284,7 +284,7 @@ TEST testPDALGetPipelineSchema(void) char json10[10]; size = PDALGetPipelineSchema(pipeline, json10, 10); - if (size != 10 ) + if (size != 9 ) { PDALDisposePipeline(pipeline); pipeline = NULL; From 31aad747d2e399a63eb4ec6209d486728c53ed6c Mon Sep 17 00:00:00 2001 From: runette Date: Sat, 4 Feb 2023 17:13:09 +0000 Subject: [PATCH 18/18] astyle --- source/pdal/pdalc_pipeline.cpp | 2 +- tests/pdal/test_pdalc_pipeline.c.in | 6 +++--- tests/pdal/test_pdalc_pointlayout.c.in | 4 ++-- tests/pdal/test_pdalc_pointview.c.in | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/pdal/pdalc_pipeline.cpp b/source/pdal/pdalc_pipeline.cpp index 3e20d7c..ce9d966 100644 --- a/source/pdal/pdalc_pipeline.cpp +++ b/source/pdal/pdalc_pipeline.cpp @@ -167,7 +167,7 @@ extern "C" { if (! ptr->m_executed) throw pdal_error("Pipeline has not been executed!"); - + std::stringstream strm; MetadataNode meta = ptr->manager->pointTable().layout()->toMetadata(); MetadataNode root = meta.clone("schema"); diff --git a/tests/pdal/test_pdalc_pipeline.c.in b/tests/pdal/test_pdalc_pipeline.c.in index 95ece45..87576b8 100644 --- a/tests/pdal/test_pdalc_pipeline.c.in +++ b/tests/pdal/test_pdalc_pipeline.c.in @@ -149,7 +149,7 @@ TEST testPDALGetPipelineAsString(void) char json10[10]; size = PDALGetPipelineAsString(pipeline, json10, 10); - if (size != 9 ) + if (size != 9) { PDALDisposePipeline(pipeline); pipeline = NULL; @@ -220,7 +220,7 @@ TEST testPDALGetPipelineMetadata(void) char json10[10]; size = PDALGetPipelineMetadata(pipeline, json10, 10); - if (size != 9 ) + if (size != 9) { PDALDisposePipeline(pipeline); pipeline = NULL; @@ -284,7 +284,7 @@ TEST testPDALGetPipelineSchema(void) char json10[10]; size = PDALGetPipelineSchema(pipeline, json10, 10); - if (size != 9 ) + if (size != 9) { PDALDisposePipeline(pipeline); pipeline = NULL; diff --git a/tests/pdal/test_pdalc_pointlayout.c.in b/tests/pdal/test_pdalc_pointlayout.c.in index 9585439..30093a6 100644 --- a/tests/pdal/test_pdalc_pointlayout.c.in +++ b/tests/pdal/test_pdalc_pointlayout.c.in @@ -129,14 +129,14 @@ TEST testPDALFindDimType(void) success &= (PDALGetDimTypeIdName(expected, name, 64) > 0); actual = PDALFindDimType(NULL, name); - success &= (idUnknown == actual.id); + success &= (idUnknown == actual.id); success &= (typeNone == actual.type); success &= (fabs(1.0 - actual.scale) < tolerance); success &= (fabs(actual.offset) < tolerance); actual = PDALFindDimType(gLayout, name); - success &= (expected.id == actual.id); + success &= (expected.id == actual.id); success &= (expected.type == actual.type); success &= (fabs(expected.scale - actual.scale) < tolerance); diff --git a/tests/pdal/test_pdalc_pointview.c.in b/tests/pdal/test_pdalc_pointview.c.in index 6e78813..26462ba 100644 --- a/tests/pdal/test_pdalc_pointview.c.in +++ b/tests/pdal/test_pdalc_pointview.c.in @@ -166,7 +166,7 @@ TEST testPDALGetPointViewSize(void) PDALDisposePointView(view); ASSERT(size > 0); - + PASS(); } @@ -189,7 +189,7 @@ TEST testPDALGetMeshSize(void) PDALDisposePointView(view); ASSERT(size == 2114); - + PASS(); } @@ -538,7 +538,7 @@ TEST testPDALGetPackedPoint(void) size_t expected = (hasView && hasDims && hasBuffer ? layoutPointSize : 0); size_t actual = PDALGetPackedPoint( - hasView ? view : NULL, hasDims ? dims : NULL, i, hasBuffer ? buffer : NULL); + hasView ? view : NULL, hasDims ? dims : NULL, i, hasBuffer ? buffer : NULL); if (expected != actual) {