Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp (1 of 8 files). Show all
Unified · Split
| @@ -34,7 +34,7 @@ using namespace GSF; · 33 unmodified lines | |||
| 34 | using namespace GSF::TimeSeries; | 34 | using namespace GSF::TimeSeries; |
| 35 | using namespace GSF::TimeSeries::Transport; | 35 | using namespace GSF::TimeSeries::Transport; |
| 36 | 36 | ||
| 37 | DataSubscriber Subscriber; | 37 | DataSubscriber* Subscriber; |
| 38 | 38 | ||
| 39 | bool RunSubscriber(const string& hostname, uint16_t port); | 39 | bool RunSubscriber(const string& hostname, uint16_t port); |
| 40 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements); | 40 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements); |
| @@ -68,6 +68,9 @@ int main(int argc, char* argv[]) · 27 unmodified lines | |||
| 68 | hostname = argv[1]; | 68 | hostname = argv[1]; |
| 69 | stringstream(argv[2]) >> port; | 69 | stringstream(argv[2]) >> port; |
| 70 | 70 | ||
| 71 | // Maintain the life-time of DataSubscriber within main | ||
| 72 | Subscriber = new DataSubscriber(); | ||
| 73 | |||
| 71 | // Run the subscriber. | 74 | // Run the subscriber. |
| 72 | if (RunSubscriber(hostname, port)) | 75 | if (RunSubscriber(hostname, port)) |
| 73 | { | 76 | { |
| @@ -77,9 +80,11 @@ int main(int argc, char* argv[]) · 3 unmodified lines | |||
| 77 | } | 80 | } |
| 78 | 81 | ||
| 79 | // Disconnect the subscriber to stop background threads. | 82 | // Disconnect the subscriber to stop background threads. |
| 80 | Subscriber.Disconnect(); | 83 | Subscriber->Disconnect(); |
| 81 | cout << "Disconnected." << endl; | 84 | cout << "Disconnected." << endl; |
| 82 | 85 | ||
| 86 | delete Subscriber; | ||
| 87 | |||
| 83 | return 0; | 88 | return 0; |
| 84 | } | 89 | } |
| 85 | 90 | ||
| @@ -96,9 +101,9 @@ bool RunSubscriber(const string& hostname, uint16_t port) · 10 unmodified lines | |||
| 96 | info.FilterExpression = "PPA:1;PPA:2;PPA:3;PPA:4;PPA:5;PPA:6;PPA:7;PPA:8;PPA:9;PPA:10;PPA:11;PPA:12;PPA:13;PPA:14"; | 101 | info.FilterExpression = "PPA:1;PPA:2;PPA:3;PPA:4;PPA:5;PPA:6;PPA:7;PPA:8;PPA:9;PPA:10;PPA:11;PPA:12;PPA:13;PPA:14"; |
| 97 | 102 | ||
| 98 | // Register callbacks | 103 | // Register callbacks |
| 99 | Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage); | 104 | Subscriber->RegisterStatusMessageCallback(&DisplayStatusMessage); |
| 100 | Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage); | 105 | Subscriber->RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 101 | Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements); | 106 | Subscriber->RegisterNewMeasurementsCallback(&ProcessMeasurements); |
| 102 | 107 | ||
| 103 | cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl; | 108 | cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl; |
| 104 | 109 | ||
| @@ -107,7 +112,7 @@ bool RunSubscriber(const string& hostname, uint16_t port) · 2 unmodified lines | |||
| 107 | 112 | ||
| 108 | try | 113 | try |
| 109 | { | 114 | { |
| 110 | Subscriber.Connect(hostname, port); | 115 | Subscriber->Connect(hostname, port); |
| 111 | connected = true; | 116 | connected = true; |
| 112 | } | 117 | } |
| 113 | catch (SubscriberException& ex) | 118 | catch (SubscriberException& ex) |
| @@ -126,7 +131,7 @@ bool RunSubscriber(const string& hostname, uint16_t port) · 12 unmodified lines | |||
| 126 | if (connected) | 131 | if (connected) |
| 127 | { | 132 | { |
| 128 | cout << "Connected! Subscribing to data..." << endl << endl; | 133 | cout << "Connected! Subscribing to data..." << endl << endl; |
| 129 | Subscriber.Subscribe(info); | 134 | Subscriber->Subscribe(info); |
| 130 | } | 135 | } |
| 131 | else | 136 | else |
| 132 | { | 137 | { |