Skip to content

Commit ada9dd8

Browse files
dmiller-polysyncLyle Johnson
authored andcommitted
Fix/core 140 logsession import does not compile (#65)
* 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. * Git ignore CMakeLists.txt.user. * Update copyright statements Harbrick -> PolySync.
1 parent 2e00fda commit ada9dd8

File tree

5 files changed

+208
-132
lines changed

5 files changed

+208
-132
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build/
2+
*txt.user

LogSessionImport/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
LogSessionImport.cpp
2223
)
2324

Lines changed: 88 additions & 132 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,156 +22,112 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25-
26-
/**
27-
* \example LogSessionImport.cpp
28-
*
29-
* Log session import example.
30-
*
31-
* Demonstrates how to use the PolySync log session transfer API to import a previously
32-
* exported log session to a new distributed system.
33-
*
34-
*/
35-
36-
#include <iostream>
37-
38-
#include <PolySyncCore.hpp>
39-
#include <PolySyncDataModel.hpp>
4025
#include <PolySyncApplication.hpp>
41-
#include <PolySyncLogSessionTransfer.hpp>
26+
#include <PolySyncDataModel.hpp>
4227

28+
#include "LogSessionImport.hpp"
4329

44-
using namespace std;
45-
using namespace polysync;
46-
using namespace datamodel;
4730

48-
/**
49-
* @brief SessionImportExample class
50-
*/
51-
class SessionImportExample : public DataSubscriber
31+
SessionImportExample::SessionImportExample( const std::string & sessionPath )
32+
:
33+
_sessionPath( sessionPath ),
34+
_importer()
5235
{
36+
// Subscribe to ApplicationEventMessage to determine when
37+
// the application connects to the PolySync bus.
38+
connectSubscriberMethod< SessionImportExample >(
39+
polysync::ApplicationEventMessage::getName(),
40+
&SessionImportExample::handleEvent,
41+
this );
42+
43+
polysync::Application::getInstance()->attachSubscriber( this );
44+
}
5345

54-
public:
5546

56-
SessionImportExample( int sessionId )
57-
:
58-
_sessionId( sessionId )
47+
void SessionImportExample::handleEvent(
48+
std::shared_ptr< polysync::Message > message )
49+
{
50+
if( auto event = polysync::datamodel::getSubclass<
51+
polysync::ApplicationEventMessage >( message ) )
5952
{
60-
// Subscribe to ApplicationEventMessage to determine when
61-
// the application connects to the PolySync bus.
62-
connectSubscriberMethod< SessionImportExample >(
63-
ApplicationEventMessage::getName(),
64-
&SessionImportExample::handleEvent,
65-
this );
66-
67-
_application = Application::getInstance();
68-
69-
_application->attachSubscriber( this );
70-
}
71-
72-
73-
private:
53+
auto eventKind = event->getEventKind();
7454

75-
void handleEvent( shared_ptr< Message > message )
76-
{
77-
if( auto event = getSubclass< ApplicationEventMessage >( message ) )
55+
if( eventKind == polysync::EventKind::Init )
7856
{
79-
if( event->getEventKind() == EventKind::Init )
57+
// This is the actual usage of the import API.
58+
_importer = std::unique_ptr< polysync::LogSessionImport >{
59+
new polysync::LogSessionImport( _sessionPath ) };
60+
61+
//
62+
// Assign imported nodes to new destination host.
63+
//
64+
65+
// Destination hosts are specified using 'LogSessionTransferTarget'.
66+
// The import API requires the transfer target to provide one of
67+
// the following:
68+
// * Interface Address String ("127.0.0.1")
69+
// * Manager GUID (562950866709306)
70+
// * Host's Id in the SDF
71+
polysync::LogSessionTransferTarget transferTarget;
72+
73+
for( const auto & availableNode : _importer->getAvailableNodes() )
8074
{
81-
// This is the actual usage of the import API.
82-
_importer = new LogSessionImport( _sessionId );
83-
84-
//
85-
// Assign imported nodes to new destination host.
86-
//
87-
88-
// Destination hosts are specified using 'LogSessionTransferTarget'.
89-
// The import API requires the transfer target to provide one of the following:
90-
// * Interface Address String ("127.0.0.1")
91-
// * Manager GUID (562950866709306)
92-
// * Host's Id in the SDF
93-
LogSessionTransferTarget transferTarget;
94-
95-
for( const auto & availableNode : _importer->getAvailableNodes() )
96-
{
97-
cout << "assigning " << availableNode.getName() << " to 127.0.0.1" << endl;
98-
99-
transferTarget.setInterfaceAddress("127.0.0.1");
100-
101-
_importer->updateNodeTarget(
102-
transferTarget,
103-
availableNode );
104-
}
105-
106-
// Import can be started with or without a progress callback.
107-
// When complete, results will be located at "PSYNC_HOME/rnr_logs/[sessionId]"
108-
_importer->start(
109-
this,
110-
&SessionImportExample::handleTransferStatus );
111-
}
112-
}
113-
}
75+
std::cout << "assigning "
76+
<< availableNode.getName()
77+
<< " to 127.0.0.1" << std::endl;
11478

79+
transferTarget.setInterfaceAddress("127.0.0.1");
11580

116-
void handleTransferStatus(
117-
const LogSessionTransferStatus & status )
118-
{
119-
// Status has other information available as well
120-
auto state = status.getState();
121-
122-
cout << "State: ";
81+
_importer->updateNodeTarget(
82+
transferTarget,
83+
availableNode );
84+
}
12385

124-
switch( state )
125-
{
126-
case LogSessionTransferState::Invalid :
127-
cout << "Invalid" << endl;
128-
break;
129-
case LogSessionTransferState::Error :
130-
cout << "Error" << endl;
131-
break;
132-
case LogSessionTransferState::Initial :
133-
cout << "Initial" << endl;
134-
break;
135-
case LogSessionTransferState::Enumeration :
136-
cout << "Enumeration" << endl;
137-
break;
138-
case LogSessionTransferState::TransferringSystemFiles :
139-
cout << "TransferringSystemFiles" << endl;
140-
break;
141-
case LogSessionTransferState::TransformingSystemFile :
142-
cout << "TransformingSystemFile" << endl;
143-
break;
144-
case LogSessionTransferState::TransferringLogfiles :
145-
cout << "TransferringLogfiles" << endl;
146-
break;
147-
case LogSessionTransferState::Complete :
148-
cout << "Complete" << endl;
149-
_application->disconnectPolySync();
150-
break;
86+
// Import can be started with or without a progress callback.
87+
// When complete, results will be located at
88+
// "PSYNC_HOME/rnr_logs/[sessionId]"
89+
_importer->start(
90+
this,
91+
&SessionImportExample::handleTransferStatus );
15192
}
15293
}
153-
154-
int _sessionId;
155-
156-
LogSessionImport * _importer;
157-
158-
Application * _application;
159-
};
94+
}
16095

