From 89e854bbe7a7b47cb1c2ec01fe12c68bfa9ce6f2 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 24 Apr 2017 09:36:22 -0700 Subject: [PATCH 1/4] Fix LogSessionExport compilation. Prior commit was not compiling. This was because the example was using outdated API code. In the process of these updates for this example as well as LogSessionImport example, some bugs were discovered in the C++ API that are now in development. Closes Core-141 --- LogSessionExport/CMakeLists.txt | 1 + LogSessionExport/LogSessionExport.cpp | 166 +++++++++++--------------- LogSessionExport/LogSessionExport.hpp | 70 +++++++++++ LogSessionExport/main.cpp | 63 ++++++++++ 4 files changed, 206 insertions(+), 94 deletions(-) create mode 100644 LogSessionExport/LogSessionExport.hpp create mode 100644 LogSessionExport/main.cpp diff --git a/LogSessionExport/CMakeLists.txt b/LogSessionExport/CMakeLists.txt index 5325c3b..3101f9b 100644 --- a/LogSessionExport/CMakeLists.txt +++ b/LogSessionExport/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories( ) add_executable( ${PROJECT_NAME} + main.cpp LogSessionExport.cpp ) diff --git a/LogSessionExport/LogSessionExport.cpp b/LogSessionExport/LogSessionExport.cpp index d06cd38..f77fe5e 100644 --- a/LogSessionExport/LogSessionExport.cpp +++ b/LogSessionExport/LogSessionExport.cpp @@ -22,115 +22,93 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -/** - * \example LogSessionExport.cpp - * - * Log session export example. - * - * Demonstrates how to use the PolySync log session transfer API to export a previously - * recorded log session from a new distributed system. - * - */ - #include + +#include #include #include -#include -#include -using namespace std; -using namespace polysync; -using namespace datamodel; +#include "LogSessionExport.hpp" -/** - * @brief SessionExportExample class - */ -class SessionExportExample : public DataSubscriber -{ - -public: - - SessionExportExample( - int sessionId ) - : - _sessionId( sessionId ) - { - // Subscribe to ApplicationEventMessage to determine when - // the application connects to the PolySync bus. - connectSubscriberMethod< SessionExportExample >( - ApplicationEventMessage::getName(), - &SessionExportExample::handleEvent, - this ); - - _application = Application::getInstance(); - _application->attachSubscriber( this ); - } - -private: - - void handleEvent( shared_ptr< Message > message ) - { - if( auto event = getSubclass< ApplicationEventMessage >( message ) ) - { - if( event->getEventKind() == EventKind::Init ) - { - // This is the actual usage of the export API. - _exporter = new LogSessionExport( _sessionId ); +SessionExportExample::SessionExportExample( + int sessionId, + const std::string & sessionPath ) + : + _sessionId( sessionId ), + _sessionPath( sessionPath ), + _exporter() +{ + // Subscribe to ApplicationEventMessage to determine when + // the application connects to the PolySync bus. + connectSubscriberMethod< SessionExportExample >( + polysync::ApplicationEventMessage::getName(), + &SessionExportExample::handleEvent, + this ); + + polysync::Application::getInstance()->attachSubscriber( this ); +} - // Export can be started with or without a progress callback. - // When complete, results will be located at "PSYNC_HOME/rnr_logs/export/[sessionId]" - _exporter->start( - this, - &SessionExportExample::handleTransferStatus ); - } - } - } - void handleTransferStatus( - const LogSessionTransferStatus & status ) +void SessionExportExample::handleEvent( + std::shared_ptr< polysync::Message > message ) +{ + if( auto event = polysync::datamodel::getSubclass< + polysync::ApplicationEventMessage >( message ) ) { - // Status has other information available as well - auto state = status.getState(); - - cout << "State: "; - - switch( state ) + if( event->getEventKind() == polysync::EventKind::Init ) { - case LogSessionTransferState::Invalid : cout << "Invalid" << endl; break; - case LogSessionTransferState::Error : cout << "Error" << endl; break; - case LogSessionTransferState::Initial : cout << "Initial" << endl; break; - case LogSessionTransferState::Enumeration : cout << "Enumeration" << endl; break; - case LogSessionTransferState::TransferringSystemFiles : cout << "TransferringSystemFiles" << endl; break; - case LogSessionTransferState::TransformingSystemFile : cout << "TransformingSystemFile" << endl; break; - case LogSessionTransferState::TransferringLogfiles : cout << "TransferringLogfiles" << endl; break; - case LogSessionTransferState::Complete : cout << "Complete" << endl; _application->disconnectPolySync(); break; + // This is the actual usage of the export API. + _exporter = std::unique_ptr< polysync::LogSessionExport >{ + new polysync::LogSessionExport{ + _sessionId, _sessionPath } }; + + // Export can be started with or without a progress callback. + // When complete, results will be located at + // "PSYNC_HOME/rnr_logs/export/[sessionId]" + _exporter->start( + this, + &SessionExportExample::handleTransferStatus ); } } - - int _sessionId; - - LogSessionExport * _exporter; - - Application * _application; - -}; +} -int main( int argc, char ** argv ) +void SessionExportExample::handleTransferStatus( + const polysync::LogSessionTransferState state, + const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & ) { - if( argc != 2 ) + std::cout << "State: "; + + switch( state ) { - cerr << "Usage: " << argv[0] << " [sessionId]" << endl; - return -1; + case polysync::LogSessionTransferState::Invalid: + std::cout << "Invalid" << std::endl; + break; + case polysync::LogSessionTransferState::Error: + std::cout << "Error" << std::endl; + break; + case polysync::LogSessionTransferState::Initial: + std::cout << "Initial" << std::endl; + break; + case polysync::LogSessionTransferState::Enumeration: + std::cout << "Enumeration" << std::endl; + break; + case polysync::LogSessionTransferState::TransferringSystemFiles: + std::cout << "TransferringSystemFiles" << std::endl; + break; + case polysync::LogSessionTransferState::TransformingSystemFile: + std::cout << "TransformingSystemFile" << std::endl; + break; + case polysync::LogSessionTransferState::TransferringLogfiles: + std::cout << "TransferringLogfiles" << std::endl; + break; + case polysync::LogSessionTransferState::Complete: + std::cout << "Complete" << std::endl; + polysync::Application::getInstance()->disconnectPolySync(); + break; + default: + std::cout << "Unknown polysync::LogSessionTransferState" + << std::endl; } - - SessionExportExample exportExample{ atoi(argv[1]) }; - - auto application = Application::getInstance(); - - application->setNodeName( "polysync-log-session-export-cpp" ); - - application->connectPolySync(); } diff --git a/LogSessionExport/LogSessionExport.hpp b/LogSessionExport/LogSessionExport.hpp new file mode 100644 index 0000000..7abcc74 --- /dev/null +++ b/LogSessionExport/LogSessionExport.hpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 HARBRICK TECHNOLOGIES, INC + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/** + * \example LogSessionExport.hpp + * + * Log session export example. + * + * Demonstrates how to use the PolySync log session transfer API to export a previously + * recorded log session from a new distributed system. + * + */ + +#ifndef LOGSESSIONEXPORT_HPP +#define LOGSESSIONEXPORT_HPP + + +#include +#include + + +class SessionExportExample : public polysync::DataSubscriber +{ + +public: + + SessionExportExample( + int sessionId, const std::string & sessionPath = {} ); + + ~SessionExportExample(){ std::cout << "dtor" << std::endl; } +private: + + void handleEvent( std::shared_ptr< polysync::Message > message ); + + void handleTransferStatus( + const polysync::LogSessionTransferState state, + const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & ); + + const ps_rnr_session_id _sessionId; + + const std::string & _sessionPath; + + std::unique_ptr< polysync::LogSessionExport > _exporter; + +}; + + +#endif // LOGSESSIONEXPORT_HPP + diff --git a/LogSessionExport/main.cpp b/LogSessionExport/main.cpp new file mode 100644 index 0000000..c4cdda6 --- /dev/null +++ b/LogSessionExport/main.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 PolySync + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include + +#include + +#include "LogSessionExport.hpp" + + +int main( int argc, char * argv[] ) +{ + if( argc < 2 ) + { + std::cerr << "Usage: " << argv[0] << " [sessionId]" << std::endl; + return -1; + } + + auto sessionId = std::atoi( argv[1] ); + + std::unique_ptr< SessionExportExample > exportExample; + + if( sessionId != 0 ) + { + if( argc == 3 ) + { + exportExample = std::unique_ptr< SessionExportExample >{ + new SessionExportExample{ sessionId, argv[2] } }; + } + else + { + exportExample = std::unique_ptr< SessionExportExample >{ + new SessionExportExample{ sessionId } }; + } + } + + auto application = polysync::Application::getInstance(); + + application->setNodeName( "polysync-log-session-export-cpp" ); + + application->connectPolySync(); +} From 784f2dc554019ff7779e48977939bf93c922b4a5 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 24 Apr 2017 10:30:41 -0700 Subject: [PATCH 2/4] Update Harbrick to Polysync in the Copyright. --- LogSessionExport/LogSessionExport.cpp | 2 +- LogSessionExport/LogSessionExport.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LogSessionExport/LogSessionExport.cpp b/LogSessionExport/LogSessionExport.cpp index f77fe5e..e8008cd 100644 --- a/LogSessionExport/LogSessionExport.cpp +++ b/LogSessionExport/LogSessionExport.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 HARBRICK TECHNOLOGIES, INC + * Copyright (c) 2015 PolySync * * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/LogSessionExport/LogSessionExport.hpp b/LogSessionExport/LogSessionExport.hpp index 7abcc74..e92db0e 100644 --- a/LogSessionExport/LogSessionExport.hpp +++ b/LogSessionExport/LogSessionExport.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 HARBRICK TECHNOLOGIES, INC + * Copyright (c) 2015 PolySync * * * Permission is hereby granted, free of charge, to any person obtaining a copy From 1f02e9a7a94c92b47c644ee12d603b79505f824c Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 25 Apr 2017 08:17:02 -0700 Subject: [PATCH 3/4] Remove unused destructor. --- LogSessionExport/LogSessionExport.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/LogSessionExport/LogSessionExport.hpp b/LogSessionExport/LogSessionExport.hpp index e92db0e..4094cf7 100644 --- a/LogSessionExport/LogSessionExport.hpp +++ b/LogSessionExport/LogSessionExport.hpp @@ -48,7 +48,6 @@ class SessionExportExample : public polysync::DataSubscriber SessionExportExample( int sessionId, const std::string & sessionPath = {} ); - ~SessionExportExample(){ std::cout << "dtor" << std::endl; } private: void handleEvent( std::shared_ptr< polysync::Message > message ); From 923e80c891151a87dcd3a98da515e8c0d41efdeb Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 27 Apr 2017 10:14:54 -0700 Subject: [PATCH 4/4] Change reference to actual string copy. --- LogSessionExport/LogSessionExport.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LogSessionExport/LogSessionExport.hpp b/LogSessionExport/LogSessionExport.hpp index 4094cf7..f43ea93 100644 --- a/LogSessionExport/LogSessionExport.hpp +++ b/LogSessionExport/LogSessionExport.hpp @@ -58,7 +58,7 @@ class SessionExportExample : public polysync::DataSubscriber const ps_rnr_session_id _sessionId; - const std::string & _sessionPath; + const std::string _sessionPath; std::unique_ptr< polysync::LogSessionExport > _exporter;