History

TimeSeriesPlatformLibrary: Updated samples to control DataSubscriber lifetimes within main function to accommodate desired order-of-operations for standard function pointer destruction.

J. Ritchie Carroll committed 7 years ago

Commit 5bc9e1f1 parent b1a5c818 files · +66 −36Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp (1 of 8 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp+12−7
@@ -34,7 +34,7 @@ using namespace GSF; · 33 unmodified lines
34using namespace GSF::TimeSeries;34using namespace GSF::TimeSeries;
35using namespace GSF::TimeSeries::Transport;35using namespace GSF::TimeSeries::Transport;
36 36
37DataSubscriber Subscriber;37DataSubscriber* Subscriber;
38 38
39bool RunSubscriber(const string& hostname, uint16_t port);39bool RunSubscriber(const string& hostname, uint16_t port);
40void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements);40void 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 callbacks103 // 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 try113 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 else136 else
132 {137 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t