Skip to content

Commit 57adc64

Browse files
Merge pull request #66 from PolySync/fix/core-141-logsession-export-example-does-not-compile
Fix LogSessionExport compilation.
2 parents ada9dd8 + 923e80c commit 57adc64

File tree

4 files changed

+206
-95
lines changed

4 files changed

+206
-95
lines changed

LogSessionExport/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include_directories(
1818
)
1919

2020
add_executable( ${PROJECT_NAME}
21+
main.cpp
2122
LogSessionExport.cpp
2223
)
2324

Lines changed: 73 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 HARBRICK TECHNOLOGIES, INC
2+
* Copyright (c) 2015 PolySync
33
*
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,115 +22,93 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
26-
/**
27-
* \example LogSessionExport.cpp
28-
*
29-
* Log session export example.
30-
*
31-
* Demonstrates how to use the PolySync log session transfer API to export a previously
32-
* recorded log session from a new distributed system.
33-
*
34-
*/
35-
3625
#include <iostream>
26+
27+
#include <PolySyncApplication.hpp>
3728
#include <PolySyncCore.hpp>
3829
#include <PolySyncDataModel.hpp>
39-
#include <PolySyncApplication.hpp>
40-
#include <PolySyncLogSessionTransfer.hpp>
4130

42-
using namespace std;
43-
using namespace polysync;
44-
using namespace datamodel;
31+
#include "LogSessionExport.hpp"
4532

46-
/**
47-
* @brief SessionExportExample class
48-
*/
49-
class SessionExportExample : public DataSubscriber
50-
{
51-
52-
public:
53-
54-
SessionExportExample(
55-
int sessionId )
56-
:
57-
_sessionId( sessionId )
58-
{
59-
// Subscribe to ApplicationEventMessage to determine when
60-
// the application connects to the PolySync bus.
61-
connectSubscriberMethod< SessionExportExample >(
62-
ApplicationEventMessage::getName(),
63-
&SessionExportExample::handleEvent,
64-
this );
65-
66-
_application = Application::getInstance();
6733

68-
_application->attachSubscriber( this );
69-
}
70-
71-
private:
72-
73-
void handleEvent( shared_ptr< Message > message )
74-
{
75-
if( auto event = getSubclass< ApplicationEventMessage >( message ) )
76-
{
77-
if( event->getEventKind() == EventKind::Init )
78-
{
79-
// This is the actual usage of the export API.
80-
_exporter = new LogSessionExport( _sessionId );
34+
SessionExportExample::SessionExportExample(
35+
int sessionId,
36+
const std::string & sessionPath )
37+
:
38+
_sessionId( sessionId ),
39+
_sessionPath( sessionPath ),
40+
_exporter()
41+
{
42+
// Subscribe to ApplicationEventMessage to determine when
43+
// the application connects to the PolySync bus.
44+
connectSubscriberMethod< SessionExportExample >(
45+
polysync::ApplicationEventMessage::getName(),
46+
&SessionExportExample::handleEvent,
47+
this );
48+
49+
polysync::Application::getInstance()->attachSubscriber( this );
50+
}
8151

82-
// Export can be started with or without a progress callback.
83-
// When complete, results will be located at "PSYNC_HOME/rnr_logs/export/[sessionId]"
84-
_exporter->start(
85-
this,
86-
&SessionExportExample::handleTransferStatus );
87-
}
88-
}
89-
}
9052

91-
void handleTransferStatus(
92-
const LogSessionTransferStatus & status )
53+
void SessionExportExample::handleEvent(
54+
std::shared_ptr< polysync::Message > message )
55+
{
56+
if( auto event = polysync::datamodel::getSubclass<
57+
polysync::ApplicationEventMessage >( message ) )
9358
{
94-
// Status has other information available as well
95-
auto state = status.getState();
96-
97-
cout << "State: ";
98-
99-
switch( state )
59+
if( event->getEventKind() == polysync::EventKind::Init )
10060
{
101-
case LogSessionTransferState::Invalid : cout << "Invalid" << endl; break;
102-
case LogSessionTransferState::Error : cout << "Error" << endl; break;
103-
case LogSessionTransferState::Initial : cout << "Initial" << endl; break;
104-
case LogSessionTransferState::Enumeration : cout << "Enumeration" << endl; break;
105-
case LogSessionTransferState::TransferringSystemFiles : cout << "TransferringSystemFiles" << endl; break;
106-
case LogSessionTransferState::TransformingSystemFile : cout << "TransformingSystemFile" << endl; break;
107-
case LogSessionTransferState::TransferringLogfiles : cout << "TransferringLogfiles" << endl; break;
108-
case LogSessionTransferState::Complete : cout << "Complete" << endl; _application->disconnectPolySync(); break;
61+
// This is the actual usage of the export API.
62+
_exporter = std::unique_ptr< polysync::LogSessionExport >{
63+
new polysync::LogSessionExport{
64+
_sessionId, _sessionPath } };
65+
66+
// Export can be started with or without a progress callback.
67+
// When complete, results will be located at
68+
// "PSYNC_HOME/rnr_logs/export/[sessionId]"
69+
_exporter->start(
70+
this,
71+
&SessionExportExample::handleTransferStatus );
10972
}
11073
}
111-
112-
int _sessionId;
113-
114-
LogSessionExport * _exporter;
115-
116-
Application * _application;
117-
118-
};
74+
}
11975

