Skip to content

Update import/export example logic #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions LogSessionExport/LogSessionExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@


SessionExportExample::SessionExportExample(
int sessionId,
ps_rnr_session_id sessionId,
const std::string & sessionPath )
:
_sessionId( sessionId ),
_sessionPath( sessionPath ),
_exporter()
_exporter(),
_transferComplete( false )
{
// Subscribe to ApplicationEventMessage to determine when
// the application connects to the PolySync bus.
Expand All @@ -56,7 +57,9 @@ void SessionExportExample::handleEvent(
if( auto event = polysync::datamodel::getSubclass<
polysync::ApplicationEventMessage >( message ) )
{
if( event->getEventKind() == polysync::EventKind::Init )
auto eventKind = event->getEventKind();

if( eventKind == polysync::EventKind::Init )
{
// This is the actual usage of the export API.
_exporter = std::unique_ptr< polysync::LogSessionExport >{
Expand All @@ -70,6 +73,11 @@ void SessionExportExample::handleEvent(
this,
&SessionExportExample::handleTransferStatus );
}
else if( eventKind == polysync::EventKind::Ok and _transferComplete )
{
_exporter.reset();
polysync::Application::getInstance()->disconnectPolySync();
}
}
}

Expand All @@ -87,6 +95,7 @@ void SessionExportExample::handleTransferStatus(
break;
case polysync::LogSessionTransferState::Error:
std::cout << "Error" << std::endl;
polysync::Application::getInstance()->disconnectPolySync();
break;
case polysync::LogSessionTransferState::Initial:
std::cout << "Initial" << std::endl;
Expand All @@ -104,11 +113,11 @@ void SessionExportExample::handleTransferStatus(
std::cout << "TransferringLogfiles" << std::endl;
break;
case polysync::LogSessionTransferState::Complete:
std::cout << "Complete" << std::endl;
polysync::Application::getInstance()->disconnectPolySync();
std::cout << "Complete" << std::endl;
_transferComplete = true;
break;
default:
std::cout << "Unknown polysync::LogSessionTransferState"
<< std::endl;
<< std::endl;
}
}
4 changes: 3 additions & 1 deletion LogSessionExport/LogSessionExport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class SessionExportExample : public polysync::DataSubscriber
public:

SessionExportExample(
int sessionId, const std::string & sessionPath = {} );
ps_rnr_session_id sessionId,
const std::string & sessionPath = {} );

private:

Expand All @@ -62,6 +63,7 @@ class SessionExportExample : public polysync::DataSubscriber

std::unique_ptr< polysync::LogSessionExport > _exporter;

bool _transferComplete;
};


Expand Down
2 changes: 1 addition & 1 deletion LogSessionExport/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main( int argc, char * argv[] )
return -1;
}

auto sessionId = std::atoi( argv[1] );
auto sessionId = std::stoull( argv[1] );

std::unique_ptr< SessionExportExample > exportExample;

Expand Down
11 changes: 9 additions & 2 deletions LogSessionImport/LogSessionImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
SessionImportExample::SessionImportExample( const std::string & sessionPath )
:
_sessionPath( sessionPath ),
_importer()
_importer(),
_transferComplete( false )
{
// Subscribe to ApplicationEventMessage to determine when
// the application connects to the PolySync bus.
Expand Down Expand Up @@ -90,6 +91,11 @@ void SessionImportExample::handleEvent(
this,
&SessionImportExample::handleTransferStatus );
}
else if( eventKind == polysync::EventKind::Ok && _transferComplete )
{
_importer.reset();
polysync::Application::getInstance()->disconnectPolySync();
}
}
}

Expand All @@ -107,6 +113,7 @@ void SessionImportExample::handleTransferStatus(
break;
case polysync::LogSessionTransferState::Error :
std::cout << "Error" << std::endl;
polysync::Application::getInstance()->disconnectPolySync();
break;
case polysync::LogSessionTransferState::Initial :
std::cout << "Initial" << std::endl;
Expand All @@ -125,7 +132,7 @@ void SessionImportExample::handleTransferStatus(
break;
case polysync::LogSessionTransferState::Complete :
std::cout << "Complete" << std::endl;
polysync::Application::getInstance()->disconnectPolySync();
_transferComplete = true;
break;
default:
std::cout << "Unknown" << std::endl;
Expand Down
3 changes: 2 additions & 1 deletion LogSessionImport/LogSessionImport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class SessionImportExample : public polysync::DataSubscriber
const std::string _sessionPath;

std::unique_ptr< polysync::LogSessionImport > _importer;


bool _transferComplete;
};


Expand Down