|
1 | 1 | /* |
2 | | - * Copyright (c) 2015 HARBRICK TECHNOLOGIES, INC |
| 2 | + * Copyright (c) 2015 PolySync |
3 | 3 | * |
4 | 4 | * |
5 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
22 | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | 23 | * THE SOFTWARE. |
24 | 24 | */ |
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 | | - |
36 | 25 | #include <iostream> |
| 26 | + |
| 27 | +#include <PolySyncApplication.hpp> |
37 | 28 | #include <PolySyncCore.hpp> |
38 | 29 | #include <PolySyncDataModel.hpp> |
39 | | -#include <PolySyncApplication.hpp> |
40 | | -#include <PolySyncLogSessionTransfer.hpp> |
41 | 30 |
|
42 | | -using namespace std; |
43 | | -using namespace polysync; |
44 | | -using namespace datamodel; |
| 31 | +#include "LogSessionExport.hpp" |
45 | 32 |
|
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(); |
67 | 33 |
|
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 | +} |
81 | 51 |
|
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 | | - } |
90 | 52 |
|
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 ) ) |
93 | 58 | { |
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 ) |
100 | 60 | { |
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 ); |
109 | 72 | } |
110 | 73 | } |
111 | | - |
112 | | - int _sessionId; |
113 | | - |
114 | | - LogSessionExport * _exporter; |
115 | | - |
116 | | - Application * _application; |
117 | | - |
118 | | -}; |
| 74 | +} |
119 | 75 |
|
120 | 76 |
|
121 | | -int main( int argc, char ** argv ) |
| 77 | +void SessionExportExample::handleTransferStatus( |
| 78 | + const polysync::LogSessionTransferState state, |
| 79 | + const std::shared_ptr< polysync::datamodel::FileSyncStatusMessage > & ) |
122 | 80 | { |
123 | | - if( argc != 2 ) |
| 81 | + std::cout << "State: "; |
| 82 | + |
| 83 | + switch( state ) |
124 | 84 | { |
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; |
127 | 113 | } |
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(); |
136 | 114 | } |
0 commit comments