12076

121-
int main( int argc, char ** argv )
77+
void SessionExportExample::handleTransferStatus(
78+
const polysync::LogSessionTransferState state,
79+
const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & )
12280
{
123-
if( argc != 2 )
81+
std::cout << "State: ";
82+
83+
switch( state )
12484
{
125-
cerr << "Usage: " << argv[0] << " [sessionId]" << endl;
126-
return -1;
85+
case polysync::LogSessionTransferState::Invalid:
86+
std::cout << "Invalid" << std::endl;
87+
break;
88+
case polysync::LogSessionTransferState::Error:
89+
std::cout << "Error" << std::endl;
90+
break;
91+
case polysync::LogSessionTransferState::Initial:
92+
std::cout << "Initial" << std::endl;
93+
break;
94+
case polysync::LogSessionTransferState::Enumeration:
95+
std::cout << "Enumeration" << std::endl;
96+
break;
97+
case polysync::LogSessionTransferState::TransferringSystemFiles:
98+
std::cout << "TransferringSystemFiles" << std::endl;
99+
break;
100+
case polysync::LogSessionTransferState::TransformingSystemFile:
101+
std::cout << "TransformingSystemFile" << std::endl;
102+
break;
103+
case polysync::LogSessionTransferState::TransferringLogfiles:
104+
std::cout << "TransferringLogfiles" << std::endl;
105+
break;
106+
case polysync::LogSessionTransferState::Complete:
107+
std::cout << "Complete" << std::endl;
108+
polysync::Application::getInstance()->disconnectPolySync();
109+
break;
110+
default:
111+
std::cout << "Unknown polysync::LogSessionTransferState"
112+
<< std::endl;
127113
}
128-
129-
SessionExportExample exportExample{ atoi(argv[1]) };
130-
131-
auto application = Application::getInstance();
132-
133-
application->setNodeName( "polysync-log-session-export-cpp" );
134-
135-
application->connectPolySync();
136114
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2015 PolySync
3+
*
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
/**
26+
* \example LogSessionExport.hpp
27+
*
28+
* Log session export example.
29+
*
30+
* Demonstrates how to use the PolySync log session transfer API to export a previously
31+
* recorded log session from a new distributed system.
32+
*
33+
*/
34+
35+
#ifndef LOGSESSIONEXPORT_HPP
36+
#define LOGSESSIONEXPORT_HPP
37+
38+
39+
#include <PolySyncLogSessionTransfer.hpp>
40+
#include <PolySyncDataSubscriber.hpp>
41+
42+
43+
class SessionExportExample : public polysync::DataSubscriber
44+
{
45+
46+
public:
47+
48+
SessionExportExample(
49+
int sessionId, const std::string & sessionPath = {} );
50+
51+
private:
52+
53+
void handleEvent( std::shared_ptr< polysync::Message > message );
54+
55+
void handleTransferStatus(
56+
const polysync::LogSessionTransferState state,
57+
const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & );
58+
59+
const ps_rnr_session_id _sessionId;
60+
61+
const std::string _sessionPath;
62+
63+
std::unique_ptr< polysync::LogSessionExport > _exporter;
64+
65+
};
66+
67+
68+
#endif // LOGSESSIONEXPORT_HPP
69+

LogSessionExport/main.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2015 PolySync
3+
*
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
#include <iostream>
26+
27+
#include <PolySyncApplication.hpp>
28+
29+
#include "LogSessionExport.hpp"
30+
31+
32+
int main( int argc, char * argv[] )
33+
{
34+
if( argc < 2 )
35+
{
36+
std::cerr << "Usage: " << argv[0] << " [sessionId]" << std::endl;
37+
return -1;
38+
}
39+
40+
auto sessionId = std::atoi( argv[1] );
41+
42+
std::unique_ptr< SessionExportExample > exportExample;
43+
44+
if( sessionId != 0 )
45+
{
46+
if( argc == 3 )
47+
{
48+
exportExample = std::unique_ptr< SessionExportExample >{
49+
new SessionExportExample{ sessionId, argv[2] } };
50+
}
51+
else
52+
{
53+
exportExample = std::unique_ptr< SessionExportExample >{
54+
new SessionExportExample{ sessionId } };
55+
}
56+
}
57+
58+
auto application = polysync::Application::getInstance();
59+
60+
application->setNodeName( "polysync-log-session-export-cpp" );
61+
62+
application->connectPolySync();
63+
}

0 commit comments

Comments
 (0)