16196

162-
int main( int argc, char ** argv )
97+
void SessionImportExample::handleTransferStatus(
98+
const polysync::LogSessionTransferState state,
99+
const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & )
163100
{
164-
if( argc != 2 )
101+
std::cout << "State: ";
102+
103+
switch( state )
165104
{
166-
cerr << "Usage: " << argv[ 0 ] << " [sessionId]" << endl;
167-
return -1;
105+
case polysync::LogSessionTransferState::Invalid :
106+
std::cout << "Invalid" << std::endl;
107+
break;
108+
case polysync::LogSessionTransferState::Error :
109+
std::cout << "Error" << std::endl;
110+
break;
111+
case polysync::LogSessionTransferState::Initial :
112+
std::cout << "Initial" << std::endl;
113+
break;
114+
case polysync::LogSessionTransferState::Enumeration :
115+
std::cout << "Enumeration" << std::endl;
116+
break;
117+
case polysync::LogSessionTransferState::TransferringSystemFiles :
118+
std::cout << "TransferringSystemFiles" << std::endl;
119+
break;
120+
case polysync::LogSessionTransferState::TransformingSystemFile :
121+
std::cout << "TransformingSystemFile" << std::endl;
122+
break;
123+
case polysync::LogSessionTransferState::TransferringLogfiles :
124+
std::cout << "TransferringLogfiles" << std::endl;
125+
break;
126+
case polysync::LogSessionTransferState::Complete :
127+
std::cout << "Complete" << std::endl;
128+
polysync::Application::getInstance()->disconnectPolySync();
129+
break;
130+
default:
131+
std::cout << "Unknown" << std::endl;
168132
}
169-
170-
SessionImportExample importExample{ atoi( argv[ 1 ] ) };
171-
172-
auto application = Application::getInstance();
173-
174-
application->setNodeName( "polysync-log-session-import-cpp" );
175-
176-
application->connectPolySync();
177133
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
/**
27+
* \example LogSessionImport.hpp
28+
*
29+
* Log session import example.
30+
*
31+
* Demonstrates how to use the PolySync log session transfer API to import a previously
32+
* exported log session to a new distributed system.
33+
*
34+
*/
35+
36+
#ifndef LOGSESSIONIMPORT_HPP
37+
#define LOGSESSIONIMPORT_HPP
38+
39+
40+
#include <PolySyncDataSubscriber.hpp>
41+
#include <PolySyncLogSessionTransfer.hpp>
42+
43+
#include "LogSessionImport.hpp"
44+
45+
46+
class SessionImportExample : public polysync::DataSubscriber
47+
{
48+
49+
public:
50+
51+
SessionImportExample( const std::string & sessionPath );
52+
53+
54+
private:
55+
56+
void handleEvent( std::shared_ptr< polysync::Message > message );
57+
58+
void handleTransferStatus(
59+
const polysync::LogSessionTransferState status,
60+
const std::shared_ptr<
61+
polysync::datamodel::FileSyncStatusMessage > & statusMsg);
62+
63+
const std::string _sessionPath;
64+
65+
std::unique_ptr< polysync::LogSessionImport > _importer;
66+
67+
};
68+
69+
70+
#endif // LOGSESSIONIMPORT_HPP
71+

LogSessionImport/main.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 "LogSessionImport.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+
SessionImportExample importExample{ argv[ 1 ] };
41+
42+
auto application = polysync::Application::getInstance();
43+
44+
application->setNodeName( "polysync-log-session-import-cpp" );
45+
46+
application->connectPolySync();
47+
}

0 commit comments

Comments
 (0)