From 1ad9a75719ef93490f0a81458e0a489be08688c4 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 21 Apr 2017 16:03:32 -0700 Subject: [PATCH 1/3] Fix compilation. Prior commit did not compile because it was using outdated features in the C++ API. This commit updates these features to compile. Additional work is still required in the C++ API to achieve full functionality for this example. --- LogSessionImport/CMakeLists.txt | 1 + LogSessionImport/LogSessionImport.cpp | 218 ++++++++++---------------- LogSessionImport/LogSessionImport.hpp | 71 +++++++++ LogSessionImport/main.cpp | 23 +++ 4 files changed, 182 insertions(+), 131 deletions(-) create mode 100644 LogSessionImport/LogSessionImport.hpp create mode 100644 LogSessionImport/main.cpp diff --git a/LogSessionImport/CMakeLists.txt b/LogSessionImport/CMakeLists.txt index 14f79cb..4c0fea3 100644 --- a/LogSessionImport/CMakeLists.txt +++ b/LogSessionImport/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories( ) add_executable( ${PROJECT_NAME} + main.cpp LogSessionImport.cpp ) diff --git a/LogSessionImport/LogSessionImport.cpp b/LogSessionImport/LogSessionImport.cpp index 18f3e59..5279321 100644 --- a/LogSessionImport/LogSessionImport.cpp +++ b/LogSessionImport/LogSessionImport.cpp @@ -22,156 +22,112 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -/** - * \example LogSessionImport.cpp - * - * Log session import example. - * - * Demonstrates how to use the PolySync log session transfer API to import a previously - * exported log session to a new distributed system. - * - */ - -#include - -#include -#include #include -#include +#include +#include "LogSessionImport.hpp" -using namespace std; -using namespace polysync; -using namespace datamodel; -/** - * @brief SessionImportExample class - */ -class SessionImportExample : public DataSubscriber +SessionImportExample::SessionImportExample( const std::string & sessionPath ) + : + _sessionPath( sessionPath ), + _importer() { + // Subscribe to ApplicationEventMessage to determine when + // the application connects to the PolySync bus. + connectSubscriberMethod< SessionImportExample >( + polysync::ApplicationEventMessage::getName(), + &SessionImportExample::handleEvent, + this ); + + polysync::Application::getInstance()->attachSubscriber( this ); +} -public: - SessionImportExample( int sessionId ) - : - _sessionId( sessionId ) +void SessionImportExample::handleEvent( + std::shared_ptr< polysync::Message > message ) +{ + if( auto event = polysync::datamodel::getSubclass< + polysync::ApplicationEventMessage >( message ) ) { - // Subscribe to ApplicationEventMessage to determine when - // the application connects to the PolySync bus. - connectSubscriberMethod< SessionImportExample >( - ApplicationEventMessage::getName(), - &SessionImportExample::handleEvent, - this ); - - _application = Application::getInstance(); - - _application->attachSubscriber( this ); - } - - -private: + auto eventKind = event->getEventKind(); - void handleEvent( shared_ptr< Message > message ) - { - if( auto event = getSubclass< ApplicationEventMessage >( message ) ) + if( eventKind == polysync::EventKind::Init ) { - if( event->getEventKind() == EventKind::Init ) + // This is the actual usage of the import API. + _importer = std::unique_ptr< polysync::LogSessionImport >{ + new polysync::LogSessionImport( _sessionPath ) }; + + // + // Assign imported nodes to new destination host. + // + + // Destination hosts are specified using 'LogSessionTransferTarget'. + // The import API requires the transfer target to provide one of + // the following: + // * Interface Address String ("127.0.0.1") + // * Manager GUID (562950866709306) + // * Host's Id in the SDF + polysync::LogSessionTransferTarget transferTarget; + + for( const auto & availableNode : _importer->getAvailableNodes() ) { - // This is the actual usage of the import API. - _importer = new LogSessionImport( _sessionId ); - - // - // Assign imported nodes to new destination host. - // - - // Destination hosts are specified using 'LogSessionTransferTarget'. - // The import API requires the transfer target to provide one of the following: - // * Interface Address String ("127.0.0.1") - // * Manager GUID (562950866709306) - // * Host's Id in the SDF - LogSessionTransferTarget transferTarget; - - for( const auto & availableNode : _importer->getAvailableNodes() ) - { - cout << "assigning " << availableNode.getName() << " to 127.0.0.1" << endl; - - transferTarget.setInterfaceAddress("127.0.0.1"); - - _importer->updateNodeTarget( - transferTarget, - availableNode ); - } - - // Import can be started with or without a progress callback. - // When complete, results will be located at "PSYNC_HOME/rnr_logs/[sessionId]" - _importer->start( - this, - &SessionImportExample::handleTransferStatus ); - } - } - } + std::cout << "assigning " + << availableNode.getName() + << " to 127.0.0.1" << std::endl; + transferTarget.setInterfaceAddress("127.0.0.1"); - void handleTransferStatus( - const LogSessionTransferStatus & status ) - { - // Status has other information available as well - auto state = status.getState(); - - cout << "State: "; + _importer->updateNodeTarget( + transferTarget, + availableNode ); + } - switch( state ) - { - 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; + // Import can be started with or without a progress callback. + // When complete, results will be located at + // "PSYNC_HOME/rnr_logs/[sessionId]" + _importer->start( + this, + &SessionImportExample::handleTransferStatus ); } } - - int _sessionId; - - LogSessionImport * _importer; - - Application * _application; -}; +} -int main( int argc, char ** argv ) +void SessionImportExample::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" << std::endl; } - - SessionImportExample importExample{ atoi( argv[ 1 ] ) }; - - auto application = Application::getInstance(); - - application->setNodeName( "polysync-log-session-import-cpp" ); - - application->connectPolySync(); } diff --git a/LogSessionImport/LogSessionImport.hpp b/LogSessionImport/LogSessionImport.hpp new file mode 100644 index 0000000..990329e --- /dev/null +++ b/LogSessionImport/LogSessionImport.hpp @@ -0,0 +1,71 @@ +/* + * 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 LogSessionImport.hpp + * + * Log session import example. + * + * Demonstrates how to use the PolySync log session transfer API to import a previously + * exported log session to a new distributed system. + * + */ + +#ifndef LOGSESSIONIMPORT_HPP +#define LOGSESSIONIMPORT_HPP + + +#include +#include + +#include "LogSessionImport.hpp" + + +class SessionImportExample : public polysync::DataSubscriber +{ + +public: + + SessionImportExample( const std::string & sessionPath ); + + +private: + + void handleEvent( std::shared_ptr< polysync::Message > message ); + + void handleTransferStatus( + const polysync::LogSessionTransferState status, + const std::shared_ptr< + polysync::datamodel::FileSyncStatusMessage > & statusMsg); + + const std::string _sessionPath; + + std::unique_ptr< polysync::LogSessionImport > _importer; + +}; + + +#endif // LOGSESSIONIMPORT_HPP + diff --git a/LogSessionImport/main.cpp b/LogSessionImport/main.cpp new file mode 100644 index 0000000..11d6e1a --- /dev/null +++ b/LogSessionImport/main.cpp @@ -0,0 +1,23 @@ +#include + +#include + +#include "LogSessionImport.hpp" + + +int main( int argc, char * argv[] ) +{ + if( argc != 2 ) + { + std::cerr << "Usage: " << argv[ 0 ] << " [sessionId]" << std::endl; + return -1; + } + + SessionImportExample importExample{ argv[ 1 ] }; + + auto application = polysync::Application::getInstance(); + + application->setNodeName( "polysync-log-session-import-cpp" ); + + application->connectPolySync(); +} From fc6cf9bef9fa14731f647d4d611ae011efc7f2b3 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 24 Apr 2017 07:32:45 -0700 Subject: [PATCH 2/3] Git ignore CMakeLists.txt.user. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 567609b..57b1a30 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +*txt.user From 47e4cf7569de5a7f8d38bc4ea0873d8576bd6ddd Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 24 Apr 2017 10:32:50 -0700 Subject: [PATCH 3/3] Update copyright statements Harbrick -> PolySync. --- LogSessionImport/LogSessionImport.cpp | 2 +- LogSessionImport/LogSessionImport.hpp | 2 +- LogSessionImport/main.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/LogSessionImport/LogSessionImport.cpp b/LogSessionImport/LogSessionImport.cpp index 5279321..c02079a 100644 --- a/LogSessionImport/LogSessionImport.cpp +++ b/LogSessionImport/LogSessionImport.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/LogSessionImport/LogSessionImport.hpp b/LogSessionImport/LogSessionImport.hpp index 990329e..487b195 100644 --- a/LogSessionImport/LogSessionImport.hpp +++ b/LogSessionImport/LogSessionImport.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 diff --git a/LogSessionImport/main.cpp b/LogSessionImport/main.cpp index 11d6e1a..c97aaf0 100644 --- a/LogSessionImport/main.cpp +++ b/LogSessionImport/main.cpp @@ -1,3 +1,27 @@ +/* + * 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